blob: 8da7fb5e4a37bc8898166114b2a2dc2fc22d107a [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
mtklein5ad6ee12014-08-11 08:08:43 -070011#include "SkBBoxHierarchy.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"
mtklein5ad6ee12014-08-11 08:08:43 -070014#include "SkRecord.h"
15
16// Fill a BBH to be used by SkRecordDraw to accelerate playback.
17void SkRecordFillBounds(const SkRecord&, SkBBoxHierarchy*);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000018
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000019// Draw an SkRecord into an SkCanvas. A convenience wrapper around SkRecords::Draw.
mtklein5ad6ee12014-08-11 08:08:43 -070020void SkRecordDraw(const SkRecord&, SkCanvas*, const SkBBoxHierarchy*, SkDrawPictureCallback*);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000021
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000022namespace SkRecords {
23
24// This is an SkRecord visitor that will draw that SkRecord to an SkCanvas.
25class Draw : SkNoncopyable {
26public:
commit-bot@chromium.org0a98d872014-05-19 15:15:24 +000027 explicit Draw(SkCanvas* canvas)
28 : fInitialCTM(canvas->getTotalMatrix()), fCanvas(canvas), fIndex(0) {}
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000029
30 unsigned index() const { return fIndex; }
31 void next() { ++fIndex; }
32
33 template <typename T> void operator()(const T& r) {
mtkleinf4078ad2014-08-08 10:05:19 -070034 this->draw(r);
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000035 }
36
37private:
38 // No base case, so we'll be compile-time checked that we implement all possibilities.
39 template <typename T> void draw(const T&);
40
commit-bot@chromium.org0a98d872014-05-19 15:15:24 +000041 const SkMatrix fInitialCTM;
commit-bot@chromium.org27f6b0d2014-05-09 14:59:29 +000042 SkCanvas* fCanvas;
43 unsigned fIndex;
44};
45
46} // namespace SkRecords
47
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000048#endif//SkRecordDraw_DEFINED