diff options
author | pkasting <pkasting@chromium.org> | 2015-11-03 13:00:21 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-03 21:02:43 +0000 |
commit | 07f4446e9c55882cd3281e1af8cde68339095ff2 (patch) | |
tree | 8c09502a9c09e33b4b55179b5dd76f3c89608ee0 | |
parent | 8e087947c7bf6f4d235d672b0d1ad35f5aeafe8d (diff) | |
download | chromium_src-07f4446e9c55882cd3281e1af8cde68339095ff2.zip chromium_src-07f4446e9c55882cd3281e1af8cde68339095ff2.tar.gz chromium_src-07f4446e9c55882cd3281e1af8cde68339095ff2.tar.bz2 |
Add PointToSkPoint() and friends.
These are useful in a few places today and will be useful in some tabstrip code
I'm writing.
BUG=none
TEST=none
Review URL: https://codereview.chromium.org/1431563004
Cr-Commit-Position: refs/heads/master@{#357621}
-rw-r--r-- | ash/wm/gestures/long_press_affordance_handler.cc | 3 | ||||
-rw-r--r-- | content/renderer/pepper/pepper_graphics_2d_host.cc | 9 | ||||
-rw-r--r-- | ui/gfx/render_text.cc | 6 | ||||
-rw-r--r-- | ui/gfx/skia_util.cc | 26 | ||||
-rw-r--r-- | ui/gfx/skia_util.h | 7 | ||||
-rw-r--r-- | ui/native_theme/native_theme_base.cc | 5 |
6 files changed, 33 insertions, 23 deletions
diff --git a/ash/wm/gestures/long_press_affordance_handler.cc b/ash/wm/gestures/long_press_affordance_handler.cc index 692510f..eafa30d 100644 --- a/ash/wm/gestures/long_press_affordance_handler.cc +++ b/ash/wm/gestures/long_press_affordance_handler.cc @@ -100,10 +100,9 @@ void PaintAffordanceGlow(gfx::Canvas* canvas, SkColor* colors, SkScalar* pos, int num_colors) { - SkPoint sk_center; int radius = (end_radius + start_radius) / 2; int glow_width = end_radius - start_radius; - sk_center.iset(center.x(), center.y()); + SkPoint sk_center(PointToSkPoint(center)); skia::RefPtr<SkShader> shader = skia::AdoptRef(SkGradientShader::CreateTwoPointConical( sk_center, SkIntToScalar(start_radius), sk_center, diff --git a/content/renderer/pepper/pepper_graphics_2d_host.cc b/content/renderer/pepper/pepper_graphics_2d_host.cc index 018cc67..efa3bc1 100644 --- a/content/renderer/pepper/pepper_graphics_2d_host.cc +++ b/content/renderer/pepper/pepper_graphics_2d_host.cc @@ -371,15 +371,10 @@ void PepperGraphics2DHost::Paint(blink::WebCanvas* canvas, paint.setXfermodeMode(SkXfermode::kSrc_Mode); } - SkPoint origin; - origin.set(SkIntToScalar(plugin_rect.x()), SkIntToScalar(plugin_rect.y())); - - SkPoint pixel_origin = origin; - + SkPoint pixel_origin(PointToSkPoint(plugin_rect.origin())); if (scale_ != 1.0f && scale_ > 0.0f) { canvas->scale(scale_, scale_); - pixel_origin.set(pixel_origin.x() * (1.0f / scale_), - pixel_origin.y() * (1.0f / scale_)); + pixel_origin.scale(1.0f / scale_); } canvas->drawBitmap(image, pixel_origin.x(), pixel_origin.y(), &paint); } diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc index 778cdd0..27c9e5a 100644 --- a/ui/gfx/render_text.cc +++ b/ui/gfx/render_text.cc @@ -153,10 +153,8 @@ skia::RefPtr<SkShader> CreateFadeShader(const Rect& text_rect, colors.push_back(colors.back()); } - SkPoint points[2]; - points[0].iset(text_rect.x(), text_rect.y()); - points[1].iset(text_rect.right(), text_rect.y()); - + const SkPoint points[2] = { PointToSkPoint(text_rect.origin()), + PointToSkPoint(text_rect.top_right()) }; return skia::AdoptRef( SkGradientShader::CreateLinear(&points[0], &colors[0], &positions[0], colors.size(), SkShader::kClamp_TileMode)); diff --git a/ui/gfx/skia_util.cc b/ui/gfx/skia_util.cc index 696dea3..d3a1ac8 100644 --- a/ui/gfx/skia_util.cc +++ b/ui/gfx/skia_util.cc @@ -20,10 +20,22 @@ namespace gfx { +SkPoint PointToSkPoint(const Point& point) { + return SkPoint::Make(SkIntToScalar(point.x()), SkIntToScalar(point.y())); +} + +SkIPoint PointToSkIPoint(const Point& point) { + return SkIPoint::Make(point.x(), point.y()); +} + +SkPoint PointFToSkPoint(const PointF& point) { + return SkPoint::Make(SkFloatToScalar(point.x()), SkFloatToScalar(point.y())); +} + SkRect RectToSkRect(const Rect& rect) { - SkRect r; - r.iset(rect.x(), rect.y(), rect.right(), rect.bottom()); - return r; + return SkRect::MakeXYWH( + SkIntToScalar(rect.x()), SkIntToScalar(rect.y()), + SkIntToScalar(rect.width()), SkIntToScalar(rect.height())); } SkIRect RectToSkIRect(const Rect& rect) { @@ -205,10 +217,10 @@ void ConvertSkiaToRGBA(const unsigned char* skia, } void QuadFToSkPoints(const gfx::QuadF& quad, SkPoint points[4]) { - points[0] = SkPoint::Make(quad.p1().x(), quad.p1().y()); - points[1] = SkPoint::Make(quad.p2().x(), quad.p2().y()); - points[2] = SkPoint::Make(quad.p3().x(), quad.p3().y()); - points[3] = SkPoint::Make(quad.p4().x(), quad.p4().y()); + points[0] = PointFToSkPoint(quad.p1()); + points[1] = PointFToSkPoint(quad.p2()); + points[2] = PointFToSkPoint(quad.p3()); + points[3] = PointFToSkPoint(quad.p4()); } } // namespace gfx diff --git a/ui/gfx/skia_util.h b/ui/gfx/skia_util.h index c550203..25c96d0 100644 --- a/ui/gfx/skia_util.h +++ b/ui/gfx/skia_util.h @@ -22,12 +22,17 @@ class SkDrawLooper; namespace gfx { class ImageSkiaRep; +class Point; +class PointF; class Rect; class RectF; class ShadowValue; class Transform; -// Convert between Skia and gfx rect types. +// Convert between Skia and gfx types. +GFX_EXPORT SkPoint PointToSkPoint(const Point& point); +GFX_EXPORT SkIPoint PointToSkIPoint(const Point& point); +GFX_EXPORT SkPoint PointFToSkPoint(const PointF& point); GFX_EXPORT SkRect RectToSkRect(const Rect& rect); GFX_EXPORT SkIRect RectToSkIRect(const Rect& rect); GFX_EXPORT Rect SkIRectToRect(const SkIRect& rect); diff --git a/ui/native_theme/native_theme_base.cc b/ui/native_theme/native_theme_base.cc index 18156a3..f709a09 100644 --- a/ui/native_theme/native_theme_base.cc +++ b/ui/native_theme/native_theme_base.cc @@ -705,8 +705,9 @@ void NativeThemeBase::PaintButton(SkCanvas* canvas, const int kLightEnd = state == kPressed ? 1 : 0; const int kDarkEnd = !kLightEnd; SkPoint gradient_bounds[2]; - gradient_bounds[kLightEnd].iset(rect.x(), rect.y()); - gradient_bounds[kDarkEnd].iset(rect.x(), kBottom - 1); + gradient_bounds[kLightEnd] = gfx::PointToSkPoint(rect.origin()); + gradient_bounds[kDarkEnd] = + gfx::PointToSkPoint(rect.bottom_left() - gfx::Vector2d(0, 1)); SkColor colors[2]; colors[0] = light_color; colors[1] = base_color; |