Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / skia / src / core / SkRecordDraw.h
1 /*
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
8 #ifndef SkRecordDraw_DEFINED
9 #define SkRecordDraw_DEFINED
10
11 #include "SkBBoxHierarchy.h"
12 #include "SkCanvas.h"
13 #include "SkDrawPictureCallback.h"
14 #include "SkRecord.h"
15
16 // Fill a BBH to be used by SkRecordDraw to accelerate playback.
17 void SkRecordFillBounds(const SkRecord&, SkBBoxHierarchy*);
18
19 // Draw an SkRecord into an SkCanvas.  A convenience wrapper around SkRecords::Draw.
20 void SkRecordDraw(const SkRecord&, SkCanvas*, const SkBBoxHierarchy*, SkDrawPictureCallback*);
21
22 namespace SkRecords {
23
24 // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas.
25 class Draw : SkNoncopyable {
26 public:
27     explicit Draw(SkCanvas* canvas)
28         : fInitialCTM(canvas->getTotalMatrix()), fCanvas(canvas), fIndex(0) {}
29
30     unsigned index() const { return fIndex; }
31     void next() { ++fIndex; }
32
33     template <typename T> void operator()(const T& r) {
34         this->draw(r);
35     }
36
37 private:
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
41     const SkMatrix fInitialCTM;
42     SkCanvas* fCanvas;
43     unsigned fIndex;
44 };
45
46 }  // namespace SkRecords
47
48 #endif//SkRecordDraw_DEFINED