blob: 92b94c44233557799dd37554a5846184646275a7 [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"
Mike Kleinc11530e2014-06-24 11:29:06 -040013#include "SkDrawPictureCallback.h"
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000014
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000015// Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw.
Mike Kleinc11530e2014-06-24 11:29:06 -040016void SkRecordDraw(const SkRecord&, SkCanvas*, SkDrawPictureCallback* = NULL);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000017
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000018namespace SkRecords {
19
20// This is an SkRecord visitor that will draw that SkRecord to an SkCanvas.
21class Draw : SkNoncopyable {
22public:
commit-bot@chromium.org0a98d872014-05-19 15:15:24 +000023 explicit Draw(SkCanvas* canvas)
24 : fInitialCTM(canvas->getTotalMatrix()), fCanvas(canvas), fIndex(0) {}
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000025
26 unsigned index() const { return fIndex; }
27 void next() { ++fIndex; }
28
29 template <typename T> void operator()(const T& r) {
30 if (!this->skip(r)) {
31 this->draw(r);
32 }
33 }
34
35private:
36 // No base case, so we'll be compile-time checked that we implement all possibilities.
37 template <typename T> void draw(const T&);
38
39 // skip() should return true if we can skip this command, false if not.
40 // It may update fIndex directly to skip more than just this one command.
41
42 // Mostly we just blindly call fCanvas and let it handle quick rejects itself.
43 template <typename T> bool skip(const T&) { return false; }
44
45 // We add our own quick rejects for commands added by optimizations.
46 bool skip(const PairedPushCull&);
47 bool skip(const BoundedDrawPosTextH&);
48
commit-bot@chromium.org0a98d872014-05-19 15:15:24 +000049 const SkMatrix fInitialCTM;
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000050 SkCanvas* fCanvas;
51 unsigned fIndex;
52};
53
54} // namespace SkRecords
55
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000056#endif//SkRecordDraw_DEFINED