Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(891)

Side by Side Diff: cc/resources/resource_provider.cc

Issue 1202843008: cc: Fix BytesPerPixel issue and refactor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed Android build break. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 688 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 dest.writePixels(source_info, image, image_stride, 0, 0); 717 dest.writePixels(source_info, image, image_stride, 0, 0);
718 } else { 718 } else {
719 DCHECK(resource->gl_id); 719 DCHECK(resource->gl_id);
720 DCHECK(!resource->pending_set_pixels); 720 DCHECK(!resource->pending_set_pixels);
721 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); 721 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D));
722 GLES2Interface* gl = ContextGL(); 722 GLES2Interface* gl = ContextGL();
723 DCHECK(gl); 723 DCHECK(gl);
724 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); 724 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id);
725 725
726 if (resource->format == ETC1) { 726 if (resource->format == ETC1) {
727 base::CheckedNumeric<int> num_bytes = BitsPerPixel(ETC1); 727 int image_bytes = ResourceUtil::CheckedSizeInBytes<int>(image_size, ETC1);
728 num_bytes *= image_size.width();
729 num_bytes *= image_size.height();
730 num_bytes /= 8;
731 gl->CompressedTexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(ETC1), 728 gl->CompressedTexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(ETC1),
732 image_size.width(), image_size.height(), 0, 729 image_size.width(), image_size.height(), 0,
733 num_bytes.ValueOrDie(), image); 730 image_bytes, image);
734 } else { 731 } else {
735 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image_size.width(), 732 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image_size.width(),
736 image_size.height(), GLDataFormat(resource->format), 733 image_size.height(), GLDataFormat(resource->format),
737 GLDataType(resource->format), image); 734 GLDataType(resource->format), image);
738 } 735 }
739 } 736 }
740 } 737 }
741 738
742 ResourceProvider::Resource* ResourceProvider::InsertResource( 739 ResourceProvider::Resource* ResourceProvider::InsertResource(
743 ResourceId id, 740 ResourceId id,
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 DCHECK(!resource->image_id); 1521 DCHECK(!resource->image_id);
1525 DCHECK_NE(ETC1, resource->format); 1522 DCHECK_NE(ETC1, resource->format);
1526 1523
1527 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type); 1524 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type);
1528 GLES2Interface* gl = ContextGL(); 1525 GLES2Interface* gl = ContextGL();
1529 DCHECK(gl); 1526 DCHECK(gl);
1530 if (!resource->gl_pixel_buffer_id) 1527 if (!resource->gl_pixel_buffer_id)
1531 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); 1528 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId();
1532 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1529 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1533 resource->gl_pixel_buffer_id); 1530 resource->gl_pixel_buffer_id);
1534 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8; 1531 size_t resource_bytes = ResourceUtil::UncheckedSizeInBytesAligned<size_t>(
1535 gl->BufferData( 1532 resource->size, resource->format);
1536 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1533 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, resource_bytes, NULL,
1537 resource->size.height() * 1534 GL_DYNAMIC_DRAW);
1538 MathUtil::RoundUp(bytes_per_pixel * resource->size.width(), 4u),
1539 NULL, GL_DYNAMIC_DRAW);
1540 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1535 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1541 } 1536 }
1542 1537
1543 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { 1538 void ResourceProvider::ReleasePixelBuffer(ResourceId id) {
1544 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 1539 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
1545 "ResourceProvider::ReleasePixelBuffer"); 1540 "ResourceProvider::ReleasePixelBuffer");
1546 1541
1547 Resource* resource = GetResource(id); 1542 Resource* resource = GetResource(id);
1548 DCHECK(resource->origin == Resource::INTERNAL); 1543 DCHECK(resource->origin == Resource::INTERNAL);
1549 DCHECK_EQ(resource->exported_count, 0); 1544 DCHECK_EQ(resource->exported_count, 0);
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1952 } 1947 }
1953 1948
1954 class GrContext* ResourceProvider::GrContext(bool worker_context) const { 1949 class GrContext* ResourceProvider::GrContext(bool worker_context) const {
1955 ContextProvider* context_provider = 1950 ContextProvider* context_provider =
1956 worker_context ? output_surface_->worker_context_provider() 1951 worker_context ? output_surface_->worker_context_provider()
1957 : output_surface_->context_provider(); 1952 : output_surface_->context_provider();
1958 return context_provider ? context_provider->GrContext() : NULL; 1953 return context_provider ? context_provider->GrContext() : NULL;
1959 } 1954 }
1960 1955
1961 } // namespace cc 1956 } // namespace cc
OLDNEW
« no previous file with comments | « cc/resources/resource_provider.h ('k') | cc/resources/resource_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698