reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 1 | /* |
| 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 Malita | 439ace9 | 2016-12-02 12:05:41 -0500 | [diff] [blame] | 12 | #include "SkNoDrawCanvas.h" |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 13 | |
Florin Malita | 439ace9 | 2016-12-02 12:05:41 -0500 | [diff] [blame] | 14 | class SK_API SkDeferredCanvas : public SkNoDrawCanvas { |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 15 | public: |
Herb Derby | 1a3c4b8 | 2017-03-17 15:51:53 -0400 | [diff] [blame] | 16 | 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); |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 25 | ~SkDeferredCanvas() override; |
| 26 | |
Herb Derby | 1356978 | 2016-10-06 14:33:43 -0400 | [diff] [blame] | 27 | void reset(SkCanvas*); |
| 28 | |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 29 | #ifdef SK_SUPPORT_LEGACY_DRAWFILTER |
| 30 | SkDrawFilter* setDrawFilter(SkDrawFilter*) override; |
| 31 | #endif |
| 32 | |
| 33 | protected: |
| 34 | sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override; |
| 35 | SkISize getBaseLayerSize() const override; |
Mike Reed | 42e8c53 | 2017-01-23 14:09:13 -0500 | [diff] [blame] | 36 | SkRect onGetLocalClipBounds() const override; |
| 37 | SkIRect onGetDeviceClipBounds() const override; |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 38 | 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; |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 45 | |
| 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 Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 67 | const SkPoint texCoords[4], SkBlendMode, |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 68 | 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 Reed | ef4ab9d | 2016-10-05 11:52:51 -0400 | [diff] [blame] | 73 | void onDrawRegion(const SkRegion& region, const SkPaint& paint) override; |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 74 | void onDrawOval(const SkRect&, const SkPaint&) override; |
bsalomon | ac3aa24 | 2016-08-19 11:25:19 -0700 | [diff] [blame] | 75 | void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override; |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 76 | void onDrawRRect(const SkRRect&, const SkPaint&) override; |
| 77 | void onDrawPath(const SkPath&, const SkPaint&) override; |
Mike Reed | ef4ab9d | 2016-10-05 11:52:51 -0400 | [diff] [blame] | 78 | |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 79 | void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override; |
Mike Reed | ef4ab9d | 2016-10-05 11:52:51 -0400 | [diff] [blame] | 80 | void onDrawBitmapLattice(const SkBitmap&, const Lattice& lattice, const SkRect& dst, |
| 81 | const SkPaint*) override; |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 82 | void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, |
| 83 | const SkPaint*) override; |
Mike Reed | ef4ab9d | 2016-10-05 11:52:51 -0400 | [diff] [blame] | 84 | 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; |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 90 | void onDrawImageNine(const SkImage* image, const SkIRect& center, |
| 91 | const SkRect& dst, const SkPaint*) override; |
Mike Reed | ef4ab9d | 2016-10-05 11:52:51 -0400 | [diff] [blame] | 92 | void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst, |
| 93 | const SkPaint*, SrcRectConstraint) override; |
| 94 | |
Mike Reed | fed9cfd | 2017-03-17 12:09:04 -0400 | [diff] [blame] | 95 | void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override; |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 96 | void onDrawAtlas(const SkImage* image, const SkRSXform xform[], |
| 97 | const SkRect rects[], const SkColor colors[], |
Mike Reed | faba371 | 2016-11-03 14:45:31 -0400 | [diff] [blame] | 98 | int count, SkBlendMode, const SkRect* cull, const SkPaint* paint) override; |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 99 | |
Mike Reed | c1f7774 | 2016-12-09 09:00:50 -0500 | [diff] [blame] | 100 | 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; |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 104 | |
| 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 | |
| 111 | private: |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 112 | 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 | }; |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 136 | |
| 137 | void push_save(); |
| 138 | void push_cliprect(const SkRect&); |
| 139 | bool push_concat(const SkMatrix&); |
Herb Derby | 1356978 | 2016-10-06 14:33:43 -0400 | [diff] [blame] | 140 | |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 141 | 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 Derby | 1a3c4b8 | 2017-03-17 15:51:53 -0400 | [diff] [blame] | 152 | SkTDArray<Rec> fRecs; |
| 153 | SkCanvas* fCanvas; |
| 154 | const EvalType fEvalType; |
| 155 | |
Florin Malita | 439ace9 | 2016-12-02 12:05:41 -0500 | [diff] [blame] | 156 | typedef SkNoDrawCanvas INHERITED; |
reed | babc3de | 2016-07-08 08:43:27 -0700 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | |
| 160 | #endif |