1 /*
2  * Copyright 2013 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkValidationUtils_DEFINED
9 #define SkValidationUtils_DEFINED
10 
11 #include "SkBitmap.h"
12 #include "SkBlendMode.h"
13 #include "SkXfermodePriv.h"
14 
15 /** Returns true if coeff's value is in the SkXfermode::Coeff enum.
16   */
SkIsValidCoeff(SkXfermode::Coeff coeff)17 static inline bool SkIsValidCoeff(SkXfermode::Coeff coeff) {
18     return coeff >= 0 && coeff < SkXfermode::kCoeffCount;
19 }
20 
21 /** Returns true if mode's value is in the SkBlendMode enum.
22   */
SkIsValidMode(SkBlendMode mode)23 static inline bool SkIsValidMode(SkBlendMode mode) {
24     return (unsigned)mode <= (unsigned)SkBlendMode::kLastMode;
25 }
26 
27 /** Returns true if the rect's dimensions are between 0 and SK_MaxS32
28   */
SkIsValidIRect(const SkIRect & rect)29 static inline bool SkIsValidIRect(const SkIRect& rect) {
30     return rect.width() >= 0 && rect.height() >= 0;
31 }
32 
33 /** Returns true if the rect's dimensions are between 0 and SK_ScalarMax
34   */
SkIsValidRect(const SkRect & rect)35 static inline bool SkIsValidRect(const SkRect& rect) {
36     return (rect.fLeft <= rect.fRight) &&
37            (rect.fTop <= rect.fBottom) &&
38            SkScalarIsFinite(rect.width()) &&
39            SkScalarIsFinite(rect.height());
40 }
41 
42 #endif
43