Commit 7e489781 authored by Tom Anderson's avatar Tom Anderson Committed by Commit Bot

[XProto] Remove usage of Xlib from OMLSyncControlVSyncProvider

BUG=1066670
R=sunnyps

Change-Id: Icc189028b7d7630d398b1efe7ff55110913d0e48
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2302735
Commit-Queue: Thomas Anderson <thomasanderson@chromium.org>
Reviewed-by: default avatarSunny Sachanandani <sunnyps@chromium.org>
Cr-Commit-Position: refs/heads/master@{#789287}
parent 524d3b94
......@@ -26,8 +26,13 @@
#include "ui/base/x/x11_util.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/x/connection.h"
#include "ui/gfx/x/dri2.h"
#include "ui/gfx/x/glx.h"
#include "ui/gfx/x/present.h"
#include "ui/gfx/x/x11.h"
#include "ui/gfx/x/x11_types.h"
#include "ui/gfx/x/xf86vidmode.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_implementation.h"
......@@ -148,8 +153,8 @@ bool CreateDummyWindow(Display* display) {
class OMLSyncControlVSyncProvider : public SyncControlVSyncProvider {
public:
explicit OMLSyncControlVSyncProvider(GLXWindow glx_window)
: SyncControlVSyncProvider(), glx_window_(glx_window) {}
explicit OMLSyncControlVSyncProvider(x11::Window window)
: SyncControlVSyncProvider(), window_(window) {}
~OMLSyncControlVSyncProvider() override = default;
......@@ -157,29 +162,85 @@ class OMLSyncControlVSyncProvider : public SyncControlVSyncProvider {
bool GetSyncValues(int64_t* system_time,
int64_t* media_stream_counter,
int64_t* swap_buffer_counter) override {
return glXGetSyncValuesOML(gfx::GetXDisplay(), glx_window_, system_time,
media_stream_counter, swap_buffer_counter);
auto* connection = x11::Connection::Get();
// First try to get the counter values using the DRI2 extension.
if (auto reply = connection->dri2().GetMSC({window_}).Sync()) {
auto merge_counter = [](uint32_t hi, uint32_t lo) {
return (static_cast<uint64_t>(hi) << 32) | lo;
};
*system_time = merge_counter(reply->ust_hi, reply->ust_lo);
*media_stream_counter = merge_counter(reply->msc_hi, reply->msc_lo);
*swap_buffer_counter = merge_counter(reply->sbc_hi, reply->sbc_lo);
return true;
}
// Next try the present extension.
auto& present = connection->present();
// Check if the present extension is available.
if (!present.present())
return false;
// Issue a NotifyMSC request and listen for the resulting event which will
// contain the counter values.
auto context = connection->GenerateId<x11::Present::Event>();
present.SelectInput(
{context, window_, x11::Present::EventMask::CompleteNotify});
connection->present().NotifyMSC({window_});
present.SelectInput({context, window_, x11::Present::EventMask::NoEvent});
connection->Sync();
connection->ReadResponses();
for (const auto& event : connection->events()) {
auto* complete = event.As<x11::Present::CompleteNotifyEvent>();
if (complete && complete->kind == x11::Present::CompleteKind::NotifyMSC &&
complete->window == window_ && complete->serial == 0) {
*system_time = complete->ust;
*media_stream_counter = complete->msc;
*swap_buffer_counter = 0;
return true;
}
}
return false;
}
bool GetMscRate(int32_t* numerator, int32_t* denominator) override {
if (!g_glx_get_msc_rate_oml_supported)
return false;
if (!glXGetMscRateOML(gfx::GetXDisplay(), glx_window_, numerator,
denominator)) {
// Once glXGetMscRateOML has been found to fail, don't try again,
auto* connection = x11::Connection::Get();
connection->xf86vidmode().SetClientVersion(
{x11::XF86VidMode::major_version, x11::XF86VidMode::minor_version});
auto reply = connection->xf86vidmode()
.GetModeLine({connection->DefaultScreenId()})
.Sync();
if (!reply) {
// Once GetModeLine has been found to fail, don't try again,
// since each failing call may spew an error message.
g_glx_get_msc_rate_oml_supported = false;
return false;
}
*numerator = static_cast<uint32_t>(reply->dotclock) * 1000;
*denominator = static_cast<uint32_t>(reply->vtotal) * reply->htotal;
// These adjustments are from mesa's __glxGetMscRate().
if (static_cast<bool>(reply->flags &
x11::XF86VidMode::ModeFlag::Interlace)) {
*numerator *= 2;
}
if (static_cast<bool>(reply->flags &
x11::XF86VidMode::ModeFlag::Composite_Sync)) {
*denominator *= 2;
}
return true;
}
bool IsHWClock() const override { return true; }
private:
GLXWindow glx_window_;
x11::Window window_;
DISALLOW_COPY_AND_ASSIGN(OMLSyncControlVSyncProvider);
};
......@@ -671,8 +732,8 @@ bool NativeViewGLSurfaceGLX::Initialize(GLSurfaceFormat format) {
}
if (g_glx_oml_sync_control_supported) {
vsync_provider_ =
std::make_unique<OMLSyncControlVSyncProvider>(glx_window_);
vsync_provider_ = std::make_unique<OMLSyncControlVSyncProvider>(
static_cast<x11::Window>(window_));
presentation_helper_ =
std::make_unique<GLSurfacePresentationHelper>(vsync_provider_.get());
} else if (g_glx_sgi_video_sync_supported) {
......
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