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

Unified Diff: src/core/SkValidationUtils.h

Issue 23021015: Initial error handling code (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Minor fixes Created 7 years, 3 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 | « src/core/SkValidatingReadBuffer.cpp ('k') | src/core/SkXfermode.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkValidationUtils.h
diff --git a/src/core/SkValidationUtils.h b/src/core/SkValidationUtils.h
new file mode 100644
index 0000000000000000000000000000000000000000..e4bb83332159f18be17ea2422ecd91fa87f35c45
--- /dev/null
+++ b/src/core/SkValidationUtils.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkValidationUtils_DEFINED
+#define SkValidationUtils_DEFINED
+
+#include "SkBitmap.h"
+#include "SkXfermode.h"
+
+/** Returns true if coeff's value is in the SkXfermode::Coeff enum.
+ */
+static inline bool SkIsValidCoeff(SkXfermode::Coeff coeff) {
+ return coeff >= 0 && coeff < SkXfermode::kCoeffCount;
+}
+
+/** Returns true if mode's value is in the SkXfermode::Mode enum.
+ */
+static inline bool SkIsValidMode(SkXfermode::Mode mode) {
+ return (mode >= 0) && (mode <= SkXfermode::kLastMode);
+}
+
+/** Returns true if config's value is in the SkBitmap::Config enum.
+ */
+static inline bool SkIsValidConfig(SkBitmap::Config config) {
+ return (config >= 0) && (config <= SkBitmap::kLastConfig);
+}
+
+/** Returns true if the rect's dimensions are between 0 and SK_MaxS32
+ */
+static inline bool SkIsValidRect(const SkIRect& rect) {
+ return !rect.isInverted() &&
+ // Make sure width() and height() are also valid
+ ((rect.fLeft >= 0) || (rect.fRight <= 0) ||
reed1 2013/09/04 20:37:41 Is this section the same as rect.width() >= 0 &&
+ ((rect.fRight - SK_MaxS32) <= rect.fLeft)) &&
+ ((rect.fTop >= 0) || (rect.fBottom <= 0) ||
+ ((rect.fBottom - SK_MaxS32) <= rect.fTop));
+}
+
+/** Returns true if the rect's dimensions are between 0 and SK_ScalarMax
+ */
+static inline bool SkIsValidRect(const SkRect& rect) {
+ return SkScalarIsFinite(rect.fLeft) &&
reed1 2013/09/04 20:37:41 Is all of this the same as return !rect.inverted(
+ SkScalarIsFinite(rect.fTop) &&
+ SkScalarIsFinite(rect.fRight) &&
+ SkScalarIsFinite(rect.fBottom) &&
+ !rect.isInverted() &&
+ // Make sure width() and height() are also valid
+ ((rect.fLeft >= 0) || (rect.fRight <= 0) ||
+ ((rect.fRight - SK_ScalarMax) <= rect.fLeft)) &&
+ ((rect.fTop >= 0) || (rect.fBottom <= 0) ||
+ ((rect.fBottom - SK_ScalarMax) <= rect.fTop));
+}
+
+#endif
« no previous file with comments | « src/core/SkValidatingReadBuffer.cpp ('k') | src/core/SkXfermode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698