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
3 // found in the LICENSE file.
5 #include "ui/ozone/platform/dri/dri_window.h"
8 #include "ui/events/event.h"
9 #include "ui/events/ozone/evdev/event_factory_evdev.h"
10 #include "ui/events/ozone/events_ozone.h"
11 #include "ui/events/platform/platform_event_source.h"
12 #include "ui/ozone/common/gpu/ozone_gpu_messages.h"
13 #include "ui/ozone/platform/dri/dri_cursor.h"
14 #include "ui/ozone/platform/dri/dri_gpu_platform_support_host.h"
15 #include "ui/ozone/platform/dri/dri_window_manager.h"
16 #include "ui/platform_window/platform_window_delegate.h"
20 DriWindow::DriWindow(PlatformWindowDelegate* delegate,
21 const gfx::Rect& bounds,
22 DriGpuPlatformSupportHost* sender,
23 EventFactoryEvdev* event_factory,
24 DriWindowManager* window_manager)
25 : delegate_(delegate),
27 event_factory_(event_factory),
28 window_manager_(window_manager),
30 widget_(window_manager->NextAcceleratedWidget()) {
31 window_manager_->AddWindow(widget_, this);
34 DriWindow::~DriWindow() {
35 PlatformEventSource::GetInstance()->RemovePlatformEventDispatcher(this);
36 window_manager_->RemoveWindow(widget_);
38 sender_->RemoveChannelObserver(this);
39 if (!sender_->IsConnected())
42 sender_->Send(new OzoneGpuMsg_DestroyWindowDelegate(widget_));
45 void DriWindow::Initialize() {
46 sender_->AddChannelObserver(this);
47 delegate_->OnAcceleratedWidgetAvailable(widget_);
48 PlatformEventSource::GetInstance()->AddPlatformEventDispatcher(this);
51 void DriWindow::Show() {}
53 void DriWindow::Hide() {}
55 void DriWindow::Close() {}
57 void DriWindow::SetBounds(const gfx::Rect& bounds) {
59 delegate_->OnBoundsChanged(bounds);
61 if (!sender_->IsConnected())
64 if (window_manager_->cursor()->GetCursorWindow() == widget_)
65 window_manager_->cursor()->HideCursor();
67 sender_->Send(new OzoneGpuMsg_WindowBoundsChanged(widget_, bounds));
69 if (window_manager_->cursor()->GetCursorWindow() == widget_)
70 window_manager_->cursor()->ShowCursor();
73 gfx::Rect DriWindow::GetBounds() {
77 void DriWindow::SetCapture() {}
79 void DriWindow::ReleaseCapture() {}
81 void DriWindow::ToggleFullscreen() {}
83 void DriWindow::Maximize() {}
85 void DriWindow::Minimize() {}
87 void DriWindow::Restore() {}
89 void DriWindow::SetCursor(PlatformCursor cursor) {
90 DriCursor* dri_cursor = window_manager_->cursor();
91 dri_cursor->SetCursor(widget_, cursor);
92 // ShowCursor results in a IPC call to GPU. So, we make sure the channel
93 // is connected. OnChannelEstablished guarantees that ShowCursor is called
95 if (sender_->IsConnected() && dri_cursor->GetCursorWindow() == widget_)
96 dri_cursor->ShowCursor();
99 void DriWindow::MoveCursorTo(const gfx::Point& location) {
100 event_factory_->WarpCursorTo(widget_, location);
103 bool DriWindow::CanDispatchEvent(const PlatformEvent& ne) {
105 Event* event = static_cast<Event*>(ne);
106 if (event->IsMouseEvent() || event->IsScrollEvent())
107 return window_manager_->cursor()->GetCursorWindow() == widget_;
112 uint32_t DriWindow::DispatchEvent(const PlatformEvent& native_event) {
113 DispatchEventFromNativeUiEvent(
114 native_event, base::Bind(&PlatformWindowDelegate::DispatchEvent,
115 base::Unretained(delegate_)));
116 return POST_DISPATCH_STOP_PROPAGATION;
119 void DriWindow::OnChannelEstablished() {
120 sender_->Send(new OzoneGpuMsg_CreateWindowDelegate(widget_));
121 sender_->Send(new OzoneGpuMsg_WindowBoundsChanged(widget_, bounds_));
123 DriCursor* dri_cursor = window_manager_->cursor();
124 if (dri_cursor->GetCursorWindow() == widget_)
125 dri_cursor->ShowCursor();
128 void DriWindow::OnChannelDestroyed() {