michael@0: /* michael@0: * Copyright 2013 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkValidationUtils_DEFINED michael@0: #define SkValidationUtils_DEFINED michael@0: michael@0: #include "SkBitmap.h" michael@0: #include "SkXfermode.h" michael@0: michael@0: /** Returns true if coeff's value is in the SkXfermode::Coeff enum. michael@0: */ michael@0: static inline bool SkIsValidCoeff(SkXfermode::Coeff coeff) { michael@0: return coeff >= 0 && coeff < SkXfermode::kCoeffCount; michael@0: } michael@0: michael@0: /** Returns true if mode's value is in the SkXfermode::Mode enum. michael@0: */ michael@0: static inline bool SkIsValidMode(SkXfermode::Mode mode) { michael@0: return (mode >= 0) && (mode <= SkXfermode::kLastMode); michael@0: } michael@0: michael@0: /** Returns true if config's value is in the SkBitmap::Config enum. michael@0: */ michael@0: static inline bool SkIsValidConfig(SkBitmap::Config config) { michael@0: return (config >= 0) && (config <= static_cast(SkBitmap::kConfigCount)); michael@0: } michael@0: michael@0: /** Returns true if the rect's dimensions are between 0 and SK_MaxS32 michael@0: */ michael@0: static inline bool SkIsValidIRect(const SkIRect& rect) { michael@0: return rect.width() >= 0 && rect.height() >= 0; michael@0: } michael@0: michael@0: /** Returns true if the rect's dimensions are between 0 and SK_ScalarMax michael@0: */ michael@0: static inline bool SkIsValidRect(const SkRect& rect) { michael@0: return (rect.fLeft <= rect.fRight) && michael@0: (rect.fTop <= rect.fBottom) && michael@0: SkScalarIsFinite(rect.width()) && michael@0: SkScalarIsFinite(rect.height()); michael@0: } michael@0: michael@0: #endif