Commit 6bd237ca authored by Erik Chen's avatar Erik Chen Committed by Commit Bot

wayland: Add support for compositor protocol version < 4.

The current implementation of DamageBuffer uses wl_surface_damage_buffer, which
relies on the assumption that the compositor protocol version is at least 4. This CL adds a fallback to wl_surface_damage when the protocol version is less than 4.

Bug: 1039481
Change-Id: I20ba46e49fd08925e0f7df1af491c8e800f210e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1999081
Commit-Queue: Maksim Sisov <msisov@igalia.com>
Reviewed-by: default avatarMaksim Sisov <msisov@igalia.com>
Auto-Submit: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#731653}
parent d17e4065
......@@ -283,14 +283,40 @@ class WaylandBufferManagerHost::Surface {
pending_damage_region.set_size(buffer->size);
DCHECK(!pending_damage_region.size().IsEmpty());
wl_surface_damage_buffer(window_->surface(), pending_damage_region.x(),
pending_damage_region.y(),
pending_damage_region.width(),
pending_damage_region.height());
if (connection_->compositor_version() >=
WL_SURFACE_DAMAGE_BUFFER_SINCE_VERSION) {
// wl_surface_damage_buffer relies on compositor API version 4. See
// https://bit.ly/2u00lv6 for details.
// We don't need to apply any scaling because pending_damage_region is
// already in buffer coordinates.
wl_surface_damage_buffer(window_->surface(), pending_damage_region.x(),
pending_damage_region.y(),
pending_damage_region.width(),
pending_damage_region.height());
} else {
// The calculation for damage region relies on two assumptions:
// 1) The buffer is always attached at surface location (0, 0)
// 2) The API wl_surface::set_buffer_transform is not used.
// It's possible to write logic that accounts for both cases above, but
// it's currently unnecessary.
//
// Note: The damage region may not be an integer multiple of scale. To
// keep the implementation simple, the x() and y() coordinates round down,
// and the width() and height() calculations always add an extra pixel.
int scale = window_->buffer_scale();
wl_surface_damage(window_->surface(), pending_damage_region.x() / scale,
pending_damage_region.y() / scale,
pending_damage_region.width() / scale + 1,
pending_damage_region.height() / scale + 1);
}
}
void AttachBuffer(WaylandBuffer* buffer) {
DCHECK(window_);
// The logic in DamageBuffer currently relies on attachment coordinates of
// (0, 0). If this changes, then the calculation in DamageBuffer will also
// need to be updated.
wl_surface_attach(window_->surface(), buffer->wl_buffer.get(), 0, 0);
}
......
......@@ -281,6 +281,7 @@ void WaylandConnection::Global(void* data,
if (!connection->compositor_ && strcmp(interface, "wl_compositor") == 0) {
connection->compositor_ = wl::Bind<wl_compositor>(
registry, name, std::min(version, kMaxCompositorVersion));
connection->compositor_version_ = version;
if (!connection->compositor_)
LOG(ERROR) << "Failed to bind to wl_compositor global";
} else if (!connection->subcompositor_ &&
......
......@@ -52,6 +52,7 @@ class WaylandConnection : public PlatformEventSource,
wl_display* display() const { return display_.get(); }
wl_compositor* compositor() const { return compositor_.get(); }
uint32_t compositor_version() const { return compositor_version_; }
wl_subcompositor* subcompositor() const { return subcompositor_.get(); }
xdg_wm_base* shell() const { return shell_.get(); }
zxdg_shell_v6* shell_v6() const { return shell_v6_.get(); }
......@@ -177,6 +178,7 @@ class WaylandConnection : public PlatformEventSource,
wl::Object<wl_display> display_;
wl::Object<wl_registry> registry_;
wl::Object<wl_compositor> compositor_;
uint32_t compositor_version_ = 0;
wl::Object<wl_subcompositor> subcompositor_;
wl::Object<wl_seat> seat_;
wl::Object<xdg_wm_base> shell_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment