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