summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorreed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-29 16:57:38 +0000
committerreed@google.com <reed@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-29 16:57:38 +0000
commit9ad44a5e815b2480cd417630c07375d2d04c30eb (patch)
tree014ca8fb7142e20ca52fdc8bcb9887a972195e2b
parentadc7f2ff7e8287396a62ad15dbb7fb92432f1d79 (diff)
downloadchromium_src-9ad44a5e815b2480cd417630c07375d2d04c30eb.zip
chromium_src-9ad44a5e815b2480cd417630c07375d2d04c30eb.tar.gz
chromium_src-9ad44a5e815b2480cd417630c07375d2d04c30eb.tar.bz2
Change CanvasPaintT from a template to just a subclass of gfx::Canvas. Greatly
simplifies source-code-readability, and will allow us to move the impl into a .cc file, rather than carry it to every call-site. This is also a necessary precursor to a subsequent change to remove initialize() from PlatformCanvas, and make it just a typedef for SkCanvas. Review URL: https://codereview.chromium.org/11193037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@164660 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc4
-rw-r--r--skia/ext/canvas_paint.h23
-rw-r--r--skia/ext/canvas_paint_common.h23
-rw-r--r--skia/ext/canvas_paint_gtk.h117
-rw-r--r--skia/ext/canvas_paint_mac.h120
-rw-r--r--skia/skia.gyp5
-rw-r--r--ui/gfx/canvas_paint_gtk.cc71
-rw-r--r--ui/gfx/canvas_paint_gtk.h62
-rw-r--r--ui/gfx/canvas_paint_mac.h59
-rw-r--r--ui/gfx/canvas_paint_mac.mm76
-rw-r--r--ui/gfx/canvas_paint_win.cc1
-rw-r--r--ui/gfx/canvas_paint_win.h (renamed from skia/ext/canvas_paint_win.h)36
-rw-r--r--ui/gfx/canvas_skia_paint.h46
-rw-r--r--ui/ui.gyp5
-rw-r--r--ui/views/win/hwnd_message_handler.cc1
15 files changed, 307 insertions, 342 deletions
diff --git a/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc b/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc
index bde4e88..4a21622 100644
--- a/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc
+++ b/chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc
@@ -184,7 +184,9 @@ void InfoBarContainerGtk::PaintArrowOn(GtkWidget* widget,
paint.setShader(gradient_shader);
gradient_shader->unref();
- skia::PlatformCanvasPaint canvas(expose, false);
+ gfx::CanvasSkiaPaint canvas_paint(expose, false);
+ SkCanvas& canvas = *canvas_paint.sk_canvas();
+
canvas.drawPath(path, paint);
paint.setShader(NULL);
diff --git a/skia/ext/canvas_paint.h b/skia/ext/canvas_paint.h
deleted file mode 100644
index 8fd388f..0000000
--- a/skia/ext/canvas_paint.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef SKIA_EXT_CANVAS_PAINT_H_
-#define SKIA_EXT_CANVAS_PAINT_H_
-
-// This file provides an easy way to include the appropriate CanvasPaint
-// header file on your platform.
-
-#if defined(WIN32)
-#include "skia/ext/canvas_paint_win.h"
-#elif defined(__APPLE__)
-#include "skia/ext/canvas_paint_mac.h"
-#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__sun)
-#if defined(TOOLKIT_GTK)
-#include "skia/ext/canvas_paint_gtk.h"
-#else
-#error "No canvas paint for this platform"
-#endif
-#endif
-
-#endif // SKIA_EXT_CANVAS_PAINT_H_
diff --git a/skia/ext/canvas_paint_common.h b/skia/ext/canvas_paint_common.h
deleted file mode 100644
index c3c7f97..0000000
--- a/skia/ext/canvas_paint_common.h
+++ /dev/null
@@ -1,23 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef SKIA_EXT_CANVAS_PAINT_COMMON_H_
-#define SKIA_EXT_CANVAS_PAINT_COMMON_H_
-
-namespace skia {
-class PlatformCanvas;
-
-template<class T> inline PlatformCanvas* GetPlatformCanvas(T* t) {
- return t;
-}
-
-// TODO(pkotwicz): Push scale into PlatformCanvas such that this function
-// is not needed.
-template<class T> inline void RecreateBackingCanvas(T* t,
- int width, int height, float scale, bool opaque) {
-}
-
-} // namespace skia
-
-#endif // SKIA_EXT_CANVAS_PAINT_COMMON_H_
diff --git a/skia/ext/canvas_paint_gtk.h b/skia/ext/canvas_paint_gtk.h
deleted file mode 100644
index 1dce27e..0000000
--- a/skia/ext/canvas_paint_gtk.h
+++ /dev/null
@@ -1,117 +0,0 @@
-
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef SKIA_EXT_CANVAS_PAINT_LINUX_H_
-#define SKIA_EXT_CANVAS_PAINT_LINUX_H_
-
-#include "base/logging.h"
-#include "skia/ext/canvas_paint_common.h"
-#include "skia/ext/platform_canvas.h"
-
-#include <gdk/gdk.h>
-
-namespace skia {
-
-// A class designed to translate skia painting into a region in a GdkWindow.
-// On construction, it will set up a context for painting into, and on
-// destruction, it will commit it to the GdkWindow.
-// Note: The created context is always inialized to (0, 0, 0, 0).
-template <class T>
-class CanvasPaintT : public T {
- public:
- // This constructor assumes the result is opaque.
- explicit CanvasPaintT(GdkEventExpose* event)
- : context_(NULL),
- window_(event->window),
- region_(gdk_region_copy(event->region)),
- composite_alpha_(false) {
- init(true);
- }
-
- CanvasPaintT(GdkEventExpose* event, bool opaque)
- : context_(NULL),
- window_(event->window),
- region_(gdk_region_copy(event->region)),
- composite_alpha_(false) {
- init(opaque);
- }
-
- virtual ~CanvasPaintT() {
- if (!is_empty()) {
- GetPlatformCanvas(this)->restoreToCount(1);
-
- // Blit the dirty rect to the window.
- CHECK(window_);
- cairo_t* cr = gdk_cairo_create(window_);
- CHECK(cr);
- if (composite_alpha_)
- cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
- cairo_surface_t* source_surface = cairo_get_target(context_);
- CHECK(source_surface);
- // Flush cairo's cache of the surface.
- cairo_surface_mark_dirty(source_surface);
- GdkRectangle bounds = rectangle();
- cairo_set_source_surface(cr, source_surface, bounds.x, bounds.y);
- gdk_cairo_region(cr, region_);
- cairo_fill(cr);
- cairo_destroy(cr);
- }
-
- gdk_region_destroy(region_);
- }
-
- // Sets whether the bitmap is composited in such a way that the alpha channel
- // is honored. This is only useful if you've enabled an RGBA colormap on the
- // widget. The default is false.
- void set_composite_alpha(bool composite_alpha) {
- composite_alpha_ = composite_alpha;
- }
-
- // Returns true if the invalid region is empty. The caller should call this
- // function to determine if anything needs painting.
- bool is_empty() const {
- return gdk_region_empty(region_);
- }
-
- GdkRectangle rectangle() const {
- GdkRectangle bounds;
- gdk_region_get_clipbox(region_, &bounds);
- return bounds;
- }
-
- private:
- void init(bool opaque) {
- GdkRectangle bounds = rectangle();
- PlatformCanvas* canvas = GetPlatformCanvas(this);
- if (!canvas->initialize(bounds.width, bounds.height, opaque, NULL)) {
- // Cause a deliberate crash;
- CHECK(false);
- }
- // No need to clear the canvas, because cairo automatically performs the
- // clear.
-
- // Need to translate so that the dirty region appears at the origin of the
- // surface.
- canvas->translate(-SkIntToScalar(bounds.x), -SkIntToScalar(bounds.y));
-
- context_ = BeginPlatformPaint(canvas);
- }
-
- cairo_t* context_;
- GdkWindow* window_;
- GdkRegion* region_;
- // See description above setter.
- bool composite_alpha_;
-
- // Disallow copy and assign.
- CanvasPaintT(const CanvasPaintT&);
- CanvasPaintT& operator=(const CanvasPaintT&);
-};
-
-typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint;
-
-} // namespace skia
-
-#endif // SKIA_EXT_CANVAS_PAINT_LINUX_H_
diff --git a/skia/ext/canvas_paint_mac.h b/skia/ext/canvas_paint_mac.h
deleted file mode 100644
index 36bf992..0000000
--- a/skia/ext/canvas_paint_mac.h
+++ /dev/null
@@ -1,120 +0,0 @@
-
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef SKIA_EXT_CANVAS_PAINT_MAC_H_
-#define SKIA_EXT_CANVAS_PAINT_MAC_H_
-
-#include "skia/ext/canvas_paint_common.h"
-#include "skia/ext/platform_canvas.h"
-
-#import <Cocoa/Cocoa.h>
-
-namespace skia {
-
-// A class designed to translate skia painting into a region to the current
-// graphics context. On construction, it will set up a context for painting
-// into, and on destruction, it will commit it to the current context.
-// Note: The created context is always inialized to (0, 0, 0, 0).
-template <class T>
-class CanvasPaintT : public T {
- public:
- // This constructor assumes the result is opaque.
- explicit CanvasPaintT(NSRect dirtyRect)
- : context_(NULL),
- rectangle_(dirtyRect),
- composite_alpha_(false) {
- init(true);
- }
-
- CanvasPaintT(NSRect dirtyRect, bool opaque)
- : context_(NULL),
- rectangle_(dirtyRect),
- composite_alpha_(false) {
- init(opaque);
- }
-
- virtual ~CanvasPaintT() {
- if (!is_empty()) {
- GetPlatformCanvas(this)->restoreToCount(1);
-
- // Blit the dirty rect to the current context.
- CGImageRef image = CGBitmapContextCreateImage(context_);
- CGRect dest_rect = NSRectToCGRect(rectangle_);
-
- CGContextRef destination_context =
- (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
- CGContextSaveGState(destination_context);
- CGContextSetBlendMode(
- destination_context,
- composite_alpha_ ? kCGBlendModeNormal : kCGBlendModeCopy);
-
- if ([[NSGraphicsContext currentContext] isFlipped]) {
- // Mirror context on the target's rect middle scanline.
- CGContextTranslateCTM(destination_context, 0.0, NSMidY(rectangle_));
- CGContextScaleCTM(destination_context, 1.0, -1.0);
- CGContextTranslateCTM(destination_context, 0.0, -NSMidY(rectangle_));
- }
-
- CGContextDrawImage(destination_context, dest_rect, image);
- CGContextRestoreGState(destination_context);
-
- CFRelease(image);
- }
- }
-
- // If true, the data painted into the CanvasPaintT is blended onto the current
- // context, else it is copied.
- void set_composite_alpha(bool composite_alpha) {
- composite_alpha_ = composite_alpha;
- }
-
- // Returns true if the invalid region is empty. The caller should call this
- // function to determine if anything needs painting.
- bool is_empty() const {
- return NSIsEmptyRect(rectangle_);
- }
-
- const NSRect& rectangle() const {
- return rectangle_;
- }
-
- private:
- void init(bool opaque) {
- CGContextRef destination_context =
- (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
- CGRect scaled_unit_rect = CGContextConvertRectToDeviceSpace(
- destination_context, CGRectMake(0, 0, 1, 1));
- // Assume that the x scale and the y scale are the same.
- CGFloat scale = scaled_unit_rect.size.width;
-
- RecreateBackingCanvas(this,
- NSWidth(rectangle_), NSHeight(rectangle_), scale, opaque);
- PlatformCanvas* canvas = GetPlatformCanvas(this);
- canvas->clear(SkColorSetARGB(0, 0, 0, 0));
-
- // Need to translate so that the dirty region appears at the origin of the
- // surface.
- canvas->translate(-SkDoubleToScalar(NSMinX(rectangle_)),
- -SkDoubleToScalar(NSMinY(rectangle_)));
-
- context_ = GetBitmapContext(GetTopDevice(*canvas));
- }
-
- CGContext* context_;
- NSRect rectangle_;
- // See description above setter.
- bool composite_alpha_;
-
- // Disallow copy and assign.
- CanvasPaintT(const CanvasPaintT&);
- CanvasPaintT& operator=(const CanvasPaintT&);
-};
-
-typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint;
-
-} // namespace skia
-
-
-#endif // SKIA_EXT_CANVAS_PAINT_MAC_H_
diff --git a/skia/skia.gyp b/skia/skia.gyp
index 747427c..1864d93 100644
--- a/skia/skia.gyp
+++ b/skia/skia.gyp
@@ -156,11 +156,6 @@
'ext/bitmap_platform_device_mac.h',
'ext/bitmap_platform_device_win.cc',
'ext/bitmap_platform_device_win.h',
- 'ext/canvas_paint.h',
- 'ext/canvas_paint_common.h',
- 'ext/canvas_paint_gtk.h',
- 'ext/canvas_paint_mac.h',
- 'ext/canvas_paint_win.h',
'ext/convolver.cc',
'ext/convolver.h',
'ext/google_logging.cc',
diff --git a/ui/gfx/canvas_paint_gtk.cc b/ui/gfx/canvas_paint_gtk.cc
new file mode 100644
index 0000000..e164cdc
--- /dev/null
+++ b/ui/gfx/canvas_paint_gtk.cc
@@ -0,0 +1,71 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/canvas_skia_paint.h"
+#include "ui/gfx/rect.h"
+
+namespace gfx {
+
+CanvasSkiaPaint::CanvasSkiaPaint(GdkEventExpose* event)
+ : context_(NULL),
+ window_(event->window),
+ region_(gdk_region_copy(event->region)),
+ composite_alpha_(false) {
+ Init(true);
+}
+
+CanvasSkiaPaint::CanvasSkiaPaint(GdkEventExpose* event, bool opaque)
+ : context_(NULL),
+ window_(event->window),
+ region_(gdk_region_copy(event->region)),
+ composite_alpha_(false) {
+ Init(opaque);
+}
+
+CanvasSkiaPaint::~CanvasSkiaPaint() {
+ if (!is_empty()) {
+ platform_canvas()->restoreToCount(1);
+
+ // Blit the dirty rect to the window.
+ CHECK(window_);
+ cairo_t* cr = gdk_cairo_create(window_);
+ CHECK(cr);
+ if (composite_alpha_)
+ cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
+ cairo_surface_t* source_surface = cairo_get_target(context_);
+ CHECK(source_surface);
+ // Flush cairo's cache of the surface.
+ cairo_surface_mark_dirty(source_surface);
+ GdkRectangle bounds = rectangle();
+ cairo_set_source_surface(cr, source_surface, bounds.x, bounds.y);
+ gdk_cairo_region(cr, region_);
+ cairo_fill(cr);
+ cairo_destroy(cr);
+ }
+
+ gdk_region_destroy(region_);
+}
+
+void CanvasSkiaPaint::Init(bool opaque) {
+ GdkRectangle bounds = rectangle();
+ skia::PlatformCanvas* canvas = platform_canvas();
+ if (!canvas->initialize(bounds.width, bounds.height, opaque, NULL)) {
+ // Cause a deliberate crash;
+ CHECK(false);
+ }
+ // No need to clear the canvas, because cairo automatically performs the
+ // clear.
+
+ // Need to translate so that the dirty region appears at the origin of the
+ // surface.
+ canvas->translate(-SkIntToScalar(bounds.x), -SkIntToScalar(bounds.y));
+
+ context_ = skia::BeginPlatformPaint(canvas);
+}
+
+} // namespace gfx
+
diff --git a/ui/gfx/canvas_paint_gtk.h b/ui/gfx/canvas_paint_gtk.h
new file mode 100644
index 0000000..db64e49
--- /dev/null
+++ b/ui/gfx/canvas_paint_gtk.h
@@ -0,0 +1,62 @@
+
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_GFX_CANVAS_PAINT_LINUX_H_
+#define UI_GFX_CANVAS_PAINT_LINUX_H_
+
+#include "base/logging.h"
+#include "skia/ext/platform_canvas.h"
+#include "ui/gfx/canvas.h"
+#include <gdk/gdk.h>
+
+namespace gfx {
+
+// A class designed to translate skia painting into a region in a GdkWindow.
+// On construction, it will set up a context for painting into, and on
+// destruction, it will commit it to the GdkWindow.
+// Note: The created context is always inialized to (0, 0, 0, 0).
+class CanvasSkiaPaint : public Canvas {
+ public:
+ // This constructor assumes the result is opaque.
+ explicit CanvasSkiaPaint(GdkEventExpose* event);
+ CanvasSkiaPaint(GdkEventExpose* event, bool opaque);
+ virtual ~CanvasSkiaPaint();
+
+ // Sets whether the bitmap is composited in such a way that the alpha channel
+ // is honored. This is only useful if you've enabled an RGBA colormap on the
+ // widget. The default is false.
+ void set_composite_alpha(bool composite_alpha) {
+ composite_alpha_ = composite_alpha;
+ }
+
+ // Returns true if the invalid region is empty. The caller should call this
+ // function to determine if anything needs painting.
+ bool is_empty() const {
+ return gdk_region_empty(region_);
+ }
+
+ GdkRectangle rectangle() const {
+ GdkRectangle bounds;
+ gdk_region_get_clipbox(region_, &bounds);
+ return bounds;
+ }
+
+ private:
+ void Init(bool opaque);
+
+ cairo_t* context_;
+ GdkWindow* window_;
+ GdkRegion* region_;
+ // See description above setter.
+ bool composite_alpha_;
+
+ // Disallow copy and assign.
+ CanvasSkiaPaint(const CanvasSkiaPaint&);
+ CanvasSkiaPaint& operator=(const CanvasSkiaPaint&);
+};
+
+} // namespace gfx
+
+#endif // UI_GFX_CANVAS_PAINT_LINUX_H_
diff --git a/ui/gfx/canvas_paint_mac.h b/ui/gfx/canvas_paint_mac.h
new file mode 100644
index 0000000..6d19565
--- /dev/null
+++ b/ui/gfx/canvas_paint_mac.h
@@ -0,0 +1,59 @@
+
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_GFX_CANVAS_PAINT_MAC_H_
+#define UI_GFX_CANVAS_PAINT_MAC_H_
+
+#include "skia/ext/platform_canvas.h"
+#include "ui/gfx/canvas.h"
+
+#import <Cocoa/Cocoa.h>
+
+namespace gfx {
+
+// A class designed to translate skia painting into a region to the current
+// graphics context. On construction, it will set up a context for painting
+// into, and on destruction, it will commit it to the current context.
+// Note: The created context is always inialized to (0, 0, 0, 0).
+class CanvasSkiaPaint : public Canvas {
+ public:
+ // This constructor assumes the result is opaque.
+ explicit CanvasSkiaPaint(NSRect dirtyRect);
+ CanvasSkiaPaint(NSRect dirtyRect, bool opaque);
+ virtual ~CanvasSkiaPaint();
+
+ // If true, the data painted into the CanvasSkiaPaint is blended onto the
+ // current context, else it is copied.
+ void set_composite_alpha(bool composite_alpha) {
+ composite_alpha_ = composite_alpha;
+ }
+
+ // Returns true if the invalid region is empty. The caller should call this
+ // function to determine if anything needs painting.
+ bool is_empty() const {
+ return NSIsEmptyRect(rectangle_);
+ }
+
+ const NSRect& rectangle() const {
+ return rectangle_;
+ }
+
+ private:
+ void Init(bool opaque);
+
+ CGContext* context_;
+ NSRect rectangle_;
+ // See description above setter.
+ bool composite_alpha_;
+
+ // Disallow copy and assign.
+ CanvasSkiaPaint(const CanvasSkiaPaint&);
+ CanvasSkiaPaint& operator=(const CanvasSkiaPaint&);
+};
+
+} // namespace gfx
+
+
+#endif // UI_GFX_CANVAS_PAINT_MAC_H_
diff --git a/ui/gfx/canvas_paint_mac.mm b/ui/gfx/canvas_paint_mac.mm
new file mode 100644
index 0000000..83c5a9bb
--- /dev/null
+++ b/ui/gfx/canvas_paint_mac.mm
@@ -0,0 +1,76 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/gfx/canvas_paint_mac.h"
+#include "ui/gfx/size.h"
+
+namespace gfx {
+
+CanvasSkiaPaint::CanvasSkiaPaint(NSRect dirtyRect)
+ : context_(NULL),
+ rectangle_(dirtyRect),
+ composite_alpha_(false) {
+ Init(true);
+}
+
+CanvasSkiaPaint::CanvasSkiaPaint(NSRect dirtyRect, bool opaque)
+ : context_(NULL),
+ rectangle_(dirtyRect),
+ composite_alpha_(false) {
+ Init(opaque);
+}
+
+CanvasSkiaPaint::~CanvasSkiaPaint() {
+ if (!is_empty()) {
+ platform_canvas()->restoreToCount(1);
+
+ // Blit the dirty rect to the current context.
+ CGImageRef image = CGBitmapContextCreateImage(context_);
+ CGRect dest_rect = NSRectToCGRect(rectangle_);
+
+ CGContextRef destination_context =
+ (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
+ CGContextSaveGState(destination_context);
+ CGContextSetBlendMode(
+ destination_context,
+ composite_alpha_ ? kCGBlendModeNormal : kCGBlendModeCopy);
+
+ if ([[NSGraphicsContext currentContext] isFlipped]) {
+ // Mirror context on the target's rect middle scanline.
+ CGContextTranslateCTM(destination_context, 0.0, NSMidY(rectangle_));
+ CGContextScaleCTM(destination_context, 1.0, -1.0);
+ CGContextTranslateCTM(destination_context, 0.0, -NSMidY(rectangle_));
+ }
+
+ CGContextDrawImage(destination_context, dest_rect, image);
+ CGContextRestoreGState(destination_context);
+
+ CFRelease(image);
+ }
+}
+
+void CanvasSkiaPaint::Init(bool opaque) {
+ CGContextRef destination_context =
+ (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
+ CGRect scaled_unit_rect = CGContextConvertRectToDeviceSpace(
+ destination_context, CGRectMake(0, 0, 1, 1));
+ // Assume that the x scale and the y scale are the same.
+ CGFloat scale = scaled_unit_rect.size.width;
+
+ ui::ScaleFactor scale_factor = ui::GetScaleFactorFromScale(scale);
+ gfx::Size size(NSWidth(rectangle_), NSHeight(rectangle_));
+ this->RecreateBackingCanvas(size, scale_factor, opaque);
+ skia::PlatformCanvas* canvas = platform_canvas();
+ canvas->clear(SkColorSetARGB(0, 0, 0, 0));
+
+ // Need to translate so that the dirty region appears at the origin of the
+ // surface.
+ canvas->translate(-SkDoubleToScalar(NSMinX(rectangle_)),
+ -SkDoubleToScalar(NSMinY(rectangle_)));
+
+ context_ = skia::GetBitmapContext(skia::GetTopDevice(*canvas));
+}
+
+} // namespace skia
+
diff --git a/ui/gfx/canvas_paint_win.cc b/ui/gfx/canvas_paint_win.cc
index 87ba3f6..27898fc 100644
--- a/ui/gfx/canvas_paint_win.cc
+++ b/ui/gfx/canvas_paint_win.cc
@@ -5,7 +5,6 @@
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "ui/gfx/canvas.h"
-#include "ui/gfx/canvas_paint.h"
#include "ui/gfx/canvas_skia_paint.h"
#include "ui/gfx/rect.h"
diff --git a/skia/ext/canvas_paint_win.h b/ui/gfx/canvas_paint_win.h
index 4492c0e..07044b5 100644
--- a/skia/ext/canvas_paint_win.h
+++ b/ui/gfx/canvas_paint_win.h
@@ -2,13 +2,14 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef SKIA_EXT_CANVAS_PAINT_WIN_H_
-#define SKIA_EXT_CANVAS_PAINT_WIN_H_
+#ifndef UI_GFX_CANVAS_PAINT_WIN_H_
+#define UI_GFX_CANVAS_PAINT_WIN_H_
-#include "skia/ext/canvas_paint_common.h"
#include "skia/ext/platform_canvas.h"
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/canvas_paint.h"
-namespace skia {
+namespace gfx {
// A class designed to help with WM_PAINT operations on Windows. It will
// do BeginPaint/EndPaint on init/destruction, and will create the bitmap and
@@ -29,25 +30,24 @@ namespace skia {
// return 0;
// }
// Note: The created context is always inialized to (0, 0, 0, 0).
-template <class T>
-class CanvasPaintT : public T {
+class CanvasSkiaPaint : public Canvas {
public:
// This constructor assumes the canvas is opaque.
- explicit CanvasPaintT(HWND hwnd) : hwnd_(hwnd), paint_dc_(NULL),
+ explicit CanvasSkiaPaint(HWND hwnd) : hwnd_(hwnd), paint_dc_(NULL),
for_paint_(true) {
memset(&ps_, 0, sizeof(ps_));
initPaint(true);
}
- CanvasPaintT(HWND hwnd, bool opaque) : hwnd_(hwnd), paint_dc_(NULL),
+ CanvasSkiaPaint(HWND hwnd, bool opaque) : hwnd_(hwnd), paint_dc_(NULL),
for_paint_(true) {
memset(&ps_, 0, sizeof(ps_));
initPaint(opaque);
}
- // Creates a CanvasPaintT for the specified region that paints to the
+ // Creates a CanvasSkiaPaint for the specified region that paints to the
// specified dc. This does NOT do BeginPaint/EndPaint.
- CanvasPaintT(HDC dc, bool opaque, int x, int y, int w, int h)
+ CanvasSkiaPaint(HDC dc, bool opaque, int x, int y, int w, int h)
: hwnd_(NULL),
paint_dc_(dc),
for_paint_(false) {
@@ -59,9 +59,9 @@ class CanvasPaintT : public T {
init(opaque);
}
- virtual ~CanvasPaintT() {
+ virtual ~CanvasSkiaPaint() {
if (!isEmpty()) {
- PlatformCanvas* canvas = GetPlatformCanvas(this);
+ skia::PlatformCanvas* canvas = platform_canvas();
canvas->restoreToCount(1);
// Commit the drawing to the screen
skia::DrawToNativeContext(canvas, paint_dc_, ps_.rcPaint.left,
@@ -102,7 +102,7 @@ class CanvasPaintT : public T {
}
void init(bool opaque) {
- PlatformCanvas* canvas = GetPlatformCanvas(this);
+ skia::PlatformCanvas* canvas = platform_canvas();
// FIXME(brettw) for ClearType, we probably want to expand the bounds of
// painting by one pixel so that the boundaries will be correct (ClearType
// text can depend on the adjacent pixel). Then we would paint just the
@@ -126,12 +126,10 @@ class CanvasPaintT : public T {
const bool for_paint_;
// Disallow copy and assign.
- CanvasPaintT(const CanvasPaintT&);
- CanvasPaintT& operator=(const CanvasPaintT&);
+ CanvasSkiaPaint(const CanvasSkiaPaint&);
+ CanvasSkiaPaint& operator=(const CanvasSkiaPaint&);
};
-typedef CanvasPaintT<PlatformCanvas> PlatformCanvasPaint;
+} // namespace gfx
-} // namespace skia
-
-#endif // SKIA_EXT_CANVAS_PAINT_WIN_H_
+#endif // UI_GFX_CANVAS_PAINT_WIN_H_
diff --git a/ui/gfx/canvas_skia_paint.h b/ui/gfx/canvas_skia_paint.h
index ad92d94..3f21f5c 100644
--- a/ui/gfx/canvas_skia_paint.h
+++ b/ui/gfx/canvas_skia_paint.h
@@ -5,37 +5,19 @@
#ifndef UI_GFX_CANVAS_SKIA_PAINT_H_
#define UI_GFX_CANVAS_SKIA_PAINT_H_
-#include "base/logging.h"
-#include "skia/ext/canvas_paint.h"
-#include "ui/gfx/canvas.h"
-#include "ui/gfx/size.h"
-
-// Define a gfx::CanvasSkiaPaint type that wraps our gfx::Canvas like the
-// skia::PlatformCanvasPaint wraps PlatformCanvas.
-
-namespace skia {
-
-template<> inline
-PlatformCanvas* GetPlatformCanvas(skia::CanvasPaintT<gfx::Canvas>* canvas) {
- PlatformCanvas* platform_canvas = canvas->platform_canvas();
- DCHECK(platform_canvas);
- return platform_canvas;
-}
-
-template<> inline
-void RecreateBackingCanvas(skia::CanvasPaintT<gfx::Canvas>* canvas,
- int width, int height, float scale, bool opaque) {
- ui::ScaleFactor scale_factor = ui::GetScaleFactorFromScale(scale);
- canvas->RecreateBackingCanvas(gfx::Size(width, height), scale_factor,
- opaque);
-}
-
-} // namespace skia
-
-namespace gfx {
-
-typedef skia::CanvasPaintT<Canvas> CanvasSkiaPaint;
-
-} // namespace gfx
+// This file provides an easy way to include the appropriate CanvasPaint
+// header file on your platform.
+
+#if defined(WIN32)
+#include "ui/gfx/canvas_paint_win.h"
+#elif defined(__APPLE__)
+#include "ui/gfx/canvas_paint_mac.h"
+#elif defined(__linux__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__sun)
+#if defined(TOOLKIT_GTK)
+#include "ui/gfx/canvas_paint_gtk.h"
+#else
+#error "No canvas paint for this platform"
+#endif
+#endif
#endif // UI_GFX_CANVAS_SKIA_PAINT_H_
diff --git a/ui/ui.gyp b/ui/ui.gyp
index a62a275..fa73fe9 100644
--- a/ui/ui.gyp
+++ b/ui/ui.gyp
@@ -362,6 +362,11 @@
'gfx/canvas_android.cc',
'gfx/canvas_mac.mm',
'gfx/canvas_paint.h',
+ 'gfx/canvas_paint_gtk.h',
+ 'gfx/canvas_paint_mac.h',
+ 'gfx/canvas_paint_win.h',
+ 'gfx/canvas_paint_gtk.cc',
+ 'gfx/canvas_paint_mac.mm',
'gfx/canvas_paint_win.cc',
'gfx/canvas_skia.cc',
'gfx/canvas_skia_paint.h',
diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc
index 0b53dc9..0312549 100644
--- a/ui/views/win/hwnd_message_handler.cc
+++ b/ui/views/win/hwnd_message_handler.cc
@@ -17,7 +17,6 @@
#include "ui/base/win/mouse_wheel_util.h"
#include "ui/base/win/shell.h"
#include "ui/gfx/canvas.h"
-#include "ui/gfx/canvas_paint.h"
#include "ui/gfx/canvas_skia_paint.h"
#include "ui/gfx/icon_util.h"
#include "ui/gfx/insets.h"