Skip to content

Commit

Permalink
[wayland] Add zaura_output_manager global (server-side)
Browse files Browse the repository at this point in the history
This CL adds a new global interface to the aura-shell extension.

This extension is responsible for sending a complete set of metrics
needed to accurately represent WaylandOutput client-side.

This CL lands the server-side code. The follow-up CL will land the
client-side changes.

Bug: 1408304
Change-Id: Ida237018e644695229a3f70f7d17f3d911cd04df
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4286784
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Commit-Queue: Thomas Lukaszewicz <tluk@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1115748}
  • Loading branch information
Thomas Lukaszewicz authored and Chromium LUCI CQ committed Mar 10, 2023
1 parent d41a414 commit eada725
Show file tree
Hide file tree
Showing 10 changed files with 375 additions and 8 deletions.
2 changes: 2 additions & 0 deletions components/exo/wayland/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ source_set("wayland") {
"wp_viewporter.h",
"xdg_shell.cc",
"xdg_shell.h",
"zaura_output_manager.cc",
"zaura_output_manager.h",
"zaura_shell.cc",
"zaura_shell.h",
"zcr_alpha_compositing.cc",
Expand Down
1 change: 1 addition & 0 deletions components/exo/wayland/clients/client_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ DEFAULT_DELETER(wl_output, wl_output_destroy)
DEFAULT_DELETER(wp_presentation, wp_presentation_destroy)
DEFAULT_DELETER(struct wp_presentation_feedback,
wp_presentation_feedback_destroy)
DEFAULT_DELETER(zaura_output_manager, zaura_output_manager_destroy)
DEFAULT_DELETER(zaura_shell, zaura_shell_destroy)
DEFAULT_DELETER(zaura_surface, zaura_surface_destroy)
DEFAULT_DELETER(zaura_output, zaura_output_destroy)
Expand Down
1 change: 1 addition & 0 deletions components/exo/wayland/clients/client_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ DEFAULT_DELETER_FDECL(wl_touch)
DEFAULT_DELETER_FDECL(wl_output)
DEFAULT_DELETER_FDECL(wp_presentation)
DEFAULT_DELETER_FDECL(struct wp_presentation_feedback)
DEFAULT_DELETER_FDECL(zaura_output_manager)
DEFAULT_DELETER_FDECL(zaura_shell)
DEFAULT_DELETER_FDECL(zaura_surface)
DEFAULT_DELETER_FDECL(zaura_output)
Expand Down
3 changes: 3 additions & 0 deletions components/exo/wayland/clients/test/client_version_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "components/exo/wayland/clients/test/client_version_test.h"

#include <alpha-compositing-unstable-v1-client-protocol.h>
#include <aura-shell-server-protocol.h>
#include <chrome-color-management-server-protocol.h>
#include <content-type-v1-server-protocol.h>
#include <cursor-shapes-unstable-v1-server-protocol.h>
Expand Down Expand Up @@ -65,6 +66,7 @@ struct Globals {
std::unique_ptr<wl_shell> wl_shell;
std::unique_ptr<wl_seat> wl_seat;
std::unique_ptr<wp_presentation> wp_presentation;
std::unique_ptr<zaura_output_manager> zaura_output_manager;
std::unique_ptr<zaura_shell> zaura_shell;
std::unique_ptr<zwp_linux_dmabuf_v1> zwp_linux_dmabuf_v1;
std::unique_ptr<wl_subcompositor> wl_subcompositor;
Expand Down Expand Up @@ -157,6 +159,7 @@ void RegistryHandler(void* data,
REGISTRY_CALLBACK(wl_shell, wl_shell),
REGISTRY_CALLBACK(wl_seat, wl_seat),
REGISTRY_CALLBACK(wp_presentation, wp_presentation),
REGISTRY_CALLBACK(zaura_output_manager, zaura_output_manager),
REGISTRY_CALLBACK(zaura_shell, zaura_shell),
REGISTRY_CALLBACK(zwp_linux_dmabuf_v1, zwp_linux_dmabuf_v1),
REGISTRY_CALLBACK(wl_subcompositor, wl_subcompositor),
Expand Down
161 changes: 161 additions & 0 deletions components/exo/wayland/protocol/aura-shell.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1187,4 +1187,165 @@
<arg name="scale_factor_as_uint" type="uint"/>
</request>
</interface>

<interface name="zaura_output_manager" version="1">
<description summary="aura shell interface to the output manager">
A global responsible for ensuring clients have a complete view of a given
output's state immediately following the bind of wl_output, and
subsequently as needed.

Clients can expect that all the manager's events for a given wl_output
arrive before the associated wl_output.done event. Clients must bind to
the manager global before any output globals.
</description>

<event name="done" since="1">
<description summary="sent all information about output">
This event is sent after all relevant properties of a
zaura_output_manager for a given wl_output have been sent.
</description>
<arg name="output" type="object" interface="wl_output" />
</event>

<event name="display_id" since="1">
<description summary="advertise the output's display id">
This event describes the 64bit display id assigned to each display by
ChromeOS. The value is opaque and should not be interpreted.

The event is sent when binding to the output object and subsequently as
output state changes.
</description>
<arg name="output" type="object" interface="wl_output" />
<arg name="display_id_hi" type="uint" />
<arg name="display_id_lo" type="uint" />
</event>

<event name="logical_position" since="1">
<description
summary="position of the output within the global compositor space">
The position event describes the location of the wl_output within the
global compositor space.

The event is sent when binding to the output object and subsequently as
output state changes.
</description>
<arg name="output" type="object" interface="wl_output" />
<arg name="x" type="int"
summary="x position within the global compositor space" />
<arg name="y" type="int"
summary="y position within the global compositor space" />
</event>

<event name="logical_size" since="1">
<description summary="size of the output in the global compositor space">
The logical_size event describes the logical size of the output in the
global compositor space.

The event is sent when binding to the output object and subsequently as
output state changes.
</description>
<arg name="output" type="object" interface="wl_output" />
<arg name="width" type="int" summary="width in global compositor space" />
<arg name="height" type="int"
summary="height in global compositor space" />
</event>

<event name="physical_size" since="1">
<description summary="size of the output in pixels">
The physical resolution of the display in pixels. The value should not
include any overscan insets or display rotation, except for any panel
orientation adjustment.

The event is sent when binding to the output object and subsequently as
output state changes.
</description>
<arg name="output" type="object" interface="wl_output" />
<arg name="width" type="int"
summary="width in global compositor space" />
<arg name="height" type="int"
summary="height in global compositor space" />
</event>

<event name="insets" since="1">
<description summary="advertise the insets for the output">
This event describes the insets for the output in logical screen
coordinates, from which the work area can be calculated.

The event is sent when binding to the output object and subsequently as
output state changes.
</description>
<arg name="output" type="object" interface="wl_output" />
<arg name="top" type="int" />
<arg name="left" type="int" />
<arg name="bottom" type="int" />
<arg name="right" type="int" />
</event>

<event name="device_scale_factor" since="1">
<description summary="advertise device scale factor for the output">
The scale factor of the output device. We reinterpret_cast the float
scale factor into a 32-bit uint and later cast back into a float. This
is because wayland does not support native transport of floats. As
different CPU architectures may use different endian representations for
IEEE 754 floats, this protocol implicitly assumes that the caller and
receiver are the same machine.

The event is sent when binding to the output object and subsequently as
output state changes.
</description>
<arg name="output" type="object" interface="wl_output" />
<arg name="device_scale_factor" type="uint"
summary="display scale factor, in float format" />
</event>

<event name="logical_transform" since="1">
<description summary="logical transform of the output">
This event describes the logical transform for the output. Whereas
panel transform corresponds to the display's panel rotation, the logical
transform corresponds to the display's logical rotation.

The event is sent when binding to the output object and subsequently as
output state changes.
</description>
<arg name="output" type="object" interface="wl_output" />
<arg name="transform" type="int" enum="wl_output.transform"
summary="transform that maps framebuffer to output" />
</event>

<event name="panel_transform" since="1">
<description summary="panel transform of the output">
This event describes the panel transform for the output, which is the
associated display's panel rotation.

The event is sent when binding to the output object and subsequently as
output state changes.
</description>
<arg name="output" type="object" interface="wl_output" />
<arg name="transform" type="int" enum="wl_output.transform"
summary="transform that maps framebuffer to output" />
</event>

<event name="name" since="1">
<description summary="human-readable name of this output">
The name is a UTF-8 string with no convention defined for its contents.

The event is sent when binding to the output object and subsequently as
output state changes.
</description>
<arg name="output" type="object" interface="wl_output" />
<arg name="name" type="string" summary="output name" />
</event>

<event name="description" since="1">
<description summary="human-readable description of this output">
The description is a UTF-8 string with no convention defined for its
contents.

The event is sent when binding to the output object and subsequently as
output state changes.
</description>
<arg name="output" type="object" interface="wl_output" />
<arg name="description" type="string" summary="output description" />
</event>
</interface>
</protocol>
9 changes: 9 additions & 0 deletions components/exo/wayland/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#include "components/exo/wayland/wp_presentation.h"
#include "components/exo/wayland/wp_viewporter.h"
#include "components/exo/wayland/xdg_shell.h"
#include "components/exo/wayland/zaura_output_manager.h"
#include "components/exo/wayland/zaura_shell.h"
#include "components/exo/wayland/zcr_alpha_compositing.h"
#include "components/exo/wayland/zcr_color_manager.h"
Expand Down Expand Up @@ -282,6 +283,14 @@ void Server::Initialize() {
wayland_feedback_manager_->GetVersionSupportedByPlatform(),
wayland_feedback_manager_.get(), bind_linux_dmabuf);
}

// aura_output_manager needs to be registered before the wl_output globals to
// ensure clients can bind to the aura_output_manager before any wl_outputs.
// This is necessary to ensure aura_output_manager can send relevant output
// events immediately after an output is bound to the client and before the
// data in these events might be needed by the client.
wl_global_create(wl_display_.get(), &zaura_output_manager_interface, 1, this,
bind_aura_output_manager);
wl_global_create(wl_display_.get(), &wl_subcompositor_interface, 1, display_,
bind_subcompositor);
for (const auto& display : display::Screen::GetScreen()->GetAllDisplays())
Expand Down
21 changes: 14 additions & 7 deletions components/exo/wayland/wayland_display_observer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "components/exo/wayland/output_metrics.h"
#include "components/exo/wayland/server_util.h"
#include "components/exo/wayland/wayland_display_output.h"
#include "components/exo/wayland/zaura_output_manager.h"
#include "components/exo/wayland/zcr_color_manager.h"
#include "ui/display/display_observer.h"
#include "ui/display/screen.h"
Expand Down Expand Up @@ -63,13 +64,7 @@ void WaylandDisplayHandler::AddObserver(WaylandDisplayObserver* observer) {

// Send the first round of changes to the observer.
constexpr uint32_t all_changes = 0xFFFFFFFF;
if (observer->SendDisplayMetrics(display, all_changes)) {
if (wl_resource_get_version(output_resource_) >=
WL_OUTPUT_DONE_SINCE_VERSION) {
wl_output_send_done(output_resource_);
}
wl_client_flush(wl_resource_get_client(output_resource_));
}
OnDisplayMetricsChanged(display, all_changes);
}

void WaylandDisplayHandler::RemoveObserver(WaylandDisplayObserver* observer) {
Expand All @@ -91,6 +86,18 @@ void WaylandDisplayHandler::OnDisplayMetricsChanged(
}

bool needs_done = false;

// If supported, the aura_output_manager must have been bound by clients
// before the wl_output associated with this WaylandDisplayHandler is bound.
wl_client* client = wl_resource_get_client(output_resource_);
if (auto* output_manager = AuraOutputManager::Get(client)) {
// This sends all relevant output metrics to clients. These events are sent
// immediately after the client binds an output and again every time display
// metrics have changed.
needs_done |= output_manager->SendOutputMetrics(output_resource_, display,
changed_metrics);
}

for (auto& observer : observers_) {
needs_done |= observer.SendDisplayMetrics(display, changed_metrics);
}
Expand Down
6 changes: 5 additions & 1 deletion components/exo/wayland/wl_output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ void bind_output(wl_client* client,
wl_resource_create(client, &wl_output_interface,
std::min(version, kWlOutputVersion), output_id);
auto handler = std::make_unique<WaylandDisplayHandler>(output, resource);
handler->Initialize();
SetImplementation(resource, &output_implementation, std::move(handler));

// Ensure we set the user_data implementation before initializing the output
// as the user_data's lifetime is expected to correlate to that of the
// wl_output resource.
GetUserDataAs<WaylandDisplayHandler>(resource)->Initialize();
}

} // namespace wayland
Expand Down

0 comments on commit eada725

Please sign in to comment.