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

Side by Side Diff: ui/base/cursor/cursor_loader_ozone.cc

Issue 2978833002: Making CursorFactoryOzone thread-local (Closed)
Patch Set: Created 3 years, 5 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 unified diff | Download patch
« no previous file with comments | « ui/base/cursor/cursor_loader_ozone.h ('k') | ui/base/cursor/image_cursors.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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> 7 #include <vector>
8 8
9 #include "ui/base/cursor/cursor.h" 9 #include "ui/base/cursor/cursor.h"
10 #include "ui/base/cursor/cursor_util.h" 10 #include "ui/base/cursor/cursor_util.h"
11 #include "ui/ozone/public/cursor_factory_ozone.h" 11 #include "ui/ozone/public/cursor_factory_ozone.h"
12 12
13 namespace ui { 13 namespace ui {
14 14
15 CursorLoaderOzone::CursorLoaderOzone() {} 15 CursorLoaderOzone::CursorLoaderOzone() {
16 factory_ = CursorFactoryOzone::GetInstance();
17 }
16 18
17 CursorLoaderOzone::~CursorLoaderOzone() {} 19 CursorLoaderOzone::~CursorLoaderOzone() {}
18 20
19 void CursorLoaderOzone::LoadImageCursor(CursorType id, 21 void CursorLoaderOzone::LoadImageCursor(CursorType id,
20 int resource_id, 22 int resource_id,
21 const gfx::Point& hot) { 23 const gfx::Point& hot) {
22 SkBitmap bitmap; 24 SkBitmap bitmap;
23 gfx::Point hotspot = hot; 25 gfx::Point hotspot = hot;
24 26
25 GetImageCursorBitmap(resource_id, scale(), rotation(), &hotspot, &bitmap); 27 GetImageCursorBitmap(resource_id, scale(), rotation(), &hotspot, &bitmap);
26 28
27 cursors_[id] = CursorFactoryOzone::GetInstance()->CreateImageCursor( 29 cursors_[id] = factory_->CreateImageCursor(bitmap, hotspot, scale());
28 bitmap, hotspot, scale());
29 } 30 }
30 31
31 void CursorLoaderOzone::LoadAnimatedCursor(CursorType id, 32 void CursorLoaderOzone::LoadAnimatedCursor(CursorType id,
32 int resource_id, 33 int resource_id,
33 const gfx::Point& hot, 34 const gfx::Point& hot,
34 int frame_delay_ms) { 35 int frame_delay_ms) {
35 std::vector<SkBitmap> bitmaps; 36 std::vector<SkBitmap> bitmaps;
36 gfx::Point hotspot = hot; 37 gfx::Point hotspot = hot;
37 38
38 GetAnimatedCursorBitmaps( 39 GetAnimatedCursorBitmaps(
39 resource_id, scale(), rotation(), &hotspot, &bitmaps); 40 resource_id, scale(), rotation(), &hotspot, &bitmaps);
40 41
41 cursors_[id] = CursorFactoryOzone::GetInstance()->CreateAnimatedCursor( 42 cursors_[id] =
42 bitmaps, hotspot, frame_delay_ms, scale()); 43 factory_->CreateAnimatedCursor(bitmaps, hotspot, frame_delay_ms, scale());
43 } 44 }
44 45
45 void CursorLoaderOzone::UnloadAll() { 46 void CursorLoaderOzone::UnloadAll() {
46 for (ImageCursorMap::const_iterator it = cursors_.begin(); 47 for (ImageCursorMap::const_iterator it = cursors_.begin();
47 it != cursors_.end(); 48 it != cursors_.end(); ++it) {
48 ++it) 49 factory_->UnrefImageCursor(it->second);
49 CursorFactoryOzone::GetInstance()->UnrefImageCursor(it->second); 50 }
50 cursors_.clear(); 51 cursors_.clear();
51 } 52 }
52 53
53 void CursorLoaderOzone::SetPlatformCursor(gfx::NativeCursor* cursor) { 54 void CursorLoaderOzone::SetPlatformCursor(gfx::NativeCursor* cursor) {
54 CursorType native_type = cursor->native_type(); 55 CursorType native_type = cursor->native_type();
55 PlatformCursor platform; 56 PlatformCursor platform;
56 57
57 if (cursors_.count(native_type)) { 58 if (cursors_.count(native_type)) {
58 // An image cursor is loaded for this type. 59 // An image cursor is loaded for this type.
59 platform = cursors_[native_type]; 60 platform = cursors_[native_type];
60 } else if (native_type == CursorType::kCustom) { 61 } else if (native_type == CursorType::kCustom) {
61 // The platform cursor was already set via WebCursor::GetPlatformCursor. 62 // The platform cursor was already set via WebCursor::GetPlatformCursor.
62 platform = cursor->platform(); 63 platform = cursor->platform();
63 } else { 64 } else {
64 // Use default cursor of this type. 65 // Use default cursor of this type.
65 platform = CursorFactoryOzone::GetInstance()->GetDefaultCursor(native_type); 66 platform = factory_->GetDefaultCursor(native_type);
66 } 67 }
67 68
68 cursor->SetPlatformCursor(platform); 69 cursor->SetPlatformCursor(platform);
69 } 70 }
70 71
71 CursorLoader* CursorLoader::Create() { 72 CursorLoader* CursorLoader::Create() {
72 return new CursorLoaderOzone(); 73 return new CursorLoaderOzone();
73 } 74 }
74 75
75 } // namespace ui 76 } // namespace ui
OLDNEW
« no previous file with comments | « ui/base/cursor/cursor_loader_ozone.h ('k') | ui/base/cursor/image_cursors.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698