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

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: Corrected comments. Created 5 years, 5 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
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 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = ResourceUtil::CheckedSizeInBytes(image_size, ETC1);
vmpstr 2015/07/16 19:04:00 This will cause a possible truncation size_t -> in
722 num_bytes *= image_size.width();
723 num_bytes *= image_size.height();
724 num_bytes /= 8;
725 gl->CompressedTexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(ETC1), 722 gl->CompressedTexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(ETC1),
726 image_size.width(), image_size.height(), 0, 723 image_size.width(), image_size.height(), 0,
727 num_bytes.ValueOrDie(), image); 724 image_bytes, image);
728 } else { 725 } else {
729 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image_size.width(), 726 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image_size.width(),
730 image_size.height(), GLDataFormat(resource->format), 727 image_size.height(), GLDataFormat(resource->format),
731 GLDataType(resource->format), image); 728 GLDataType(resource->format), image);
732 } 729 }
733 } 730 }
734 } 731 }
735 732
736 ResourceProvider::Resource* ResourceProvider::InsertResource( 733 ResourceProvider::Resource* ResourceProvider::InsertResource(
737 ResourceId id, 734 ResourceId id,
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
1517 DCHECK(!resource->image_id); 1514 DCHECK(!resource->image_id);
1518 DCHECK_NE(ETC1, resource->format); 1515 DCHECK_NE(ETC1, resource->format);
1519 1516
1520 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type); 1517 DCHECK_EQ(RESOURCE_TYPE_GL_TEXTURE, resource->type);
1521 GLES2Interface* gl = ContextGL(); 1518 GLES2Interface* gl = ContextGL();
1522 DCHECK(gl); 1519 DCHECK(gl);
1523 if (!resource->gl_pixel_buffer_id) 1520 if (!resource->gl_pixel_buffer_id)
1524 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId(); 1521 resource->gl_pixel_buffer_id = buffer_id_allocator_->NextId();
1525 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1522 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM,
1526 resource->gl_pixel_buffer_id); 1523 resource->gl_pixel_buffer_id);
1527 unsigned bytes_per_pixel = BitsPerPixel(resource->format) / 8; 1524 int resource_bytes = ResourceUtil::UncheckedSizeInBytesAligned(
vmpstr 2015/07/16 19:04:00 I don't think this will compile on windows because
prashant.n 2015/07/22 15:44:58 I'll change this to size_t. But BufferData takes s
1528 gl->BufferData( 1525 resource->size, resource->format);
1529 GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 1526 gl->BufferData(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, resource_bytes, NULL,
1530 resource->size.height() * 1527 GL_DYNAMIC_DRAW);
1531 MathUtil::RoundUp(bytes_per_pixel * resource->size.width(), 4u),
1532 NULL, GL_DYNAMIC_DRAW);
1533 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0); 1528 gl->BindBuffer(GL_PIXEL_UNPACK_TRANSFER_BUFFER_CHROMIUM, 0);
1534 } 1529 }
1535 1530
1536 void ResourceProvider::ReleasePixelBuffer(ResourceId id) { 1531 void ResourceProvider::ReleasePixelBuffer(ResourceId id) {
1537 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 1532 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
1538 "ResourceProvider::ReleasePixelBuffer"); 1533 "ResourceProvider::ReleasePixelBuffer");
1539 1534
1540 Resource* resource = GetResource(id); 1535 Resource* resource = GetResource(id);
1541 DCHECK(resource->origin == Resource::INTERNAL); 1536 DCHECK(resource->origin == Resource::INTERNAL);
1542 DCHECK_EQ(resource->exported_count, 0); 1537 DCHECK_EQ(resource->exported_count, 0);
(...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1945 } 1940 }
1946 1941
1947 class GrContext* ResourceProvider::GrContext(bool worker_context) const { 1942 class GrContext* ResourceProvider::GrContext(bool worker_context) const {
1948 ContextProvider* context_provider = 1943 ContextProvider* context_provider =
1949 worker_context ? output_surface_->worker_context_provider() 1944 worker_context ? output_surface_->worker_context_provider()
1950 : output_surface_->context_provider(); 1945 : output_surface_->context_provider();
1951 return context_provider ? context_provider->GrContext() : NULL; 1946 return context_provider ? context_provider->GrContext() : NULL;
1952 } 1947 }
1953 1948
1954 } // namespace cc 1949 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698