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

Unified Diff: ui/gfx/canvas.cc

Issue 2615493003: use SkSurface behind gfx::Canvas (Closed)
Patch Set: rebase Created 3 years, 11 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
« ui/gfx/canvas.h ('K') | « ui/gfx/canvas.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/gfx/canvas.cc
diff --git a/ui/gfx/canvas.cc b/ui/gfx/canvas.cc
index 9e82c7fc411256174891b9d69c6c7a6ca91b9e78..fd88255bac2c8cbe82d3e0cc33f5510984846c75 100644
--- a/ui/gfx/canvas.cc
+++ b/ui/gfx/canvas.cc
@@ -26,12 +26,21 @@
namespace gfx {
+sk_sp<SkSurface> create_surface(int width, int height, bool is_opaque) {
sadrul 2017/01/06 05:41:32 Should be called 'CreateSurface'. The signature c
reed1 2017/01/06 16:00:37 Done.
+ // SkSurface cannot be zero-sized, but clients of Canvas sometimes request
+ // that (and then later resize).
+ width = std::max(width, 1);
+ height = std::max(height, 1);
+ SkAlphaType alpha = is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
+ SkImageInfo info = SkImageInfo::MakeN32(width, height, alpha);
+ return SkSurface::MakeRaster(info);
+}
sadrul 2017/01/06 05:41:32 This should be in anon namespace.
reed1 2017/01/06 16:00:38 Done.
+
Canvas::Canvas(const Size& size, float image_scale, bool is_opaque)
: image_scale_(image_scale) {
Size pixel_size = ScaleToCeiledSize(size, image_scale);
- canvas_owner_ = skia::CreatePlatformCanvas(pixel_size.width(),
- pixel_size.height(), is_opaque);
- canvas_ = canvas_owner_.get();
+ surface_ = create_surface(pixel_size.width(), pixel_size.height(), is_opaque);
+ canvas_ = surface_->getCanvas();
#if !defined(USE_CAIRO)
// skia::PlatformCanvas instances are initialized to 0 by Cairo, but
@@ -46,8 +55,8 @@ Canvas::Canvas(const Size& size, float image_scale, bool is_opaque)
Canvas::Canvas()
: image_scale_(1.f),
- canvas_owner_(skia::CreatePlatformCanvas(0, 0, false)),
- canvas_(canvas_owner_.get()) {}
+ surface_(create_surface(0, 0, false)),
+ canvas_(surface_->getCanvas()) {}
Canvas::Canvas(SkCanvas* canvas, float image_scale)
: image_scale_(image_scale), canvas_(canvas) {
@@ -62,9 +71,8 @@ void Canvas::RecreateBackingCanvas(const Size& size,
bool is_opaque) {
image_scale_ = image_scale;
Size pixel_size = ScaleToFlooredSize(size, image_scale);
- canvas_owner_ = skia::CreatePlatformCanvas(pixel_size.width(),
sadrul 2017/01/06 05:41:32 Looks like these are the only uses of skia::Create
reed1 2017/01/06 16:00:38 Good observation. Florin and I are interleaving CL
- pixel_size.height(), is_opaque);
- canvas_ = canvas_owner_.get();
+ surface_ = create_surface(pixel_size.width(), pixel_size.height(), is_opaque);
+ canvas_ = surface_->getCanvas();
SkScalar scale_scalar = SkFloatToScalar(image_scale);
canvas_->scale(scale_scalar, scale_scalar);
« ui/gfx/canvas.h ('K') | « ui/gfx/canvas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698