1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115
|
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/ozone/platform/wayland/host/proxy/wayland_proxy_impl.h"
#include <algorithm>
#include "ui/ozone/platform/wayland/host/wayland_connection.h"
#include "ui/ozone/platform/wayland/host/wayland_shm_buffer.h"
#include "ui/ozone/platform/wayland/host/wayland_window.h"
namespace wl {
WaylandProxyImpl::WaylandProxyImpl(ui::WaylandConnection* connection)
: connection_(connection) {
WaylandProxy::SetInstance(this);
connection_->window_manager()->AddObserver(this);
}
WaylandProxyImpl::~WaylandProxyImpl() {
connection_->window_manager()->RemoveObserver(this);
WaylandProxy::SetInstance(nullptr);
}
void WaylandProxyImpl::SetDelegate(WaylandProxy::Delegate* delegate) {
delegate_ = delegate;
}
struct wl_registry* WaylandProxyImpl::GetRegistry() {
return connection_->GetRegistry();
}
void WaylandProxyImpl::RoundTripQueue() {
connection_->RoundTripQueue();
}
wl_surface* WaylandProxyImpl::GetWlSurfaceForAcceleratedWidget(
gfx::AcceleratedWidget widget) {
auto* window = connection_->window_manager()->GetWindow(widget);
DCHECK(window);
return window->root_surface()->surface();
}
ui::WaylandWindow* WaylandProxyImpl::GetWaylandWindowForAcceleratedWidget(
gfx::AcceleratedWidget widget) {
auto* window = connection_->window_manager()->GetWindow(widget);
DCHECK(window);
return window;
}
wl_buffer* WaylandProxyImpl::CreateShmBasedWlBuffer(
const gfx::Size& buffer_size) {
ui::WaylandShmBuffer shm_buffer(connection_->buffer_factory(), buffer_size);
auto* wlbuffer = shm_buffer.get();
DCHECK(wlbuffer);
shm_buffers_.emplace_back(std::move(shm_buffer));
return wlbuffer;
}
void WaylandProxyImpl::DestroyShmForWlBuffer(wl_buffer* buffer) {
auto it = std::ranges::find(shm_buffers_, buffer, &ui::WaylandShmBuffer::get);
CHECK(it != shm_buffers_.end());
shm_buffers_.erase(it);
}
void WaylandProxyImpl::FlushForTesting() {
connection_->Flush();
}
ui::PlatformWindowType WaylandProxyImpl::GetWindowType(
gfx::AcceleratedWidget widget) {
auto* window = connection_->window_manager()->GetWindow(widget);
DCHECK(window);
return window->type();
}
bool WaylandProxyImpl::WindowHasPointerFocus(gfx::AcceleratedWidget widget) {
auto* window = connection_->window_manager()->GetWindow(widget);
DCHECK(window);
return window->HasPointerFocus();
}
bool WaylandProxyImpl::WindowHasKeyboardFocus(gfx::AcceleratedWidget widget) {
auto* window = connection_->window_manager()->GetWindow(widget);
DCHECK(window);
return window->HasKeyboardFocus();
}
void WaylandProxyImpl::OnWindowAdded(ui::WaylandWindow* window) {
if (delegate_) {
delegate_->OnWindowAdded(window->GetWidget());
}
}
void WaylandProxyImpl::OnWindowRemoved(ui::WaylandWindow* window) {
if (delegate_) {
delegate_->OnWindowRemoved(window->GetWidget());
}
}
void WaylandProxyImpl::OnWindowConfigured(ui::WaylandWindow* window) {
if (delegate_) {
delegate_->OnWindowConfigured(window->GetWidget(),
window->IsSurfaceConfigured());
}
}
void WaylandProxyImpl::OnWindowRoleAssigned(ui::WaylandWindow* window) {
if (delegate_) {
delegate_->OnWindowRoleAssigned(window->GetWidget());
}
}
} // namespace wl
|