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

Unified Diff: gpu/command_buffer/common/gles2_cmd_utils.h

Issue 1028333002: Chromium -> Mojo roll. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation.cc ('k') | gpu/command_buffer/common/gles2_cmd_utils.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: gpu/command_buffer/common/gles2_cmd_utils.h
diff --git a/gpu/command_buffer/common/gles2_cmd_utils.h b/gpu/command_buffer/common/gles2_cmd_utils.h
index 1661247d313a6521e429b4e8c05c1b52087c29fb..e6b8bf09aa2f8146307b945fb3511db2b6c2adb0 100644
--- a/gpu/command_buffer/common/gles2_cmd_utils.h
+++ b/gpu/command_buffer/common/gles2_cmd_utils.h
@@ -14,6 +14,7 @@
#include <string>
#include <vector>
+#include "base/numerics/safe_math.h"
#include "gpu/command_buffer/common/gles2_utils_export.h"
namespace gpu {
@@ -25,44 +26,29 @@ namespace gles2 {
// Multiplies 2 32 bit unsigned numbers checking for overflow.
// If there was no overflow returns true.
inline bool SafeMultiplyUint32(uint32_t a, uint32_t b, uint32_t* dst) {
- if (b == 0) {
- *dst = 0;
- return true;
- }
- uint32_t v = a * b;
- if (v / b != a) {
- *dst = 0;
- return false;
- }
- *dst = v;
- return true;
+ DCHECK(dst);
+ base::CheckedNumeric<uint32_t> checked = a;
+ checked *= b;
+ *dst = checked.ValueOrDefault(0);
+ return checked.IsValid();
}
// Does an add checking for overflow. If there was no overflow returns true.
inline bool SafeAddUint32(uint32_t a, uint32_t b, uint32_t* dst) {
- if (a + b < a) {
- *dst = 0;
- return false;
- }
- *dst = a + b;
- return true;
+ DCHECK(dst);
+ base::CheckedNumeric<uint32_t> checked = a;
+ checked += b;
+ *dst = checked.ValueOrDefault(0);
+ return checked.IsValid();
}
// Does an add checking for overflow. If there was no overflow returns true.
inline bool SafeAddInt32(int32_t a, int32_t b, int32_t* dst) {
- int64_t sum64 = static_cast<int64_t>(a) + b;
- int32_t sum32 = static_cast<int32_t>(sum64);
- bool safe = sum64 == static_cast<int64_t>(sum32);
- *dst = safe ? sum32 : 0;
- return safe;
-}
-
-// Return false if |value| is more than a 32 bit integer can represent.
-template<typename T>
-inline bool FitInt32NonNegative(T value) {
- const int32_t max = std::numeric_limits<int32_t>::max();
- return (std::numeric_limits<T>::max() <= max ||
- value <= static_cast<T>(max));
+ DCHECK(dst);
+ base::CheckedNumeric<int32_t> checked = a;
+ checked += b;
+ *dst = checked.ValueOrDefault(0);
+ return checked.IsValid();
}
// Utilties for GLES2 support.
« no previous file with comments | « gpu/command_buffer/client/gles2_implementation.cc ('k') | gpu/command_buffer/common/gles2_cmd_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698