#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/message_loop/message_loop.h"
+#include "base/single_thread_task_runner.h"
#include "base/synchronization/cancellation_flag.h"
#include "base/synchronization/lock.h"
+#include "base/thread_task_runner_handle.h"
#include "base/threading/non_thread_safe.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
-#include "third_party/mesa/src/include/GL/osmesa.h"
#include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/x/x11_connection.h"
#include "ui/gfx/x/x11_types.h"
bool g_glx_sgi_video_sync_supported = false;
+static const base::TimeDelta kGetVSyncParametersMinPeriod =
+#if defined(OS_LINUX)
+ // See crbug.com/373489
+ // On Linux, querying the vsync parameters might burn CPU for up to an
+ // entire vsync, so we only query periodically to reduce CPU usage.
+ // 5 seconds is chosen somewhat abitrarily as a balance between:
+ // a) Drift in the phase of our signal.
+ // b) Potential janks from periodically pegging the CPU.
+ base::TimeDelta::FromSeconds(5);
+#else
+ base::TimeDelta::FromSeconds(0);
+#endif
+
class OMLSyncControlVSyncProvider
: public gfx::SyncControlVSyncProvider {
public:
explicit SGIVideoSyncProviderThreadShim(XID window)
: window_(window),
context_(NULL),
- message_loop_(base::MessageLoopProxy::current()),
+ task_runner_(base::ThreadTaskRunnerHandle::Get()),
cancel_vsync_flag_(),
vsync_lock_() {
// This ensures that creation of |window_| has occured when this shim
const base::TimeDelta kDefaultInterval =
base::TimeDelta::FromSeconds(1) / 60;
- message_loop_->PostTask(
+ task_runner_->PostTask(
FROM_HERE, base::Bind(callback, now, kDefaultInterval));
}
XID window_;
GLXContext context_;
- scoped_refptr<base::MessageLoopProxy> message_loop_;
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
base::CancellationFlag cancel_vsync_flag_;
base::Lock vsync_lock_;
virtual void GetVSyncParameters(
const VSyncProvider::UpdateVSyncCallback& callback) OVERRIDE {
+ if (kGetVSyncParametersMinPeriod > base::TimeDelta()) {
+ base::TimeTicks now = base::TimeTicks::Now();
+ base::TimeDelta delta = now - last_get_vsync_parameters_time_;
+ if (delta < kGetVSyncParametersMinPeriod)
+ return;
+ last_get_vsync_parameters_time_ = now;
+ }
+
// Only one outstanding request per surface.
if (!pending_callback_) {
pending_callback_.reset(
base::CancellationFlag* cancel_vsync_flag_;
base::Lock* vsync_lock_;
+ base::TimeTicks last_get_vsync_parameters_time_;
+
DISALLOW_COPY_AND_ASSIGN(SGIVideoSyncVSyncProvider);
};