Commit 25adf51e authored by erikchen's avatar erikchen Committed by Commit Bot

Responsiveness calculator: Hook into aura::env on OS_LINUX.

Previously, there was separate logic for OZONE and X11. This simplifies the
existing logic, while also adding support for mash.

Change-Id: I0f652360457e27dcdcdcc4e3afb131626aa07429
Reviewed-on: https://chromium-review.googlesource.com/1246726Reviewed-by: default avatarTimothy Dresser <tdresser@chromium.org>
Commit-Queue: Erik Chen <erikchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594899}
parent 97a515a8
...@@ -17,14 +17,9 @@ ...@@ -17,14 +17,9 @@
#include "ui/events/platform/platform_event_source.h" #include "ui/events/platform/platform_event_source.h"
#if defined(USE_X11)
#include "ui/events/platform/x11/x11_event_source.h" // nogncheck
#elif defined(USE_OZONE)
#include "ui/events/event.h"
#endif
#if defined(OS_LINUX) #if defined(OS_LINUX)
#include "ui/events/platform_event.h" #include "ui/aura/env.h"
#include "ui/events/event.h"
#endif #endif
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -71,41 +66,25 @@ NativeEventObserver::~NativeEventObserver() { ...@@ -71,41 +66,25 @@ NativeEventObserver::~NativeEventObserver() {
#if defined(OS_LINUX) #if defined(OS_LINUX)
void NativeEventObserver::RegisterObserver() { void NativeEventObserver::RegisterObserver() {
ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this); aura::Env::GetInstance()->AddWindowEventDispatcherObserver(this);
} }
void NativeEventObserver::DeregisterObserver() { void NativeEventObserver::DeregisterObserver() {
ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this); aura::Env::GetInstance()->RemoveWindowEventDispatcherObserver(this);
} }
void NativeEventObserver::WillProcessEvent(const ui::PlatformEvent& event) { void NativeEventObserver::OnWindowEventDispatcherStartedProcessing(
aura::WindowEventDispatcher* dispatcher,
const ui::Event& event) {
EventInfo info{&event, event.time_stamp()};
events_being_processed_.push_back(info);
will_run_event_callback_.Run(&event); will_run_event_callback_.Run(&event);
} }
void NativeEventObserver::DidProcessEvent(const ui::PlatformEvent& event) { void NativeEventObserver::OnWindowEventDispatcherFinishedProcessingEvent(
#if defined(USE_OZONE) aura::WindowEventDispatcher* dispatcher) {
did_run_event_callback_.Run(&event, event->time_stamp()); EventInfo& info = events_being_processed_.back();
#elif defined(USE_X11) did_run_event_callback_.Run(info.unique_id, info.creation_time);
// X11 uses a uint32_t on the wire protocol. Xlib casts this to an unsigned events_being_processed_.pop_back();
// long by prepending with 0s. We cast back to a uint32_t so that subtraction
// works properly when the timestamp overflows back to 0.
uint32_t event_server_time_ms =
static_cast<uint32_t>(ui::X11EventSource::GetInstance()->GetTimestamp());
uint32_t current_server_time_ms = static_cast<uint32_t>(
ui::X11EventSource::GetInstance()->GetCurrentServerTime());
// On X11, event times are in X11 Server time. To convert to base::TimeTicks,
// we perform a round-trip to the X11 Server, subtract the two times to get a
// TimeDelta, and then subtract that from base::TimeTicks::Now(). Since we're
// working with units of time from an external source, we clamp the TimeDelta
// to reasonable values.
uint32_t delta_ms = current_server_time_ms - event_server_time_ms;
base::TimeDelta delta = base::TimeDelta::FromMilliseconds(delta_ms);
base::TimeDelta sanitized = ClampDeltaFromExternalSource(delta);
did_run_event_callback_.Run(&event, base::TimeTicks::Now() - sanitized);
#else
#error
#endif
} }
#endif // defined(OS_LINUX) #endif // defined(OS_LINUX)
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/time/time.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
...@@ -15,7 +16,7 @@ ...@@ -15,7 +16,7 @@
#endif #endif
#if defined(OS_LINUX) #if defined(OS_LINUX)
#include "ui/events/platform/platform_event_observer.h" #include "ui/aura/window_event_dispatcher_observer.h"
#endif #endif
#if defined(OS_WIN) #if defined(OS_WIN)
...@@ -40,7 +41,7 @@ class CONTENT_EXPORT NativeEventObserver ...@@ -40,7 +41,7 @@ class CONTENT_EXPORT NativeEventObserver
#if defined(OS_MACOSX) #if defined(OS_MACOSX)
: public NativeEventProcessorObserver : public NativeEventProcessorObserver
#elif defined(OS_LINUX) #elif defined(OS_LINUX)
: public ui::PlatformEventObserver : public aura::WindowEventDispatcherObserver
#elif defined(OS_WIN) #elif defined(OS_WIN)
: public base::MessagePumpForUI::Observer : public base::MessagePumpForUI::Observer
#endif #endif
...@@ -73,10 +74,12 @@ class CONTENT_EXPORT NativeEventObserver ...@@ -73,10 +74,12 @@ class CONTENT_EXPORT NativeEventObserver
void DidRunNativeEvent(const void* opaque_identifier, void DidRunNativeEvent(const void* opaque_identifier,
base::TimeTicks creation_time) override; base::TimeTicks creation_time) override;
#elif defined(OS_LINUX) #elif defined(OS_LINUX)
// PlatformEventObserver overrides: // aura::WindowEventDispatcherObserver overrides:
// Exposed for tests. void OnWindowEventDispatcherStartedProcessing(
void WillProcessEvent(const ui::PlatformEvent& event) override; aura::WindowEventDispatcher* dispatcher,
void DidProcessEvent(const ui::PlatformEvent& event) override; const ui::Event& event) override;
void OnWindowEventDispatcherFinishedProcessingEvent(
aura::WindowEventDispatcher* dispatcher) override;
#elif defined(OS_WIN) #elif defined(OS_WIN)
// base::MessagePumpForUI::Observer overrides: // base::MessagePumpForUI::Observer overrides:
void WillDispatchMSG(const MSG& msg) override; void WillDispatchMSG(const MSG& msg) override;
...@@ -87,6 +90,14 @@ class CONTENT_EXPORT NativeEventObserver ...@@ -87,6 +90,14 @@ class CONTENT_EXPORT NativeEventObserver
void RegisterObserver(); void RegisterObserver();
void DeregisterObserver(); void DeregisterObserver();
#if defined(OS_LINUX)
struct EventInfo {
const void* unique_id;
base::TimeTicks creation_time;
};
std::vector<EventInfo> events_being_processed_;
#endif
WillRunEventCallback will_run_event_callback_; WillRunEventCallback will_run_event_callback_;
DidRunEventCallback did_run_event_callback_; DidRunEventCallback did_run_event_callback_;
......
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