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#ifndef PHYSICAL_DEVICE_H
17#define PHYSICAL_DEVICE_H
18
19#include <DisplayPlane.h>
20#include <IVsyncControl.h>
21#include <IBlankControl.h>
22#include <IPrepareListener.h>
23#include <VsyncEventObserver.h>
24#include <HwcLayerList.h>
25#include <Drm.h>
26#include <IDisplayDevice.h>
27
28namespace android {
29namespace intel {
30
31class IHdcpControl;
32
33class DeviceControlFactory {
34public:
35    virtual ~DeviceControlFactory(){}
36public:
37    virtual IVsyncControl* createVsyncControl() = 0;
38    virtual IBlankControl* createBlankControl() = 0;
39    virtual IHdcpControl* createHdcpControl() = 0;
40};
41
42class Hwcomposer;
43
44// Base class for primary and external devices
45class PhysicalDevice : public IDisplayDevice {
46public:
47    PhysicalDevice(uint32_t type, Hwcomposer& hwc, DeviceControlFactory* controlFactory);
48    virtual ~PhysicalDevice();
49public:
50    virtual bool prePrepare(hwc_display_contents_1_t *display);
51    virtual bool prepare(hwc_display_contents_1_t *display);
52    virtual bool commit(hwc_display_contents_1_t *display, IDisplayContext *context);
53
54    virtual bool vsyncControl(bool enabled);
55    virtual bool blank(bool blank);
56    virtual bool getDisplaySize(int *width, int *height);
57    virtual bool getDisplayConfigs(uint32_t *configs,
58                                       size_t *numConfigs);
59    virtual bool getDisplayAttributes(uint32_t config,
60                                          const uint32_t *attributes,
61                                          int32_t *values);
62    virtual bool compositionComplete();
63
64    virtual bool setPowerMode(int mode);
65    virtual int  getActiveConfig();
66    virtual bool setActiveConfig(int index);
67
68    // display config operations
69    virtual void removeDisplayConfigs();
70    virtual bool detectDisplayConfigs();
71
72    // device related operations
73    virtual bool initCheck() const { return mInitialized; }
74    virtual bool initialize();
75    virtual void deinitialize();
76    virtual bool isConnected() const;
77    virtual const char* getName() const;
78    virtual int getType() const;
79    virtual uint32_t getFpsDivider();
80
81    //events
82    virtual void onVsync(int64_t timestamp);
83
84    virtual void dump(Dump& d);
85
86protected:
87    void onGeometryChanged(hwc_display_contents_1_t *list);
88    bool updateDisplayConfigs();
89    IVsyncControl* createVsyncControl() {return mControlFactory->createVsyncControl();}
90    friend class VsyncEventObserver;
91
92protected:
93    uint32_t mType;
94    const char *mName;
95
96    Hwcomposer& mHwc;
97
98    // display configs
99    Vector<DisplayConfig*> mDisplayConfigs;
100    int mActiveDisplayConfig;
101
102
103    IBlankControl *mBlankControl;
104    VsyncEventObserver *mVsyncObserver;
105
106    DeviceControlFactory *mControlFactory;
107
108    // layer list
109    HwcLayerList *mLayerList;
110    bool mConnected;
111    bool mBlank;
112
113    // lock
114    Mutex mLock;
115
116    // DPMS on (1) or off (0)
117    int mDisplayState;
118    bool mInitialized;
119    uint32_t mFpsDivider;
120};
121
122
123
124}
125}
126
127#endif /* PHYSICAL_DEVICE_H */
128