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