| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 id_allocation_chunk_size_(id_allocation_chunk_size), | 58 id_allocation_chunk_size_(id_allocation_chunk_size), |
| 59 ids_(new GLuint[id_allocation_chunk_size]), | 59 ids_(new GLuint[id_allocation_chunk_size]), |
| 60 next_id_index_(id_allocation_chunk_size) { | 60 next_id_index_(id_allocation_chunk_size) { |
| 61 DCHECK(id_allocation_chunk_size_); | 61 DCHECK(id_allocation_chunk_size_); |
| 62 DCHECK_LE(id_allocation_chunk_size_, | 62 DCHECK_LE(id_allocation_chunk_size_, |
| 63 static_cast<size_t>(std::numeric_limits<int>::max())); | 63 static_cast<size_t>(std::numeric_limits<int>::max())); |
| 64 } | 64 } |
| 65 | 65 |
| 66 GLES2Interface* gl_; | 66 GLES2Interface* gl_; |
| 67 const size_t id_allocation_chunk_size_; | 67 const size_t id_allocation_chunk_size_; |
| 68 scoped_ptr<GLuint[]> ids_; | 68 std::unique_ptr<GLuint[]> ids_; |
| 69 size_t next_id_index_; | 69 size_t next_id_index_; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 namespace { | 72 namespace { |
| 73 | 73 |
| 74 bool IsGpuResourceType(ResourceProvider::ResourceType type) { | 74 bool IsGpuResourceType(ResourceProvider::ResourceType type) { |
| 75 return type != ResourceProvider::RESOURCE_TYPE_BITMAP; | 75 return type != ResourceProvider::RESOURCE_TYPE_BITMAP; |
| 76 } | 76 } |
| 77 | 77 |
| 78 GLenum TextureToStorageFormat(ResourceFormat format) { | 78 GLenum TextureToStorageFormat(ResourceFormat format) { |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 SetSynchronized(); | 376 SetSynchronized(); |
| 377 } | 377 } |
| 378 | 378 |
| 379 ResourceProvider::Child::Child() | 379 ResourceProvider::Child::Child() |
| 380 : marked_for_deletion(false), needs_sync_tokens(true) {} | 380 : marked_for_deletion(false), needs_sync_tokens(true) {} |
| 381 | 381 |
| 382 ResourceProvider::Child::Child(const Child& other) = default; | 382 ResourceProvider::Child::Child(const Child& other) = default; |
| 383 | 383 |
| 384 ResourceProvider::Child::~Child() {} | 384 ResourceProvider::Child::~Child() {} |
| 385 | 385 |
| 386 scoped_ptr<ResourceProvider> ResourceProvider::Create( | 386 std::unique_ptr<ResourceProvider> ResourceProvider::Create( |
| 387 OutputSurface* output_surface, | 387 OutputSurface* output_surface, |
| 388 SharedBitmapManager* shared_bitmap_manager, | 388 SharedBitmapManager* shared_bitmap_manager, |
| 389 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 389 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, |
| 390 BlockingTaskRunner* blocking_main_thread_task_runner, | 390 BlockingTaskRunner* blocking_main_thread_task_runner, |
| 391 int highp_threshold_min, | 391 int highp_threshold_min, |
| 392 size_t id_allocation_chunk_size, | 392 size_t id_allocation_chunk_size, |
| 393 bool use_gpu_memory_buffer_resources, | 393 bool use_gpu_memory_buffer_resources, |
| 394 const std::vector<unsigned>& use_image_texture_targets) { | 394 const std::vector<unsigned>& use_image_texture_targets) { |
| 395 scoped_ptr<ResourceProvider> resource_provider(new ResourceProvider( | 395 std::unique_ptr<ResourceProvider> resource_provider(new ResourceProvider( |
| 396 output_surface, shared_bitmap_manager, gpu_memory_buffer_manager, | 396 output_surface, shared_bitmap_manager, gpu_memory_buffer_manager, |
| 397 blocking_main_thread_task_runner, highp_threshold_min, | 397 blocking_main_thread_task_runner, highp_threshold_min, |
| 398 id_allocation_chunk_size, use_gpu_memory_buffer_resources, | 398 id_allocation_chunk_size, use_gpu_memory_buffer_resources, |
| 399 use_image_texture_targets)); | 399 use_image_texture_targets)); |
| 400 resource_provider->Initialize(); | 400 resource_provider->Initialize(); |
| 401 return resource_provider; | 401 return resource_provider; |
| 402 } | 402 } |
| 403 | 403 |
| 404 ResourceProvider::~ResourceProvider() { | 404 ResourceProvider::~ResourceProvider() { |
| 405 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( | 405 base::trace_event::MemoryDumpManager::GetInstance()->UnregisterDumpProvider( |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 Resource* resource = | 544 Resource* resource = |
| 545 InsertResource(id, Resource(0, size, Resource::INTERNAL, target, | 545 InsertResource(id, Resource(0, size, Resource::INTERNAL, target, |
| 546 GL_LINEAR, hint, type, format)); | 546 GL_LINEAR, hint, type, format)); |
| 547 resource->allocated = false; | 547 resource->allocated = false; |
| 548 return id; | 548 return id; |
| 549 } | 549 } |
| 550 | 550 |
| 551 ResourceId ResourceProvider::CreateBitmap(const gfx::Size& size) { | 551 ResourceId ResourceProvider::CreateBitmap(const gfx::Size& size) { |
| 552 DCHECK(thread_checker_.CalledOnValidThread()); | 552 DCHECK(thread_checker_.CalledOnValidThread()); |
| 553 | 553 |
| 554 scoped_ptr<SharedBitmap> bitmap = | 554 std::unique_ptr<SharedBitmap> bitmap = |
| 555 shared_bitmap_manager_->AllocateSharedBitmap(size); | 555 shared_bitmap_manager_->AllocateSharedBitmap(size); |
| 556 uint8_t* pixels = bitmap->pixels(); | 556 uint8_t* pixels = bitmap->pixels(); |
| 557 DCHECK(pixels); | 557 DCHECK(pixels); |
| 558 | 558 |
| 559 ResourceId id = next_id_++; | 559 ResourceId id = next_id_++; |
| 560 Resource* resource = InsertResource( | 560 Resource* resource = InsertResource( |
| 561 id, | 561 id, |
| 562 Resource(pixels, bitmap.release(), size, Resource::INTERNAL, GL_LINEAR)); | 562 Resource(pixels, bitmap.release(), size, Resource::INTERNAL, GL_LINEAR)); |
| 563 resource->allocated = true; | 563 resource->allocated = true; |
| 564 return id; | 564 return id; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 579 DCHECK(gl); | 579 DCHECK(gl); |
| 580 gl->BindTexture(GL_TEXTURE_RECTANGLE_ARB, resource->gl_id); | 580 gl->BindTexture(GL_TEXTURE_RECTANGLE_ARB, resource->gl_id); |
| 581 gl->TexImageIOSurface2DCHROMIUM( | 581 gl->TexImageIOSurface2DCHROMIUM( |
| 582 GL_TEXTURE_RECTANGLE_ARB, size.width(), size.height(), io_surface_id, 0); | 582 GL_TEXTURE_RECTANGLE_ARB, size.width(), size.height(), io_surface_id, 0); |
| 583 resource->allocated = true; | 583 resource->allocated = true; |
| 584 return id; | 584 return id; |
| 585 } | 585 } |
| 586 | 586 |
| 587 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 587 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
| 588 const TextureMailbox& mailbox, | 588 const TextureMailbox& mailbox, |
| 589 scoped_ptr<SingleReleaseCallbackImpl> release_callback_impl, | 589 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl, |
| 590 bool read_lock_fences_enabled) { | 590 bool read_lock_fences_enabled) { |
| 591 DCHECK(thread_checker_.CalledOnValidThread()); | 591 DCHECK(thread_checker_.CalledOnValidThread()); |
| 592 // Just store the information. Mailbox will be consumed in LockForRead(). | 592 // Just store the information. Mailbox will be consumed in LockForRead(). |
| 593 ResourceId id = next_id_++; | 593 ResourceId id = next_id_++; |
| 594 DCHECK(mailbox.IsValid()); | 594 DCHECK(mailbox.IsValid()); |
| 595 Resource* resource = nullptr; | 595 Resource* resource = nullptr; |
| 596 if (mailbox.IsTexture()) { | 596 if (mailbox.IsTexture()) { |
| 597 resource = InsertResource( | 597 resource = InsertResource( |
| 598 id, | 598 id, |
| 599 Resource(0, mailbox.size_in_pixels(), Resource::EXTERNAL, | 599 Resource(0, mailbox.size_in_pixels(), Resource::EXTERNAL, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 615 base::Bind(&SingleReleaseCallbackImpl::Run, | 615 base::Bind(&SingleReleaseCallbackImpl::Run, |
| 616 base::Owned(release_callback_impl.release())); | 616 base::Owned(release_callback_impl.release())); |
| 617 resource->read_lock_fences_enabled = read_lock_fences_enabled; | 617 resource->read_lock_fences_enabled = read_lock_fences_enabled; |
| 618 resource->is_overlay_candidate = mailbox.is_overlay_candidate(); | 618 resource->is_overlay_candidate = mailbox.is_overlay_candidate(); |
| 619 | 619 |
| 620 return id; | 620 return id; |
| 621 } | 621 } |
| 622 | 622 |
| 623 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 623 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
| 624 const TextureMailbox& mailbox, | 624 const TextureMailbox& mailbox, |
| 625 scoped_ptr<SingleReleaseCallbackImpl> release_callback_impl) { | 625 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl) { |
| 626 return CreateResourceFromTextureMailbox( | 626 return CreateResourceFromTextureMailbox( |
| 627 mailbox, std::move(release_callback_impl), false); | 627 mailbox, std::move(release_callback_impl), false); |
| 628 } | 628 } |
| 629 | 629 |
| 630 void ResourceProvider::DeleteResource(ResourceId id) { | 630 void ResourceProvider::DeleteResource(ResourceId id) { |
| 631 DCHECK(thread_checker_.CalledOnValidThread()); | 631 DCHECK(thread_checker_.CalledOnValidThread()); |
| 632 ResourceMap::iterator it = resources_.find(id); | 632 ResourceMap::iterator it = resources_.find(id); |
| 633 CHECK(it != resources_.end()); | 633 CHECK(it != resources_.end()); |
| 634 Resource* resource = &it->second; | 634 Resource* resource = &it->second; |
| 635 DCHECK(!resource->marked_for_deletion); | 635 DCHECK(!resource->marked_for_deletion); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 | 861 |
| 862 GLES2Interface* gl = ContextGL(); | 862 GLES2Interface* gl = ContextGL(); |
| 863 DCHECK(gl); | 863 DCHECK(gl); |
| 864 resource->gl_id = gl->CreateAndConsumeTextureCHROMIUM( | 864 resource->gl_id = gl->CreateAndConsumeTextureCHROMIUM( |
| 865 resource->mailbox().target(), resource->mailbox().name()); | 865 resource->mailbox().target(), resource->mailbox().name()); |
| 866 resource->SetLocallyUsed(); | 866 resource->SetLocallyUsed(); |
| 867 } | 867 } |
| 868 | 868 |
| 869 if (!resource->pixels && resource->has_shared_bitmap_id && | 869 if (!resource->pixels && resource->has_shared_bitmap_id && |
| 870 shared_bitmap_manager_) { | 870 shared_bitmap_manager_) { |
| 871 scoped_ptr<SharedBitmap> bitmap = | 871 std::unique_ptr<SharedBitmap> bitmap = |
| 872 shared_bitmap_manager_->GetSharedBitmapFromId( | 872 shared_bitmap_manager_->GetSharedBitmapFromId( |
| 873 resource->size, resource->shared_bitmap_id); | 873 resource->size, resource->shared_bitmap_id); |
| 874 if (bitmap) { | 874 if (bitmap) { |
| 875 resource->shared_bitmap = bitmap.release(); | 875 resource->shared_bitmap = bitmap.release(); |
| 876 resource->pixels = resource->shared_bitmap->pixels(); | 876 resource->pixels = resource->shared_bitmap->pixels(); |
| 877 } | 877 } |
| 878 } | 878 } |
| 879 | 879 |
| 880 resource->lock_for_read_count++; | 880 resource->lock_for_read_count++; |
| 881 if (resource->read_lock_fences_enabled) { | 881 if (resource->read_lock_fences_enabled) { |
| (...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1961 | 1961 |
| 1962 const int kImportance = 2; | 1962 const int kImportance = 2; |
| 1963 pmd->CreateSharedGlobalAllocatorDump(guid); | 1963 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 1964 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 1964 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| 1965 } | 1965 } |
| 1966 | 1966 |
| 1967 return true; | 1967 return true; |
| 1968 } | 1968 } |
| 1969 | 1969 |
| 1970 } // namespace cc | 1970 } // namespace cc |
| OLD | NEW |