SkMultiPictureDraw.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 SkMultiPictureDraw_DEFINED
  8. #define SkMultiPictureDraw_DEFINED
  9. #include "../private/SkTDArray.h"
  10. #include "SkMatrix.h"
  11. class SkCanvas;
  12. class SkPaint;
  13. class SkPicture;
  14. /** \class SkMultiPictureDraw
  15. The MultiPictureDraw object accepts several picture/canvas pairs and
  16. then attempts to optimally draw the pictures into the canvases, sharing
  17. as many resources as possible.
  18. */
  19. class SK_API SkMultiPictureDraw {
  20. public:
  21. /**
  22. * Create an object to optimize the drawing of multiple pictures.
  23. * @param reserve Hint for the number of add calls expected to be issued
  24. */
  25. SkMultiPictureDraw(int reserve = 0);
  26. ~SkMultiPictureDraw() { this->reset(); }
  27. /**
  28. * Add a canvas/picture pair for later rendering.
  29. * @param canvas the canvas in which to draw picture
  30. * @param picture the picture to draw into canvas
  31. * @param matrix if non-NULL, applied to the CTM when drawing
  32. * @param paint if non-NULL, draw picture to a temporary buffer
  33. * and then apply the paint when the result is drawn
  34. */
  35. void add(SkCanvas* canvas,
  36. const SkPicture* picture,
  37. const SkMatrix* matrix = nullptr,
  38. const SkPaint* paint = nullptr);
  39. /**
  40. * Perform all the previously added draws. This will reset the state
  41. * of this object. If flush is true, all canvases are flushed after
  42. * draw.
  43. */
  44. void draw(bool flush = false);
  45. /**
  46. * Abandon all buffered draws and reset to the initial state.
  47. */
  48. void reset();
  49. private:
  50. struct DrawData {
  51. SkCanvas* fCanvas;
  52. const SkPicture* fPicture; // reffed
  53. SkMatrix fMatrix;
  54. SkPaint* fPaint; // owned
  55. void init(SkCanvas*, const SkPicture*, const SkMatrix*, const SkPaint*);
  56. void draw();
  57. static void Reset(SkTDArray<DrawData>&);
  58. };
  59. SkTDArray<DrawData> fThreadSafeDrawData;
  60. SkTDArray<DrawData> fGPUDrawData;
  61. };
  62. #endif