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

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

Issue 2690583002: Make cc/paint have concrete types (Closed)
Patch Set: Add missing file 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
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"
11 #include "base/logging.h"
12 #include "base/macros.h"
8 #include "build/build_config.h" 13 #include "build/build_config.h"
9 #include "cc/paint/paint_export.h" 14 #include "cc/paint/paint_export.h"
15 #include "cc/paint/paint_flags.h"
10 #include "third_party/skia/include/core/SkCanvas.h" 16 #include "third_party/skia/include/core/SkCanvas.h"
11 #include "third_party/skia/include/utils/SkNWayCanvas.h"
12 #include "third_party/skia/include/utils/SkNoDrawCanvas.h" 17 #include "third_party/skia/include/utils/SkNoDrawCanvas.h"
13 18
14 namespace cc { 19 namespace cc {
15 20
16 using PaintCanvas = SkCanvas; 21 class PaintFlags;
17 using PaintCanvasNoDraw = SkNoDrawCanvas; 22 class PaintRecord;
18 using PaintCanvasAutoRestore = SkAutoCanvasRestore; 23
19 24 class CC_PAINT_EXPORT PaintCanvas {
20 class CC_PAINT_EXPORT PaintCanvasPassThrough : public SkNWayCanvas {
21 public: 25 public:
22 explicit PaintCanvasPassThrough(SkCanvas* canvas); 26 // TODO(enne): remove all constructors but the one that takes an SkCanvas
23 PaintCanvasPassThrough(int width, int height); 27 // and a future one that will take a PaintOpBuffer to build a PaintRecord.
24 ~PaintCanvasPassThrough() override; 28 explicit PaintCanvas(SkCanvas* canvas);
29 explicit PaintCanvas(const SkBitmap& bitmap);
30 explicit PaintCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props);
31 ~PaintCanvas();
32
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
39 // doesn't really make sense for recording. However, this gets used by
40 // SkCanvasVideoRenderer which takes a PaintCanvas to paint both
41 // software and hardware video. This is super entangled with ImageBuffer
42 // and canvas/video painting in Blink where the same paths are used for
43 // both recording and gpu work.
44 ALWAYS_INLINE void flush() { canvas_->flush(); }
45
46 ALWAYS_INLINE SkISize getBaseLayerSize() const {
47 return canvas_->getBaseLayerSize();
48 }
49 ALWAYS_INLINE bool peekPixels(SkPixmap* pixmap) {
50 return canvas_->peekPixels(pixmap);
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 rowBytes,
danakj 2017/03/03 18:33:18 row_bytes
69 int x,
70 int y) {
71 return canvas_->writePixels(info, pixels, rowBytes, 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 }
87
88 using SaveLayerRec = SkCanvas::SaveLayerRec;
89 ALWAYS_INLINE int saveLayer(const SaveLayerRec& rec) {
90 return canvas_->saveLayer(rec);
91 }
92 ALWAYS_INLINE void restore() { canvas_->restore(); }
93 ALWAYS_INLINE int getSaveCount() const { return canvas_->getSaveCount(); }
94 ALWAYS_INLINE void restoreToCount(int save_count) {
95 canvas_->restoreToCount(save_count);
96 }
97 ALWAYS_INLINE void translate(SkScalar dx, SkScalar dy) {
98 canvas_->translate(dx, dy);
99 }
100 ALWAYS_INLINE void scale(SkScalar sx, SkScalar sy) { canvas_->scale(sx, sy); }
101 ALWAYS_INLINE void rotate(SkScalar degrees) { canvas_->rotate(degrees); }
102 ALWAYS_INLINE void rotate(SkScalar degrees, SkScalar px, SkScalar py) {
103 canvas_->rotate(degrees, px, py);
104 }
105 ALWAYS_INLINE void skew(SkScalar sx, SkScalar sy) { canvas_->skew(sx, sy); }
106 ALWAYS_INLINE void concat(const SkMatrix& matrix) { canvas_->concat(matrix); }
107 ALWAYS_INLINE void setMatrix(const SkMatrix& matrix) {
108 canvas_->setMatrix(matrix);
109 }
110 ALWAYS_INLINE void resetMatrix() { canvas_->resetMatrix(); }
111 ALWAYS_INLINE void clipRect(const SkRect& rect,
112 SkClipOp op,
113 bool do_anti_alias = false) {
114 canvas_->clipRect(rect, op, do_anti_alias);
115 }
116 ALWAYS_INLINE void clipRect(const SkRect& rect, bool do_anti_alias = false) {
117 canvas_->clipRect(rect, do_anti_alias);
118 }
119 ALWAYS_INLINE void clipRRect(const SkRRect& rrect,
120 SkClipOp op,
121 bool do_anti_alias) {
122 canvas_->clipRRect(rrect, op, do_anti_alias);
123 }
124 ALWAYS_INLINE void clipRRect(const SkRRect& rrect, SkClipOp op) {
125 canvas_->clipRRect(rrect, op);
126 }
127 ALWAYS_INLINE void clipRRect(const SkRRect& rrect,
128 bool do_anti_alias = false) {
129 canvas_->clipRRect(rrect, do_anti_alias);
130 }
131 ALWAYS_INLINE void clipPath(const SkPath& path,
132 SkClipOp op,
133 bool do_anti_alias) {
134 canvas_->clipPath(path, op, do_anti_alias);
135 }
136 ALWAYS_INLINE void clipPath(const SkPath& path, SkClipOp op) {
137 canvas_->clipPath(path, op);
138 }
139 ALWAYS_INLINE void clipPath(const SkPath& path, bool do_anti_alias = false) {
140 canvas_->clipPath(path, do_anti_alias);
141 }
142 ALWAYS_INLINE void clipRegion(const SkRegion& device_region,
143 SkClipOp op = SkClipOp::kIntersect) {
144 canvas_->clipRegion(device_region, op);
145 }
146 ALWAYS_INLINE bool quickReject(const SkRect& rect) const {
147 return canvas_->quickReject(rect);
148 }
149 ALWAYS_INLINE bool quickReject(const SkPath& path) const {
150 return canvas_->quickReject(path);
151 }
152 ALWAYS_INLINE SkRect getLocalClipBounds() const {
153 return canvas_->getLocalClipBounds();
154 }
155 ALWAYS_INLINE bool getLocalClipBounds(SkRect* bounds) const {
156 return canvas_->getLocalClipBounds(bounds);
157 }
158 ALWAYS_INLINE SkIRect getDeviceClipBounds() const {
159 return canvas_->getDeviceClipBounds();
160 }
161 ALWAYS_INLINE bool getDeviceClipBounds(SkIRect* bounds) const {
162 return canvas_->getDeviceClipBounds(bounds);
163 }
164 ALWAYS_INLINE void drawColor(SkColor color,
165 SkBlendMode mode = SkBlendMode::kSrcOver) {
166 canvas_->drawColor(color, mode);
167 }
168 ALWAYS_INLINE void clear(SkColor color) { canvas_->clear(color); }
169 ALWAYS_INLINE void discard() { canvas_->discard(); }
170
171 ALWAYS_INLINE void drawLine(SkScalar x0,
172 SkScalar y0,
173 SkScalar x1,
174 SkScalar y1,
175 const PaintFlags& flags) {
176 canvas_->drawLine(x0, y0, x1, y1, ToSkPaint(flags));
177 }
178 ALWAYS_INLINE void drawRect(const SkRect& rect, const PaintFlags& flags) {
179 canvas_->drawRect(rect, ToSkPaint(flags));
180 }
181 ALWAYS_INLINE void drawIRect(const SkIRect& rect, const PaintFlags& flags) {
182 canvas_->drawIRect(rect, ToSkPaint(flags));
183 }
184 ALWAYS_INLINE void drawOval(const SkRect& oval, const PaintFlags& flags) {
185 canvas_->drawOval(oval, ToSkPaint(flags));
186 }
187 ALWAYS_INLINE void drawRRect(const SkRRect& rrect, const PaintFlags& flags) {
188 canvas_->drawRRect(rrect, ToSkPaint(flags));
189 }
190 ALWAYS_INLINE void drawDRRect(const SkRRect& outer,
191 const SkRRect& inner,
192 const PaintFlags& flags) {
193 canvas_->drawDRRect(outer, inner, ToSkPaint(flags));
194 }
195 ALWAYS_INLINE void drawCircle(SkScalar cx,
196 SkScalar cy,
197 SkScalar radius,
198 const PaintFlags& flags) {
199 canvas_->drawCircle(cx, cy, radius, ToSkPaint(flags));
200 }
201 ALWAYS_INLINE void drawArc(const SkRect& oval,
202 SkScalar start_angle,
203 SkScalar sweep_angle,
204 bool use_center,
205 const PaintFlags& flags) {
206 canvas_->drawArc(oval, start_angle, sweep_angle, use_center,
207 ToSkPaint(flags));
208 }
209 ALWAYS_INLINE void drawRoundRect(const SkRect& rect,
210 SkScalar rx,
211 SkScalar ry,
212 const PaintFlags& flags) {
213 canvas_->drawRoundRect(rect, rx, ry, ToSkPaint(flags));
214 }
215 ALWAYS_INLINE void drawPath(const SkPath& path, const PaintFlags& flags) {
216 canvas_->drawPath(path, ToSkPaint(flags));
217 }
218 ALWAYS_INLINE void drawImage(const SkImage* image,
219 SkScalar left,
220 SkScalar top,
221 const PaintFlags* flags = nullptr) {
222 canvas_->drawImage(image, left, top, ToSkPaint(flags));
223 }
224 ALWAYS_INLINE void drawImage(const sk_sp<SkImage>& image,
225 SkScalar left,
226 SkScalar top,
227 const PaintFlags* flags = nullptr) {
228 canvas_->drawImage(image, left, top, ToSkPaint(flags));
229 }
230
231 enum SrcRectConstraint {
232 kStrict_SrcRectConstraint = SkCanvas::kStrict_SrcRectConstraint,
233 kFast_SrcRectConstraint = SkCanvas::kFast_SrcRectConstraint,
234 };
235
236 ALWAYS_INLINE void drawImageRect(
237 const SkImage* image,
238 const SkRect& src,
239 const SkRect& dst,
240 const PaintFlags* flags,
241 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
242 canvas_->drawImageRect(
243 image, src, dst, ToSkPaint(flags),
244 static_cast<SkCanvas::SrcRectConstraint>(constraint));
245 }
246 ALWAYS_INLINE void drawImageRect(
247 const SkImage* image,
248 const SkIRect& isrc,
249 const SkRect& dst,
250 const PaintFlags* flags,
251 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
252 canvas_->drawImageRect(
253 image, isrc, dst, ToSkPaint(flags),
254 static_cast<SkCanvas::SrcRectConstraint>(constraint));
255 }
256 ALWAYS_INLINE void drawImageRect(
257 const SkImage* image,
258 const SkRect& dst,
259 const PaintFlags* flags,
260 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
261 canvas_->drawImageRect(
262 image, dst, ToSkPaint(flags),
263 static_cast<SkCanvas::SrcRectConstraint>(constraint));
264 }
265 ALWAYS_INLINE void drawImageRect(
266 const sk_sp<SkImage>& image,
267 const SkRect& src,
268 const SkRect& dst,
269 const PaintFlags* flags,
270 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
271 canvas_->drawImageRect(
272 image, src, dst, ToSkPaint(flags),
273 static_cast<SkCanvas::SrcRectConstraint>(constraint));
274 }
275 ALWAYS_INLINE void drawImageRect(
276 const sk_sp<SkImage>& image,
277 const SkIRect& isrc,
278 const SkRect& dst,
279 const PaintFlags* flags,
280 SrcRectConstraint cons = kStrict_SrcRectConstraint) {
281 canvas_->drawImageRect(image, isrc, dst, ToSkPaint(flags),
282 static_cast<SkCanvas::SrcRectConstraint>(cons));
283 }
284 ALWAYS_INLINE void drawImageRect(
285 const sk_sp<SkImage>& image,
286 const SkRect& dst,
287 const PaintFlags* flags,
288 SrcRectConstraint cons = kStrict_SrcRectConstraint) {
289 canvas_->drawImageRect(image, dst, ToSkPaint(flags),
290 static_cast<SkCanvas::SrcRectConstraint>(cons));
291 }
292 ALWAYS_INLINE void drawBitmap(const SkBitmap& bitmap,
293 SkScalar left,
294 SkScalar top,
295 const PaintFlags* flags = nullptr) {
296 canvas_->drawBitmap(bitmap, left, top, ToSkPaint(flags));
297 }
298 ALWAYS_INLINE void drawBitmapRect(
299 const SkBitmap& bitmap,
300 const SkRect& src,
301 const SkRect& dst,
302 const PaintFlags* flags,
303 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
304 canvas_->drawBitmapRect(
305 bitmap, src, dst, ToSkPaint(flags),
306 static_cast<SkCanvas::SrcRectConstraint>(constraint));
307 }
308 ALWAYS_INLINE void drawBitmapRect(
309 const SkBitmap& bitmap,
310 const SkIRect& isrc,
311 const SkRect& dst,
312 const PaintFlags* flags,
313 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
314 canvas_->drawBitmapRect(
315 bitmap, isrc, dst, ToSkPaint(flags),
316 static_cast<SkCanvas::SrcRectConstraint>(constraint));
317 }
318 ALWAYS_INLINE void drawBitmapRect(
319 const SkBitmap& bitmap,
320 const SkRect& dst,
321 const PaintFlags* flags,
322 SrcRectConstraint constraint = kStrict_SrcRectConstraint) {
323 canvas_->drawBitmapRect(
324 bitmap, dst, ToSkPaint(flags),
325 static_cast<SkCanvas::SrcRectConstraint>(constraint));
326 }
327
328 ALWAYS_INLINE void drawText(const void* text,
329 size_t byte_length,
330 SkScalar x,
331 SkScalar y,
332 const PaintFlags& flags) {
333 canvas_->drawText(text, byte_length, x, y, ToSkPaint(flags));
334 }
335 ALWAYS_INLINE void drawPosText(const void* text,
336 size_t byte_length,
337 const SkPoint pos[],
338 const PaintFlags& flags) {
339 canvas_->drawPosText(text, byte_length, pos, ToSkPaint(flags));
340 }
341 ALWAYS_INLINE void drawTextBlob(const SkTextBlob* blob,
342 SkScalar x,
343 SkScalar y,
344 const PaintFlags& flags) {
345 canvas_->drawTextBlob(blob, x, y, ToSkPaint(flags));
346 }
347 ALWAYS_INLINE void drawTextBlob(const sk_sp<SkTextBlob>& blob,
348 SkScalar x,
349 SkScalar y,
350 const PaintFlags& flags) {
351 canvas_->drawTextBlob(blob, x, y, ToSkPaint(flags));
352 }
353
354 ALWAYS_INLINE void drawPicture(const PaintRecord* record) {
355 canvas_->drawPicture(ToSkPicture(record));
356 }
357 ALWAYS_INLINE void drawPicture(const PaintRecord* record,
358 const SkMatrix* matrix,
359 const PaintFlags* flags) {
360 canvas_->drawPicture(ToSkPicture(record), matrix, ToSkPaint(flags));
361 }
362 ALWAYS_INLINE void drawPicture(sk_sp<PaintRecord> record) {
363 drawPicture(record.get());
364 }
365
366 ALWAYS_INLINE bool isClipEmpty() const { return canvas_->isClipEmpty(); }
367 ALWAYS_INLINE bool isClipRect() const { return canvas_->isClipRect(); }
368 ALWAYS_INLINE const SkMatrix& getTotalMatrix() const {
369 return canvas_->getTotalMatrix();
370 }
371
372 // For GraphicsContextCanvas only. Maybe this could be rewritten?
373 ALWAYS_INLINE void temporary_internal_describeTopLayer(SkMatrix* matrix,
374 SkIRect* clip_bounds) {
375 return canvas_->temporary_internal_describeTopLayer(matrix, clip_bounds);
376 }
377
378 protected:
379 friend class PaintSurface;
380 friend class PaintRecord;
381 friend class PaintRecorder;
382 friend CC_PAINT_EXPORT void PaintCanvasAnnotateRectWithURL(
383 PaintCanvas* canvas,
384 const SkRect& rect,
385 SkData* data);
386 friend CC_PAINT_EXPORT void PaintCanvasAnnotateNamedDestination(
387 PaintCanvas* canvas,
388 const SkPoint& point,
389 SkData* data);
390 friend CC_PAINT_EXPORT void PaintCanvasAnnotateLinkToDestination(
391 PaintCanvas* canvas,
392 const SkRect& rect,
393 SkData* data);
394 friend CC_PAINT_EXPORT bool ToPixmap(PaintCanvas* canvas, SkPixmap* output);
395
396 private:
397 SkCanvas* canvas_;
398 std::unique_ptr<SkCanvas> owned_;
399
400 DISALLOW_COPY_AND_ASSIGN(PaintCanvas);
25 }; 401 };
26 402
27 // TODO(enne): Move all these functions into PaintCanvas. 403 class CC_PAINT_EXPORT PaintCanvasAutoRestore {
404 public:
405 ALWAYS_INLINE PaintCanvasAutoRestore(PaintCanvas* canvas, bool save)
406 : canvas_(canvas) {
407 if (canvas_) {
408 save_count_ = canvas_->getSaveCount();
409 if (save) {
410 canvas_->save();
411 }
412 }
413 }
414
415 ALWAYS_INLINE ~PaintCanvasAutoRestore() {
416 if (canvas_) {
417 canvas_->restoreToCount(save_count_);
418 }
419 }
420
421 ALWAYS_INLINE void restore() {
422 if (canvas_) {
423 canvas_->restoreToCount(save_count_);
424 canvas_ = nullptr;
425 }
426 }
427
428 private:
429 PaintCanvas* canvas_ = nullptr;
430 int save_count_ = 0;
431 };
432
433 // TODO(enne): Move all these functions into PaintCanvas. These are only
434 // separate now to make the transition to concrete types easier by keeping
435 // the base PaintCanvas type equivalent to the SkCanvas interface and
436 // all these helper functions potentially operating on both.
28 437
29 // PaintCanvas equivalent of skia::GetWritablePixels. 438 // PaintCanvas equivalent of skia::GetWritablePixels.
30 CC_PAINT_EXPORT bool ToPixmap(PaintCanvas* canvas, SkPixmap* output); 439 CC_PAINT_EXPORT bool ToPixmap(PaintCanvas* canvas, SkPixmap* output);
31 440
32 // Following routines are used in print preview workflow to mark the 441 // Following routines are used in print preview workflow to mark the
33 // preview metafile. 442 // preview metafile.
34 #if defined(OS_MACOSX) 443 #if defined(OS_MACOSX)
35 CC_PAINT_EXPORT void SetIsPreviewMetafile(PaintCanvas* canvas, bool is_preview); 444 CC_PAINT_EXPORT void SetIsPreviewMetafile(PaintCanvas* canvas, bool is_preview);
36 CC_PAINT_EXPORT bool IsPreviewMetafile(PaintCanvas* canvas); 445 CC_PAINT_EXPORT bool IsPreviewMetafile(PaintCanvas* canvas);
37 #endif 446 #endif
38 447
448 CC_PAINT_EXPORT void PaintCanvasAnnotateRectWithURL(PaintCanvas* canvas,
449 const SkRect& rect,
450 SkData* data);
451
452 CC_PAINT_EXPORT void PaintCanvasAnnotateNamedDestination(PaintCanvas* canvas,
453 const SkPoint& point,
454 SkData* data);
455
456 CC_PAINT_EXPORT void PaintCanvasAnnotateLinkToDestination(PaintCanvas* canvas,
457 const SkRect& rect,
458 SkData* data);
459
39 } // namespace cc 460 } // namespace cc
40 461
41 #endif // CC_PAINT_PAINT_CANVAS_H_ 462 #endif // CC_PAINT_PAINT_CANVAS_H_
OLDNEW
« no previous file with comments | « cc/paint/BUILD.gn ('k') | cc/paint/paint_canvas.cc » ('j') | cc/paint/paint_flags.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698