Commit b0f88f7c authored by spang's avatar spang Committed by Commit bot

ozone: Handle default cursors with no bitmap in BitmapCursorFactoryOzone

Looks like there's fewer bitmaps than cursor types. On CrOS X11 we
fallback to left pointer, so do the same here.

BUG=410870
TEST=manual on link_freon
NOTRY=true

Review URL: https://codereview.chromium.org/540103002

Cr-Commit-Position: refs/heads/master@{#293333}
parent e19f20f7
...@@ -20,6 +20,14 @@ PlatformCursor ToPlatformCursor(BitmapCursorOzone* cursor) { ...@@ -20,6 +20,14 @@ PlatformCursor ToPlatformCursor(BitmapCursorOzone* cursor) {
return static_cast<PlatformCursor>(cursor); return static_cast<PlatformCursor>(cursor);
} }
scoped_refptr<BitmapCursorOzone> CreateDefaultBitmapCursor(int type) {
SkBitmap bitmap;
gfx::Point hotspot;
if (GetCursorBitmap(type, &bitmap, &hotspot))
return new BitmapCursorOzone(bitmap, hotspot);
return NULL;
}
} // namespace } // namespace
BitmapCursorFactoryOzone::BitmapCursorFactoryOzone() {} BitmapCursorFactoryOzone::BitmapCursorFactoryOzone() {}
...@@ -33,19 +41,7 @@ scoped_refptr<BitmapCursorOzone> BitmapCursorFactoryOzone::GetBitmapCursor( ...@@ -33,19 +41,7 @@ scoped_refptr<BitmapCursorOzone> BitmapCursorFactoryOzone::GetBitmapCursor(
} }
PlatformCursor BitmapCursorFactoryOzone::GetDefaultCursor(int type) { PlatformCursor BitmapCursorFactoryOzone::GetDefaultCursor(int type) {
if (type == kCursorNone) return GetDefaultCursorInternal(type);
return NULL; // NULL is used for hidden cursor.
if (!default_cursors_.count(type)) {
// Create new owned image cursor from default aura bitmap for this type.
SkBitmap bitmap;
gfx::Point hotspot;
CHECK(GetCursorBitmap(type, &bitmap, &hotspot));
default_cursors_[type] = new BitmapCursorOzone(bitmap, hotspot);
}
// Returned owned default cursor for this type.
return default_cursors_[type];
} }
PlatformCursor BitmapCursorFactoryOzone::CreateImageCursor( PlatformCursor BitmapCursorFactoryOzone::CreateImageCursor(
...@@ -64,4 +60,23 @@ void BitmapCursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) { ...@@ -64,4 +60,23 @@ void BitmapCursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) {
ToBitmapCursorOzone(cursor)->Release(); ToBitmapCursorOzone(cursor)->Release();
} }
scoped_refptr<BitmapCursorOzone>
BitmapCursorFactoryOzone::GetDefaultCursorInternal(int type) {
if (type == kCursorNone)
return NULL; // NULL is used for hidden cursor.
if (!default_cursors_.count(type)) {
// Create new image cursor from default aura bitmap for this type. We hold a
// ref forever because clients do not do refcounting for default cursors.
scoped_refptr<BitmapCursorOzone> cursor = CreateDefaultBitmapCursor(type);
if (!cursor && type != kCursorPointer)
cursor = GetDefaultCursorInternal(kCursorPointer);
DCHECK(cursor) << "Failed to load default cursor bitmap";
default_cursors_[type] = cursor;
}
// Returned owned default cursor for this type.
return default_cursors_[type];
}
} // namespace ui } // namespace ui
...@@ -60,6 +60,9 @@ class UI_BASE_EXPORT BitmapCursorFactoryOzone : public CursorFactoryOzone { ...@@ -60,6 +60,9 @@ class UI_BASE_EXPORT BitmapCursorFactoryOzone : public CursorFactoryOzone {
virtual void UnrefImageCursor(PlatformCursor cursor) OVERRIDE; virtual void UnrefImageCursor(PlatformCursor cursor) OVERRIDE;
private: private:
// Get cached BitmapCursorOzone for a default cursor.
scoped_refptr<BitmapCursorOzone> GetDefaultCursorInternal(int type);
// Default cursors are cached & owned by the factory. // Default cursors are cached & owned by the factory.
typedef std::map<int, scoped_refptr<BitmapCursorOzone> > DefaultCursorMap; typedef std::map<int, scoped_refptr<BitmapCursorOzone> > DefaultCursorMap;
DefaultCursorMap default_cursors_; DefaultCursorMap default_cursors_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment