OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
3 * | 3 * |
4 * 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 |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrContext.h" | 8 #include "GrContext.h" |
9 #include "GrLayerCache.h" | 9 #include "GrLayerCache.h" |
10 #include "GrRecordReplaceDraw.h" | 10 #include "GrRecordReplaceDraw.h" |
| 11 #include "SkAbortCallback.h" |
11 #include "SkCanvasPriv.h" | 12 #include "SkCanvasPriv.h" |
12 #include "SkGrPixelRef.h" | 13 #include "SkGrPixelRef.h" |
13 #include "SkImage.h" | 14 #include "SkImage.h" |
14 #include "SkRecordDraw.h" | 15 #include "SkRecordDraw.h" |
15 #include "SkRecords.h" | 16 #include "SkRecords.h" |
16 | 17 |
17 static inline void wrap_texture(GrTexture* texture, int width, int height, SkBit
map* result) { | 18 static inline void wrap_texture(GrTexture* texture, int width, int height, SkBit
map* result) { |
18 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); | 19 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); |
19 result->setInfo(info); | 20 result->setInfo(info); |
20 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); | 21 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); |
(...skipping 27 matching lines...) Expand all Loading... |
48 | 49 |
49 // Used by GrRecordReplaceDraw. It intercepts nested drawPicture calls and | 50 // Used by GrRecordReplaceDraw. It intercepts nested drawPicture calls and |
50 // also draws them with replaced layers. | 51 // also draws them with replaced layers. |
51 class ReplaceDraw : public SkRecords::Draw { | 52 class ReplaceDraw : public SkRecords::Draw { |
52 public: | 53 public: |
53 ReplaceDraw(SkCanvas* canvas, GrLayerCache* layerCache, | 54 ReplaceDraw(SkCanvas* canvas, GrLayerCache* layerCache, |
54 SkPicture const* const drawablePicts[], int drawableCount, | 55 SkPicture const* const drawablePicts[], int drawableCount, |
55 const SkPicture* topLevelPicture, | 56 const SkPicture* topLevelPicture, |
56 const SkPicture* picture, | 57 const SkPicture* picture, |
57 const SkMatrix& initialMatrix, | 58 const SkMatrix& initialMatrix, |
58 SkDrawPictureCallback* callback, | 59 SkAbortCallback* callback, |
59 const unsigned* opIndices, int numIndices) | 60 const unsigned* opIndices, int numIndices) |
60 : INHERITED(canvas, drawablePicts, NULL, drawableCount) | 61 : INHERITED(canvas, drawablePicts, NULL, drawableCount) |
61 , fCanvas(canvas) | 62 , fCanvas(canvas) |
62 , fLayerCache(layerCache) | 63 , fLayerCache(layerCache) |
63 , fTopLevelPicture(topLevelPicture) | 64 , fTopLevelPicture(topLevelPicture) |
64 , fPicture(picture) | 65 , fPicture(picture) |
65 , fInitialMatrix(initialMatrix) | 66 , fInitialMatrix(initialMatrix) |
66 , fCallback(callback) | 67 , fCallback(callback) |
67 , fIndex(0) | 68 , fIndex(0) |
68 , fNumReplaced(0) { | 69 , fNumReplaced(0) { |
(...skipping 16 matching lines...) Expand all Loading... |
85 // The SkRecord and BBH were recorded in identity space. This canva
s | 86 // The SkRecord and BBH were recorded in identity space. This canva
s |
86 // is not necessarily in that same space. getClipBounds() returns u
s | 87 // is not necessarily in that same space. getClipBounds() returns u
s |
87 // this canvas' clip bounds transformed back into identity space, wh
ich | 88 // this canvas' clip bounds transformed back into identity space, wh
ich |
88 // lets us query the BBH. | 89 // lets us query the BBH. |
89 SkRect query = { 0, 0, 0, 0 }; | 90 SkRect query = { 0, 0, 0, 0 }; |
90 (void)fCanvas->getClipBounds(&query); | 91 (void)fCanvas->getClipBounds(&query); |
91 | 92 |
92 bbh->search(query, &fOps); | 93 bbh->search(query, &fOps); |
93 | 94 |
94 for (fIndex = 0; fIndex < fOps.count(); ++fIndex) { | 95 for (fIndex = 0; fIndex < fOps.count(); ++fIndex) { |
95 if (fCallback && fCallback->abortDrawing()) { | 96 if (fCallback && fCallback->abort()) { |
96 return fNumReplaced; | 97 return fNumReplaced; |
97 } | 98 } |
98 | 99 |
99 record->visit<void>(fOps[fIndex], *this); | 100 record->visit<void>(fOps[fIndex], *this); |
100 } | 101 } |
101 | 102 |
102 } else { | 103 } else { |
103 for (fIndex = 0; fIndex < (int) record->count(); ++fIndex) { | 104 for (fIndex = 0; fIndex < (int) record->count(); ++fIndex) { |
104 if (fCallback && fCallback->abortDrawing()) { | 105 if (fCallback && fCallback->abort()) { |
105 return fNumReplaced; | 106 return fNumReplaced; |
106 } | 107 } |
107 | 108 |
108 record->visit<void>(fIndex, *this); | 109 record->visit<void>(fIndex, *this); |
109 } | 110 } |
110 } | 111 } |
111 | 112 |
112 return fNumReplaced; | 113 return fNumReplaced; |
113 } | 114 } |
114 | 115 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 180 |
180 fOpIndexStack.pop(); | 181 fOpIndexStack.pop(); |
181 } | 182 } |
182 | 183 |
183 private: | 184 private: |
184 SkCanvas* fCanvas; | 185 SkCanvas* fCanvas; |
185 GrLayerCache* fLayerCache; | 186 GrLayerCache* fLayerCache; |
186 const SkPicture* fTopLevelPicture; | 187 const SkPicture* fTopLevelPicture; |
187 const SkPicture* fPicture; | 188 const SkPicture* fPicture; |
188 const SkMatrix fInitialMatrix; | 189 const SkMatrix fInitialMatrix; |
189 SkDrawPictureCallback* fCallback; | 190 SkAbortCallback* fCallback; |
190 | 191 |
191 SkTDArray<unsigned> fOps; | 192 SkTDArray<unsigned> fOps; |
192 int fIndex; | 193 int fIndex; |
193 int fNumReplaced; | 194 int fNumReplaced; |
194 | 195 |
195 // The op code indices of all the enclosing drawPicture and saveLayer calls | 196 // The op code indices of all the enclosing drawPicture and saveLayer calls |
196 SkTDArray<unsigned> fOpIndexStack; | 197 SkTDArray<unsigned> fOpIndexStack; |
197 | 198 |
198 typedef Draw INHERITED; | 199 typedef Draw INHERITED; |
199 }; | 200 }; |
200 | 201 |
201 int GrRecordReplaceDraw(const SkPicture* picture, | 202 int GrRecordReplaceDraw(const SkPicture* picture, |
202 SkCanvas* canvas, | 203 SkCanvas* canvas, |
203 GrLayerCache* layerCache, | 204 GrLayerCache* layerCache, |
204 const SkMatrix& initialMatrix, | 205 const SkMatrix& initialMatrix, |
205 SkDrawPictureCallback* callback) { | 206 SkAbortCallback* callback) { |
206 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); | 207 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); |
207 | 208 |
208 // TODO: drawablePicts? | 209 // TODO: drawablePicts? |
209 ReplaceDraw draw(canvas, layerCache, NULL, 0, | 210 ReplaceDraw draw(canvas, layerCache, NULL, 0, |
210 picture, picture, | 211 picture, picture, |
211 initialMatrix, callback, NULL, 0); | 212 initialMatrix, callback, NULL, 0); |
212 return draw.draw(); | 213 return draw.draw(); |
213 } | 214 } |
OLD | NEW |