Merge "Build and package Layer Management service binaries." into tizen
[profile/ivi/layer-management.git] / LayerManagerPlugins / Renderers / Graphic / include / GraphicSystems / DrmGLESGraphicSystem.h
1 /***************************************************************************
2  *
3  * Copyright 2010,2011 BMW Car IT GmbH
4  * Copyright (C) 2011 DENSO CORPORATION and Robert Bosch Car Multimedia Gmbh
5  *
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  ****************************************************************************/
20
21 #ifndef _DRMGLESGRAPHICSYSTEM_H_
22 #define _DRMGLESGRAPHICSYSTEM_H_
23
24 #include "GraphicSystems/BaseGraphicSystem.h"
25 #include "GraphicSystems/GLESGraphicSystem.h"
26 #include "ShaderProgramFactory.h"
27 #include "EGL/egl.h"
28 #include "EGL/eglext.h"
29 #include "GLES2/gl2.h"
30 #include "GLES2/gl2ext.h"
31 #include "Log.h"
32 #include "Shader.h"
33
34 #include "wayland-util.h"
35
36 #include <xf86drm.h>
37 #include <xf86drmMode.h>
38
39 struct gbm_device;
40
41 struct DrmMode
42 {
43     uint32_t        flags;
44     int32_t         width;
45     int32_t         height;
46     uint32_t        refresh;
47     drmModeModeInfo modeInfo;
48     wl_list         link;
49 };
50
51 struct DrmOutput;
52 struct DrmFb
53 {
54     struct gbm_bo    *bo;
55     struct DrmOutput *output;
56     uint32_t          fbId;
57 };
58
59 struct DrmOutput
60 {
61     struct wl_list  link;
62     struct DrmMode* currentMode;
63     struct wl_list  modeList;
64     uint32_t        crtcID;
65     uint32_t        connectorID;
66     drmModeCrtcPtr  orgCrtc;
67     int             pageFlipPending;
68     int             fdDev;
69     struct gbm_surface *surface;
70     struct DrmFb       *current, *next;
71     EGLSurface  eglSurface;
72     uint32_t    screenID;
73     BaseWindowSystem *windowSystem;
74 };
75
76 class DrmGLESGraphicSystem : public GLESGraphicsystem
77 {
78 // functions
79 public:
80     DrmGLESGraphicSystem(int windowWidth, int windowHeight,
81                         PfnShaderProgramCreator shaderProgram);
82     virtual ~DrmGLESGraphicSystem();
83
84     virtual bool init(EGLNativeDisplayType display, EGLNativeWindowType window);
85     virtual void activateGraphicContext();
86     virtual void swapBuffers();
87     virtual void updateScreenList(LmScreenList& screenList);
88     virtual void switchScreen(uint screenid);
89
90 // proterties
91 private:
92     struct wl_list m_outputList;
93
94     gbm_device*    m_gbm;
95     int            m_fdDev;
96     uint32_t*      m_crtcs;
97     int            m_crtcsNum;
98     uint32_t       m_crtcAllocator;
99     uint32_t       m_connectorAllocator;
100     DrmOutput*     m_currentOutput;
101
102     PFNEGLBINDWAYLANDDISPLAYWL      m_pfEglBindWaylandDisplayWL;
103     PFNEGLUNBINDWAYLANDDISPLAYWL    m_pfEglUnbindWaylandDisplayWL;
104
105 // private functions
106 private:
107     bool initializeSystem();
108     bool createOutputs();
109     int  createOutputForConnector(drmModeRes* resources, drmModeConnector* connector, int x, int y);
110     int  drmOutputAddMode(struct DrmOutput* output, drmModeModeInfo* info);
111     int  drmOutputPrepareRender(struct DrmOutput* output);
112 };
113
114 #endif /* _DRMGLESGRAPHICSYSTEM_H_ */