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

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

Issue 1154393003: cc: Use CheckedNumeric for resource size calculations. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
« cc/resources/resource.h ('K') | « cc/resources/resource.h ('k') | no next file » | 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/stl_util.h" 13 #include "base/stl_util.h"
13 #include "base/strings/string_split.h" 14 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 15 #include "base/strings/string_util.h"
15 #include "base/trace_event/trace_event.h" 16 #include "base/trace_event/trace_event.h"
16 #include "cc/base/math_util.h" 17 #include "cc/base/math_util.h"
17 #include "cc/resources/platform_color.h" 18 #include "cc/resources/platform_color.h"
18 #include "cc/resources/returned_resource.h" 19 #include "cc/resources/returned_resource.h"
19 #include "cc/resources/shared_bitmap_manager.h" 20 #include "cc/resources/shared_bitmap_manager.h"
20 #include "cc/resources/texture_uploader.h" 21 #include "cc/resources/texture_uploader.h"
21 #include "cc/resources/transferable_resource.h" 22 #include "cc/resources/transferable_resource.h"
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 } else { 766 } else {
766 DCHECK(resource->gl_id); 767 DCHECK(resource->gl_id);
767 DCHECK(!resource->pending_set_pixels); 768 DCHECK(!resource->pending_set_pixels);
768 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D)); 769 DCHECK_EQ(resource->target, static_cast<GLenum>(GL_TEXTURE_2D));
769 GLES2Interface* gl = ContextGL(); 770 GLES2Interface* gl = ContextGL();
770 DCHECK(gl); 771 DCHECK(gl);
771 DCHECK(texture_uploader_.get()); 772 DCHECK(texture_uploader_.get());
772 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id); 773 gl->BindTexture(GL_TEXTURE_2D, resource->gl_id);
773 774
774 if (resource->format == ETC1) { 775 if (resource->format == ETC1) {
775 // TODO(vmpstr): Make this overflow safe. crbug.com/495867 776 base::CheckedNumeric<int> num_bytes = BitsPerPixel(ETC1);
danakj 2015/06/04 19:02:38 This function is called with less trustworthy info
776 int num_bytes = 777 num_bytes *= image_size.width();
777 image_size.width() * image_size.height() * BitsPerPixel(ETC1) / 8; 778 num_bytes *= image_size.height();
779 num_bytes /= 8;
778 gl->CompressedTexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(ETC1), 780 gl->CompressedTexImage2D(GL_TEXTURE_2D, 0, GLInternalFormat(ETC1),
779 image_size.width(), image_size.height(), 0, 781 image_size.width(), image_size.height(), 0,
780 num_bytes, image); 782 num_bytes.ValueOrDie(), image);
781 } else { 783 } else {
782 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image_size.width(), 784 gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, image_size.width(),
783 image_size.height(), GLDataFormat(resource->format), 785 image_size.height(), GLDataFormat(resource->format),
784 GLDataType(resource->format), image); 786 GLDataType(resource->format), image);
785 } 787 }
786 } 788 }
787 } 789 }
788 790
789 size_t ResourceProvider::NumBlockingUploads() { 791 size_t ResourceProvider::NumBlockingUploads() {
790 if (!texture_uploader_) 792 if (!texture_uploader_)
(...skipping 1265 matching lines...) Expand 10 before | Expand all | Expand 10 after
2056 } 2058 }
2057 2059
2058 class GrContext* ResourceProvider::GrContext(bool worker_context) const { 2060 class GrContext* ResourceProvider::GrContext(bool worker_context) const {
2059 ContextProvider* context_provider = 2061 ContextProvider* context_provider =
2060 worker_context ? output_surface_->worker_context_provider() 2062 worker_context ? output_surface_->worker_context_provider()
2061 : output_surface_->context_provider(); 2063 : output_surface_->context_provider();
2062 return context_provider ? context_provider->GrContext() : NULL; 2064 return context_provider ? context_provider->GrContext() : NULL;
2063 } 2065 }
2064 2066
2065 } // namespace cc 2067 } // namespace cc
OLDNEW
« cc/resources/resource.h ('K') | « cc/resources/resource.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698