OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/resources/resource_provider.h" | 5 #include "cc/resources/resource_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/debug/alias.h" | 10 #include "base/debug/alias.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 exported(false), | 78 exported(false), |
79 marked_for_deletion(false), | 79 marked_for_deletion(false), |
80 pending_set_pixels(false), | 80 pending_set_pixels(false), |
81 set_pixels_completion_forced(false), | 81 set_pixels_completion_forced(false), |
82 allocated(false), | 82 allocated(false), |
83 enable_read_lock_fences(false), | 83 enable_read_lock_fences(false), |
84 read_lock_fence(NULL), | 84 read_lock_fence(NULL), |
85 size(), | 85 size(), |
86 format(0), | 86 format(0), |
87 filter(0), | 87 filter(0), |
88 image_id(0), | |
88 type(static_cast<ResourceType>(0)) {} | 89 type(static_cast<ResourceType>(0)) {} |
89 | 90 |
90 ResourceProvider::Resource::~Resource() {} | 91 ResourceProvider::Resource::~Resource() {} |
91 | 92 |
92 ResourceProvider::Resource::Resource( | 93 ResourceProvider::Resource::Resource( |
93 unsigned texture_id, gfx::Size size, GLenum format, GLenum filter) | 94 unsigned texture_id, gfx::Size size, GLenum format, GLenum filter) |
94 : gl_id(texture_id), | 95 : gl_id(texture_id), |
95 gl_pixel_buffer_id(0), | 96 gl_pixel_buffer_id(0), |
96 gl_upload_query_id(0), | 97 gl_upload_query_id(0), |
97 pixels(NULL), | 98 pixels(NULL), |
98 pixel_buffer(NULL), | 99 pixel_buffer(NULL), |
99 lock_for_read_count(0), | 100 lock_for_read_count(0), |
100 locked_for_write(false), | 101 locked_for_write(false), |
101 external(false), | 102 external(false), |
102 exported(false), | 103 exported(false), |
103 marked_for_deletion(false), | 104 marked_for_deletion(false), |
104 pending_set_pixels(false), | 105 pending_set_pixels(false), |
105 set_pixels_completion_forced(false), | 106 set_pixels_completion_forced(false), |
106 allocated(false), | 107 allocated(false), |
107 enable_read_lock_fences(false), | 108 enable_read_lock_fences(false), |
108 read_lock_fence(NULL), | 109 read_lock_fence(NULL), |
109 size(size), | 110 size(size), |
110 format(format), | 111 format(format), |
111 filter(filter), | 112 filter(filter), |
113 image_id(0), | |
112 type(GLTexture) {} | 114 type(GLTexture) {} |
113 | 115 |
114 ResourceProvider::Resource::Resource( | 116 ResourceProvider::Resource::Resource( |
115 uint8_t* pixels, gfx::Size size, GLenum format, GLenum filter) | 117 uint8_t* pixels, gfx::Size size, GLenum format, GLenum filter) |
116 : gl_id(0), | 118 : gl_id(0), |
117 gl_pixel_buffer_id(0), | 119 gl_pixel_buffer_id(0), |
118 gl_upload_query_id(0), | 120 gl_upload_query_id(0), |
119 pixels(pixels), | 121 pixels(pixels), |
120 pixel_buffer(NULL), | 122 pixel_buffer(NULL), |
121 lock_for_read_count(0), | 123 lock_for_read_count(0), |
122 locked_for_write(false), | 124 locked_for_write(false), |
123 external(false), | 125 external(false), |
124 exported(false), | 126 exported(false), |
125 marked_for_deletion(false), | 127 marked_for_deletion(false), |
126 pending_set_pixels(false), | 128 pending_set_pixels(false), |
127 set_pixels_completion_forced(false), | 129 set_pixels_completion_forced(false), |
128 allocated(false), | 130 allocated(false), |
129 enable_read_lock_fences(false), | 131 enable_read_lock_fences(false), |
130 read_lock_fence(NULL), | 132 read_lock_fence(NULL), |
131 size(size), | 133 size(size), |
132 format(format), | 134 format(format), |
133 filter(filter), | 135 filter(filter), |
136 image_id(0), | |
134 type(Bitmap) {} | 137 type(Bitmap) {} |
135 | 138 |
136 ResourceProvider::Child::Child() {} | 139 ResourceProvider::Child::Child() {} |
137 | 140 |
138 ResourceProvider::Child::~Child() {} | 141 ResourceProvider::Child::~Child() {} |
139 | 142 |
140 scoped_ptr<ResourceProvider> ResourceProvider::Create( | 143 scoped_ptr<ResourceProvider> ResourceProvider::Create( |
141 OutputSurface* output_surface, | 144 OutputSurface* output_surface, |
142 int highp_threshold_min) { | 145 int highp_threshold_min) { |
143 scoped_ptr<ResourceProvider> resource_provider( | 146 scoped_ptr<ResourceProvider> resource_provider( |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
301 | 304 |
302 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, | 305 void ResourceProvider::DeleteResourceInternal(ResourceMap::iterator it, |
303 DeleteStyle style) { | 306 DeleteStyle style) { |
304 Resource* resource = &it->second; | 307 Resource* resource = &it->second; |
305 bool lost_resource = lost_output_surface_; | 308 bool lost_resource = lost_output_surface_; |
306 | 309 |
307 DCHECK(!resource->exported || style != Normal); | 310 DCHECK(!resource->exported || style != Normal); |
308 if (style == ForShutdown && resource->exported) | 311 if (style == ForShutdown && resource->exported) |
309 lost_resource = true; | 312 lost_resource = true; |
310 | 313 |
314 if (resource->image_id) { | |
315 WebGraphicsContext3D* context3d = output_surface_->context3d(); | |
316 DCHECK(context3d); | |
317 GLC(context3d, context3d->destroyImageCHROMIUM(resource->image_id)); | |
318 } | |
319 | |
311 if (resource->gl_id && !resource->external) { | 320 if (resource->gl_id && !resource->external) { |
312 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 321 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
313 DCHECK(context3d); | 322 DCHECK(context3d); |
314 GLC(context3d, context3d->deleteTexture(resource->gl_id)); | 323 GLC(context3d, context3d->deleteTexture(resource->gl_id)); |
315 } | 324 } |
316 if (resource->gl_upload_query_id) { | 325 if (resource->gl_upload_query_id) { |
317 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 326 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
318 DCHECK(context3d); | 327 DCHECK(context3d); |
319 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id)); | 328 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id)); |
320 } | 329 } |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 gfx::Vector2d dest_offset) { | 371 gfx::Vector2d dest_offset) { |
363 DCHECK(thread_checker_.CalledOnValidThread()); | 372 DCHECK(thread_checker_.CalledOnValidThread()); |
364 ResourceMap::iterator it = resources_.find(id); | 373 ResourceMap::iterator it = resources_.find(id); |
365 CHECK(it != resources_.end()); | 374 CHECK(it != resources_.end()); |
366 Resource* resource = &it->second; | 375 Resource* resource = &it->second; |
367 DCHECK(!resource->locked_for_write); | 376 DCHECK(!resource->locked_for_write); |
368 DCHECK(!resource->lock_for_read_count); | 377 DCHECK(!resource->lock_for_read_count); |
369 DCHECK(!resource->external); | 378 DCHECK(!resource->external); |
370 DCHECK(!resource->exported); | 379 DCHECK(!resource->exported); |
371 DCHECK(ReadLockFenceHasPassed(resource)); | 380 DCHECK(ReadLockFenceHasPassed(resource)); |
381 DCHECK(!resource->image_id); | |
372 LazyAllocate(resource); | 382 LazyAllocate(resource); |
373 | 383 |
374 if (resource->gl_id) { | 384 if (resource->gl_id) { |
375 DCHECK(!resource->pending_set_pixels); | 385 DCHECK(!resource->pending_set_pixels); |
376 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 386 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
377 DCHECK(context3d); | 387 DCHECK(context3d); |
378 DCHECK(texture_uploader_.get()); | 388 DCHECK(texture_uploader_.get()); |
379 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); | 389 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
380 texture_uploader_->Upload(image, | 390 texture_uploader_->Upload(image, |
381 image_rect, | 391 image_rect, |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
624 ResourceProvider::ResourceProvider(OutputSurface* output_surface) | 634 ResourceProvider::ResourceProvider(OutputSurface* output_surface) |
625 : output_surface_(output_surface), | 635 : output_surface_(output_surface), |
626 lost_output_surface_(false), | 636 lost_output_surface_(false), |
627 next_id_(1), | 637 next_id_(1), |
628 next_child_(1), | 638 next_child_(1), |
629 default_resource_type_(output_surface->context3d() ? GLTexture : Bitmap), | 639 default_resource_type_(output_surface->context3d() ? GLTexture : Bitmap), |
630 use_texture_storage_ext_(false), | 640 use_texture_storage_ext_(false), |
631 use_texture_usage_hint_(false), | 641 use_texture_usage_hint_(false), |
632 use_shallow_flush_(false), | 642 use_shallow_flush_(false), |
633 max_texture_size_(0), | 643 max_texture_size_(0), |
634 best_texture_format_(0) {} | 644 best_texture_format_(0), |
645 use_gpu_memory_buffers_(false) { | |
646 } | |
635 | 647 |
636 bool ResourceProvider::Initialize(int highp_threshold_min) { | 648 bool ResourceProvider::Initialize(int highp_threshold_min) { |
637 DCHECK(thread_checker_.CalledOnValidThread()); | 649 DCHECK(thread_checker_.CalledOnValidThread()); |
638 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 650 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
639 if (!context3d) { | 651 if (!context3d) { |
640 max_texture_size_ = INT_MAX / 2; | 652 max_texture_size_ = INT_MAX / 2; |
641 best_texture_format_ = GL_RGBA; | 653 best_texture_format_ = GL_RGBA; |
642 return true; | 654 return true; |
643 } | 655 } |
644 if (!context3d->makeContextCurrent()) | 656 if (!context3d->makeContextCurrent()) |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
852 TransferableResource* resource) { | 864 TransferableResource* resource) { |
853 DCHECK(thread_checker_.CalledOnValidThread()); | 865 DCHECK(thread_checker_.CalledOnValidThread()); |
854 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 866 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
855 ResourceMap::iterator it = resources_.find(id); | 867 ResourceMap::iterator it = resources_.find(id); |
856 CHECK(it != resources_.end()); | 868 CHECK(it != resources_.end()); |
857 Resource* source = &it->second; | 869 Resource* source = &it->second; |
858 DCHECK(!source->locked_for_write); | 870 DCHECK(!source->locked_for_write); |
859 DCHECK(!source->lock_for_read_count); | 871 DCHECK(!source->lock_for_read_count); |
860 DCHECK(!source->external || (source->external && !source->mailbox.IsEmpty())); | 872 DCHECK(!source->external || (source->external && !source->mailbox.IsEmpty())); |
861 DCHECK(source->allocated); | 873 DCHECK(source->allocated); |
874 DCHECK(!source->image_id); | |
862 if (source->exported) | 875 if (source->exported) |
863 return false; | 876 return false; |
864 resource->id = id; | 877 resource->id = id; |
865 resource->format = source->format; | 878 resource->format = source->format; |
866 resource->filter = source->filter; | 879 resource->filter = source->filter; |
867 resource->size = source->size; | 880 resource->size = source->size; |
868 | 881 |
869 if (source->mailbox.IsEmpty()) { | 882 if (source->mailbox.IsEmpty()) { |
870 GLC(context3d, context3d->genMailboxCHROMIUM(resource->mailbox.name)); | 883 GLC(context3d, context3d->genMailboxCHROMIUM(resource->mailbox.name)); |
871 source->mailbox.SetName(resource->mailbox); | 884 source->mailbox.SetName(resource->mailbox); |
(...skipping 16 matching lines...) Expand all Loading... | |
888 DCHECK(thread_checker_.CalledOnValidThread()); | 901 DCHECK(thread_checker_.CalledOnValidThread()); |
889 ResourceMap::iterator it = resources_.find(id); | 902 ResourceMap::iterator it = resources_.find(id); |
890 CHECK(it != resources_.end()); | 903 CHECK(it != resources_.end()); |
891 Resource* resource = &it->second; | 904 Resource* resource = &it->second; |
892 DCHECK(!resource->external); | 905 DCHECK(!resource->external); |
893 DCHECK(!resource->exported); | 906 DCHECK(!resource->exported); |
894 | 907 |
895 if (resource->gl_id) { | 908 if (resource->gl_id) { |
896 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 909 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
897 DCHECK(context3d); | 910 DCHECK(context3d); |
898 if (!resource->gl_pixel_buffer_id) | 911 if (!use_gpu_memory_buffers_) { |
899 resource->gl_pixel_buffer_id = context3d->createBuffer(); | 912 if (!resource->gl_pixel_buffer_id) |
900 context3d->bindBuffer( | 913 resource->gl_pixel_buffer_id = context3d->createBuffer(); |
901 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 914 context3d->bindBuffer( |
902 resource->gl_pixel_buffer_id); | 915 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
903 context3d->bufferData( | 916 resource->gl_pixel_buffer_id); |
904 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 917 context3d->bufferData( |
905 resource->size.width() * resource->size.height() * 4, | 918 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
906 NULL, | 919 resource->size.width() * resource->size.height() * 4, |
907 GL_DYNAMIC_DRAW); | 920 NULL, |
908 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 921 GL_DYNAMIC_DRAW); |
922 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | |
923 } else { | |
924 DCHECK_EQ(0u, resource->image_id); | |
925 resource->image_id = context3d->createImageCHROMIUM( | |
926 resource->size.width(), resource->size.height(), GL_RGBA8_OES); | |
reveman
2013/05/17 01:48:08
please put this in a new AcquireImage() function i
kaanb
2013/05/17 21:27:36
Done.
| |
927 } | |
909 } | 928 } |
910 | 929 |
911 if (resource->pixels) { | 930 if (resource->pixels) { |
912 if (resource->pixel_buffer) | 931 if (resource->pixel_buffer) |
913 return; | 932 return; |
914 | 933 |
915 resource->pixel_buffer = new uint8_t[ | 934 resource->pixel_buffer = new uint8_t[ |
916 resource->size.width() * resource->size.height() * 4]; | 935 resource->size.width() * resource->size.height() * 4]; |
917 } | 936 } |
918 } | 937 } |
919 | 938 |
920 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { | 939 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { |
921 DCHECK(thread_checker_.CalledOnValidThread()); | 940 DCHECK(thread_checker_.CalledOnValidThread()); |
922 ResourceMap::iterator it = resources_.find(id); | 941 ResourceMap::iterator it = resources_.find(id); |
923 CHECK(it != resources_.end()); | 942 CHECK(it != resources_.end()); |
924 Resource* resource = &it->second; | 943 Resource* resource = &it->second; |
925 DCHECK(!resource->external); | 944 DCHECK(!resource->external); |
926 DCHECK(!resource->exported); | 945 DCHECK(!resource->exported); |
927 | 946 |
928 if (resource->gl_id) { | 947 if (resource->gl_id) { |
929 if (!resource->gl_pixel_buffer_id) | 948 if (!resource->gl_pixel_buffer_id && resource->image_id == 0) |
930 return; | 949 return; |
931 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 950 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
932 DCHECK(context3d); | 951 DCHECK(context3d); |
933 context3d->bindBuffer( | 952 if (resource->image_id == 0) { |
934 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 953 DCHECK(resource->gl_pixel_buffer_id); |
935 resource->gl_pixel_buffer_id); | 954 context3d->bindBuffer( |
936 context3d->bufferData( | 955 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
937 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 956 resource->gl_pixel_buffer_id); |
938 0, | 957 context3d->bufferData( |
939 NULL, | 958 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
940 GL_DYNAMIC_DRAW); | 959 0, |
941 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 960 NULL, |
961 GL_DYNAMIC_DRAW); | |
962 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | |
963 } else { | |
964 context3d->destroyImageCHROMIUM(resource->image_id); | |
965 resource->image_id = 0; | |
reveman
2013/05/17 01:48:08
and this in ReleaseImage()
kaanb
2013/05/17 21:27:36
Done.
| |
966 } | |
942 } | 967 } |
943 | 968 |
944 if (resource->pixels) { | 969 if (resource->pixels) { |
945 if (!resource->pixel_buffer) | 970 if (!resource->pixel_buffer) |
946 return; | 971 return; |
947 delete[] resource->pixel_buffer; | 972 delete[] resource->pixel_buffer; |
948 resource->pixel_buffer = NULL; | 973 resource->pixel_buffer = NULL; |
949 } | 974 } |
950 } | 975 } |
951 | 976 |
952 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { | 977 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { |
953 DCHECK(thread_checker_.CalledOnValidThread()); | 978 DCHECK(thread_checker_.CalledOnValidThread()); |
954 ResourceMap::iterator it = resources_.find(id); | 979 ResourceMap::iterator it = resources_.find(id); |
955 CHECK(it != resources_.end()); | 980 CHECK(it != resources_.end()); |
956 Resource* resource = &it->second; | 981 Resource* resource = &it->second; |
957 DCHECK(!resource->external); | 982 DCHECK(!resource->external); |
958 DCHECK(!resource->exported); | 983 DCHECK(!resource->exported); |
959 | 984 |
960 if (resource->gl_id) { | 985 if (resource->gl_id) { |
961 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 986 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
962 DCHECK(context3d); | 987 DCHECK(context3d); |
963 DCHECK(resource->gl_pixel_buffer_id); | 988 if (resource->image_id == 0) { |
964 context3d->bindBuffer( | 989 DCHECK(resource->gl_pixel_buffer_id); |
965 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 990 context3d->bindBuffer( |
966 resource->gl_pixel_buffer_id); | 991 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
967 uint8_t* image = static_cast<uint8_t*>( | 992 resource->gl_pixel_buffer_id); |
968 context3d->mapBufferCHROMIUM( | 993 uint8_t* image = static_cast<uint8_t*>( |
969 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); | 994 context3d->mapBufferCHROMIUM( |
970 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 995 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); |
971 return image; | 996 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
997 return image; | |
998 } else { | |
999 return static_cast<uint8_t*>( | |
1000 context3d->mapImageCHROMIUM(resource->image_id, GL_READ_WRITE)); | |
reveman
2013/05/17 01:48:08
and I prefer this in a MapImage() function. We mig
kaanb
2013/05/17 21:27:36
Done.
| |
1001 } | |
972 } | 1002 } |
973 | 1003 |
974 if (resource->pixels) | 1004 if (resource->pixels) |
975 return resource->pixel_buffer; | 1005 return resource->pixel_buffer; |
976 | 1006 |
977 return NULL; | 1007 return NULL; |
978 } | 1008 } |
979 | 1009 |
980 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { | 1010 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { |
981 DCHECK(thread_checker_.CalledOnValidThread()); | 1011 DCHECK(thread_checker_.CalledOnValidThread()); |
982 ResourceMap::iterator it = resources_.find(id); | 1012 ResourceMap::iterator it = resources_.find(id); |
983 CHECK(it != resources_.end()); | 1013 CHECK(it != resources_.end()); |
984 Resource* resource = &it->second; | 1014 Resource* resource = &it->second; |
985 DCHECK(!resource->external); | 1015 DCHECK(!resource->external); |
986 DCHECK(!resource->exported); | 1016 DCHECK(!resource->exported); |
987 | 1017 |
988 if (resource->gl_id) { | 1018 if (resource->gl_id) { |
989 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1019 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
990 DCHECK(context3d); | 1020 DCHECK(context3d); |
991 DCHECK(resource->gl_pixel_buffer_id); | 1021 if (resource->image_id == 0) { |
992 context3d->bindBuffer( | 1022 DCHECK(resource->gl_pixel_buffer_id); |
993 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1023 context3d->bindBuffer( |
994 resource->gl_pixel_buffer_id); | 1024 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
995 context3d->unmapBufferCHROMIUM( | 1025 resource->gl_pixel_buffer_id); |
996 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); | 1026 context3d->unmapBufferCHROMIUM( |
997 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1027 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); |
1028 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | |
1029 } else { | |
1030 context3d->unmapImageCHROMIUM(resource->image_id); | |
reveman
2013/05/17 01:48:08
UnmapImage.
kaanb
2013/05/17 21:27:36
Done.
| |
1031 } | |
998 } | 1032 } |
999 } | 1033 } |
1000 | 1034 |
1001 void ResourceProvider::SetPixelsFromBuffer(ResourceId id) { | 1035 void ResourceProvider::SetPixelsFromBuffer(ResourceId id) { |
1002 DCHECK(thread_checker_.CalledOnValidThread()); | 1036 DCHECK(thread_checker_.CalledOnValidThread()); |
1003 ResourceMap::iterator it = resources_.find(id); | 1037 ResourceMap::iterator it = resources_.find(id); |
1004 CHECK(it != resources_.end()); | 1038 CHECK(it != resources_.end()); |
1005 Resource* resource = &it->second; | 1039 Resource* resource = &it->second; |
1006 DCHECK(!resource->locked_for_write); | 1040 DCHECK(!resource->locked_for_write); |
1007 DCHECK(!resource->lock_for_read_count); | 1041 DCHECK(!resource->lock_for_read_count); |
1008 DCHECK(!resource->external); | 1042 DCHECK(!resource->external); |
1009 DCHECK(!resource->exported); | 1043 DCHECK(!resource->exported); |
1010 DCHECK(ReadLockFenceHasPassed(resource)); | 1044 DCHECK(ReadLockFenceHasPassed(resource)); |
1045 DCHECK(!resource->image_id); | |
reveman
2013/05/17 01:48:08
I don't think this DCHECK should be here.
kaanb
2013/05/17 21:27:36
Done.
| |
1011 LazyAllocate(resource); | 1046 LazyAllocate(resource); |
1012 | 1047 |
1013 if (resource->gl_id) { | 1048 if (resource->gl_id) { |
1014 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1049 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
1015 DCHECK(context3d); | 1050 DCHECK(context3d); |
1016 DCHECK(resource->gl_pixel_buffer_id); | 1051 DCHECK(resource->gl_pixel_buffer_id); |
1017 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); | 1052 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
1018 context3d->bindBuffer( | 1053 context3d->bindBuffer( |
1019 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1054 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1020 resource->gl_pixel_buffer_id); | 1055 resource->gl_pixel_buffer_id); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1074 DCHECK(resource->gl_id || resource->allocated); | 1109 DCHECK(resource->gl_id || resource->allocated); |
1075 DCHECK(ReadLockFenceHasPassed(resource)); | 1110 DCHECK(ReadLockFenceHasPassed(resource)); |
1076 | 1111 |
1077 bool allocate = !resource->allocated; | 1112 bool allocate = !resource->allocated; |
1078 resource->allocated = true; | 1113 resource->allocated = true; |
1079 LockForWrite(id); | 1114 LockForWrite(id); |
1080 | 1115 |
1081 if (resource->gl_id) { | 1116 if (resource->gl_id) { |
1082 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1117 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
1083 DCHECK(context3d); | 1118 DCHECK(context3d); |
1084 DCHECK(resource->gl_pixel_buffer_id); | 1119 if (resource->image_id == 0) { |
1085 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); | 1120 DCHECK(resource->gl_pixel_buffer_id); |
1086 context3d->bindBuffer( | 1121 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
1087 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1122 context3d->bindBuffer( |
1088 resource->gl_pixel_buffer_id); | 1123 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1089 if (!resource->gl_upload_query_id) | 1124 resource->gl_pixel_buffer_id); |
1090 resource->gl_upload_query_id = context3d->createQueryEXT(); | 1125 if (!resource->gl_upload_query_id) |
1091 context3d->beginQueryEXT( | 1126 resource->gl_upload_query_id = context3d->createQueryEXT(); |
1092 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, | 1127 context3d->beginQueryEXT( |
1093 resource->gl_upload_query_id); | 1128 GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM, |
1094 if (allocate) { | 1129 resource->gl_upload_query_id); |
1095 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, | 1130 if (allocate) { |
1096 0, /* level */ | 1131 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, |
1097 resource->format, | 1132 0, /* level */ |
1098 resource->size.width(), | 1133 resource->format, |
1099 resource->size.height(), | 1134 resource->size.width(), |
1100 0, /* border */ | 1135 resource->size.height(), |
1101 resource->format, | 1136 0, /* border */ |
1102 GL_UNSIGNED_BYTE, | 1137 resource->format, |
1103 NULL); | 1138 GL_UNSIGNED_BYTE, |
1139 NULL); | |
1140 } else { | |
1141 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | |
1142 0, /* level */ | |
1143 0, /* x */ | |
1144 0, /* y */ | |
1145 resource->size.width(), | |
1146 resource->size.height(), | |
1147 resource->format, | |
1148 GL_UNSIGNED_BYTE, | |
1149 NULL); | |
1150 } | |
1151 context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM); | |
1152 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | |
1104 } else { | 1153 } else { |
1105 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, | 1154 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
1106 0, /* level */ | 1155 context3d->bindTexImage2DCHROMIUM(GL_TEXTURE_2D, resource->image_id); |
reveman
2013/05/17 01:48:08
please add a BindImage() function for this instead
kaanb
2013/05/17 21:27:36
Done.
| |
1107 0, /* x */ | |
1108 0, /* y */ | |
1109 resource->size.width(), | |
1110 resource->size.height(), | |
1111 resource->format, | |
1112 GL_UNSIGNED_BYTE, | |
1113 NULL); | |
1114 } | 1156 } |
1115 context3d->endQueryEXT(GL_ASYNC_PIXEL_TRANSFERS_COMPLETED_CHROMIUM); | |
1116 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | |
1117 } | 1157 } |
1118 | 1158 |
1119 if (resource->pixels) | 1159 if (resource->pixels) |
1120 SetPixelsFromBuffer(id); | 1160 SetPixelsFromBuffer(id); |
1121 | 1161 |
1122 resource->pending_set_pixels = true; | 1162 resource->pending_set_pixels = true; |
1123 resource->set_pixels_completion_forced = false; | 1163 resource->set_pixels_completion_forced = false; |
1124 } | 1164 } |
1125 | 1165 |
1126 void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) { | 1166 void ResourceProvider::ForceSetPixelsToComplete(ResourceId id) { |
1127 DCHECK(thread_checker_.CalledOnValidThread()); | 1167 DCHECK(thread_checker_.CalledOnValidThread()); |
1128 ResourceMap::iterator it = resources_.find(id); | 1168 ResourceMap::iterator it = resources_.find(id); |
1129 CHECK(it != resources_.end()); | 1169 CHECK(it != resources_.end()); |
1130 Resource* resource = &it->second; | 1170 Resource* resource = &it->second; |
1131 DCHECK(resource->locked_for_write); | 1171 DCHECK(resource->locked_for_write); |
1132 DCHECK(resource->pending_set_pixels); | 1172 DCHECK(resource->pending_set_pixels); |
1133 DCHECK(!resource->set_pixels_completion_forced); | 1173 DCHECK(!resource->set_pixels_completion_forced); |
1134 | 1174 |
1135 if (resource->gl_id) { | 1175 if (resource->gl_id && resource->image_id == 0) { |
1136 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1176 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
1137 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); | 1177 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); |
1138 GLC(context3d, context3d->waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)); | 1178 GLC(context3d, context3d->waitAsyncTexImage2DCHROMIUM(GL_TEXTURE_2D)); |
1139 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, 0)); | 1179 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, 0)); |
1140 } | 1180 } |
1141 | 1181 |
1142 resource->set_pixels_completion_forced = true; | 1182 resource->set_pixels_completion_forced = true; |
1143 } | 1183 } |
1144 | 1184 |
1145 bool ResourceProvider::DidSetPixelsComplete(ResourceId id) { | 1185 bool ResourceProvider::DidSetPixelsComplete(ResourceId id) { |
1146 DCHECK(thread_checker_.CalledOnValidThread()); | 1186 DCHECK(thread_checker_.CalledOnValidThread()); |
1147 ResourceMap::iterator it = resources_.find(id); | 1187 ResourceMap::iterator it = resources_.find(id); |
1148 CHECK(it != resources_.end()); | 1188 CHECK(it != resources_.end()); |
1149 Resource* resource = &it->second; | 1189 Resource* resource = &it->second; |
1150 DCHECK(resource->locked_for_write); | 1190 DCHECK(resource->locked_for_write); |
1151 DCHECK(resource->pending_set_pixels); | 1191 DCHECK(resource->pending_set_pixels); |
1152 | 1192 |
1153 if (resource->gl_id) { | 1193 if (resource->gl_id && resource->image_id == 0) { |
1154 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1194 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
1155 DCHECK(context3d); | 1195 DCHECK(context3d); |
1156 DCHECK(resource->gl_upload_query_id); | 1196 DCHECK(resource->gl_upload_query_id); |
1157 unsigned complete = 1; | 1197 unsigned complete = 1; |
1158 context3d->getQueryObjectuivEXT( | 1198 context3d->getQueryObjectuivEXT( |
1159 resource->gl_upload_query_id, | 1199 resource->gl_upload_query_id, |
1160 GL_QUERY_RESULT_AVAILABLE_EXT, | 1200 GL_QUERY_RESULT_AVAILABLE_EXT, |
1161 &complete); | 1201 &complete); |
1162 if (!complete) | 1202 if (!complete) |
1163 return false; | 1203 return false; |
1164 } | 1204 } |
1165 | 1205 |
1166 resource->pending_set_pixels = false; | 1206 resource->pending_set_pixels = false; |
1167 UnlockForWrite(id); | 1207 UnlockForWrite(id); |
1168 | 1208 |
1169 return true; | 1209 return true; |
1170 } | 1210 } |
1171 | 1211 |
1172 void ResourceProvider::AbortSetPixels(ResourceId id) { | 1212 void ResourceProvider::AbortSetPixels(ResourceId id) { |
1173 DCHECK(thread_checker_.CalledOnValidThread()); | 1213 DCHECK(thread_checker_.CalledOnValidThread()); |
1174 ResourceMap::iterator it = resources_.find(id); | 1214 ResourceMap::iterator it = resources_.find(id); |
1175 CHECK(it != resources_.end()); | 1215 CHECK(it != resources_.end()); |
1176 Resource* resource = &it->second; | 1216 Resource* resource = &it->second; |
1177 DCHECK(resource->locked_for_write); | 1217 DCHECK(resource->locked_for_write); |
1178 DCHECK(resource->pending_set_pixels); | 1218 DCHECK(resource->pending_set_pixels); |
1179 | 1219 |
1180 if (resource->gl_id) { | 1220 if (resource->gl_id) { |
1181 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1221 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
1182 DCHECK(context3d); | 1222 DCHECK(context3d); |
1183 DCHECK(resource->gl_upload_query_id); | 1223 if (resource->image_id == 0) { |
1184 // CHROMIUM_async_pixel_transfers currently doesn't have a way to | 1224 DCHECK(resource->gl_upload_query_id); |
1185 // abort an upload. The best we can do is delete the query and | 1225 // CHROMIUM_async_pixel_transfers currently doesn't have a way to |
1186 // the texture. | 1226 // abort an upload. The best we can do is delete the query and |
1187 context3d->deleteQueryEXT(resource->gl_upload_query_id); | 1227 // the texture. |
1188 resource->gl_upload_query_id = 0; | 1228 context3d->deleteQueryEXT(resource->gl_upload_query_id); |
1229 resource->gl_upload_query_id = 0; | |
1230 } else { | |
1231 // CHROMIUM_map_image doesn't have a way to abort an upload either. | |
1232 // So we just destroy the image. | |
1233 DCHECK(resource->image_id); | |
1234 context3d->destroyImageCHROMIUM(resource->image_id); | |
1235 resource->image_id = 0; | |
reveman
2013/05/17 01:48:08
no need for any of these changes.
kaanb
2013/05/17 21:27:36
Done.
| |
1236 } | |
1189 context3d->deleteTexture(resource->gl_id); | 1237 context3d->deleteTexture(resource->gl_id); |
1190 resource->gl_id = CreateTextureId(context3d); | 1238 resource->gl_id = CreateTextureId(context3d); |
1191 resource->allocated = false; | 1239 resource->allocated = false; |
1192 } | 1240 } |
1193 | 1241 |
1194 resource->pending_set_pixels = false; | 1242 resource->pending_set_pixels = false; |
1195 UnlockForWrite(id); | 1243 UnlockForWrite(id); |
1196 } | 1244 } |
1197 | 1245 |
1198 void ResourceProvider::AllocateForTesting(ResourceId id) { | 1246 void ResourceProvider::AllocateForTesting(ResourceId id) { |
1199 ResourceMap::iterator it = resources_.find(id); | 1247 ResourceMap::iterator it = resources_.find(id); |
1200 CHECK(it != resources_.end()); | 1248 CHECK(it != resources_.end()); |
1201 Resource* resource = &it->second; | 1249 Resource* resource = &it->second; |
1202 LazyAllocate(resource); | 1250 LazyAllocate(resource); |
1203 } | 1251 } |
1204 | 1252 |
1205 void ResourceProvider::LazyAllocate(Resource* resource) { | 1253 void ResourceProvider::LazyAllocate(Resource* resource) { |
1206 DCHECK(resource); | 1254 DCHECK(resource); |
1207 DCHECK(resource->gl_id || resource->allocated); | 1255 DCHECK(resource->gl_id || resource->allocated); |
1208 | 1256 |
1209 if (resource->allocated || !resource->gl_id) | 1257 if (resource->allocated || !resource->gl_id) |
1210 return; | 1258 return; |
1211 resource->allocated = true; | 1259 resource->allocated = true; |
1212 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1260 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
1213 gfx::Size& size = resource->size; | 1261 gfx::Size& size = resource->size; |
1214 GLenum format = resource->format; | 1262 GLenum format = resource->format; |
1263 | |
1215 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); | 1264 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); |
1216 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { | 1265 if (use_texture_storage_ext_ && IsTextureFormatSupportedForStorage(format)) { |
1217 GLenum storage_format = TextureToStorageFormat(format); | 1266 GLenum storage_format = TextureToStorageFormat(format); |
1218 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, | 1267 GLC(context3d, context3d->texStorage2DEXT(GL_TEXTURE_2D, |
1219 1, | 1268 1, |
1220 storage_format, | 1269 storage_format, |
1221 size.width(), | 1270 size.width(), |
1222 size.height())); | 1271 size.height())); |
1223 } else { | 1272 } else { |
1273 // TODO(kaanb): Check with reviewers if we want this call | |
1274 // for GpuMemoryBuffers? | |
reveman
2013/05/17 01:48:08
I don't think this affects zero-copy. just like it
kaanb
2013/05/17 21:27:36
Acknowledged.
| |
1224 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, | 1275 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, |
1225 0, | 1276 0, |
1226 format, | 1277 format, |
1227 size.width(), | 1278 size.width(), |
1228 size.height(), | 1279 size.height(), |
1229 0, | 1280 0, |
1230 format, | 1281 format, |
1231 GL_UNSIGNED_BYTE, | 1282 GL_UNSIGNED_BYTE, |
1232 NULL)); | 1283 NULL)); |
1233 } | 1284 } |
1234 } | 1285 } |
1235 | 1286 |
1236 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, | 1287 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, |
1237 bool enable) { | 1288 bool enable) { |
1238 DCHECK(thread_checker_.CalledOnValidThread()); | 1289 DCHECK(thread_checker_.CalledOnValidThread()); |
1239 ResourceMap::iterator it = resources_.find(id); | 1290 ResourceMap::iterator it = resources_.find(id); |
1240 CHECK(it != resources_.end()); | 1291 CHECK(it != resources_.end()); |
1241 Resource* resource = &it->second; | 1292 Resource* resource = &it->second; |
1242 resource->enable_read_lock_fences = enable; | 1293 resource->enable_read_lock_fences = enable; |
1243 } | 1294 } |
1244 | 1295 |
1296 void ResourceProvider::SetUseGpuMemoryBuffers(bool use_gpu_memory_buffers) { | |
1297 use_gpu_memory_buffers_ = use_gpu_memory_buffers; | |
1298 } | |
1299 | |
1245 } // namespace cc | 1300 } // namespace cc |
OLD | NEW |