SkValidationUtils.h 1013 B

123456789101112131415161718192021222324252627282930313233343536
  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. #ifndef SkValidationUtils_DEFINED
  8. #define SkValidationUtils_DEFINED
  9. #include "include/core/SkBitmap.h"
  10. #include "include/core/SkBlendMode.h"
  11. #include "src/core/SkXfermodePriv.h"
  12. /** Returns true if mode's value is in the SkBlendMode enum.
  13. */
  14. static inline bool SkIsValidMode(SkBlendMode mode) {
  15. return (unsigned)mode <= (unsigned)SkBlendMode::kLastMode;
  16. }
  17. /** Returns true if the rect's dimensions are between 0 and SK_MaxS32
  18. */
  19. static inline bool SkIsValidIRect(const SkIRect& rect) {
  20. return rect.width() >= 0 && rect.height() >= 0;
  21. }
  22. /** Returns true if the rect's dimensions are between 0 and SK_ScalarMax
  23. */
  24. static inline bool SkIsValidRect(const SkRect& rect) {
  25. return (rect.fLeft <= rect.fRight) &&
  26. (rect.fTop <= rect.fBottom) &&
  27. SkScalarIsFinite(rect.width()) &&
  28. SkScalarIsFinite(rect.height());
  29. }
  30. #endif