summaryrefslogtreecommitdiffstats
path: root/gfx
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-17 22:40:49 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-17 22:40:49 +0000
commit62c6a781a95250f273f3bd3df945b3ff850e913e (patch)
treec28cafb3018b81a85227781fd46c3ebe0160f1d6 /gfx
parent1c53ffde1ea034448b09129c975d93aa83b16c94 (diff)
downloadchromium_src-62c6a781a95250f273f3bd3df945b3ff850e913e.zip
chromium_src-62c6a781a95250f273f3bd3df945b3ff850e913e.tar.gz
chromium_src-62c6a781a95250f273f3bd3df945b3ff850e913e.tar.bz2
Cleanup:
* Remove unnecessary code * Make function declaration style match style guide (one arg per line is preferred when all don't fit, but related args may be together) BUG=none TEST=none Review URL: http://codereview.chromium.org/3109019 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@56432 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gfx')
-rw-r--r--gfx/canvas.h120
-rw-r--r--gfx/canvas_direct2d.cc161
-rw-r--r--gfx/canvas_direct2d.h71
-rw-r--r--gfx/canvas_direct2d_unittest.cc51
-rw-r--r--gfx/canvas_skia.cc129
-rw-r--r--gfx/canvas_skia.h86
-rw-r--r--gfx/canvas_skia_linux.cc3
-rw-r--r--gfx/canvas_skia_mac.mm12
-rw-r--r--gfx/canvas_skia_win.cc20
9 files changed, 192 insertions, 461 deletions
diff --git a/gfx/canvas.h b/gfx/canvas.h
index 8699807..70892b4 100644
--- a/gfx/canvas.h
+++ b/gfx/canvas.h
@@ -103,30 +103,32 @@ class Canvas {
// Fills the specified region with the specified color using a transfer
// mode of SkXfermode::kSrcOver_Mode.
- virtual void FillRectInt(const SkColor& color, int x, int y, int w,
- int h) = 0;
+ virtual void FillRectInt(const SkColor& color,
+ int x, int y, int w, int h) = 0;
// Fills the specified region with the specified brush.
- virtual void FillRectInt(const gfx::Brush* brush, int x, int y, int w,
- int h) = 0;
+ virtual void FillRectInt(const gfx::Brush* brush,
+ int x, int y, int w, int h) = 0;
// Draws a single pixel rect in the specified region with the specified
// color, using a transfer mode of SkXfermode::kSrcOver_Mode.
//
- // NOTE: if you need a single pixel line, use DraLineInt.
- virtual void DrawRectInt(const SkColor& color, int x, int y, int w,
- int h) = 0;
+ // NOTE: if you need a single pixel line, use DrawLineInt.
+ virtual void DrawRectInt(const SkColor& color,
+ int x, int y, int w, int h) = 0;
// Draws a single pixel rect in the specified region with the specified
// color and transfer mode.
//
- // NOTE: if you need a single pixel line, use DraLineInt.
- virtual void DrawRectInt(const SkColor& color, int x, int y, int w, int h,
+ // NOTE: if you need a single pixel line, use DrawLineInt.
+ virtual void DrawRectInt(const SkColor& color,
+ int x, int y, int w, int h,
SkXfermode::Mode mode) = 0;
// Draws a single pixel line with the specified color.
- virtual void DrawLineInt(const SkColor& color, int x1, int y1, int x2,
- int y2) = 0;
+ virtual void DrawLineInt(const SkColor& color,
+ int x1, int y1,
+ int x2, int y2) = 0;
// Draws a bitmap with the origin at the specified location. The upper left
// corner of the bitmap is rendered at the specified location.
@@ -135,7 +137,8 @@ class Canvas {
// Draws a bitmap with the origin at the specified location, using the
// specified paint. The upper left corner of the bitmap is rendered at the
// specified location.
- virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y,
+ virtual void DrawBitmapInt(const SkBitmap& bitmap,
+ int x, int y,
const SkPaint& paint) = 0;
// Draws a portion of a bitmap in the specified location. The src parameters
@@ -150,38 +153,45 @@ class Canvas {
// is used for resampling.
//
// An optional custom SkPaint can be provided.
- 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) = 0;
- 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) = 0;
+ 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) = 0;
// 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.
- virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font,
- const SkColor& color, int x, int y, int w,
- int h) = 0;
- virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font,
+ virtual void DrawStringInt(const std::wstring& text, const
+ gfx::Font& font,
+ const SkColor& color,
+ int x, int y, int w, int h) = 0;
+ virtual void DrawStringInt(const std::wstring& text,
+ const gfx::Font& font,
const SkColor& color,
const gfx::Rect& display_rect) = 0;
// Draws text with the specified color, font and location. The last argument
// specifies flags for how the text should be rendered. It can be one of
// TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT.
- 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,
+ int x, int y, int w, int h,
int flags) = 0;
// Draws a dotted gray rectangle used for focus purposes.
virtual void DrawFocusRect(int x, int y, int width, int height) = 0;
// Tiles the image in the specified region.
- virtual void TileImageInt(const SkBitmap& bitmap, int x, int y, int w,
- int h) = 0;
- virtual void TileImageInt(const SkBitmap& bitmap, int src_x, int src_y,
+ virtual void TileImageInt(const SkBitmap& bitmap,
+ int x, int y, int w, int h) = 0;
+ virtual void TileImageInt(const SkBitmap& bitmap,
+ int src_x, int src_y,
int dest_x, int dest_y, int w, int h) = 0;
// Returns a native drawing context for platform specific drawing routines to
@@ -192,62 +202,6 @@ class Canvas {
// returned by BeginPlatformPaint().
virtual void EndPlatformPaint() = 0;
- // Defines how a brush paints the area outside its normal content area.
- enum TileMode {
- TileMode_Clamp,
- TileMode_Repeat,
- TileMode_Mirror
- };
-
- // Creates a linear gradient brush.
- // |start_point| and |end_point| are the pixel positions of the start and end
- // points of the gradient.
- // |colors| is a list of color stops.
- // |positions| is a list of positions corresponding to the color stops, an
- // array of floats of increasing value ranging from 0.0f to 1.0f.
- // |position_count| is the size of the |colors| and |positions| arrays.
- // |tile_mode| specifies how the gradient brush repeats outside its natural
- // bounds.
- // Returns an encapsulated platform brush object which the caller must delete.
- // Returns NULL if the system is unable to create the brush for some reason.
- virtual Brush* CreateLinearGradientBrush(
- const gfx::Point& start_point,
- const gfx::Point& end_point,
- const SkColor colors[],
- const float positions[],
- size_t position_count,
- TileMode tile_mode) = 0;
-
- // Creates a radial gradient brush.
- // |center_point| is the center of the circle in the brush's coordinate space.
- // |radius| is the radius of the circle.
- // |colors| is a list of color stops.
- // |positions| is a list of positions corresponding to the color stops, an
- // array of floats of increasing value ranging from 0.0f to 1.0f.
- // |position_count| is the size of the |colors| and |positions| arrays.
- // |tile_mode| specifies how the gradient brush repeats outside its natural
- // bounds.
- // Returns an encapsulated platform brush object which the caller must delete.
- // Returns NULL if the system is unable to create the brush for some reason.
- virtual Brush* CreateRadialGradientBrush(
- const gfx::Point& center_point,
- float radius,
- const SkColor colors[],
- const float positions[],
- size_t position_count,
- TileMode tile_mode) = 0;
-
- // Creates a bitmap brush.
- // |bitmap| is the bitmap to be used for the brush.
- // |tile_mode_x,y| - specifies how the brush tiles the areas beyond those
- // filled by its bitmap along each axis.
- // Returns an encapsulated platform brush object which the caller must delete.
- // Returns NULL if the system is unable to create the brush for some reason.
- virtual Brush* CreateBitmapBrush(
- const SkBitmap& bitmap,
- TileMode tile_mode_x,
- TileMode tile_mode_y) = 0;
-
// TODO(beng): remove this once we don't need to use any skia-specific methods
// through this interface.
// A quick and dirty way to obtain the underlying SkCanvas.
diff --git a/gfx/canvas_direct2d.cc b/gfx/canvas_direct2d.cc
index dbd1287..0908802 100644
--- a/gfx/canvas_direct2d.cc
+++ b/gfx/canvas_direct2d.cc
@@ -27,58 +27,15 @@ D2D1_RECT_F RectToRectF(const gfx::Rect& rect) {
return RectToRectF(rect.x(), rect.y(), rect.width(), rect.height());
}
-D2D1_POINT_2F PointToPoint2F(const gfx::Point& point) {
- return D2D1::Point2F(static_cast<float>(point.x()),
- static_cast<float>(point.y()));
-}
-
D2D1_POINT_2F PointToPoint2F(int x, int y) {
return D2D1::Point2F(static_cast<float>(x), static_cast<float>(y));
}
-D2D1_EXTEND_MODE TileModeToExtendMode(gfx::Canvas::TileMode tile_mode) {
- switch (tile_mode) {
- case gfx::Canvas::TileMode_Clamp:
- return D2D1_EXTEND_MODE_CLAMP;
- case gfx::Canvas::TileMode_Mirror:
- return D2D1_EXTEND_MODE_MIRROR;
- case gfx::Canvas::TileMode_Repeat:
- return D2D1_EXTEND_MODE_WRAP;
- default:
- NOTREACHED() << "Invalid TileMode";
- }
- return D2D1_EXTEND_MODE_CLAMP;
-}
-
D2D1_BITMAP_INTERPOLATION_MODE FilterToInterpolationMode(bool filter) {
return filter ? D2D1_BITMAP_INTERPOLATION_MODE_LINEAR
: D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR;
}
-// Creates a Direct2D gradient stop collection for the specified colors and
-// positions. The caller is responsible for releasing this object.
-ID2D1GradientStopCollection* CreateGradientStopCollection(
- ID2D1RenderTarget* render_target,
- const SkColor colors[],
- const float positions[],
- size_t position_count,
- gfx::Canvas::TileMode tile_mode) {
- scoped_array<D2D1_GRADIENT_STOP> gradient_stops(
- new D2D1_GRADIENT_STOP[position_count]);
- for (size_t i = 0; i < position_count; ++i) {
- gradient_stops[i].color = SkColorToColorF(colors[i]);
- gradient_stops[i].position = positions[i];
- }
- ID2D1GradientStopCollection* gradient_stop_collection = NULL;
- HRESULT hr = render_target->CreateGradientStopCollection(
- gradient_stops.get(),
- position_count,
- D2D1_GAMMA_2_2,
- TileModeToExtendMode(tile_mode),
- &gradient_stop_collection);
- return SUCCEEDED(hr) ? gradient_stop_collection : NULL;
-}
-
// Creates a Direct2D bitmap object from the contents of a SkBitmap. The caller
// is responsible for releasing this object.
ID2D1Bitmap* CreateD2D1BitmapFromSkBitmap(ID2D1RenderTarget* render_target,
@@ -104,16 +61,15 @@ ID2D1Bitmap* CreateD2D1BitmapFromSkBitmap(ID2D1RenderTarget* render_target,
// is responsible for releasing this object.
ID2D1Brush* CreateD2D1BrushFromSkBitmap(ID2D1RenderTarget* render_target,
const SkBitmap& bitmap,
- gfx::Canvas::TileMode tile_mode_x,
- gfx::Canvas::TileMode tile_mode_y) {
+ D2D1_EXTEND_MODE extend_mode_x,
+ D2D1_EXTEND_MODE extend_mode_y) {
ScopedComPtr<ID2D1Bitmap> d2d1_bitmap(
CreateD2D1BitmapFromSkBitmap(render_target, bitmap));
ID2D1BitmapBrush* brush = NULL;
render_target->CreateBitmapBrush(
d2d1_bitmap,
- D2D1::BitmapBrushProperties(TileModeToExtendMode(tile_mode_x),
- TileModeToExtendMode(tile_mode_y)),
+ D2D1::BitmapBrushProperties(extend_mode_x, extend_mode_y),
D2D1::BrushProperties(),
&brush);
return brush;
@@ -251,33 +207,35 @@ void CanvasDirect2D::FillRectInt(int x, int y, int w, int h,
NOTIMPLEMENTED();
}
-void CanvasDirect2D::FillRectInt(const SkColor& color, int x, int y, int w,
- int h) {
+void CanvasDirect2D::FillRectInt(const SkColor& color,
+ int x, int y, int w, int h) {
ScopedComPtr<ID2D1SolidColorBrush> solid_brush;
rt_->CreateSolidColorBrush(SkColorToColorF(color), solid_brush.Receive());
rt_->FillRectangle(RectToRectF(x, y, w, h), solid_brush);
}
-void CanvasDirect2D::FillRectInt(const gfx::Brush* brush, int x, int y, int w,
- int h) {
+void CanvasDirect2D::FillRectInt(const gfx::Brush* brush,
+ int x, int y, int w, int h) {
const Direct2DBrush* d2d_brush = static_cast<const Direct2DBrush*>(brush);
rt_->FillRectangle(RectToRectF(x, y, w, h), d2d_brush->brush());
}
-void CanvasDirect2D::DrawRectInt(const SkColor& color, int x, int y, int w,
- int h) {
+void CanvasDirect2D::DrawRectInt(const SkColor& color,
+ int x, int y, int w, int h) {
ScopedComPtr<ID2D1SolidColorBrush> solid_brush;
rt_->CreateSolidColorBrush(SkColorToColorF(color), solid_brush.Receive());
rt_->DrawRectangle(RectToRectF(x, y, w, h), solid_brush);
}
-void CanvasDirect2D::DrawRectInt(const SkColor& color, int x, int y, int w,
- int h, SkXfermode::Mode mode) {
+void CanvasDirect2D::DrawRectInt(const SkColor& color,
+ int x, int y, int w, int h,
+ SkXfermode::Mode mode) {
NOTIMPLEMENTED();
}
-void CanvasDirect2D::DrawLineInt(const SkColor& color, int x1, int y1, int x2,
- int y2) {
+void CanvasDirect2D::DrawLineInt(const SkColor& color,
+ int x1, int y1,
+ int x2, int y2) {
ScopedComPtr<ID2D1SolidColorBrush> solid_brush;
rt_->CreateSolidColorBrush(SkColorToColorF(color), solid_brush.Receive());
rt_->DrawLine(PointToPoint2F(x1, y1), PointToPoint2F(x2, y2), solid_brush);
@@ -293,14 +251,17 @@ void CanvasDirect2D::DrawBitmapInt(const SkBitmap& bitmap, int x, int y) {
RectToRectF(0, 0, bitmap.width(), bitmap.height()));
}
-void CanvasDirect2D::DrawBitmapInt(const SkBitmap& bitmap, int x, int y,
+void CanvasDirect2D::DrawBitmapInt(const SkBitmap& bitmap,
+ int x, int y,
const SkPaint& paint) {
NOTIMPLEMENTED();
}
-void CanvasDirect2D::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 CanvasDirect2D::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) {
ScopedComPtr<ID2D1Bitmap> d2d1_bitmap(
CreateD2D1BitmapFromSkBitmap(rt_, bitmap));
rt_->DrawBitmap(d2d1_bitmap,
@@ -310,17 +271,19 @@ void CanvasDirect2D::DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y,
RectToRectF(src_x, src_y, src_w, src_h));
}
-void CanvasDirect2D::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 CanvasDirect2D::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) {
NOTIMPLEMENTED();
}
void CanvasDirect2D::DrawStringInt(const std::wstring& text,
const gfx::Font& font,
- const SkColor& color, int x, int y, int w,
- int h) {
+ const SkColor& color,
+ int x, int y, int w, int h) {
NOTIMPLEMENTED();
}
@@ -343,15 +306,16 @@ void CanvasDirect2D::DrawFocusRect(int x, int y, int width, int height) {
NOTIMPLEMENTED();
}
-void CanvasDirect2D::TileImageInt(const SkBitmap& bitmap, int x, int y, int w,
- int h) {
+void CanvasDirect2D::TileImageInt(const SkBitmap& bitmap,
+ int x, int y, int w, int h) {
ScopedComPtr<ID2D1Brush> brush(
- CreateD2D1BrushFromSkBitmap(rt_, bitmap, TileMode_Repeat,
- TileMode_Repeat));
+ CreateD2D1BrushFromSkBitmap(rt_, bitmap, D2D1_EXTEND_MODE_WRAP,
+ D2D1_EXTEND_MODE_WRAP));
rt_->FillRectangle(RectToRectF(x, y, w, h), brush);
}
-void CanvasDirect2D::TileImageInt(const SkBitmap& bitmap, int src_x, int src_y,
+void CanvasDirect2D::TileImageInt(const SkBitmap& bitmap,
+ int src_x, int src_y,
int dest_x, int dest_y, int w, int h) {
NOTIMPLEMENTED();
}
@@ -371,61 +335,6 @@ void CanvasDirect2D::EndPlatformPaint() {
interop_rt_.release();
}
-Brush* CanvasDirect2D::CreateLinearGradientBrush(
- const gfx::Point& start_point,
- const gfx::Point& end_point,
- const SkColor colors[],
- const float positions[],
- size_t position_count,
- TileMode tile_mode) {
- ScopedComPtr<ID2D1GradientStopCollection> gradient_stop_collection(
- CreateGradientStopCollection(rt_, colors, positions, position_count,
- tile_mode));
- if (!gradient_stop_collection.get())
- return NULL;
-
- ID2D1LinearGradientBrush* brush = NULL;
- HRESULT hr = rt_->CreateLinearGradientBrush(
- D2D1::LinearGradientBrushProperties(PointToPoint2F(start_point),
- PointToPoint2F(end_point)),
- gradient_stop_collection,
- &brush);
- return SUCCEEDED(hr) ? new Direct2DBrush(brush) : NULL;
-}
-
-Brush* CanvasDirect2D::CreateRadialGradientBrush(
- const gfx::Point& center_point,
- float radius,
- const SkColor colors[],
- const float positions[],
- size_t position_count,
- TileMode tile_mode) {
- ScopedComPtr<ID2D1GradientStopCollection> gradient_stop_collection(
- CreateGradientStopCollection(rt_, colors, positions, position_count,
- tile_mode));
- if (!gradient_stop_collection.get())
- return NULL;
-
- ID2D1RadialGradientBrush* brush = NULL;
- HRESULT hr = rt_->CreateRadialGradientBrush(
- D2D1::RadialGradientBrushProperties(PointToPoint2F(center_point),
- PointToPoint2F(gfx::Point()),
- radius,
- radius),
- gradient_stop_collection,
- &brush);
- return SUCCEEDED(hr) ? new Direct2DBrush(brush) : NULL;
-}
-
-Brush* CanvasDirect2D::CreateBitmapBrush(
- const SkBitmap& bitmap,
- TileMode tile_mode_x,
- TileMode tile_mode_y) {
- ID2D1Brush* brush =
- CreateD2D1BrushFromSkBitmap(rt_, bitmap, tile_mode_x, tile_mode_y);
- return brush ? new Direct2DBrush(brush) : NULL;
-}
-
CanvasSkia* CanvasDirect2D::AsCanvasSkia() {
return NULL;
}
diff --git a/gfx/canvas_direct2d.h b/gfx/canvas_direct2d.h
index 4cd5cd4..61025d9 100644
--- a/gfx/canvas_direct2d.h
+++ b/gfx/canvas_direct2d.h
@@ -32,60 +32,49 @@ class CanvasDirect2D : public Canvas {
virtual bool ClipRectInt(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 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 FillRectInt(const gfx::Brush* brush, 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,
+ 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 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,
+ 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,
+ 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,
+ 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,
+ 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,
+ virtual void TileImageInt(const SkBitmap& bitmap,
+ int src_x, int src_y,
int dest_x, int dest_y, int w, int h);
virtual gfx::NativeDrawingContext BeginPlatformPaint();
virtual void EndPlatformPaint();
- virtual Brush* CreateLinearGradientBrush(
- const gfx::Point& start_point,
- const gfx::Point& end_point,
- const SkColor colors[],
- const float positions[],
- size_t position_count,
- TileMode tile_mode);
- virtual Brush* CreateRadialGradientBrush(
- const gfx::Point& center_point,
- float radius,
- const SkColor colors[],
- const float positions[],
- size_t position_count,
- TileMode tile_mode);
- virtual Brush* CreateBitmapBrush(
- const SkBitmap& bitmap,
- TileMode tile_mode_x,
- TileMode tile_mode_y);
virtual CanvasSkia* AsCanvasSkia();
virtual const CanvasSkia* AsCanvasSkia() const;
diff --git a/gfx/canvas_direct2d_unittest.cc b/gfx/canvas_direct2d_unittest.cc
index 95f4398..a4d2c52 100644
--- a/gfx/canvas_direct2d_unittest.cc
+++ b/gfx/canvas_direct2d_unittest.cc
@@ -231,57 +231,6 @@ TEST(CanvasDirect2D, ClipRectWithScale) {
canvas.Restore();
}
-TEST(CanvasDirect2D, CreateLinearGradientBrush) {
- TestWindow window;
- gfx::CanvasDirect2D canvas(window.rt());
-
- canvas.Save();
- SkColor colors[] = { SK_ColorRED, SK_ColorWHITE };
- float positions[] = { 0.0f, 1.0f };
- scoped_ptr<gfx::Brush> brush(canvas.CreateLinearGradientBrush(
- gfx::Point(0, 0),
- gfx::Point(100, 0),
- colors,
- positions,
- 2,
- gfx::Canvas::TileMode_Clamp));
- canvas.FillRectInt(brush.get(), 0, 0, 500, 500);
- canvas.Restore();
-}
-
-TEST(CanvasDirect2D, CreateRadialGradientBrush) {
- TestWindow window;
- gfx::CanvasDirect2D canvas(window.rt());
-
- canvas.Save();
- SkColor colors[] = { SK_ColorBLUE, SK_ColorGREEN };
- float positions[] = { 0.0f, 1.0f };
- scoped_ptr<gfx::Brush> brush(canvas.CreateRadialGradientBrush(
- gfx::Point(200, 200),
- 100.0f,
- colors,
- positions,
- 2,
- gfx::Canvas::TileMode_Clamp));
- canvas.FillRectInt(brush.get(), 0, 0, 500, 500);
- canvas.Restore();
-}
-
-TEST(CanvasDirect2D, CreateBitmapBrush) {
- TestWindow window;
- gfx::CanvasDirect2D canvas(window.rt());
-
- SkBitmap bitmap = LoadBitmapFromResources(IDR_BITMAP_BRUSH_IMAGE);
-
- canvas.Save();
- scoped_ptr<gfx::Brush> brush(canvas.CreateBitmapBrush(
- bitmap,
- gfx::Canvas::TileMode_Mirror,
- gfx::Canvas::TileMode_Mirror));
- canvas.FillRectInt(brush.get(), 0, 0, 500, 500);
- canvas.Restore();
-}
-
TEST(CanvasDirect2D, DrawRectInt) {
TestWindow window;
gfx::CanvasDirect2D canvas(window.rt());
diff --git a/gfx/canvas_skia.cc b/gfx/canvas_skia.cc
index d46e519..c15b2e5 100644
--- a/gfx/canvas_skia.cc
+++ b/gfx/canvas_skia.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// 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.
@@ -19,26 +19,6 @@
namespace {
-SkPoint PointToSkPoint(const gfx::Point point) {
- SkPoint sk_point;
- sk_point.set(SkIntToScalar(point.x()), SkIntToScalar(point.y()));
- return sk_point;
-}
-
-SkShader::TileMode TileModeToSkShaderTileMode(gfx::Canvas::TileMode tile_mode) {
- switch (tile_mode) {
- case gfx::Canvas::TileMode_Clamp:
- return SkShader::kClamp_TileMode;
- case gfx::Canvas::TileMode_Mirror:
- return SkShader::kMirror_TileMode;
- case gfx::Canvas::TileMode_Repeat:
- return SkShader::kRepeat_TileMode;
- default:
- NOTREACHED() << "Invalid TileMode";
- }
- return SkShader::kClamp_TileMode;
-}
-
// A platform wrapper for a Skia shader that makes sure the underlying
// SkShader object is unref'ed when this object is destroyed.
class SkiaShader : public gfx::Brush {
@@ -132,8 +112,8 @@ void CanvasSkia::FillRectInt(const SkColor& color, int x, int y, int w, int h) {
FillRectInt(x, y, w, h, paint);
}
-void CanvasSkia::FillRectInt(const gfx::Brush* brush, int x, int y, int w,
- int h) {
+void CanvasSkia::FillRectInt(const gfx::Brush* brush,
+ int x, int y, int w, int h) {
const SkiaShader* shader = static_cast<const SkiaShader*>(brush);
SkPaint paint;
paint.setShader(shader->shader());
@@ -150,7 +130,8 @@ void CanvasSkia::DrawRectInt(const SkColor& color, int x, int y, int w, int h) {
DrawRectInt(color, x, y, w, h, SkXfermode::kSrcOver_Mode);
}
-void CanvasSkia::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,
SkXfermode::Mode mode) {
SkPaint paint;
paint.setColor(color);
@@ -161,12 +142,12 @@ void CanvasSkia::DrawRectInt(const SkColor& color, int x, int y, int w, int h,
paint.setStrokeWidth(SkIntToScalar(0));
paint.setXfermodeMode(mode);
- SkIRect rc = {x, y, x + w, y + h};
- drawIRect(rc, paint);
+ FillRectInt(x, y, w, h, paint);
}
-void CanvasSkia::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));
@@ -212,44 +193,36 @@ void CanvasSkia::DrawFocusRect(int x, int y, int width, int height) {
paint.setShader(shader);
shader->unref();
- SkRect rect;
- rect.set(SkIntToScalar(x), SkIntToScalar(y),
- SkIntToScalar(x + width), SkIntToScalar(y + 1));
- drawRect(rect, paint);
- rect.set(SkIntToScalar(x), SkIntToScalar(y + height - 1),
- SkIntToScalar(x + width), SkIntToScalar(y + height));
- drawRect(rect, paint);
-
- rect.set(SkIntToScalar(x), SkIntToScalar(y),
- SkIntToScalar(x + 1), SkIntToScalar(y + height));
- drawRect(rect, paint);
- rect.set(SkIntToScalar(x + width - 1), SkIntToScalar(y),
- SkIntToScalar(x + width), SkIntToScalar(y + height));
- drawRect(rect, paint);
+ FillRectInt(x, y, width, 1, paint);
+ FillRectInt(x, y + height - 1, width, 1, paint);
+ FillRectInt(x, y, 1, height, paint);
+ FillRectInt(x + width - 1, y, 1, height, paint);
}
void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, int x, int y) {
drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y));
}
-void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap, int x, int y,
+void CanvasSkia::DrawBitmapInt(const SkBitmap& bitmap,
+ int x, int y,
const SkPaint& paint) {
drawBitmap(bitmap, SkIntToScalar(x), SkIntToScalar(y), &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,
+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 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) {
+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) {
@@ -314,12 +287,13 @@ void CanvasSkia::DrawStringInt(const std::wstring& text,
display_rect.width(), display_rect.height());
}
-void CanvasSkia::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 CanvasSkia::TileImageInt(const SkBitmap& bitmap, int src_x, int src_y,
+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;
@@ -350,55 +324,6 @@ void CanvasSkia::EndPlatformPaint() {
endPlatformPaint();
}
-Brush* CanvasSkia::CreateLinearGradientBrush(
- const gfx::Point& start_point,
- const gfx::Point& end_point,
- const SkColor colors[],
- const float positions[],
- size_t position_count,
- TileMode tile_mode) {
- SkPoint boundary_points[2];
- boundary_points[0].set(SkIntToScalar(start_point.x()),
- SkIntToScalar(start_point.y()));
- boundary_points[1].set(SkIntToScalar(start_point.y()),
- SkIntToScalar(start_point.y()));
- SkShader* shader = SkGradientShader::CreateLinear(
- boundary_points,
- colors,
- positions,
- position_count,
- TileModeToSkShaderTileMode(tile_mode));
- return new SkiaShader(shader);
-}
-
-Brush* CanvasSkia::CreateRadialGradientBrush(
- const gfx::Point& center_point,
- float radius,
- const SkColor colors[],
- const float positions[],
- size_t position_count,
- TileMode tile_mode) {
- SkShader* shader = SkGradientShader::CreateRadial(
- PointToSkPoint(center_point),
- radius,
- colors,
- positions,
- position_count,
- TileModeToSkShaderTileMode(tile_mode));
- return new SkiaShader(shader);
-}
-
-Brush* CanvasSkia::CreateBitmapBrush(
- const SkBitmap& bitmap,
- TileMode tile_mode_x,
- TileMode tile_mode_y) {
- SkShader* shader = SkShader::CreateBitmapShader(
- bitmap,
- TileModeToSkShaderTileMode(tile_mode_x),
- TileModeToSkShaderTileMode(tile_mode_y));
- return new SkiaShader(shader);
-}
-
CanvasSkia* CanvasSkia::AsCanvasSkia() {
return this;
}
diff --git a/gfx/canvas_skia.h b/gfx/canvas_skia.h
index 71fbb42..457fa23 100644
--- a/gfx/canvas_skia.h
+++ b/gfx/canvas_skia.h
@@ -48,8 +48,10 @@ class CanvasSkia : public skia::PlatformCanvas,
// 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);
+ 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.
@@ -74,7 +76,8 @@ class CanvasSkia : public skia::PlatformCanvas,
const gfx::Font& font,
const SkColor& text_color,
const SkColor& halo_color,
- int x, int y, int w, int h, int flags);
+ int x, int y, int w, int h,
+ int flags);
#endif
// Extracts a bitmap from the contents of this canvas.
@@ -88,60 +91,49 @@ class CanvasSkia : public skia::PlatformCanvas,
virtual bool ClipRectInt(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 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 FillRectInt(const gfx::Brush* brush, 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,
+ 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 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,
+ 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,
+ 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,
+ 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,
+ 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,
+ virtual void TileImageInt(const SkBitmap& bitmap,
+ int src_x, int src_y,
int dest_x, int dest_y, int w, int h);
virtual gfx::NativeDrawingContext BeginPlatformPaint();
virtual void EndPlatformPaint();
- virtual Brush* CreateLinearGradientBrush(
- const gfx::Point& start_point,
- const gfx::Point& end_point,
- const SkColor colors[],
- const float positions[],
- size_t position_count,
- TileMode tile_mode);
- virtual Brush* CreateRadialGradientBrush(
- const gfx::Point& center_point,
- float radius,
- const SkColor colors[],
- const float positions[],
- size_t position_count,
- TileMode tile_mode);
- virtual Brush* CreateBitmapBrush(
- const SkBitmap& bitmap,
- TileMode tile_mode_x,
- TileMode tile_mode_y);
virtual CanvasSkia* AsCanvasSkia();
virtual const CanvasSkia* AsCanvasSkia() const;
@@ -153,8 +145,10 @@ class CanvasSkia : public skia::PlatformCanvas,
// 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,
+ void DrawStringInt(const std::wstring& text,
+ HFONT font,
+ const SkColor& color,
+ int x, int y, int w, int h,
int flags);
#endif
diff --git a/gfx/canvas_skia_linux.cc b/gfx/canvas_skia_linux.cc
index 1a22af5..6d675ad 100644
--- a/gfx/canvas_skia_linux.cc
+++ b/gfx/canvas_skia_linux.cc
@@ -176,7 +176,8 @@ static void SetupPangoLayout(PangoLayout* layout,
// static
void CanvasSkia::SizeStringInt(const std::wstring& text,
const gfx::Font& font,
- int* width, int* height, int flags) {
+ int* width, int* height,
+ int flags) {
int org_width = *width;
cairo_surface_t* surface =
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 0, 0);
diff --git a/gfx/canvas_skia_mac.mm b/gfx/canvas_skia_mac.mm
index e2cb553..f134eda 100644
--- a/gfx/canvas_skia_mac.mm
+++ b/gfx/canvas_skia_mac.mm
@@ -27,7 +27,8 @@ CanvasSkia::~CanvasSkia() {
// static
void CanvasSkia::SizeStringInt(const std::wstring& text,
const gfx::Font& font,
- int *width, int *height, int flags) {
+ int* width, int* height,
+ int flags) {
NSFont* native_font = font.GetNativeFont();
NSString* ns_string = base::SysWideToNSString(text);
NSDictionary* attributes =
@@ -38,8 +39,10 @@ void CanvasSkia::SizeStringInt(const std::wstring& text,
*height = font.GetHeight();
}
-void CanvasSkia::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,
int flags) {
if (!IntersectsClipRectInt(x, y, w, h))
return;
@@ -68,7 +71,8 @@ void CanvasSkia::DrawStringInt(const std::wstring& text, const gfx::Font& font,
[[[NSAttributedString alloc] initWithString:base::SysWideToNSString(text)
attributes:attributes] autorelease];
scoped_cftyperef<CTFramesetterRef> framesetter(
- CTFramesetterCreateWithAttributedString(reinterpret_cast<CFAttributedStringRef>(ns_string)));
+ CTFramesetterCreateWithAttributedString(
+ reinterpret_cast<CFAttributedStringRef>(ns_string)));
CGRect text_bounds = CGRectMake(x, y, w, h);
CGMutablePathRef path = CGPathCreateMutable();
diff --git a/gfx/canvas_skia_win.cc b/gfx/canvas_skia_win.cc
index cc8a7eb..46fe2c6 100644
--- a/gfx/canvas_skia_win.cc
+++ b/gfx/canvas_skia_win.cc
@@ -15,8 +15,10 @@ namespace {
// We make sure that LTR text we draw in an RTL context is modified
// appropriately to make sure it maintains it LTR orientation.
-void DoDrawText(HDC hdc, const std::wstring& text,
- RECT* text_bounds, int flags) {
+void DoDrawText(HDC hdc,
+ const std::wstring& text,
+ RECT* text_bounds,
+ int flags) {
std::wstring localized_text;
const wchar_t* string_ptr = text.c_str();
int string_size = static_cast<int>(text.length());
@@ -138,7 +140,8 @@ CanvasSkia::~CanvasSkia() {
// static
void CanvasSkia::SizeStringInt(const std::wstring& text,
const gfx::Font& font,
- int* width, int* height, int flags) {
+ 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,8 +176,10 @@ void CanvasSkia::SizeStringInt(const std::wstring& text,
*height = r.bottom;
}
-void CanvasSkia::DrawStringInt(const std::wstring& text, HFONT font,
- const SkColor& color, int x, int y, int w, int h,
+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;
@@ -211,7 +216,8 @@ void CanvasSkia::DrawStringInt(const std::wstring& text, HFONT font,
void CanvasSkia::DrawStringInt(const std::wstring& text,
const gfx::Font& font,
const SkColor& color,
- int x, int y, int w, int h, int flags) {
+ int x, int y, int w, int h,
+ int flags) {
DrawStringInt(text, font.GetNativeFont(), color, x, y, w, h, flags);
}
@@ -287,7 +293,7 @@ void CanvasSkia::DrawStringWithHalo(const std::wstring& text,
}
// Draw the halo bitmap with blur.
- drawBitmap(text_bitmap, SkIntToScalar(x - 1), SkIntToScalar(y - 1));
+ DrawBitmapInt(text_bitmap, x - 1, y - 1);
}
} // namespace gfx