aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/utils/SkShadowPaintFilterCanvas.h
blob: 190c68b7ce6ee9ab54e083960fc09fef3a0718bd (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
/*
 * Copyright 2016 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkShadowPaintFilterCanvas_DEFINED
#define SkShadowPaintFilterCanvas_DEFINED

#include "SkPaintFilterCanvas.h"

#ifdef SK_EXPERIMENTAL_SHADOWING

/** \class SkShadowPaintFilterCanvas
 *
 *  A utility proxy class for implementing shadow maps.
 *
 *  We override the onFilter method to draw depths into the canvas
 *  depending on the current draw depth of the canvas, throwing out
 *  the actual draw color.
 *
 *  Note that we can only do this for one light at a time!
 *  It is up to the user to set the 0th light in fLights to
 *  the light the want to render the depth map with.
 */
class SkShadowPaintFilterCanvas : public SkPaintFilterCanvas {
public:

    SkShadowPaintFilterCanvas(SkCanvas *canvas);

    // TODO use a shader instead
    bool onFilter(SkTCopyOnFirstWrite<SkPaint>* paint, Type type) const override;

    static SkISize ComputeDepthMapSize(const SkLights::Light& light, int maxDepth,
                                       int width, int height);

    void setShadowParams(const SkShadowParams &params);
protected:
    void updateMatrix();

    void onDrawPicture(const SkPicture *picture, const SkMatrix *matrix,
                       const SkPaint *paint) override;

    void onDrawPaint(const SkPaint &paint) override;

    void onDrawPoints(PointMode mode, size_t count, const SkPoint pts[],
                      const SkPaint &paint) override;

    void onDrawRect(const SkRect &rect, const SkPaint &paint) override;

    void onDrawRRect(const SkRRect &rrect, const SkPaint &paint) override;

    void onDrawDRRect(const SkRRect &outer, const SkRRect &inner,
                      const SkPaint &paint) override;

    void onDrawOval(const SkRect &rect, const SkPaint &paint) override;

    void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;

    void onDrawPath(const SkPath &path, const SkPaint &paint) override;

    void onDrawBitmap(const SkBitmap &bm, SkScalar left, SkScalar top,
                      const SkPaint *paint) override;

    void onDrawBitmapRect(const SkBitmap &bm, const SkRect *src, const SkRect &dst,
                          const SkPaint *paint, SrcRectConstraint constraint) override;

    void onDrawBitmapNine(const SkBitmap &bm, const SkIRect &center,
                          const SkRect &dst, const SkPaint *paint) override;

    void onDrawImage(const SkImage *image, SkScalar left, SkScalar top,
                     const SkPaint *paint) override;

    void onDrawImageRect(const SkImage *image, const SkRect *src,
                         const SkRect &dst, const SkPaint *paint,
                         SrcRectConstraint constraint) override;

    void onDrawImageNine(const SkImage *image, const SkIRect &center,
                         const SkRect &dst, const SkPaint *paint) override;

    void onDrawVertices(VertexMode vmode, int vertexCount,
                        const SkPoint vertices[], const SkPoint texs[],
                        const SkColor colors[], SkXfermode *xmode,
                        const uint16_t indices[], int indexCount,
                        const SkPaint &paint) override;

    void onDrawPatch(const SkPoint cubics[], const SkColor colors[],
                     const SkPoint texCoords[], SkXfermode *xmode,
                     const SkPaint &paint) override;

    void onDrawText(const void *text, size_t byteLength, SkScalar x, SkScalar y,
                    const SkPaint &paint) override;

    void onDrawPosText(const void *text, size_t byteLength, const SkPoint pos[],
                       const SkPaint &paint) override;

    void onDrawPosTextH(const void *text, size_t byteLength, const SkScalar xpos[],
                        SkScalar constY, const SkPaint &paint) override;

    void onDrawTextOnPath(const void *text, size_t byteLength, const SkPath &path,
                          const SkMatrix *matrix, const SkPaint &paint) override;

    void onDrawTextRSXform(const void *text, size_t byteLength,
                           const SkRSXform xform[], const SkRect *cull,
                           const SkPaint &paint) override;

    void onDrawTextBlob(const SkTextBlob *blob, SkScalar x,
                        SkScalar y, const SkPaint &paint) override;
private:
    SkShadowParams fShadowParams;
    typedef SkPaintFilterCanvas INHERITED;
};


#endif
#endif