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 "GrRecordReplaceDraw.h" | 8 #include "GrRecordReplaceDraw.h" |
9 #include "SkImage.h" | 9 #include "SkImage.h" |
10 #include "SkRecordDraw.h" | 10 #include "SkRecordDraw.h" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 SkIntToScalar(ri->fPos.fY), | 59 SkIntToScalar(ri->fPos.fY), |
60 SkIntToScalar(ri->fSrcRect.width()), | 60 SkIntToScalar(ri->fSrcRect.width()), |
61 SkIntToScalar(ri->fSrcRect.height())); | 61 SkIntToScalar(ri->fSrcRect.height())); |
62 | 62 |
63 canvas->save(); | 63 canvas->save(); |
64 canvas->setMatrix(initialMatrix); | 64 canvas->setMatrix(initialMatrix); |
65 canvas->drawImageRect(ri->fImage, &src, dst, ri->fPaint); | 65 canvas->drawImageRect(ri->fImage, &src, dst, ri->fPaint); |
66 canvas->restore(); | 66 canvas->restore(); |
67 } | 67 } |
68 | 68 |
69 void GrRecordReplaceDraw(const SkRecord& record, | 69 void GrRecordReplaceDraw(const SkPicture* picture, |
70 SkCanvas* canvas, | 70 SkCanvas* canvas, |
71 const SkBBoxHierarchy* bbh, | |
72 const GrReplacements* replacements, | 71 const GrReplacements* replacements, |
| 72 const SkMatrix& initialMatrix, |
73 SkDrawPictureCallback* callback) { | 73 SkDrawPictureCallback* callback) { |
74 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); | 74 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); |
75 | 75 |
| 76 const SkBBoxHierarchy* bbh = picture->fBBH.get(); |
| 77 const SkRecord* record = picture->fRecord.get(); |
| 78 if (NULL == record) { |
| 79 return; |
| 80 } |
| 81 |
76 SkRecords::Draw draw(canvas); | 82 SkRecords::Draw draw(canvas); |
77 const GrReplacements::ReplacementInfo* ri = NULL; | 83 const GrReplacements::ReplacementInfo* ri = NULL; |
78 int searchStart = 0; | 84 int searchStart = 0; |
79 | 85 |
80 const SkMatrix initialMatrix = canvas->getTotalMatrix(); | |
81 | |
82 if (bbh) { | 86 if (bbh) { |
83 // Draw only ops that affect pixels in the canvas's current clip. | 87 // Draw only ops that affect pixels in the canvas's current clip. |
84 // The SkRecord and BBH were recorded in identity space. This canvas | 88 // The SkRecord and BBH were recorded in identity space. This canvas |
85 // is not necessarily in that same space. getClipBounds() returns us | 89 // is not necessarily in that same space. getClipBounds() returns us |
86 // this canvas' clip bounds transformed back into identity space, which | 90 // this canvas' clip bounds transformed back into identity space, which |
87 // lets us query the BBH. | 91 // lets us query the BBH. |
88 SkRect query = { 0, 0, 0, 0 }; | 92 SkRect query = { 0, 0, 0, 0 }; |
89 (void)canvas->getClipBounds(&query); | 93 (void)canvas->getClipBounds(&query); |
90 | 94 |
91 SkTDArray<void*> ops; | 95 SkTDArray<void*> ops; |
92 bbh->search(query, &ops); | 96 bbh->search(query, &ops); |
93 | 97 |
94 for (int i = 0; i < ops.count(); i++) { | 98 for (int i = 0; i < ops.count(); i++) { |
95 if (callback && callback->abortDrawing()) { | 99 if (callback && callback->abortDrawing()) { |
96 return; | 100 return; |
97 } | 101 } |
98 ri = replacements->lookupByStart((uintptr_t)ops[i], &searchStart); | 102 ri = replacements->lookupByStart((uintptr_t)ops[i], &searchStart); |
99 if (ri) { | 103 if (ri) { |
100 draw_replacement_bitmap(ri, canvas, initialMatrix); | 104 draw_replacement_bitmap(ri, canvas, initialMatrix); |
101 | 105 |
102 while ((uintptr_t)ops[i] < ri->fStop) { | 106 while ((uintptr_t)ops[i] < ri->fStop) { |
103 ++i; | 107 ++i; |
104 } | 108 } |
105 SkASSERT((uintptr_t)ops[i] == ri->fStop); | 109 SkASSERT((uintptr_t)ops[i] == ri->fStop); |
106 continue; | 110 continue; |
107 } | 111 } |
108 | 112 |
109 record.visit<void>((uintptr_t)ops[i], draw); | 113 record->visit<void>((uintptr_t)ops[i], draw); |
110 } | 114 } |
111 } else { | 115 } else { |
112 for (unsigned int i = 0; i < record.count(); ++i) { | 116 for (unsigned int i = 0; i < record->count(); ++i) { |
113 if (callback && callback->abortDrawing()) { | 117 if (callback && callback->abortDrawing()) { |
114 return; | 118 return; |
115 } | 119 } |
116 ri = replacements->lookupByStart(i, &searchStart); | 120 ri = replacements->lookupByStart(i, &searchStart); |
117 if (ri) { | 121 if (ri) { |
118 draw_replacement_bitmap(ri, canvas, initialMatrix); | 122 draw_replacement_bitmap(ri, canvas, initialMatrix); |
119 i = ri->fStop; | 123 i = ri->fStop; |
120 continue; | 124 continue; |
121 } | 125 } |
122 | 126 |
123 record.visit<void>(i, draw); | 127 record->visit<void>(i, draw); |
124 } | 128 } |
125 } | 129 } |
126 } | 130 } |
OLD | NEW |