| 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 "SkLayerInfo.h" | 8 #include "SkLayerInfo.h" |
| 9 #include "SkRecordDraw.h" | 9 #include "SkRecordDraw.h" |
| 10 #include "SkPatchUtils.h" | 10 #include "SkPatchUtils.h" |
| 11 | 11 |
| 12 void SkRecordDraw(const SkRecord& record, | 12 void SkRecordDraw(const SkRecord& record, |
| 13 SkCanvas* canvas, | 13 SkCanvas* canvas, |
| 14 SkPicture const* const drawablePicts[], int drawableCount, | 14 SkPicture const* const drawablePicts[], |
| 15 SkCanvasDrawable* const drawables[], |
| 16 int drawableCount, |
| 15 const SkBBoxHierarchy* bbh, | 17 const SkBBoxHierarchy* bbh, |
| 16 SkDrawPictureCallback* callback) { | 18 SkDrawPictureCallback* callback) { |
| 17 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); | 19 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); |
| 18 | 20 |
| 19 if (bbh) { | 21 if (bbh) { |
| 20 // Draw only ops that affect pixels in the canvas's current clip. | 22 // Draw only ops that affect pixels in the canvas's current clip. |
| 21 // The SkRecord and BBH were recorded in identity space. This canvas | 23 // The SkRecord and BBH were recorded in identity space. This canvas |
| 22 // is not necessarily in that same space. getClipBounds() returns us | 24 // is not necessarily in that same space. getClipBounds() returns us |
| 23 // this canvas' clip bounds transformed back into identity space, which | 25 // this canvas' clip bounds transformed back into identity space, which |
| 24 // lets us query the BBH. | 26 // lets us query the BBH. |
| 25 SkRect query; | 27 SkRect query; |
| 26 if (!canvas->getClipBounds(&query)) { | 28 if (!canvas->getClipBounds(&query)) { |
| 27 // We want to make sure our query rectangle is never totally empty. | 29 // We want to make sure our query rectangle is never totally empty. |
| 28 // Clear ignores the clip, so it must draw even if the clip is logic
ally empty. | 30 // Clear ignores the clip, so it must draw even if the clip is logic
ally empty. |
| 29 query = SkRect::MakeWH(SK_ScalarNearlyZero, SK_ScalarNearlyZero); | 31 query = SkRect::MakeWH(SK_ScalarNearlyZero, SK_ScalarNearlyZero); |
| 30 } | 32 } |
| 31 | 33 |
| 32 SkTDArray<unsigned> ops; | 34 SkTDArray<unsigned> ops; |
| 33 bbh->search(query, &ops); | 35 bbh->search(query, &ops); |
| 34 | 36 |
| 35 SkRecords::Draw draw(canvas, drawablePicts, drawableCount); | 37 SkRecords::Draw draw(canvas, drawablePicts, drawables, drawableCount); |
| 36 for (int i = 0; i < ops.count(); i++) { | 38 for (int i = 0; i < ops.count(); i++) { |
| 37 if (callback && callback->abortDrawing()) { | 39 if (callback && callback->abortDrawing()) { |
| 38 return; | 40 return; |
| 39 } | 41 } |
| 40 // This visit call uses the SkRecords::Draw::operator() to call | 42 // This visit call uses the SkRecords::Draw::operator() to call |
| 41 // methods on the |canvas|, wrapped by methods defined with the | 43 // methods on the |canvas|, wrapped by methods defined with the |
| 42 // DRAW() macro. | 44 // DRAW() macro. |
| 43 record.visit<void>(ops[i], draw); | 45 record.visit<void>(ops[i], draw); |
| 44 } | 46 } |
| 45 } else { | 47 } else { |
| 46 // Draw all ops. | 48 // Draw all ops. |
| 47 SkRecords::Draw draw(canvas, drawablePicts, drawableCount); | 49 SkRecords::Draw draw(canvas, drawablePicts, drawables, drawableCount); |
| 48 for (unsigned i = 0; i < record.count(); i++) { | 50 for (unsigned i = 0; i < record.count(); i++) { |
| 49 if (callback && callback->abortDrawing()) { | 51 if (callback && callback->abortDrawing()) { |
| 50 return; | 52 return; |
| 51 } | 53 } |
| 52 // This visit call uses the SkRecords::Draw::operator() to call | 54 // This visit call uses the SkRecords::Draw::operator() to call |
| 53 // methods on the |canvas|, wrapped by methods defined with the | 55 // methods on the |canvas|, wrapped by methods defined with the |
| 54 // DRAW() macro. | 56 // DRAW() macro. |
| 55 record.visit<void>(i, draw); | 57 record.visit<void>(i, draw); |
| 56 } | 58 } |
| 57 } | 59 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 DRAW(DrawTextBlob, drawTextBlob(r.blob, r.x, r.y, r.paint)); | 128 DRAW(DrawTextBlob, drawTextBlob(r.blob, r.x, r.y, r.paint)); |
| 127 DRAW(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, r.matrix, r.pa
int)); | 129 DRAW(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, r.matrix, r.pa
int)); |
| 128 DRAW(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.co
lors, | 130 DRAW(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.co
lors, |
| 129 r.xmode.get(), r.indices, r.indexCount, r.paint)
); | 131 r.xmode.get(), r.indices, r.indexCount, r.paint)
); |
| 130 DRAW(DrawData, drawData(r.data, r.length)); | 132 DRAW(DrawData, drawData(r.data, r.length)); |
| 131 #undef DRAW | 133 #undef DRAW |
| 132 | 134 |
| 133 template <> void Draw::draw(const DrawDrawable& r) { | 135 template <> void Draw::draw(const DrawDrawable& r) { |
| 134 SkASSERT(r.index >= 0); | 136 SkASSERT(r.index >= 0); |
| 135 SkASSERT(r.index < fDrawableCount); | 137 SkASSERT(r.index < fDrawableCount); |
| 136 fCanvas->drawPicture(fDrawablePicts[r.index]); | 138 if (fDrawables) { |
| 139 SkASSERT(NULL == fDrawablePicts); |
| 140 fCanvas->EXPERIMENTAL_drawDrawable(fDrawables[r.index]); |
| 141 } else { |
| 142 fCanvas->drawPicture(fDrawablePicts[r.index]); |
| 143 } |
| 137 } | 144 } |
| 138 | 145 |
| 139 // This is an SkRecord visitor that fills an SkBBoxHierarchy. | 146 // This is an SkRecord visitor that fills an SkBBoxHierarchy. |
| 140 // | 147 // |
| 141 // The interesting part here is how to calculate bounds for ops which don't | 148 // The interesting part here is how to calculate bounds for ops which don't |
| 142 // have intrinsic bounds. What is the bounds of a Save or a Translate? | 149 // have intrinsic bounds. What is the bounds of a Save or a Translate? |
| 143 // | 150 // |
| 144 // We answer this by thinking about a particular definition of bounds: if I | 151 // We answer this by thinking about a particular definition of bounds: if I |
| 145 // don't execute this op, pixels in this rectangle might draw incorrectly. So | 152 // don't execute this op, pixels in this rectangle might draw incorrectly. So |
| 146 // the bounds of a Save, a Translate, a Restore, etc. are the union of the | 153 // the bounds of a Save, a Translate, a Restore, etc. are the union of the |
| (...skipping 618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 765 SkRecords::CollectLayers visitor(cullRect, record, data); | 772 SkRecords::CollectLayers visitor(cullRect, record, data); |
| 766 | 773 |
| 767 for (unsigned curOp = 0; curOp < record.count(); curOp++) { | 774 for (unsigned curOp = 0; curOp < record.count(); curOp++) { |
| 768 visitor.setCurrentOp(curOp); | 775 visitor.setCurrentOp(curOp); |
| 769 record.visit<void>(curOp, visitor); | 776 record.visit<void>(curOp, visitor); |
| 770 } | 777 } |
| 771 | 778 |
| 772 visitor.cleanUp(bbh); | 779 visitor.cleanUp(bbh); |
| 773 } | 780 } |
| 774 | 781 |
| OLD | NEW |