xref: /aosp_15_r20/external/skia/src/core/SkValidationUtils.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 "include/core/SkBitmap.h"
12 #include "include/core/SkBlendMode.h"
13 
14 /** Returns true if mode's value is in the SkBlendMode enum.
15   */
SkIsValidMode(SkBlendMode mode)16 static inline bool SkIsValidMode(SkBlendMode mode) {
17     return (unsigned)mode <= (unsigned)SkBlendMode::kLastMode;
18 }
19 
20 /** Returns true if the rect's dimensions are between 0 and SK_MaxS32
21   */
SkIsValidIRect(const SkIRect & rect)22 static inline bool SkIsValidIRect(const SkIRect& rect) {
23     return rect.width() >= 0 && rect.height() >= 0;
24 }
25 
26 /** Returns true if the rect's dimensions are between 0 and SK_ScalarMax
27   */
SkIsValidRect(const SkRect & rect)28 static inline bool SkIsValidRect(const SkRect& rect) {
29     return (rect.fLeft <= rect.fRight) &&
30            (rect.fTop <= rect.fBottom) &&
31            SkIsFinite(rect.width(), rect.height());
32 }
33 
34 #endif
35