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

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

Issue 551843002: Fix two SkRecord-backed layer hoisting bugs (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix unit test Created 6 years, 3 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') | tests/RecordReplaceDrawTest.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 "SkImage.h" 9 #include "SkImage.h"
10 #include "SkRecordDraw.h" 10 #include "SkRecordDraw.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 return &fReplacements[i]; 44 return &fReplacements[i];
45 } else if (start < fReplacements[i].fStart) { 45 } else if (start < fReplacements[i].fStart) {
46 return NULL; // the ranges are monotonically increasing and non-ove rlapping 46 return NULL; // the ranges are monotonically increasing and non-ove rlapping
47 } 47 }
48 } 48 }
49 49
50 return NULL; 50 return NULL;
51 } 51 }
52 52
53 static inline void draw_replacement_bitmap(const GrReplacements::ReplacementInfo * ri, 53 static inline void draw_replacement_bitmap(const GrReplacements::ReplacementInfo * ri,
54 SkCanvas* canvas) { 54 SkCanvas* canvas,
55 const SkMatrix& initialMatrix) {
55 SkRect src = SkRect::Make(ri->fSrcRect); 56 SkRect src = SkRect::Make(ri->fSrcRect);
56 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(ri->fPos.fX), 57 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(ri->fPos.fX),
57 SkIntToScalar(ri->fPos.fY), 58 SkIntToScalar(ri->fPos.fY),
58 SkIntToScalar(ri->fSrcRect.width()), 59 SkIntToScalar(ri->fSrcRect.width()),
59 SkIntToScalar(ri->fSrcRect.height())); 60 SkIntToScalar(ri->fSrcRect.height()));
61
62 canvas->save();
63 canvas->setMatrix(initialMatrix);
60 ri->fImage->draw(canvas, &src, dst, ri->fPaint); 64 ri->fImage->draw(canvas, &src, dst, ri->fPaint);
65 canvas->restore();
61 } 66 }
62 67
63 void GrRecordReplaceDraw(const SkRecord& record, 68 void GrRecordReplaceDraw(const SkRecord& record,
64 SkCanvas* canvas, 69 SkCanvas* canvas,
65 const SkBBoxHierarchy* bbh, 70 const SkBBoxHierarchy* bbh,
66 const GrReplacements* replacements, 71 const GrReplacements* replacements,
67 SkDrawPictureCallback* callback) { 72 SkDrawPictureCallback* callback) {
68 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); 73 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/);
69 74
70 SkRecords::Draw draw(canvas); 75 SkRecords::Draw draw(canvas);
71 const GrReplacements::ReplacementInfo* ri = NULL; 76 const GrReplacements::ReplacementInfo* ri = NULL;
72 int searchStart = 0; 77 int searchStart = 0;
73 78
79 const SkMatrix initialMatrix = canvas->getTotalMatrix();
80
74 if (bbh) { 81 if (bbh) {
75 // Draw only ops that affect pixels in the canvas's current clip. 82 // Draw only ops that affect pixels in the canvas's current clip.
76 // The SkRecord and BBH were recorded in identity space. This canvas 83 // The SkRecord and BBH were recorded in identity space. This canvas
77 // is not necessarily in that same space. getClipBounds() returns us 84 // is not necessarily in that same space. getClipBounds() returns us
78 // this canvas' clip bounds transformed back into identity space, which 85 // this canvas' clip bounds transformed back into identity space, which
79 // lets us query the BBH. 86 // lets us query the BBH.
80 SkRect query = { 0, 0, 0, 0 }; 87 SkRect query = { 0, 0, 0, 0 };
81 (void)canvas->getClipBounds(&query); 88 (void)canvas->getClipBounds(&query);
82 89
83 SkTDArray<void*> ops; 90 SkTDArray<void*> ops;
84 bbh->search(query, &ops); 91 bbh->search(query, &ops);
85 92
86 for (int i = 0; i < ops.count(); i++) { 93 for (int i = 0; i < ops.count(); i++) {
87 if (callback && callback->abortDrawing()) { 94 if (callback && callback->abortDrawing()) {
88 return; 95 return;
89 } 96 }
90 ri = replacements->lookupByStart((uintptr_t)ops[i], &searchStart); 97 ri = replacements->lookupByStart((uintptr_t)ops[i], &searchStart);
91 if (ri) { 98 if (ri) {
92 draw_replacement_bitmap(ri, canvas); 99 draw_replacement_bitmap(ri, canvas, initialMatrix);
93 100
94 while ((uintptr_t)ops[i] < ri->fStop) { 101 while ((uintptr_t)ops[i] < ri->fStop) {
95 ++i; 102 ++i;
96 } 103 }
97 SkASSERT((uintptr_t)ops[i] == ri->fStop); 104 SkASSERT((uintptr_t)ops[i] == ri->fStop);
98 continue; 105 continue;
99 } 106 }
100 107
101 record.visit<void>((uintptr_t)ops[i], draw); 108 record.visit<void>((uintptr_t)ops[i], draw);
102 } 109 }
103 } else { 110 } else {
104 for (unsigned int i = 0; i < record.count(); ++i) { 111 for (unsigned int i = 0; i < record.count(); ++i) {
105 if (callback && callback->abortDrawing()) { 112 if (callback && callback->abortDrawing()) {
106 return; 113 return;
107 } 114 }
108 ri = replacements->lookupByStart(i, &searchStart); 115 ri = replacements->lookupByStart(i, &searchStart);
109 if (ri) { 116 if (ri) {
110 draw_replacement_bitmap(ri, canvas); 117 draw_replacement_bitmap(ri, canvas, initialMatrix);
111
112 i = ri->fStop; 118 i = ri->fStop;
113 continue; 119 continue;
114 } 120 }
115 121
116 record.visit<void>(i, draw); 122 record.visit<void>(i, draw);
117 } 123 }
118 } 124 }
119 } 125 }
OLDNEW
« no previous file with comments | « src/gpu/GrLayerHoister.cpp ('k') | tests/RecordReplaceDrawTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698