OLD | NEW |
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_SKIA_PAINT_CANVAS_H_ | 5 #ifndef CC_PAINT_RECORD_PAINT_CANVAS_H_ |
6 #define CC_PAINT_SKIA_PAINT_CANVAS_H_ | 6 #define CC_PAINT_RECORD_PAINT_CANVAS_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "build/build_config.h" | 13 #include "build/build_config.h" |
14 #include "cc/paint/paint_canvas.h" | 14 #include "cc/paint/paint_canvas.h" |
15 #include "cc/paint/paint_flags.h" | 15 #include "cc/paint/paint_flags.h" |
16 #include "cc/paint/paint_record.h" | 16 #include "cc/paint/paint_record.h" |
17 #include "third_party/skia/include/core/SkCanvas.h" | 17 #include "third_party/skia/include/utils/SkNoDrawCanvas.h" |
18 | 18 |
19 namespace cc { | 19 namespace cc { |
20 | 20 |
| 21 class PaintOpBuffer; |
21 class PaintFlags; | 22 class PaintFlags; |
22 | 23 |
23 // A PaintCanvas derived class that passes PaintCanvas APIs through to | 24 class CC_PAINT_EXPORT RecordPaintCanvas final : public PaintCanvas { |
24 // an SkCanvas. This is more efficient than recording to a PaintRecord | |
25 // and then playing back to an SkCanvas. | |
26 class CC_PAINT_EXPORT SkiaPaintCanvas final : public PaintCanvas { | |
27 public: | 25 public: |
28 explicit SkiaPaintCanvas(SkCanvas* canvas); | 26 explicit RecordPaintCanvas(PaintOpBuffer* buffer, const SkRect& cull_rect); |
29 explicit SkiaPaintCanvas(const SkBitmap& bitmap); | 27 ~RecordPaintCanvas() override; |
30 explicit SkiaPaintCanvas(const SkBitmap& bitmap, const SkSurfaceProps& props); | |
31 explicit SkiaPaintCanvas(SkiaPaintCanvas&& other); | |
32 ~SkiaPaintCanvas() override; | |
33 | |
34 SkiaPaintCanvas& operator=(SkiaPaintCanvas&& other) = default; | |
35 | 28 |
36 SkMetaData& getMetaData() override; | 29 SkMetaData& getMetaData() override; |
37 SkImageInfo imageInfo() const override; | 30 SkImageInfo imageInfo() const override; |
38 | 31 |
39 void flush() override; | 32 void flush() override; |
40 | 33 |
41 int save() override; | 34 int save() override; |
42 int saveLayer(const SkRect* bounds, const PaintFlags* flags) override; | 35 int saveLayer(const SkRect* bounds, const PaintFlags* flags) override; |
43 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) override; | 36 int saveLayerAlpha(const SkRect* bounds, uint8_t alpha) override; |
44 | 37 |
45 void restore() override; | 38 void restore() override; |
46 int getSaveCount() const override; | 39 int getSaveCount() const override; |
47 void restoreToCount(int save_count) override; | 40 void restoreToCount(int save_count) override; |
48 void translate(SkScalar dx, SkScalar dy) override; | 41 void translate(SkScalar dx, SkScalar dy) override; |
49 void scale(SkScalar sx, SkScalar sy) override; | 42 void scale(SkScalar sx, SkScalar sy) override; |
50 void rotate(SkScalar degrees) override; | 43 void rotate(SkScalar degrees) override; |
51 void concat(const SkMatrix& matrix) override; | 44 void concat(const SkMatrix& matrix) override; |
52 void setMatrix(const SkMatrix& matrix) override; | 45 void setMatrix(const SkMatrix& matrix) override; |
53 | 46 |
54 void clipRect(const SkRect& rect, SkClipOp op, bool do_anti_alias) override; | 47 void clipRect(const SkRect& rect, SkClipOp op, bool antialias) override; |
55 void clipRRect(const SkRRect& rrect, | 48 void clipRRect(const SkRRect& rrect, SkClipOp op, bool antialias) override; |
56 SkClipOp op, | 49 void clipPath(const SkPath& path, SkClipOp op, bool antialias) override; |
57 bool do_anti_alias) override; | |
58 void clipPath(const SkPath& path, SkClipOp op, bool do_anti_alias) override; | |
59 bool quickReject(const SkRect& rect) const override; | 50 bool quickReject(const SkRect& rect) const override; |
60 bool quickReject(const SkPath& path) const override; | 51 bool quickReject(const SkPath& path) const override; |
61 SkRect getLocalClipBounds() const override; | 52 SkRect getLocalClipBounds() const override; |
62 bool getLocalClipBounds(SkRect* bounds) const override; | 53 bool getLocalClipBounds(SkRect* bounds) const override; |
63 SkIRect getDeviceClipBounds() const override; | 54 SkIRect getDeviceClipBounds() const override; |
64 bool getDeviceClipBounds(SkIRect* bounds) const override; | 55 bool getDeviceClipBounds(SkIRect* bounds) const override; |
65 void drawColor(SkColor color, SkBlendMode mode) override; | 56 void drawColor(SkColor color, SkBlendMode mode) override; |
66 void clear(SkColor color) override; | 57 void clear(SkColor color) override; |
67 | 58 |
68 void drawLine(SkScalar x0, | 59 void drawLine(SkScalar x0, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 // Don't shadow non-virtual helper functions. | 128 // Don't shadow non-virtual helper functions. |
138 using PaintCanvas::clipRect; | 129 using PaintCanvas::clipRect; |
139 using PaintCanvas::clipRRect; | 130 using PaintCanvas::clipRRect; |
140 using PaintCanvas::clipPath; | 131 using PaintCanvas::clipPath; |
141 using PaintCanvas::drawBitmap; | 132 using PaintCanvas::drawBitmap; |
142 using PaintCanvas::drawColor; | 133 using PaintCanvas::drawColor; |
143 using PaintCanvas::drawImage; | 134 using PaintCanvas::drawImage; |
144 using PaintCanvas::drawPicture; | 135 using PaintCanvas::drawPicture; |
145 | 136 |
146 private: | 137 private: |
147 SkCanvas* canvas_; | 138 PaintOpBuffer* buffer_; |
148 std::unique_ptr<SkCanvas> owned_; | |
149 | 139 |
150 DISALLOW_COPY_AND_ASSIGN(SkiaPaintCanvas); | 140 // TODO(enne): Although RecordPaintCanvas is mostly a write-only interface |
| 141 // where paint commands are stored, occasionally users of PaintCanvas want |
| 142 // to ask stateful questions mid-stream of clip and transform state. |
| 143 // To avoid duplicating all this code (for now?), just forward to an SkCanvas |
| 144 // that's not backed by anything but can answer these questions. |
| 145 SkNoDrawCanvas canvas_; |
151 }; | 146 }; |
152 | 147 |
153 } // namespace cc | 148 } // namespace cc |
154 | 149 |
155 #endif // CC_PAINT_SKIA_PAINT_CANVAS_H_ | 150 #endif // CC_PAINT_RECORD_PAINT_CANVAS_H_ |
OLD | NEW |