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

Unified Diff: cc/paint/paint_surface.h

Issue 2690583002: Make cc/paint have concrete types (Closed)
Patch Set: Rebase Created 3 years, 10 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: cc/paint/paint_surface.h
diff --git a/cc/paint/paint_surface.h b/cc/paint/paint_surface.h
index 34165bf16ed70e74bd47550cc18e707eaef97488..97bbb1a09b382d9169a5524216a6d4408a5e9b91 100644
--- a/cc/paint/paint_surface.h
+++ b/cc/paint/paint_surface.h
@@ -5,10 +5,52 @@
#ifndef CC_PAINT_PAINT_SURFACE_H_
#define CC_PAINT_PAINT_SURFACE_H_
+#include "base/memory/ptr_util.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:
+ ~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_sp<PaintSurface>(new PaintSurface(std::move(s)));
danakj 2017/03/02 19:44:40 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_sp<PaintSurface>(new PaintSurface(std::move(s)));
danakj 2017/03/02 19:44:40 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_)
+ canvas_ = base::WrapUnique(new PaintCanvas(surface_->getCanvas()));
danakj 2017/03/02 19:44:40 MakeUnique?
+ return canvas_.get();
+ }
+
+ private:
+ explicit PaintSurface(sk_sp<SkSurface> surface);
+
+ const sk_sp<SkSurface> surface_;
+ std::unique_ptr<PaintCanvas> canvas_;
danakj 2017/03/02 19:44:40 you could use Optional if you want to avoid malloc
enne (OOO) 2017/03/02 23:59:44 Yeah, just made this optional.
+};
+
+} // namespace cc
#endif // CC_PAINT_PAINT_SURFACE_H_

Powered by Google App Engine
This is Rietveld 408576698