| 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..00c6779269f681cb983d4669f295de1afb0ebb86 100644
|
| --- a/sky/engine/core/painting/Canvas.h
|
| +++ b/sky/engine/core/painting/Canvas.h
|
| @@ -5,9 +5,11 @@
|
| #ifndef SKY_ENGINE_CORE_PAINTING_CANVAS_H_
|
| #define SKY_ENGINE_CORE_PAINTING_CANVAS_H_
|
|
|
| +#include "sky/engine/bindings/exception_state.h"
|
| #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 +17,43 @@
|
| #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(PictureRecorder* recorder,
|
| + double width,
|
| + double height,
|
| + ExceptionState& es) {
|
| + ASSERT(recorder);
|
| + if (recorder->isRecording()) {
|
| + es.ThrowTypeError(
|
| + "You must call PictureRecorder.endRecording() before reusing a"
|
| + " PictureRecorder to create a new Canvas object.");
|
| + // TODO(iansf): We should return a nullptr here, I think, but doing
|
| + // so will require modifying the dart template code to
|
| + // to correctly handle constructors that throw
|
| + // exceptions. For now, just let it return a dart
|
| + // object that may cause a crash later on -- if the
|
| + // dart code catches the error, it will leak a canvas
|
| + // but it won't crash.
|
| + }
|
| + PassRefPtr<Canvas> canvas = create(
|
| + recorder->beginRecording(width, height));
|
| + recorder->set_canvas(canvas.get());
|
| + 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 +83,16 @@ public:
|
| const Paint* paint);
|
|
|
| SkCanvas* skCanvas() { return m_canvas; }
|
| + void clearSkCanvas() { m_canvas = nullptr; }
|
| + bool isRecording() const { return !!m_canvas; }
|
|
|
| protected:
|
| - PassRefPtr<DisplayList> finishRecording();
|
| -
|
| - bool isRecording() const { return m_canvas; }
|
| + explicit Canvas(SkCanvas* skCanvas);
|
|
|
| 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.
|
| SkCanvas* m_canvas;
|
| };
|
|
|
|
|