Commit 1e9fa490 authored by Daniel Nicoara's avatar Daniel Nicoara Committed by Commit Bot

EXO: Refactor wp_presentation interface

Move the wp_presentation interface into its own files. This
change only moves code around, no functional changes.

Bug: 896710
Test: Build and run exo_unittests
Change-Id: I221c199074376420f3ca842dcd063c4bd4057589
Reviewed-on: https://chromium-review.googlesource.com/c/1480995
Commit-Queue: Daniel Nicoara <dnicoara@chromium.org>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Cr-Commit-Position: refs/heads/master@{#634815}
parent 7220068e
......@@ -57,6 +57,8 @@ source_set("wayland") {
"wl_shm.h",
"wl_subcompositor.cc",
"wl_subcompositor.h",
"wp_presentation.cc",
"wp_presentation.h",
"wp_viewporter.cc",
"wp_viewporter.h",
"zcr_vsync_feedback.cc",
......
......@@ -75,6 +75,7 @@
#include "components/exo/wayland/wl_seat.h"
#include "components/exo/wayland/wl_shm.h"
#include "components/exo/wayland/wl_subcompositor.h"
#include "components/exo/wayland/wp_presentation.h"
#include "components/exo/wayland/wp_viewporter.h"
#include "components/exo/wayland/zcr_vsync_feedback.h"
#include "components/exo/wm_helper.h"
......@@ -90,7 +91,6 @@
#include "ui/display/screen.h"
#include "ui/events/keycodes/dom/keycode_converter.h"
#include "ui/gfx/buffer_types.h"
#include "ui/gfx/presentation_feedback.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_observer.h"
#include "ui/wm/core/coordinate_conversion.h"
......@@ -165,87 +165,6 @@ DEFINE_UI_CLASS_PROPERTY_KEY(bool, kSurfaceHasSecurityKey, false)
// associated with surface object.
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kSurfaceHasBlendingKey, false)
////////////////////////////////////////////////////////////////////////////////
// presentation_interface:
void HandleSurfacePresentationCallback(
wl_resource* resource,
const gfx::PresentationFeedback& feedback) {
if (feedback.timestamp.is_null()) {
wp_presentation_feedback_send_discarded(resource);
} else {
int64_t presentation_time_us = feedback.timestamp.ToInternalValue();
int64_t seconds = presentation_time_us / base::Time::kMicrosecondsPerSecond;
int64_t microseconds =
presentation_time_us % base::Time::kMicrosecondsPerSecond;
static_assert(
static_cast<uint32_t>(gfx::PresentationFeedback::Flags::kVSync) ==
static_cast<uint32_t>(WP_PRESENTATION_FEEDBACK_KIND_VSYNC),
"gfx::PresentationFlags::VSync don't match!");
static_assert(
static_cast<uint32_t>(gfx::PresentationFeedback::Flags::kHWClock) ==
static_cast<uint32_t>(WP_PRESENTATION_FEEDBACK_KIND_HW_CLOCK),
"gfx::PresentationFlags::HWClock don't match!");
static_assert(
static_cast<uint32_t>(
gfx::PresentationFeedback::Flags::kHWCompletion) ==
static_cast<uint32_t>(WP_PRESENTATION_FEEDBACK_KIND_HW_COMPLETION),
"gfx::PresentationFlags::HWCompletion don't match!");
static_assert(
static_cast<uint32_t>(gfx::PresentationFeedback::Flags::kZeroCopy) ==
static_cast<uint32_t>(WP_PRESENTATION_FEEDBACK_KIND_ZERO_COPY),
"gfx::PresentationFlags::ZeroCopy don't match!");
wp_presentation_feedback_send_presented(
resource, seconds >> 32, seconds & 0xffffffff,
microseconds * base::Time::kNanosecondsPerMicrosecond,
feedback.interval.InMicroseconds() *
base::Time::kNanosecondsPerMicrosecond,
0, 0, feedback.flags);
}
wl_client_flush(wl_resource_get_client(resource));
}
void presentation_destroy(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
void presentation_feedback(wl_client* client,
wl_resource* resource,
wl_resource* surface_resource,
uint32_t id) {
wl_resource* presentation_feedback_resource =
wl_resource_create(client, &wp_presentation_feedback_interface,
wl_resource_get_version(resource), id);
// base::Unretained is safe as the resource owns the callback.
auto cancelable_callback = std::make_unique<
base::CancelableCallback<void(const gfx::PresentationFeedback&)>>(
base::Bind(&HandleSurfacePresentationCallback,
base::Unretained(presentation_feedback_resource)));
GetUserDataAs<Surface>(surface_resource)
->RequestPresentationCallback(cancelable_callback->callback());
SetImplementation(presentation_feedback_resource, nullptr,
std::move(cancelable_callback));
}
const struct wp_presentation_interface presentation_implementation = {
presentation_destroy, presentation_feedback};
void bind_presentation(wl_client* client,
void* data,
uint32_t version,
uint32_t id) {
wl_resource* resource =
wl_resource_create(client, &wp_presentation_interface, 1, id);
wl_resource_set_implementation(resource, &presentation_implementation, data,
nullptr);
wp_presentation_send_clock_id(resource, CLOCK_MONOTONIC);
}
////////////////////////////////////////////////////////////////////////////////
// security_interface:
......
// Copyright 2019 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 "components/exo/wayland/wp_presentation.h"
#include <presentation-time-server-protocol.h>
#include <memory>
#include <utility>
#include "base/bind.h"
#include "components/exo/wayland/server_util.h"
#include "ui/gfx/presentation_feedback.h"
namespace exo {
namespace wayland {
namespace {
////////////////////////////////////////////////////////////////////////////////
// presentation_interface:
void HandleSurfacePresentationCallback(
wl_resource* resource,
const gfx::PresentationFeedback& feedback) {
if (feedback.timestamp.is_null()) {
wp_presentation_feedback_send_discarded(resource);
} else {
int64_t presentation_time_us = feedback.timestamp.ToInternalValue();
int64_t seconds = presentation_time_us / base::Time::kMicrosecondsPerSecond;
int64_t microseconds =
presentation_time_us % base::Time::kMicrosecondsPerSecond;
static_assert(
static_cast<uint32_t>(gfx::PresentationFeedback::Flags::kVSync) ==
static_cast<uint32_t>(WP_PRESENTATION_FEEDBACK_KIND_VSYNC),
"gfx::PresentationFlags::VSync don't match!");
static_assert(
static_cast<uint32_t>(gfx::PresentationFeedback::Flags::kHWClock) ==
static_cast<uint32_t>(WP_PRESENTATION_FEEDBACK_KIND_HW_CLOCK),
"gfx::PresentationFlags::HWClock don't match!");
static_assert(
static_cast<uint32_t>(
gfx::PresentationFeedback::Flags::kHWCompletion) ==
static_cast<uint32_t>(WP_PRESENTATION_FEEDBACK_KIND_HW_COMPLETION),
"gfx::PresentationFlags::HWCompletion don't match!");
static_assert(
static_cast<uint32_t>(gfx::PresentationFeedback::Flags::kZeroCopy) ==
static_cast<uint32_t>(WP_PRESENTATION_FEEDBACK_KIND_ZERO_COPY),
"gfx::PresentationFlags::ZeroCopy don't match!");
wp_presentation_feedback_send_presented(
resource, seconds >> 32, seconds & 0xffffffff,
microseconds * base::Time::kNanosecondsPerMicrosecond,
feedback.interval.InMicroseconds() *
base::Time::kNanosecondsPerMicrosecond,
0, 0, feedback.flags);
}
wl_client_flush(wl_resource_get_client(resource));
}
void presentation_destroy(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
void presentation_feedback(wl_client* client,
wl_resource* resource,
wl_resource* surface_resource,
uint32_t id) {
wl_resource* presentation_feedback_resource =
wl_resource_create(client, &wp_presentation_feedback_interface,
wl_resource_get_version(resource), id);
// base::Unretained is safe as the resource owns the callback.
auto cancelable_callback = std::make_unique<
base::CancelableCallback<void(const gfx::PresentationFeedback&)>>(
base::Bind(&HandleSurfacePresentationCallback,
base::Unretained(presentation_feedback_resource)));
GetUserDataAs<Surface>(surface_resource)
->RequestPresentationCallback(cancelable_callback->callback());
SetImplementation(presentation_feedback_resource, nullptr,
std::move(cancelable_callback));
}
const struct wp_presentation_interface presentation_implementation = {
presentation_destroy, presentation_feedback};
} // namespace
void bind_presentation(wl_client* client,
void* data,
uint32_t version,
uint32_t id) {
wl_resource* resource =
wl_resource_create(client, &wp_presentation_interface, 1, id);
wl_resource_set_implementation(resource, &presentation_implementation, data,
nullptr);
wp_presentation_send_clock_id(resource, CLOCK_MONOTONIC);
}
} // namespace wayland
} // namespace exo
// Copyright 2019 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 COMPONENTS_EXO_WAYLAND_WP_PRESENTATION_H_
#define COMPONENTS_EXO_WAYLAND_WP_PRESENTATION_H_
#include <stdint.h>
struct wl_client;
namespace exo {
namespace wayland {
void bind_presentation(wl_client* client,
void* data,
uint32_t version,
uint32_t id);
} // namespace wayland
} // namespace exo
#endif // COMPONENTS_EXO_WAYLAND_WP_PRESENTATION_H_
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