| 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/ozone/bitmap_cursor_factory_ozone.h" | 5 #include "ui/base/cursor/ozone/bitmap_cursor_factory_ozone.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
| 9 #include "ui/base/cursor/cursors_aura.h" | 9 #include "ui/base/cursor/cursors_aura.h" |
| 10 | 10 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 BitmapCursorFactoryOzone::~BitmapCursorFactoryOzone() {} | 35 BitmapCursorFactoryOzone::~BitmapCursorFactoryOzone() {} |
| 36 | 36 |
| 37 // static | 37 // static |
| 38 scoped_refptr<BitmapCursorOzone> BitmapCursorFactoryOzone::GetBitmapCursor( | 38 scoped_refptr<BitmapCursorOzone> BitmapCursorFactoryOzone::GetBitmapCursor( |
| 39 PlatformCursor platform_cursor) { | 39 PlatformCursor platform_cursor) { |
| 40 return make_scoped_refptr(ToBitmapCursorOzone(platform_cursor)); | 40 return make_scoped_refptr(ToBitmapCursorOzone(platform_cursor)); |
| 41 } | 41 } |
| 42 | 42 |
| 43 PlatformCursor BitmapCursorFactoryOzone::GetDefaultCursor(int type) { | 43 PlatformCursor BitmapCursorFactoryOzone::GetDefaultCursor(int type) { |
| 44 return GetDefaultCursorInternal(type); | 44 return GetDefaultCursorInternal(type).get(); |
| 45 } | 45 } |
| 46 | 46 |
| 47 PlatformCursor BitmapCursorFactoryOzone::CreateImageCursor( | 47 PlatformCursor BitmapCursorFactoryOzone::CreateImageCursor( |
| 48 const SkBitmap& bitmap, | 48 const SkBitmap& bitmap, |
| 49 const gfx::Point& hotspot) { | 49 const gfx::Point& hotspot) { |
| 50 BitmapCursorOzone* cursor = new BitmapCursorOzone(bitmap, hotspot); | 50 BitmapCursorOzone* cursor = new BitmapCursorOzone(bitmap, hotspot); |
| 51 cursor->AddRef(); // Balanced by UnrefImageCursor. | 51 cursor->AddRef(); // Balanced by UnrefImageCursor. |
| 52 return ToPlatformCursor(cursor); | 52 return ToPlatformCursor(cursor); |
| 53 } | 53 } |
| 54 | 54 |
| 55 void BitmapCursorFactoryOzone::RefImageCursor(PlatformCursor cursor) { | 55 void BitmapCursorFactoryOzone::RefImageCursor(PlatformCursor cursor) { |
| 56 ToBitmapCursorOzone(cursor)->AddRef(); | 56 ToBitmapCursorOzone(cursor)->AddRef(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 void BitmapCursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) { | 59 void BitmapCursorFactoryOzone::UnrefImageCursor(PlatformCursor cursor) { |
| 60 ToBitmapCursorOzone(cursor)->Release(); | 60 ToBitmapCursorOzone(cursor)->Release(); |
| 61 } | 61 } |
| 62 | 62 |
| 63 scoped_refptr<BitmapCursorOzone> | 63 scoped_refptr<BitmapCursorOzone> |
| 64 BitmapCursorFactoryOzone::GetDefaultCursorInternal(int type) { | 64 BitmapCursorFactoryOzone::GetDefaultCursorInternal(int type) { |
| 65 if (type == kCursorNone) | 65 if (type == kCursorNone) |
| 66 return NULL; // NULL is used for hidden cursor. | 66 return NULL; // NULL is used for hidden cursor. |
| 67 | 67 |
| 68 if (!default_cursors_.count(type)) { | 68 if (!default_cursors_.count(type)) { |
| 69 // Create new image cursor from default aura bitmap for this type. We hold a | 69 // Create new image cursor from default aura bitmap for this type. We hold a |
| 70 // ref forever because clients do not do refcounting for default cursors. | 70 // ref forever because clients do not do refcounting for default cursors. |
| 71 scoped_refptr<BitmapCursorOzone> cursor = CreateDefaultBitmapCursor(type); | 71 scoped_refptr<BitmapCursorOzone> cursor = CreateDefaultBitmapCursor(type); |
| 72 if (!cursor && type != kCursorPointer) | 72 if (!cursor.get() && type != kCursorPointer) |
| 73 cursor = GetDefaultCursorInternal(kCursorPointer); | 73 cursor = GetDefaultCursorInternal(kCursorPointer); |
| 74 DCHECK(cursor) << "Failed to load default cursor bitmap"; | 74 DCHECK(cursor.get()) << "Failed to load default cursor bitmap"; |
| 75 default_cursors_[type] = cursor; | 75 default_cursors_[type] = cursor; |
| 76 } | 76 } |
| 77 | 77 |
| 78 // Returned owned default cursor for this type. | 78 // Returned owned default cursor for this type. |
| 79 return default_cursors_[type]; | 79 return default_cursors_[type]; |
| 80 } | 80 } |
| 81 | 81 |
| 82 } // namespace ui | 82 } // namespace ui |
| OLD | NEW |