This repository was archived by the owner on Jan 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vm_tools: sommelier: Implement fractional scale protocol
A simple implementation of the fractional scale protocol, forwarding the value from the parent compositor and adjusting it for the requested scale, similar to sl_output. See https://chromium-review.googlesource.com/c/chromium/src/+/4660423 for the Exo implementation. BUG=b:289488725 TEST=Manual testing with test clients Change-Id: I64bc417248241c0b1b62c4c40c053eaaf2798e60 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform2/+/4827206 Commit-Queue: Robert Mader <[email protected]> Tested-by: Robert Mader <[email protected]> Reviewed-by: Nic Hollingum <[email protected]> Reviewed-by: Ryan Neph <[email protected]>
- Loading branch information
Showing
8 changed files
with
276 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<protocol name="fractional_scale_v1"> | ||
<copyright> | ||
Copyright © 2022 Kenny Levinsen | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a | ||
copy of this software and associated documentation files (the "Software"), | ||
to deal in the Software without restriction, including without limitation | ||
the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
and/or sell copies of the Software, and to permit persons to whom the | ||
Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice (including the next | ||
paragraph) shall be included in all copies or substantial portions of the | ||
Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
DEALINGS IN THE SOFTWARE. | ||
</copyright> | ||
|
||
<description summary="Protocol for requesting fractional surface scales"> | ||
This protocol allows a compositor to suggest for surfaces to render at | ||
fractional scales. | ||
|
||
A client can submit scaled content by utilizing wp_viewport. This is done by | ||
creating a wp_viewport object for the surface and setting the destination | ||
rectangle to the surface size before the scale factor is applied. | ||
|
||
The buffer size is calculated by multiplying the surface size by the | ||
intended scale. | ||
|
||
The wl_surface buffer scale should remain set to 1. | ||
|
||
If a surface has a surface-local size of 100 px by 50 px and wishes to | ||
submit buffers with a scale of 1.5, then a buffer of 150px by 75 px should | ||
be used and the wp_viewport destination rectangle should be 100 px by 50 px. | ||
|
||
For toplevel surfaces, the size is rounded halfway away from zero. The | ||
rounding algorithm for subsurface position and size is not defined. | ||
</description> | ||
|
||
<interface name="wp_fractional_scale_manager_v1" version="1"> | ||
<description summary="fractional surface scale information"> | ||
A global interface for requesting surfaces to use fractional scales. | ||
</description> | ||
|
||
<request name="destroy" type="destructor"> | ||
<description summary="unbind the fractional surface scale interface"> | ||
Informs the server that the client will not be using this protocol | ||
object anymore. This does not affect any other objects, | ||
wp_fractional_scale_v1 objects included. | ||
</description> | ||
</request> | ||
|
||
<enum name="error"> | ||
<entry name="fractional_scale_exists" value="0" | ||
summary="the surface already has a fractional_scale object associated"/> | ||
</enum> | ||
|
||
<request name="get_fractional_scale"> | ||
<description summary="extend surface interface for scale information"> | ||
Create an add-on object for the the wl_surface to let the compositor | ||
request fractional scales. If the given wl_surface already has a | ||
wp_fractional_scale_v1 object associated, the fractional_scale_exists | ||
protocol error is raised. | ||
</description> | ||
<arg name="id" type="new_id" interface="wp_fractional_scale_v1" | ||
summary="the new surface scale info interface id"/> | ||
<arg name="surface" type="object" interface="wl_surface" | ||
summary="the surface"/> | ||
</request> | ||
</interface> | ||
|
||
<interface name="wp_fractional_scale_v1" version="1"> | ||
<description summary="fractional scale interface to a wl_surface"> | ||
An additional interface to a wl_surface object which allows the compositor | ||
to inform the client of the preferred scale. | ||
</description> | ||
|
||
<request name="destroy" type="destructor"> | ||
<description summary="remove surface scale information for surface"> | ||
Destroy the fractional scale object. When this object is destroyed, | ||
preferred_scale events will no longer be sent. | ||
</description> | ||
</request> | ||
|
||
<event name="preferred_scale"> | ||
<description summary="notify of new preferred scale"> | ||
Notification of a new preferred scale for this surface that the | ||
compositor suggests that the client should use. | ||
|
||
The sent scale is the numerator of a fraction with a denominator of 120. | ||
</description> | ||
<arg name="scale" type="uint" summary="the new preferred scale"/> | ||
</event> | ||
</interface> | ||
</protocol> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// Copyright 2023 The ChromiumOS Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "sommelier.h" // NOLINT(build/include_directory) | ||
#include "sommelier-tracing.h" // NOLINT(build/include_directory) | ||
|
||
#include <assert.h> | ||
#include <stdlib.h> | ||
|
||
#include "fractional-scale-v1-client-protocol.h" // NOLINT(build/include_directory) | ||
#include "fractional-scale-v1-server-protocol.h" // NOLINT(build/include_directory) | ||
|
||
struct sl_host_fractional_scale_manager { | ||
struct sl_fractional_scale_manager* fractional_scale_manager; | ||
struct wl_resource* resource; | ||
struct wp_fractional_scale_manager_v1* proxy; | ||
}; | ||
|
||
struct sl_host_fractional_scale { | ||
struct sl_host_fractional_scale_manager* host_fractional_scale_manager; | ||
struct wl_resource* resource; | ||
struct wp_fractional_scale_v1* proxy; | ||
}; | ||
|
||
static void sl_fractional_scale_destroy(struct wl_client* client, | ||
struct wl_resource* resource) { | ||
wl_resource_destroy(resource); | ||
} | ||
|
||
static void sl_fractional_scale_handle_preferred_scale( | ||
void* data, | ||
struct wp_fractional_scale_v1* fractional_scale, | ||
uint32_t wire_scale) { | ||
struct sl_host_fractional_scale* host_fractional_scale = | ||
static_cast<sl_host_fractional_scale*>( | ||
wp_fractional_scale_v1_get_user_data(fractional_scale)); | ||
struct sl_fractional_scale_manager* fractional_scale_manager = | ||
host_fractional_scale->host_fractional_scale_manager | ||
->fractional_scale_manager; | ||
|
||
wp_fractional_scale_v1_send_preferred_scale( | ||
host_fractional_scale->resource, | ||
round(wire_scale / fractional_scale_manager->ctx->scale)); | ||
} | ||
|
||
static const struct wp_fractional_scale_v1_listener fractional_scale_listener = | ||
{ | ||
.preferred_scale = sl_fractional_scale_handle_preferred_scale, | ||
}; | ||
|
||
static const struct wp_fractional_scale_v1_interface | ||
sl_fractional_scale_implementation = {sl_fractional_scale_destroy}; | ||
|
||
static void sl_destroy_host_fractional_scale(struct wl_resource* resource) { | ||
struct sl_host_fractional_scale* host = | ||
static_cast<sl_host_fractional_scale*>( | ||
wl_resource_get_user_data(resource)); | ||
|
||
wl_resource_set_user_data(resource, nullptr); | ||
delete host; | ||
} | ||
|
||
static void sl_fractional_scale_manager_destroy(struct wl_client* client, | ||
struct wl_resource* resource) { | ||
wl_resource_destroy(resource); | ||
} | ||
|
||
static void sl_fractional_scale_manager_get_fractional_scale( | ||
struct wl_client* client, | ||
struct wl_resource* resource, | ||
uint32_t id, | ||
struct wl_resource* surface_resource) { | ||
struct sl_host_fractional_scale_manager* host = | ||
static_cast<sl_host_fractional_scale_manager*>( | ||
wl_resource_get_user_data(resource)); | ||
struct sl_host_surface* host_surface = static_cast<sl_host_surface*>( | ||
wl_resource_get_user_data(surface_resource)); | ||
struct sl_host_fractional_scale* host_fractional_scale = | ||
new sl_host_fractional_scale(); | ||
|
||
host_fractional_scale->host_fractional_scale_manager = host; | ||
host_fractional_scale->resource = | ||
wl_resource_create(client, &wp_fractional_scale_v1_interface, 1, id); | ||
host_fractional_scale->proxy = | ||
wp_fractional_scale_manager_v1_get_fractional_scale( | ||
host->fractional_scale_manager->internal, host_surface->proxy); | ||
wp_fractional_scale_v1_add_listener(host_fractional_scale->proxy, | ||
&fractional_scale_listener, | ||
host_fractional_scale); | ||
wl_resource_set_implementation( | ||
host_fractional_scale->resource, &sl_fractional_scale_implementation, | ||
host_fractional_scale, sl_destroy_host_fractional_scale); | ||
} | ||
|
||
static const struct wp_fractional_scale_manager_v1_interface | ||
sl_wp_fractional_scale_manager_implementation = { | ||
sl_fractional_scale_manager_destroy, | ||
sl_fractional_scale_manager_get_fractional_scale, | ||
}; | ||
|
||
static void sl_destroy_host_fractional_scale_manager( | ||
struct wl_resource* resource) { | ||
struct sl_host_fractional_scale_manager* host = | ||
static_cast<sl_host_fractional_scale_manager*>( | ||
wl_resource_get_user_data(resource)); | ||
|
||
wp_fractional_scale_manager_v1_destroy(host->proxy); | ||
wl_resource_set_user_data(resource, nullptr); | ||
delete host; | ||
} | ||
|
||
static void sl_bind_host_fractional_scale_manager(struct wl_client* client, | ||
void* data, | ||
uint32_t version, | ||
uint32_t id) { | ||
struct sl_context* ctx = (struct sl_context*)data; | ||
struct sl_host_fractional_scale_manager* host = | ||
new sl_host_fractional_scale_manager(); | ||
host->fractional_scale_manager = ctx->fractional_scale_manager; | ||
host->resource = wl_resource_create( | ||
client, &wp_fractional_scale_manager_v1_interface, 1, id); | ||
wl_resource_set_implementation( | ||
host->resource, &sl_wp_fractional_scale_manager_implementation, host, | ||
sl_destroy_host_fractional_scale_manager); | ||
host->proxy = static_cast<wp_fractional_scale_manager_v1*>(wl_registry_bind( | ||
wl_display_get_registry(ctx->display), ctx->fractional_scale_manager->id, | ||
&wp_fractional_scale_manager_v1_interface, 1)); | ||
wp_fractional_scale_manager_v1_set_user_data(host->proxy, host); | ||
} | ||
|
||
struct sl_global* sl_fractional_scale_manager_global_create( | ||
struct sl_context* ctx) { | ||
return sl_global_create(ctx, &wp_fractional_scale_manager_v1_interface, 1, | ||
ctx, sl_bind_host_fractional_scale_manager); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters