OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/native_theme/native_theme_base.h" | 5 #include "ui/native_theme/native_theme_base.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 986 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 SkIntToScalar(y + h)); | 997 SkIntToScalar(y + h)); |
998 } | 998 } |
999 | 999 |
1000 void NativeThemeBase::DrawImageInt( | 1000 void NativeThemeBase::DrawImageInt( |
1001 SkCanvas* sk_canvas, const gfx::ImageSkia& image, | 1001 SkCanvas* sk_canvas, const gfx::ImageSkia& image, |
1002 int src_x, int src_y, int src_w, int src_h, | 1002 int src_x, int src_y, int src_w, int src_h, |
1003 int dest_x, int dest_y, int dest_w, int dest_h) const { | 1003 int dest_x, int dest_y, int dest_w, int dest_h) const { |
1004 // TODO(pkotwicz): Do something better and don't infer device | 1004 // TODO(pkotwicz): Do something better and don't infer device |
1005 // scale factor from canvas scale. | 1005 // scale factor from canvas scale. |
1006 SkMatrix m = sk_canvas->getTotalMatrix(); | 1006 SkMatrix m = sk_canvas->getTotalMatrix(); |
1007 ui::ScaleFactor device_scale_factor = ui::GetScaleFactorFromScale( | 1007 float device_scale = static_cast<float>(SkScalarAbs(m.getScaleX())); |
1008 SkScalarAbs(m.getScaleX())); | |
1009 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling( | 1008 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling( |
1010 sk_canvas, device_scale_factor)); | 1009 sk_canvas, device_scale)); |
1011 canvas->DrawImageInt(image, src_x, src_y, src_w, src_h, | 1010 canvas->DrawImageInt(image, src_x, src_y, src_w, src_h, |
1012 dest_x, dest_y, dest_w, dest_h, true); | 1011 dest_x, dest_y, dest_w, dest_h, true); |
1013 } | 1012 } |
1014 | 1013 |
1015 void NativeThemeBase::DrawTiledImage(SkCanvas* sk_canvas, | 1014 void NativeThemeBase::DrawTiledImage(SkCanvas* sk_canvas, |
1016 const gfx::ImageSkia& image, | 1015 const gfx::ImageSkia& image, |
1017 int src_x, int src_y, float tile_scale_x, float tile_scale_y, | 1016 int src_x, int src_y, float tile_scale_x, float tile_scale_y, |
1018 int dest_x, int dest_y, int w, int h) const { | 1017 int dest_x, int dest_y, int w, int h) const { |
1019 // TODO(pkotwicz): Do something better and don't infer device | 1018 // TODO(pkotwicz): Do something better and don't infer device |
1020 // scale factor from canvas scale. | 1019 // scale factor from canvas scale. |
1021 SkMatrix m = sk_canvas->getTotalMatrix(); | 1020 SkMatrix m = sk_canvas->getTotalMatrix(); |
1022 ui::ScaleFactor device_scale_factor = ui::GetScaleFactorFromScale( | 1021 float device_scale = static_cast<float>(SkScalarAbs(m.getScaleX())); |
1023 SkScalarAbs(m.getScaleX())); | |
1024 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling( | 1022 scoped_ptr<gfx::Canvas> canvas(gfx::Canvas::CreateCanvasWithoutScaling( |
1025 sk_canvas, device_scale_factor)); | 1023 sk_canvas, device_scale)); |
1026 canvas->TileImageInt(image, src_x, src_y, tile_scale_x, | 1024 canvas->TileImageInt(image, src_x, src_y, tile_scale_x, |
1027 tile_scale_y, dest_x, dest_y, w, h); | 1025 tile_scale_y, dest_x, dest_y, w, h); |
1028 } | 1026 } |
1029 | 1027 |
1030 SkColor NativeThemeBase::SaturateAndBrighten(SkScalar* hsv, | 1028 SkColor NativeThemeBase::SaturateAndBrighten(SkScalar* hsv, |
1031 SkScalar saturate_amount, | 1029 SkScalar saturate_amount, |
1032 SkScalar brighten_amount) const { | 1030 SkScalar brighten_amount) const { |
1033 SkScalar color[3]; | 1031 SkScalar color[3]; |
1034 color[0] = hsv[0]; | 1032 color[0] = hsv[0]; |
1035 color[1] = Clamp(hsv[1] + saturate_amount, 0.0, 1.0); | 1033 color[1] = Clamp(hsv[1] + saturate_amount, 0.0, 1.0); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1105 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); | 1103 SkScalar min_diff = Clamp((hsv1[1] + hsv2[1]) * 1.2f, 0.28f, 0.5f); |
1106 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); | 1104 SkScalar diff = Clamp(fabs(hsv1[2] - hsv2[2]) / 2, min_diff, 0.5f); |
1107 | 1105 |
1108 if (hsv1[2] + hsv2[2] > 1.0) | 1106 if (hsv1[2] + hsv2[2] > 1.0) |
1109 diff = -diff; | 1107 diff = -diff; |
1110 | 1108 |
1111 return SaturateAndBrighten(hsv2, -0.2f, diff); | 1109 return SaturateAndBrighten(hsv2, -0.2f, diff); |
1112 } | 1110 } |
1113 | 1111 |
1114 } // namespace ui | 1112 } // namespace ui |
OLD | NEW |