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

Side by Side Diff: src/core/SkRecordDraw.cpp

Issue 454123003: Plumbing for using a BBH in SkRecordDraw. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Undo tilegrid changes for now. Created 6 years, 4 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
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 "SkRecordDraw.h" 8 #include "SkRecordDraw.h"
9 #include "SkTSort.h"
9 10
10 void SkRecordDraw(const SkRecord& record, SkCanvas* canvas, SkDrawPictureCallbac k* callback) { 11 void SkRecordDraw(const SkRecord& record,
12 SkCanvas* canvas,
13 const SkBBoxHierarchy* bbh,
14 SkDrawPictureCallback* callback) {
11 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/); 15 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/);
12 for (SkRecords::Draw draw(canvas); draw.index() < record.count(); draw.next( )) { 16
13 if (NULL != callback && callback->abortDrawing()) { 17 if (NULL != bbh) {
14 return; 18 SkASSERT(bbh->getCount() == record.count());
19
20 // Draw only ops that affect pixels in the canvas's current clip.
21 SkIRect devBounds;
22 canvas->getClipDeviceBounds(&devBounds);
23 SkTDArray<void*> ops;
24 bbh->search(devBounds, &ops);
25
26 // Until we start filling in real bounds, we should get every op back.
27 SkASSERT(ops.count() == record.count());
28
29 // FIXME: QuadTree doesn't send these back in the order we inserted them . :(
30 if (ops.count() > 0) {
31 SkTQSort(ops.begin(), ops.end() - 1, SkTCompareLT<void*>());
15 } 32 }
16 record.visit<void>(draw.index(), draw); 33
34 SkRecords::Draw draw(canvas);
35 for (int i = 0; i < ops.count(); i++) {
robertphillips 2014/08/11 14:45:18 split "{ return; }" onto separate lines ?
36 if (NULL != callback && callback->abortDrawing()) { return; }
37 record.visit<void>((uintptr_t)ops[i], draw); // See FillBounds belo w.
38 }
39 } else {
40 // Draw all ops.
41 for (SkRecords::Draw draw(canvas); draw.index() < record.count(); draw.n ext()) {
robertphillips 2014/08/11 14:45:18 split "{ return; }" onto separate lines ?
42 if (NULL != callback && callback->abortDrawing()) { return; }
43 record.visit<void>(draw.index(), draw);
44 }
17 } 45 }
18 } 46 }
19 47
20 namespace SkRecords { 48 namespace SkRecords {
21 49
22 // FIXME: SkBitmaps are stateful, so we need to copy them to play back in multip le threads. 50 // FIXME: SkBitmaps are stateful, so we need to copy them to play back in multip le threads.
23 static SkBitmap shallow_copy(const SkBitmap& bitmap) { 51 static SkBitmap shallow_copy(const SkBitmap& bitmap) {
24 return bitmap; 52 return bitmap;
25 } 53 }
26 54
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 DRAW(DrawPosTextH, drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.paint)); 86 DRAW(DrawPosTextH, drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.paint));
59 DRAW(DrawRRect, drawRRect(r.rrect, r.paint)); 87 DRAW(DrawRRect, drawRRect(r.rrect, r.paint));
60 DRAW(DrawRect, drawRect(r.rect, r.paint)); 88 DRAW(DrawRect, drawRect(r.rect, r.paint));
61 DRAW(DrawSprite, drawSprite(shallow_copy(r.bitmap), r.left, r.top, r.paint)); 89 DRAW(DrawSprite, drawSprite(shallow_copy(r.bitmap), r.left, r.top, r.paint));
62 DRAW(DrawText, drawText(r.text, r.byteLength, r.x, r.y, r.paint)); 90 DRAW(DrawText, drawText(r.text, r.byteLength, r.x, r.y, r.paint));
63 DRAW(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, r.matrix, r.pa int)); 91 DRAW(DrawTextOnPath, drawTextOnPath(r.text, r.byteLength, r.path, r.matrix, r.pa int));
64 DRAW(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.co lors, 92 DRAW(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.co lors,
65 r.xmode.get(), r.indices, r.indexCount, r.paint) ); 93 r.xmode.get(), r.indices, r.indexCount, r.paint) );
66 #undef DRAW 94 #undef DRAW
67 95
96
97 // This is an SkRecord visitor that fills an SkBBoxHierarchy.
98 class FillBounds : SkNoncopyable {
99 public:
100 explicit FillBounds(SkBBoxHierarchy* bbh) : fBBH(bbh), fIndex(0) {}
101 ~FillBounds() { fBBH->flushDeferredInserts(); }
102
103 uintptr_t index() const { return fIndex; }
104 void next() { ++fIndex; }
105
106 template <typename T> void operator()(const T& r) {
107 // MakeLargest() is a trivially safe default for ops that haven't been b ounded yet.
108 this->insert(this->index(), SkIRect::MakeLargest());
109 }
110
111 private:
robertphillips 2014/08/11 14:45:18 const SkIRect& ?
112 void insert(uintptr_t opIndex, SkIRect bounds) {
113 fBBH->insert((void*)opIndex, bounds, true/*ok to defer*/);
114 }
115
116 SkBBoxHierarchy* fBBH; // Unowned. The BBH is guaranteed to be ref'd for ou r lifetime.
117 uintptr_t fIndex;
118 };
119
68 } // namespace SkRecords 120 } // namespace SkRecords
121
122 void SkRecordFillBounds(const SkRecord& record, SkBBoxHierarchy* bbh) {
123 SkASSERT(NULL != bbh);
124 for(SkRecords::FillBounds fb(bbh); fb.index() < record.count(); fb.next()) {
125 record.visit<void>(fb.index(), fb);
126 }
127 }
OLDNEW
« dm/DMQuiltTask.cpp ('K') | « src/core/SkRecordDraw.h ('k') | src/core/SkRecording.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698