summaryrefslogtreecommitdiffstats
path: root/gfx/canvas.cc
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-22 23:48:23 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-22 23:48:23 +0000
commitf35d5e8112599c578f0e5891028bd43553f4e0bd (patch)
tree4f16a2cd945f4477ca215daaba465907f3232cf6 /gfx/canvas.cc
parent601e664f992c48f8a4009cc2d8843075a5e29192 (diff)
downloadchromium_src-f35d5e8112599c578f0e5891028bd43553f4e0bd.zip
chromium_src-f35d5e8112599c578f0e5891028bd43553f4e0bd.tar.gz
chromium_src-f35d5e8112599c578f0e5891028bd43553f4e0bd.tar.bz2
Canvas refactoring part 1.
- Introduce a new Canvas2 interface. This will become the way that everyone talks to Canvas. It is populated primarily with the cross-platform methods from Canvas. - Make Canvas implement this interface. - Hook it up to the Windows RootView. Review URL: http://codereview.chromium.org/2866010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50543 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gfx/canvas.cc')
-rw-r--r--gfx/canvas.cc48
1 files changed, 48 insertions, 0 deletions
diff --git a/gfx/canvas.cc b/gfx/canvas.cc
index 0099e4c..28bc231 100644
--- a/gfx/canvas.cc
+++ b/gfx/canvas.cc
@@ -12,6 +12,10 @@
#include "gfx/rect.h"
#include "third_party/skia/include/core/SkShader.h"
+#if defined(OS_WIN)
+#include "gfx/canvas_paint.h"
+#endif
+
namespace gfx {
bool Canvas::GetClipRect(gfx::Rect* r) {
@@ -267,6 +271,10 @@ SkBitmap Canvas::ExtractBitmap() const {
return result;
}
+Canvas* Canvas::AsCanvas() {
+ return this;
+}
+
// static
int Canvas::DefaultCanvasTextAlignment() {
if (!base::i18n::IsRTL())
@@ -274,4 +282,44 @@ int Canvas::DefaultCanvasTextAlignment() {
return gfx::Canvas::TEXT_ALIGN_RIGHT;
}
+////////////////////////////////////////////////////////////////////////////////
+// Canvas2, public:
+
+Canvas2* Canvas2::CreateCanvas() {
+ return new Canvas;
+}
+
+Canvas2* Canvas2::CreateCanvas(int width, int height, bool is_opaque) {
+ return new Canvas(width, height, is_opaque);
+}
+
+#if defined(OS_WIN)
+// TODO(beng): move to canvas_win.cc, etc.
+class CanvasPaintWin : public CanvasPaint, public CanvasPaint2 {
+ public:
+ CanvasPaintWin(gfx::NativeView view) : CanvasPaint(view) {}
+
+ // Overridden from CanvasPaint2:
+ virtual bool IsValid() const {
+ return isEmpty();
+ }
+
+ virtual gfx::Rect GetInvalidRect() const {
+ return gfx::Rect(paintStruct().rcPaint);
+ }
+
+ virtual Canvas2* AsCanvas2() {
+ return this;
+ }
+};
+#endif
+
+CanvasPaint2* CanvasPaint2::CreateCanvasPaint(gfx::NativeView view) {
+#if defined(OS_WIN)
+ return new CanvasPaintWin(view);
+#else
+ return NULL;
+#endif
+}
+
} // namespace gfx