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

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

Issue 748853002: Add support for hoisting layers in pictures drawn with a matrix (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Clean up Created 6 years 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/GrRecordReplaceDraw.h ('k') | src/gpu/SkGpuDevice.cpp » ('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 "GrRecordReplaceDraw.h" 8 #include "GrRecordReplaceDraw.h"
9 #include "SkCanvasPriv.h" 9 #include "SkCanvasPriv.h"
10 #include "SkImage.h" 10 #include "SkImage.h"
11 #include "SkRecordDraw.h" 11 #include "SkRecordDraw.h"
12 #include "SkRecords.h" 12 #include "SkRecords.h"
13 13
14 GrReplacements::ReplacementInfo* GrReplacements::newReplacement(uint32_t picture ID, 14 GrReplacements::ReplacementInfo* GrReplacements::newReplacement(uint32_t picture ID,
15 unsigned int sta rt, 15 unsigned start,
16 const SkMatrix& ctm) { 16 const SkMatrix& ctm) {
17 ReplacementInfo* replacement = SkNEW_ARGS(ReplacementInfo, (pictureID, start , ctm)); 17 ReplacementInfo* replacement = SkNEW_ARGS(ReplacementInfo, (pictureID, start , ctm));
18 fReplacementHash.add(replacement); 18 fReplacementHash.add(replacement);
19 return replacement; 19 return replacement;
20 } 20 }
21 21
22 void GrReplacements::freeAll() { 22 void GrReplacements::freeAll() {
23 SkTDynamicHash<ReplacementInfo, ReplacementInfo::Key>::Iter iter(&fReplaceme ntHash); 23 SkTDynamicHash<ReplacementInfo, ReplacementInfo::Key>::Iter iter(&fReplaceme ntHash);
24 24
25 for (; !iter.done(); ++iter) { 25 for (; !iter.done(); ++iter) {
26 ReplacementInfo* replacement = &(*iter); 26 ReplacementInfo* replacement = &(*iter);
27 SkDELETE(replacement); 27 SkDELETE(replacement);
28 } 28 }
29 29
30 fReplacementHash.reset(); 30 fReplacementHash.reset();
31 } 31 }
32 32
33 const GrReplacements::ReplacementInfo* GrReplacements::lookupByStart(uint32_t pi ctureID, 33 const GrReplacements::ReplacementInfo* GrReplacements::lookupByStart(uint32_t pi ctureID,
34 size_t star t, 34 unsigned st art,
35 const SkMat rix& ctm) const { 35 const SkMat rix& ctm) const {
36 return fReplacementHash.find(ReplacementInfo::Key(pictureID, start, ctm)); 36 return fReplacementHash.find(ReplacementInfo::Key(pictureID, start, ctm));
37 } 37 }
38 38
39 static inline void draw_replacement_bitmap(const GrReplacements::ReplacementInfo * ri, 39 static inline void draw_replacement_bitmap(const GrReplacements::ReplacementInfo * ri,
40 SkCanvas* canvas, 40 SkCanvas* canvas) {
41 const SkMatrix& initialMatrix) {
42 SkRect src = SkRect::Make(ri->fSrcRect); 41 SkRect src = SkRect::Make(ri->fSrcRect);
43 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(ri->fPos.fX), 42 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(ri->fPos.fX),
44 SkIntToScalar(ri->fPos.fY), 43 SkIntToScalar(ri->fPos.fY),
45 SkIntToScalar(ri->fSrcRect.width()), 44 SkIntToScalar(ri->fSrcRect.width()),
46 SkIntToScalar(ri->fSrcRect.height())); 45 SkIntToScalar(ri->fSrcRect.height()));
47 46
48 canvas->save(); 47 canvas->save();
49 canvas->setMatrix(initialMatrix); 48 canvas->setMatrix(SkMatrix::I());
50 canvas->drawImageRect(ri->fImage, &src, dst, ri->fPaint); 49 canvas->drawImageRect(ri->fImage, &src, dst, ri->fPaint);
51 canvas->restore(); 50 canvas->restore();
52 } 51 }
53 52
54 // Used by GrRecordReplaceDraw. It intercepts nested drawPicture calls and 53 // Used by GrRecordReplaceDraw. It intercepts nested drawPicture calls and
55 // also draws them with replaced layers. 54 // also draws them with replaced layers.
56 class ReplaceDraw : public SkRecords::Draw { 55 class ReplaceDraw : public SkRecords::Draw {
57 public: 56 public:
58 ReplaceDraw(SkCanvas* canvas, 57 ReplaceDraw(SkCanvas* canvas,
59 SkPicture const* const drawablePicts[], int drawableCount, 58 SkPicture const* const drawablePicts[], int drawableCount,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // Draw sub-pictures with the same replacement list but a different pict ure 123 // Draw sub-pictures with the same replacement list but a different pict ure
125 ReplaceDraw draw(fCanvas, this->drawablePicts(), this->drawableCount(), 124 ReplaceDraw draw(fCanvas, this->drawablePicts(), this->drawableCount(),
126 dp.picture, fReplacements, fInitialMatrix, fCallback); 125 dp.picture, fReplacements, fInitialMatrix, fCallback);
127 126
128 fNumReplaced += draw.draw(); 127 fNumReplaced += draw.draw();
129 } 128 }
130 void operator()(const SkRecords::SaveLayer& sl) { 129 void operator()(const SkRecords::SaveLayer& sl) {
131 130
132 // For a saveLayer command, check if it can be replaced by a drawBitmap 131 // For a saveLayer command, check if it can be replaced by a drawBitmap
133 // call and, if so, draw it and then update the current op index accordi ngly. 132 // call and, if so, draw it and then update the current op index accordi ngly.
134 size_t startOffset; 133 unsigned startOffset;
135 if (fOps.count()) { 134 if (fOps.count()) {
136 startOffset = fOps[fIndex]; 135 startOffset = fOps[fIndex];
137 } else { 136 } else {
138 startOffset = fIndex; 137 startOffset = fIndex;
139 } 138 }
140 139
141 const SkMatrix& ctm = fCanvas->getTotalMatrix(); 140 const SkMatrix& ctm = fCanvas->getTotalMatrix();
142 const GrReplacements::ReplacementInfo* ri = fReplacements->lookupByStart ( 141 const GrReplacements::ReplacementInfo* ri = fReplacements->lookupByStart (
143 fPicture->uniqueID() , 142 fPicture->uniqueID() ,
144 startOffset, 143 startOffset,
145 ctm); 144 ctm);
146 145
147 if (ri) { 146 if (ri) {
148 fNumReplaced++; 147 fNumReplaced++;
149 draw_replacement_bitmap(ri, fCanvas, fInitialMatrix); 148 draw_replacement_bitmap(ri, fCanvas);
150 149
151 if (fPicture->fBBH.get()) { 150 if (fPicture->fBBH.get()) {
152 while (fOps[fIndex] < ri->fStop) { 151 while (fOps[fIndex] < ri->fStop) {
153 ++fIndex; 152 ++fIndex;
154 } 153 }
155 SkASSERT(fOps[fIndex] == ri->fStop); 154 SkASSERT(fOps[fIndex] == ri->fStop);
156 } else { 155 } else {
157 fIndex = ri->fStop; 156 fIndex = ri->fStop;
158 } 157 }
159 return; 158 return;
(...skipping 22 matching lines...) Expand all
182 const GrReplacements* replacements, 181 const GrReplacements* replacements,
183 const SkMatrix& initialMatrix, 182 const SkMatrix& initialMatrix,
184 SkDrawPictureCallback* callback) { 183 SkDrawPictureCallback* callback) {
185 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); 184 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/);
186 185
187 // TODO: drawablePicts? 186 // TODO: drawablePicts?
188 ReplaceDraw draw(canvas, NULL, 0, picture, replacements, initialMatrix, call back); 187 ReplaceDraw draw(canvas, NULL, 0, picture, replacements, initialMatrix, call back);
189 188
190 return draw.draw(); 189 return draw.draw();
191 } 190 }
OLDNEW
« no previous file with comments | « src/gpu/GrRecordReplaceDraw.h ('k') | src/gpu/SkGpuDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698