blob: a9557f45ea2eb309f3941d5234785c6ea930aa98 [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) {
mtkleinf4078ad2014-08-08 10:05:19 -070030 this->draw(r);
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000031 }
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
commit-bot@chromium.org0a98d872014-05-19 15:15:24 +000037 const SkMatrix fInitialCTM;
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000038 SkCanvas* fCanvas;
39 unsigned fIndex;
40};
41
42} // namespace SkRecords
43
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000044#endif//SkRecordDraw_DEFINED