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

Side by Side Diff: cc/tiles/mipmap_util.cc

Issue 2105903003: Remove error handling from MipmapUtil and add DCHECKs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fixdrt
Patch Set: rebase Created 4 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
« no previous file with comments | « cc/tiles/mipmap_util.h ('k') | cc/tiles/mipmap_util_unittest.cc » ('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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/tiles/mipmap_util.h" 5 #include "cc/tiles/mipmap_util.h"
6 6
7 namespace cc { 7 namespace cc {
8 namespace { 8 namespace {
9 // Calculates the size of |axis_base_size| at the given |mip_level| using 9 // Calculates the size of |axis_base_size| at the given |mip_level| using
10 // OpenGL rounding rules. 10 // OpenGL rounding rules.
11 int ScaleAxisToMipLevel(int axis_base_size, int mip_level) { 11 int ScaleAxisToMipLevel(int axis_base_size, int mip_level) {
12 DCHECK_GE(mip_level, 0); 12 DCHECK_GE(mip_level, 0);
13 DCHECK_LT(mip_level, 32); 13 DCHECK_LT(mip_level, 32);
14 return std::max(1, axis_base_size >> mip_level); 14 return std::max(1, axis_base_size >> mip_level);
15 } 15 }
16 16
17 } // namespace 17 } // namespace
18 18
19 int MipMapUtil::GetLevelForSize(const gfx::Size& src_size, 19 int MipMapUtil::GetLevelForSize(const gfx::Size& src_size,
20 const gfx::Size& target_size) { 20 const gfx::Size& target_size) {
21 int src_height = src_size.height(); 21 int src_height = src_size.height();
22 int src_width = src_size.width(); 22 int src_width = src_size.width();
23 int target_height = target_size.height(); 23 int target_height = target_size.height();
24 int target_width = target_size.width(); 24 int target_width = target_size.width();
25 bool target_invalid = target_height == 0 || target_width == 0; 25 DCHECK_GT(target_height, 0);
26 bool src_invalid = src_height == 0 || src_width == 0; 26 DCHECK_GT(target_width, 0);
27 if (target_invalid || src_invalid) 27 DCHECK_GT(src_width, 0);
28 return -1; 28 DCHECK_GT(src_height, 0);
29 29
30 int next_mip_height = src_height; 30 int next_mip_height = src_height;
31 int next_mip_width = src_width; 31 int next_mip_width = src_width;
32 for (int current_mip_level = 0;; current_mip_level++) { 32 for (int current_mip_level = 0;; current_mip_level++) {
33 int mip_height = next_mip_height; 33 int mip_height = next_mip_height;
34 int mip_width = next_mip_width; 34 int mip_width = next_mip_width;
35 35
36 next_mip_height = ScaleAxisToMipLevel(src_height, current_mip_level + 1); 36 next_mip_height = ScaleAxisToMipLevel(src_height, current_mip_level + 1);
37 next_mip_width = ScaleAxisToMipLevel(src_width, current_mip_level + 1); 37 next_mip_width = ScaleAxisToMipLevel(src_width, current_mip_level + 1);
38 38
39 // Check if an axis on the next mip level would be smaller than the target. 39 // Check if an axis on the next mip level would be smaller than the target.
40 // If so, use the current mip level. 40 // If so, use the current mip level.
41 // This effectively always uses the larger image and always scales down. 41 // This effectively always uses the larger image and always scales down.
42 if (next_mip_height < target_height || next_mip_width < target_width) { 42 if (next_mip_height < target_height || next_mip_width < target_width) {
43 return current_mip_level; 43 return current_mip_level;
44 } 44 }
45 45
46 if (mip_height == 1 && mip_width == 1) { 46 if (mip_height == 1 && mip_width == 1) {
47 // We have reached the final mip level 47 // We have reached the final mip level
48 return current_mip_level; 48 return current_mip_level;
49 } 49 }
50 } 50 }
51 } 51 }
52 52
53 SkSize MipMapUtil::GetScaleAdjustmentForLevel(const gfx::Size& src_size, 53 SkSize MipMapUtil::GetScaleAdjustmentForLevel(const gfx::Size& src_size,
54 int mip_level) { 54 int mip_level) {
55 if (src_size.width() == 0 || src_size.height() == 0 || mip_level == -1) 55 DCHECK_GT(src_size.width(), 0);
56 return SkSize::Make(-1, -1); 56 DCHECK_GT(src_size.height(), 0);
57 DCHECK_GE(mip_level, 0);
57 58
58 gfx::Size target_size = GetSizeForLevel(src_size, mip_level); 59 gfx::Size target_size = GetSizeForLevel(src_size, mip_level);
59 60
60 return SkSize::Make( 61 return SkSize::Make(
61 static_cast<float>(target_size.width()) / src_size.width(), 62 static_cast<float>(target_size.width()) / src_size.width(),
62 static_cast<float>(target_size.height()) / src_size.height()); 63 static_cast<float>(target_size.height()) / src_size.height());
63 } 64 }
64 65
65 gfx::Size MipMapUtil::GetSizeForLevel(const gfx::Size& src_size, 66 gfx::Size MipMapUtil::GetSizeForLevel(const gfx::Size& src_size,
66 int mip_level) { 67 int mip_level) {
67 if (src_size.width() == 0 || src_size.height() == 0 || mip_level == -1) 68 DCHECK_GT(src_size.width(), 0);
68 return gfx::Size(-1, -1); 69 DCHECK_GT(src_size.height(), 0);
70 DCHECK_GE(mip_level, 0);
69 71
70 return gfx::Size(ScaleAxisToMipLevel(src_size.width(), mip_level), 72 return gfx::Size(ScaleAxisToMipLevel(src_size.width(), mip_level),
71 ScaleAxisToMipLevel(src_size.height(), mip_level)); 73 ScaleAxisToMipLevel(src_size.height(), mip_level));
72 } 74 }
73 75
74 SkSize MipMapUtil::GetScaleAdjustmentForSize(const gfx::Size& src_size, 76 SkSize MipMapUtil::GetScaleAdjustmentForSize(const gfx::Size& src_size,
75 const gfx::Size& target_size) { 77 const gfx::Size& target_size) {
76 int target_mip_level = GetLevelForSize(src_size, target_size); 78 int target_mip_level = GetLevelForSize(src_size, target_size);
77 return GetScaleAdjustmentForLevel(src_size, target_mip_level); 79 return GetScaleAdjustmentForLevel(src_size, target_mip_level);
78 } 80 }
79 81
80 } // namespace cc 82 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/mipmap_util.h ('k') | cc/tiles/mipmap_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698