1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/core/SkValidationUtils.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,47 @@ 1.4 +/* 1.5 + * Copyright 2013 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 +#ifndef SkValidationUtils_DEFINED 1.12 +#define SkValidationUtils_DEFINED 1.13 + 1.14 +#include "SkBitmap.h" 1.15 +#include "SkXfermode.h" 1.16 + 1.17 +/** Returns true if coeff's value is in the SkXfermode::Coeff enum. 1.18 + */ 1.19 +static inline bool SkIsValidCoeff(SkXfermode::Coeff coeff) { 1.20 + return coeff >= 0 && coeff < SkXfermode::kCoeffCount; 1.21 +} 1.22 + 1.23 +/** Returns true if mode's value is in the SkXfermode::Mode enum. 1.24 + */ 1.25 +static inline bool SkIsValidMode(SkXfermode::Mode mode) { 1.26 + return (mode >= 0) && (mode <= SkXfermode::kLastMode); 1.27 +} 1.28 + 1.29 +/** Returns true if config's value is in the SkBitmap::Config enum. 1.30 + */ 1.31 +static inline bool SkIsValidConfig(SkBitmap::Config config) { 1.32 + return (config >= 0) && (config <= static_cast<int>(SkBitmap::kConfigCount)); 1.33 +} 1.34 + 1.35 +/** Returns true if the rect's dimensions are between 0 and SK_MaxS32 1.36 + */ 1.37 +static inline bool SkIsValidIRect(const SkIRect& rect) { 1.38 + return rect.width() >= 0 && rect.height() >= 0; 1.39 +} 1.40 + 1.41 +/** Returns true if the rect's dimensions are between 0 and SK_ScalarMax 1.42 + */ 1.43 +static inline bool SkIsValidRect(const SkRect& rect) { 1.44 + return (rect.fLeft <= rect.fRight) && 1.45 + (rect.fTop <= rect.fBottom) && 1.46 + SkScalarIsFinite(rect.width()) && 1.47 + SkScalarIsFinite(rect.height()); 1.48 +} 1.49 + 1.50 +#endif