Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(194)

Side by Side Diff: cc/paint/paint_canvas.h

Issue 2752593002: cc: Make PaintCanvas abstract (Closed)
Patch Set: Remove default parameters on virtual functions Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/paint/BUILD.gn ('k') | cc/paint/paint_canvas.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CC_PAINT_PAINT_CANVAS_H_ 5 #ifndef CC_PAINT_PAINT_CANVAS_H_
6 #define CC_PAINT_PAINT_CANVAS_H_ 6 #define CC_PAINT_PAINT_CANVAS_H_
7 7
8 #include <memory>
9
10 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
11 #include "base/logging.h"
12 #include "base/macros.h" 9 #include "base/macros.h"
13 #include "build/build_config.h" 10 #include "build/build_config.h"
14 #include "cc/paint/paint_export.h" 11 #include "cc/paint/paint_export.h"
15 #include "cc/paint/paint_flags.h"
16 #include "cc/paint/paint_record.h" 12 #include "cc/paint/paint_record.h"
17 #include "third_party/skia/include/core/SkCanvas.h" 13 #include "third_party/skia/include/core/SkCanvas.h"
18 #include "third_party/skia/include/utils/SkNoDrawCanvas.h"
19 14
20 namespace cc { 15 namespace cc {
21 16
22 class PaintFlags; 17 class PaintFlags;
23 18
24 class CC_PAINT_EXPORT PaintCanvas { 19 class CC_PAINT_EXPORT PaintCanvas {
25 public: 20 public:
26 // TODO(enne): remove all constructors but the one that takes an SkCanvas 21 virtual SkMetaData& getMetaData() = 0;
27 // and a future one that will take a PaintOpBuffer to build a PaintRecord. 22 virtual SkImageInfo imageInfo() const = 0;
28 explicit PaintCanvas(SkCanvas* canvas);
29 explicit PaintCanvas(const SkBitmap& bitmap);
30 explicit PaintCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props);
31 ~PaintCanvas();
32 23
33 ALWAYS_INLINE SkMetaData& getMetaData() { return canvas_->getMetaData(); }
34 ALWAYS_INLINE SkImageInfo imageInfo() const { return canvas_->imageInfo(); }
35 ALWAYS_INLINE bool getProps(SkSurfaceProps* props) const {
36 return canvas_->getProps(props);
37 }
38 // TODO(enne): It would be nice to get rid of flush() entirely, as it 24 // TODO(enne): It would be nice to get rid of flush() entirely, as it
39 // doesn't really make sense for recording. However, this gets used by 25 // doesn't really make sense for recording. However, this gets used by
40 // SkCanvasVideoRenderer which takes a PaintCanvas to paint both 26 // SkCanvasVideoRenderer which takes a PaintCanvas to paint both
41 // software and hardware video. This is super entangled with ImageBuffer 27 // software and hardware video. This is super entangled with ImageBuffer
42 // and canvas/video painting in Blink where the same paths are used for 28 // and canvas/video painting in Blink where the same paths are used for
43 // both recording and gpu work. 29 // both recording and gpu work.
44 ALWAYS_INLINE void flush() { canvas_->flush(); } 30 virtual void flush() = 0;
45 31
46 ALWAYS_INLINE SkISize getBaseLayerSize() const { 32 virtual SkISize getBaseLayerSize() const = 0;
47 return canvas_->getBaseLayerSize(); 33 virtual bool peekPixels(SkPixmap* pixmap) = 0;
34 virtual bool readPixels(const SkImageInfo& dest_info,
35 void* dest_pixels,
36 size_t dest_row_bytes,
37 int src_x,
38 int src_y) = 0;
39 virtual bool readPixels(SkBitmap* bitmap, int src_x, int src_y) = 0;
40 virtual bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap) = 0;
41 virtual bool writePixels(const SkImageInfo& info,
42 const void* pixels,
43 size_t row_bytes,
44 int x,
45 int y) = 0;
46 virtual int save() = 0;
47 virtual int saveLayer(const SkRect* bounds, const PaintFlags* flags) = 0;
48 virtual int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) = 0;
49
50 virtual void restore() = 0;
51 virtual int getSaveCount() const = 0;
52 virtual void restoreToCount(int save_count) = 0;
53 virtual void translate(SkScalar dx, SkScalar dy) = 0;
54 virtual void scale(SkScalar sx, SkScalar sy) = 0;
55 virtual void rotate(SkScalar degrees) = 0;
56 virtual void rotate(SkScalar degrees, SkScalar px, SkScalar py) = 0;
57 virtual void concat(const SkMatrix& matrix) = 0;
58 virtual void setMatrix(const SkMatrix& matrix) = 0;
59 virtual void resetMatrix() = 0;
60
61 virtual void clipRect(const SkRect& rect,
62 SkClipOp op,
63 bool do_anti_alias) = 0;
64 void clipRect(const SkRect& rect, SkClipOp op) { clipRect(rect, op, false); }
65 void clipRect(const SkRect& rect, bool do_anti_alias) {
66 clipRect(rect, SkClipOp::kIntersect, do_anti_alias);
48 } 67 }
49 ALWAYS_INLINE bool peekPixels(SkPixmap* pixmap) { 68 void clipRect(const SkRect& rect) {
50 return canvas_->peekPixels(pixmap); 69 clipRect(rect, SkClipOp::kIntersect, false);
51 }
52 ALWAYS_INLINE bool readPixels(const SkImageInfo& dest_info,
53 void* dest_pixels,
54 size_t dest_row_bytes,
55 int src_x,
56 int src_y) {
57 return canvas_->readPixels(dest_info, dest_pixels, dest_row_bytes, src_x,
58 src_y);
59 }
60 ALWAYS_INLINE bool readPixels(SkBitmap* bitmap, int src_x, int src_y) {
61 return canvas_->readPixels(bitmap, src_x, src_y);
62 }
63 ALWAYS_INLINE bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap) {
64 return canvas_->readPixels(srcRect, bitmap);
65 }
66 ALWAYS_INLINE bool writePixels(const SkImageInfo& info,
67 const void* pixels,
68 size_t row_bytes,
69 int x,
70 int y) {
71 return canvas_->writePixels(info, pixels, row_bytes, x, y);
72 }
73 ALWAYS_INLINE int save() { return canvas_->save(); }
74 ALWAYS_INLINE int saveLayer(const SkRect* bounds, const PaintFlags* flags) {
75 return canvas_->saveLayer(bounds, ToSkPaint(flags));
76 }
77 ALWAYS_INLINE int saveLayer(const SkRect& bounds, const PaintFlags* flags) {
78 return canvas_->saveLayer(bounds, ToSkPaint(flags));
79 }
80 ALWAYS_INLINE int saveLayerPreserveLCDTextRequests(const SkRect* bounds,
81 const PaintFlags* flags) {
82 return canvas_->saveLayerPreserveLCDTextRequests(bounds, ToSkPaint(flags));
83 }
84 ALWAYS_INLINE int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) {
85 return canvas_->saveLayerAlpha(bounds, alpha);
86 } 70 }
87 71
88 ALWAYS_INLINE void restore() { canvas_->restore(); } 72 virtual void clipRRect(const SkRRect& rrect,
89 ALWAYS_INLINE int getSaveCount() const { return canvas_->getSaveCount(); } 73 SkClipOp op,
90 ALWAYS_INLINE void restoreToCount(int save_count) { 74 bool do_anti_alias) = 0;
91 canvas_->restoreToCount(save_count); 75 void clipRRect(const SkRRect& rrect, bool do_anti_alias) {
76 clipRRect(rrect, SkClipOp::kIntersect, do_anti_alias);
92 } 77 }
93 ALWAYS_INLINE void translate(SkScalar dx, SkScalar dy) { 78 void clipRRect(const SkRRect& rrect, SkClipOp op) {
94 canvas_->translate(dx, dy); 79 clipRRect(rrect, op, false);
95 } 80 }
96 ALWAYS_INLINE void scale(SkScalar sx, SkScalar sy) { canvas_->scale(sx, sy); } 81 void clipRRect(const SkRRect& rrect) {
97 ALWAYS_INLINE void rotate(SkScalar degrees) { canvas_->rotate(degrees); } 82 clipRRect(rrect, SkClipOp::kIntersect, false);
98 ALWAYS_INLINE void rotate(SkScalar degrees, SkScalar px, SkScalar py) {
99 canvas_->rotate(degrees, px, py);
100 } 83 }
101 ALWAYS_INLINE void skew(SkScalar sx, SkScalar sy) { canvas_->skew(sx, sy); } 84
102 ALWAYS_INLINE void concat(const SkMatrix& matrix) { canvas_->concat(matrix); } 85 virtual void clipPath(const SkPath& path,
103 ALWAYS_INLINE void setMatrix(const SkMatrix& matrix) { 86 SkClipOp op,
104 canvas_->setMatrix(matrix); 87 bool do_anti_alias) = 0;
88 void clipPath(const SkPath& path, SkClipOp op) { clipPath(path, op, false); }
89 void clipPath(const SkPath& path, bool do_anti_alias) {
90 clipPath(path, SkClipOp::kIntersect, do_anti_alias);
105 } 91 }
106 ALWAYS_INLINE void resetMatrix() { canvas_->resetMatrix(); } 92
107 ALWAYS_INLINE void clipRect(const SkRect& rect, 93 virtual bool quickReject(const SkRect& rect) const = 0;
108 SkClipOp op, 94 virtual bool quickReject(const SkPath& path) const = 0;
109 bool do_anti_alias = false) { 95 virtual SkRect getLocalClipBounds() const = 0;
110 canvas_->clipRect(rect, op, do_anti_alias); 96 virtual bool getLocalClipBounds(SkRect* bounds) const = 0;
97 virtual SkIRect getDeviceClipBounds() const = 0;
98 virtual bool getDeviceClipBounds(SkIRect* bounds) const = 0;
99 virtual void drawColor(SkColor color, SkBlendMode mode) = 0;
100 void drawColor(SkColor color) { drawColor(color, SkBlendMode::kSrcOver); }
101 virtual void clear(SkColor color) = 0;
102
103 virtual void drawLine(SkScalar x0,
104 SkScalar y0,
105 SkScalar x1,
106 SkScalar y1,
107 const PaintFlags& flags) = 0;
108 virtual void drawRect(const SkRect& rect, const PaintFlags& flags) = 0;
109 virtual void drawIRect(const SkIRect& rect, const PaintFlags& flags) = 0;
110 virtual void drawOval(const SkRect& oval, const PaintFlags& flags) = 0;
111 virtual void drawRRect(const SkRRect& rrect, const PaintFlags& flags) = 0;
112 virtual void drawDRRect(const SkRRect& outer,
113 const SkRRect& inner,
114 const PaintFlags& flags) = 0;
115 virtual void drawCircle(SkScalar cx,
116 SkScalar cy,
117 SkScalar radius,
118 const PaintFlags& flags) = 0;
119 virtual void drawArc(const SkRect& oval,
120 SkScalar start_angle,
121 SkScalar sweep_angle,
122 bool use_center,
123 const PaintFlags& flags) = 0;
124 virtual void drawRoundRect(const SkRect& rect,
125 SkScalar rx,
126 SkScalar ry,
127 const PaintFlags& flags) = 0;
128 virtual void drawPath(const SkPath& path, const PaintFlags& flags) = 0;
129 virtual void drawImage(const SkImage* image,
130 SkScalar left,
131 SkScalar top,
132 const PaintFlags* flags) = 0;
133 void drawImage(const SkImage* image, SkScalar left, SkScalar top) {
134 drawImage(image, left, top, nullptr);
111 } 135 }
112 ALWAYS_INLINE void clipRect(const SkRect& rect, bool do_anti_alias = false) { 136 virtual void drawImage(const sk_sp<SkImage>& image,
113 canvas_->clipRect(rect, do_anti_alias); 137 SkScalar left,
114 } 138 SkScalar top,
115 ALWAYS_INLINE void clipRRect(const SkRRect& rrect, 139 const PaintFlags* flags) = 0;
116 SkClipOp op, 140 void drawImage(const sk_sp<SkImage>& image, SkScalar left, SkScalar top) {
117 bool do_anti_alias) { 141 drawImage(image, left, top, nullptr);
118 canvas_->clipRRect(rrect, op, do_anti_alias);
119 }
120 ALWAYS_INLINE void clipRRect(const SkRRect& rrect, SkClipOp op) {
121 canvas_->clipRRect(rrect, op);
122 }
123 ALWAYS_INLINE void clipRRect(const SkRRect& rrect,
124 bool do_anti_alias = false) {
125 canvas_->clipRRect(rrect, do_anti_alias);
126 }
127 ALWAYS_INLINE void clipPath(const SkPath& path,
128 SkClipOp op,
129 bool do_anti_alias) {
130 canvas_->clipPath(path, op, do_anti_alias);
131 }
132 ALWAYS_INLINE void clipPath(const SkPath& path, SkClipOp op) {
133 canvas_->clipPath(path, op);
134 }
135 ALWAYS_INLINE void clipPath(const SkPath& path, bool do_anti_alias = false) {
136 canvas_->clipPath(path, do_anti_alias);
137 }
138 ALWAYS_INLINE void clipRegion(const SkRegion& device_region,
139 SkClipOp op = SkClipOp::kIntersect) {
140 canvas_->clipRegion(device_region, op);
141 }
142 ALWAYS_INLINE bool quickReject(const SkRect& rect) const {
143 return canvas_->quickReject(rect);
144 }
145 ALWAYS_INLINE bool quickReject(const SkPath& path) const {
146 return canvas_->quickReject(path);
147 }
148 ALWAYS_INLINE SkRect getLocalClipBounds() const {
149 return canvas_->getLocalClipBounds();
150 }
151 ALWAYS_INLINE bool getLocalClipBounds(SkRect* bounds) const {
152 return canvas_->getLocalClipBounds(bounds);
153 }
154 ALWAYS_INLINE SkIRect getDeviceClipBounds() const {
155 return canvas_->getDeviceClipBounds();
156 }
157 ALWAYS_INLINE bool getDeviceClipBounds(SkIRect* bounds) const {
158 return canvas_->getDeviceClipBounds(bounds);
159 }
160 ALWAYS_INLINE void drawColor(SkColor color,
161 SkBlendMode mode = SkBlendMode::kSrcOver) {
162 canvas_->drawColor(color, mode);
163 }
164 ALWAYS_INLINE void clear(SkColor color) { canvas_->clear(color); }
165 ALWAYS_INLINE void discard() { canvas_->discard(); }
166
167 ALWAYS_INLINE void drawLine(SkScalar x0,
168 SkScalar y0,
169 SkScalar x1,
170 SkScalar y1,
171 const PaintFlags& flags) {
172 canvas_->drawLine(x0, y0, x1, y1, ToSkPaint(flags));
173 }
174 ALWAYS_INLINE void drawRect(const SkRect& rect, const PaintFlags& flags) {
175 canvas_->drawRect(rect, ToSkPaint(flags));
176 }
177 ALWAYS_INLINE void drawIRect(const SkIRect& rect, const PaintFlags& flags) {
178 canvas_->drawIRect(rect, ToSkPaint(flags));
179 }
180 ALWAYS_INLINE void drawOval(const SkRect& oval, const PaintFlags& flags) {
181 canvas_->drawOval(oval, ToSkPaint(flags));
182 }
183 ALWAYS_INLINE void drawRRect(const SkRRect& rrect, const PaintFlags& flags) {
184 canvas_->drawRRect(rrect, ToSkPaint(flags));
185 }
186 ALWAYS_INLINE void drawDRRect(const SkRRect& outer,
187 const SkRRect& inner,
188 const PaintFlags& flags) {
189 canvas_->drawDRRect(outer, inner, ToSkPaint(flags));
190 }
191 ALWAYS_INLINE void drawCircle(SkScalar cx,
192 SkScalar cy,
193 SkScalar radius,
194 const PaintFlags& flags) {
195 canvas_->drawCircle(cx, cy, radius, ToSkPaint(flags));
196 }
197 ALWAYS_INLINE void drawArc(const SkRect& oval,
198 SkScalar start_angle,
199 SkScalar sweep_angle,
200 bool use_center,
201 const PaintFlags& flags) {
202 canvas_->drawArc(oval, start_angle, sweep_angle, use_center,
203 ToSkPaint(flags));
204 }
205 ALWAYS_INLINE void drawRoundRect(const SkRect& rect,
206 SkScalar rx,
207 SkScalar ry,
208 const PaintFlags& flags) {
209 canvas_->drawRoundRect(rect, rx, ry, ToSkPaint(flags));
210 }
211 ALWAYS_INLINE void drawPath(const SkPath& path, const PaintFlags& flags) {
212 canvas_->drawPath(path, ToSkPaint(flags));
213 }
214 ALWAYS_INLINE void drawImage(const SkImage* image,
215 SkScalar left,
216 SkScalar top,
217 const PaintFlags* flags = nullptr) {
218 canvas_->drawImage(image, left, top, ToSkPaint(flags));
219 }
220 ALWAYS_INLINE void drawImage(const sk_sp<SkImage>& image,
221 SkScalar left,
222 SkScalar top,
223 const PaintFlags* flags = nullptr) {
224 canvas_->drawImage(image, left, top, ToSkPaint(flags));
225 } 142 }
226 143
227 enum SrcRectConstraint { 144 enum SrcRectConstraint {
228 kStrict_SrcRectConstraint = SkCanvas::kStrict_SrcRectConstraint, 145 kStrict_SrcRectConstraint = SkCanvas::kStrict_SrcRectConstraint,
229 kFast_SrcRectConstraint = SkCanvas::kFast_SrcRectConstraint, 146 kFast_SrcRectConstraint = SkCanvas::kFast_SrcRectConstraint,
230 }; 147 };
231 148
232 ALWAYS_INLINE void drawImageRect( 149 virtual void drawImageRect(const SkImage* image,
233 const SkImage* image, 150 const SkRect& src,
234 const SkRect& src, 151 const SkRect& dst,
235 const SkRect& dst, 152 const PaintFlags* flags,
236 const PaintFlags* flags, 153 SrcRectConstraint constraint) = 0;
237 SrcRectConstraint constraint = kStrict_SrcRectConstraint) { 154 virtual void drawBitmap(const SkBitmap& bitmap,
238 canvas_->drawImageRect( 155 SkScalar left,
239 image, src, dst, ToSkPaint(flags), 156 SkScalar top,
240 static_cast<SkCanvas::SrcRectConstraint>(constraint)); 157 const PaintFlags* flags) = 0;
241 } 158 void drawBitmap(const SkBitmap& bitmap, SkScalar left, SkScalar top) {
242 ALWAYS_INLINE void drawImageRect( 159 drawBitmap(bitmap, left, top, nullptr);
243 const SkImage* image,
244 const SkIRect& isrc,
245 const SkRect& dst,
246 const PaintFlags* flags,
247 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
248 canvas_->drawImageRect(
249 image, isrc, dst, ToSkPaint(flags),
250 static_cast<SkCanvas::SrcRectConstraint>(constraint));
251 }
252 ALWAYS_INLINE void drawImageRect(
253 const SkImage* image,
254 const SkRect& dst,
255 const PaintFlags* flags,
256 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
257 canvas_->drawImageRect(
258 image, dst, ToSkPaint(flags),
259 static_cast<SkCanvas::SrcRectConstraint>(constraint));
260 }
261 ALWAYS_INLINE void drawImageRect(
262 const sk_sp<SkImage>& image,
263 const SkRect& src,
264 const SkRect& dst,
265 const PaintFlags* flags,
266 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
267 canvas_->drawImageRect(
268 image, src, dst, ToSkPaint(flags),
269 static_cast<SkCanvas::SrcRectConstraint>(constraint));
270 }
271 ALWAYS_INLINE void drawImageRect(
272 const sk_sp<SkImage>& image,
273 const SkIRect& isrc,
274 const SkRect& dst,
275 const PaintFlags* flags,
276 SrcRectConstraint cons = kStrict_SrcRectConstraint) {
277 canvas_->drawImageRect(image, isrc, dst, ToSkPaint(flags),
278 static_cast<SkCanvas::SrcRectConstraint>(cons));
279 }
280 ALWAYS_INLINE void drawImageRect(
281 const sk_sp<SkImage>& image,
282 const SkRect& dst,
283 const PaintFlags* flags,
284 SrcRectConstraint cons = kStrict_SrcRectConstraint) {
285 canvas_->drawImageRect(image, dst, ToSkPaint(flags),
286 static_cast<SkCanvas::SrcRectConstraint>(cons));
287 }
288 ALWAYS_INLINE void drawBitmap(const SkBitmap& bitmap,
289 SkScalar left,
290 SkScalar top,
291 const PaintFlags* flags = nullptr) {
292 canvas_->drawBitmap(bitmap, left, top, ToSkPaint(flags));
293 }
294 ALWAYS_INLINE void drawBitmapRect(
295 const SkBitmap& bitmap,
296 const SkRect& src,
297 const SkRect& dst,
298 const PaintFlags* flags,
299 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
300 canvas_->drawBitmapRect(
301 bitmap, src, dst, ToSkPaint(flags),
302 static_cast<SkCanvas::SrcRectConstraint>(constraint));
303 }
304 ALWAYS_INLINE void drawBitmapRect(
305 const SkBitmap& bitmap,
306 const SkIRect& isrc,
307 const SkRect& dst,
308 const PaintFlags* flags,
309 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
310 canvas_->drawBitmapRect(
311 bitmap, isrc, dst, ToSkPaint(flags),
312 static_cast<SkCanvas::SrcRectConstraint>(constraint));
313 }
314 ALWAYS_INLINE void drawBitmapRect(
315 const SkBitmap& bitmap,
316 const SkRect& dst,
317 const PaintFlags* flags,
318 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
319 canvas_->drawBitmapRect(
320 bitmap, dst, ToSkPaint(flags),
321 static_cast<SkCanvas::SrcRectConstraint>(constraint));
322 } 160 }
323 161
324 ALWAYS_INLINE void drawText(const void* text, 162 virtual void drawText(const void* text,
325 size_t byte_length, 163 size_t byte_length,
326 SkScalar x, 164 SkScalar x,
327 SkScalar y, 165 SkScalar y,
328 const PaintFlags& flags) { 166 const PaintFlags& flags) = 0;
329 canvas_->drawText(text, byte_length, x, y, ToSkPaint(flags)); 167 virtual void drawPosText(const void* text,
330 } 168 size_t byte_length,
331 ALWAYS_INLINE void drawPosText(const void* text, 169 const SkPoint pos[],
332 size_t byte_length, 170 const PaintFlags& flags) = 0;
333 const SkPoint pos[], 171 virtual void drawTextBlob(const SkTextBlob* blob,
334 const PaintFlags& flags) { 172 SkScalar x,
335 canvas_->drawPosText(text, byte_length, pos, ToSkPaint(flags)); 173 SkScalar y,
336 } 174 const PaintFlags& flags) = 0;
337 ALWAYS_INLINE void drawTextBlob(const SkTextBlob* blob, 175 virtual void drawTextBlob(const sk_sp<SkTextBlob>& blob,
338 SkScalar x, 176 SkScalar x,
339 SkScalar y, 177 SkScalar y,
340 const PaintFlags& flags) { 178 const PaintFlags& flags) = 0;
341 canvas_->drawTextBlob(blob, x, y, ToSkPaint(flags));
342 }
343 ALWAYS_INLINE void drawTextBlob(const sk_sp<SkTextBlob>& blob,
344 SkScalar x,
345 SkScalar y,
346 const PaintFlags& flags) {
347 canvas_->drawTextBlob(blob, x, y, ToSkPaint(flags));
348 }
349 179
350 ALWAYS_INLINE void drawPicture(const PaintRecord* record) { 180 virtual void drawPicture(const PaintRecord* record) = 0;
351 canvas_->drawPicture(ToSkPicture(record)); 181 virtual void drawPicture(const PaintRecord* record,
352 } 182 const SkMatrix* matrix,
353 ALWAYS_INLINE void drawPicture(const PaintRecord* record, 183 const PaintFlags* flags) = 0;
354 const SkMatrix* matrix, 184 virtual void drawPicture(sk_sp<PaintRecord> record) = 0;
355 const PaintFlags* flags) {
356 canvas_->drawPicture(ToSkPicture(record), matrix, ToSkPaint(flags));
357 }
358 ALWAYS_INLINE void drawPicture(sk_sp<PaintRecord> record) {
359 drawPicture(record.get());
360 }
361 185
362 ALWAYS_INLINE bool isClipEmpty() const { return canvas_->isClipEmpty(); } 186 virtual bool isClipEmpty() const = 0;
363 ALWAYS_INLINE bool isClipRect() const { return canvas_->isClipRect(); } 187 virtual bool isClipRect() const = 0;
364 ALWAYS_INLINE const SkMatrix& getTotalMatrix() const { 188 virtual const SkMatrix& getTotalMatrix() const = 0;
365 return canvas_->getTotalMatrix();
366 }
367 189
368 // For GraphicsContextCanvas only. Maybe this could be rewritten? 190 // For GraphicsContextCanvas only. Maybe this could be rewritten?
369 ALWAYS_INLINE void temporary_internal_describeTopLayer(SkMatrix* matrix, 191 virtual void temporary_internal_describeTopLayer(SkMatrix* matrix,
370 SkIRect* clip_bounds) { 192 SkIRect* clip_bounds) = 0;
371 return canvas_->temporary_internal_describeTopLayer(matrix, clip_bounds); 193
372 } 194 virtual bool ToPixmap(SkPixmap* output) = 0;
195 virtual void AnnotateRectWithURL(const SkRect& rect, SkData* data) = 0;
196 virtual void AnnotateNamedDestination(const SkPoint& point, SkData* data) = 0;
197 virtual void AnnotateLinkToDestination(const SkRect& rect, SkData* data) = 0;
373 198
374 protected: 199 protected:
375 friend class PaintSurface; 200 friend class PaintSurface;
376 friend class PaintRecorder; 201 friend class PaintRecorder;
377 friend CC_PAINT_EXPORT void PaintCanvasAnnotateRectWithURL( 202 friend CC_PAINT_EXPORT void PaintCanvasAnnotateRectWithURL(
378 PaintCanvas* canvas, 203 PaintCanvas* canvas,
379 const SkRect& rect, 204 const SkRect& rect,
380 SkData* data); 205 SkData* data);
381 friend CC_PAINT_EXPORT void PaintCanvasAnnotateNamedDestination( 206 friend CC_PAINT_EXPORT void PaintCanvasAnnotateNamedDestination(
382 PaintCanvas* canvas, 207 PaintCanvas* canvas,
383 const SkPoint& point, 208 const SkPoint& point,
384 SkData* data); 209 SkData* data);
385 friend CC_PAINT_EXPORT void PaintCanvasAnnotateLinkToDestination( 210 friend CC_PAINT_EXPORT void PaintCanvasAnnotateLinkToDestination(
386 PaintCanvas* canvas, 211 PaintCanvas* canvas,
387 const SkRect& rect, 212 const SkRect& rect,
388 SkData* data); 213 SkData* data);
389 friend CC_PAINT_EXPORT bool ToPixmap(PaintCanvas* canvas, SkPixmap* output); 214 friend CC_PAINT_EXPORT bool ToPixmap(PaintCanvas* canvas, SkPixmap* output);
390
391 private:
392 SkCanvas* canvas_;
393 std::unique_ptr<SkCanvas> owned_;
394
395 DISALLOW_COPY_AND_ASSIGN(PaintCanvas);
396 }; 215 };
397 216
398 class CC_PAINT_EXPORT PaintCanvasAutoRestore { 217 class CC_PAINT_EXPORT PaintCanvasAutoRestore {
399 public: 218 public:
400 ALWAYS_INLINE PaintCanvasAutoRestore(PaintCanvas* canvas, bool save) 219 PaintCanvasAutoRestore(PaintCanvas* canvas, bool save) : canvas_(canvas) {
401 : canvas_(canvas) {
402 if (canvas_) { 220 if (canvas_) {
403 save_count_ = canvas_->getSaveCount(); 221 save_count_ = canvas_->getSaveCount();
404 if (save) { 222 if (save) {
405 canvas_->save(); 223 canvas_->save();
406 } 224 }
407 } 225 }
408 } 226 }
409 227
410 ALWAYS_INLINE ~PaintCanvasAutoRestore() { 228 ~PaintCanvasAutoRestore() {
411 if (canvas_) { 229 if (canvas_) {
412 canvas_->restoreToCount(save_count_); 230 canvas_->restoreToCount(save_count_);
413 } 231 }
414 } 232 }
415 233
416 ALWAYS_INLINE void restore() { 234 void restore() {
417 if (canvas_) { 235 if (canvas_) {
418 canvas_->restoreToCount(save_count_); 236 canvas_->restoreToCount(save_count_);
419 canvas_ = nullptr; 237 canvas_ = nullptr;
420 } 238 }
421 } 239 }
422 240
423 private: 241 private:
424 PaintCanvas* canvas_ = nullptr; 242 PaintCanvas* canvas_ = nullptr;
425 int save_count_ = 0; 243 int save_count_ = 0;
426 }; 244 };
(...skipping 21 matching lines...) Expand all
448 const SkPoint& point, 266 const SkPoint& point,
449 SkData* data); 267 SkData* data);
450 268
451 CC_PAINT_EXPORT void PaintCanvasAnnotateLinkToDestination(PaintCanvas* canvas, 269 CC_PAINT_EXPORT void PaintCanvasAnnotateLinkToDestination(PaintCanvas* canvas,
452 const SkRect& rect, 270 const SkRect& rect,
453 SkData* data); 271 SkData* data);
454 272
455 } // namespace cc 273 } // namespace cc
456 274
457 #endif // CC_PAINT_PAINT_CANVAS_H_ 275 #endif // CC_PAINT_PAINT_CANVAS_H_
OLDNEW
« no previous file with comments | « cc/paint/BUILD.gn ('k') | cc/paint/paint_canvas.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698