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