Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / ozone / ui / gfx / vsync_provider_wayland.cc
1 // Copyright 2013 Intel Corporation. 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 "ozone/ui/gfx/vsync_provider_wayland.h"
6
7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h"
9 #include "ozone/ui/gfx/ozone_display.h"
10
11 namespace gfx {
12
13 WaylandSyncProvider::WaylandSyncProvider(unsigned handle) : handle_(handle) {
14 }
15
16 WaylandSyncProvider::~WaylandSyncProvider() {
17   // WaylandSyncProvider is destroyed when the associated NativeSurface is
18   // destroyed. Inform OzoneDisplay to release Wayland resources.
19   OzoneDisplay::GetInstance()->DestroyWidget(handle_);
20   OzoneDisplay::GetInstance()->FlushDisplay();
21 }
22
23 void WaylandSyncProvider::GetVSyncParameters(
24          const UpdateVSyncCallback& callback) {
25   // PassThroughImageTransportSurface calls this before swapping the surface.
26   // Post a task to flush display as it should be handled immediately after
27   // swap buffers is done.
28   base::MessageLoop::current()->message_loop_proxy()->PostTask(
29       FROM_HERE, base::Bind(&WaylandSyncProvider::ScheduleFlush));
30
31   // TODO(kalyan): Pass refresh rate and time of the last refresh.
32 }
33
34 void WaylandSyncProvider::ScheduleFlush() {
35   OzoneDisplay* native_display = OzoneDisplay::GetInstance();
36   if (native_display)
37     native_display->FlushDisplay();
38 }
39
40 }  // namespace gfx