Home | History | Annotate | Download | only in core
      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 mode's value is in the SkBlendMode enum.
     16   */
     17 static inline bool SkIsValidMode(SkBlendMode mode) {
     18     return (unsigned)mode <= (unsigned)SkBlendMode::kLastMode;
     19 }
     20 
     21 /** Returns true if the rect's dimensions are between 0 and SK_MaxS32
     22   */
     23 static 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   */
     29 static 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
     37