aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkValidationUtils.h
blob: 5e2b91d4d344a6b8013f05f03d23c63eb4ed34c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
 * 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 "SkBlendMode.h"
#include "SkXfermodePriv.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 SkBlendMode enum.
  */
static inline bool SkIsValidMode(SkBlendMode mode) {
    return (unsigned)mode <= (unsigned)SkBlendMode::kLastMode;
}

/** Returns true if the rect's dimensions are between 0 and SK_MaxS32
  */
static inline bool SkIsValidIRect(const SkIRect& rect) {
    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.fLeft <= rect.fRight) &&
           (rect.fTop <= rect.fBottom) &&
           SkScalarIsFinite(rect.width()) &&
           SkScalarIsFinite(rect.height());
}

#endif