SkRecordDraw.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Copyright 2014 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 SkRecordDraw_DEFINED
  8. #define SkRecordDraw_DEFINED
  9. #include "include/core/SkCanvas.h"
  10. #include "include/core/SkMatrix.h"
  11. #include "src/core/SkBBoxHierarchy.h"
  12. #include "src/core/SkBigPicture.h"
  13. #include "src/core/SkRecord.h"
  14. class SkDrawable;
  15. class SkLayerInfo;
  16. // Calculate conservative identity space bounds for each op in the record.
  17. void SkRecordFillBounds(const SkRect& cullRect, const SkRecord&, SkRect bounds[]);
  18. // SkRecordFillBounds(), and gathers information about saveLayers and stores it for later
  19. // use (e.g., layer hoisting). The gathered information is sufficient to determine
  20. // where each saveLayer will land and which ops in the picture it represents.
  21. void SkRecordComputeLayers(const SkRect& cullRect, const SkRecord&, SkRect bounds[],
  22. const SkBigPicture::SnapshotArray*, SkLayerInfo* data);
  23. // Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw.
  24. void SkRecordDraw(const SkRecord&, SkCanvas*, SkPicture const* const drawablePicts[],
  25. SkDrawable* const drawables[], int drawableCount,
  26. const SkBBoxHierarchy*, SkPicture::AbortCallback*);
  27. // Draw a portion of an SkRecord into an SkCanvas.
  28. // When drawing a portion of an SkRecord the CTM on the passed in canvas must be
  29. // the composition of the replay matrix with the record-time CTM (for the portion
  30. // of the record that is being replayed). For setMatrix calls to behave correctly
  31. // the initialCTM parameter must set to just the replay matrix.
  32. void SkRecordPartialDraw(const SkRecord&, SkCanvas*,
  33. SkPicture const* const drawablePicts[], int drawableCount,
  34. int start, int stop, const SkMatrix& initialCTM);
  35. namespace SkRecords {
  36. // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas.
  37. class Draw : SkNoncopyable {
  38. public:
  39. explicit Draw(SkCanvas* canvas, SkPicture const* const drawablePicts[],
  40. SkDrawable* const drawables[], int drawableCount,
  41. const SkMatrix* initialCTM = nullptr)
  42. : fInitialCTM(initialCTM ? *initialCTM : canvas->getTotalMatrix())
  43. , fCanvas(canvas)
  44. , fDrawablePicts(drawablePicts)
  45. , fDrawables(drawables)
  46. , fDrawableCount(drawableCount)
  47. {}
  48. // This operator calls methods on the |canvas|. The various draw() wrapper
  49. // methods around SkCanvas are defined by the DRAW() macro in
  50. // SkRecordDraw.cpp.
  51. template <typename T> void operator()(const T& r) {
  52. this->draw(r);
  53. }
  54. protected:
  55. SkPicture const* const* drawablePicts() const { return fDrawablePicts; }
  56. int drawableCount() const { return fDrawableCount; }
  57. private:
  58. // No base case, so we'll be compile-time checked that we implement all possibilities.
  59. template <typename T> void draw(const T&);
  60. const SkMatrix fInitialCTM;
  61. SkCanvas* fCanvas;
  62. SkPicture const* const* fDrawablePicts;
  63. SkDrawable* const* fDrawables;
  64. int fDrawableCount;
  65. };
  66. } // namespace SkRecords
  67. #endif//SkRecordDraw_DEFINED