1/*
2// Copyright (c) 2014 Intel Corporation 
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8//      http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#include <HwcTrace.h>
17#include <Drm.h>
18#include <Hwcomposer.h>
19#include <DrmConfig.h>
20#include <PrimaryDevice.h>
21
22namespace android {
23namespace intel {
24
25PrimaryDevice::PrimaryDevice(Hwcomposer& hwc, DeviceControlFactory* controlFactory)
26    : PhysicalDevice(DEVICE_PRIMARY, hwc, controlFactory)
27{
28    CTRACE();
29}
30
31PrimaryDevice::~PrimaryDevice()
32{
33    CTRACE();
34}
35
36bool PrimaryDevice::initialize()
37{
38    if (!PhysicalDevice::initialize()) {
39        DEINIT_AND_RETURN_FALSE("failed to initialize physical device");
40    }
41
42    UeventObserver *observer = Hwcomposer::getInstance().getUeventObserver();
43    if (observer) {
44        observer->registerListener(
45            DrmConfig::getRepeatedFrameString(),
46            repeatedFrameEventListener,
47            this);
48    } else {
49        ETRACE("Uevent observer is NULL");
50    }
51
52    return true;
53}
54
55void PrimaryDevice::deinitialize()
56{
57    PhysicalDevice::deinitialize();
58}
59
60
61void PrimaryDevice::repeatedFrameEventListener(void *data)
62{
63    PrimaryDevice *pThis = (PrimaryDevice*)data;
64    if (pThis) {
65        pThis->repeatedFrameListener();
66    }
67}
68
69void PrimaryDevice::repeatedFrameListener()
70{
71    Hwcomposer::getInstance().getDisplayAnalyzer()->postIdleEntryEvent();
72    Hwcomposer::getInstance().invalidate();
73}
74
75bool PrimaryDevice::blank(bool blank)
76{
77    if (!mConnected)
78        return true;
79
80    return PhysicalDevice::blank(blank);
81}
82
83} // namespace intel
84} // namespace android
85