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

Side by Side Diff: src/gpu/GrRecordReplaceDraw.cpp

Issue 1130283004: Revert of Sketch splitting SkPicture into an interface and SkBigPicture. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 7 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
« no previous file with comments | « src/gpu/GrLayerHoister.cpp ('k') | src/gpu/SkGpuDevice.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkBigPicture.h"
12 #include "SkCanvasPriv.h" 11 #include "SkCanvasPriv.h"
13 #include "SkGrPixelRef.h" 12 #include "SkGrPixelRef.h"
14 #include "SkImage.h" 13 #include "SkImage.h"
15 #include "SkRecordDraw.h" 14 #include "SkRecordDraw.h"
16 #include "SkRecords.h" 15 #include "SkRecords.h"
17 16
18 static inline void wrap_texture(GrTexture* texture, int width, int height, SkBit map* result) { 17 static inline void wrap_texture(GrTexture* texture, int width, int height, SkBit map* result) {
19 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height); 18 SkImageInfo info = SkImageInfo::MakeN32Premul(width, height);
20 result->setInfo(info); 19 result->setInfo(info);
21 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref(); 20 result->setPixelRef(SkNEW_ARGS(SkGrPixelRef, (info, texture)))->unref();
(...skipping 17 matching lines...) Expand all
39 const SkRect src = SkRect::Make(layer->rect()); 38 const SkRect src = SkRect::Make(layer->rect());
40 const SkRect dst = SkRect::Make(layer->srcIR()); 39 const SkRect dst = SkRect::Make(layer->srcIR());
41 40
42 SkASSERT(layer->offset().isZero()); 41 SkASSERT(layer->offset().isZero());
43 42
44 canvas->save(); 43 canvas->save();
45 canvas->setMatrix(SkMatrix::I()); 44 canvas->setMatrix(SkMatrix::I());
46 canvas->drawBitmapRectToRect(bm, &src, dst, layer->paint()); 45 canvas->drawBitmapRectToRect(bm, &src, dst, layer->paint());
47 canvas->restore(); 46 canvas->restore();
48 } else { 47 } else {
49 canvas->drawSprite(bm, 48 canvas->drawSprite(bm,
50 layer->srcIR().fLeft + layer->offset().fX, 49 layer->srcIR().fLeft + layer->offset().fX,
51 layer->srcIR().fTop + layer->offset().fY, 50 layer->srcIR().fTop + layer->offset().fY,
52 layer->paint()); 51 layer->paint());
53 } 52 }
54 } 53 }
55 54
56 // Used by GrRecordReplaceDraw. It intercepts nested drawPicture calls and 55 // Used by GrRecordReplaceDraw. It intercepts nested drawPicture calls and
57 // also draws them with replaced layers. 56 // also draws them with replaced layers.
58 class ReplaceDraw : public SkRecords::Draw { 57 class ReplaceDraw : public SkRecords::Draw {
59 public: 58 public:
60 ReplaceDraw(SkCanvas* canvas, GrLayerCache* layerCache, 59 ReplaceDraw(SkCanvas* canvas, GrLayerCache* layerCache,
61 SkPicture const* const drawablePicts[], int drawableCount, 60 SkPicture const* const drawablePicts[], int drawableCount,
62 const SkPicture* topLevelPicture, 61 const SkPicture* topLevelPicture,
63 const SkBigPicture* picture, 62 const SkPicture* picture,
64 const SkMatrix& initialMatrix, 63 const SkMatrix& initialMatrix,
65 SkPicture::AbortCallback* callback, 64 SkPicture::AbortCallback* callback,
66 const unsigned* opIndices, int numIndices) 65 const unsigned* opIndices, int numIndices)
67 : INHERITED(canvas, drawablePicts, NULL, drawableCount) 66 : INHERITED(canvas, drawablePicts, NULL, drawableCount)
68 , fCanvas(canvas) 67 , fCanvas(canvas)
69 , fLayerCache(layerCache) 68 , fLayerCache(layerCache)
70 , fTopLevelPicture(topLevelPicture) 69 , fTopLevelPicture(topLevelPicture)
71 , fPicture(picture) 70 , fPicture(picture)
72 , fInitialMatrix(initialMatrix) 71 , fInitialMatrix(initialMatrix)
73 , fCallback(callback) 72 , fCallback(callback)
74 , fIndex(0) 73 , fIndex(0)
75 , fNumReplaced(0) { 74 , fNumReplaced(0) {
76 fOpIndexStack.append(numIndices, opIndices); 75 fOpIndexStack.append(numIndices, opIndices);
77 } 76 }
78 77
79 int draw() { 78 int draw() {
80 const SkBBoxHierarchy* bbh = fPicture->bbh(); 79 const SkBBoxHierarchy* bbh = fPicture->fBBH.get();
81 const SkRecord* record = fPicture->record(); 80 const SkRecord* record = fPicture->fRecord.get();
82 if (NULL == record) { 81 if (NULL == record) {
83 return 0; 82 return 0;
84 } 83 }
85 84
86 fNumReplaced = 0; 85 fNumReplaced = 0;
87 86
88 fOps.rewind(); 87 fOps.rewind();
89 88
90 if (bbh) { 89 if (bbh) {
91 // Draw only ops that affect pixels in the canvas's current clip. 90 // Draw only ops that affect pixels in the canvas's current clip.
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 if (fOps.count()) { 128 if (fOps.count()) {
130 drawPictureOffset = fOps[fIndex]; 129 drawPictureOffset = fOps[fIndex];
131 } else { 130 } else {
132 drawPictureOffset = fIndex; 131 drawPictureOffset = fIndex;
133 } 132 }
134 133
135 fOpIndexStack.push(drawPictureOffset); 134 fOpIndexStack.push(drawPictureOffset);
136 135
137 SkAutoCanvasMatrixPaint acmp(fCanvas, &dp.matrix, dp.paint, dp.picture-> cullRect()); 136 SkAutoCanvasMatrixPaint acmp(fCanvas, &dp.matrix, dp.paint, dp.picture-> cullRect());
138 137
139 if (const SkBigPicture* bp = dp.picture->asSkBigPicture()) { 138 // Draw sub-pictures with the same replacement list but a different pict ure
140 // Draw sub-pictures with the same replacement list but a different picture 139 ReplaceDraw draw(fCanvas, fLayerCache,
141 ReplaceDraw draw(fCanvas, fLayerCache, 140 this->drawablePicts(), this->drawableCount(),
142 this->drawablePicts(), this->drawableCount(), 141 fTopLevelPicture, dp.picture, fInitialMatrix, fCallback ,
143 fTopLevelPicture, bp, fInitialMatrix, fCallback, 142 fOpIndexStack.begin(), fOpIndexStack.count());
144 fOpIndexStack.begin(), fOpIndexStack.count()); 143
145 fNumReplaced += draw.draw(); 144 fNumReplaced += draw.draw();
146 } else {
147 // TODO: can we assume / assert this doesn't happen?
148 dp.picture->playback(fCanvas, fCallback);
149 }
150 145
151 fOpIndexStack.pop(); 146 fOpIndexStack.pop();
152 } 147 }
153 void operator()(const SkRecords::SaveLayer& sl) { 148 void operator()(const SkRecords::SaveLayer& sl) {
154 149
155 // For a saveLayer command, check if it can be replaced by a drawBitmap 150 // For a saveLayer command, check if it can be replaced by a drawBitmap
156 // call and, if so, draw it and then update the current op index accordi ngly. 151 // call and, if so, draw it and then update the current op index accordi ngly.
157 unsigned startOffset; 152 unsigned startOffset;
158 if (fOps.count()) { 153 if (fOps.count()) {
159 startOffset = fOps[fIndex]; 154 startOffset = fOps[fIndex];
160 } else { 155 } else {
161 startOffset = fIndex; 156 startOffset = fIndex;
162 } 157 }
163 158
164 fOpIndexStack.push(startOffset); 159 fOpIndexStack.push(startOffset);
165 160
166 GrCachedLayer* layer = fLayerCache->findLayer(fTopLevelPicture->uniqueID (), 161 GrCachedLayer* layer = fLayerCache->findLayer(fTopLevelPicture->uniqueID (),
167 fInitialMatrix, 162 fInitialMatrix,
168 fOpIndexStack.begin(), 163 fOpIndexStack.begin(),
169 fOpIndexStack.count()); 164 fOpIndexStack.count());
170 165
171 if (layer) { 166 if (layer) {
172 fNumReplaced++; 167 fNumReplaced++;
173 168
174 draw_replacement_bitmap(layer, fCanvas); 169 draw_replacement_bitmap(layer, fCanvas);
175 170
176 if (fPicture->bbh()) { 171 if (fPicture->fBBH.get()) {
177 while (fOps[fIndex] < layer->stop()) { 172 while (fOps[fIndex] < layer->stop()) {
178 ++fIndex; 173 ++fIndex;
179 } 174 }
180 SkASSERT(fOps[fIndex] == layer->stop()); 175 SkASSERT(fOps[fIndex] == layer->stop());
181 } else { 176 } else {
182 fIndex = layer->stop(); 177 fIndex = layer->stop();
183 } 178 }
184 fOpIndexStack.pop(); 179 fOpIndexStack.pop();
185 return; 180 return;
186 } 181 }
187 182
188 // This is a fail for layer hoisting 183 // This is a fail for layer hoisting
189 this->INHERITED::operator()(sl); 184 this->INHERITED::operator()(sl);
190 185
191 fOpIndexStack.pop(); 186 fOpIndexStack.pop();
192 } 187 }
193 188
194 private: 189 private:
195 SkCanvas* fCanvas; 190 SkCanvas* fCanvas;
196 GrLayerCache* fLayerCache; 191 GrLayerCache* fLayerCache;
197 const SkPicture* fTopLevelPicture; 192 const SkPicture* fTopLevelPicture;
198 const SkBigPicture* fPicture; 193 const SkPicture* fPicture;
199 const SkMatrix fInitialMatrix; 194 const SkMatrix fInitialMatrix;
200 SkPicture::AbortCallback* fCallback; 195 SkPicture::AbortCallback* fCallback;
201 196
202 SkTDArray<unsigned> fOps; 197 SkTDArray<unsigned> fOps;
203 int fIndex; 198 int fIndex;
204 int fNumReplaced; 199 int fNumReplaced;
205 200
206 // The op code indices of all the enclosing drawPicture and saveLayer calls 201 // The op code indices of all the enclosing drawPicture and saveLayer calls
207 SkTDArray<unsigned> fOpIndexStack; 202 SkTDArray<unsigned> fOpIndexStack;
208 203
209 typedef Draw INHERITED; 204 typedef Draw INHERITED;
210 }; 205 };
211 206
212 int GrRecordReplaceDraw(const SkPicture* picture, 207 int GrRecordReplaceDraw(const SkPicture* picture,
213 SkCanvas* canvas, 208 SkCanvas* canvas,
214 GrLayerCache* layerCache, 209 GrLayerCache* layerCache,
215 const SkMatrix& initialMatrix, 210 const SkMatrix& initialMatrix,
216 SkPicture::AbortCallback* callback) { 211 SkPicture::AbortCallback* callback) {
217 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); 212 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/);
218 213
219 if (const SkBigPicture* bp = picture->asSkBigPicture()) { 214 // TODO: drawablePicts?
220 // TODO: drawablePicts? 215 ReplaceDraw draw(canvas, layerCache, NULL, 0,
221 ReplaceDraw draw(canvas, layerCache, NULL, 0, 216 picture, picture,
222 bp, bp, 217 initialMatrix, callback, NULL, 0);
223 initialMatrix, callback, NULL, 0); 218 return draw.draw();
224 return draw.draw();
225 } else {
226 // TODO: can we assume / assert this doesn't happen?
227 picture->playback(canvas, callback);
228 return 0;
229 }
230 } 219 }
OLDNEW
« no previous file with comments | « src/gpu/GrLayerHoister.cpp ('k') | src/gpu/SkGpuDevice.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698