Index: cc/paint/paint_surface.h |
diff --git a/cc/paint/paint_surface.h b/cc/paint/paint_surface.h |
index 34165bf16ed70e74bd47550cc18e707eaef97488..471901732aab3fb200855256587ee0b1c9327fb1 100644 |
--- a/cc/paint/paint_surface.h |
+++ b/cc/paint/paint_surface.h |
@@ -5,10 +5,55 @@ |
#ifndef CC_PAINT_PAINT_SURFACE_H_ |
#define CC_PAINT_PAINT_SURFACE_H_ |
+#include "base/macros.h" |
+#include "base/memory/ptr_util.h" |
+#include "base/optional.h" |
+#include "cc/paint/paint_canvas.h" |
+#include "cc/paint/paint_export.h" |
#include "third_party/skia/include/core/SkSurface.h" |
namespace cc { |
-using PaintSurface = SkSurface; |
-} |
+ |
+class CC_PAINT_EXPORT PaintSurface : public SkRefCntBase { |
+ public: |
+ explicit PaintSurface(sk_sp<SkSurface> surface); |
+ ~PaintSurface() override; |
+ |
+ // TODO(enne): this interface matches SkSurface for simplicity. |
+ // However, this should really be changed to make the SkSurface ctor |
+ // public and have that be the only constructor. This will also |
+ // clean up a bunch of code where there's an SkSurface and a PaintCanvas, |
+ // such as for canvas in Blink. |
+ static sk_sp<PaintSurface> MakeRaster(const SkImageInfo& info, |
+ const SkSurfaceProps* props = nullptr) { |
+ sk_sp<SkSurface> s = SkSurface::MakeRaster(info, props); |
+ return sk_make_sp<PaintSurface>(std::move(s)); |
+ } |
+ static sk_sp<PaintSurface> MakeRasterN32Premul( |
+ int width, |
+ int height, |
+ const SkSurfaceProps* props = nullptr) { |
+ sk_sp<SkSurface> s = SkSurface::MakeRasterN32Premul(width, height, props); |
+ return sk_make_sp<PaintSurface>(std::move(s)); |
+ } |
+ |
+ int width() const { return surface_->width(); } |
+ int height() const { return surface_->height(); } |
+ uint32_t generationID() { return surface_->generationID(); } |
+ |
+ PaintCanvas* getCanvas() { |
+ if (!canvas_.has_value()) |
+ canvas_.emplace(surface_->getCanvas()); |
+ return &canvas_.value(); |
+ } |
+ |
+ private: |
+ const sk_sp<SkSurface> surface_; |
+ base::Optional<PaintCanvas> canvas_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PaintSurface); |
+}; |
+ |
+} // namespace cc |
#endif // CC_PAINT_PAINT_SURFACE_H_ |