Chromium Code Reviews| Index: sky/engine/core/painting/Canvas.h |
| diff --git a/sky/engine/core/painting/Canvas.h b/sky/engine/core/painting/Canvas.h |
| index abd325643ec8188ffcf6a0feb467d3ef19f0d020..6b3d6f0e42595dc594b357a2b0805b088ce1d3be 100644 |
| --- a/sky/engine/core/painting/Canvas.h |
| +++ b/sky/engine/core/painting/Canvas.h |
| @@ -8,6 +8,7 @@ |
| #include "sky/engine/core/painting/CanvasPath.h" |
| #include "sky/engine/core/painting/Paint.h" |
| #include "sky/engine/core/painting/Picture.h" |
| +#include "sky/engine/core/painting/PictureRecorder.h" |
| #include "sky/engine/core/painting/RRect.h" |
| #include "sky/engine/core/painting/Rect.h" |
| #include "sky/engine/platform/graphics/DisplayList.h" |
| @@ -15,21 +16,30 @@ |
| #include "sky/engine/tonic/float32_list.h" |
| #include "sky/engine/wtf/PassRefPtr.h" |
| #include "sky/engine/wtf/RefCounted.h" |
| +#include "third_party/skia/include/core/SkCanvas.h" |
| namespace blink { |
| -class Element; |
| class CanvasImage; |
| class Canvas : public RefCounted<Canvas>, public DartWrappable { |
| DEFINE_WRAPPERTYPEINFO(); |
| public: |
| - Canvas(const FloatSize& size); |
| - ~Canvas() override; |
| + static PassRefPtr<Canvas> create(SkCanvas* skCanvas) { |
| + ASSERT(skCanvas); |
| + return adoptRef(new Canvas(skCanvas)); |
| + } |
| + |
| + static PassRefPtr<Canvas> create(PassRefPtr<PictureRecorder> recorder, |
|
abarth-chromium
2015/06/23 02:28:44
I think what Eric is saying is that ideally |PassR
iansf
2015/06/23 22:46:09
Confirmed that |PictureRecorder*| works, and updat
|
| + double width, |
| + double height) { |
| + ASSERT(recorder); |
| + PassRefPtr<Canvas> canvas = create( |
| + recorder->beginRecording(width, height)); |
| + recorder->set_canvas(canvas.get()); |
|
eseidel
2015/06/23 00:41:32
Who keeps the PictureRecorder alive? , Typically a
abarth-chromium
2015/06/23 02:28:44
Canvas effectively has a weak reference to the pic
|
| + return canvas; |
| + } |
| - // Width/Height define a culling rect which Skia may use for optimizing |
| - // out draw calls issued outside the rect. |
| - float width() const { return m_size.width(); } |
| - float height() const { return m_size.height(); } |
| + ~Canvas() override; |
| void save(); |
| void saveLayer(const Rect& bounds, const Paint* paint = nullptr); |
| @@ -59,15 +69,16 @@ public: |
| const Paint* paint); |
| SkCanvas* skCanvas() { return m_canvas; } |
| + void clearSkCanvas() { m_canvas = nullptr; } |
| + bool isRecording() const { return m_canvas != nullptr; } |
|
eseidel
2015/06/23 00:41:32
!!m_canvas works too. This is fine though. :)
iansf
2015/06/23 22:46:09
Acknowledged.
|
| protected: |
| - PassRefPtr<DisplayList> finishRecording(); |
| - |
| - bool isRecording() const { return m_canvas; } |
| + Canvas(SkCanvas* skCanvas); |
|
abarth-chromium
2015/06/23 02:28:44
Please mark one-argument constructors |explicit|.
iansf
2015/06/23 22:46:09
Done.
|
| private: |
| - FloatSize m_size; |
| - RefPtr<DisplayList> m_displayList; |
| + // The SkCanvas is supplied by a call to SkPictureRecorder::beginRecording, |
| + // which does not transfer ownership. For this reason, we hold a raw |
| + // pointer and manually set the SkCanvas to null in clearSkCanvas. |
|
abarth-chromium
2015/06/23 02:28:44
@eseidel: Here's the comment that's intended to an
|
| SkCanvas* m_canvas; |
| }; |