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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
884 return true; | 894 return true; |
885 } | 895 } |
886 | 896 |
887 void ResourceProvider::AcquirePixelBuffer(ResourceId id) { | 897 void ResourceProvider::AcquirePixelBuffer(ResourceId id) { |
888 DCHECK(thread_checker_.CalledOnValidThread()); | 898 DCHECK(thread_checker_.CalledOnValidThread()); |
889 ResourceMap::iterator it = resources_.find(id); | 899 ResourceMap::iterator it = resources_.find(id); |
890 CHECK(it != resources_.end()); | 900 CHECK(it != resources_.end()); |
891 Resource* resource = &it->second; | 901 Resource* resource = &it->second; |
892 DCHECK(!resource->external); | 902 DCHECK(!resource->external); |
893 DCHECK(!resource->exported); | 903 DCHECK(!resource->exported); |
| 904 DCHECK(!resource->image_id); |
894 | 905 |
895 if (resource->gl_id) { | 906 if (resource->gl_id) { |
896 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 907 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
897 DCHECK(context3d); | 908 DCHECK(context3d); |
898 if (!resource->gl_pixel_buffer_id) | 909 if (!resource->gl_pixel_buffer_id) |
899 resource->gl_pixel_buffer_id = context3d->createBuffer(); | 910 resource->gl_pixel_buffer_id = context3d->createBuffer(); |
900 context3d->bindBuffer( | 911 context3d->bindBuffer( |
901 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 912 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
902 resource->gl_pixel_buffer_id); | 913 resource->gl_pixel_buffer_id); |
903 context3d->bufferData( | 914 context3d->bufferData( |
(...skipping 13 matching lines...) Expand all 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); |
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 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1262 ResourceMap::iterator it = resources_.find(id); |
| 1263 CHECK(it != resources_.end()); |
| 1264 Resource* resource = &it->second; |
| 1265 |
| 1266 DCHECK(resource->gl_id); |
| 1267 DCHECK(!resource->pixels); |
| 1268 DCHECK(!resource->external); |
| 1269 DCHECK(!resource->exported); |
| 1270 |
| 1271 if (resource->image_id != 0) { |
| 1272 // If we had previously allocated an image for this resource, |
| 1273 // release it before allocating a new one to prevent leaks. |
| 1274 ReleaseImage(id); |
| 1275 } |
| 1276 |
| 1277 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| 1278 DCHECK(context3d); |
| 1279 resource->image_id = context3d->createImageCHROMIUM( |
| 1280 resource->size.width(), resource->size.height(), GL_RGBA8_OES); |
| 1281 } |
| 1282 |
| 1283 void ResourceProvider::ReleaseImage(ResourceId id) { |
| 1284 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1285 ResourceMap::iterator it = resources_.find(id); |
| 1286 CHECK(it != resources_.end()); |
| 1287 Resource* resource = &it->second; |
| 1288 |
| 1289 DCHECK(!resource->external); |
| 1290 DCHECK(!resource->exported); |
| 1291 DCHECK(!resource->pixels); |
| 1292 |
| 1293 if (resource->image_id == 0) |
| 1294 return; |
| 1295 |
| 1296 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| 1297 DCHECK(context3d); |
| 1298 context3d->destroyImageCHROMIUM(resource->image_id); |
| 1299 resource->image_id = 0; |
| 1300 } |
| 1301 |
| 1302 uint8_t* ResourceProvider::MapImage(ResourceId id) { |
| 1303 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1304 ResourceMap::iterator it = resources_.find(id); |
| 1305 CHECK(it != resources_.end()); |
| 1306 Resource* resource = &it->second; |
| 1307 |
| 1308 DCHECK(ReadLockFenceHasPassed(resource)); |
| 1309 DCHECK(!resource->external); |
| 1310 DCHECK(!resource->exported); |
| 1311 DCHECK(!resource->pixels); |
| 1312 DCHECK(resource->image_id); |
| 1313 |
| 1314 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| 1315 DCHECK(context3d); |
| 1316 return static_cast<uint8_t*>( |
| 1317 context3d->mapImageCHROMIUM(resource->image_id, GL_READ_WRITE)); |
| 1318 } |
| 1319 |
| 1320 void ResourceProvider::UnmapImage(ResourceId id) { |
| 1321 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1322 ResourceMap::iterator it = resources_.find(id); |
| 1323 CHECK(it != resources_.end()); |
| 1324 Resource* resource = &it->second; |
| 1325 |
| 1326 DCHECK(!resource->external); |
| 1327 DCHECK(!resource->exported); |
| 1328 DCHECK(!resource->pixels); |
| 1329 DCHECK(resource->image_id); |
| 1330 |
| 1331 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| 1332 DCHECK(context3d); |
| 1333 context3d->unmapImageCHROMIUM(resource->image_id); |
| 1334 } |
| 1335 |
| 1336 void ResourceProvider::BindImage(ResourceId id) { |
| 1337 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1338 ResourceMap::iterator it = resources_.find(id); |
| 1339 CHECK(it != resources_.end()); |
| 1340 Resource* resource = &it->second; |
| 1341 |
| 1342 DCHECK(!resource->external); |
| 1343 DCHECK(!resource->exported); |
| 1344 DCHECK(!resource->pixels); |
| 1345 DCHECK(resource->image_id); |
| 1346 DCHECK(resource->gl_id); |
| 1347 |
| 1348 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| 1349 DCHECK(context3d); |
| 1350 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); |
| 1351 context3d->bindTexImage2DCHROMIUM(GL_TEXTURE_2D, resource->image_id); |
| 1352 } |
| 1353 |
| 1354 int ResourceProvider::GetImageStride(ResourceId id) { |
| 1355 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1356 ResourceMap::iterator it = resources_.find(id); |
| 1357 CHECK(it != resources_.end()); |
| 1358 Resource* resource = &it->second; |
| 1359 |
| 1360 DCHECK(!resource->external); |
| 1361 DCHECK(!resource->exported); |
| 1362 DCHECK(!resource->pixels); |
| 1363 DCHECK(resource->image_id); |
| 1364 |
| 1365 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| 1366 DCHECK(context3d); |
| 1367 int stride = 0; |
| 1368 context3d->getImageParameterivCHROMIUM( |
| 1369 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride); |
| 1370 return stride; |
| 1371 } |
| 1372 |
| 1373 |
1245 } // namespace cc | 1374 } // namespace cc |
OLD | NEW |