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

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: clang says asserts are always true 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
« no previous file with comments | « src/core/SkRecordDraw.h ('k') | src/core/SkRecording.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 "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() == SkToInt(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() == SkToInt(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++) {
36 if (NULL != callback && callback->abortDrawing()) {
37 return;
38 }
39 record.visit<void>((uintptr_t)ops[i], draw); // See FillBounds belo w.
40 }
41 } else {
42 // Draw all ops.
43 for (SkRecords::Draw draw(canvas); draw.index() < record.count(); draw.n ext()) {
44 if (NULL != callback && callback->abortDrawing()) {
45 return;
46 }
47 record.visit<void>(draw.index(), draw);
48 }
17 } 49 }
18 } 50 }
19 51
20 namespace SkRecords { 52 namespace SkRecords {
21 53
22 // FIXME: SkBitmaps are stateful, so we need to copy them to play back in multip le threads. 54 // 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) { 55 static SkBitmap shallow_copy(const SkBitmap& bitmap) {
24 return bitmap; 56 return bitmap;
25 } 57 }
26 58
(...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)); 90 DRAW(DrawPosTextH, drawPosTextH(r.text, r.byteLength, r.xpos, r.y, r.paint));
59 DRAW(DrawRRect, drawRRect(r.rrect, r.paint)); 91 DRAW(DrawRRect, drawRRect(r.rrect, r.paint));
60 DRAW(DrawRect, drawRect(r.rect, r.paint)); 92 DRAW(DrawRect, drawRect(r.rect, r.paint));
61 DRAW(DrawSprite, drawSprite(shallow_copy(r.bitmap), r.left, r.top, r.paint)); 93 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)); 94 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)); 95 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, 96 DRAW(DrawVertices, drawVertices(r.vmode, r.vertexCount, r.vertices, r.texs, r.co lors,
65 r.xmode.get(), r.indices, r.indexCount, r.paint) ); 97 r.xmode.get(), r.indices, r.indexCount, r.paint) );
66 #undef DRAW 98 #undef DRAW
67 99
100
101 // This is an SkRecord visitor that fills an SkBBoxHierarchy.
102 class FillBounds : SkNoncopyable {
103 public:
104 explicit FillBounds(SkBBoxHierarchy* bbh) : fBBH(bbh), fIndex(0) {}
105 ~FillBounds() { fBBH->flushDeferredInserts(); }
106
107 uintptr_t index() const { return fIndex; }
108 void next() { ++fIndex; }
109
110 template <typename T> void operator()(const T& r) {
111 // MakeLargest() is a trivially safe default for ops that haven't been b ounded yet.
112 this->insert(this->index(), SkIRect::MakeLargest());
113 }
114
115 private:
116 void insert(uintptr_t opIndex, const SkIRect& bounds) {
117 fBBH->insert((void*)opIndex, bounds, true/*ok to defer*/);
118 }
119
120 SkBBoxHierarchy* fBBH; // Unowned. The BBH is guaranteed to be ref'd for ou r lifetime.
121 uintptr_t fIndex;
122 };
123
68 } // namespace SkRecords 124 } // namespace SkRecords
125
126 void SkRecordFillBounds(const SkRecord& record, SkBBoxHierarchy* bbh) {
127 SkASSERT(NULL != bbh);
128 for(SkRecords::FillBounds fb(bbh); fb.index() < record.count(); fb.next()) {
129 record.visit<void>(fb.index(), fb);
130 }
131 }
OLDNEW
« no previous file with comments | « src/core/SkRecordDraw.h ('k') | src/core/SkRecording.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698