Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Unified Diff: sky/engine/core/painting/Canvas.h

Issue 1190123003: Decouple Canvas from DisplayList and map Picture and PictureRecorder more directly to their Skia co… (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: j/k -- this one should actually be fully merged and testable Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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;
};

Powered by Google App Engine
This is Rietveld 408576698