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 HWCOMPOSER_H
17#define HWCOMPOSER_H
18
19#include <EGL/egl.h>
20#include <hardware/hwcomposer.h>
21#include <utils/Vector.h>
22
23#include <IDisplayDevice.h>
24#include <BufferManager.h>
25#include <IDisplayContext.h>
26#include <Drm.h>
27#include <DisplayPlaneManager.h>
28#include <DisplayAnalyzer.h>
29#include <VsyncManager.h>
30#include <MultiDisplayObserver.h>
31#include <UeventObserver.h>
32#include <IPlatFactory.h>
33
34
35namespace android {
36namespace intel {
37
38class Hwcomposer : public hwc_composer_device_1_t {
39public:
40    virtual ~Hwcomposer();
41public:
42    // callbacks implementation
43    virtual bool prepare(size_t numDisplays,
44                           hwc_display_contents_1_t** displays);
45    virtual bool commit(size_t numDisplays,
46                           hwc_display_contents_1_t** displays);
47    virtual bool vsyncControl(int disp, int enabled);
48    virtual bool release();
49    virtual bool dump(char *buff, int buff_len, int *cur_len);
50    virtual void registerProcs(hwc_procs_t const *procs);
51
52    virtual bool blank(int disp, int blank);
53    virtual bool getDisplayConfigs(int disp,
54                                       uint32_t *configs,
55                                       size_t *numConfigs);
56    virtual bool getDisplayAttributes(int disp,
57                                          uint32_t config,
58                                          const uint32_t *attributes,
59                                          int32_t *values);
60    virtual bool compositionComplete(int disp);
61
62    virtual bool setPowerMode(int disp, int mode);
63    virtual int  getActiveConfig(int disp);
64    virtual bool setActiveConfig(int disp, int index);
65    virtual bool setCursorPositionAsync(int disp, int x, int y);
66
67    // callbacks
68    virtual void vsync(int disp, int64_t timestamp);
69    virtual void hotplug(int disp, bool connected);
70    virtual void invalidate();
71
72    virtual bool initCheck() const;
73    virtual bool initialize();
74    virtual void deinitialize();
75
76
77public:
78    Drm* getDrm();
79    DisplayPlaneManager* getPlaneManager();
80    BufferManager* getBufferManager();
81    IDisplayContext* getDisplayContext();
82    DisplayAnalyzer* getDisplayAnalyzer();
83    VsyncManager* getVsyncManager();
84    MultiDisplayObserver* getMultiDisplayObserver();
85    IDisplayDevice* getDisplayDevice(int disp);
86    UeventObserver* getUeventObserver();
87    IPlatFactory* getPlatFactory() {return mPlatFactory;}
88protected:
89    Hwcomposer(IPlatFactory *factory);
90
91public:
92    static Hwcomposer& getInstance() {
93        Hwcomposer *instance = sInstance;
94        if (instance == 0) {
95            instance = createHwcomposer();
96            sInstance = instance;
97        }
98        return *sInstance;
99    }
100    static void releaseInstance() {
101        delete sInstance;
102        sInstance = NULL;
103    }
104    // Need to be implemented
105    static Hwcomposer* createHwcomposer();
106
107
108private:
109    hwc_procs_t const *mProcs;
110    Drm *mDrm;
111
112    // plugin through set
113    IPlatFactory *mPlatFactory;
114    VsyncManager *mVsyncManager;
115    DisplayAnalyzer *mDisplayAnalyzer;
116    MultiDisplayObserver *mMultiDisplayObserver;
117    UeventObserver *mUeventObserver;
118
119    // created from IPlatFactory
120    DisplayPlaneManager *mPlaneManager;
121    BufferManager *mBufferManager;
122    IDisplayContext *mDisplayContext;
123
124    Vector<IDisplayDevice*> mDisplayDevices;
125
126    bool mInitialized;
127
128
129
130    static Hwcomposer *sInstance;
131};
132
133} // namespace intel
134}
135
136#endif /*HW_COMPOSER_H*/
137