Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: cc/resources/resource_provider.cc

Issue 14409006: cc: Changes to use GL API for GpuMemoryBuffers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@glapi
Patch Set: Incorporate code reviews Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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
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);
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 12 matching lines...) Expand all
884 return true; 895 return true;
885 } 896 }
886 897
887 void ResourceProvider::AcquirePixelBuffer(ResourceId id) { 898 void ResourceProvider::AcquirePixelBuffer(ResourceId id) {
888 DCHECK(thread_checker_.CalledOnValidThread()); 899 DCHECK(thread_checker_.CalledOnValidThread());
889 ResourceMap::iterator it = resources_.find(id); 900 ResourceMap::iterator it = resources_.find(id);
890 CHECK(it != resources_.end()); 901 CHECK(it != resources_.end());
891 Resource* resource = &it->second; 902 Resource* resource = &it->second;
892 DCHECK(!resource->external); 903 DCHECK(!resource->external);
893 DCHECK(!resource->exported); 904 DCHECK(!resource->exported);
905 DCHECK(!resource->image_id);
894 906
895 if (resource->gl_id) { 907 if (resource->gl_id) {
896 WebGraphicsContext3D* context3d = output_surface_->context3d(); 908 WebGraphicsContext3D* context3d = output_surface_->context3d();
897 DCHECK(context3d); 909 DCHECK(context3d);
898 if (!resource->gl_pixel_buffer_id) 910 if (!resource->gl_pixel_buffer_id)
899 resource->gl_pixel_buffer_id = context3d->createBuffer(); 911 resource->gl_pixel_buffer_id = context3d->createBuffer();
900 context3d->bindBuffer( 912 context3d->bindBuffer(
901 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 913 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
902 resource->gl_pixel_buffer_id); 914 resource->gl_pixel_buffer_id);
903 context3d->bufferData( 915 context3d->bufferData(
(...skipping 13 matching lines...) Expand all
917 } 929 }
918 } 930 }
919 931
920 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { 932 void ResourceProvider::ReleasePixelBuffer(ResourceId id) {
921 DCHECK(thread_checker_.CalledOnValidThread()); 933 DCHECK(thread_checker_.CalledOnValidThread());
922 ResourceMap::iterator it = resources_.find(id); 934 ResourceMap::iterator it = resources_.find(id);
923 CHECK(it != resources_.end()); 935 CHECK(it != resources_.end());
924 Resource* resource = &it->second; 936 Resource* resource = &it->second;
925 DCHECK(!resource->external); 937 DCHECK(!resource->external);
926 DCHECK(!resource->exported); 938 DCHECK(!resource->exported);
939 DCHECK(!resource->image_id);
927 940
928 if (resource->gl_id) { 941 if (resource->gl_id) {
929 if (!resource->gl_pixel_buffer_id) 942 if (!resource->gl_pixel_buffer_id)
930 return; 943 return;
931 WebGraphicsContext3D* context3d = output_surface_->context3d(); 944 WebGraphicsContext3D* context3d = output_surface_->context3d();
932 DCHECK(context3d); 945 DCHECK(context3d);
933 context3d->bindBuffer( 946 context3d->bindBuffer(
934 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 947 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
935 resource->gl_pixel_buffer_id); 948 resource->gl_pixel_buffer_id);
936 context3d->bufferData( 949 context3d->bufferData(
(...skipping 12 matching lines...) Expand all
949 } 962 }
950 } 963 }
951 964
952 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) { 965 uint8_t* ResourceProvider::MapPixelBuffer(ResourceId id) {
953 DCHECK(thread_checker_.CalledOnValidThread()); 966 DCHECK(thread_checker_.CalledOnValidThread());
954 ResourceMap::iterator it = resources_.find(id); 967 ResourceMap::iterator it = resources_.find(id);
955 CHECK(it != resources_.end()); 968 CHECK(it != resources_.end());
956 Resource* resource = &it->second; 969 Resource* resource = &it->second;
957 DCHECK(!resource->external); 970 DCHECK(!resource->external);
958 DCHECK(!resource->exported); 971 DCHECK(!resource->exported);
972 DCHECK(!resource->image_id);
959 973
960 if (resource->gl_id) { 974 if (resource->gl_id) {
961 WebGraphicsContext3D* context3d = output_surface_->context3d(); 975 WebGraphicsContext3D* context3d = output_surface_->context3d();
962 DCHECK(context3d); 976 DCHECK(context3d);
963 DCHECK(resource->gl_pixel_buffer_id); 977 DCHECK(resource->gl_pixel_buffer_id);
964 context3d->bindBuffer( 978 context3d->bindBuffer(
965 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 979 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
966 resource->gl_pixel_buffer_id); 980 resource->gl_pixel_buffer_id);
967 uint8_t* image = static_cast<uint8_t*>( 981 uint8_t* image = static_cast<uint8_t*>(
968 context3d->mapBufferCHROMIUM( 982 context3d->mapBufferCHROMIUM(
969 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY)); 983 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, GL_WRITE_ONLY));
970 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 984 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
971 return image; 985 return image;
972 } 986 }
973 987
974 if (resource->pixels) 988 if (resource->pixels)
975 return resource->pixel_buffer; 989 return resource->pixel_buffer;
976 990
977 return NULL; 991 return NULL;
978 } 992 }
979 993
980 void ResourceProvider::UnmapPixelBuffer(ResourceId id) { 994 void ResourceProvider::UnmapPixelBuffer(ResourceId id) {
981 DCHECK(thread_checker_.CalledOnValidThread()); 995 DCHECK(thread_checker_.CalledOnValidThread());
982 ResourceMap::iterator it = resources_.find(id); 996 ResourceMap::iterator it = resources_.find(id);
983 CHECK(it != resources_.end()); 997 CHECK(it != resources_.end());
984 Resource* resource = &it->second; 998 Resource* resource = &it->second;
985 DCHECK(!resource->external); 999 DCHECK(!resource->external);
986 DCHECK(!resource->exported); 1000 DCHECK(!resource->exported);
1001 DCHECK(!resource->image_id);
987 1002
988 if (resource->gl_id) { 1003 if (resource->gl_id) {
989 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1004 WebGraphicsContext3D* context3d = output_surface_->context3d();
990 DCHECK(context3d); 1005 DCHECK(context3d);
991 DCHECK(resource->gl_pixel_buffer_id); 1006 DCHECK(resource->gl_pixel_buffer_id);
992 context3d->bindBuffer( 1007 context3d->bindBuffer(
993 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1008 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
994 resource->gl_pixel_buffer_id); 1009 resource->gl_pixel_buffer_id);
995 context3d->unmapBufferCHROMIUM( 1010 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); 1011 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
998 } 1012 }
999 } 1013 }
1000 1014
1001 void ResourceProvider::SetPixelsFromBuffer(ResourceId id) { 1015 void ResourceProvider::SetPixelsFromBuffer(ResourceId id) {
1002 DCHECK(thread_checker_.CalledOnValidThread()); 1016 DCHECK(thread_checker_.CalledOnValidThread());
1003 ResourceMap::iterator it = resources_.find(id); 1017 ResourceMap::iterator it = resources_.find(id);
1004 CHECK(it != resources_.end()); 1018 CHECK(it != resources_.end());
1005 Resource* resource = &it->second; 1019 Resource* resource = &it->second;
1006 DCHECK(!resource->locked_for_write); 1020 DCHECK(!resource->locked_for_write);
1007 DCHECK(!resource->lock_for_read_count); 1021 DCHECK(!resource->lock_for_read_count);
1008 DCHECK(!resource->external); 1022 DCHECK(!resource->external);
1009 DCHECK(!resource->exported); 1023 DCHECK(!resource->exported);
1010 DCHECK(ReadLockFenceHasPassed(resource)); 1024 DCHECK(ReadLockFenceHasPassed(resource));
1025 DCHECK(!resource->image_id);
1011 LazyAllocate(resource); 1026 LazyAllocate(resource);
1012 1027
1013 if (resource->gl_id) { 1028 if (resource->gl_id) {
1014 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1029 WebGraphicsContext3D* context3d = output_surface_->context3d();
1015 DCHECK(context3d); 1030 DCHECK(context3d);
1016 DCHECK(resource->gl_pixel_buffer_id); 1031 DCHECK(resource->gl_pixel_buffer_id);
1017 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); 1032 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
1018 context3d->bindBuffer( 1033 context3d->bindBuffer(
1019 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1034 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1020 resource->gl_pixel_buffer_id); 1035 resource->gl_pixel_buffer_id);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 } 1081 }
1067 1082
1068 void ResourceProvider::BeginSetPixels(ResourceId id) { 1083 void ResourceProvider::BeginSetPixels(ResourceId id) {
1069 DCHECK(thread_checker_.CalledOnValidThread()); 1084 DCHECK(thread_checker_.CalledOnValidThread());
1070 ResourceMap::iterator it = resources_.find(id); 1085 ResourceMap::iterator it = resources_.find(id);
1071 CHECK(it != resources_.end()); 1086 CHECK(it != resources_.end());
1072 Resource* resource = &it->second; 1087 Resource* resource = &it->second;
1073 DCHECK(!resource->pending_set_pixels); 1088 DCHECK(!resource->pending_set_pixels);
1074 DCHECK(resource->gl_id || resource->allocated); 1089 DCHECK(resource->gl_id || resource->allocated);
1075 DCHECK(ReadLockFenceHasPassed(resource)); 1090 DCHECK(ReadLockFenceHasPassed(resource));
1091 DCHECK(!resource->image_id);
1076 1092
1077 bool allocate = !resource->allocated; 1093 bool allocate = !resource->allocated;
1078 resource->allocated = true; 1094 resource->allocated = true;
1079 LockForWrite(id); 1095 LockForWrite(id);
1080 1096
1081 if (resource->gl_id) { 1097 if (resource->gl_id) {
1082 WebGraphicsContext3D* context3d = output_surface_->context3d(); 1098 WebGraphicsContext3D* context3d = output_surface_->context3d();
1083 DCHECK(context3d); 1099 DCHECK(context3d);
1084 DCHECK(resource->gl_pixel_buffer_id); 1100 DCHECK(resource->gl_pixel_buffer_id);
1085 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); 1101 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
1235 1251
1236 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, 1252 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id,
1237 bool enable) { 1253 bool enable) {
1238 DCHECK(thread_checker_.CalledOnValidThread()); 1254 DCHECK(thread_checker_.CalledOnValidThread());
1239 ResourceMap::iterator it = resources_.find(id); 1255 ResourceMap::iterator it = resources_.find(id);
1240 CHECK(it != resources_.end()); 1256 CHECK(it != resources_.end());
1241 Resource* resource = &it->second; 1257 Resource* resource = &it->second;
1242 resource->enable_read_lock_fences = enable; 1258 resource->enable_read_lock_fences = enable;
1243 } 1259 }
1244 1260
1261 void ResourceProvider::AcquireImage(ResourceId id) {
1262 // TODO(kaanb): Should we delay glGenTextures to this method as well?
1263 DCHECK(thread_checker_.CalledOnValidThread());
1264 ResourceMap::iterator it = resources_.find(id);
1265 CHECK(it != resources_.end());
1266 Resource* resource = &it->second;
1267
1268 DCHECK(resource->gl_id);
1269 DCHECK(!resource->pixels);
1270 DCHECK(!resource->external);
1271 DCHECK(!resource->exported);
1272 DCHECK_EQ(0u, resource->image_id);
1273
1274 WebGraphicsContext3D* context3d = output_surface_->context3d();
1275 DCHECK(context3d);
1276 resource->image_id = context3d->createImageCHROMIUM(
1277 resource->size.width(), resource->size.height(), GL_RGBA8_OES);
1278 }
1279
1280 void ResourceProvider::ReleaseImage(ResourceId id) {
1281 // TODO(kaanb): CalledOnValidThread() will not be called if we're not in debug
1282 // mode is it intentional?
1283 DCHECK(thread_checker_.CalledOnValidThread());
1284 ResourceMap::iterator it = resources_.find(id);
1285 CHECK(it != resources_.end());
1286 Resource* resource = &it->second;
1287
1288 DCHECK(!resource->external);
1289 DCHECK(!resource->exported);
1290 DCHECK(!resource->pixels);
1291 DCHECK(resource->image_id);
1292
1293 WebGraphicsContext3D* context3d = output_surface_->context3d();
1294 DCHECK(context3d);
1295 context3d->destroyImageCHROMIUM(resource->image_id);
1296 resource->image_id = 0;
1297 }
1298
1299 uint8_t* ResourceProvider::MapImage(ResourceId id) {
1300 DCHECK(thread_checker_.CalledOnValidThread());
1301 ResourceMap::iterator it = resources_.find(id);
1302 CHECK(it != resources_.end());
1303 Resource* resource = &it->second;
1304
1305 DCHECK(ReadLockFenceHasPassed(resource));
1306 DCHECK(!resource->external);
1307 DCHECK(!resource->exported);
1308 DCHECK(!resource->pixels);
1309 DCHECK(resource->image_id);
1310
1311 WebGraphicsContext3D* context3d = output_surface_->context3d();
1312 DCHECK(context3d);
1313 return static_cast<uint8_t*>(
1314 context3d->mapImageCHROMIUM(resource->image_id, GL_READ_WRITE));
1315 }
1316
1317 void ResourceProvider::UnmapImage(ResourceId id) {
1318 DCHECK(thread_checker_.CalledOnValidThread());
1319 ResourceMap::iterator it = resources_.find(id);
1320 CHECK(it != resources_.end());
1321 Resource* resource = &it->second;
1322
1323 DCHECK(!resource->external);
1324 DCHECK(!resource->exported);
1325 DCHECK(!resource->pixels);
1326 DCHECK(resource->image_id);
1327
1328 WebGraphicsContext3D* context3d = output_surface_->context3d();
1329 DCHECK(context3d);
1330 context3d->unmapImageCHROMIUM(resource->image_id);
1331 }
1332
1333 void ResourceProvider::BindImage(ResourceId id) {
1334 DCHECK(thread_checker_.CalledOnValidThread());
1335 ResourceMap::iterator it = resources_.find(id);
1336 CHECK(it != resources_.end());
1337 Resource* resource = &it->second;
1338
1339 DCHECK(!resource->external);
1340 DCHECK(!resource->exported);
1341 DCHECK(!resource->pixels);
1342 DCHECK(resource->image_id);
1343 DCHECK(resource->gl_id);
1344
1345 // TODO(kaanb): Do we need ReadLockFenceHasPassed and/or LockForWrite()
1346 WebGraphicsContext3D* context3d = output_surface_->context3d();
1347 DCHECK(context3d);
1348 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
1349 context3d->bindTexImage2DCHROMIUM(GL_TEXTURE_2D, resource->image_id);
1350 }
1351
1352 int ResourceProvider::GetImageStride(ResourceId id) {
1353 DCHECK(thread_checker_.CalledOnValidThread());
1354 ResourceMap::iterator it = resources_.find(id);
1355 CHECK(it != resources_.end());
1356 Resource* resource = &it->second;
1357
1358 DCHECK(!resource->external);
1359 DCHECK(!resource->exported);
1360 DCHECK(!resource->pixels);
1361 DCHECK(resource->image_id);
1362
1363 WebGraphicsContext3D* context3d = output_surface_->context3d();
1364 DCHECK(context3d);
1365 int stride = 0;
1366 context3d->getImageParameterivCHROMIUM(
1367 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride);
1368 return stride;
1369 }
1370
1371
1245 } // namespace cc 1372 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698