blob: 4ec6e68e928cc77207d8036c97b21ac8bb177784 [file] [log] [blame]
commit-bot@chromium.orgc4b21e62014-04-11 18:33:31 +00001/*
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
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +00008#ifndef SkRecordDraw_DEFINED
9#define SkRecordDraw_DEFINED
10
11#include "SkRecord.h"
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000012#include "SkCanvas.h"
13
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000014// Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw.
commit-bot@chromium.org506db0b2014-04-08 23:31:35 +000015void SkRecordDraw(const SkRecord&, SkCanvas*);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000016
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000017namespace SkRecords {
18
19// This is an SkRecord visitor that will draw that SkRecord to an SkCanvas.
20class Draw : SkNoncopyable {
21public:
22 explicit Draw(SkCanvas* canvas) : fCanvas(canvas), fIndex(0) {}
23
24 unsigned index() const { return fIndex; }
25 void next() { ++fIndex; }
26
27 template <typename T> void operator()(const T& r) {
28 if (!this->skip(r)) {
29 this->draw(r);
30 }
31 }
32
33private:
34 // No base case, so we'll be compile-time checked that we implement all possibilities.
35 template <typename T> void draw(const T&);
36
37 // skip() should return true if we can skip this command, false if not.
38 // It may update fIndex directly to skip more than just this one command.
39
40 // Mostly we just blindly call fCanvas and let it handle quick rejects itself.
41 template <typename T> bool skip(const T&) { return false; }
42
43 // We add our own quick rejects for commands added by optimizations.
44 bool skip(const PairedPushCull&);
45 bool skip(const BoundedDrawPosTextH&);
46
47 SkCanvas* fCanvas;
48 unsigned fIndex;
49};
50
51} // namespace SkRecords
52
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000053#endif//SkRecordDraw_DEFINED