blob: eb07965799f2b4f3f2544411663b7ad19fdd87cc [file] [log] [blame]
reedbabc3de2016-07-08 08:43:27 -07001/*
2 * Copyright 2016 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 SkDeferredCanvas_DEFINED
9#define SkDeferredCanvas_DEFINED
10
11#include "../private/SkTDArray.h"
Florin Malita439ace92016-12-02 12:05:41 -050012#include "SkNoDrawCanvas.h"
reedbabc3de2016-07-08 08:43:27 -070013
Florin Malita439ace92016-12-02 12:05:41 -050014class SK_API SkDeferredCanvas : public SkNoDrawCanvas {
reedbabc3de2016-07-08 08:43:27 -070015public:
Herb Derby1a3c4b82017-03-17 15:51:53 -040016 enum EvalType {kEager, kLazy};
17 // There are two strategies for evaluating of sub-drawings (pictures and drawables).
18 // * kEager - a sub-drawing is expanded using the using the SkDeferredCanvas. This has
19 // the advantage of optimizing the sub drawing, and is used when the underlying
20 // SkCanvas is drawing and not recording.
21 // * kLazy - a sub-drawing is not expanded, but passed directly to the underlying SkCanvas.
22 // This has the advantage of not expanding the sub drawing and then immediately
23 // re-encoding it, and is used for recording canvases.
24 SkDeferredCanvas(SkCanvas*, EvalType);
reedbabc3de2016-07-08 08:43:27 -070025 ~SkDeferredCanvas() override;
26
Herb Derby13569782016-10-06 14:33:43 -040027 void reset(SkCanvas*);
28
reedbabc3de2016-07-08 08:43:27 -070029#ifdef SK_SUPPORT_LEGACY_DRAWFILTER
30 SkDrawFilter* setDrawFilter(SkDrawFilter*) override;
31#endif
32
33protected:
34 sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override;
35 SkISize getBaseLayerSize() const override;
Mike Reed42e8c532017-01-23 14:09:13 -050036 SkRect onGetLocalClipBounds() const override;
37 SkIRect onGetDeviceClipBounds() const override;
reedbabc3de2016-07-08 08:43:27 -070038 bool isClipEmpty() const override;
39 bool isClipRect() const override;
40 bool onPeekPixels(SkPixmap*) override;
41 bool onAccessTopLayerPixels(SkPixmap*) override;
42 SkImageInfo onImageInfo() const override;
43 bool onGetProps(SkSurfaceProps*) const override;
44 void onFlush() override;
reedbabc3de2016-07-08 08:43:27 -070045
46 void willSave() override;
47 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
48 void willRestore() override;
49
50 void didConcat(const SkMatrix&) override;
51 void didSetMatrix(const SkMatrix&) override;
52
53 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
54 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
55 const SkPaint&) override;
56 virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
57 const SkPaint&) override;
58 virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
59 SkScalar constY, const SkPaint&) override;
60 virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
61 const SkMatrix* matrix, const SkPaint&) override;
62 void onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform[],
63 const SkRect* cullRect, const SkPaint&) override;
64 virtual void onDrawTextBlob(const SkTextBlob* blob, SkScalar x, SkScalar y,
65 const SkPaint& paint) override;
66 virtual void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
Mike Reedfaba3712016-11-03 14:45:31 -040067 const SkPoint texCoords[4], SkBlendMode,
reedbabc3de2016-07-08 08:43:27 -070068 const SkPaint& paint) override;
69
70 void onDrawPaint(const SkPaint&) override;
71 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
72 void onDrawRect(const SkRect&, const SkPaint&) override;
Mike Reedef4ab9d2016-10-05 11:52:51 -040073 void onDrawRegion(const SkRegion& region, const SkPaint& paint) override;
reedbabc3de2016-07-08 08:43:27 -070074 void onDrawOval(const SkRect&, const SkPaint&) override;
bsalomonac3aa242016-08-19 11:25:19 -070075 void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
reedbabc3de2016-07-08 08:43:27 -070076 void onDrawRRect(const SkRRect&, const SkPaint&) override;
77 void onDrawPath(const SkPath&, const SkPaint&) override;
Mike Reedef4ab9d2016-10-05 11:52:51 -040078
reedbabc3de2016-07-08 08:43:27 -070079 void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override;
Mike Reedef4ab9d2016-10-05 11:52:51 -040080 void onDrawBitmapLattice(const SkBitmap&, const Lattice& lattice, const SkRect& dst,
81 const SkPaint*) override;
reedbabc3de2016-07-08 08:43:27 -070082 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
83 const SkPaint*) override;
Mike Reedef4ab9d2016-10-05 11:52:51 -040084 void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
85 SrcRectConstraint) override;
86
87 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override;
88 void onDrawImageLattice(const SkImage*, const Lattice& lattice, const SkRect& dst,
89 const SkPaint*) override;
reedbabc3de2016-07-08 08:43:27 -070090 void onDrawImageNine(const SkImage* image, const SkIRect& center,
91 const SkRect& dst, const SkPaint*) override;
Mike Reedef4ab9d2016-10-05 11:52:51 -040092 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
93 const SkPaint*, SrcRectConstraint) override;
94
Mike Reedfed9cfd2017-03-17 12:09:04 -040095 void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override;
reedbabc3de2016-07-08 08:43:27 -070096 void onDrawAtlas(const SkImage* image, const SkRSXform xform[],
97 const SkRect rects[], const SkColor colors[],
Mike Reedfaba3712016-11-03 14:45:31 -040098 int count, SkBlendMode, const SkRect* cull, const SkPaint* paint) override;
reedbabc3de2016-07-08 08:43:27 -070099
Mike Reedc1f77742016-12-09 09:00:50 -0500100 void onClipRect(const SkRect&, SkClipOp, ClipEdgeStyle) override;
101 void onClipRRect(const SkRRect&, SkClipOp, ClipEdgeStyle) override;
102 void onClipPath(const SkPath&, SkClipOp, ClipEdgeStyle) override;
103 void onClipRegion(const SkRegion&, SkClipOp) override;
reedbabc3de2016-07-08 08:43:27 -0700104
105 void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
106 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
107 void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
108
109 class Iter;
110
111private:
reedbabc3de2016-07-08 08:43:27 -0700112 enum Type {
113 kSave_Type,
114 kClipRect_Type,
115 kTrans_Type,
116 kScaleTrans_Type,
117 };
118 struct Rec {
119 Type fType;
120 union {
121 SkRect fBounds;
122 SkVector fTranslate;
123 struct {
124 SkVector fScale;
125 SkVector fTrans; // post translate
126 } fScaleTrans;
127 } fData;
128
129 bool isConcat(SkMatrix*) const;
130 void getConcat(SkMatrix* mat) const {
131 SkDEBUGCODE(bool isconcat = ) this->isConcat(mat);
132 SkASSERT(isconcat);
133 }
134 void setConcat(const SkMatrix&);
135 };
reedbabc3de2016-07-08 08:43:27 -0700136
137 void push_save();
138 void push_cliprect(const SkRect&);
139 bool push_concat(const SkMatrix&);
Herb Derby13569782016-10-06 14:33:43 -0400140
reedbabc3de2016-07-08 08:43:27 -0700141 void emit(const Rec& rec);
142
143 void flush_all();
144 void flush_before_saves();
145 void flush_le(int index);
146 void flush_translate(SkScalar* x, SkScalar* y, const SkPaint&);
147 void flush_translate(SkScalar* x, SkScalar* y, const SkRect& bounds, const SkPaint* = nullptr);
148 void flush_check(SkRect* bounds, const SkPaint*, unsigned flags = 0);
149
150 void internal_flush_translate(SkScalar* x, SkScalar* y, const SkRect* boundsOrNull);
151
Herb Derby1a3c4b82017-03-17 15:51:53 -0400152 SkTDArray<Rec> fRecs;
153 SkCanvas* fCanvas;
154 const EvalType fEvalType;
155
Florin Malita439ace92016-12-02 12:05:41 -0500156 typedef SkNoDrawCanvas INHERITED;
reedbabc3de2016-07-08 08:43:27 -0700157};
158
159
160#endif