| 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 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), |
| 111 shared_memory(NULL), |
| 110 format(format), | 112 format(format), |
| 111 filter(filter), | 113 filter(filter), |
| 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), |
| 134 shared_memory(NULL), |
| 132 format(format), | 135 format(format), |
| 133 filter(filter), | 136 filter(filter), |
| 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, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 resource.allocated = true; | 269 resource.allocated = true; |
| 267 resources_[id] = resource; | 270 resources_[id] = resource; |
| 268 return id; | 271 return id; |
| 269 } | 272 } |
| 270 | 273 |
| 271 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 274 ResourceProvider::ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
| 272 const TextureMailbox& mailbox) { | 275 const TextureMailbox& mailbox) { |
| 273 DCHECK(thread_checker_.CalledOnValidThread()); | 276 DCHECK(thread_checker_.CalledOnValidThread()); |
| 274 // Just store the information. Mailbox will be consumed in LockForRead(). | 277 // Just store the information. Mailbox will be consumed in LockForRead(). |
| 275 ResourceId id = next_id_++; | 278 ResourceId id = next_id_++; |
| 276 unsigned texture_id = 0; | 279 if (mailbox.IsTexture()) { |
| 277 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR); | 280 unsigned texture_id = 0; |
| 278 resource.external = true; | 281 Resource resource(texture_id, gfx::Size(), 0, GL_LINEAR); |
| 279 resource.allocated = true; | 282 resource.external = true; |
| 280 resource.mailbox = mailbox; | 283 resource.allocated = true; |
| 281 resources_[id] = resource; | 284 resource.mailbox = mailbox; |
| 285 resources_[id] = resource; |
| 286 } else if (mailbox.IsSharedMemory()) { |
| 287 uint8_t *pixels = NULL; |
| 288 Resource resource(pixels, mailbox.size(), 0, GL_LINEAR); |
| 289 resource.external = true; |
| 290 resource.allocated = true; |
| 291 resource.mailbox = mailbox; |
| 292 resources_[id] = resource; |
| 293 } |
| 282 return id; | 294 return id; |
| 283 } | 295 } |
| 284 | 296 |
| 285 void ResourceProvider::DeleteResource(ResourceId id) { | 297 void ResourceProvider::DeleteResource(ResourceId id) { |
| 286 DCHECK(thread_checker_.CalledOnValidThread()); | 298 DCHECK(thread_checker_.CalledOnValidThread()); |
| 287 ResourceMap::iterator it = resources_.find(id); | 299 ResourceMap::iterator it = resources_.find(id); |
| 288 CHECK(it != resources_.end()); | 300 CHECK(it != resources_.end()); |
| 289 Resource* resource = &it->second; | 301 Resource* resource = &it->second; |
| 290 DCHECK(!resource->lock_for_read_count); | 302 DCHECK(!resource->lock_for_read_count); |
| 291 DCHECK(!resource->marked_for_deletion); | 303 DCHECK(!resource->marked_for_deletion); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 316 if (resource->gl_upload_query_id) { | 328 if (resource->gl_upload_query_id) { |
| 317 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 329 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| 318 DCHECK(context3d); | 330 DCHECK(context3d); |
| 319 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id)); | 331 GLC(context3d, context3d->deleteQueryEXT(resource->gl_upload_query_id)); |
| 320 } | 332 } |
| 321 if (resource->gl_pixel_buffer_id) { | 333 if (resource->gl_pixel_buffer_id) { |
| 322 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 334 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| 323 DCHECK(context3d); | 335 DCHECK(context3d); |
| 324 GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id)); | 336 GLC(context3d, context3d->deleteBuffer(resource->gl_pixel_buffer_id)); |
| 325 } | 337 } |
| 326 if (!resource->mailbox.IsEmpty() && resource->external) { | 338 if (resource->mailbox.IsValid() && resource->external) { |
| 327 WebGraphicsContext3D* context3d = output_surface_->context3d(); | |
| 328 DCHECK(context3d); | |
| 329 unsigned sync_point = resource->mailbox.sync_point(); | 339 unsigned sync_point = resource->mailbox.sync_point(); |
| 330 if (!lost_resource && resource->gl_id) { | 340 if (resource->mailbox.IsTexture()) { |
| 331 GLC(context3d, context3d->bindTexture( | 341 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| 332 resource->mailbox.target(), resource->gl_id)); | 342 DCHECK(context3d); |
| 333 GLC(context3d, context3d->produceTextureCHROMIUM( | 343 if (!lost_resource && resource->gl_id) { |
| 334 resource->mailbox.target(), resource->mailbox.data())); | 344 GLC(context3d, context3d->bindTexture( |
| 345 resource->mailbox.target(), resource->gl_id)); |
| 346 GLC(context3d, context3d->produceTextureCHROMIUM( |
| 347 resource->mailbox.target(), resource->mailbox.data())); |
| 348 } |
| 349 if (resource->gl_id) |
| 350 GLC(context3d, context3d->deleteTexture(resource->gl_id)); |
| 351 if (!lost_resource && resource->gl_id) |
| 352 sync_point = context3d->insertSyncPoint(); |
| 353 } else { |
| 354 DCHECK(resource->mailbox.IsSharedMemory()); |
| 355 if (resource->shared_memory) { |
| 356 DCHECK(resource->shared_memory->memory() == resource->pixels); |
| 357 delete resource->shared_memory; |
| 358 resource->shared_memory = NULL; |
| 359 resource->pixels = NULL; |
| 360 } |
| 335 } | 361 } |
| 336 if (resource->gl_id) | |
| 337 GLC(context3d, context3d->deleteTexture(resource->gl_id)); | |
| 338 if (!lost_resource && resource->gl_id) | |
| 339 sync_point = context3d->insertSyncPoint(); | |
| 340 resource->mailbox.RunReleaseCallback(sync_point, lost_resource); | 362 resource->mailbox.RunReleaseCallback(sync_point, lost_resource); |
| 341 } | 363 } |
| 342 if (resource->pixels) | 364 if (resource->pixels) |
| 343 delete[] resource->pixels; | 365 delete[] resource->pixels; |
| 344 if (resource->pixel_buffer) | 366 if (resource->pixel_buffer) |
| 345 delete[] resource->pixel_buffer; | 367 delete[] resource->pixel_buffer; |
| 346 | 368 |
| 347 resources_.erase(it); | 369 resources_.erase(it); |
| 348 } | 370 } |
| 349 | 371 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 CHECK(it != resources_.end()); | 493 CHECK(it != resources_.end()); |
| 472 Resource* resource = &it->second; | 494 Resource* resource = &it->second; |
| 473 DCHECK(!resource->locked_for_write || | 495 DCHECK(!resource->locked_for_write || |
| 474 resource->set_pixels_completion_forced) << | 496 resource->set_pixels_completion_forced) << |
| 475 "locked for write: " << resource->locked_for_write << | 497 "locked for write: " << resource->locked_for_write << |
| 476 " pixels completion forced: " << resource->set_pixels_completion_forced; | 498 " pixels completion forced: " << resource->set_pixels_completion_forced; |
| 477 DCHECK(!resource->exported); | 499 DCHECK(!resource->exported); |
| 478 // Uninitialized! Call SetPixels or LockForWrite first. | 500 // Uninitialized! Call SetPixels or LockForWrite first. |
| 479 DCHECK(resource->allocated); | 501 DCHECK(resource->allocated); |
| 480 | 502 |
| 481 if (!resource->gl_id && resource->external && !resource->mailbox.IsEmpty()) { | 503 if (resource->external) { |
| 482 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 504 if (!resource->gl_id && resource->mailbox.IsTexture()) { |
| 483 DCHECK(context3d); | 505 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| 484 if (resource->mailbox.sync_point()) { | 506 DCHECK(context3d); |
| 485 GLC(context3d, context3d->waitSyncPoint(resource->mailbox.sync_point())); | 507 if (resource->mailbox.sync_point()) { |
| 486 resource->mailbox.ResetSyncPoint(); | 508 GLC(context3d, |
| 509 context3d->waitSyncPoint(resource->mailbox.sync_point())); |
| 510 resource->mailbox.ResetSyncPoint(); |
| 511 } |
| 512 resource->gl_id = context3d->createTexture(); |
| 513 GLC(context3d, context3d->bindTexture( |
| 514 resource->mailbox.target(), resource->gl_id)); |
| 515 GLC(context3d, context3d->consumeTextureCHROMIUM( |
| 516 resource->mailbox.target(), resource->mailbox.data())); |
| 517 } else if (!resource->shared_memory && resource->mailbox.IsSharedMemory()) { |
| 518 CHECK(!resource->pixels); |
| 519 resource->size = resource->mailbox.size(); |
| 520 resource->shared_memory = new base::SharedMemory( |
| 521 resource->mailbox.handle(), false); |
| 522 const size_t size = 4 * resource->size.GetArea(); |
| 523 bool success = resource->shared_memory->Map(size); |
| 524 CHECK(success); |
| 525 resource->format = GL_RGBA; |
| 526 resource->pixels = |
| 527 reinterpret_cast<uint8_t*>(resource->shared_memory->memory()); |
| 487 } | 528 } |
| 488 resource->gl_id = context3d->createTexture(); | |
| 489 GLC(context3d, context3d->bindTexture( | |
| 490 resource->mailbox.target(), resource->gl_id)); | |
| 491 GLC(context3d, context3d->consumeTextureCHROMIUM( | |
| 492 resource->mailbox.target(), resource->mailbox.data())); | |
| 493 } | 529 } |
| 494 | 530 |
| 495 resource->lock_for_read_count++; | 531 resource->lock_for_read_count++; |
| 496 if (resource->enable_read_lock_fences) | 532 if (resource->enable_read_lock_fences) |
| 497 resource->read_lock_fence = current_read_lock_fence_; | 533 resource->read_lock_fence = current_read_lock_fence_; |
| 498 | 534 |
| 499 return resource; | 535 return resource; |
| 500 } | 536 } |
| 501 | 537 |
| 502 void ResourceProvider::UnlockForRead(ResourceId id) { | 538 void ResourceProvider::UnlockForRead(ResourceId id) { |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 bool ResourceProvider::TransferResource(WebGraphicsContext3D* context, | 886 bool ResourceProvider::TransferResource(WebGraphicsContext3D* context, |
| 851 ResourceId id, | 887 ResourceId id, |
| 852 TransferableResource* resource) { | 888 TransferableResource* resource) { |
| 853 DCHECK(thread_checker_.CalledOnValidThread()); | 889 DCHECK(thread_checker_.CalledOnValidThread()); |
| 854 WebGraphicsContext3D* context3d = output_surface_->context3d(); | 890 WebGraphicsContext3D* context3d = output_surface_->context3d(); |
| 855 ResourceMap::iterator it = resources_.find(id); | 891 ResourceMap::iterator it = resources_.find(id); |
| 856 CHECK(it != resources_.end()); | 892 CHECK(it != resources_.end()); |
| 857 Resource* source = &it->second; | 893 Resource* source = &it->second; |
| 858 DCHECK(!source->locked_for_write); | 894 DCHECK(!source->locked_for_write); |
| 859 DCHECK(!source->lock_for_read_count); | 895 DCHECK(!source->lock_for_read_count); |
| 860 DCHECK(!source->external || (source->external && !source->mailbox.IsEmpty())); | 896 DCHECK(!source->external || (source->external && source->mailbox.IsValid())); |
| 861 DCHECK(source->allocated); | 897 DCHECK(source->allocated); |
| 862 if (source->exported) | 898 if (source->exported) |
| 863 return false; | 899 return false; |
| 864 resource->id = id; | 900 resource->id = id; |
| 865 resource->format = source->format; | 901 resource->format = source->format; |
| 866 resource->filter = source->filter; | 902 resource->filter = source->filter; |
| 867 resource->size = source->size; | 903 resource->size = source->size; |
| 868 | 904 |
| 869 if (source->mailbox.IsEmpty()) { | 905 // TODO(skaslev) Implement this path for shared memory resources. |
| 906 if (!source->mailbox.IsTexture()) { |
| 870 GLC(context3d, context3d->genMailboxCHROMIUM(resource->mailbox.name)); | 907 GLC(context3d, context3d->genMailboxCHROMIUM(resource->mailbox.name)); |
| 871 source->mailbox.SetName(resource->mailbox); | 908 source->mailbox.SetName(resource->mailbox); |
| 872 } else { | 909 } else { |
| 873 resource->mailbox = source->mailbox.name(); | 910 resource->mailbox = source->mailbox.name(); |
| 874 } | 911 } |
| 875 | 912 |
| 876 if (source->gl_id) { | 913 if (source->gl_id) { |
| 877 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id)); | 914 GLC(context, context->bindTexture(GL_TEXTURE_2D, source->gl_id)); |
| 878 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, | 915 GLC(context, context->produceTextureCHROMIUM(GL_TEXTURE_2D, |
| 879 resource->mailbox.name)); | 916 resource->mailbox.name)); |
| (...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1236 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, | 1273 void ResourceProvider::EnableReadLockFences(ResourceProvider::ResourceId id, |
| 1237 bool enable) { | 1274 bool enable) { |
| 1238 DCHECK(thread_checker_.CalledOnValidThread()); | 1275 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1239 ResourceMap::iterator it = resources_.find(id); | 1276 ResourceMap::iterator it = resources_.find(id); |
| 1240 CHECK(it != resources_.end()); | 1277 CHECK(it != resources_.end()); |
| 1241 Resource* resource = &it->second; | 1278 Resource* resource = &it->second; |
| 1242 resource->enable_read_lock_fences = enable; | 1279 resource->enable_read_lock_fences = enable; |
| 1243 } | 1280 } |
| 1244 | 1281 |
| 1245 } // namespace cc | 1282 } // namespace cc |
| OLD | NEW |