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

Side by Side Diff: src/gpu/GrRecordReplaceDraw.cpp

Issue 535953002: Replace SkPictureReplacementPlayback with GrRecordReplaceDraw (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix memory leak Created 6 years, 3 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
(Empty)
1 /*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #include "GrRecordReplaceDraw.h"
9 #include "SkRecordDraw.h"
10
11 GrReplacements::ReplacementInfo* GrReplacements::push() {
12 SkDEBUGCODE(this->validate());
13 return fReplacements.push();
14 }
15
16 void GrReplacements::freeAll() {
17 for (int i = 0; i < fReplacements.count(); ++i) {
18 SkDELETE(fReplacements[i].fBM);
19 }
20 fReplacements.reset();
21 }
22
23 #ifdef SK_DEBUG
24 void GrReplacements::validate() const {
25 // Check that the ranges are monotonically increasing and non-overlapping
26 if (fReplacements.count() > 0) {
27 SkASSERT(fReplacements[0].fStart < fReplacements[0].fStop);
28
29 for (int i = 1; i < fReplacements.count(); ++i) {
30 SkASSERT(fReplacements[i].fStart < fReplacements[i].fStop);
31 SkASSERT(fReplacements[i - 1].fStop < fReplacements[i].fStart);
32 }
33 }
34 }
35 #endif
36
37 const GrReplacements::ReplacementInfo*
38 GrReplacements::lookupByStart(size_t start, int* searchStart) const {
39 SkDEBUGCODE(this->validate());
40 for (int i = *searchStart; i < fReplacements.count(); ++i) {
41 if (start == fReplacements[i].fStart) {
42 *searchStart = i + 1;
43 return &fReplacements[i];
44 } else if (start < fReplacements[i].fStart) {
45 return NULL; // the ranges are monotonically increasing and non-ove rlapping
46 }
47 }
48
49 return NULL;
50 }
51
52 static inline void draw_replacement_bitmap(const GrReplacements::ReplacementInfo * ri,
53 SkRecords::Draw* draw) {
54 SkRect src = SkRect::Make(ri->fSrcRect);
55 SkRect dst = SkRect::MakeXYWH(SkIntToScalar(ri->fPos.fX),
56 SkIntToScalar(ri->fPos.fY),
57 SkIntToScalar(ri->fSrcRect.width()),
58 SkIntToScalar(ri->fSrcRect.height()));
59 SkRecords::DrawBitmapRectToRect dbmr2r(const_cast<SkPaint*>(ri->fPaint),
mtklein 2014/09/03 15:46:11 Hrm. This isn't going to work. dbmr2r will destr
60 *ri->fBM,
61 &src,
62 dst,
63 SkCanvas::kNone_DrawBitmapRectFlag);
64 (*draw)(dbmr2r);
mtklein 2014/09/03 15:49:14 Wait a sec, maybe that's still even too complicate
robertphillips 2014/09/03 17:36:24 Done.
65 }
66
67 void GrRecordReplaceDraw(const SkRecord& record,
68 SkCanvas* canvas,
69 const SkBBoxHierarchy* bbh,
70 const GrReplacements* replacements,
71 SkDrawPictureCallback* callback) {
72 SkAutoCanvasRestore saveRestore(canvas, true /*save now, restore at exit*/);
73
74 SkRecords::Draw draw(canvas);
75 const GrReplacements::ReplacementInfo* ri = NULL;
76 int searchStart = 0;
77
78 if (NULL != bbh) {
79 // Draw only ops that affect pixels in the canvas's current clip.
80 // The SkRecord and BBH were recorded in identity space. This canvas
81 // is not necessarily in that same space. getClipBounds() returns us
82 // this canvas' clip bounds transformed back into identity space, which
83 // lets us query the BBH.
84 SkRect query = { 0, 0, 0, 0 };
85 (void)canvas->getClipBounds(&query);
86
87 SkTDArray<void*> ops;
88 bbh->search(query, &ops);
89
90 for (int i = 0; i < ops.count(); i++) {
91 if (NULL != callback && callback->abortDrawing()) {
92 return;
93 }
94 ri = replacements->lookupByStart(i, &searchStart);
95 if (NULL != ri) {
96 draw_replacement_bitmap(ri, &draw);
97
98 for (; (uintptr_t)ops[i] < ri->fStop; ++i)
bsalomon 2014/09/03 15:43:50 while ((uintptr_t)ops[i] < ri->fStop) { ++i; } w
robertphillips 2014/09/03 17:36:24 Done.
99 ;
100 SkASSERT((uintptr_t)ops[i] == ri->fStop);
101 continue;
102 }
103
104 record.visit<void>((uintptr_t)ops[i], draw);
105 }
106 } else {
107 for (unsigned int i = 0; i < record.count(); ++i) {
108 if (NULL != callback && callback->abortDrawing()) {
109 return;
110 }
111 ri = replacements->lookupByStart(i, &searchStart);
112 if (NULL != ri) {
113 draw_replacement_bitmap(ri, &draw);
114
115 i = ri->fStop;
116 continue;
117 }
118
119 record.visit<void>(i, draw);
120 }
121 }
122 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698