Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(497)

Unified Diff: ui/base/cursor/cursor_util.cc

Issue 543823002: ozone: Plumb animated cursors from CursorLoaderOzone to CursorFactoryOzone (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: s/0/0U/ Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/base/cursor/cursor_util.h ('k') | ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/cursor/cursor_util.cc
diff --git a/ui/base/cursor/cursor_util.cc b/ui/base/cursor/cursor_util.cc
index a17d94479596a0af88c83c77c867f9f6f94406ab..bddb1bcaabf456d0b0ad5d34aeacbb084f2278ac 100644
--- a/ui/base/cursor/cursor_util.cc
+++ b/ui/base/cursor/cursor_util.cc
@@ -6,6 +6,8 @@
#include "base/logging.h"
#include "skia/ext/image_operations.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/point_conversions.h"
#include "ui/gfx/size_conversions.h"
#include "ui/gfx/skbitmap_operations.h"
@@ -57,4 +59,52 @@ void ScaleAndRotateCursorBitmapAndHotpoint(float scale,
*hotpoint = gfx::ToFlooredPoint(gfx::ScalePoint(*hotpoint, scale));
}
+void GetImageCursorBitmap(int resource_id,
+ float scale,
+ gfx::Display::Rotation rotation,
+ gfx::Point* hotspot,
+ SkBitmap* bitmap) {
+ const gfx::ImageSkia* image =
+ ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
+ const gfx::ImageSkiaRep& image_rep = image->GetRepresentation(scale);
+ // TODO(oshima): The cursor should use resource scale factor when
+ // fractional scale factor is enabled. crbug.com/372212
+ (*bitmap) = image_rep.sk_bitmap();
+ ScaleAndRotateCursorBitmapAndHotpoint(
+ scale / image_rep.scale(), rotation, bitmap, hotspot);
+ // |image_rep| is owned by the resource bundle. So we do not need to free it.
+}
+
+void GetAnimatedCursorBitmaps(int resource_id,
+ float scale,
+ gfx::Display::Rotation rotation,
+ gfx::Point* hotspot,
+ std::vector<SkBitmap>* bitmaps) {
+ // TODO(oshima|tdanderson): Support rotation and fractional scale factor.
+ 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);
+
+ bitmaps->resize(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(
+ bitmap, x_offset, 0, frame_width, frame_height);
+ DCHECK_EQ(frame_width, cropped.width());
+ DCHECK_EQ(frame_height, cropped.height());
+
+ (*bitmaps)[frame] = cropped;
+ }
+}
+
} // namespace ui
« no previous file with comments | « ui/base/cursor/cursor_util.h ('k') | ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698