SkLatticeIter.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright 2015 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 SkLatticeIter_DEFINED
  8. #define SkLatticeIter_DEFINED
  9. #include "include/core/SkCanvas.h"
  10. #include "include/core/SkScalar.h"
  11. #include "include/private/SkTArray.h"
  12. struct SkIRect;
  13. struct SkRect;
  14. /**
  15. * Disect a lattice request into an sequence of src-rect / dst-rect pairs
  16. */
  17. class SK_API SkLatticeIter {
  18. public:
  19. static bool Valid(int imageWidth, int imageHeight, const SkCanvas::Lattice& lattice);
  20. SkLatticeIter(const SkCanvas::Lattice& lattice, const SkRect& dst);
  21. static bool Valid(int imageWidth, int imageHeight, const SkIRect& center);
  22. SkLatticeIter(int imageWidth, int imageHeight, const SkIRect& center, const SkRect& dst);
  23. /**
  24. * While it returns true, use src/dst to draw the image/bitmap. Optional parameters
  25. * isFixedColor and fixedColor specify if the rectangle is filled with a fixed color.
  26. * If (*isFixedColor) is true, then (*fixedColor) contains the rectangle color.
  27. */
  28. bool next(SkIRect* src, SkRect* dst, bool* isFixedColor = nullptr,
  29. SkColor* fixedColor = nullptr);
  30. /** Version of above that converts the integer src rect to a scalar rect. */
  31. bool next(SkRect* src, SkRect* dst, bool* isFixedColor = nullptr,
  32. SkColor* fixedColor = nullptr) {
  33. SkIRect isrcR;
  34. if (this->next(&isrcR, dst, isFixedColor, fixedColor)) {
  35. *src = SkRect::Make(isrcR);
  36. return true;
  37. }
  38. return false;
  39. }
  40. /**
  41. * Apply a matrix to the dst points.
  42. */
  43. void mapDstScaleTranslate(const SkMatrix& matrix);
  44. /**
  45. * Returns the number of rects that will actually be drawn.
  46. */
  47. int numRectsToDraw() const {
  48. return fNumRectsToDraw;
  49. }
  50. private:
  51. SkTArray<int> fSrcX;
  52. SkTArray<int> fSrcY;
  53. SkTArray<SkScalar> fDstX;
  54. SkTArray<SkScalar> fDstY;
  55. SkTArray<SkCanvas::Lattice::RectType> fRectTypes;
  56. SkTArray<SkColor> fColors;
  57. int fCurrX;
  58. int fCurrY;
  59. int fNumRectsInLattice;
  60. int fNumRectsToDraw;
  61. };
  62. #endif