Chromium Code Reviews| 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_loader_ozone.h" | 5 #include "ui/base/cursor/cursor_loader_ozone.h" |
| 6 | 6 |
| 7 #include <vector> | |
| 8 | |
| 7 #include "ui/base/cursor/cursor.h" | 9 #include "ui/base/cursor/cursor.h" |
| 8 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| 9 #include "ui/gfx/image/image_skia.h" | 11 #include "ui/gfx/image/image_skia.h" |
| 12 #include "ui/gfx/skbitmap_operations.h" | |
| 10 #include "ui/ozone/public/cursor_factory_ozone.h" | 13 #include "ui/ozone/public/cursor_factory_ozone.h" |
| 11 | 14 |
| 12 namespace ui { | 15 namespace ui { |
| 13 | 16 |
| 14 CursorLoaderOzone::CursorLoaderOzone() {} | 17 CursorLoaderOzone::CursorLoaderOzone() {} |
| 15 | 18 |
| 16 CursorLoaderOzone::~CursorLoaderOzone() {} | 19 CursorLoaderOzone::~CursorLoaderOzone() {} |
| 17 | 20 |
| 18 void CursorLoaderOzone::LoadImageCursor(int id, | 21 void CursorLoaderOzone::LoadImageCursor(int id, |
| 19 int resource_id, | 22 int resource_id, |
| 20 const gfx::Point& hot) { | 23 const gfx::Point& hot) { |
| 21 const gfx::ImageSkia* image = | 24 const gfx::ImageSkia* image = |
| 22 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); | 25 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); |
| 23 const gfx::ImageSkiaRep& image_rep = | 26 const gfx::ImageSkiaRep& image_rep = |
| 24 image->GetRepresentation(scale()); | 27 image->GetRepresentation(scale()); |
| 25 SkBitmap bitmap = image_rep.sk_bitmap(); | 28 SkBitmap bitmap = image_rep.sk_bitmap(); |
| 26 cursors_[id] = | 29 cursors_[id] = |
| 27 CursorFactoryOzone::GetInstance()->CreateImageCursor(bitmap, hot); | 30 CursorFactoryOzone::GetInstance()->CreateImageCursor(bitmap, hot); |
| 28 } | 31 } |
| 29 | 32 |
| 30 void CursorLoaderOzone::LoadAnimatedCursor(int id, | 33 void CursorLoaderOzone::LoadAnimatedCursor(int id, |
| 31 int resource_id, | 34 int resource_id, |
| 32 const gfx::Point& hot, | 35 const gfx::Point& hot, |
| 33 int frame_delay_ms) { | 36 int frame_delay_ms) { |
| 34 // TODO(dnicoara) Add support: crbug.com/343245 | 37 const gfx::ImageSkia* image = |
| 35 NOTIMPLEMENTED(); | 38 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); |
| 39 const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale()); | |
| 40 SkBitmap bitmap = image_rep.sk_bitmap(); | |
| 41 int frame_width = bitmap.height(); | |
| 42 int frame_height = frame_width; | |
| 43 int total_width = bitmap.width(); | |
| 44 DCHECK_EQ(total_width % frame_width, 0); | |
| 45 int frame_count = total_width / frame_width; | |
| 46 DCHECK_GT(frame_count, 0); | |
| 47 | |
| 48 std::vector<SkBitmap> bitmaps(frame_count); | |
| 49 | |
| 50 for (int frame = 0; frame < frame_count; ++frame) { | |
| 51 int x_offset = frame_width * frame; | |
| 52 DCHECK_LE(x_offset + frame_width, total_width); | |
| 53 | |
| 54 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.
| |
| 55 bitmap, x_offset, 0, frame_width, frame_height); | |
| 56 DCHECK_EQ(frame_width, cropped.width()); | |
| 57 DCHECK_EQ(frame_height, cropped.height()); | |
| 58 | |
| 59 bitmaps[frame] = cropped; | |
| 60 } | |
| 61 | |
| 62 cursors_[id] = CursorFactoryOzone::GetInstance()->CreateAnimatedCursor( | |
| 63 bitmaps, hot, frame_delay_ms); | |
| 36 } | 64 } |
| 37 | 65 |
| 38 void CursorLoaderOzone::UnloadAll() { | 66 void CursorLoaderOzone::UnloadAll() { |
| 39 for (ImageCursorMap::const_iterator it = cursors_.begin(); | 67 for (ImageCursorMap::const_iterator it = cursors_.begin(); |
| 40 it != cursors_.end(); | 68 it != cursors_.end(); |
| 41 ++it) | 69 ++it) |
| 42 CursorFactoryOzone::GetInstance()->UnrefImageCursor(it->second); | 70 CursorFactoryOzone::GetInstance()->UnrefImageCursor(it->second); |
| 43 cursors_.clear(); | 71 cursors_.clear(); |
| 44 } | 72 } |
| 45 | 73 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 59 } | 87 } |
| 60 | 88 |
| 61 cursor->SetPlatformCursor(platform); | 89 cursor->SetPlatformCursor(platform); |
| 62 } | 90 } |
| 63 | 91 |
| 64 CursorLoader* CursorLoader::Create() { | 92 CursorLoader* CursorLoader::Create() { |
| 65 return new CursorLoaderOzone(); | 93 return new CursorLoaderOzone(); |
| 66 } | 94 } |
| 67 | 95 |
| 68 } // namespace ui | 96 } // namespace ui |
| OLD | NEW |