blob: 84b906a650aa13be7bb76701e843e3444280c53c [file] [log] [blame]
commit-bot@chromium.orgc0b7e102013-10-23 17:06:21 +00001/*
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"
Mike Reed7d954ad2016-10-28 15:42:34 -040012#include "SkBlendMode.h"
Hal Canary6b20a552017-02-07 14:09:38 -050013#include "SkXfermodePriv.h"
commit-bot@chromium.orgc0b7e102013-10-23 17:06:21 +000014
Mike Reed7d954ad2016-10-28 15:42:34 -040015/** Returns true if mode's value is in the SkBlendMode enum.
commit-bot@chromium.orgc0b7e102013-10-23 17:06:21 +000016 */
Mike Reed7d954ad2016-10-28 15:42:34 -040017static inline bool SkIsValidMode(SkBlendMode mode) {
18 return (unsigned)mode <= (unsigned)SkBlendMode::kLastMode;
commit-bot@chromium.orgc0b7e102013-10-23 17:06:21 +000019}
20
commit-bot@chromium.orgc0b7e102013-10-23 17:06:21 +000021/** Returns true if the rect's dimensions are between 0 and SK_MaxS32
22 */
23static inline bool SkIsValidIRect(const SkIRect& rect) {
24 return rect.width() >= 0 && rect.height() >= 0;
25}
26
27/** Returns true if the rect's dimensions are between 0 and SK_ScalarMax
28 */
29static inline bool SkIsValidRect(const SkRect& rect) {
30 return (rect.fLeft <= rect.fRight) &&
31 (rect.fTop <= rect.fBottom) &&
32 SkScalarIsFinite(rect.width()) &&
33 SkScalarIsFinite(rect.height());
34}
35
36#endif