[go: nahoru, domu]

blob: ecc386082c8853468f9ef6428eb741eaa1a87be7 [file] [log] [blame]
enne59df29de2017-05-02 03:23:371// 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"
enne59df29de2017-05-02 03:23:3712#include "base/optional.h"
13#include "build/build_config.h"
14#include "cc/paint/paint_canvas.h"
15#include "cc/paint/paint_flags.h"
16#include "cc/paint/paint_record.h"
17#include "third_party/skia/include/utils/SkNoDrawCanvas.h"
18
19namespace cc {
20
Vladimir Levin53a4abf2017-07-24 23:54:1921class DisplayItemList;
enne59df29de2017-05-02 03:23:3722class PaintFlags;
23
Aaron Krajeski86ff5cc2019-12-20 20:31:4224class CC_PAINT_EXPORT RecordPaintCanvas : public PaintCanvas {
enne59df29de2017-05-02 03:23:3725 public:
Vladimir Levin53a4abf2017-07-24 23:54:1926 RecordPaintCanvas(DisplayItemList* list, const SkRect& bounds);
Vladimir Levinf06d1cd72019-03-13 18:24:1027 RecordPaintCanvas(const RecordPaintCanvas&) = delete;
enne59df29de2017-05-02 03:23:3728 ~RecordPaintCanvas() override;
29
Vladimir Levinf06d1cd72019-03-13 18:24:1030 RecordPaintCanvas& operator=(const RecordPaintCanvas&) = delete;
31
enne59df29de2017-05-02 03:23:3732 SkImageInfo imageInfo() const override;
33
Tom Andersonbec09512019-09-16 20:32:1634 void* accessTopLayerPixels(SkImageInfo* info,
35 size_t* rowBytes,
36 SkIPoint* origin = nullptr) override;
37
enne59df29de2017-05-02 03:23:3738 void flush() override;
39
40 int save() override;
41 int saveLayer(const SkRect* bounds, const PaintFlags* flags) override;
Peter Kastingfe4ba932019-01-07 20:21:0542 int saveLayerAlpha(const SkRect* bounds, uint8_t alpha) override;
enne59df29de2017-05-02 03:23:3743
44 void restore() override;
45 int getSaveCount() const override;
46 void restoreToCount(int save_count) override;
47 void translate(SkScalar dx, SkScalar dy) override;
48 void scale(SkScalar sx, SkScalar sy) override;
49 void rotate(SkScalar degrees) override;
50 void concat(const SkMatrix& matrix) override;
51 void setMatrix(const SkMatrix& matrix) override;
52
53 void clipRect(const SkRect& rect, SkClipOp op, bool antialias) override;
54 void clipRRect(const SkRRect& rrect, SkClipOp op, bool antialias) override;
55 void clipPath(const SkPath& path, SkClipOp op, bool antialias) override;
enne59df29de2017-05-02 03:23:3756 SkRect getLocalClipBounds() const override;
57 bool getLocalClipBounds(SkRect* bounds) const override;
58 SkIRect getDeviceClipBounds() const override;
59 bool getDeviceClipBounds(SkIRect* bounds) const override;
60 void drawColor(SkColor color, SkBlendMode mode) override;
61 void clear(SkColor color) override;
62
63 void drawLine(SkScalar x0,
64 SkScalar y0,
65 SkScalar x1,
66 SkScalar y1,
67 const PaintFlags& flags) override;
68 void drawRect(const SkRect& rect, const PaintFlags& flags) override;
69 void drawIRect(const SkIRect& rect, const PaintFlags& flags) override;
70 void drawOval(const SkRect& oval, const PaintFlags& flags) override;
71 void drawRRect(const SkRRect& rrect, const PaintFlags& flags) override;
72 void drawDRRect(const SkRRect& outer,
73 const SkRRect& inner,
74 const PaintFlags& flags) override;
enne59df29de2017-05-02 03:23:3775 void drawRoundRect(const SkRect& rect,
76 SkScalar rx,
77 SkScalar ry,
78 const PaintFlags& flags) override;
79 void drawPath(const SkPath& path, const PaintFlags& flags) override;
80 void drawImage(const PaintImage& image,
81 SkScalar left,
82 SkScalar top,
83 const PaintFlags* flags) override;
84 void drawImageRect(const PaintImage& image,
85 const SkRect& src,
86 const SkRect& dst,
87 const PaintFlags* flags,
88 SrcRectConstraint constraint) override;
Malay Keshavcf4ceef12018-10-19 17:56:5189 void drawSkottie(scoped_refptr<SkottieWrapper> skottie,
90 const SkRect& dst,
91 float t) override;
Khushal464808c92018-10-19 23:45:5992 void drawTextBlob(sk_sp<SkTextBlob> blob,
enne59df29de2017-05-02 03:23:3793 SkScalar x,
94 SkScalar y,
95 const PaintFlags& flags) override;
Tao Baiedaf87092019-01-30 23:12:5496 void drawTextBlob(sk_sp<SkTextBlob> blob,
97 SkScalar x,
98 SkScalar y,
Tao Bai1e1deb412019-07-21 16:14:0099 NodeId node_id,
100 const PaintFlags& flags) override;
enne59df29de2017-05-02 03:23:37101
enne59df29de2017-05-02 03:23:37102 void drawPicture(sk_sp<const PaintRecord> record) override;
103
104 bool isClipEmpty() const override;
Mike Reedf97e2d162020-01-07 15:26:43105 SkMatrix getTotalMatrix() const override;
enne59df29de2017-05-02 03:23:37106
107 void Annotate(AnnotationType type,
108 const SkRect& rect,
109 sk_sp<SkData> data) override;
Wei Li2a9bfe42018-01-13 05:42:56110 void recordCustomData(uint32_t id) override;
enne59df29de2017-05-02 03:23:37111
enne59df29de2017-05-02 03:23:37112 // Don't shadow non-virtual helper functions.
113 using PaintCanvas::clipRect;
114 using PaintCanvas::clipRRect;
115 using PaintCanvas::clipPath;
enne59df29de2017-05-02 03:23:37116 using PaintCanvas::drawColor;
117 using PaintCanvas::drawImage;
118 using PaintCanvas::drawPicture;
119
120 private:
121 const SkNoDrawCanvas* GetCanvas() const;
122 SkNoDrawCanvas* GetCanvas();
123
Walter Korman944f4852017-10-30 19:41:09124 bool InitializedWithRecordingBounds() const;
125
Vladimir Levin53a4abf2017-07-24 23:54:19126 DisplayItemList* list_;
enne59df29de2017-05-02 03:23:37127
128 // TODO(enne): Although RecordPaintCanvas is mostly a write-only interface
129 // where paint commands are stored, occasionally users of PaintCanvas want
130 // to ask stateful questions mid-stream of clip and transform state.
131 // To avoid duplicating all this code (for now?), just forward to an SkCanvas
132 // that's not backed by anything but can answer these questions.
133 //
134 // This is mutable so that const functions (e.g. quickReject) that may
135 // lazy initialize the canvas can still be const.
136 mutable base::Optional<SkNoDrawCanvas> canvas_;
danakj29ef1202017-05-23 18:06:31137 SkRect recording_bounds_;
enne59df29de2017-05-02 03:23:37138};
139
140} // namespace cc
141
142#endif // CC_PAINT_RECORD_PAINT_CANVAS_H_