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

Unified Diff: ui/gfx/canvas.cc

Issue 2615493003: use SkSurface behind gfx::Canvas (Closed)
Patch Set: anon namespace 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
« no previous file with comments | « 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..68601c3cd4108351803195b9d550938c985a7983 100644
--- a/ui/gfx/canvas.cc
+++ b/ui/gfx/canvas.cc
@@ -12,6 +12,7 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkPath.h"
#include "third_party/skia/include/core/SkRefCnt.h"
+#include "third_party/skia/include/core/SkSurface.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
#include "ui/gfx/font_list.h"
#include "ui/gfx/geometry/insets_f.h"
@@ -26,12 +27,23 @@
namespace gfx {
+namespace {
Alexei Svitkine (slow) 2017/01/06 16:02:51 Nit: Add empty lines within the namespace.
reed1 2017/01/06 16:10:11 Done.
+sk_sp<SkSurface> CreateSurface(const Size& size, bool is_opaque) {
+ // SkSurface cannot be zero-sized, but clients of Canvas sometimes request
+ // that (and then later resize).
+ int width = std::max(size.width(), 1);
+ int height = std::max(size.height(), 1);
+ SkAlphaType alpha = is_opaque ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
+ SkImageInfo info = SkImageInfo::MakeN32(width, height, alpha);
+ return SkSurface::MakeRaster(info);
+}
+} // namespace
+
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_ = CreateSurface(pixel_size, is_opaque);
+ canvas_ = surface_->getCanvas();
#if !defined(USE_CAIRO)
// skia::PlatformCanvas instances are initialized to 0 by Cairo, but
@@ -46,8 +58,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_(CreateSurface({0, 0}, false)),
+ canvas_(surface_->getCanvas()) {}
Canvas::Canvas(SkCanvas* canvas, float image_scale)
: image_scale_(image_scale), canvas_(canvas) {
@@ -62,9 +74,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(),
- pixel_size.height(), is_opaque);
- canvas_ = canvas_owner_.get();
+ surface_ = CreateSurface(pixel_size, is_opaque);
+ canvas_ = surface_->getCanvas();
SkScalar scale_scalar = SkFloatToScalar(image_scale);
canvas_->scale(scale_scalar, scale_scalar);
« no previous file with comments | « ui/gfx/canvas.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698