Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/base/cursor/ozone/cursor_data_factory_ozone.h" | |
| 6 | |
| 7 #include "ui/base/cursor/cursor.h" | |
| 8 | |
| 9 namespace ui { | |
| 10 | |
| 11 namespace { | |
| 12 | |
| 13 // A magic value that we store at the start of an instance. | |
| 14 const uint32_t kCookie = 0xF60D214C; | |
| 15 | |
| 16 const uint32_t kBadCookie = 0xBADBADCC; | |
| 17 | |
| 18 CursorDataOzone* ToCursorDataOzone(PlatformCursor cursor) { | |
| 19 CursorDataOzone* ozone = static_cast<CursorDataOzone*>(cursor); | |
| 20 ozone->AssertIsACusrorDataOzone(); | |
|
sadrul
2017/04/18 17:04:59
Should the magic cookie/assertions be behind DCHEC
Elliot Glaysher
2017/04/18 20:11:58
Done.
| |
| 21 return ozone; | |
| 22 } | |
| 23 | |
| 24 PlatformCursor ToPlatformCursor(CursorDataOzone* cursor) { | |
| 25 return static_cast<PlatformCursor>(cursor); | |
| 26 } | |
| 27 | |
| 28 } // namespace | |
| 29 | |
| 30 CursorDataOzone::CursorDataOzone(const ui::CursorData& data) | |
| 31 : magic_cookie_(kCookie), data_(data) {} | |
| 32 | |
| 33 void CursorDataOzone::AssertIsACusrorDataOzone() { | |
| 34 CHECK_EQ(magic_cookie_, kCookie); | |
| 35 } | |
| 36 | |
| 37 CursorDataOzone::~CursorDataOzone() { | |
| 38 magic_cookie_ = kBadCookie; | |
| 39 } | |
| 40 | |
| 41 CursorDataFactoryOzone::CursorDataFactoryOzone() {} | |
| 42 | |
| 43 CursorDataFactoryOzone::~CursorDataFactoryOzone() {} | |
| 44 | |
| 45 // static | |
| 46 const ui::CursorData& CursorDataFactoryOzone::GetCursorData( | |
| 47 PlatformCursor platform_cursor) { | |
| 48 return ToCursorDataOzone(platform_cursor)->data(); | |
| 49 } | |
| 50 | |
| 51 PlatformCursor CursorDataFactoryOzone::GetDefaultCursor(int type) { | |
| 52 // Unlike BitmapCursorFactoryOzone, we aren't making heavyweight bitmaps, but | |
| 53 // we still have to cache these forever because objects that come out of the | |
| 54 // GetDefaultCursor() method aren't treated as refcounted by the ozone | |
| 55 // interfaces. | |
| 56 return GetDefaultCursorInternal(type).get(); | |
| 57 } | |
| 58 | |
| 59 PlatformCursor CursorDataFactoryOzone::CreateImageCursor( | |
| 60 const SkBitmap& bitmap, | |
| 61 const gfx::Point& hotspot, | |
| 62 float bitmap_dpi) { | |
| 63 CursorDataOzone* cursor = new CursorDataOzone( | |
| 64 ui::CursorData(hotspot, {bitmap}, bitmap_dpi, base::TimeDelta())); | |
| 65 cursor->AddRef(); // Balanced by UnrefImageCursor. | |
| 66 return ToPlatformCursor(cursor); | |
|
sadrul
2017/04/18 17:04:59
So this is essentially: make_scoped_refptr....rele
Elliot Glaysher
2017/04/18 20:11:58
Acknowledged.
| |
| 67 } | |
| 68 | |
| 69 PlatformCursor CursorDataFactoryOzone::CreateAnimatedCursor( | |
| 70 const std::vector<SkBitmap>& bitmaps, | |
| 71 const gfx::Point& hotspot, | |
| 72 int frame_delay_ms, | |
| 73 float bitmap_dpi) { | |
| 74 CursorDataOzone* cursor = new CursorDataOzone( | |
| 75 ui::CursorData(hotspot, bitmaps, bitmap_dpi, | |
| 76 base::TimeDelta::FromMilliseconds(frame_delay_ms))); | |
| 77 cursor->AddRef(); // Balanced by UnrefImageCursor. | |
| 78 return ToPlatformCursor(cursor); | |
| 79 } | |
| 80 | |
| 81 void CursorDataFactoryOzone::RefImageCursor(PlatformCursor cursor) { | |
| 82 ToCursorDataOzone(cursor)->AddRef(); | |
| 83 } | |
| 84 | |
| 85 void CursorDataFactoryOzone::UnrefImageCursor(PlatformCursor cursor) { | |
| 86 ToCursorDataOzone(cursor)->Release(); | |
| 87 } | |
| 88 | |
| 89 scoped_refptr<CursorDataOzone> CursorDataFactoryOzone::GetDefaultCursorInternal( | |
| 90 int type) { | |
| 91 if (type == kCursorNone) | |
| 92 return nullptr; // nullptr is used for hidden cursor. | |
| 93 | |
| 94 if (!default_cursors_.count(type)) { | |
| 95 // We hold a ref forever because clients do not do refcounting for default | |
| 96 // cursors. | |
| 97 scoped_refptr<CursorDataOzone> cursor = scoped_refptr<CursorDataOzone>( | |
|
sadrul
2017/04/18 17:04:59
make_scoped_refptr?
Elliot Glaysher
2017/04/18 20:11:58
Done.
| |
| 98 new CursorDataOzone(ui::CursorData(type))); | |
| 99 default_cursors_[type] = cursor; | |
|
sadrul
2017/04/18 17:04:59
std::move(cursor)
Elliot Glaysher
2017/04/18 20:11:57
Done.
| |
| 100 } | |
| 101 | |
| 102 // Returned owned default cursor for this type. | |
| 103 return default_cursors_[type]; | |
| 104 } | |
| 105 | |
| 106 } // namespace ui | |
| OLD | NEW |