Commit 2761eb6a authored by Shawn Gallea's avatar Shawn Gallea Committed by Commit Bot

EXO: Refactor input timestamps manager interface

Move input timestamps manager out of server.cc
This CL only moves code around.

Bug: 896710
Test: Built on ChromeOS
Change-Id: I65e8baba6d20b726cf69fed3b90286d6ea7cd756
Reviewed-on: https://chromium-review.googlesource.com/c/1318789
Commit-Queue: Shawn Gallea <sagallea@google.com>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608228}
parent 4a71f4e5
......@@ -45,6 +45,8 @@ source_set("wayland") {
"wayland_touch_delegate.h",
"zcr_notification_shell.cc",
"zcr_notification_shell.h",
"zwp_input_timestamps_manager.cc",
"zwp_input_timestamps_manager.h",
"zwp_text_input_manager.cc",
"zwp_text_input_manager.h",
]
......
......@@ -100,6 +100,7 @@
#include "components/exo/wayland/wayland_pointer_delegate.h"
#include "components/exo/wayland/wayland_touch_delegate.h"
#include "components/exo/wayland/zcr_notification_shell.h"
#include "components/exo/wayland/zwp_input_timestamps_manager.h"
#include "components/exo/wayland/zwp_text_input_manager.h"
#include "components/exo/wm_helper.h"
#include "components/exo/wm_helper_chromeos.h"
......@@ -4782,94 +4783,6 @@ void bind_cursor_shapes(wl_client* client,
nullptr);
}
////////////////////////////////////////////////////////////////////////////////
// input_timestamps_v1 interface:
class WaylandInputTimestamps : public WaylandInputDelegate::Observer {
public:
WaylandInputTimestamps(wl_resource* resource, WaylandInputDelegate* delegate)
: resource_(resource), delegate_(delegate) {
delegate_->AddObserver(this);
}
~WaylandInputTimestamps() override {
if (delegate_)
delegate_->RemoveObserver(this);
}
// Overridden from WaylandInputDelegate::Observer:
void OnDelegateDestroying(WaylandInputDelegate* delegate) override {
DCHECK(delegate_ == delegate);
delegate_ = nullptr;
}
void OnSendTimestamp(base::TimeTicks time_stamp) override {
timespec ts = (time_stamp - base::TimeTicks()).ToTimeSpec();
zwp_input_timestamps_v1_send_timestamp(
resource_, static_cast<uint64_t>(ts.tv_sec) >> 32,
ts.tv_sec & 0xffffffff, ts.tv_nsec);
}
private:
wl_resource* const resource_;
WaylandInputDelegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(WaylandInputTimestamps);
};
void input_timestamps_destroy(struct wl_client* client,
struct wl_resource* resource) {
wl_resource_destroy(resource);
}
const struct zwp_input_timestamps_v1_interface input_timestamps_implementation =
{input_timestamps_destroy};
////////////////////////////////////////////////////////////////////////////////
// input_timestamps_manager_v1 interface:
void input_timestamps_manager_destroy(struct wl_client* client,
struct wl_resource* resource) {
wl_resource_destroy(resource);
}
template <typename T, typename D>
void input_timestamps_manager_get_timestamps(wl_client* client,
wl_resource* resource,
uint32_t id,
wl_resource* input_resource) {
wl_resource* input_timestamps_resource =
wl_resource_create(client, &zwp_input_timestamps_v1_interface, 1, id);
auto input_timestamps = std::make_unique<WaylandInputTimestamps>(
input_timestamps_resource,
static_cast<WaylandInputDelegate*>(
static_cast<D*>(GetUserDataAs<T>(input_resource)->delegate())));
SetImplementation(input_timestamps_resource, &input_timestamps_implementation,
std::move(input_timestamps));
}
const struct zwp_input_timestamps_manager_v1_interface
input_timestamps_manager_implementation = {
input_timestamps_manager_destroy,
input_timestamps_manager_get_timestamps<Keyboard,
WaylandKeyboardDelegate>,
input_timestamps_manager_get_timestamps<Pointer,
WaylandPointerDelegate>,
input_timestamps_manager_get_timestamps<Touch, WaylandTouchDelegate>};
void bind_input_timestamps_manager(wl_client* client,
void* data,
uint32_t version,
uint32_t id) {
wl_resource* resource = wl_resource_create(
client, &zwp_input_timestamps_manager_v1_interface, 1, id);
wl_resource_set_implementation(
resource, &input_timestamps_manager_implementation, nullptr, nullptr);
}
} // namespace
////////////////////////////////////////////////////////////////////////////////
......
// Copyright 2018 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/zwp_input_timestamps_manager.h"
#include <input-timestamps-unstable-v1-server-protocol.h>
#include <wayland-server-core.h>
#include <wayland-server-protocol-core.h>
#include "components/exo/keyboard.h"
#include "components/exo/pointer.h"
#include "components/exo/touch.h"
#include "components/exo/wayland/server_util.h"
#include "components/exo/wayland/wayland_input_delegate.h"
#include "components/exo/wayland/wayland_keyboard_delegate.h"
#include "components/exo/wayland/wayland_pointer_delegate.h"
#include "components/exo/wayland/wayland_touch_delegate.h"
namespace exo {
namespace wayland {
namespace {
////////////////////////////////////////////////////////////////////////////////
// input_timestamps_v1 interface:
class WaylandInputTimestamps : public WaylandInputDelegate::Observer {
public:
WaylandInputTimestamps(wl_resource* resource, WaylandInputDelegate* delegate)
: resource_(resource), delegate_(delegate) {
delegate_->AddObserver(this);
}
~WaylandInputTimestamps() override {
if (delegate_)
delegate_->RemoveObserver(this);
}
// Overridden from WaylandInputDelegate::Observer:
void OnDelegateDestroying(WaylandInputDelegate* delegate) override {
DCHECK(delegate_ == delegate);
delegate_ = nullptr;
}
void OnSendTimestamp(base::TimeTicks time_stamp) override {
timespec ts = (time_stamp - base::TimeTicks()).ToTimeSpec();
zwp_input_timestamps_v1_send_timestamp(
resource_, static_cast<uint64_t>(ts.tv_sec) >> 32,
ts.tv_sec & 0xffffffff, ts.tv_nsec);
}
private:
wl_resource* const resource_;
WaylandInputDelegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(WaylandInputTimestamps);
};
void input_timestamps_destroy(struct wl_client* client,
struct wl_resource* resource) {
wl_resource_destroy(resource);
}
const struct zwp_input_timestamps_v1_interface input_timestamps_implementation =
{input_timestamps_destroy};
////////////////////////////////////////////////////////////////////////////////
// input_timestamps_manager_v1 interface:
void input_timestamps_manager_destroy(struct wl_client* client,
struct wl_resource* resource) {
wl_resource_destroy(resource);
}
template <typename T, typename D>
void input_timestamps_manager_get_timestamps(wl_client* client,
wl_resource* resource,
uint32_t id,
wl_resource* input_resource) {
wl_resource* input_timestamps_resource =
wl_resource_create(client, &zwp_input_timestamps_v1_interface, 1, id);
auto input_timestamps = std::make_unique<WaylandInputTimestamps>(
input_timestamps_resource,
static_cast<WaylandInputDelegate*>(
static_cast<D*>(GetUserDataAs<T>(input_resource)->delegate())));
SetImplementation(input_timestamps_resource, &input_timestamps_implementation,
std::move(input_timestamps));
}
const struct zwp_input_timestamps_manager_v1_interface
input_timestamps_manager_implementation = {
input_timestamps_manager_destroy,
input_timestamps_manager_get_timestamps<Keyboard,
WaylandKeyboardDelegate>,
input_timestamps_manager_get_timestamps<Pointer,
WaylandPointerDelegate>,
input_timestamps_manager_get_timestamps<Touch, WaylandTouchDelegate>};
} // namespace
void bind_input_timestamps_manager(wl_client* client,
void* data,
uint32_t version,
uint32_t id) {
wl_resource* resource = wl_resource_create(
client, &zwp_input_timestamps_manager_v1_interface, 1, id);
wl_resource_set_implementation(
resource, &input_timestamps_manager_implementation, nullptr, nullptr);
}
} // namespace wayland
} // namespace exo
// Copyright 2018 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_ZWP_INPUT_TIMESTAMPS_MANAGER_H_
#define COMPONENTS_EXO_WAYLAND_ZWP_INPUT_TIMESTAMPS_MANAGER_H_
#include <stdint.h>
struct wl_client;
namespace exo {
namespace wayland {
void bind_input_timestamps_manager(wl_client* client,
void* data,
uint32_t version,
uint32_t id);
} // namespace wayland
} // namespace exo
#endif // COMPONENTS_EXO_WAYLAND_ZWP_INPUT_TIMESTAMPS_MANAGER_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