Chromium Code Reviews| Index: src/core/SkValidationUtils.h |
| diff --git a/src/core/SkValidationUtils.h b/src/core/SkValidationUtils.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f31d86ce2289936c960ff25b556baca7bf14e7b4 |
| --- /dev/null |
| +++ b/src/core/SkValidationUtils.h |
| @@ -0,0 +1,46 @@ |
| +/* |
| + * 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) { |
|
mtklein
2013/09/24 22:52:18
I sort of want these to live with their correspond
sugoi1
2013/09/25 21:15:27
I'm not sure about this, but I don't have a strong
|
| + 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) { |
|
mtklein
2013/09/24 22:52:18
This is going to be a little confusing. Let's cal
sugoi1
2013/09/25 21:15:27
Done.
|
| + return rect.width() >= 0 && rect.height() >= 0; |
| +} |
| + |
| +/** Returns true if the rect's dimensions are between 0 and SK_ScalarMax |
| + */ |
| +static inline bool SkIsValidRect(const SkRect& rect) { |
| + return !rect.isInverted() && |
| + SkScalarIsFinite(rect.width()) && |
| + SkScalarIsFinite(rect.height()); |
| +} |
| + |
| +#endif |