OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/base/cursor/cursor_util.h" | 5 #include "ui/base/cursor/cursor_util.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "skia/ext/image_operations.h" | 8 #include "skia/ext/image_operations.h" |
| 9 #include "ui/base/resource/resource_bundle.h" |
| 10 #include "ui/gfx/image/image_skia.h" |
9 #include "ui/gfx/point_conversions.h" | 11 #include "ui/gfx/point_conversions.h" |
10 #include "ui/gfx/size_conversions.h" | 12 #include "ui/gfx/size_conversions.h" |
11 #include "ui/gfx/skbitmap_operations.h" | 13 #include "ui/gfx/skbitmap_operations.h" |
12 #include "ui/gfx/skia_util.h" | 14 #include "ui/gfx/skia_util.h" |
13 | 15 |
14 namespace ui { | 16 namespace ui { |
15 | 17 |
16 void ScaleAndRotateCursorBitmapAndHotpoint(float scale, | 18 void ScaleAndRotateCursorBitmapAndHotpoint(float scale, |
17 gfx::Display::Rotation rotation, | 19 gfx::Display::Rotation rotation, |
18 SkBitmap* bitmap, | 20 SkBitmap* bitmap, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 gfx::ScaleSize(gfx::Size(bitmap->width(), bitmap->height()), scale)); | 52 gfx::ScaleSize(gfx::Size(bitmap->width(), bitmap->height()), scale)); |
51 | 53 |
52 *bitmap = skia::ImageOperations::Resize( | 54 *bitmap = skia::ImageOperations::Resize( |
53 *bitmap, | 55 *bitmap, |
54 skia::ImageOperations::RESIZE_BETTER, | 56 skia::ImageOperations::RESIZE_BETTER, |
55 scaled_size.width(), | 57 scaled_size.width(), |
56 scaled_size.height()); | 58 scaled_size.height()); |
57 *hotpoint = gfx::ToFlooredPoint(gfx::ScalePoint(*hotpoint, scale)); | 59 *hotpoint = gfx::ToFlooredPoint(gfx::ScalePoint(*hotpoint, scale)); |
58 } | 60 } |
59 | 61 |
| 62 void GetImageCursorBitmap(int resource_id, |
| 63 float scale, |
| 64 gfx::Display::Rotation rotation, |
| 65 gfx::Point* hotspot, |
| 66 SkBitmap* bitmap) { |
| 67 const gfx::ImageSkia* image = |
| 68 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); |
| 69 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale); |
| 70 // TODO(oshima): The cursor should use resource scale factor when |
| 71 // fractional scale factor is enabled. crbug.com/372212 |
| 72 (*bitmap) = image_rep.sk_bitmap(); |
| 73 ScaleAndRotateCursorBitmapAndHotpoint( |
| 74 scale / image_rep.scale(), rotation, bitmap, hotspot); |
| 75 // |image_rep| is owned by the resource bundle. So we do not need to free it. |
| 76 } |
| 77 |
| 78 void GetAnimatedCursorBitmaps(int resource_id, |
| 79 float scale, |
| 80 gfx::Display::Rotation rotation, |
| 81 gfx::Point* hotspot, |
| 82 std::vector<SkBitmap>* bitmaps) { |
| 83 // TODO(oshima|tdanderson): Support rotation and fractional scale factor. |
| 84 const gfx::ImageSkia* image = |
| 85 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); |
| 86 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale); |
| 87 SkBitmap bitmap = image_rep.sk_bitmap(); |
| 88 int frame_width = bitmap.height(); |
| 89 int frame_height = frame_width; |
| 90 int total_width = bitmap.width(); |
| 91 DCHECK_EQ(total_width % frame_width, 0); |
| 92 int frame_count = total_width / frame_width; |
| 93 DCHECK_GT(frame_count, 0); |
| 94 |
| 95 bitmaps->resize(frame_count); |
| 96 |
| 97 for (int frame = 0; frame < frame_count; ++frame) { |
| 98 int x_offset = frame_width * frame; |
| 99 DCHECK_LE(x_offset + frame_width, total_width); |
| 100 |
| 101 SkBitmap cropped = SkBitmapOperations::CreateTiledBitmap( |
| 102 bitmap, x_offset, 0, frame_width, frame_height); |
| 103 DCHECK_EQ(frame_width, cropped.width()); |
| 104 DCHECK_EQ(frame_height, cropped.height()); |
| 105 |
| 106 (*bitmaps)[frame] = cropped; |
| 107 } |
| 108 } |
| 109 |
60 } // namespace ui | 110 } // namespace ui |
OLD | NEW |