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/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 gfx::Vector2d source_offset = source_rect.origin() - image_rect.origin(); | 773 gfx::Vector2d source_offset = source_rect.origin() - image_rect.origin(); |
774 image += source_offset.y() * image_row_bytes + source_offset.x() * 4; | 774 image += source_offset.y() * image_row_bytes + source_offset.x() * 4; |
775 | 775 |
776 ScopedWriteLockSoftware lock(this, id); | 776 ScopedWriteLockSoftware lock(this, id); |
777 SkCanvas dest(lock.sk_bitmap()); | 777 SkCanvas dest(lock.sk_bitmap()); |
778 dest.writePixels(source_info, image, image_row_bytes, dest_offset.x(), | 778 dest.writePixels(source_info, image, image_row_bytes, dest_offset.x(), |
779 dest_offset.y()); | 779 dest_offset.y()); |
780 } | 780 } |
781 } | 781 } |
782 | 782 |
| 783 void ResourceProvider::CopyToResource(ResourceId id, |
| 784 const uint8_t* image, |
| 785 const gfx::Size& image_size) { |
| 786 Resource* resource = GetResource(id); |
| 787 DCHECK(!resource->locked_for_write); |
| 788 DCHECK(!resource->lock_for_read_count); |
| 789 DCHECK(resource->origin == Resource::Internal); |
| 790 DCHECK_EQ(resource->exported_count, 0); |
| 791 DCHECK(ReadLockFenceHasPassed(resource)); |
| 792 LazyAllocate(resource); |
| 793 |
| 794 DCHECK_EQ(image_size.width(), resource->size.width()); |
| 795 DCHECK_EQ(image_size.height(), resource->size.height()); |
| 796 |
| 797 if (resource->type == Bitmap) { |
| 798 DCHECK_EQ(Bitmap, resource->type); |
| 799 DCHECK(resource->allocated); |
| 800 DCHECK_EQ(RGBA_8888, resource->format); |
| 801 SkImageInfo source_info = |
| 802 SkImageInfo::MakeN32Premul(image_size.width(), image_size.height()); |
| 803 size_t image_stride = image_size.width() * 4; |
| 804 |
| 805 ScopedWriteLockSoftware lock(this, id); |
| 806 SkCanvas dest(lock.sk_bitmap()); |
| 807 dest.writePixels(source_info, image, image_stride, 0, 0); |
| 808 } else { |
| 809 DCHECK(resource->gl_id); |
| 810 DCHECK(!resource->pending_set_pixels); |
| 811 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
| 812 GLES2Interface* gl = ContextGL(); |
| 813 DCHECK(gl); |
| 814 DCHECK(texture_uploader_.get()); |
| 815 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); |
| 816 |
| 817 if (resource->format == ETC1) { |
| 818 size_t num_bytes = static_cast<size_t>(image_size.width()) * |
| 819 image_size.height() * BitsPerPixel(ETC1) / 8; |
| 820 gl->CompressedTexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(ETC1), |
| 821 image_size.width(), image_size.height(), 0, |
| 822 num_bytes, image); |
| 823 } else { |
| 824 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image_size.width(), |
| 825 image_size.height(), GLDataFormat(resource->format), |
| 826 GLDataType(resource->format), image); |
| 827 } |
| 828 } |
| 829 } |
| 830 |
783 size_t ResourceProvider::NumBlockingUploads() { | 831 size_t ResourceProvider::NumBlockingUploads() { |
784 if (!texture_uploader_) | 832 if (!texture_uploader_) |
785 return 0; | 833 return 0; |
786 | 834 |
787 return texture_uploader_->NumBlockingUploads(); | 835 return texture_uploader_->NumBlockingUploads(); |
788 } | 836 } |
789 | 837 |
790 void ResourceProvider::MarkPendingUploadsAsNonBlocking() { | 838 void ResourceProvider::MarkPendingUploadsAsNonBlocking() { |
791 if (!texture_uploader_) | 839 if (!texture_uploader_) |
792 return; | 840 return; |
(...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2146 } | 2194 } |
2147 | 2195 |
2148 class GrContext* ResourceProvider::GrContext(bool worker_context) const { | 2196 class GrContext* ResourceProvider::GrContext(bool worker_context) const { |
2149 ContextProvider* context_provider = | 2197 ContextProvider* context_provider = |
2150 worker_context ? output_surface_->worker_context_provider() | 2198 worker_context ? output_surface_->worker_context_provider() |
2151 : output_surface_->context_provider(); | 2199 : output_surface_->context_provider(); |
2152 return context_provider ? context_provider->GrContext() : NULL; | 2200 return context_provider ? context_provider->GrContext() : NULL; |
2153 } | 2201 } |
2154 | 2202 |
2155 } // namespace cc | 2203 } // namespace cc |
OLD | NEW |