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 SkISize getBaseLayerSize() const override; | 34 SkISize getBaseLayerSize() const override; |
42 bool readPixels(const SkImageInfo& dest_info, | 35 bool readPixels(const SkImageInfo& dest_info, |
43 void* dest_pixels, | 36 void* dest_pixels, |
44 size_t dest_row_bytes, | 37 size_t dest_row_bytes, |
45 int src_x, | 38 int src_x, |
46 int src_y) override; | 39 int src_y) override; |
47 bool readPixels(SkBitmap* bitmap, int src_x, int src_y) override; | 40 bool readPixels(SkBitmap* bitmap, int src_x, int src_y) override; |
48 bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap) override; | 41 bool readPixels(const SkIRect& srcRect, SkBitmap* bitmap) override; |
49 bool writePixels(const SkImageInfo& info, | 42 bool writePixels(const SkImageInfo& info, |
50 const void* pixels, | 43 const void* pixels, |
51 size_t row_bytes, | 44 size_t row_bytes, |
52 int x, | 45 int x, |
53 int y) override; | 46 int y) override; |
54 int save() override; | 47 int save() override; |
55 int saveLayer(const SkRect* bounds, const PaintFlags* flags) override; | 48 int saveLayer(const SkRect* bounds, const PaintFlags* flags) override; |
56 int saveLayerAlpha(const SkRect* bounds, U8CPU alpha) override; | 49 int saveLayerAlpha(const SkRect* bounds, uint8_t alpha) override; |
57 | 50 |
58 void restore() override; | 51 void restore() override; |
59 int getSaveCount() const override; | 52 int getSaveCount() const override; |
60 void restoreToCount(int save_count) override; | 53 void restoreToCount(int save_count) override; |
61 void translate(SkScalar dx, SkScalar dy) override; | 54 void translate(SkScalar dx, SkScalar dy) override; |
62 void scale(SkScalar sx, SkScalar sy) override; | 55 void scale(SkScalar sx, SkScalar sy) override; |
63 void rotate(SkScalar degrees) override; | 56 void rotate(SkScalar degrees) override; |
64 void concat(const SkMatrix& matrix) override; | 57 void concat(const SkMatrix& matrix) override; |
65 void setMatrix(const SkMatrix& matrix) override; | 58 void setMatrix(const SkMatrix& matrix) override; |
66 | 59 |
67 void clipRect(const SkRect& rect, SkClipOp op, bool do_anti_alias) override; | 60 void clipRect(const SkRect& rect, SkClipOp op, bool antialias) override; |
68 void clipRRect(const SkRRect& rrect, | 61 void clipRRect(const SkRRect& rrect, SkClipOp op, bool antialias) override; |
69 SkClipOp op, | 62 void clipPath(const SkPath& path, SkClipOp op, bool antialias) override; |
70 bool do_anti_alias) override; | |
71 void clipPath(const SkPath& path, SkClipOp op, bool do_anti_alias) override; | |
72 bool quickReject(const SkRect& rect) const override; | 63 bool quickReject(const SkRect& rect) const override; |
73 bool quickReject(const SkPath& path) const override; | 64 bool quickReject(const SkPath& path) const override; |
74 SkRect getLocalClipBounds() const override; | 65 SkRect getLocalClipBounds() const override; |
75 bool getLocalClipBounds(SkRect* bounds) const override; | 66 bool getLocalClipBounds(SkRect* bounds) const override; |
76 SkIRect getDeviceClipBounds() const override; | 67 SkIRect getDeviceClipBounds() const override; |
77 bool getDeviceClipBounds(SkIRect* bounds) const override; | 68 bool getDeviceClipBounds(SkIRect* bounds) const override; |
78 void drawColor(SkColor color, SkBlendMode mode) override; | 69 void drawColor(SkColor color, SkBlendMode mode) override; |
79 void clear(SkColor color) override; | 70 void clear(SkColor color) override; |
80 | 71 |
81 void drawLine(SkScalar x0, | 72 void drawLine(SkScalar x0, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 // Don't shadow non-virtual helper functions. | 145 // Don't shadow non-virtual helper functions. |
155 using PaintCanvas::clipRect; | 146 using PaintCanvas::clipRect; |
156 using PaintCanvas::clipRRect; | 147 using PaintCanvas::clipRRect; |
157 using PaintCanvas::clipPath; | 148 using PaintCanvas::clipPath; |
158 using PaintCanvas::drawBitmap; | 149 using PaintCanvas::drawBitmap; |
159 using PaintCanvas::drawColor; | 150 using PaintCanvas::drawColor; |
160 using PaintCanvas::drawImage; | 151 using PaintCanvas::drawImage; |
161 using PaintCanvas::drawPicture; | 152 using PaintCanvas::drawPicture; |
162 | 153 |
163 private: | 154 private: |
164 SkCanvas* canvas_; | 155 PaintOpBuffer* buffer_; |
165 std::unique_ptr<SkCanvas> owned_; | |
166 | 156 |
167 DISALLOW_COPY_AND_ASSIGN(SkiaPaintCanvas); | 157 // TODO(enne): Although RecordPaintCanvas is mostly a write-only interface |
| 158 // where paint commands are stored, occasionally users of PaintCanvas want |
| 159 // to ask stateful questions mid-stream of clip and transform state. |
| 160 // To avoid duplicating all this code (for now?), just forward to an SkCanvas |
| 161 // that's not backed by anything but can answer these questions. |
| 162 SkNoDrawCanvas canvas_; |
168 }; | 163 }; |
169 | 164 |
170 } // namespace cc | 165 } // namespace cc |
171 | 166 |
172 #endif // CC_PAINT_SKIA_PAINT_CANVAS_H_ | 167 #endif // CC_PAINT_RECORD_PAINT_CANVAS_H_ |
OLD | NEW |