1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "ui/ozone/platform/dri/dri_vsync_provider.h"
6
7#include "base/time/time.h"
8#include "ui/ozone/platform/dri/hardware_display_controller.h"
9
10namespace ui {
11
12DriVSyncProvider::DriVSyncProvider(
13    const base::WeakPtr<HardwareDisplayController>& controller)
14    : controller_(controller) {
15}
16
17DriVSyncProvider::~DriVSyncProvider() {}
18
19void DriVSyncProvider::GetVSyncParameters(const UpdateVSyncCallback& callback) {
20  if (!controller_)
21    return;
22
23  // The value is invalid, so we can't update the parameters.
24  if (controller_->get_time_of_last_flip() == 0 ||
25      controller_->get_mode().vrefresh == 0)
26    return;
27
28  // Stores the time of the last refresh.
29  base::TimeTicks timebase =
30      base::TimeTicks::FromInternalValue(controller_->get_time_of_last_flip());
31  // Stores the refresh rate.
32  base::TimeDelta interval =
33      base::TimeDelta::FromSeconds(1) / controller_->get_mode().vrefresh;
34
35  callback.Run(timebase, interval);
36}
37
38}  // namespace ui
39