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

Side by Side Diff: cc/resources/resource_util.h

Issue 1900053002: cc: Use std::is_same in resource_util.h. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 | « no previous file | 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 #ifndef CC_RESOURCES_RESOURCE_UTIL_H_ 5 #ifndef CC_RESOURCES_RESOURCE_UTIL_H_
6 #define CC_RESOURCES_RESOURCE_UTIL_H_ 6 #define CC_RESOURCES_RESOURCE_UTIL_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 // this for computing widths for sizes that have already been checked. 48 // this for computing widths for sizes that have already been checked.
49 template <typename T> 49 template <typename T>
50 static T UncheckedWidthInBytesAligned(int width, ResourceFormat format); 50 static T UncheckedWidthInBytesAligned(int width, ResourceFormat format);
51 // Returns the size in bytes aligned but may overflow or return 0. Only do 51 // Returns the size in bytes aligned but may overflow or return 0. Only do
52 // this for sizes that have already been checked. 52 // this for sizes that have already been checked.
53 template <typename T> 53 template <typename T>
54 static T UncheckedSizeInBytesAligned(const gfx::Size& size, 54 static T UncheckedSizeInBytesAligned(const gfx::Size& size,
55 ResourceFormat format); 55 ResourceFormat format);
56 56
57 private: 57 private:
58 // TODO(prashant.n): Replace IsSameType with std::is_same once C++11 is used
59 // on all platforms.
60 template <typename T, typename U>
61 struct IsSameType {
62 static const bool value = false;
63 };
64
65 template <typename T>
66 struct IsSameType<T, T> {
67 static const bool value = true;
68 };
69
70 template <typename T> 58 template <typename T>
71 static inline void VerifyType(); 59 static inline void VerifyType();
72 60
73 template <typename T> 61 template <typename T>
74 static bool VerifyFitsInBytesInternal(int width, 62 static bool VerifyFitsInBytesInternal(int width,
75 int height, 63 int height,
76 ResourceFormat format, 64 ResourceFormat format,
77 bool verify_size, 65 bool verify_size,
78 bool aligned); 66 bool aligned);
79 67
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 ResourceFormat format) { 142 ResourceFormat format) {
155 VerifyType<T>(); 143 VerifyType<T>();
156 DCHECK(VerifyFitsInBytesInternal<T>(size.width(), size.height(), format, true, 144 DCHECK(VerifyFitsInBytesInternal<T>(size.width(), size.height(), format, true,
157 true)); 145 true));
158 return BytesInternal<T>(size.width(), size.height(), format, true, true); 146 return BytesInternal<T>(size.width(), size.height(), format, true, true);
159 } 147 }
160 148
161 template <typename T> 149 template <typename T>
162 void ResourceUtil::VerifyType() { 150 void ResourceUtil::VerifyType() {
163 static_assert( 151 static_assert(
164 std::numeric_limits<T>::is_integer && !IsSameType<T, bool>::value, 152 std::numeric_limits<T>::is_integer && !std::is_same<T, bool>::value,
165 "T must be non-bool integer type. Preferred type is size_t."); 153 "T must be non-bool integer type. Preferred type is size_t.");
166 } 154 }
167 155
168 template <typename T> 156 template <typename T>
169 bool ResourceUtil::VerifyFitsInBytesInternal(int width, 157 bool ResourceUtil::VerifyFitsInBytesInternal(int width,
170 int height, 158 int height,
171 ResourceFormat format, 159 ResourceFormat format,
172 bool verify_size, 160 bool verify_size,
173 bool aligned) { 161 bool aligned) {
174 base::CheckedNumeric<T> checked_value = BitsPerPixel(format); 162 base::CheckedNumeric<T> checked_value = BitsPerPixel(format);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 bytes = MathUtil::UncheckedRoundUp<T>(bytes, 4); 204 bytes = MathUtil::UncheckedRoundUp<T>(bytes, 4);
217 if (verify_size) 205 if (verify_size)
218 bytes *= height; 206 bytes *= height;
219 207
220 return bytes; 208 return bytes;
221 } 209 }
222 210
223 } // namespace cc 211 } // namespace cc
224 212
225 #endif // CC_RESOURCES_RESOURCE_UTIL_H_ 213 #endif // CC_RESOURCES_RESOURCE_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698