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" |
11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
12 #include "base/numerics/safe_math.h" | 12 #include "base/numerics/safe_math.h" |
13 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
14 #include "base/strings/string_split.h" | 14 #include "base/strings/string_split.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/trace_event/trace_event.h" | 16 #include "base/trace_event/trace_event.h" |
17 #include "cc/base/math_util.h" | |
18 #include "cc/resources/platform_color.h" | 17 #include "cc/resources/platform_color.h" |
| 18 #include "cc/resources/resource_util.h" |
19 #include "cc/resources/returned_resource.h" | 19 #include "cc/resources/returned_resource.h" |
20 #include "cc/resources/shared_bitmap_manager.h" | 20 #include "cc/resources/shared_bitmap_manager.h" |
21 #include "cc/resources/transferable_resource.h" | 21 #include "cc/resources/transferable_resource.h" |
22 #include "gpu/GLES2/gl2extchromium.h" | 22 #include "gpu/GLES2/gl2extchromium.h" |
23 #include "gpu/command_buffer/client/gles2_interface.h" | 23 #include "gpu/command_buffer/client/gles2_interface.h" |
24 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" | 24 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
25 #include "third_party/khronos/GLES2/gl2.h" | 25 #include "third_party/khronos/GLES2/gl2.h" |
26 #include "third_party/khronos/GLES2/gl2ext.h" | 26 #include "third_party/khronos/GLES2/gl2ext.h" |
27 #include "third_party/skia/include/core/SkSurface.h" | 27 #include "third_party/skia/include/core/SkSurface.h" |
28 #include "third_party/skia/include/gpu/GrContext.h" | 28 #include "third_party/skia/include/gpu/GrContext.h" |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 dest.writePixels(source_info, image, image_stride, 0, 0); | 711 dest.writePixels(source_info, image, image_stride, 0, 0); |
712 } else { | 712 } else { |
713 DCHECK(resource->gl_id); | 713 DCHECK(resource->gl_id); |
714 DCHECK(!resource->pending_set_pixels); | 714 DCHECK(!resource->pending_set_pixels); |
715 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); | 715 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); |
716 GLES2Interface* gl = ContextGL(); | 716 GLES2Interface* gl = ContextGL(); |
717 DCHECK(gl); | 717 DCHECK(gl); |
718 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); | 718 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); |
719 | 719 |
720 if (resource->format == ETC1) { | 720 if (resource->format == ETC1) { |
721 base::CheckedNumeric<int> num_bytes = BitsPerPixel(ETC1); | 721 int image_bytes = |
722 num_bytes *= image_size.width(); | 722 ResourceUtil::UncheckedMemorySizeBytes(image_size, ETC1); |
723 num_bytes *= image_size.height(); | |
724 num_bytes /= 8; | |
725 gl->CompressedTexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(ETC1), | 723 gl->CompressedTexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(ETC1), |
726 image_size.width(), image_size.height(), 0, | 724 image_size.width(), image_size.height(), 0, |
727 num_bytes.ValueOrDie(), image); | 725 image_bytes, image); |
728 } else { | 726 } else { |
729 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image_size.width(), | 727 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image_size.width(), |
730 image_size.height(), GLDataFormat(resource->format), | 728 image_size.height(), GLDataFormat(resource->format), |
731 GLDataType(resource->format), image); | 729 GLDataType(resource->format), image); |
732 } | 730 } |
733 } | 731 } |
734 } | 732 } |
735 | 733 |
736 ResourceProvider::Resource* ResourceProvider::InsertResource( | 734 ResourceProvider::Resource* ResourceProvider::InsertResource( |
737 ResourceId id, | 735 ResourceId id, |
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1517 DCHECK(!resource->image_id); | 1515 DCHECK(!resource->image_id); |
1518 DCHECK_NE(ETC1, resource->format); | 1516 DCHECK_NE(ETC1, resource->format); |
1519 | 1517 |
1520 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type); | 1518 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type); |
1521 GLES2Interface* gl = ContextGL(); | 1519 GLES2Interface* gl = ContextGL(); |
1522 DCHECK(gl); | 1520 DCHECK(gl); |
1523 if (!resource->gl_pixel_buffer_id) | 1521 if (!resource->gl_pixel_buffer_id) |
1524 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); | 1522 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); |
1525 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1523 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, |
1526 resource->gl_pixel_buffer_id); | 1524 resource->gl_pixel_buffer_id); |
1527 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8; | 1525 |
1528 gl->BufferData( | 1526 int resource_bytes = ResourceUtil::UncheckedMemorySizeBytesAligned( |
1529 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, | 1527 resource->size, resource->format); |
1530 resource->size.height() * | 1528 |
1531 MathUtil::RoundUp(bytes_per_pixel * resource->size.width(), 4u), | 1529 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, resource_bytes, NULL, |
1532 NULL, GL_DYNAMIC_DRAW); | 1530 GL_DYNAMIC_DRAW); |
1533 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); | 1531 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); |
1534 } | 1532 } |
1535 | 1533 |
1536 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { | 1534 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { |
1537 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 1535 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
1538 "ResourceProvider::ReleasePixelBuffer"); | 1536 "ResourceProvider::ReleasePixelBuffer"); |
1539 | 1537 |
1540 Resource* resource = GetResource(id); | 1538 Resource* resource = GetResource(id); |
1541 DCHECK(resource->origin == Resource::INTERNAL); | 1539 DCHECK(resource->origin == Resource::INTERNAL); |
1542 DCHECK_EQ(resource->exported_count, 0); | 1540 DCHECK_EQ(resource->exported_count, 0); |
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1945 } | 1943 } |
1946 | 1944 |
1947 class GrContext* ResourceProvider::GrContext(bool worker_context) const { | 1945 class GrContext* ResourceProvider::GrContext(bool worker_context) const { |
1948 ContextProvider* context_provider = | 1946 ContextProvider* context_provider = |
1949 worker_context ? output_surface_->worker_context_provider() | 1947 worker_context ? output_surface_->worker_context_provider() |
1950 : output_surface_->context_provider(); | 1948 : output_surface_->context_provider(); |
1951 return context_provider ? context_provider->GrContext() : NULL; | 1949 return context_provider ? context_provider->GrContext() : NULL; |
1952 } | 1950 } |
1953 | 1951 |
1954 } // namespace cc | 1952 } // namespace cc |
OLD | NEW |