OLD | NEW |
| (Empty) |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CC_PAINT_RECORD_PAINT_CANVAS_H_ | |
6 #define CC_PAINT_RECORD_PAINT_CANVAS_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/compiler_specific.h" | |
11 #include "base/logging.h" | |
12 #include "base/macros.h" | |
13 #include "base/optional.h" | |
14 #include "build/build_config.h" | |
15 #include "cc/paint/paint_canvas.h" | |
16 #include "cc/paint/paint_flags.h" | |
17 #include "cc/paint/paint_record.h" | |
18 #include "third_party/skia/include/utils/SkNoDrawCanvas.h" | |
19 | |
20 namespace cc { | |
21 | |
22 class PaintOpBuffer; | |
23 class PaintFlags; | |
24 | |
25 class CC_PAINT_EXPORT RecordPaintCanvas final : public PaintCanvas { | |
26 public: | |
27 explicit RecordPaintCanvas(PaintOpBuffer* buffer); | |
28 ~RecordPaintCanvas() override; | |
29 | |
30 SkMetaData& getMetaData() override; | |
31 SkImageInfo imageInfo() const override; | |
32 | |
33 void flush() override; | |
34 | |
35 int save() override; | |
36 int saveLayer(const SkRect* bounds, const PaintFlags* flags) override; | |
37 int saveLayerAlpha(const SkRect* bounds, uint8_t alpha) override; | |
38 | |
39 void restore() override; | |
40 int getSaveCount() const override; | |
41 void restoreToCount(int save_count) override; | |
42 void translate(SkScalar dx, SkScalar dy) override; | |
43 void scale(SkScalar sx, SkScalar sy) override; | |
44 void rotate(SkScalar degrees) override; | |
45 void concat(const SkMatrix& matrix) override; | |
46 void setMatrix(const SkMatrix& matrix) override; | |
47 | |
48 void clipRect(const SkRect& rect, SkClipOp op, bool antialias) override; | |
49 void clipRRect(const SkRRect& rrect, SkClipOp op, bool antialias) override; | |
50 void clipPath(const SkPath& path, SkClipOp op, bool antialias) override; | |
51 bool quickReject(const SkRect& rect) const override; | |
52 bool quickReject(const SkPath& path) const override; | |
53 SkRect getLocalClipBounds() const override; | |
54 bool getLocalClipBounds(SkRect* bounds) const override; | |
55 SkIRect getDeviceClipBounds() const override; | |
56 bool getDeviceClipBounds(SkIRect* bounds) const override; | |
57 void drawColor(SkColor color, SkBlendMode mode) override; | |
58 void clear(SkColor color) override; | |
59 | |
60 void drawLine(SkScalar x0, | |
61 SkScalar y0, | |
62 SkScalar x1, | |
63 SkScalar y1, | |
64 const PaintFlags& flags) override; | |
65 void drawRect(const SkRect& rect, const PaintFlags& flags) override; | |
66 void drawIRect(const SkIRect& rect, const PaintFlags& flags) override; | |
67 void drawOval(const SkRect& oval, const PaintFlags& flags) override; | |
68 void drawRRect(const SkRRect& rrect, const PaintFlags& flags) override; | |
69 void drawDRRect(const SkRRect& outer, | |
70 const SkRRect& inner, | |
71 const PaintFlags& flags) override; | |
72 void drawCircle(SkScalar cx, | |
73 SkScalar cy, | |
74 SkScalar radius, | |
75 const PaintFlags& flags) override; | |
76 void drawArc(const SkRect& oval, | |
77 SkScalar start_angle, | |
78 SkScalar sweep_angle, | |
79 bool use_center, | |
80 const PaintFlags& flags) override; | |
81 void drawRoundRect(const SkRect& rect, | |
82 SkScalar rx, | |
83 SkScalar ry, | |
84 const PaintFlags& flags) override; | |
85 void drawPath(const SkPath& path, const PaintFlags& flags) override; | |
86 void drawImage(const PaintImage& image, | |
87 SkScalar left, | |
88 SkScalar top, | |
89 const PaintFlags* flags) override; | |
90 void drawImageRect(const PaintImage& image, | |
91 const SkRect& src, | |
92 const SkRect& dst, | |
93 const PaintFlags* flags, | |
94 SrcRectConstraint constraint) override; | |
95 void drawBitmap(const SkBitmap& bitmap, | |
96 SkScalar left, | |
97 SkScalar top, | |
98 const PaintFlags* flags) override; | |
99 | |
100 void drawText(const void* text, | |
101 size_t byte_length, | |
102 SkScalar x, | |
103 SkScalar y, | |
104 const PaintFlags& flags) override; | |
105 void drawPosText(const void* text, | |
106 size_t byte_length, | |
107 const SkPoint pos[], | |
108 const PaintFlags& flags) override; | |
109 void drawTextBlob(sk_sp<SkTextBlob> blob, | |
110 SkScalar x, | |
111 SkScalar y, | |
112 const PaintFlags& flags) override; | |
113 | |
114 void drawDisplayItemList( | |
115 scoped_refptr<DisplayItemList> display_item_list) override; | |
116 | |
117 void drawPicture(sk_sp<const PaintRecord> record) override; | |
118 | |
119 bool isClipEmpty() const override; | |
120 bool isClipRect() const override; | |
121 const SkMatrix& getTotalMatrix() const override; | |
122 | |
123 void Annotate(AnnotationType type, | |
124 const SkRect& rect, | |
125 sk_sp<SkData> data) override; | |
126 | |
127 void PlaybackPaintRecord(sk_sp<const PaintRecord> record) override; | |
128 | |
129 // Don't shadow non-virtual helper functions. | |
130 using PaintCanvas::clipRect; | |
131 using PaintCanvas::clipRRect; | |
132 using PaintCanvas::clipPath; | |
133 using PaintCanvas::drawBitmap; | |
134 using PaintCanvas::drawColor; | |
135 using PaintCanvas::drawImage; | |
136 using PaintCanvas::drawPicture; | |
137 | |
138 private: | |
139 const SkNoDrawCanvas* GetCanvas() const; | |
140 SkNoDrawCanvas* GetCanvas(); | |
141 | |
142 PaintOpBuffer* buffer_; | |
143 | |
144 // TODO(enne): Although RecordPaintCanvas is mostly a write-only interface | |
145 // where paint commands are stored, occasionally users of PaintCanvas want | |
146 // to ask stateful questions mid-stream of clip and transform state. | |
147 // To avoid duplicating all this code (for now?), just forward to an SkCanvas | |
148 // that's not backed by anything but can answer these questions. | |
149 // | |
150 // This is mutable so that const functions (e.g. quickReject) that may | |
151 // lazy initialize the canvas can still be const. | |
152 mutable base::Optional<SkNoDrawCanvas> canvas_; | |
153 | |
154 DISALLOW_COPY_AND_ASSIGN(RecordPaintCanvas); | |
155 }; | |
156 | |
157 } // namespace cc | |
158 | |
159 #endif // CC_PAINT_RECORD_PAINT_CANVAS_H_ | |
OLD | NEW |