1c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org/* 2c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org * Copyright 2013 Google Inc. 3c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org * 4c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org * Use of this source code is governed by a BSD-style license that can be 5c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org * found in the LICENSE file. 6c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org */ 7c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 8c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#ifndef SkValidationUtils_DEFINED 9c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#define SkValidationUtils_DEFINED 10c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 11c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#include "SkBitmap.h" 12c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#include "SkXfermode.h" 13c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 14c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org/** Returns true if coeff's value is in the SkXfermode::Coeff enum. 15c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org */ 16c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.orgstatic inline bool SkIsValidCoeff(SkXfermode::Coeff coeff) { 17c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org return coeff >= 0 && coeff < SkXfermode::kCoeffCount; 18c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org} 19c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 20c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org/** Returns true if mode's value is in the SkXfermode::Mode enum. 21c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org */ 22c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.orgstatic inline bool SkIsValidMode(SkXfermode::Mode mode) { 23c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org return (mode >= 0) && (mode <= SkXfermode::kLastMode); 24c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org} 25c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 26c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org/** Returns true if the rect's dimensions are between 0 and SK_MaxS32 27c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org */ 28c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.orgstatic inline bool SkIsValidIRect(const SkIRect& rect) { 29c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org return rect.width() >= 0 && rect.height() >= 0; 30c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org} 31c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 32c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org/** Returns true if the rect's dimensions are between 0 and SK_ScalarMax 33c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org */ 34c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.orgstatic inline bool SkIsValidRect(const SkRect& rect) { 35c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org return (rect.fLeft <= rect.fRight) && 36c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org (rect.fTop <= rect.fBottom) && 37c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org SkScalarIsFinite(rect.width()) && 38c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org SkScalarIsFinite(rect.height()); 39c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org} 40c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org 41c0b7e10c6a68f59e1653e6c18e6bc954b3c3f0cfcommit-bot@chromium.org#endif 42