blob: faa3d66e2cb34073e194e56c6c2bfd358ae547db [file] [log] [blame]
reedbabc3de2016-07-08 08:43:27 -07001
2/*
3 * Copyright 2016 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#ifndef SkDeferredCanvas_DEFINED
10#define SkDeferredCanvas_DEFINED
11
12#include "../private/SkTDArray.h"
13#include "SkCanvas.h"
14
15class SK_API SkDeferredCanvas : public SkCanvas {
16public:
17 SkDeferredCanvas(SkCanvas*);
18 ~SkDeferredCanvas() override;
19
20#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
21 SkDrawFilter* setDrawFilter(SkDrawFilter*) override;
22#endif
23
24protected:
25 sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override;
26 SkISize getBaseLayerSize() const override;
27 bool getClipBounds(SkRect* bounds) const override;
28 bool getClipDeviceBounds(SkIRect* bounds) const override;
29 bool isClipEmpty() const override;
30 bool isClipRect() const override;
31 bool onPeekPixels(SkPixmap*) override;
32 bool onAccessTopLayerPixels(SkPixmap*) override;
33 SkImageInfo onImageInfo() const override;
34 bool onGetProps(SkSurfaceProps*) const override;
35 void onFlush() override;
36// SkCanvas* canvasForDrawIter() override;
37
38 void willSave() override;
39 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
40 void willRestore() override;
41
42 void didConcat(const SkMatrix&) override;
43 void didSetMatrix(const SkMatrix&) override;
44
45 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
46 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
47 const SkPaint&) override;
48 virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
49 const SkPaint&) override;
50 virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
51 SkScalar constY, const SkPaint&) override;
52 virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
53 const SkMatrix* matrix, const SkPaint&) override;
54 void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform[],
55 const SkRect* cullRect, const SkPaint&) override;
56 virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
57 const SkPaint& paint) override;
58 virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
59 const SkPoint texCoords[4], SkXfermode* xmode,
60 const SkPaint& paint) override;
61
62 void onDrawPaint(const SkPaint&) override;
63 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
64 void onDrawRect(const SkRect&, const SkPaint&) override;
65 void onDrawOval(const SkRect&, const SkPaint&) override;
bsalomonac3aa242016-08-19 11:25:19 -070066 void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
reedbabc3de2016-07-08 08:43:27 -070067 void onDrawRRect(const SkRRect&, const SkPaint&) override;
68 void onDrawPath(const SkPath&, const SkPaint&) override;
69 void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override;
70 void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
71 SrcRectConstraint) override;
72 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override;
73 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
74 const SkPaint*, SrcRectConstraint) override;
75 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
76 const SkPaint*) override;
77 void onDrawImageNine(const SkImage* image, const SkIRect& center,
78 const SkRect& dst, const SkPaint*) override;
79 void onDrawVertices(VertexMode vmode, int vertexCount,
80 const SkPoint vertices[], const SkPoint texs[],
81 const SkColor colors[], SkXfermode* xmode,
82 const uint16_t indices[], int indexCount,
83 const SkPaint&) override;
84 void onDrawAtlas(const SkImage* image, const SkRSXform xform[],
85 const SkRect rects[], const SkColor colors[],
86 int count, SkXfermode::Mode mode,
87 const SkRect* cull, const SkPaint* paint) override;
88
89 void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) override;
90 void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) override;
91 void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) override;
92 void onClipRegion(const SkRegion&, SkRegion::Op) override;
93
94 void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
95 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
96 void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
97
98 class Iter;
99
100private:
101 SkCanvas* fCanvas;
102
103 enum Type {
104 kSave_Type,
105 kClipRect_Type,
106 kTrans_Type,
107 kScaleTrans_Type,
108 };
109 struct Rec {
110 Type fType;
111 union {
112 SkRect fBounds;
113 SkVector fTranslate;
114 struct {
115 SkVector fScale;
116 SkVector fTrans; // post translate
117 } fScaleTrans;
118 } fData;
119
120 bool isConcat(SkMatrix*) const;
121 void getConcat(SkMatrix* mat) const {
122 SkDEBUGCODE(bool isconcat = ) this->isConcat(mat);
123 SkASSERT(isconcat);
124 }
125 void setConcat(const SkMatrix&);
126 };
127 SkTDArray<Rec> fRecs;
128
129 void push_save();
130 void push_cliprect(const SkRect&);
131 bool push_concat(const SkMatrix&);
132
133 void emit(const Rec& rec);
134
135 void flush_all();
136 void flush_before_saves();
137 void flush_le(int index);
138 void flush_translate(SkScalar* x, SkScalar* y, const SkPaint&);
139 void flush_translate(SkScalar* x, SkScalar* y, const SkRect& bounds, const SkPaint* = nullptr);
140 void flush_check(SkRect* bounds, const SkPaint*, unsigned flags = 0);
141
142 void internal_flush_translate(SkScalar* x, SkScalar* y, const SkRect* boundsOrNull);
143
144 typedef SkCanvas INHERITED;
145};
146
147
148#endif