aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkPicturePreroll.cpp
blob: c2d10fc7a28d975aee61b7512afa1c7eb31f0e68 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
 * Copyright 2015 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include "SkCanvas.h"
#include "SkPicture.h"

class SkPrerollCanvas : public SkCanvas {
public:
    SkPrerollCanvas(int width, int height, const SkSurfaceProps* props)
        : SkCanvas(width, height, props)
    {}

protected:
    void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint& paint) SK_OVERRIDE {
        this->handlePaint(paint);
    }
    
    void onDrawText(const void*, size_t, SkScalar, SkScalar, const SkPaint& paint) SK_OVERRIDE {
        this->handlePaint(paint);
    }
    
    void onDrawPosText(const void*, size_t, const SkPoint[], const SkPaint& paint) SK_OVERRIDE {
        this->handlePaint(paint);
    }
    
    void onDrawPosTextH(const void*, size_t, const SkScalar[], SkScalar,
                        const SkPaint& paint) SK_OVERRIDE {
        this->handlePaint(paint);
    }
    
    void onDrawTextOnPath(const void*, size_t, const SkPath&, const SkMatrix*,
                          const SkPaint& paint) SK_OVERRIDE {
        this->handlePaint(paint);
    }
    
    void onDrawTextBlob(const SkTextBlob*, SkScalar, SkScalar, const SkPaint& paint) SK_OVERRIDE {
        this->handlePaint(paint);
    }
    
    void onDrawPatch(const SkPoint[12], const SkColor[4], const SkPoint[4], SkXfermode*,
                     const SkPaint& paint) SK_OVERRIDE {
        this->handlePaint(paint);
    }
    
    void onDrawPaint(const SkPaint& paint) SK_OVERRIDE {
        this->handlePaint(paint);
    }

    void onDrawRect(const SkRect&, const SkPaint& paint) SK_OVERRIDE {
        this->handlePaint(paint);
    }

    void onDrawOval(const SkRect&, const SkPaint& paint) SK_OVERRIDE {
        this->handlePaint(paint);
    }

    void onDrawRRect(const SkRRect&, const SkPaint& paint) SK_OVERRIDE {
        this->handlePaint(paint);
    }

    void onDrawPoints(PointMode, size_t, const SkPoint[], const SkPaint& paint) SK_OVERRIDE {
        this->handlePaint(paint);
    }

    void onDrawVertices(VertexMode, int, const SkPoint[], const SkPoint[], const SkColor[],
                        SkXfermode*, const uint16_t[], int, const SkPaint& paint) SK_OVERRIDE {
        this->handlePaint(paint);
    }

    void onDrawPath(const SkPath&, const SkPaint& paint) SK_OVERRIDE {
        this->handlePaint(paint);
    }

    void onDrawImage(const SkImage* image, SkScalar, SkScalar, const SkPaint* paint) SK_OVERRIDE {
        this->handleImage(image);
        if (paint) {
            this->handlePaint(*paint);
        }
    }

    void onDrawImageRect(const SkImage* image, const SkRect*, const SkRect&,
                         const SkPaint* paint) SK_OVERRIDE {
        this->handleImage(image);
        if (paint) {
            this->handlePaint(*paint);
        }
    }

    void onDrawBitmap(const SkBitmap& bm, SkScalar, SkScalar, const SkPaint* paint) SK_OVERRIDE {
        this->handleBitmap(bm);
        if (paint) {
            this->handlePaint(*paint);
        }
    }

    void onDrawBitmapRect(const SkBitmap& bm, const SkRect*, const SkRect&, const SkPaint* paint,
                          DrawBitmapRectFlags) SK_OVERRIDE {
        this->handleBitmap(bm);
        if (paint) {
            this->handlePaint(*paint);
        }
    }

    void onDrawBitmapNine(const SkBitmap& bm, const SkIRect&, const SkRect&,
                          const SkPaint* paint) SK_OVERRIDE {
        this->handleBitmap(bm);
        if (paint) {
            this->handlePaint(*paint);
        }
    }

    void onDrawSprite(const SkBitmap& bm, int, int, const SkPaint* paint) SK_OVERRIDE {
        this->handleBitmap(bm);
        if (paint) {
            this->handlePaint(*paint);
        }
    }

private:
    void handlePaint(const SkPaint& paint) {
        const SkShader* shader = paint.getShader();
        if (shader) {
            shader->preroll();
        }
    }

    void handleImage(const SkImage* image) {
        image->preroll();
    }

    void handleBitmap(const SkBitmap& bitmap) {
        SkBitmap bm(bitmap);
        bm.lockPixels();
    }

    typedef SkCanvas INHERITED;
};

///////////////////////////////////////////////////////////////////////////////////////////////////

void SkPicture::preroll(const SkRect* srcBounds, const SkMatrix* initialMatrix,
                        const SkSurfaceProps* props, void* gpuCacheAccessor) const {
    SkRect bounds = this->cullRect();
    if (srcBounds && !bounds.intersect(*srcBounds)) {
        return;
    }

    const SkIRect ibounds = bounds.roundOut();
    if (ibounds.isEmpty()) {
        return;
    }

    SkPrerollCanvas canvas(ibounds.width(), ibounds.height(), props);

    canvas.translate(-SkIntToScalar(ibounds.left()), -SkIntToScalar(ibounds.top()));
    canvas.drawPicture(this, initialMatrix, NULL);
}