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

Side by Side Diff: components/exo/pointer.cc

Issue 1705343002: Revert of exo: Default pointer surface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 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 | « components/exo/pointer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/exo/pointer.h" 5 #include "components/exo/pointer.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h" 8 #include "ash/shell_window_ids.h"
9 #include "components/exo/buffer.h"
10 #include "components/exo/pointer_delegate.h" 9 #include "components/exo/pointer_delegate.h"
11 #include "components/exo/surface.h" 10 #include "components/exo/surface.h"
12 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "ui/aura/env.h"
15 #include "ui/aura/window.h" 11 #include "ui/aura/window.h"
16 #include "ui/base/cursor/cursors_aura.h"
17 #include "ui/compositor/compositor.h"
18 #include "ui/events/event.h" 12 #include "ui/events/event.h"
19 #include "ui/views/widget/widget.h" 13 #include "ui/views/widget/widget.h"
20 14
21 namespace exo { 15 namespace exo {
22 namespace {
23
24 scoped_ptr<Buffer> CreateDefaultCursor(gfx::Point* hotspot) {
25 ui::Cursor cursor(ui::kCursorPointer);
26 cursor.set_device_scale_factor(1.0f);
27
28 SkBitmap bitmap;
29 if (!ui::GetCursorBitmap(cursor, &bitmap, hotspot)) {
30 LOG(ERROR) << "Failed to load default cursor bitmap";
31 return nullptr;
32 }
33
34 DCHECK_EQ(bitmap.colorType(), kBGRA_8888_SkColorType);
35 scoped_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer =
36 aura::Env::GetInstance()
37 ->context_factory()
38 ->GetGpuMemoryBufferManager()
39 ->AllocateGpuMemoryBuffer(gfx::SkISizeToSize(bitmap.dimensions()),
40 gfx::BufferFormat::BGRA_8888,
41 gfx::BufferUsage::GPU_READ_CPU_READ_WRITE);
42 bool rv = gpu_memory_buffer->Map();
43 DCHECK(rv);
44 int stride = gpu_memory_buffer->stride(0 /* plane */);
45 DCHECK_GT(stride, 0);
46 bitmap.copyPixelsTo(gpu_memory_buffer->memory(0 /* plane */),
47 stride * bitmap.height(), stride);
48 gpu_memory_buffer->Unmap();
49
50 return make_scoped_ptr(new Buffer(std::move(gpu_memory_buffer)));
51 }
52
53 } // namespace
54 16
55 //////////////////////////////////////////////////////////////////////////////// 17 ////////////////////////////////////////////////////////////////////////////////
56 // Pointer, public: 18 // Pointer, public:
57 19
58 Pointer::Pointer(PointerDelegate* delegate) 20 Pointer::Pointer(PointerDelegate* delegate)
59 : delegate_(delegate), surface_(nullptr), focus_(nullptr) { 21 : delegate_(delegate), surface_(nullptr), focus_(nullptr) {
60 ash::Shell::GetInstance()->AddPreTargetHandler(this); 22 ash::Shell::GetInstance()->AddPreTargetHandler(this);
61 } 23 }
62 24
63 Pointer::~Pointer() { 25 Pointer::~Pointer() {
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 case ui::ET_MOUSE_EXITED: 133 case ui::ET_MOUSE_EXITED:
172 case ui::ET_MOUSE_CAPTURE_CHANGED: 134 case ui::ET_MOUSE_CAPTURE_CHANGED:
173 break; 135 break;
174 default: 136 default:
175 NOTREACHED(); 137 NOTREACHED();
176 break; 138 break;
177 } 139 }
178 140
179 // Update cursor widget to reflect current focus and pointer location. 141 // Update cursor widget to reflect current focus and pointer location.
180 if (focus_) { 142 if (focus_) {
181 if (!widget_) { 143 if (!widget_)
182 CreatePointerWidget(); 144 CreatePointerWidget();
183
184 // Create default pointer surface. This will be used until a different
185 // pointer surface is set using SetCursor().
186 default_cursor_ = CreateDefaultCursor(&hotspot_);
187 default_surface_.reset(new Surface);
188 surface_ = default_surface_.get();
189 surface_->SetSurfaceDelegate(this);
190 surface_->AddSurfaceObserver(this);
191 widget_->GetNativeWindow()->AddChild(surface_);
192 surface_->Attach(default_cursor_.get());
193 surface_->Commit();
194 surface_->Show();
195 }
196 widget_->SetBounds(gfx::Rect( 145 widget_->SetBounds(gfx::Rect(
197 focus_->GetBoundsInScreen().origin() + location_.OffsetFromOrigin(), 146 focus_->GetBoundsInScreen().origin() + location_.OffsetFromOrigin(),
198 gfx::Size(1, 1))); 147 gfx::Size(1, 1)));
199 if (!widget_->IsVisible()) 148 if (!widget_->IsVisible())
200 widget_->Show(); 149 widget_->Show();
201 } else { 150 } else {
202 if (widget_ && widget_->IsVisible()) 151 if (widget_ && widget_->IsVisible())
203 widget_->Hide(); 152 widget_->Hide();
204 } 153 }
205 } 154 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
258 Surface* Pointer::GetEffectiveTargetForEvent(ui::Event* event) const { 207 Surface* Pointer::GetEffectiveTargetForEvent(ui::Event* event) const {
259 Surface* target = 208 Surface* target =
260 Surface::AsSurface(static_cast<aura::Window*>(event->target())); 209 Surface::AsSurface(static_cast<aura::Window*>(event->target()));
261 if (!target) 210 if (!target)
262 return nullptr; 211 return nullptr;
263 212
264 return delegate_->CanAcceptPointerEventsForSurface(target) ? target : nullptr; 213 return delegate_->CanAcceptPointerEventsForSurface(target) ? target : nullptr;
265 } 214 }
266 215
267 } // namespace exo 216 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/pointer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698