Chromium Code Reviews| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 locked_for_write(false), | 76 locked_for_write(false), |
| 77 external(false), | 77 external(false), |
| 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 shared_memory(NULL), | |
| 86 format(0), | 87 format(0), |
| 87 filter(0), | 88 filter(0), |
| 88 image_id(0), | 89 image_id(0), |
| 89 type(static_cast<ResourceType>(0)) {} | 90 type(static_cast<ResourceType>(0)) {} |
| 90 | 91 |
| 91 ResourceProvider::Resource::~Resource() {} | 92 ResourceProvider::Resource::~Resource() {} |
| 92 | 93 |
| 93 ResourceProvider::Resource::Resource( | 94 ResourceProvider::Resource::Resource( |
| 94 unsigned texture_id, gfx::Size size, GLenum format, GLenum filter) | 95 unsigned texture_id, gfx::Size size, GLenum format, GLenum filter) |
| 95 : gl_id(texture_id), | 96 : gl_id(texture_id), |
| 96 gl_pixel_buffer_id(0), | 97 gl_pixel_buffer_id(0), |
| 97 gl_upload_query_id(0), | 98 gl_upload_query_id(0), |
| 98 pixels(NULL), | 99 pixels(NULL), |
| 99 pixel_buffer(NULL), | 100 pixel_buffer(NULL), |
| 100 lock_for_read_count(0), | 101 lock_for_read_count(0), |
| 101 locked_for_write(false), | 102 locked_for_write(false), |
| 102 external(false), | 103 external(false), |
| 103 exported(false), | 104 exported(false), |
| 104 marked_for_deletion(false), | 105 marked_for_deletion(false), |
| 105 pending_set_pixels(false), | 106 pending_set_pixels(false), |
| 106 set_pixels_completion_forced(false), | 107 set_pixels_completion_forced(false), |
| 107 allocated(false), | 108 allocated(false), |
| 108 enable_read_lock_fences(false), | 109 enable_read_lock_fences(false), |
| 109 read_lock_fence(NULL), | 110 read_lock_fence(NULL), |
| 110 size(size), | 111 size(size), |
| 112 shared_memory(NULL), | |
| 111 format(format), | 113 format(format), |
| 112 filter(filter), | 114 filter(filter), |
| 113 image_id(0), | 115 image_id(0), |
| 114 type(GLTexture) {} | 116 type(GLTexture) {} |
| 115 | 117 |
| 116 ResourceProvider::Resource::Resource( | 118 ResourceProvider::Resource::Resource( |
| 117 uint8_t* pixels, gfx::Size size, GLenum format, GLenum filter) | 119 uint8_t* pixels, gfx::Size size, GLenum format, GLenum filter) |
| 118 : gl_id(0), | 120 : gl_id(0), |
| 119 gl_pixel_buffer_id(0), | 121 gl_pixel_buffer_id(0), |
| 120 gl_upload_query_id(0), | 122 gl_upload_query_id(0), |
| 121 pixels(pixels), | 123 pixels(pixels), |
| 122 pixel_buffer(NULL), | 124 pixel_buffer(NULL), |
| 123 lock_for_read_count(0), | 125 lock_for_read_count(0), |
| 124 locked_for_write(false), | 126 locked_for_write(false), |
| 125 external(false), | 127 external(false), |
| 126 exported(false), | 128 exported(false), |
| 127 marked_for_deletion(false), | 129 marked_for_deletion(false), |
| 128 pending_set_pixels(false), | 130 pending_set_pixels(false), |
| 129 set_pixels_completion_forced(false), | 131 set_pixels_completion_forced(false), |
| 130 allocated(false), | 132 allocated(false), |
| 131 enable_read_lock_fences(false), | 133 enable_read_lock_fences(false), |
| 132 read_lock_fence(NULL), | 134 read_lock_fence(NULL), |
| 133 size(size), | 135 size(size), |
| 136 shared_memory(NULL), | |
| 134 format(format), | 137 format(format), |
| 135 filter(filter), | 138 filter(filter), |
| 136 image_id(0), | 139 image_id(0), |
| 137 type(Bitmap) {} | 140 type(Bitmap) {} |
| 138 | 141 |
| 139 ResourceProvider::Child::Child() {} | 142 ResourceProvider::Child::Child() {} |
| 140 | 143 |
| 141 ResourceProvider::Child::~Child() {} | 144 ResourceProvider::Child::~Child() {} |
| 142 | 145 |
| 143 scoped_ptr<ResourceProvider> ResourceProvider::Create( | 146 scoped_ptr<ResourceProvider> ResourceProvider::Create( |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 269 resource.allocated = true; | 272 resource.allocated = true; |
| 270 resources_[id] = resource; | 273 resources_[id] = resource; |
| 271 return id; | 274 return id; |
| 272 } | 275 } |
| 273 | 276 |
| 274 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 277 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
| 275 const TextureMailbox& mailbox) { | 278 const TextureMailbox& mailbox) { |
| 276 DCHECK(thread_checker_.CalledOnValidThread()); | 279 DCHECK(thread_checker_.CalledOnValidThread()); |
| 277 // Just store the information. Mailbox will be consumed in LockForRead(). | 280 // Just store the information. Mailbox will be consumed in LockForRead(). |
| 278 ResourceId id = next_id_++; | 281 ResourceId id = next_id_++; |
| 279 unsigned texture_id = 0; | 282 if (mailbox.IsTexture()) { |
|
piman
2013/05/28 20:58:57
nit: I think we should DCHECK that the mailbox IsV
slavi
2013/05/29 18:31:48
Done.
| |
| 280 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR); | 283 unsigned texture_id = 0; |
| 281 resource.external = true; | 284 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR); |
| 282 resource.allocated = true; | 285 resource.external = true; |
| 283 resource.mailbox = mailbox; | 286 resource.allocated = true; |
| 284 resources_[id] = resource; | 287 resource.mailbox = mailbox; |
| 288 resources_[id] = resource; | |
| 289 } else if (mailbox.IsSharedMemory()) { | |
| 290 uint8_t *pixels = NULL; | |
| 291 Resource resource(pixels, mailbox.size(), 0, GL_LINEAR); | |
| 292 resource.external = true; | |
| 293 resource.allocated = true; | |
| 294 resource.mailbox = mailbox; | |
| 295 resources_[id] = resource; | |
| 296 } | |
| 285 return id; | 297 return id; |
| 286 } | 298 } |
| 287 | 299 |
| 288 void ResourceProvider::DeleteResource(ResourceId id) { | 300 void ResourceProvider::DeleteResource(ResourceId id) { |
| 289 DCHECK(thread_checker_.CalledOnValidThread()); | 301 DCHECK(thread_checker_.CalledOnValidThread()); |
| 290 ResourceMap::iterator it = resources_.find(id); | 302 ResourceMap::iterator it = resources_.find(id); |
| 291 CHECK(it != resources_.end()); | 303 CHECK(it != resources_.end()); |
| 292 Resource* resource = &it->second; | 304 Resource* resource = &it->second; |
| 293 DCHECK(!resource->lock_for_read_count); | 305 DCHECK(!resource->lock_for_read_count); |
| 294 DCHECK(!resource->marked_for_deletion); | 306 DCHECK(!resource->marked_for_deletion); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 325 if (resource->gl_upload_query_id) { | 337 if (resource->gl_upload_query_id) { |
| 326 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 338 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| 327 DCHECK(context3d); | 339 DCHECK(context3d); |
| 328 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id)); | 340 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id)); |
| 329 } | 341 } |
| 330 if (resource->gl_pixel_buffer_id) { | 342 if (resource->gl_pixel_buffer_id) { |
| 331 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 343 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| 332 DCHECK(context3d); | 344 DCHECK(context3d); |
| 333 GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id)); | 345 GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id)); |
| 334 } | 346 } |
| 335 if (!resource->mailbox.IsEmpty() && resource->external) { | 347 if (resource->mailbox.IsValid() && resource->external) { |
| 336 WebGraphicsContext3D* context3d = output_surface_->context3d(); | |
| 337 DCHECK(context3d); | |
| 338 unsigned sync_point = resource->mailbox.sync_point(); | 348 unsigned sync_point = resource->mailbox.sync_point(); |
| 339 if (!lost_resource && resource->gl_id) { | 349 if (resource->mailbox.IsTexture()) { |
| 340 GLC(context3d, context3d->bindTexture( | 350 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| 341 resource->mailbox.target(), resource->gl_id)); | 351 DCHECK(context3d); |
| 342 GLC(context3d, context3d->produceTextureCHROMIUM( | 352 if (!lost_resource && resource->gl_id) { |
| 343 resource->mailbox.target(), resource->mailbox.data())); | 353 GLC(context3d, context3d->bindTexture( |
| 354 resource->mailbox.target(), resource->gl_id)); | |
| 355 GLC(context3d, context3d->produceTextureCHROMIUM( | |
| 356 resource->mailbox.target(), resource->mailbox.data())); | |
| 357 } | |
| 358 if (resource->gl_id) | |
| 359 GLC(context3d, context3d->deleteTexture(resource->gl_id)); | |
| 360 if (!lost_resource && resource->gl_id) | |
| 361 sync_point = context3d->insertSyncPoint(); | |
| 362 } else { | |
| 363 DCHECK(resource->mailbox.IsSharedMemory()); | |
| 364 if (resource->shared_memory) { | |
| 365 DCHECK(resource->shared_memory->memory() == resource->pixels); | |
| 366 delete resource->shared_memory; | |
| 367 resource->shared_memory = NULL; | |
| 368 resource->pixels = NULL; | |
| 369 } | |
| 344 } | 370 } |
| 345 if (resource->gl_id) | |
| 346 GLC(context3d, context3d->deleteTexture(resource->gl_id)); | |
| 347 if (!lost_resource && resource->gl_id) | |
| 348 sync_point = context3d->insertSyncPoint(); | |
| 349 resource->mailbox.RunReleaseCallback(sync_point, lost_resource); | 371 resource->mailbox.RunReleaseCallback(sync_point, lost_resource); |
| 350 } | 372 } |
| 351 if (resource->pixels) | 373 if (resource->pixels) |
| 352 delete[] resource->pixels; | 374 delete[] resource->pixels; |
| 353 if (resource->pixel_buffer) | 375 if (resource->pixel_buffer) |
| 354 delete[] resource->pixel_buffer; | 376 delete[] resource->pixel_buffer; |
| 355 | 377 |
| 356 resources_.erase(it); | 378 resources_.erase(it); |
| 357 } | 379 } |
| 358 | 380 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 480 CHECK(it != resources_.end()); | 502 CHECK(it != resources_.end()); |
| 481 Resource* resource = &it->second; | 503 Resource* resource = &it->second; |
| 482 DCHECK(!resource->locked_for_write || | 504 DCHECK(!resource->locked_for_write || |
| 483 resource->set_pixels_completion_forced) << | 505 resource->set_pixels_completion_forced) << |
| 484 "locked for write: " << resource->locked_for_write << | 506 "locked for write: " << resource->locked_for_write << |
| 485 " pixels completion forced: " << resource->set_pixels_completion_forced; | 507 " pixels completion forced: " << resource->set_pixels_completion_forced; |
| 486 DCHECK(!resource->exported); | 508 DCHECK(!resource->exported); |
| 487 // Uninitialized! Call SetPixels or LockForWrite first. | 509 // Uninitialized! Call SetPixels or LockForWrite first. |
| 488 DCHECK(resource->allocated); | 510 DCHECK(resource->allocated); |
| 489 | 511 |
| 490 if (!resource->gl_id && resource->external && !resource->mailbox.IsEmpty()) { | 512 if (resource->external) { |
| 491 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 513 if (!resource->gl_id && resource->mailbox.IsTexture()) { |
| 492 DCHECK(context3d); | 514 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| 493 if (resource->mailbox.sync_point()) { | 515 DCHECK(context3d); |
| 494 GLC(context3d, context3d->waitSyncPoint(resource->mailbox.sync_point())); | 516 if (resource->mailbox.sync_point()) { |
| 495 resource->mailbox.ResetSyncPoint(); | 517 GLC(context3d, |
| 518 context3d->waitSyncPoint(resource->mailbox.sync_point())); | |
| 519 resource->mailbox.ResetSyncPoint(); | |
| 520 } | |
| 521 resource->gl_id = context3d->createTexture(); | |
| 522 GLC(context3d, context3d->bindTexture( | |
| 523 resource->mailbox.target(), resource->gl_id)); | |
| 524 GLC(context3d, context3d->consumeTextureCHROMIUM( | |
| 525 resource->mailbox.target(), resource->mailbox.data())); | |
| 526 } else if (!resource->shared_memory && resource->mailbox.IsSharedMemory()) { | |
| 527 CHECK(!resource->pixels); | |
| 528 resource->size = resource->mailbox.size(); | |
| 529 resource->shared_memory = new base::SharedMemory( | |
| 530 resource->mailbox.handle(), false); | |
| 531 const size_t size = 4 * resource->size.GetArea(); | |
| 532 bool success = resource->shared_memory->Map(size); | |
| 533 CHECK(success); | |
| 534 resource->format = GL_RGBA; | |
| 535 resource->pixels = | |
| 536 reinterpret_cast<uint8_t*>(resource->shared_memory->memory()); | |
| 496 } | 537 } |
| 497 resource->gl_id = context3d->createTexture(); | |
| 498 GLC(context3d, context3d->bindTexture( | |
| 499 resource->mailbox.target(), resource->gl_id)); | |
| 500 GLC(context3d, context3d->consumeTextureCHROMIUM( | |
| 501 resource->mailbox.target(), resource->mailbox.data())); | |
| 502 } | 538 } |
| 503 | 539 |
| 504 resource->lock_for_read_count++; | 540 resource->lock_for_read_count++; |
| 505 if (resource->enable_read_lock_fences) | 541 if (resource->enable_read_lock_fences) |
| 506 resource->read_lock_fence = current_read_lock_fence_; | 542 resource->read_lock_fence = current_read_lock_fence_; |
| 507 | 543 |
| 508 return resource; | 544 return resource; |
| 509 } | 545 } |
| 510 | 546 |
| 511 void ResourceProvider::UnlockForRead(ResourceId id) { | 547 void ResourceProvider::UnlockForRead(ResourceId id) { |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 833 } | 869 } |
| 834 for (TransferableResourceArray::const_iterator it = resources.begin(); | 870 for (TransferableResourceArray::const_iterator it = resources.begin(); |
| 835 it != resources.end(); | 871 it != resources.end(); |
| 836 ++it) { | 872 ++it) { |
| 837 ResourceMap::iterator map_iterator = resources_.find(it->id); | 873 ResourceMap::iterator map_iterator = resources_.find(it->id); |
| 838 DCHECK(map_iterator != resources_.end()); | 874 DCHECK(map_iterator != resources_.end()); |
| 839 Resource* resource = &map_iterator->second; | 875 Resource* resource = &map_iterator->second; |
| 840 DCHECK(resource->exported); | 876 DCHECK(resource->exported); |
| 841 resource->exported = false; | 877 resource->exported = false; |
| 842 resource->filter = it->filter; | 878 resource->filter = it->filter; |
| 843 DCHECK(resource->mailbox.Equals(it->mailbox)); | 879 DCHECK(resource->mailbox.Contains(it->mailbox)); |
| 844 if (resource->gl_id) { | 880 if (resource->gl_id) { |
| 845 if (it->sync_point) | 881 if (it->sync_point) |
| 846 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); | 882 GLC(context3d, context3d->waitSyncPoint(it->sync_point)); |
| 847 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); | 883 GLC(context3d, context3d->bindTexture(GL_TEXTURE_2D, resource->gl_id)); |
| 848 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, | 884 GLC(context3d, context3d->consumeTextureCHROMIUM(GL_TEXTURE_2D, |
| 849 it->mailbox.name)); | 885 it->mailbox.name)); |
| 850 } else { | 886 } else { |
| 851 resource->mailbox = TextureMailbox(resource->mailbox.name(), | 887 resource->mailbox = TextureMailbox(resource->mailbox.name(), |
| 852 resource->mailbox.callback(), | 888 resource->mailbox.callback(), |
| 853 it->sync_point); | 889 it->sync_point); |
| 854 } | 890 } |
| 855 if (resource->marked_for_deletion) | 891 if (resource->marked_for_deletion) |
| 856 DeleteResourceInternal(map_iterator, Normal); | 892 DeleteResourceInternal(map_iterator, Normal); |
| 857 } | 893 } |
| 858 } | 894 } |
| 859 | 895 |
| 860 bool ResourceProvider::TransferResource(WebGraphicsContext3D* context, | 896 bool ResourceProvider::TransferResource(WebGraphicsContext3D* context, |
| 861 ResourceId id, | 897 ResourceId id, |
| 862 TransferableResource* resource) { | 898 TransferableResource* resource) { |
| 863 DCHECK(thread_checker_.CalledOnValidThread()); | 899 DCHECK(thread_checker_.CalledOnValidThread()); |
| 864 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 900 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| 865 ResourceMap::iterator it = resources_.find(id); | 901 ResourceMap::iterator it = resources_.find(id); |
| 866 CHECK(it != resources_.end()); | 902 CHECK(it != resources_.end()); |
| 867 Resource* source = &it->second; | 903 Resource* source = &it->second; |
| 868 DCHECK(!source->locked_for_write); | 904 DCHECK(!source->locked_for_write); |
| 869 DCHECK(!source->lock_for_read_count); | 905 DCHECK(!source->lock_for_read_count); |
| 870 DCHECK(!source->external || (source->external && !source->mailbox.IsEmpty())); | 906 DCHECK(!source->external || (source->external && source->mailbox.IsValid())); |
| 871 DCHECK(source->allocated); | 907 DCHECK(source->allocated); |
| 872 if (source->exported) | 908 if (source->exported) |
| 873 return false; | 909 return false; |
| 874 resource->id = id; | 910 resource->id = id; |
| 875 resource->format = source->format; | 911 resource->format = source->format; |
| 876 resource->filter = source->filter; | 912 resource->filter = source->filter; |
| 877 resource->size = source->size; | 913 resource->size = source->size; |
| 878 | 914 |
| 879 if (source->mailbox.IsEmpty()) { | 915 // TODO(skaslev) Implement this path for shared memory resources. |
|
piman
2013/05/28 20:58:57
This needs to be at least a DCHECK or something. R
slavi
2013/05/29 18:31:48
Done.
| |
| 916 if (!source->mailbox.IsTexture()) { | |
| 880 GLC(context3d, context3d->genMailboxCHROMIUM(resource->mailbox.name)); | 917 GLC(context3d, context3d->genMailboxCHROMIUM(resource->mailbox.name)); |
| 881 source->mailbox.SetName(resource->mailbox); | 918 source->mailbox.SetName(resource->mailbox); |
| 882 } else { | 919 } else { |
| 883 resource->mailbox = source->mailbox.name(); | 920 resource->mailbox = source->mailbox.name(); |
| 884 } | 921 } |
| 885 | 922 |
| 886 if (source->gl_id) { | 923 if (source->gl_id) { |
| 887 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id)); | 924 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id)); |
| 888 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, | 925 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, |
| 889 resource->mailbox.name)); | 926 resource->mailbox.name)); |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1367 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 1404 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| 1368 DCHECK(context3d); | 1405 DCHECK(context3d); |
| 1369 int stride = 0; | 1406 int stride = 0; |
| 1370 context3d->getImageParameterivCHROMIUM( | 1407 context3d->getImageParameterivCHROMIUM( |
| 1371 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride); | 1408 resource->image_id, GL_IMAGE_ROWBYTES_CHROMIUM, &stride); |
| 1372 return stride; | 1409 return stride; |
| 1373 } | 1410 } |
| 1374 | 1411 |
| 1375 | 1412 |
| 1376 } // namespace cc | 1413 } // namespace cc |
| OLD | NEW |