1177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu/*
2cd727f537d5085eec7f1b8f9c1d33922d4de75d4Prodyut Hazarika// Copyright (c) 2014 Intel Corporation 
3cd727f537d5085eec7f1b8f9c1d33922d4de75d4Prodyut Hazarika//
4cd727f537d5085eec7f1b8f9c1d33922d4de75d4Prodyut Hazarika// Licensed under the Apache License, Version 2.0 (the "License");
5cd727f537d5085eec7f1b8f9c1d33922d4de75d4Prodyut Hazarika// you may not use this file except in compliance with the License.
6cd727f537d5085eec7f1b8f9c1d33922d4de75d4Prodyut Hazarika// You may obtain a copy of the License at
7cd727f537d5085eec7f1b8f9c1d33922d4de75d4Prodyut Hazarika//
8cd727f537d5085eec7f1b8f9c1d33922d4de75d4Prodyut Hazarika//      http://www.apache.org/licenses/LICENSE-2.0
9cd727f537d5085eec7f1b8f9c1d33922d4de75d4Prodyut Hazarika//
10cd727f537d5085eec7f1b8f9c1d33922d4de75d4Prodyut Hazarika// Unless required by applicable law or agreed to in writing, software
11cd727f537d5085eec7f1b8f9c1d33922d4de75d4Prodyut Hazarika// distributed under the License is distributed on an "AS IS" BASIS,
12cd727f537d5085eec7f1b8f9c1d33922d4de75d4Prodyut Hazarika// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13cd727f537d5085eec7f1b8f9c1d33922d4de75d4Prodyut Hazarika// See the License for the specific language governing permissions and
14cd727f537d5085eec7f1b8f9c1d33922d4de75d4Prodyut Hazarika// limitations under the License.
15cd727f537d5085eec7f1b8f9c1d33922d4de75d4Prodyut Hazarika*/
16177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu#ifndef SOFT_VSYNC_OBSERVER_H
17177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu#define SOFT_VSYNC_OBSERVER_H
18177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
190594c42af26255fd8d3d7d39c0cb0e2da5b8841bThierry Strudel#include <common/base/SimpleThread.h>
20177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
21177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiunamespace android {
22177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiunamespace intel {
23177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
24177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiuclass IDisplayDevice;
25177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
26177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiuclass SoftVsyncObserver {
27177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiupublic:
28177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    SoftVsyncObserver(IDisplayDevice& disp);
29177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    virtual ~SoftVsyncObserver();
30177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
31177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiupublic:
32177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    virtual bool initialize();
33177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    virtual void deinitialize();
34177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    virtual void setRefreshRate(int rate);
35177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    virtual bool control(bool enabled);
36177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
37177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiuprivate:
38177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    IDisplayDevice& mDisplayDevice;
39177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    int  mDevice;
40177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    bool mEnabled;
41177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    int mRefreshRate;
42177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    nsecs_t mRefreshPeriod;
43177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    mutable Mutex mLock;
44177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    Condition mCondition;
45177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    mutable nsecs_t mNextFakeVSync;
46d4645947e422612e1858bc4121b9c3907afde5b0Tan Wei    bool mExitThread;
47009ab1d686644a8294b16d97ec1d4fe58879cf89Lei Zhang    bool mInitialized;
48177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
49177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiuprivate:
50177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu    DECLARE_THREAD(VsyncEventPollThread, SoftVsyncObserver);
51177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu};
52177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
53177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu} // namespace intel
54177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu} // namespace android
55177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
56177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
57177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
58177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu#endif /* SOFT_VSYNC_OBSERVER_H */
59177b44e0661a92d06f8f37c51e59af86423f7a95Andy Qiu
60