Chromium Code Reviews| Index: ui/base/cursor/cursor_loader_ozone.cc |
| diff --git a/ui/base/cursor/cursor_loader_ozone.cc b/ui/base/cursor/cursor_loader_ozone.cc |
| index 8309c2e4b2afc8e8e38cac4e5cd3eb249a8f37ff..7d1e1d279efa301a690758bae3b880feee79f090 100644 |
| --- a/ui/base/cursor/cursor_loader_ozone.cc |
| +++ b/ui/base/cursor/cursor_loader_ozone.cc |
| @@ -4,9 +4,12 @@ |
| #include "ui/base/cursor/cursor_loader_ozone.h" |
| +#include <vector> |
| + |
| #include "ui/base/cursor/cursor.h" |
| #include "ui/base/resource/resource_bundle.h" |
| #include "ui/gfx/image/image_skia.h" |
| +#include "ui/gfx/skbitmap_operations.h" |
| #include "ui/ozone/public/cursor_factory_ozone.h" |
| namespace ui { |
| @@ -31,8 +34,33 @@ void CursorLoaderOzone::LoadAnimatedCursor(int id, |
| int resource_id, |
| const gfx::Point& hot, |
| int frame_delay_ms) { |
| - // TODO(dnicoara) Add support: crbug.com/343245 |
| - NOTIMPLEMENTED(); |
| + const gfx::ImageSkia* image = |
| + ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); |
| + const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale()); |
| + SkBitmap bitmap = image_rep.sk_bitmap(); |
| + int frame_width = bitmap.height(); |
| + int frame_height = frame_width; |
| + int total_width = bitmap.width(); |
| + DCHECK_EQ(total_width % frame_width, 0); |
| + int frame_count = total_width / frame_width; |
| + DCHECK_GT(frame_count, 0); |
| + |
| + std::vector<SkBitmap> bitmaps(frame_count); |
| + |
| + for (int frame = 0; frame < frame_count; ++frame) { |
| + int x_offset = frame_width * frame; |
| + DCHECK_LE(x_offset + frame_width, total_width); |
| + |
| + SkBitmap cropped = SkBitmapOperations::CreateTiledBitmap( |
|
sky
2014/09/04 21:23:12
Please refactor this as it looks to be exactly the
spang
2014/09/05 16:26:26
Done.
|
| + bitmap, x_offset, 0, frame_width, frame_height); |
| + DCHECK_EQ(frame_width, cropped.width()); |
| + DCHECK_EQ(frame_height, cropped.height()); |
| + |
| + bitmaps[frame] = cropped; |
| + } |
| + |
| + cursors_[id] = CursorFactoryOzone::GetInstance()->CreateAnimatedCursor( |
| + bitmaps, hot, frame_delay_ms); |
| } |
| void CursorLoaderOzone::UnloadAll() { |