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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
624 ResourceProvider::ResourceProvider(OutputSurface* output_surface) | 633 ResourceProvider::ResourceProvider(OutputSurface* output_surface) |
625 : output_surface_(output_surface), | 634 : output_surface_(output_surface), |
626 lost_output_surface_(false), | 635 lost_output_surface_(false), |
627 next_id_(1), | 636 next_id_(1), |
628 next_child_(1), | 637 next_child_(1), |
629 default_resource_type_(output_surface->context3d() ? GLTexture : Bitmap), | 638 default_resource_type_(output_surface->context3d() ? GLTexture : Bitmap), |
630 use_texture_storage_ext_(false), | 639 use_texture_storage_ext_(false), |
631 use_texture_usage_hint_(false), | 640 use_texture_usage_hint_(false), |
632 use_shallow_flush_(false), | 641 use_shallow_flush_(false), |
633 max_texture_size_(0), | 642 max_texture_size_(0), |
634 best_texture_format_(0) {} | 643 best_texture_format_(0) { |
644 } | |
635 | 645 |
636 bool ResourceProvider::Initialize(int highp_threshold_min) { | 646 bool ResourceProvider::Initialize(int highp_threshold_min) { |
637 DCHECK(thread_checker_.CalledOnValidThread()); | 647 DCHECK(thread_checker_.CalledOnValidThread()); |
638 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 648 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
639 if (!context3d) { | 649 if (!context3d) { |
640 max_texture_size_ = INT_MAX / 2; | 650 max_texture_size_ = INT_MAX / 2; |
641 best_texture_format_ = GL_RGBA; | 651 best_texture_format_ = GL_RGBA; |
642 return true; | 652 return true; |
643 } | 653 } |
644 if (!context3d->makeContextCurrent()) | 654 if (!context3d->makeContextCurrent()) |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
852 TransferableResource* resource) { | 862 TransferableResource* resource) { |
853 DCHECK(thread_checker_.CalledOnValidThread()); | 863 DCHECK(thread_checker_.CalledOnValidThread()); |
854 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 864 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
855 ResourceMap::iterator it = resources_.find(id); | 865 ResourceMap::iterator it = resources_.find(id); |
856 CHECK(it != resources_.end()); | 866 CHECK(it != resources_.end()); |
857 Resource* source = &it->second; | 867 Resource* source = &it->second; |
858 DCHECK(!source->locked_for_write); | 868 DCHECK(!source->locked_for_write); |
859 DCHECK(!source->lock_for_read_count); | 869 DCHECK(!source->lock_for_read_count); |
860 DCHECK(!source->external || (source->external && !source->mailbox.IsEmpty())); | 870 DCHECK(!source->external || (source->external && !source->mailbox.IsEmpty())); |
861 DCHECK(source->allocated); | 871 DCHECK(source->allocated); |
872 DCHECK(!source->image_id); | |
reveman
2013/05/20 23:16:01
hm, I think we might need to support this. any spe
kaanb
2013/05/21 00:52:29
I'm not sure if this would be relevant for WebView
no sievers
2013/05/21 19:15:46
I'd just remove the DCHECK().
WebView would not u
piman
2013/05/21 19:50:39
It probably doesn't work right now, but should wor
kaanb
2013/05/21 20:25:41
Done.
| |
862 if (source->exported) | 873 if (source->exported) |
863 return false; | 874 return false; |
864 resource->id = id; | 875 resource->id = id; |
865 resource->format = source->format; | 876 resource->format = source->format; |
866 resource->filter = source->filter; | 877 resource->filter = source->filter; |
867 resource->size = source->size; | 878 resource->size = source->size; |
868 | 879 |
869 if (source->mailbox.IsEmpty()) { | 880 if (source->mailbox.IsEmpty()) { |
870 GLC(context3d, context3d->genMailboxCHROMIUM(resource->mailbox.name)); | 881 GLC(context3d, context3d->genMailboxCHROMIUM(resource->mailbox.name)); |
871 source->mailbox.SetName(resource->mailbox); | 882 source->mailbox.SetName(resource->mailbox); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
917 } | 928 } |
918 } | 929 } |
919 | 930 |
920 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { | 931 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { |
921 DCHECK(thread_checker_.CalledOnValidThread()); | 932 DCHECK(thread_checker_.CalledOnValidThread()); |
922 ResourceMap::iterator it = resources_.find(id); | 933 ResourceMap::iterator it = resources_.find(id); |
923 CHECK(it != resources_.end()); | 934 CHECK(it != resources_.end()); |
924 Resource* resource = &it->second; | 935 Resource* resource = &it->second; |
925 DCHECK(!resource->external); | 936 DCHECK(!resource->external); |
926 DCHECK(!resource->exported); | 937 DCHECK(!resource->exported); |
938 DCHECK(!resource->image_id); | |
reveman
2013/05/20 23:16:01
technically, there's nothing that stops us from us
kaanb
2013/05/21 00:52:29
Done.
| |
927 | 939 |
928 if (resource->gl_id) { | 940 if (resource->gl_id) { |
929 if (!resource->gl_pixel_buffer_id) | 941 if (!resource->gl_pixel_buffer_id) |
930 return; | 942 return; |
931 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 943 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
932 DCHECK(context3d); | 944 DCHECK(context3d); |
933 context3d->bindBuffer( | 945 context3d->bindBuffer( |
934 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 946 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
935 resource->gl_pixel_buffer_id); | 947 resource->gl_pixel_buffer_id); |
936 context3d->bufferData( | 948 context3d->bufferData( |
(...skipping 12 matching lines...) Expand all Loading... | |
949 } | 961 } |
950 } | 962 } |
951 | 963 |
952 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { | 964 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { |
953 DCHECK(thread_checker_.CalledOnValidThread()); | 965 DCHECK(thread_checker_.CalledOnValidThread()); |
954 ResourceMap::iterator it = resources_.find(id); | 966 ResourceMap::iterator it = resources_.find(id); |
955 CHECK(it != resources_.end()); | 967 CHECK(it != resources_.end()); |
956 Resource* resource = &it->second; | 968 Resource* resource = &it->second; |
957 DCHECK(!resource->external); | 969 DCHECK(!resource->external); |
958 DCHECK(!resource->exported); | 970 DCHECK(!resource->exported); |
971 DCHECK(!resource->image_id); | |
959 | 972 |
960 if (resource->gl_id) { | 973 if (resource->gl_id) { |
961 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 974 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
962 DCHECK(context3d); | 975 DCHECK(context3d); |
963 DCHECK(resource->gl_pixel_buffer_id); | 976 DCHECK(resource->gl_pixel_buffer_id); |
964 context3d->bindBuffer( | 977 context3d->bindBuffer( |
965 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 978 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
966 resource->gl_pixel_buffer_id); | 979 resource->gl_pixel_buffer_id); |
967 uint8_t* image = static_cast<uint8_t*>( | 980 uint8_t* image = static_cast<uint8_t*>( |
968 context3d->mapBufferCHROMIUM( | 981 context3d->mapBufferCHROMIUM( |
969 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); | 982 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); |
970 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 983 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
971 return image; | 984 return image; |
972 } | 985 } |
973 | 986 |
974 if (resource->pixels) | 987 if (resource->pixels) |
975 return resource->pixel_buffer; | 988 return resource->pixel_buffer; |
976 | 989 |
977 return NULL; | 990 return NULL; |
978 } | 991 } |
979 | 992 |
980 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { | 993 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { |
981 DCHECK(thread_checker_.CalledOnValidThread()); | 994 DCHECK(thread_checker_.CalledOnValidThread()); |
982 ResourceMap::iterator it = resources_.find(id); | 995 ResourceMap::iterator it = resources_.find(id); |
983 CHECK(it != resources_.end()); | 996 CHECK(it != resources_.end()); |
984 Resource* resource = &it->second; | 997 Resource* resource = &it->second; |
985 DCHECK(!resource->external); | 998 DCHECK(!resource->external); |
986 DCHECK(!resource->exported); | 999 DCHECK(!resource->exported); |
1000 DCHECK(!resource->image_id); | |
987 | 1001 |
988 if (resource->gl_id) { | 1002 if (resource->gl_id) { |
989 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1003 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
990 DCHECK(context3d); | 1004 DCHECK(context3d); |
991 DCHECK(resource->gl_pixel_buffer_id); | 1005 DCHECK(resource->gl_pixel_buffer_id); |
992 context3d->bindBuffer( | 1006 context3d->bindBuffer( |
993 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1007 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
994 resource->gl_pixel_buffer_id); | 1008 resource->gl_pixel_buffer_id); |
995 context3d->unmapBufferCHROMIUM( | 1009 context3d->unmapBufferCHROMIUM(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); |
996 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM); | |
997 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1010 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
998 } | 1011 } |
999 } | 1012 } |
1000 | 1013 |
1001 void ResourceProvider::SetPixelsFromBuffer(ResourceId id) { | 1014 void ResourceProvider::SetPixelsFromBuffer(ResourceId id) { |
1002 DCHECK(thread_checker_.CalledOnValidThread()); | 1015 DCHECK(thread_checker_.CalledOnValidThread()); |
1003 ResourceMap::iterator it = resources_.find(id); | 1016 ResourceMap::iterator it = resources_.find(id); |
1004 CHECK(it != resources_.end()); | 1017 CHECK(it != resources_.end()); |
1005 Resource* resource = &it->second; | 1018 Resource* resource = &it->second; |
1006 DCHECK(!resource->locked_for_write); | 1019 DCHECK(!resource->locked_for_write); |
1007 DCHECK(!resource->lock_for_read_count); | 1020 DCHECK(!resource->lock_for_read_count); |
1008 DCHECK(!resource->external); | 1021 DCHECK(!resource->external); |
1009 DCHECK(!resource->exported); | 1022 DCHECK(!resource->exported); |
1010 DCHECK(ReadLockFenceHasPassed(resource)); | 1023 DCHECK(ReadLockFenceHasPassed(resource)); |
1024 DCHECK(!resource->image_id); | |
1011 LazyAllocate(resource); | 1025 LazyAllocate(resource); |
1012 | 1026 |
1013 if (resource->gl_id) { | 1027 if (resource->gl_id) { |
1014 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1028 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
1015 DCHECK(context3d); | 1029 DCHECK(context3d); |
1016 DCHECK(resource->gl_pixel_buffer_id); | 1030 DCHECK(resource->gl_pixel_buffer_id); |
1017 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); | 1031 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
1018 context3d->bindBuffer( | 1032 context3d->bindBuffer( |
1019 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1033 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1020 resource->gl_pixel_buffer_id); | 1034 resource->gl_pixel_buffer_id); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1066 } | 1080 } |
1067 | 1081 |
1068 void ResourceProvider::BeginSetPixels(ResourceId id) { | 1082 void ResourceProvider::BeginSetPixels(ResourceId id) { |
1069 DCHECK(thread_checker_.CalledOnValidThread()); | 1083 DCHECK(thread_checker_.CalledOnValidThread()); |
1070 ResourceMap::iterator it = resources_.find(id); | 1084 ResourceMap::iterator it = resources_.find(id); |
1071 CHECK(it != resources_.end()); | 1085 CHECK(it != resources_.end()); |
1072 Resource* resource = &it->second; | 1086 Resource* resource = &it->second; |
1073 DCHECK(!resource->pending_set_pixels); | 1087 DCHECK(!resource->pending_set_pixels); |
1074 DCHECK(resource->gl_id || resource->allocated); | 1088 DCHECK(resource->gl_id || resource->allocated); |
1075 DCHECK(ReadLockFenceHasPassed(resource)); | 1089 DCHECK(ReadLockFenceHasPassed(resource)); |
1090 DCHECK(!resource->image_id); | |
1076 | 1091 |
1077 bool allocate = !resource->allocated; | 1092 bool allocate = !resource->allocated; |
1078 resource->allocated = true; | 1093 resource->allocated = true; |
1079 LockForWrite(id); | 1094 LockForWrite(id); |
1080 | 1095 |
1081 if (resource->gl_id) { | 1096 if (resource->gl_id) { |
1082 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1097 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
1083 DCHECK(context3d); | 1098 DCHECK(context3d); |
1084 DCHECK(resource->gl_pixel_buffer_id); | 1099 DCHECK(resource->gl_pixel_buffer_id); |
1085 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); | 1100 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1235 | 1250 |
1236 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, | 1251 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, |
1237 bool enable) { | 1252 bool enable) { |
1238 DCHECK(thread_checker_.CalledOnValidThread()); | 1253 DCHECK(thread_checker_.CalledOnValidThread()); |
1239 ResourceMap::iterator it = resources_.find(id); | 1254 ResourceMap::iterator it = resources_.find(id); |
1240 CHECK(it != resources_.end()); | 1255 CHECK(it != resources_.end()); |
1241 Resource* resource = &it->second; | 1256 Resource* resource = &it->second; |
1242 resource->enable_read_lock_fences = enable; | 1257 resource->enable_read_lock_fences = enable; |
1243 } | 1258 } |
1244 | 1259 |
1260 void ResourceProvider::AcquireImage(ResourceId id) { | |
1261 // TODO(kaanb): Should we delay glGenTextures to this method as well? | |
1262 DCHECK(thread_checker_.CalledOnValidThread()); | |
1263 ResourceMap::iterator it = resources_.find(id); | |
1264 CHECK(it != resources_.end()); | |
1265 Resource* resource = &it->second; | |
1266 | |
1267 DCHECK(resource->gl_id); | |
1268 DCHECK(!resource->pixels); | |
1269 DCHECK(!resource->external); | |
1270 DCHECK(!resource->exported); | |
1271 DCHECK_EQ(0u, resource->image_id); | |
reveman
2013/05/20 23:16:01
AcquirePixelBuffer can be called twice without an
kaanb
2013/05/21 00:52:29
I think we'd be leaking the first buffer if we cal
reveman
2013/05/21 02:20:19
It's perfectly fine to call glBufferData multiple
kaanb
2013/05/21 17:53:48
I looked at the code and for pixel buffers glBuffe
| |
1272 | |
1273 WebGraphicsContext3D* context3d = output_surface_->context3d(); | |
1274 DCHECK(context3d); | |
1275 resource->image_id = context3d->createImageCHROMIUM( | |
1276 resource->size.width(), resource->size.height(), GL_RGBA8_OES); | |
1277 } | |
1278 | |
1279 void ResourceProvider::ReleaseImage(ResourceId id) { | |
1280 // TODO(kaanb): CalledOnValidThread() will not be called if we're not in debug | |
1281 // mode is it intentional? | |
1282 DCHECK(thread_checker_.CalledOnValidThread()); | |
1283 ResourceMap::iterator it = resources_.find(id); | |
1284 CHECK(it != resources_.end()); | |
1285 Resource* resource = &it->second; | |
1286 | |
1287 DCHECK(!resource->external); | |
1288 DCHECK(!resource->exported); | |
1289 DCHECK(!resource->pixels); | |
1290 DCHECK(resource->image_id); | |
reveman
2013/05/20 23:16:01
Same thing here. It's Ok to call ReleasePixelBuffe
kaanb
2013/05/21 00:52:29
Again, "double free" is almost always an anti-patt
reveman
2013/05/21 02:20:19
ReleasePixelBuffer handles this properly. Maybe it
kaanb
2013/05/21 17:53:48
ReleasePixelBuffer simply returns if pixel_buffer_
| |
1291 | |
1292 WebGraphicsContext3D* context3d = output_surface_->context3d(); | |
1293 DCHECK(context3d); | |
1294 context3d->destroyImageCHROMIUM(resource->image_id); | |
1295 resource->image_id = 0; | |
1296 } | |
1297 | |
1298 uint8_t* ResourceProvider::MapImage(ResourceId id) { | |
1299 DCHECK(thread_checker_.CalledOnValidThread()); | |
1300 ResourceMap::iterator it = resources_.find(id); | |
1301 CHECK(it != resources_.end()); | |
1302 Resource* resource = &it->second; | |
1303 | |
reveman
2013/05/20 23:16:01
It's probably best to have a DCHECK(ReadLockFenceH
kaanb
2013/05/21 00:52:29
Done, should we add the same DCHECK for BindImage
reveman
2013/05/21 02:20:19
I don't think so. BindImage doesn't modify the ima
kaanb
2013/05/21 17:53:48
Acknowledged.
| |
1304 DCHECK(!resource->external); | |
1305 DCHECK(!resource->exported); | |
1306 DCHECK(!resource->pixels); | |
1307 DCHECK(resource->image_id); | |
1308 | |
1309 WebGraphicsContext3D* context3d = output_surface_->context3d(); | |
1310 DCHECK(context3d); | |
1311 return static_cast<uint8_t*>( | |
1312 context3d->mapImageCHROMIUM(resource->image_id, GL_READ_WRITE)); | |
1313 } | |
1314 | |
1315 void ResourceProvider::UnmapImage(ResourceId id) { | |
1316 DCHECK(thread_checker_.CalledOnValidThread()); | |
1317 ResourceMap::iterator it = resources_.find(id); | |
1318 CHECK(it != resources_.end()); | |
1319 Resource* resource = &it->second; | |
1320 | |
1321 DCHECK(!resource->external); | |
1322 DCHECK(!resource->exported); | |
1323 DCHECK(!resource->pixels); | |
1324 DCHECK(resource->image_id); | |
1325 | |
1326 WebGraphicsContext3D* context3d = output_surface_->context3d(); | |
1327 DCHECK(context3d); | |
1328 context3d->unmapImageCHROMIUM(resource->image_id); | |
1329 } | |
1330 | |
1331 void ResourceProvider::BindImage(ResourceId id) { | |
1332 DCHECK(thread_checker_.CalledOnValidThread()); | |
1333 ResourceMap::iterator it = resources_.find(id); | |
1334 CHECK(it != resources_.end()); | |
1335 Resource* resource = &it->second; | |
1336 | |
1337 DCHECK(!resource->external); | |
1338 DCHECK(!resource->exported); | |
1339 DCHECK(!resource->pixels); | |
1340 DCHECK(resource->image_id); | |
1341 DCHECK(resource->gl_id); | |
1342 | |
1343 // TODO(kaanb): Do we need ReadLockFenceHasPassed and/or LockForWrite() | |
1344 WebGraphicsContext3D* context3d = output_surface_->context3d(); | |
1345 DCHECK(context3d); | |
1346 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); | |
1347 context3d->bindTexImage2DCHROMIUM(GL_TEXTURE_2D, resource->image_id); | |
1348 } | |
1349 | |
1350 int ResourceProvider::GetImageStride(ResourceId id) { | |
1351 DCHECK(thread_checker_.CalledOnValidThread()); | |
1352 ResourceMap::iterator it = resources_.find(id); | |
1353 CHECK(it != resources_.end()); | |
1354 Resource* resource = &it->second; | |
1355 | |
1356 DCHECK(!resource->external); | |
1357 DCHECK(!resource->exported); | |
1358 DCHECK(!resource->pixels); | |
1359 DCHECK(resource->image_id); | |
1360 | |
1361 WebGraphicsContext3D* context3d = output_surface_->context3d(); | |
1362 DCHECK(context3d); | |
1363 int stride = 0; | |
1364 context3d->getImageParameterivCHROMIUM( | |
1365 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride); | |
1366 return stride; | |
1367 } | |
1368 | |
1369 | |
1245 } // namespace cc | 1370 } // namespace cc |
OLD | NEW |