enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 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" |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 12 | #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 | |
| 19 | namespace cc { |
| 20 | |
Vladimir Levin | 53a4abf | 2017-07-24 23:54:19 | [diff] [blame] | 21 | class DisplayItemList; |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 22 | class PaintFlags; |
| 23 | |
Aaron Krajeski | 86ff5cc | 2019-12-20 20:31:42 | [diff] [blame] | 24 | class CC_PAINT_EXPORT RecordPaintCanvas : public PaintCanvas { |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 25 | public: |
Vladimir Levin | 53a4abf | 2017-07-24 23:54:19 | [diff] [blame] | 26 | RecordPaintCanvas(DisplayItemList* list, const SkRect& bounds); |
Vladimir Levin | f06d1cd7 | 2019-03-13 18:24:10 | [diff] [blame] | 27 | RecordPaintCanvas(const RecordPaintCanvas&) = delete; |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 28 | ~RecordPaintCanvas() override; |
| 29 | |
Vladimir Levin | f06d1cd7 | 2019-03-13 18:24:10 | [diff] [blame] | 30 | RecordPaintCanvas& operator=(const RecordPaintCanvas&) = delete; |
| 31 | |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 32 | SkImageInfo imageInfo() const override; |
| 33 | |
Tom Anderson | bec0951 | 2019-09-16 20:32:16 | [diff] [blame] | 34 | void* accessTopLayerPixels(SkImageInfo* info, |
| 35 | size_t* rowBytes, |
| 36 | SkIPoint* origin = nullptr) override; |
| 37 | |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 38 | void flush() override; |
| 39 | |
| 40 | int save() override; |
| 41 | int saveLayer(const SkRect* bounds, const PaintFlags* flags) override; |
Peter Kasting | fe4ba93 | 2019-01-07 20:21:05 | [diff] [blame] | 42 | int saveLayerAlpha(const SkRect* bounds, uint8_t alpha) override; |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 43 | |
| 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; |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 56 | 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; |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 75 | 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 Keshav | cf4ceef1 | 2018-10-19 17:56:51 | [diff] [blame] | 89 | void drawSkottie(scoped_refptr<SkottieWrapper> skottie, |
| 90 | const SkRect& dst, |
| 91 | float t) override; |
Khushal | 464808c9 | 2018-10-19 23:45:59 | [diff] [blame] | 92 | void drawTextBlob(sk_sp<SkTextBlob> blob, |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 93 | SkScalar x, |
| 94 | SkScalar y, |
| 95 | const PaintFlags& flags) override; |
Tao Bai | edaf8709 | 2019-01-30 23:12:54 | [diff] [blame] | 96 | void drawTextBlob(sk_sp<SkTextBlob> blob, |
| 97 | SkScalar x, |
| 98 | SkScalar y, |
Tao Bai | 1e1deb41 | 2019-07-21 16:14:00 | [diff] [blame] | 99 | NodeId node_id, |
| 100 | const PaintFlags& flags) override; |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 101 | |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 102 | void drawPicture(sk_sp<const PaintRecord> record) override; |
| 103 | |
| 104 | bool isClipEmpty() const override; |
Mike Reed | f97e2d16 | 2020-01-07 15:26:43 | [diff] [blame] | 105 | SkMatrix getTotalMatrix() const override; |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 106 | |
| 107 | void Annotate(AnnotationType type, |
| 108 | const SkRect& rect, |
| 109 | sk_sp<SkData> data) override; |
Wei Li | 2a9bfe4 | 2018-01-13 05:42:56 | [diff] [blame] | 110 | void recordCustomData(uint32_t id) override; |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 111 | |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 112 | // Don't shadow non-virtual helper functions. |
| 113 | using PaintCanvas::clipRect; |
| 114 | using PaintCanvas::clipRRect; |
| 115 | using PaintCanvas::clipPath; |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 116 | using PaintCanvas::drawColor; |
| 117 | using PaintCanvas::drawImage; |
| 118 | using PaintCanvas::drawPicture; |
| 119 | |
| 120 | private: |
| 121 | const SkNoDrawCanvas* GetCanvas() const; |
| 122 | SkNoDrawCanvas* GetCanvas(); |
| 123 | |
Walter Korman | 944f485 | 2017-10-30 19:41:09 | [diff] [blame] | 124 | bool InitializedWithRecordingBounds() const; |
| 125 | |
Vladimir Levin | 53a4abf | 2017-07-24 23:54:19 | [diff] [blame] | 126 | DisplayItemList* list_; |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 127 | |
| 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_; |
danakj | 29ef120 | 2017-05-23 18:06:31 | [diff] [blame] | 137 | SkRect recording_bounds_; |
enne | 59df29de | 2017-05-02 03:23:37 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | } // namespace cc |
| 141 | |
| 142 | #endif // CC_PAINT_RECORD_PAINT_CANVAS_H_ |