Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(78)

Side by Side Diff: src/pipe/SkPipeCanvas.h

Issue 2201323003: add pipecanvas (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: drawVertices and drawTextOnPath Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1
2 /* 1 /*
3 * Copyright 2011 Google Inc. 2 * Copyright 2016 Google Inc.
4 * 3 *
5 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 5 * found in the LICENSE file.
7 */ 6 */
8 7
9 #ifndef SkNWayCanvas_DEFINED 8 #ifndef SkPipeCanvas_DEFINED
10 #define SkNWayCanvas_DEFINED 9 #define SkPipeCanvas_DEFINED
11 10
12 #include "../private/SkTDArray.h"
13 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkDeduper.h"
13 #include "SkImage.h"
14 #include "SkTypeface.h"
15 #include "SkWriteBuffer.h"
14 16
15 class SK_API SkNWayCanvas : public SkCanvas { 17 class SkPipeCanvas;
18 class SkPipeWriter;
19
20 template <typename T> class SkTIndexSet {
16 public: 21 public:
17 SkNWayCanvas(int width, int height); 22 void reset() { fArray.reset(); }
18 virtual ~SkNWayCanvas();
19 23
20 virtual void addCanvas(SkCanvas*); 24 // returns the found index or 0
21 virtual void removeCanvas(SkCanvas*); 25 int find(const T& key) {
22 virtual void removeAll(); 26 const Rec* stop = fArray.end();
27 for (const Rec* curr = fArray.begin(); curr < stop; ++curr) {
28 if (key == curr->fKey) {
29 return curr->fIndex;
30 }
31 }
32 return 0;
33 }
23 34
24 /////////////////////////////////////////////////////////////////////////// 35 // returns the new index
25 // These are forwarded to the N canvases we're referencing 36 int add(const T& key) {
37 Rec* rec = fArray.append();
38 rec->fKey = key;
39 rec->fIndex = fNextIndex++;
40 return rec->fIndex;
41 }
26 42
27 #ifdef SK_SUPPORT_LEGACY_DRAWFILTER 43 private:
28 SkDrawFilter* setDrawFilter(SkDrawFilter*) override; 44 struct Rec {
29 #endif 45 T fKey;
46 int fIndex;
47 };
48
49 SkTDArray<Rec> fArray;
50 int fNextIndex = 1;
51 };
52
53 class SkPipeDeduper : public SkDeduper {
54 public:
55 SkPipeDeduper() : fPipeCanvas(nullptr), fStream(nullptr) {}
56
57 void resetCaches() {
58 fImages.reset();
59 fPictures.reset();
60 fTypefaces.reset();
61 fFactories.reset();
62 }
63
64 void setCanvas(SkPipeCanvas* canvas) { fPipeCanvas = canvas; }
65 void setStream(SkWStream* stream) { fStream = stream; }
66
67 int findOrDefineImage(SkImage*) override;
68 int findOrDefinePicture(SkPicture*) override;
69 int findOrDefineTypeface(SkTypeface*) override;
70 int findOrDefineFactory(SkFlattenable*) override;
71
72 private:
73 SkPipeCanvas* fPipeCanvas;
74 SkWStream* fStream;
75
76 // All our keys (at the moment) are 32bit uniqueIDs
77 SkTIndexSet<uint32_t> fImages;
78 SkTIndexSet<uint32_t> fPictures;
79 SkTIndexSet<uint32_t> fTypefaces;
80 SkTIndexSet<SkFlattenable::Factory> fFactories;
81 };
82
83
84 class SkPipeCanvas : public SkCanvas {
85 public:
86 SkPipeCanvas(const SkRect& cull, SkPipeDeduper*, SkWStream*);
87 ~SkPipeCanvas() override;
30 88
31 protected: 89 protected:
32 SkTDArray<SkCanvas*> fList;
33
34 void willSave() override; 90 void willSave() override;
35 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override; 91 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
36 void willRestore() override; 92 void willRestore() override;
37 93
38 void didConcat(const SkMatrix&) override; 94 void didConcat(const SkMatrix&) override;
39 void didSetMatrix(const SkMatrix&) override; 95 void didSetMatrix(const SkMatrix&) override;
40 96
41 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override; 97 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
42 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkS calar y, 98 virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkS calar y,
43 const SkPaint&) override; 99 const SkPaint&) override;
(...skipping 13 matching lines...) Expand all
57 113
58 void onDrawPaint(const SkPaint&) override; 114 void onDrawPaint(const SkPaint&) override;
59 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPain t&) override; 115 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPain t&) override;
60 void onDrawRect(const SkRect&, const SkPaint&) override; 116 void onDrawRect(const SkRect&, const SkPaint&) override;
61 void onDrawOval(const SkRect&, const SkPaint&) override; 117 void onDrawOval(const SkRect&, const SkPaint&) override;
62 void onDrawRRect(const SkRRect&, const SkPaint&) override; 118 void onDrawRRect(const SkRRect&, const SkPaint&) override;
63 void onDrawPath(const SkPath&, const SkPaint&) override; 119 void onDrawPath(const SkPath&, const SkPaint&) override;
64 void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPain t*) override; 120 void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPain t*) override;
65 void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*, 121 void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
66 SrcRectConstraint) override; 122 SrcRectConstraint) override;
123 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
124 const SkPaint*) override;
67 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint* ) override; 125 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint* ) override;
68 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst, 126 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
69 const SkPaint*, SrcRectConstraint) override; 127 const SkPaint*, SrcRectConstraint) override;
70 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, 128 void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& ds t,
71 const SkPaint*) override; 129 const SkPaint*) override;
72 void onDrawVertices(VertexMode vmode, int vertexCount, 130 void onDrawVertices(VertexMode vmode, int vertexCount,
73 const SkPoint vertices[], const SkPoint texs[], 131 const SkPoint vertices[], const SkPoint texs[],
74 const SkColor colors[], SkXfermode* xmode, 132 const SkColor colors[], SkXfermode* xmode,
75 const uint16_t indices[], int indexCount, 133 const uint16_t indices[], int indexCount,
76 const SkPaint&) override; 134 const SkPaint&) override;
77 135
78 void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) override; 136 void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) override;
79 void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) override; 137 void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) override;
80 void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) override; 138 void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) override;
81 void onClipRegion(const SkRegion&, SkRegion::Op) override; 139 void onClipRegion(const SkRegion&, SkRegion::Op) override;
82 140
83 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) overri de; 141 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) overri de;
84 void onDrawAnnotation(const SkRect&, const char[], SkData*) override; 142 void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
85 143
86 class Iter; 144 private:
145 SkPipeDeduper* fDeduper;
146 SkWStream* fStream;
87 147
88 private: 148 friend class SkPipeWriter;
149
89 typedef SkCanvas INHERITED; 150 typedef SkCanvas INHERITED;
90 }; 151 };
91 152
92 153
93 #endif 154 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698