xref: /aosp_15_r20/external/skia/src/core/SkRecordDraw.h (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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 "include/core/SkBBHFactory.h"
12 #include "include/core/SkCanvas.h"
13 #include "include/core/SkM44.h"
14 #include "include/core/SkPicture.h"
15 #include "include/private/base/SkNoncopyable.h"
16 
17 class SkDrawable;
18 class SkRecord;
19 struct SkRect;
20 
21 // Calculate conservative identity space bounds for each op in the record.
22 void SkRecordFillBounds(const SkRect& cullRect, const SkRecord&,
23                         SkRect bounds[], SkBBoxHierarchy::Metadata[]);
24 
25 // Draw an SkRecord into an SkCanvas.  A convenience wrapper around SkRecords::Draw.
26 void SkRecordDraw(const SkRecord&, SkCanvas*, SkPicture const* const drawablePicts[],
27                   SkDrawable* const drawables[], int drawableCount,
28                   const SkBBoxHierarchy*, SkPicture::AbortCallback*);
29 
30 namespace SkRecords {
31 
32 // This is an SkRecord visitor that will draw that SkRecord to an SkCanvas.
33 class Draw : SkNoncopyable {
34 public:
35     explicit Draw(SkCanvas* canvas, SkPicture const* const drawablePicts[],
36                   SkDrawable* const drawables[], int drawableCount,
37                   const SkM44* initialCTM = nullptr)
38         : fInitialCTM(initialCTM ? *initialCTM : canvas->getLocalToDevice())
39         , fCanvas(canvas)
40         , fDrawablePicts(drawablePicts)
41         , fDrawables(drawables)
42         , fDrawableCount(drawableCount)
43     {}
44 
45     // This operator calls methods on the |canvas|. The various draw() wrapper
46     // methods around SkCanvas are defined by the DRAW() macro in
47     // SkRecordDraw.cpp.
operator()48     template <typename T> void operator()(const T& r) {
49         this->draw(r);
50     }
51 
52 protected:
drawablePicts()53     SkPicture const* const* drawablePicts() const { return fDrawablePicts; }
drawableCount()54     int drawableCount() const { return fDrawableCount; }
55 
56 private:
57     // No base case, so we'll be compile-time checked that we implement all possibilities.
58     template <typename T> void draw(const T&);
59 
60     const SkM44 fInitialCTM;
61     SkCanvas* fCanvas;
62     SkPicture const* const* fDrawablePicts;
63     SkDrawable* const* fDrawables;
64     int fDrawableCount;
65 };
66 
67 }  // namespace SkRecords
68 
69 #endif//SkRecordDraw_DEFINED
70