diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-23 23:04:23 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-23 23:04:23 +0000 |
commit | 3024338797b31cd0e0357878bcd5b084e4a8af69 (patch) | |
tree | cf20d1d15f3907bb625a7cd1e465bbc47118821e /gfx | |
parent | 218f45da1c19e775cf72f46cc72f1c624927fd93 (diff) | |
download | chromium_src-3024338797b31cd0e0357878bcd5b084e4a8af69.zip chromium_src-3024338797b31cd0e0357878bcd5b084e4a8af69.tar.gz chromium_src-3024338797b31cd0e0357878bcd5b084e4a8af69.tar.bz2 |
Canvas refactoring part 2.
- Rename Canvas to CanvasSkia.
- Create a subclass Canvas that inherits from CanvasSkia for compatibility.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2862025
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50664 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gfx')
-rw-r--r-- | gfx/canvas.h | 124 | ||||
-rw-r--r-- | gfx/canvas_skia.cc (renamed from gfx/canvas.cc) | 87 | ||||
-rw-r--r-- | gfx/canvas_skia.h | 135 | ||||
-rw-r--r-- | gfx/canvas_skia_linux.cc (renamed from gfx/canvas_linux.cc) | 24 | ||||
-rw-r--r-- | gfx/canvas_skia_mac.mm (renamed from gfx/canvas_mac.mm) | 18 | ||||
-rw-r--r-- | gfx/canvas_skia_paint.h (renamed from gfx/canvas_paint.h) | 10 | ||||
-rw-r--r-- | gfx/canvas_skia_win.cc (renamed from gfx/canvas_win.cc) | 42 | ||||
-rw-r--r-- | gfx/gfx.gyp | 13 |
8 files changed, 243 insertions, 210 deletions
diff --git a/gfx/canvas.h b/gfx/canvas.h index 53661db..589d77d 100644 --- a/gfx/canvas.h +++ b/gfx/canvas.h @@ -5,129 +5,27 @@ #ifndef GFX_CANVAS_H_ #define GFX_CANVAS_H_ -#include "base/basictypes.h" -#include "gfx/canvas_2.h" -#include "skia/ext/platform_canvas.h" - -#if defined(OS_POSIX) && !defined(OS_MACOSX) -typedef struct _GdkPixbuf GdkPixbuf; -#endif +#include "gfx/canvas_skia.h" namespace gfx { -// Canvas is a SkCanvas subclass that provides a number of methods for common -// operations used throughout an application built using base/gfx and app/gfx. -// -// All methods that take integer arguments (as is used throughout views) -// end with Int. If you need to use methods provided by the superclass -// you'll need to do a conversion. In particular you'll need to use -// macro SkIntToScalar(xxx), or if converting from a scalar to an integer -// SkScalarRound. -// -// A handful of methods in this class are overloaded providing an additional -// argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the -// source and destination colors are combined. Unless otherwise specified, -// the variant that does not take a SkXfermode::Mode uses a transfer mode -// of kSrcOver_Mode. -class Canvas : public skia::PlatformCanvas, - public Canvas2 { +// Temporary compatibility shim, remove once Canvas2->Canvas. +class Canvas : public CanvasSkia { public: - // Creates an empty Canvas. Callers must use initialize before using the - // canvas. - Canvas(); - - Canvas(int width, int height, bool is_opaque); - - virtual ~Canvas(); - - // Compute the size required to draw some text with the provided font. - // Attempts to fit the text with the provided width and height. Increases - // height and then width as needed to make the text fit. This method - // supports multiple lines. - static void SizeStringInt(const std::wstring& text, const gfx::Font& font, - int* width, int* height, int flags); - - // Returns the default text alignment to be used when drawing text on a - // gfx::Canvas based on the directionality of the system locale language. This - // function is used by gfx::Canvas::DrawStringInt when the text alignment is - // not specified. - // - // This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or - // gfx::Canvas::TEXT_ALIGN_RIGHT. - static int DefaultCanvasTextAlignment(); - -#if defined(OS_POSIX) && !defined(OS_MACOSX) - // Draw the pixbuf in its natural size at (x, y). - void DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y); -#endif - -#ifdef OS_WIN // Only implemented on Windows for now. - // Draws text with a 1-pixel halo around it of the given color. It allows - // ClearType to be drawn to an otherwise transparenct bitmap for drag images. - // Drag images have only 1-bit of transparency, so we don't do any fancy - // blurring. - void DrawStringWithHalo(const std::wstring& text, - const gfx::Font& font, - const SkColor& text_color, - const SkColor& halo_color, - int x, int y, int w, int h, int flags); -#endif + Canvas(int width, int height, bool is_opaque) + : CanvasSkia(width, height, is_opaque) { + } + Canvas() : CanvasSkia() {} // Overridden from Canvas2: - virtual bool GetClipRect(gfx::Rect* clip_rect); - virtual bool ClipRectInt(int x, int y, int w, int h); - virtual bool IntersectsClipRectInt(int x, int y, int w, int h); - virtual void TranslateInt(int x, int y); - virtual void ScaleInt(int x, int y); - virtual void FillRectInt(int x, int y, int w, int h, - const SkPaint& paint); - virtual void FillRectInt(const SkColor& color, int x, int y, int w, - int h); - virtual void DrawRectInt(const SkColor& color, int x, int y, int w, - int h); - virtual void DrawRectInt(const SkColor& color, int x, int y, int w, int h, - SkXfermode::Mode mode); - virtual void DrawLineInt(const SkColor& color, int x1, int y1, int x2, - int y2); - virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y); - virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y, - const SkPaint& paint); - virtual void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, - int src_w, int src_h, int dest_x, int dest_y, - int dest_w, int dest_h, bool filter); - virtual void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, - int src_w, int src_h, int dest_x, int dest_y, - int dest_w, int dest_h, bool filter, - const SkPaint& paint); - virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, - const SkColor& color, int x, int y, int w, - int h); - virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, - const SkColor& color, - const gfx::Rect& display_rect); - virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, - const SkColor& color, int x, int y, int w, int h, - int flags); - virtual void DrawFocusRect(int x, int y, int width, int height); - virtual void TileImageInt(const SkBitmap& bitmap, int x, int y, int w, int h); - virtual void TileImageInt(const SkBitmap& bitmap, int src_x, int src_y, - int dest_x, int dest_y, int w, int h); - virtual SkBitmap ExtractBitmap() const; - virtual Canvas* AsCanvas(); + Canvas* AsCanvas() { + return this; + } private: -#if defined(OS_WIN) - // Draws text with the specified color, font and location. The text is - // aligned to the left, vertically centered, clipped to the region. If the - // text is too big, it is truncated and '...' is added to the end. - void DrawStringInt(const std::wstring& text, HFONT font, - const SkColor& color, int x, int y, int w, int h, - int flags); -#endif - DISALLOW_COPY_AND_ASSIGN(Canvas); }; -} // namespace gfx; +} #endif // GFX_CANVAS_H_ diff --git a/gfx/canvas.cc b/gfx/canvas_skia.cc index 28bc231..8fa763a 100644 --- a/gfx/canvas.cc +++ b/gfx/canvas_skia.cc @@ -8,17 +8,18 @@ #include "base/i18n/rtl.h" #include "base/logging.h" +#include "gfx/canvas.h" #include "gfx/font.h" #include "gfx/rect.h" #include "third_party/skia/include/core/SkShader.h" #if defined(OS_WIN) -#include "gfx/canvas_paint.h" +#include "gfx/canvas_skia_paint.h" #endif namespace gfx { -bool Canvas::GetClipRect(gfx::Rect* r) { +bool CanvasSkia::GetClipRect(gfx::Rect* r) { SkRect clip; if (!getClipBounds(&clip)) { if (r) @@ -31,29 +32,29 @@ bool Canvas::GetClipRect(gfx::Rect* r) { return true; } -bool Canvas::ClipRectInt(int x, int y, int w, int h) { +bool CanvasSkia::ClipRectInt(int x, int y, int w, int h) { SkRect new_clip; new_clip.set(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w), SkIntToScalar(y + h)); return clipRect(new_clip); } -bool Canvas::IntersectsClipRectInt(int x, int y, int w, int h) { +bool CanvasSkia::IntersectsClipRectInt(int x, int y, int w, int h) { SkRect clip; return getClipBounds(&clip) && clip.intersect(SkIntToScalar(x), SkIntToScalar(y), SkIntToScalar(x + w), SkIntToScalar(y + h)); } -void Canvas::TranslateInt(int x, int y) { +void CanvasSkia::TranslateInt(int x, int y) { translate(SkIntToScalar(x), SkIntToScalar(y)); } -void Canvas::ScaleInt(int x, int y) { +void CanvasSkia::ScaleInt(int x, int y) { scale(SkIntToScalar(x), SkIntToScalar(y)); } -void Canvas::FillRectInt(const SkColor& color, int x, int y, int w, int h) { +void CanvasSkia::FillRectInt(const SkColor& color, int x, int y, int w, int h) { SkPaint paint; paint.setColor(color); paint.setStyle(SkPaint::kFill_Style); @@ -61,17 +62,17 @@ void Canvas::FillRectInt(const SkColor& color, int x, int y, int w, int h) { FillRectInt(x, y, w, h, paint); } -void Canvas::FillRectInt(int x, int y, int w, int h, const SkPaint& paint) { +void CanvasSkia::FillRectInt(int x, int y, int w, int h, const SkPaint& paint) { SkIRect rc = {x, y, x + w, y + h}; drawIRect(rc, paint); } -void Canvas::DrawRectInt(const SkColor& color, int x, int y, int w, int h) { +void CanvasSkia::DrawRectInt(const SkColor& color, int x, int y, int w, int h) { DrawRectInt(color, x, y, w, h, SkXfermode::kSrcOver_Mode); } -void Canvas::DrawRectInt(const SkColor& color, int x, int y, int w, int h, - SkXfermode::Mode mode) { +void CanvasSkia::DrawRectInt(const SkColor& color, int x, int y, int w, int h, + SkXfermode::Mode mode) { SkPaint paint; paint.setColor(color); paint.setStyle(SkPaint::kStroke_Style); @@ -85,7 +86,8 @@ void Canvas::DrawRectInt(const SkColor& color, int x, int y, int w, int h, drawIRect(rc, paint); } -void Canvas::DrawLineInt(const SkColor& color, int x1, int y1, int x2, int y2) { +void CanvasSkia::DrawLineInt(const SkColor& color, int x1, int y1, int x2, + int y2) { SkPaint paint; paint.setColor(color); paint.setStrokeWidth(SkIntToScalar(1)); @@ -93,7 +95,7 @@ void Canvas::DrawLineInt(const SkColor& color, int x1, int y1, int x2, int y2) { SkIntToScalar(y2), paint); } -void Canvas::DrawFocusRect(int x, int y, int width, int height) { +void CanvasSkia::DrawFocusRect(int x, int y, int width, int height) { // Create a 2D bitmap containing alternating on/off pixels - we do this // so that you never get two pixels of the same color around the edges // of the focus rect (this may mean that opposing edges of the rect may @@ -147,28 +149,28 @@ void Canvas::DrawFocusRect(int x, int y, int width, int height) { drawRect(rect, paint); } -void Canvas::DrawBitmapInt(const SkBitmap& bitmap, int x, int y) { +void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, int x, int y) { drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y)); } -void Canvas::DrawBitmapInt(const SkBitmap& bitmap, int x, int y, - const SkPaint& paint) { +void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, int x, int y, + const SkPaint& paint) { drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y), &paint); } -void Canvas::DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, - int src_w, int src_h, int dest_x, int dest_y, - int dest_w, int dest_h, - bool filter) { +void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, + int src_w, int src_h, int dest_x, int dest_y, + int dest_w, int dest_h, + bool filter) { SkPaint p; DrawBitmapInt(bitmap, src_x, src_y, src_w, src_h, dest_x, dest_y, dest_w, dest_h, filter, p); } -void Canvas::DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, - int src_w, int src_h, int dest_x, int dest_y, - int dest_w, int dest_h, - bool filter, const SkPaint& paint) { +void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, + int src_w, int src_h, int dest_x, int dest_y, + int dest_w, int dest_h, + bool filter, const SkPaint& paint) { DLOG_ASSERT(src_x + src_w < std::numeric_limits<int16_t>::max() && src_y + src_h < std::numeric_limits<int16_t>::max()); if (src_w <= 0 || src_h <= 0 || dest_w <= 0 || dest_h <= 0) { @@ -217,28 +219,29 @@ void Canvas::DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, drawRect(dest_rect, p); } -void Canvas::DrawStringInt(const std::wstring& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h) { +void CanvasSkia::DrawStringInt(const std::wstring& text, + const gfx::Font& font, + const SkColor& color, + int x, int y, int w, int h) { DrawStringInt(text, font, color, x, y, w, h, - gfx::Canvas::DefaultCanvasTextAlignment()); + gfx::CanvasSkia::DefaultCanvasTextAlignment()); } -void Canvas::DrawStringInt(const std::wstring& text, - const gfx::Font& font, - const SkColor& color, - const gfx::Rect& display_rect) { +void CanvasSkia::DrawStringInt(const std::wstring& text, + const gfx::Font& font, + const SkColor& color, + const gfx::Rect& display_rect) { DrawStringInt(text, font, color, display_rect.x(), display_rect.y(), display_rect.width(), display_rect.height()); } -void Canvas::TileImageInt(const SkBitmap& bitmap, int x, int y, int w, int h) { +void CanvasSkia::TileImageInt(const SkBitmap& bitmap, int x, int y, int w, + int h) { TileImageInt(bitmap, 0, 0, x, y, w, h); } -void Canvas::TileImageInt(const SkBitmap& bitmap, int src_x, int src_y, - int dest_x, int dest_y, int w, int h) { +void CanvasSkia::TileImageInt(const SkBitmap& bitmap, int src_x, int src_y, + int dest_x, int dest_y, int w, int h) { if (!IntersectsClipRectInt(dest_x, dest_y, w, h)) return; @@ -260,7 +263,7 @@ void Canvas::TileImageInt(const SkBitmap& bitmap, int src_x, int src_y, restore(); } -SkBitmap Canvas::ExtractBitmap() const { +SkBitmap CanvasSkia::ExtractBitmap() const { const SkBitmap& device_bitmap = getDevice()->accessBitmap(false); // Make a bitmap to return, and a canvas to draw into it. We don't just want @@ -271,12 +274,8 @@ SkBitmap Canvas::ExtractBitmap() const { return result; } -Canvas* Canvas::AsCanvas() { - return this; -} - // static -int Canvas::DefaultCanvasTextAlignment() { +int CanvasSkia::DefaultCanvasTextAlignment() { if (!base::i18n::IsRTL()) return gfx::Canvas::TEXT_ALIGN_LEFT; return gfx::Canvas::TEXT_ALIGN_RIGHT; @@ -295,9 +294,9 @@ Canvas2* Canvas2::CreateCanvas(int width, int height, bool is_opaque) { #if defined(OS_WIN) // TODO(beng): move to canvas_win.cc, etc. -class CanvasPaintWin : public CanvasPaint, public CanvasPaint2 { +class CanvasPaintWin : public CanvasSkiaPaint, public CanvasPaint2 { public: - CanvasPaintWin(gfx::NativeView view) : CanvasPaint(view) {} + CanvasPaintWin(gfx::NativeView view) : CanvasSkiaPaint(view) {} // Overridden from CanvasPaint2: virtual bool IsValid() const { diff --git a/gfx/canvas_skia.h b/gfx/canvas_skia.h new file mode 100644 index 0000000..9a976fd --- /dev/null +++ b/gfx/canvas_skia.h @@ -0,0 +1,135 @@ +// Copyright (c) 2010 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 GFX_CANVAS_SKIA_H_ +#define GFX_CANVAS_SKIA_H_ + +#include "base/basictypes.h" +#include "gfx/canvas_2.h" +#include "skia/ext/platform_canvas.h" + +#if defined(OS_POSIX) && !defined(OS_MACOSX) +typedef struct _GdkPixbuf GdkPixbuf; +#endif + +namespace gfx { + +class Canvas; + +// CanvasSkia is a SkCanvas subclass that provides a number of methods for +// common operations used throughout an application built using base/gfx and +// app/gfx. +// +// All methods that take integer arguments (as is used throughout views) +// end with Int. If you need to use methods provided by the superclass +// you'll need to do a conversion. In particular you'll need to use +// macro SkIntToScalar(xxx), or if converting from a scalar to an integer +// SkScalarRound. +// +// A handful of methods in this class are overloaded providing an additional +// argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the +// source and destination colors are combined. Unless otherwise specified, +// the variant that does not take a SkXfermode::Mode uses a transfer mode +// of kSrcOver_Mode. +class CanvasSkia : public skia::PlatformCanvas, + public Canvas2 { + public: + // Creates an empty Canvas. Callers must use initialize before using the + // canvas. + CanvasSkia(); + + CanvasSkia(int width, int height, bool is_opaque); + + virtual ~CanvasSkia(); + + // Compute the size required to draw some text with the provided font. + // Attempts to fit the text with the provided width and height. Increases + // height and then width as needed to make the text fit. This method + // supports multiple lines. + static void SizeStringInt(const std::wstring& text, const gfx::Font& font, + int* width, int* height, int flags); + + // Returns the default text alignment to be used when drawing text on a + // gfx::CanvasSkia based on the directionality of the system locale language. + // This function is used by gfx::Canvas::DrawStringInt when the text alignment + // is not specified. + // + // This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or + // gfx::Canvas::TEXT_ALIGN_RIGHT. + static int DefaultCanvasTextAlignment(); + +#if defined(OS_POSIX) && !defined(OS_MACOSX) + // Draw the pixbuf in its natural size at (x, y). + void DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y); +#endif + +#ifdef OS_WIN // Only implemented on Windows for now. + // Draws text with a 1-pixel halo around it of the given color. It allows + // ClearType to be drawn to an otherwise transparenct bitmap for drag images. + // Drag images have only 1-bit of transparency, so we don't do any fancy + // blurring. + void DrawStringWithHalo(const std::wstring& text, + const gfx::Font& font, + const SkColor& text_color, + const SkColor& halo_color, + int x, int y, int w, int h, int flags); +#endif + + // Overridden from Canvas2: + virtual bool GetClipRect(gfx::Rect* clip_rect); + virtual bool ClipRectInt(int x, int y, int w, int h); + virtual bool IntersectsClipRectInt(int x, int y, int w, int h); + virtual void TranslateInt(int x, int y); + virtual void ScaleInt(int x, int y); + virtual void FillRectInt(int x, int y, int w, int h, + const SkPaint& paint); + virtual void FillRectInt(const SkColor& color, int x, int y, int w, + int h); + virtual void DrawRectInt(const SkColor& color, int x, int y, int w, + int h); + virtual void DrawRectInt(const SkColor& color, int x, int y, int w, int h, + SkXfermode::Mode mode); + virtual void DrawLineInt(const SkColor& color, int x1, int y1, int x2, + int y2); + virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y); + virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y, + const SkPaint& paint); + virtual void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, + int src_w, int src_h, int dest_x, int dest_y, + int dest_w, int dest_h, bool filter); + virtual void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, + int src_w, int src_h, int dest_x, int dest_y, + int dest_w, int dest_h, bool filter, + const SkPaint& paint); + virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, + const SkColor& color, int x, int y, int w, + int h); + virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, + const SkColor& color, + const gfx::Rect& display_rect); + virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font, + const SkColor& color, int x, int y, int w, int h, + int flags); + virtual void DrawFocusRect(int x, int y, int width, int height); + virtual void TileImageInt(const SkBitmap& bitmap, int x, int y, int w, int h); + virtual void TileImageInt(const SkBitmap& bitmap, int src_x, int src_y, + int dest_x, int dest_y, int w, int h); + virtual SkBitmap ExtractBitmap() const; + + private: +#if defined(OS_WIN) + // Draws text with the specified color, font and location. The text is + // aligned to the left, vertically centered, clipped to the region. If the + // text is too big, it is truncated and '...' is added to the end. + void DrawStringInt(const std::wstring& text, HFONT font, + const SkColor& color, int x, int y, int w, int h, + int flags); +#endif + + DISALLOW_COPY_AND_ASSIGN(CanvasSkia); +}; + +} // namespace gfx; + +#endif // GFX_CANVAS_SKIA_H_ diff --git a/gfx/canvas_linux.cc b/gfx/canvas_skia_linux.cc index 3f658d4..59e0e29 100644 --- a/gfx/canvas_linux.cc +++ b/gfx/canvas_skia_linux.cc @@ -91,14 +91,14 @@ static void UpdateCairoFontOptions() { namespace gfx { -Canvas::Canvas(int width, int height, bool is_opaque) +CanvasSkia::CanvasSkia(int width, int height, bool is_opaque) : skia::PlatformCanvas(width, height, is_opaque) { } -Canvas::Canvas() : skia::PlatformCanvas() { +CanvasSkia::CanvasSkia() : skia::PlatformCanvas() { } -Canvas::~Canvas() { +CanvasSkia::~CanvasSkia() { } // Pass a width > 0 to force wrapping and elliding. @@ -168,9 +168,9 @@ static void SetupPangoLayout(PangoLayout* layout, } // static -void Canvas::SizeStringInt(const std::wstring& text, - const gfx::Font& font, - int* width, int* height, int flags) { +void CanvasSkia::SizeStringInt(const std::wstring& text, + const gfx::Font& font, + int* width, int* height, int flags) { int org_width = *width; cairo_surface_t* surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0); @@ -202,11 +202,11 @@ void Canvas::SizeStringInt(const std::wstring& text, cairo_surface_destroy(surface); } -void Canvas::DrawStringInt(const std::wstring& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h, - int flags) { +void CanvasSkia::DrawStringInt(const std::wstring& text, + const gfx::Font& font, + const SkColor& color, + int x, int y, int w, int h, + int flags) { if (w <= 0 || h <= 0) return; @@ -255,7 +255,7 @@ void Canvas::DrawStringInt(const std::wstring& text, // NOTE: beginPlatformPaint returned its surface, we shouldn't destroy it. } -void Canvas::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { +void CanvasSkia::DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y) { if (!pixbuf) { NOTREACHED(); return; diff --git a/gfx/canvas_mac.mm b/gfx/canvas_skia_mac.mm index 87ff09b..29102fd 100644 --- a/gfx/canvas_mac.mm +++ b/gfx/canvas_skia_mac.mm @@ -14,20 +14,20 @@ namespace gfx { -Canvas::Canvas(int width, int height, bool is_opaque) +CanvasSkia::CanvasSkia(int width, int height, bool is_opaque) : skia::PlatformCanvas(width, height, is_opaque) { } -Canvas::Canvas() : skia::PlatformCanvas() { +CanvasSkia::CanvasSkia() : skia::PlatformCanvas() { } -Canvas::~Canvas() { +CanvasSkia::~CanvasSkia() { } // static -void Canvas::SizeStringInt(const std::wstring& text, - const gfx::Font& font, - int *width, int *height, int flags) { +void CanvasSkia::SizeStringInt(const std::wstring& text, + const gfx::Font& font, + int *width, int *height, int flags) { NSFont* native_font = font.nativeFont(); NSString* ns_string = base::SysWideToNSString(text); NSDictionary* attributes = @@ -38,9 +38,9 @@ void Canvas::SizeStringInt(const std::wstring& text, *height = font.height(); } -void Canvas::DrawStringInt(const std::wstring& text, const gfx::Font& font, - const SkColor& color, int x, int y, int w, int h, - int flags) { +void CanvasSkia::DrawStringInt(const std::wstring& text, const gfx::Font& font, + const SkColor& color, int x, int y, int w, int h, + int flags) { if (!IntersectsClipRectInt(x, y, w, h)) return; diff --git a/gfx/canvas_paint.h b/gfx/canvas_skia_paint.h index a11a693..4e6f768 100644 --- a/gfx/canvas_paint.h +++ b/gfx/canvas_skia_paint.h @@ -2,19 +2,19 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef GFX_CANVAS_PAINT_H_ -#define GFX_CANVAS_PAINT_H_ +#ifndef GFX_CANVAS_SKIA_PAINT_H_ +#define GFX_CANVAS_SKIA_PAINT_H_ #include "gfx/canvas.h" #include "skia/ext/canvas_paint.h" -// Define a skia::CanvasPaint type that wraps our gfx::Canvas like the +// Define a gfx::CanvasSkiaPaint type that wraps our gfx::Canvas like the // skia::PlatformCanvasPaint wraps PlatformCanvas. namespace gfx { -typedef skia::CanvasPaintT<Canvas> CanvasPaint; +typedef skia::CanvasPaintT<Canvas> CanvasSkiaPaint; } // namespace gfx -#endif // GFX_CANVAS_PAINT_H_ +#endif // GFX_CANVAS_SKIA_PAINT_H_ diff --git a/gfx/canvas_win.cc b/gfx/canvas_skia_win.cc index 98c5f74..4177ef5 100644 --- a/gfx/canvas_win.cc +++ b/gfx/canvas_skia_win.cc @@ -42,7 +42,7 @@ int ComputeFormatFlags(int flags, const std::wstring& text) { if (!(flags & (gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::TEXT_ALIGN_RIGHT | gfx::Canvas::TEXT_ALIGN_LEFT))) { - flags |= gfx::Canvas::DefaultCanvasTextAlignment(); + flags |= gfx::CanvasSkia::DefaultCanvasTextAlignment(); } // horizontal alignment @@ -125,20 +125,20 @@ int ComputeFormatFlags(int flags, const std::wstring& text) { namespace gfx { -Canvas::Canvas(int width, int height, bool is_opaque) +CanvasSkia::CanvasSkia(int width, int height, bool is_opaque) : skia::PlatformCanvas(width, height, is_opaque) { } -Canvas::Canvas() : skia::PlatformCanvas() { +CanvasSkia::CanvasSkia() : skia::PlatformCanvas() { } -Canvas::~Canvas() { +CanvasSkia::~CanvasSkia() { } // static -void Canvas::SizeStringInt(const std::wstring& text, - const gfx::Font& font, - int* width, int* height, int flags) { +void CanvasSkia::SizeStringInt(const std::wstring& text, + const gfx::Font& font, + int* width, int* height, int flags) { // Clamp the max amount of text we'll measure to 2K. When the string is // actually drawn, it will be clipped to whatever size box is provided, and // the time to do that doesn't depend on the length being clipped off. @@ -173,9 +173,9 @@ void Canvas::SizeStringInt(const std::wstring& text, *height = r.bottom; } -void Canvas::DrawStringInt(const std::wstring& text, HFONT font, - const SkColor& color, int x, int y, int w, int h, - int flags) { +void CanvasSkia::DrawStringInt(const std::wstring& text, HFONT font, + const SkColor& color, int x, int y, int w, int h, + int flags) { if (!IntersectsClipRectInt(x, y, w, h)) return; @@ -208,10 +208,10 @@ void Canvas::DrawStringInt(const std::wstring& text, HFONT font, getTopPlatformDevice().makeOpaque(x, y, w, h); } -void Canvas::DrawStringInt(const std::wstring& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h, int flags) { +void CanvasSkia::DrawStringInt(const std::wstring& text, + const gfx::Font& font, + const SkColor& color, + int x, int y, int w, int h, int flags) { DrawStringInt(text, font.hfont(), color, x, y, w, h, flags); } @@ -242,19 +242,19 @@ static bool pixelShouldGetHalo(const SkBitmap& bitmap, int x, int y, return false; } -void Canvas::DrawStringWithHalo(const std::wstring& text, - const gfx::Font& font, - const SkColor& text_color, - const SkColor& halo_color_in, - int x, int y, int w, int h, - int flags) { +void CanvasSkia::DrawStringWithHalo(const std::wstring& text, + const gfx::Font& font, + const SkColor& text_color, + const SkColor& halo_color_in, + int x, int y, int w, int h, + int flags) { // Some callers will have semitransparent halo colors, which we don't handle // (since the resulting image can have 1-bit transparency only). SkColor halo_color = halo_color_in | 0xFF000000; // Create a temporary buffer filled with the halo color. It must leave room // for the 1-pixel border around the text. - Canvas text_canvas(w + 2, h + 2, true); + CanvasSkia text_canvas(w + 2, h + 2, true); SkPaint bkgnd_paint; bkgnd_paint.setColor(halo_color); text_canvas.FillRectInt(0, 0, w + 2, h + 2, bkgnd_paint); diff --git a/gfx/gfx.gyp b/gfx/gfx.gyp index 54d6833..c0d4000 100644 --- a/gfx/gfx.gyp +++ b/gfx/gfx.gyp @@ -62,13 +62,14 @@ 'sources': [ 'blit.cc', 'blit.h', - 'canvas.cc', 'canvas.h', 'canvas_2.h', - 'canvas_linux.cc', - 'canvas_mac.mm', - 'canvas_paint.h', - 'canvas_win.cc', + 'canvas_skia.h', + 'canvas_skia.cc', + 'canvas_skia_linux.cc', + 'canvas_skia_mac.mm', + 'canvas_skia_paint.h', + 'canvas_skia_win.cc', 'codec/jpeg_codec.cc', 'codec/jpeg_codec.h', 'codec/png_codec.cc', @@ -79,7 +80,6 @@ 'font.h', 'font_gtk.cc', 'font_mac.mm', - 'font_skia.cc', 'font_win.cc', 'gfx_paths.cc', 'gfx_paths.h', @@ -123,6 +123,7 @@ '../build/linux/system.gyp:fontconfig', ], 'sources': [ + 'font_skia.cc', 'gtk_native_view_id_manager.cc', 'gtk_native_view_id_manager.h', 'gtk_util.cc', |