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

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

Issue 527423002: SkRecordPartialDraw with less code duplication (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: test 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
« no previous file with comments | « no previous file | src/core/SkRecordDraw.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 #ifndef SkRecordDraw_DEFINED 8 #ifndef SkRecordDraw_DEFINED
9 #define SkRecordDraw_DEFINED 9 #define SkRecordDraw_DEFINED
10 10
11 #include "SkBBoxHierarchy.h" 11 #include "SkBBoxHierarchy.h"
12 #include "SkCanvas.h" 12 #include "SkCanvas.h"
13 #include "SkDrawPictureCallback.h" 13 #include "SkDrawPictureCallback.h"
14 #include "SkRecord.h" 14 #include "SkRecord.h"
15 15
16 // Fill a BBH to be used by SkRecordDraw to accelerate playback. 16 // Fill a BBH to be used by SkRecordDraw to accelerate playback.
17 void SkRecordFillBounds(const SkRecord&, SkBBoxHierarchy*); 17 void SkRecordFillBounds(const SkRecord&, SkBBoxHierarchy*);
18 18
19 // Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::D raw. 19 // Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::D raw.
20 void SkRecordDraw(const SkRecord&, SkCanvas*, const SkBBoxHierarchy*, SkDrawPict ureCallback*); 20 void SkRecordDraw(const SkRecord&, SkCanvas*, const SkBBoxHierarchy*, SkDrawPict ureCallback*);
21 21
22 // Draw a portion of an SkRecord into an SkCanvas while replacing clears with dr awRects.
23 void SkRecordPartialDraw(const SkRecord&, SkCanvas*, const SkRect&, unsigned sta rt, unsigned stop);
24
22 namespace SkRecords { 25 namespace SkRecords {
23 26
24 // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas. 27 // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas.
25 class Draw : SkNoncopyable { 28 class Draw : SkNoncopyable {
26 public: 29 public:
27 explicit Draw(SkCanvas* canvas) 30 explicit Draw(SkCanvas* canvas)
28 : fInitialCTM(canvas->getTotalMatrix()), fCanvas(canvas), fIndex(0) {} 31 : fInitialCTM(canvas->getTotalMatrix()), fCanvas(canvas) {}
29
30 unsigned index() const { return fIndex; }
31 void next() { ++fIndex; }
32 32
33 template <typename T> void operator()(const T& r) { 33 template <typename T> void operator()(const T& r) {
34 this->draw(r); 34 this->draw(r);
35 } 35 }
36 36
37 private: 37 private:
38 // No base case, so we'll be compile-time checked that we implement all poss ibilities. 38 // No base case, so we'll be compile-time checked that we implement all poss ibilities.
39 template <typename T> void draw(const T&); 39 template <typename T> void draw(const T&);
40 40
41 const SkMatrix fInitialCTM; 41 const SkMatrix fInitialCTM;
42 SkCanvas* fCanvas; 42 SkCanvas* fCanvas;
43 unsigned fIndex; 43 };
44
45 // Used by SkRecordPartialDraw.
46 class PartialDraw : public Draw {
47 public:
48 PartialDraw(SkCanvas* canvas, const SkRect& clearRect)
49 : INHERITED(canvas), fClearRect(clearRect) {}
50
51 // Same as Draw for all ops except Clear.
52 template <typename T> void operator()(const T& r) {
53 this->INHERITED::operator()(r);
54 }
55 void operator()(const Clear& c) {
56 SkPaint p;
57 p.setColor(c.color);
58 DrawRect drawRect(p, fClearRect);
59 this->INHERITED::operator()(drawRect);
60 }
61
62 private:
63 const SkRect fClearRect;
64 typedef Draw INHERITED;
44 }; 65 };
45 66
46 } // namespace SkRecords 67 } // namespace SkRecords
47 68
48 #endif//SkRecordDraw_DEFINED 69 #endif//SkRecordDraw_DEFINED
OLDNEW
« no previous file with comments | « no previous file | src/core/SkRecordDraw.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698