aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkMultiPictureDraw.h
blob: 9995721ab952af3162552ea1040d43ddef5a29eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * Copyright 2014 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkMultiPictureDraw_DEFINED
#define SkMultiPictureDraw_DEFINED

#include "../private/SkTDArray.h"
#include "SkMatrix.h"

class SkCanvas;
class SkPaint;
class SkPicture;

/** \class SkMultiPictureDraw

    The MultiPictureDraw object accepts several picture/canvas pairs and
    then attempts to optimally draw the pictures into the canvases, sharing
    as many resources as possible.
*/
class SK_API SkMultiPictureDraw {
public:
    /**
     *  Create an object to optimize the drawing of multiple pictures.
     *  @param reserve Hint for the number of add calls expected to be issued
     */
    SkMultiPictureDraw(int reserve = 0);
    ~SkMultiPictureDraw() { this->reset(); }

    /**
     *  Add a canvas/picture pair for later rendering.
     *  @param canvas   the canvas in which to draw picture
     *  @param picture  the picture to draw into canvas
     *  @param matrix   if non-NULL, applied to the CTM when drawing
     *  @param paint    if non-NULL, draw picture to a temporary buffer
     *                  and then apply the paint when the result is drawn
     */
    void add(SkCanvas* canvas,
             const SkPicture* picture,
             const SkMatrix* matrix = NULL,
             const SkPaint* paint = NULL);

    /**
     *  Perform all the previously added draws. This will reset the state
     *  of this object. If flush is true, all canvases are flushed after
     *  draw.
     */
    void draw(bool flush = false);

    /**
     *  Abandon all buffered draws and reset to the initial state.
     */
    void reset();

private:
    struct DrawData {
        SkCanvas*        fCanvas;
        const SkPicture* fPicture; // reffed
        SkMatrix         fMatrix;
        SkPaint*         fPaint;   // owned

        void init(SkCanvas*, const SkPicture*, const SkMatrix*, const SkPaint*);
        void draw();

        static void Reset(SkTDArray<DrawData>&);
    };

    SkTDArray<DrawData> fThreadSafeDrawData;
    SkTDArray<DrawData> fGPUDrawData;
};

#endif