Line data Source code
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 : */
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 : */
23 0 : static inline bool SkIsValidMode(SkBlendMode mode) {
24 0 : return (unsigned)mode <= (unsigned)SkBlendMode::kLastMode;
25 : }
26 :
27 : /** Returns true if the rect's dimensions are between 0 and SK_MaxS32
28 : */
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 : */
35 0 : static inline bool SkIsValidRect(const SkRect& rect) {
36 0 : return (rect.fLeft <= rect.fRight) &&
37 0 : (rect.fTop <= rect.fBottom) &&
38 0 : SkScalarIsFinite(rect.width()) &&
39 0 : SkScalarIsFinite(rect.height());
40 : }
41 :
42 : #endif
|