| 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/atomic_sequence_num.h" | 10 #include "base/atomic_sequence_num.h" |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 format); | 392 format); |
| 393 case RESOURCE_TYPE_BITMAP: | 393 case RESOURCE_TYPE_BITMAP: |
| 394 DCHECK_EQ(RGBA_8888, format); | 394 DCHECK_EQ(RGBA_8888, format); |
| 395 return CreateBitmap(size); | 395 return CreateBitmap(size); |
| 396 } | 396 } |
| 397 | 397 |
| 398 LOG(FATAL) << "Invalid default resource type."; | 398 LOG(FATAL) << "Invalid default resource type."; |
| 399 return 0; | 399 return 0; |
| 400 } | 400 } |
| 401 | 401 |
| 402 ResourceId ResourceProvider::CreateManagedResource(const gfx::Size& size, | 402 ResourceId ResourceProvider::CreateResourceWithTextureTarget( |
| 403 GLenum target, | 403 const gfx::Size& size, |
| 404 TextureHint hint, | 404 GLenum target, |
| 405 ResourceFormat format) { | 405 TextureHint hint, |
| 406 ResourceFormat format) { |
| 406 DCHECK(!size.IsEmpty()); | 407 DCHECK(!size.IsEmpty()); |
| 407 switch (default_resource_type_) { | 408 switch (default_resource_type_) { |
| 408 case RESOURCE_TYPE_GL_TEXTURE: | 409 case RESOURCE_TYPE_GL_TEXTURE: |
| 409 return CreateGLTexture(size, | 410 return CreateGLTexture(size, |
| 410 target, | 411 target, |
| 411 hint, | 412 hint, |
| 412 format); | 413 format); |
| 413 case RESOURCE_TYPE_BITMAP: | 414 case RESOURCE_TYPE_BITMAP: |
| 414 DCHECK_EQ(RGBA_8888, format); | 415 DCHECK_EQ(RGBA_8888, format); |
| 415 return CreateBitmap(size); | 416 return CreateBitmap(size); |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 | 617 |
| 617 void ResourceProvider::CopyToResource(ResourceId id, | 618 void ResourceProvider::CopyToResource(ResourceId id, |
| 618 const uint8_t* image, | 619 const uint8_t* image, |
| 619 const gfx::Size& image_size) { | 620 const gfx::Size& image_size) { |
| 620 Resource* resource = GetResource(id); | 621 Resource* resource = GetResource(id); |
| 621 DCHECK(!resource->locked_for_write); | 622 DCHECK(!resource->locked_for_write); |
| 622 DCHECK(!resource->lock_for_read_count); | 623 DCHECK(!resource->lock_for_read_count); |
| 623 DCHECK(resource->origin == Resource::INTERNAL); | 624 DCHECK(resource->origin == Resource::INTERNAL); |
| 624 DCHECK_EQ(resource->exported_count, 0); | 625 DCHECK_EQ(resource->exported_count, 0); |
| 625 DCHECK(ReadLockFenceHasPassed(resource)); | 626 DCHECK(ReadLockFenceHasPassed(resource)); |
| 626 LazyAllocate(resource); | |
| 627 | 627 |
| 628 DCHECK_EQ(image_size.width(), resource->size.width()); | 628 DCHECK_EQ(image_size.width(), resource->size.width()); |
| 629 DCHECK_EQ(image_size.height(), resource->size.height()); | 629 DCHECK_EQ(image_size.height(), resource->size.height()); |
| 630 | 630 |
| 631 if (resource->type == RESOURCE_TYPE_BITMAP) { | 631 if (resource->type == RESOURCE_TYPE_BITMAP) { |
| 632 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); | 632 DCHECK_EQ(RESOURCE_TYPE_BITMAP, resource->type); |
| 633 DCHECK(resource->allocated); | 633 DCHECK(resource->allocated); |
| 634 DCHECK_EQ(RGBA_8888, resource->format); | 634 DCHECK_EQ(RGBA_8888, resource->format); |
| 635 SkImageInfo source_info = | 635 SkImageInfo source_info = |
| 636 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height()); | 636 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height()); |
| 637 size_t image_stride = image_size.width() * 4; | 637 size_t image_stride = image_size.width() * 4; |
| 638 | 638 |
| 639 ScopedWriteLockSoftware lock(this, id); | 639 ScopedWriteLockSoftware lock(this, id); |
| 640 SkCanvas dest(lock.sk_bitmap()); | 640 SkCanvas dest(lock.sk_bitmap()); |
| 641 dest.writePixels(source_info, image, image_stride, 0, 0); | 641 dest.writePixels(source_info, image, image_stride, 0, 0); |
| 642 } else { | 642 } else { |
| 643 DCHECK(resource->gl_id); | 643 ScopedWriteLockGL lock(this, id); |
| 644 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); | 644 DCHECK(lock.texture_id()); |
| 645 GLES2Interface* gl = ContextGL(); | 645 GLES2Interface* gl = ContextGL(); |
| 646 DCHECK(gl); | 646 DCHECK(gl); |
| 647 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); | 647 gl->BindTexture(resource->target, lock.texture_id()); |
| 648 | |
| 649 if (resource->format == ETC1) { | 648 if (resource->format == ETC1) { |
| 649 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
| 650 int image_bytes = ResourceUtil::CheckedSizeInBytes<int>(image_size, ETC1); | 650 int image_bytes = ResourceUtil::CheckedSizeInBytes<int>(image_size, ETC1); |
| 651 gl->CompressedTexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(ETC1), | 651 gl->CompressedTexImage2D(resource->target, 0, GLInternalFormat(ETC1), |
| 652 image_size.width(), image_size.height(), 0, | 652 image_size.width(), image_size.height(), 0, |
| 653 image_bytes, image); | 653 image_bytes, image); |
| 654 } else { | 654 } else { |
| 655 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image_size.width(), | 655 gl->TexSubImage2D(resource->target, 0, 0, 0, image_size.width(), |
| 656 image_size.height(), GLDataFormat(resource->format), | 656 image_size.height(), GLDataFormat(resource->format), |
| 657 GLDataType(resource->format), image); | 657 GLDataType(resource->format), image); |
| 658 } | 658 } |
| 659 } | 659 } |
| 660 } | 660 } |
| 661 | 661 |
| 662 ResourceProvider::Resource* ResourceProvider::InsertResource( | 662 ResourceProvider::Resource* ResourceProvider::InsertResource( |
| 663 ResourceId id, | 663 ResourceId id, |
| 664 const Resource& resource) { | 664 const Resource& resource) { |
| 665 std::pair<ResourceMap::iterator, bool> result = | 665 std::pair<ResourceMap::iterator, bool> result = |
| (...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1640 const int kImportance = 2; | 1640 const int kImportance = 2; |
| 1641 pmd->CreateSharedGlobalAllocatorDump(guid); | 1641 pmd->CreateSharedGlobalAllocatorDump(guid); |
| 1642 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); | 1642 pmd->AddOwnershipEdge(dump->guid(), guid, kImportance); |
| 1643 } | 1643 } |
| 1644 } | 1644 } |
| 1645 | 1645 |
| 1646 return true; | 1646 return true; |
| 1647 } | 1647 } |
| 1648 | 1648 |
| 1649 } // namespace cc | 1649 } // namespace cc |
| OLD | NEW |