Skip to content

Commit

Permalink
ozone/wayland: use struct traits instead of TypeConverter
Browse files Browse the repository at this point in the history
TypeConverter uses unnecessary copies and it's suggested to
use StructTraits instead.

This should slightly improve speed of serialization and
deserialization as it avoids copies.

Bug: 1295527
Change-Id: I1480be154dea59f82c521a8e6ad9a8400a744e08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3623479
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Kramer Ge <fangzhoug@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1002511}
  • Loading branch information
msisov authored and Chromium LUCI CQ committed May 12, 2022
1 parent ed12b09 commit 7caf517
Show file tree
Hide file tree
Showing 23 changed files with 553 additions and 332 deletions.
11 changes: 11 additions & 0 deletions ui/ozone/platform/wayland/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ import("//ui/ozone/platform/wayland/wayland.gni")

assert(is_linux || is_chromeos_lacros)

source_set("common") {
sources = [
"common/wayland_overlay_config.cc",
"common/wayland_overlay_config.h",
]

deps = [ "//ui/gfx" ]
}

source_set("wayland") {
sources = [
"client_native_pixmap_factory_wayland.cc",
Expand Down Expand Up @@ -207,6 +216,7 @@ source_set("wayland") {
defines = [ "OZONE_IMPLEMENTATION" ]

deps = [
":common",
"//base",
"//build:chromeos_buildflags",
"//build/config/linux/libdrm",
Expand Down Expand Up @@ -525,6 +535,7 @@ source_set("wayland_unittests") {
]

deps = [
":common",
":test_support",
":wayland",
"//build:chromeos_buildflags",
Expand Down
38 changes: 38 additions & 0 deletions ui/ozone/platform/wayland/common/wayland_overlay_config.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// 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/common/wayland_overlay_config.h"

namespace wl {

WaylandOverlayConfig::WaylandOverlayConfig() = default;

WaylandOverlayConfig::WaylandOverlayConfig(WaylandOverlayConfig&& other) =
default;

WaylandOverlayConfig::WaylandOverlayConfig(const gfx::OverlayPlaneData& data,
std::unique_ptr<gfx::GpuFence> fence,
BufferId buffer_id,
float scale_factor)
: z_order(data.z_order),
transform(data.plane_transform),
buffer_id(buffer_id),
surface_scale_factor(scale_factor),
bounds_rect(data.display_bounds),
crop_rect(data.crop_rect),
damage_region(data.damage_rect),
enable_blend(data.enable_blend),
opacity(data.opacity),
access_fence_handle(fence ? fence->GetGpuFenceHandle().Clone()
: gfx::GpuFenceHandle()),
priority_hint(data.priority_hint),
rounded_clip_bounds(data.rounded_corners),
background_color(data.color) {}

WaylandOverlayConfig& WaylandOverlayConfig::operator=(
WaylandOverlayConfig&& other) = default;

WaylandOverlayConfig::~WaylandOverlayConfig() = default;

} // namespace wl
87 changes: 87 additions & 0 deletions ui/ozone/platform/wayland/common/wayland_overlay_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright 2022 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_OZONE_PLATFORM_WAYLAND_COMMON_WAYLAND_OVERLAY_CONFIG_H_
#define UI_OZONE_PLATFORM_WAYLAND_COMMON_WAYLAND_OVERLAY_CONFIG_H_

#include <memory>

#include "ui/gfx/gpu_fence.h"
#include "ui/gfx/gpu_fence_handle.h"
#include "ui/gfx/overlay_plane_data.h"
#include "ui/gfx/overlay_priority_hint.h"
#include "ui/gfx/overlay_transform.h"

namespace wl {

using BufferId = uint32_t;

struct WaylandOverlayConfig {
WaylandOverlayConfig();
WaylandOverlayConfig(WaylandOverlayConfig&& other);
WaylandOverlayConfig(const gfx::OverlayPlaneData& data,
std::unique_ptr<gfx::GpuFence> fence,
BufferId buffer_id,
float scale_factor);
WaylandOverlayConfig& operator=(WaylandOverlayConfig&& other);

~WaylandOverlayConfig();

// Specifies the stacking order of this overlay plane, relative to primary
// plane.
int z_order = 0;

// Specifies how the buffer is to be transformed during composition.
gfx::OverlayTransform transform =
gfx::OverlayTransform::OVERLAY_TRANSFORM_NONE;

// A unique id for the buffer, which is used to identify imported wl_buffers
// on the browser process.
uint32_t buffer_id = 0;

// Scale factor of the GPU side surface with respect to a display where the
// surface is located at.
float surface_scale_factor = 1.f;

// Specifies where it is supposed to be on the display in physical pixels.
// This, after scaled by buffer_scale sets the destination rectangle of
// Wayland Viewport.
gfx::RectF bounds_rect;

// Specifies the region within the buffer to be placed inside |bounds_rect|.
// This sets the source rectangle of Wayland Viewport.
gfx::RectF crop_rect = {1.f, 1.f};

// Describes the changed region of the buffer. Optional to hint a partial
// swap.
gfx::Rect damage_region;

// Specifies if alpha blending, with premultiplied alpha should be applied at
// scanout.
bool enable_blend = false;

// Opacity of the overlay independent of buffer alpha.
// Valid values are [0.0, 1.0f].
float opacity = 1.f;

// Specifies a GpuFenceHandle to be waited on before content of the buffer can
// be accessed by the display controller for overlay, or by the gpu for
// compositing.
gfx::GpuFenceHandle access_fence_handle;

// Specifies priority of this overlay if delegated composition is supported
// and enabled.
gfx::OverlayPriorityHint priority_hint = gfx::OverlayPriorityHint::kNone;

// Specifies rounded clip bounds of the overlay if delegated composition is
// supported and enabled.
gfx::RRectF rounded_clip_bounds;

// Optional: background color of this overlay plane.
absl::optional<SkColor> background_color;
};

} // namespace wl

#endif // COMPONENTS_VIZ_COMMON_QUADS_COMPOSITOR_FRAME_H_
14 changes: 6 additions & 8 deletions ui/ozone/platform/wayland/gpu/gbm_pixmap_wayland.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "ui/gfx/native_pixmap_handle.h"
#include "ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.h"
#include "ui/ozone/platform/wayland/gpu/wayland_buffer_manager_gpu.h"
#include "ui/ozone/public/overlay_plane.h"
#include "ui/ozone/public/ozone_platform.h"

namespace ui {
Expand Down Expand Up @@ -179,13 +178,12 @@ bool GbmPixmapWayland::ScheduleOverlayPlane(
DCHECK(surfaceless);

DCHECK(acquire_fences.empty() || acquire_fences.size() == 1u);
surfaceless->QueueOverlayPlane(
OverlayPlane(this,
acquire_fences.empty() ? nullptr
: std::make_unique<gfx::GpuFence>(
std::move(acquire_fences[0])),
overlay_plane_data),
buffer_id_);
surfaceless->QueueWaylandOverlayConfig(
{overlay_plane_data,
acquire_fences.empty()
? nullptr
: std::make_unique<gfx::GpuFence>(std::move(acquire_fences[0])),
buffer_id_, surfaceless->surface_scale_factor()});
return true;
}

Expand Down
40 changes: 17 additions & 23 deletions ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ GbmSurfacelessWayland::GbmSurfacelessWayland(
std::make_unique<PendingFrame>(next_frame_id()));
}

void GbmSurfacelessWayland::QueueOverlayPlane(OverlayPlane plane,
BufferId buffer_id) {
unsubmitted_frames_.back()->planes.emplace_back(buffer_id, std::move(plane));
void GbmSurfacelessWayland::QueueWaylandOverlayConfig(
wl::WaylandOverlayConfig config) {
unsubmitted_frames_.back()->configs.emplace_back(std::move(config));
}

bool GbmSurfacelessWayland::ScheduleOverlayPlane(
Expand Down Expand Up @@ -217,9 +217,12 @@ void GbmSurfacelessWayland::SwapBuffersAsync(

base::OnceClosure fence_wait_task;
std::vector<std::unique_ptr<gfx::GpuFence>> fences;
for (auto& plane : frame->planes) {
if (plane.second.gpu_fence)
fences.push_back(std::move(plane.second.gpu_fence));
for (auto& config : frame->configs) {
if (!config.access_fence_handle.is_null()) {
fences.push_back(std::make_unique<gfx::GpuFence>(
std::move(config.access_fence_handle)));
config.access_fence_handle = gfx::GpuFenceHandle();
}
}

fence_wait_task = base::BindOnce(&WaitForGpuFences, std::move(fences));
Expand Down Expand Up @@ -320,6 +323,7 @@ void GbmSurfacelessWayland::PendingFrame::ScheduleOverlayPlanes(
// Solid color overlays are non-backed. Thus, queue them directly.
// TODO(msisov): reconsider this once Linux Wayland compositors also support
// creation of non-backed solid color wl_buffers.
in_flight_color_buffers.reserve(non_backed_overlays.size());
for (auto& overlay_data : non_backed_overlays) {
// This mustn't happen, but let's be explicit here and fail scheduling if
// it is not a solid color overlay.
Expand All @@ -336,8 +340,9 @@ void GbmSurfacelessWayland::PendingFrame::ScheduleOverlayPlanes(
schedule_planes_succeeded = false;
return;
}
surfaceless->QueueOverlayPlane(OverlayPlane(nullptr, nullptr, overlay_data),
buf_id);
in_flight_color_buffers.push_back(buf_id);
surfaceless->QueueWaylandOverlayConfig(
{overlay_data, nullptr, buf_id, surfaceless->surface_scale_factor()});
}

schedule_planes_succeeded = true;
Expand Down Expand Up @@ -367,19 +372,8 @@ void GbmSurfacelessWayland::MaybeSubmitFrames() {
return;
}

std::vector<ui::ozone::mojom::WaylandOverlayConfigPtr> overlay_configs;
for (auto& plane : submitted_frame->planes) {
overlay_configs.push_back(
ui::ozone::mojom::WaylandOverlayConfig::From(plane.second));
overlay_configs.back()->buffer_id = plane.first;
// The current scale factor of the surface, which is used to determine
// the size in pixels of resources allocated by the GPU process.
overlay_configs.back()->surface_scale_factor = surface_scale_factor_;
plane.second.gpu_fence.reset();
}

buffer_manager_->CommitOverlays(widget_, submitted_frame->frame_id,
std::move(overlay_configs));
std::move(submitted_frame->configs));
submitted_frames_.push_back(std::move(submitted_frame));
}
}
Expand Down Expand Up @@ -417,11 +411,11 @@ void GbmSurfacelessWayland::OnSubmission(uint32_t frame_id,

auto submitted_frame = std::move(submitted_frames_.front());
submitted_frames_.erase(submitted_frames_.begin());
for (auto& plane : submitted_frame->planes) {
for (auto& buf : submitted_frame->in_flight_color_buffers) {
// Let the holder mark this buffer as free to reuse.
solid_color_buffers_holder_->OnSubmission(plane.first, buffer_manager_);
solid_color_buffers_holder_->OnSubmission(buf, buffer_manager_);
}
submitted_frame->planes.clear();
submitted_frame->in_flight_color_buffers.clear();
submitted_frame->overlays.clear();

// Check if the fence has retired.
Expand Down
16 changes: 10 additions & 6 deletions ui/ozone/platform/wayland/gpu/gbm_surfaceless_wayland.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
#include "base/memory/weak_ptr.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gl/gl_surface_egl.h"
#include "ui/ozone/platform/wayland/common/wayland_overlay_config.h"
#include "ui/ozone/platform/wayland/gpu/wayland_surface_gpu.h"
#include "ui/ozone/public/overlay_plane.h"
#include "ui/ozone/public/swap_completion_callback.h"

namespace ui {
Expand All @@ -35,7 +35,9 @@ class GbmSurfacelessWayland : public gl::SurfacelessEGL,
GbmSurfacelessWayland(const GbmSurfacelessWayland&) = delete;
GbmSurfacelessWayland& operator=(const GbmSurfacelessWayland&) = delete;

void QueueOverlayPlane(OverlayPlane plane, BufferId buffer_id);
float surface_scale_factor() const { return surface_scale_factor_; }

void QueueWaylandOverlayConfig(wl::WaylandOverlayConfig config);

// gl::GLSurface:
bool ScheduleOverlayPlane(
Expand Down Expand Up @@ -135,7 +137,7 @@ class GbmSurfacelessWayland : public gl::SurfacelessEGL,
explicit PendingFrame(uint32_t frame_id);
~PendingFrame();

// Queues overlay configs to |planes|.
// Queues overlay configs to |configs|.
void ScheduleOverlayPlanes(GbmSurfacelessWayland* surfaceless);
void Flush();

Expand All @@ -149,13 +151,15 @@ class GbmSurfacelessWayland : public gl::SurfacelessEGL,
std::vector<gfx::OverlayPlaneData> non_backed_overlays;
SwapCompletionCallback completion_callback;
PresentationCallback presentation_callback;

// Merged release fence fd. This is taken as the union of all release
// fences for a particular OnSubmission.
bool schedule_planes_succeeded = false;

// Contains |buffer_id|s to OverlayPlanes, used for committing overlays and
// wait for OnSubmission's.
std::vector<std::pair<BufferId, OverlayPlane>> planes;
std::vector<BufferId> in_flight_color_buffers;
// Contains |buffer_id|s to gl::GLSurfaceOverlay, used for committing
// overlays and wait for OnSubmission's.
std::vector<wl::WaylandOverlayConfig> configs;
};

void MaybeSubmitFrames();
Expand Down

0 comments on commit 7caf517

Please sign in to comment.