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

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

Issue 21159007: cc: Adding support for RGBA_4444 tile textures (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase and feedback Created 7 years, 3 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/containers/hash_tables.h" 10 #include "base/containers/hash_tables.h"
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 ResourceProvider::Resource::~Resource() {} 106 ResourceProvider::Resource::~Resource() {}
107 107
108 ResourceProvider::Resource::Resource( 108 ResourceProvider::Resource::Resource(
109 unsigned texture_id, 109 unsigned texture_id,
110 gfx::Size size, 110 gfx::Size size,
111 GLenum format, 111 GLenum format,
112 GLenum filter, 112 GLenum filter,
113 GLenum texture_pool, 113 GLenum texture_pool,
114 GLint wrap_mode, 114 GLint wrap_mode,
115 TextureUsageHint hint) 115 TextureUsageHint hint,
116 TextureType texture_type)
116 : gl_id(texture_id), 117 : gl_id(texture_id),
117 gl_pixel_buffer_id(0), 118 gl_pixel_buffer_id(0),
118 gl_upload_query_id(0), 119 gl_upload_query_id(0),
119 pixels(NULL), 120 pixels(NULL),
120 pixel_buffer(NULL), 121 pixel_buffer(NULL),
121 lock_for_read_count(0), 122 lock_for_read_count(0),
122 imported_count(0), 123 imported_count(0),
123 exported_count(0), 124 exported_count(0),
124 locked_for_write(false), 125 locked_for_write(false),
125 external(false), 126 external(false),
126 marked_for_deletion(false), 127 marked_for_deletion(false),
127 pending_set_pixels(false), 128 pending_set_pixels(false),
128 set_pixels_completion_forced(false), 129 set_pixels_completion_forced(false),
129 allocated(false), 130 allocated(false),
130 enable_read_lock_fences(false), 131 enable_read_lock_fences(false),
131 read_lock_fence(NULL), 132 read_lock_fence(NULL),
132 size(size), 133 size(size),
133 format(format), 134 format(format),
134 filter(filter), 135 filter(filter),
135 image_id(0), 136 image_id(0),
136 texture_pool(texture_pool), 137 texture_pool(texture_pool),
137 wrap_mode(wrap_mode), 138 wrap_mode(wrap_mode),
138 hint(hint), 139 hint(hint),
139 type(GLTexture) { 140 type(GLTexture),
141 texture_type(texture_type) {
140 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); 142 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT);
141 } 143 }
142 144
143 ResourceProvider::Resource::Resource( 145 ResourceProvider::Resource::Resource(
144 uint8_t* pixels, 146 uint8_t* pixels,
145 gfx::Size size, 147 gfx::Size size,
146 GLenum format, 148 GLenum format,
147 GLenum filter, 149 GLenum filter,
148 GLint wrap_mode) 150 GLint wrap_mode)
149 : gl_id(0), 151 : gl_id(0),
(...skipping 12 matching lines...) Expand all
162 allocated(false), 164 allocated(false),
163 enable_read_lock_fences(false), 165 enable_read_lock_fences(false),
164 read_lock_fence(NULL), 166 read_lock_fence(NULL),
165 size(size), 167 size(size),
166 format(format), 168 format(format),
167 filter(filter), 169 filter(filter),
168 image_id(0), 170 image_id(0),
169 texture_pool(0), 171 texture_pool(0),
170 wrap_mode(wrap_mode), 172 wrap_mode(wrap_mode),
171 hint(TextureUsageAny), 173 hint(TextureUsageAny),
172 type(Bitmap) { 174 type(Bitmap),
175 texture_type(INVALID_TYPE) {
173 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT); 176 DCHECK(wrap_mode == GL_CLAMP_TO_EDGE || wrap_mode == GL_REPEAT);
174 } 177 }
175 178
176 ResourceProvider::Child::Child() {} 179 ResourceProvider::Child::Child() {}
177 180
178 ResourceProvider::Child::~Child() {} 181 ResourceProvider::Child::~Child() {}
179 182
180 scoped_ptr<ResourceProvider> ResourceProvider::Create( 183 scoped_ptr<ResourceProvider> ResourceProvider::Create(
181 OutputSurface* output_surface, 184 OutputSurface* output_surface,
182 int highp_threshold_min) { 185 int highp_threshold_min) {
183 scoped_ptr<ResourceProvider> resource_provider( 186 scoped_ptr<ResourceProvider> resource_provider(
184 new ResourceProvider(output_surface, highp_threshold_min)); 187 new ResourceProvider(output_surface,
188 highp_threshold_min));
185 189
186 bool success = false; 190 bool success = false;
187 if (resource_provider->Context3d()) { 191 if (resource_provider->Context3d()) {
188 success = resource_provider->InitializeGL(); 192 success = resource_provider->InitializeGL();
189 } else { 193 } else {
190 resource_provider->InitializeSoftware(); 194 resource_provider->InitializeSoftware();
191 success = true; 195 success = true;
192 } 196 }
193 197
194 if (!success) 198 if (!success)
195 return scoped_ptr<ResourceProvider>(); 199 return scoped_ptr<ResourceProvider>();
196 200
197 DCHECK_NE(InvalidType, resource_provider->default_resource_type()); 201 DCHECK_NE(InvalidType, resource_provider->default_resource_type());
198 return resource_provider.Pass(); 202 return resource_provider.Pass();
199 } 203 }
200 204
201 ResourceProvider::~ResourceProvider() { 205 ResourceProvider::~ResourceProvider() {
202 while (!resources_.empty()) 206 while (!resources_.empty())
203 DeleteResourceInternal(resources_.begin(), ForShutdown); 207 DeleteResourceInternal(resources_.begin(), ForShutdown);
204 208
205 CleanUpGLIfNeeded(); 209 CleanUpGLIfNeeded();
206 } 210 }
207 211
208 bool ResourceProvider::InUseByConsumer(ResourceId id) { 212 bool ResourceProvider::InUseByConsumer(ResourceId id) {
209 Resource* resource = GetResource(id); 213 Resource* resource = GetResource(id);
210 return resource->lock_for_read_count > 0 || resource->exported_count > 0; 214 return resource->lock_for_read_count > 0 || resource->exported_count > 0;
211 } 215 }
212 216
213 ResourceProvider::ResourceId ResourceProvider::CreateResource( 217 ResourceProvider::ResourceId ResourceProvider::CreateResource(
214 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { 218 gfx::Size size,
219 GLenum format,
220 GLint wrap_mode,
221 TextureUsageHint hint,
222 TextureType texture_type) {
215 DCHECK(!size.IsEmpty()); 223 DCHECK(!size.IsEmpty());
216 switch (default_resource_type_) { 224 switch (default_resource_type_) {
217 case GLTexture: 225 case GLTexture:
218 return CreateGLTexture(size, format, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM, 226 return CreateGLTexture(size,
219 wrap_mode, hint); 227 format,
228 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM,
229 wrap_mode,
230 hint,
231 texture_type);
220 case Bitmap: 232 case Bitmap:
221 // The only wrap_mode currently implemented in software mode is 233 // The only wrap_mode currently implemented in software mode is
222 // GL_CLAMP_TO_EDGE. 234 // GL_CLAMP_TO_EDGE.
223 // http://crbug.com/284796 235 // http://crbug.com/284796
224 DCHECK(format == GL_RGBA); 236 DCHECK(format == GL_RGBA);
225 return CreateBitmap(size); 237 return CreateBitmap(size);
226 case InvalidType: 238 case InvalidType:
227 break; 239 break;
228 } 240 }
229 241
230 LOG(FATAL) << "Invalid default resource type."; 242 LOG(FATAL) << "Invalid default resource type.";
231 return 0; 243 return 0;
232 } 244 }
233 245
234 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource( 246 ResourceProvider::ResourceId ResourceProvider::CreateManagedResource(
235 gfx::Size size, GLenum format, GLint wrap_mode, TextureUsageHint hint) { 247 gfx::Size size,
248 GLenum format,
249 GLint wrap_mode,
250 TextureUsageHint hint,
251 TextureType texture_type) {
236 DCHECK(!size.IsEmpty()); 252 DCHECK(!size.IsEmpty());
237 switch (default_resource_type_) { 253 switch (default_resource_type_) {
238 case GLTexture: 254 case GLTexture:
239 return CreateGLTexture(size, format, GL_TEXTURE_POOL_MANAGED_CHROMIUM, 255 return CreateGLTexture(size,
240 wrap_mode, hint); 256 format,
257 GL_TEXTURE_POOL_MANAGED_CHROMIUM,
258 wrap_mode,
259 hint,
260 texture_type);
241 case Bitmap: 261 case Bitmap:
242 DCHECK(format == GL_RGBA); 262 DCHECK(format == GL_RGBA);
243 return CreateBitmap(size); 263 return CreateBitmap(size);
244 case InvalidType: 264 case InvalidType:
245 break; 265 break;
246 } 266 }
247 267
248 LOG(FATAL) << "Invalid default resource type."; 268 LOG(FATAL) << "Invalid default resource type.";
249 return 0; 269 return 0;
250 } 270 }
251 271
252 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture( 272 ResourceProvider::ResourceId ResourceProvider::CreateGLTexture(
253 gfx::Size size, 273 gfx::Size size,
254 GLenum format, 274 GLenum format,
255 GLenum texture_pool, 275 GLenum texture_pool,
256 GLint wrap_mode, 276 GLint wrap_mode,
257 TextureUsageHint hint) { 277 TextureUsageHint hint,
278 TextureType texture_type) {
258 DCHECK_LE(size.width(), max_texture_size_); 279 DCHECK_LE(size.width(), max_texture_size_);
259 DCHECK_LE(size.height(), max_texture_size_); 280 DCHECK_LE(size.height(), max_texture_size_);
260 DCHECK(thread_checker_.CalledOnValidThread()); 281 DCHECK(thread_checker_.CalledOnValidThread());
261 282
262 ResourceId id = next_id_++; 283 ResourceId id = next_id_++;
263 Resource resource(0, size, format, GL_LINEAR, texture_pool, wrap_mode, hint); 284 Resource resource(
285 0, size, format, GL_LINEAR, texture_pool, wrap_mode, hint, texture_type);
264 resource.allocated = false; 286 resource.allocated = false;
265 resources_[id] = resource; 287 resources_[id] = resource;
266 return id; 288 return id;
267 } 289 }
268 290
269 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) { 291 ResourceProvider::ResourceId ResourceProvider::CreateBitmap(gfx::Size size) {
270 DCHECK(thread_checker_.CalledOnValidThread()); 292 DCHECK(thread_checker_.CalledOnValidThread());
271 293
272 uint8_t* pixels = new uint8_t[4 * size.GetArea()]; 294 uint8_t* pixels = new uint8_t[4 * size.GetArea()];
273 295
(...skipping 16 matching lines...) Expand all
290 GLC(context3d, context3d->texParameteri( 312 GLC(context3d, context3d->texParameteri(
291 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR)); 313 texture_target, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
292 GLC(context3d, context3d->texParameteri( 314 GLC(context3d, context3d->texParameteri(
293 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); 315 texture_target, GL_TEXTURE_MAG_FILTER, GL_LINEAR));
294 GLC(context3d, context3d->texParameteri( 316 GLC(context3d, context3d->texParameteri(
295 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE)); 317 texture_target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
296 GLC(context3d, context3d->texParameteri( 318 GLC(context3d, context3d->texParameteri(
297 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE)); 319 texture_target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
298 320
299 ResourceId id = next_id_++; 321 ResourceId id = next_id_++;
300 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, 322 Resource resource(texture_id,
301 TextureUsageAny); 323 gfx::Size(),
324 0,
325 GL_LINEAR,
326 0,
327 GL_CLAMP_TO_EDGE,
328 TextureUsageAny,
329 INVALID_TYPE);
302 resource.external = true; 330 resource.external = true;
303 resource.allocated = true; 331 resource.allocated = true;
304 resources_[id] = resource; 332 resources_[id] = resource;
305 return id; 333 return id;
306 } 334 }
307 335
308 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( 336 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox(
309 const TextureMailbox& mailbox) { 337 const TextureMailbox& mailbox) {
310 DCHECK(thread_checker_.CalledOnValidThread()); 338 DCHECK(thread_checker_.CalledOnValidThread());
311 // Just store the information. Mailbox will be consumed in LockForRead(). 339 // Just store the information. Mailbox will be consumed in LockForRead().
312 ResourceId id = next_id_++; 340 ResourceId id = next_id_++;
313 DCHECK(mailbox.IsValid()); 341 DCHECK(mailbox.IsValid());
314 Resource& resource = resources_[id]; 342 Resource& resource = resources_[id];
315 if (mailbox.IsTexture()) { 343 if (mailbox.IsTexture()) {
316 resource = Resource(0, gfx::Size(), 0, GL_LINEAR, 0, GL_CLAMP_TO_EDGE, 344 resource = Resource(0,
317 TextureUsageAny); 345 gfx::Size(),
346 0,
347 GL_LINEAR,
348 0,
349 GL_CLAMP_TO_EDGE,
350 TextureUsageAny,
351 INVALID_TYPE);
318 } else { 352 } else {
319 DCHECK(mailbox.IsSharedMemory()); 353 DCHECK(mailbox.IsSharedMemory());
320 base::SharedMemory* shared_memory = mailbox.shared_memory(); 354 base::SharedMemory* shared_memory = mailbox.shared_memory();
321 DCHECK(shared_memory->memory()); 355 DCHECK(shared_memory->memory());
322 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory()); 356 uint8_t* pixels = reinterpret_cast<uint8_t*>(shared_memory->memory());
323 resource = Resource(pixels, mailbox.shared_memory_size(), 357 resource = Resource(pixels, mailbox.shared_memory_size(),
324 GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE); 358 GL_RGBA, GL_LINEAR, GL_CLAMP_TO_EDGE);
325 } 359 }
326 resource.external = true; 360 resource.external = true;
327 resource.allocated = true; 361 resource.allocated = true;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 DCHECK(!resource->pending_set_pixels); 460 DCHECK(!resource->pending_set_pixels);
427 WebGraphicsContext3D* context3d = Context3d(); 461 WebGraphicsContext3D* context3d = Context3d();
428 DCHECK(context3d); 462 DCHECK(context3d);
429 DCHECK(texture_uploader_.get()); 463 DCHECK(texture_uploader_.get());
430 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); 464 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
431 texture_uploader_->Upload(image, 465 texture_uploader_->Upload(image,
432 image_rect, 466 image_rect,
433 source_rect, 467 source_rect,
434 dest_offset, 468 dest_offset,
435 resource->format, 469 resource->format,
436 resource->size); 470 resource->size,
471 resource->texture_type);
437 } 472 }
438 473
439 if (resource->pixels) { 474 if (resource->pixels) {
440 DCHECK(resource->allocated); 475 DCHECK(resource->allocated);
441 DCHECK(resource->format == GL_RGBA); 476 DCHECK(resource->format == GL_RGBA);
442 SkBitmap src_full; 477 SkBitmap src_full;
443 src_full.setConfig( 478 src_full.setConfig(
444 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height()); 479 SkBitmap::kARGB_8888_Config, image_rect.width(), image_rect.height());
445 src_full.setPixels(const_cast<uint8_t*>(image)); 480 src_full.setPixels(const_cast<uint8_t*>(image));
446 SkBitmap src_subset; 481 SkBitmap src_subset;
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 const ContextProvider::Capabilities& caps = 774 const ContextProvider::Capabilities& caps =
740 output_surface_->context_provider()->ContextCapabilities(); 775 output_surface_->context_provider()->ContextCapabilities();
741 776
742 bool use_map_sub = caps.map_sub; 777 bool use_map_sub = caps.map_sub;
743 bool use_bgra = caps.texture_format_bgra8888; 778 bool use_bgra = caps.texture_format_bgra8888;
744 use_texture_storage_ext_ = caps.texture_storage; 779 use_texture_storage_ext_ = caps.texture_storage;
745 use_shallow_flush_ = caps.shallow_flush; 780 use_shallow_flush_ = caps.shallow_flush;
746 use_texture_usage_hint_ = caps.texture_usage; 781 use_texture_usage_hint_ = caps.texture_usage;
747 782
748 texture_uploader_ = 783 texture_uploader_ =
749 TextureUploader::Create(context3d, use_map_sub, use_shallow_flush_); 784 TextureUploader::Create(context3d,
785 use_map_sub,
786 use_shallow_flush_);
750 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE, 787 GLC(context3d, context3d->getIntegerv(GL_MAX_TEXTURE_SIZE,
751 &max_texture_size_)); 788 &max_texture_size_));
752 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra); 789 best_texture_format_ = PlatformColor::BestTextureFormat(use_bgra);
753 790
754 return true; 791 return true;
755 } 792 }
756 793
757 void ResourceProvider::CleanUpGLIfNeeded() { 794 void ResourceProvider::CleanUpGLIfNeeded() {
758 WebGraphicsContext3D* context3d = Context3d(); 795 WebGraphicsContext3D* context3d = Context3d();
759 if (default_resource_type_ != GLTexture) { 796 if (default_resource_type_ != GLTexture) {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 // However if the parent is a renderer (e.g. browser tag), it may be ok 941 // However if the parent is a renderer (e.g. browser tag), it may be ok
905 // (and is simpler) to wait. 942 // (and is simpler) to wait.
906 if (it->sync_point) 943 if (it->sync_point)
907 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); 944 GLC(context3d, context3d->waitSyncPoint(it->sync_point));
908 GLC(context3d, texture_id = context3d->createTexture()); 945 GLC(context3d, texture_id = context3d->createTexture());
909 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id)); 946 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, texture_id));
910 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, 947 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D,
911 it->mailbox.name)); 948 it->mailbox.name));
912 ResourceId id = next_id_++; 949 ResourceId id = next_id_++;
913 Resource resource( 950 Resource resource(
914 texture_id, it->size, it->format, it->filter, 0, GL_CLAMP_TO_EDGE, 951 texture_id,
915 TextureUsageAny); 952 it->size,
953 it->format,
954 it->filter,
955 0,
956 GL_CLAMP_TO_EDGE,
957 TextureUsageAny,
958 static_cast<TextureType>(it->texture_type));
916 resource.mailbox.SetName(it->mailbox); 959 resource.mailbox.SetName(it->mailbox);
917 // Don't allocate a texture for a child. 960 // Don't allocate a texture for a child.
918 resource.allocated = true; 961 resource.allocated = true;
919 resource.imported_count = 1; 962 resource.imported_count = 1;
920 resources_[id] = resource; 963 resources_[id] = resource;
921 child_info.parent_to_child_map[id] = it->id; 964 child_info.parent_to_child_map[id] = it->id;
922 child_info.child_to_parent_map[it->id] = id; 965 child_info.child_to_parent_map[it->id] = id;
923 } 966 }
924 } 967 }
925 968
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
960 TransferableResource* resource) { 1003 TransferableResource* resource) {
961 Resource* source = GetResource(id); 1004 Resource* source = GetResource(id);
962 DCHECK(!source->locked_for_write); 1005 DCHECK(!source->locked_for_write);
963 DCHECK(!source->lock_for_read_count); 1006 DCHECK(!source->lock_for_read_count);
964 DCHECK(!source->external || (source->external && source->mailbox.IsValid())); 1007 DCHECK(!source->external || (source->external && source->mailbox.IsValid()));
965 DCHECK(source->allocated); 1008 DCHECK(source->allocated);
966 resource->id = id; 1009 resource->id = id;
967 resource->format = source->format; 1010 resource->format = source->format;
968 resource->filter = source->filter; 1011 resource->filter = source->filter;
969 resource->size = source->size; 1012 resource->size = source->size;
1013 resource->texture_type = source->texture_type;
970 1014
971 // TODO(skaslev) Implement this path for shared memory resources. 1015 // TODO(skaslev) Implement this path for shared memory resources.
972 DCHECK(!source->mailbox.IsSharedMemory()); 1016 DCHECK(!source->mailbox.IsSharedMemory());
973 1017
974 if (!source->mailbox.IsTexture()) { 1018 if (!source->mailbox.IsTexture()) {
975 // This is a resource allocated by the compositor, we need to produce it. 1019 // This is a resource allocated by the compositor, we need to produce it.
976 // Don't set a sync point, the caller will do it. 1020 // Don't set a sync point, the caller will do it.
977 DCHECK(source->gl_id); 1021 DCHECK(source->gl_id);
978 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id)); 1022 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id));
979 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name)); 1023 GLC(context, context->genMailboxCHROMIUM(resource->mailbox.name));
(...skipping 16 matching lines...) Expand all
996 DCHECK(!resource->image_id); 1040 DCHECK(!resource->image_id);
997 1041
998 if (resource->type == GLTexture) { 1042 if (resource->type == GLTexture) {
999 WebGraphicsContext3D* context3d = Context3d(); 1043 WebGraphicsContext3D* context3d = Context3d();
1000 DCHECK(context3d); 1044 DCHECK(context3d);
1001 if (!resource->gl_pixel_buffer_id) 1045 if (!resource->gl_pixel_buffer_id)
1002 resource->gl_pixel_buffer_id = context3d->createBuffer(); 1046 resource->gl_pixel_buffer_id = context3d->createBuffer();
1003 context3d->bindBuffer( 1047 context3d->bindBuffer(
1004 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1048 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1005 resource->gl_pixel_buffer_id); 1049 resource->gl_pixel_buffer_id);
1050 size_t bytes_per_pixel =
1051 BytesPerPixel(best_texture_format_, resource->texture_type);
1006 context3d->bufferData( 1052 context3d->bufferData(
1007 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1053 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1008 4 * resource->size.GetArea(), 1054 bytes_per_pixel * resource->size.GetArea(),
1009 NULL, 1055 NULL,
1010 GL_DYNAMIC_DRAW); 1056 GL_DYNAMIC_DRAW);
1011 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1057 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1012 } 1058 }
1013 1059
1014 if (resource->pixels) { 1060 if (resource->pixels) {
1015 if (resource->pixel_buffer) 1061 if (resource->pixel_buffer)
1016 return; 1062 return;
1017 1063
1018 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()]; 1064 resource->pixel_buffer = new uint8_t[4 * resource->size.GetArea()];
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 DCHECK(resource->gl_pixel_buffer_id); 1215 DCHECK(resource->gl_pixel_buffer_id);
1170 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id); 1216 context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id);
1171 context3d->bindBuffer( 1217 context3d->bindBuffer(
1172 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1218 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1173 resource->gl_pixel_buffer_id); 1219 resource->gl_pixel_buffer_id);
1174 if (!resource->gl_upload_query_id) 1220 if (!resource->gl_upload_query_id)
1175 resource->gl_upload_query_id = context3d->createQueryEXT(); 1221 resource->gl_upload_query_id = context3d->createQueryEXT();
1176 context3d->beginQueryEXT( 1222 context3d->beginQueryEXT(
1177 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, 1223 GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM,
1178 resource->gl_upload_query_id); 1224 resource->gl_upload_query_id);
1225 GLenum texture_data_type = GetTextureDataType(resource->texture_type);
1179 if (allocate) { 1226 if (allocate) {
1180 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D, 1227 context3d->asyncTexImage2DCHROMIUM(GL_TEXTURE_2D,
1181 0, /* level */ 1228 0, /* level */
1182 resource->format, 1229 resource->format,
1183 resource->size.width(), 1230 resource->size.width(),
1184 resource->size.height(), 1231 resource->size.height(),
1185 0, /* border */ 1232 0, /* border */
1186 resource->format, 1233 resource->format,
1187 GL_UNSIGNED_BYTE, 1234 texture_data_type,
1188 NULL); 1235 NULL);
1189 } else { 1236 } else {
1190 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D, 1237 context3d->asyncTexSubImage2DCHROMIUM(GL_TEXTURE_2D,
1191 0, /* level */ 1238 0, /* level */
1192 0, /* x */ 1239 0, /* x */
1193 0, /* y */ 1240 0, /* y */
1194 resource->size.width(), 1241 resource->size.width(),
1195 resource->size.height(), 1242 resource->size.height(),
1196 resource->format, 1243 resource->format,
1197 GL_UNSIGNED_BYTE, 1244 texture_data_type,
1198 NULL); 1245 NULL);
1199 } 1246 }
1200 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM); 1247 context3d->endQueryEXT(GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM);
1201 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1248 context3d->bindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1202 } 1249 }
1203 1250
1204 if (resource->pixels) { 1251 if (resource->pixels) {
1205 DCHECK(!resource->mailbox.IsValid()); 1252 DCHECK(!resource->mailbox.IsValid());
1206 DCHECK(resource->pixel_buffer); 1253 DCHECK(resource->pixel_buffer);
1207 DCHECK(resource->format == GL_RGBA); 1254 DCHECK(resource->format == GL_RGBA);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 size.width(), 1367 size.width(),
1321 size.height())); 1368 size.height()));
1322 } else { 1369 } else {
1323 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D, 1370 GLC(context3d, context3d->texImage2D(GL_TEXTURE_2D,
1324 0, 1371 0,
1325 format, 1372 format,
1326 size.width(), 1373 size.width(),
1327 size.height(), 1374 size.height(),
1328 0, 1375 0,
1329 format, 1376 format,
1330 GL_UNSIGNED_BYTE, 1377 GetTextureDataType(
1378 resource->texture_type),
1331 NULL)); 1379 NULL));
1332 } 1380 }
1333 } 1381 }
1334 1382
1335 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, 1383 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id,
1336 bool enable) { 1384 bool enable) {
1337 Resource* resource = GetResource(id); 1385 Resource* resource = GetResource(id);
1338 resource->enable_read_lock_fences = enable; 1386 resource->enable_read_lock_fences = enable;
1339 } 1387 }
1340 1388
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1425 GLint active_unit = 0; 1473 GLint active_unit = 0;
1426 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit); 1474 context->getIntegerv(GL_ACTIVE_TEXTURE, &active_unit);
1427 return active_unit; 1475 return active_unit;
1428 } 1476 }
1429 1477
1430 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const { 1478 WebKit::WebGraphicsContext3D* ResourceProvider::Context3d() const {
1431 ContextProvider* context_provider = output_surface_->context_provider(); 1479 ContextProvider* context_provider = output_surface_->context_provider();
1432 return context_provider ? context_provider->Context3d() : NULL; 1480 return context_provider ? context_provider->Context3d() : NULL;
1433 } 1481 }
1434 1482
1483 size_t ResourceProvider::BytesPerPixel(GLenum format, TextureType type) {
1484 size_t components_per_pixel = 0;
1485 switch (format) {
1486 case GL_RGBA:
1487 components_per_pixel = 4;
1488 break;
1489 case GL_BGRA_EXT:
1490 components_per_pixel = 4;
1491 break;
1492 case GL_LUMINANCE:
1493 components_per_pixel = 1;
1494 break;
1495 default:
1496 NOTREACHED();
1497 }
1498 size_t bits_per_component = 0;
1499 switch (type) {
1500 case RGBA_8888:
1501 case BGRA_8888:
1502 bits_per_component = 8;
1503 break;
1504 case RGBA_4444:
1505 bits_per_component = 4;
1506 break;
1507 default:
1508 NOTREACHED();
1509 }
1510 const size_t kBitsPerByte = 8;
1511 return (components_per_pixel * bits_per_component) / kBitsPerByte;
1512 }
1513
1514 GLenum ResourceProvider::GetTextureDataType(GLenum texture_type) {
1515 GLenum texture_data_type = GL_UNSIGNED_BYTE;
1516 switch (texture_type) {
1517 case RGBA_4444:
1518 texture_data_type = GL_UNSIGNED_SHORT_4_4_4_4;
1519 break;
1520 case RGBA_8888:
1521 texture_data_type = GL_UNSIGNED_BYTE;
1522 break;
1523 default:
1524 NOTREACHED();
1525 break;
1526 }
1527 return texture_data_type;
1528 }
1529
1435 } // namespace cc 1530 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698