| 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 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 } | 541 } |
| 542 | 542 |
| 543 ResourceFormat ResourceProvider::YuvResourceFormat(int bits) const { | 543 ResourceFormat ResourceProvider::YuvResourceFormat(int bits) const { |
| 544 if (bits > 8) { | 544 if (bits > 8) { |
| 545 return yuv_highbit_resource_format_; | 545 return yuv_highbit_resource_format_; |
| 546 } else { | 546 } else { |
| 547 return yuv_resource_format_; | 547 return yuv_resource_format_; |
| 548 } | 548 } |
| 549 } | 549 } |
| 550 | 550 |
| 551 ResourceId ResourceProvider::CreateResource(const gfx::Size& size, | 551 ResourceId ResourceProvider::CreateResource( |
| 552 TextureHint hint, | 552 const gfx::Size& size, |
| 553 ResourceFormat format) { | 553 TextureHint hint, |
| 554 ResourceFormat format, |
| 555 const gfx::ColorSpace& color_space) { |
| 554 DCHECK(!size.IsEmpty()); | 556 DCHECK(!size.IsEmpty()); |
| 555 switch (default_resource_type_) { | 557 switch (default_resource_type_) { |
| 556 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: | 558 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: |
| 557 // GPU memory buffers don't support LUMINANCE_F16. | 559 // GPU memory buffers don't support LUMINANCE_F16. |
| 558 if (format != LUMINANCE_F16) { | 560 if (format != LUMINANCE_F16) { |
| 559 return CreateGLTexture(size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER, | 561 return CreateGLTexture( |
| 560 format, | 562 size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER, format, |
| 561 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE); | 563 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, color_space); |
| 562 } | 564 } |
| 563 // Fall through and use a regular texture. | 565 // Fall through and use a regular texture. |
| 564 case RESOURCE_TYPE_GL_TEXTURE: | 566 case RESOURCE_TYPE_GL_TEXTURE: |
| 565 return CreateGLTexture(size, hint, RESOURCE_TYPE_GL_TEXTURE, format, | 567 return CreateGLTexture(size, hint, RESOURCE_TYPE_GL_TEXTURE, format, |
| 566 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE); | 568 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE, |
| 569 color_space); |
| 567 | 570 |
| 568 case RESOURCE_TYPE_BITMAP: | 571 case RESOURCE_TYPE_BITMAP: |
| 569 DCHECK_EQ(RGBA_8888, format); | 572 DCHECK_EQ(RGBA_8888, format); |
| 570 return CreateBitmap(size); | 573 return CreateBitmap(size, color_space); |
| 571 } | 574 } |
| 572 | 575 |
| 573 LOG(FATAL) << "Invalid default resource type."; | 576 LOG(FATAL) << "Invalid default resource type."; |
| 574 return 0; | 577 return 0; |
| 575 } | 578 } |
| 576 | 579 |
| 577 ResourceId ResourceProvider::CreateGpuMemoryBufferResource( | 580 ResourceId ResourceProvider::CreateGpuMemoryBufferResource( |
| 578 const gfx::Size& size, | 581 const gfx::Size& size, |
| 579 TextureHint hint, | 582 TextureHint hint, |
| 580 ResourceFormat format, | 583 ResourceFormat format, |
| 581 gfx::BufferUsage usage) { | 584 gfx::BufferUsage usage, |
| 585 const gfx::ColorSpace& color_space) { |
| 582 DCHECK(!size.IsEmpty()); | 586 DCHECK(!size.IsEmpty()); |
| 583 switch (default_resource_type_) { | 587 switch (default_resource_type_) { |
| 584 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: | 588 case RESOURCE_TYPE_GPU_MEMORY_BUFFER: |
| 585 case RESOURCE_TYPE_GL_TEXTURE: { | 589 case RESOURCE_TYPE_GL_TEXTURE: { |
| 586 return CreateGLTexture(size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER, | 590 return CreateGLTexture(size, hint, RESOURCE_TYPE_GPU_MEMORY_BUFFER, |
| 587 format, usage); | 591 format, usage, color_space); |
| 588 } | 592 } |
| 589 case RESOURCE_TYPE_BITMAP: | 593 case RESOURCE_TYPE_BITMAP: |
| 590 DCHECK_EQ(RGBA_8888, format); | 594 DCHECK_EQ(RGBA_8888, format); |
| 591 return CreateBitmap(size); | 595 return CreateBitmap(size, color_space); |
| 592 } | 596 } |
| 593 | 597 |
| 594 LOG(FATAL) << "Invalid default resource type."; | 598 LOG(FATAL) << "Invalid default resource type."; |
| 595 return 0; | 599 return 0; |
| 596 } | 600 } |
| 597 | 601 |
| 598 ResourceId ResourceProvider::CreateGLTexture(const gfx::Size& size, | 602 ResourceId ResourceProvider::CreateGLTexture( |
| 599 TextureHint hint, | 603 const gfx::Size& size, |
| 600 ResourceType type, | 604 TextureHint hint, |
| 601 ResourceFormat format, | 605 ResourceType type, |
| 602 gfx::BufferUsage usage) { | 606 ResourceFormat format, |
| 607 gfx::BufferUsage usage, |
| 608 const gfx::ColorSpace& color_space) { |
| 603 DCHECK_LE(size.width(), max_texture_size_); | 609 DCHECK_LE(size.width(), max_texture_size_); |
| 604 DCHECK_LE(size.height(), max_texture_size_); | 610 DCHECK_LE(size.height(), max_texture_size_); |
| 605 DCHECK(thread_checker_.CalledOnValidThread()); | 611 DCHECK(thread_checker_.CalledOnValidThread()); |
| 606 | 612 |
| 607 // TODO(crbug.com/590317): We should not assume that all resources created by | 613 // TODO(crbug.com/590317): We should not assume that all resources created by |
| 608 // ResourceProvider are GPU_READ_CPU_READ_WRITE. We should determine this | 614 // ResourceProvider are GPU_READ_CPU_READ_WRITE. We should determine this |
| 609 // based on the current RasterBufferProvider's needs. | 615 // based on the current RasterBufferProvider's needs. |
| 610 GLenum target = type == RESOURCE_TYPE_GPU_MEMORY_BUFFER | 616 GLenum target = type == RESOURCE_TYPE_GPU_MEMORY_BUFFER |
| 611 ? GetImageTextureTarget(usage, format) | 617 ? GetImageTextureTarget(usage, format) |
| 612 : GL_TEXTURE_2D; | 618 : GL_TEXTURE_2D; |
| 613 | 619 |
| 614 ResourceId id = next_id_++; | 620 ResourceId id = next_id_++; |
| 615 Resource* resource = | 621 Resource* resource = |
| 616 InsertResource(id, Resource(0, size, Resource::INTERNAL, target, | 622 InsertResource(id, Resource(0, size, Resource::INTERNAL, target, |
| 617 GL_LINEAR, hint, type, format)); | 623 GL_LINEAR, hint, type, format)); |
| 618 resource->usage = usage; | 624 resource->usage = usage; |
| 619 resource->allocated = false; | 625 resource->allocated = false; |
| 626 resource->color_space = color_space; |
| 620 return id; | 627 return id; |
| 621 } | 628 } |
| 622 | 629 |
| 623 ResourceId ResourceProvider::CreateBitmap(const gfx::Size& size) { | 630 ResourceId ResourceProvider::CreateBitmap(const gfx::Size& size, |
| 631 const gfx::ColorSpace& color_space) { |
| 624 DCHECK(thread_checker_.CalledOnValidThread()); | 632 DCHECK(thread_checker_.CalledOnValidThread()); |
| 625 | 633 |
| 626 std::unique_ptr<SharedBitmap> bitmap = | 634 std::unique_ptr<SharedBitmap> bitmap = |
| 627 shared_bitmap_manager_->AllocateSharedBitmap(size); | 635 shared_bitmap_manager_->AllocateSharedBitmap(size); |
| 628 uint8_t* pixels = bitmap->pixels(); | 636 uint8_t* pixels = bitmap->pixels(); |
| 629 DCHECK(pixels); | 637 DCHECK(pixels); |
| 630 | 638 |
| 631 ResourceId id = next_id_++; | 639 ResourceId id = next_id_++; |
| 632 Resource* resource = InsertResource( | 640 Resource* resource = InsertResource( |
| 633 id, | 641 id, |
| 634 Resource(pixels, bitmap.release(), size, Resource::INTERNAL, GL_LINEAR)); | 642 Resource(pixels, bitmap.release(), size, Resource::INTERNAL, GL_LINEAR)); |
| 635 resource->allocated = true; | 643 resource->allocated = true; |
| 644 resource->color_space = color_space; |
| 636 return id; | 645 return id; |
| 637 } | 646 } |
| 638 | 647 |
| 639 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( | 648 ResourceId ResourceProvider::CreateResourceFromTextureMailbox( |
| 640 const TextureMailbox& mailbox, | 649 const TextureMailbox& mailbox, |
| 641 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl, | 650 std::unique_ptr<SingleReleaseCallbackImpl> release_callback_impl, |
| 642 bool read_lock_fences_enabled) { | 651 bool read_lock_fences_enabled) { |
| 643 DCHECK(thread_checker_.CalledOnValidThread()); | 652 DCHECK(thread_checker_.CalledOnValidThread()); |
| 644 // Just store the information. Mailbox will be consumed in LockForRead(). | 653 // Just store the information. Mailbox will be consumed in LockForRead(). |
| 645 ResourceId id = next_id_++; | 654 ResourceId id = next_id_++; |
| (...skipping 1360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2006 | 2015 |
| 2007 const int kImportance = 2; | 2016 const int kImportance = 2; |
| 2008 pmd->CreateSharedGlobalAllocatorDump(guid); | 2017 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 2009 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 2018 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| 2010 } | 2019 } |
| 2011 | 2020 |
| 2012 return true; | 2021 return true; |
| 2013 } | 2022 } |
| 2014 | 2023 |
| 2015 } // namespace cc | 2024 } // namespace cc |
| OLD | NEW |