6c88aeeb0382eaed394a8e0ada564ade5a8e32e1
[profile/ivi/layer-management.git] / LayerManagerPlugins / Renderers / Platform / GLXRenderer / src / X11GLXRenderer.cpp
1 /***************************************************************************
2 *
3 * Copyright 2010 BMW Car IT GmbH
4 *
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 *        http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 ****************************************************************************/
19
20 #include "X11GLXRenderer.h"
21 #include "config.h"
22 #include "GraphicSystems/GLXGraphicsystem.h"
23 #include "WindowSystems/X11WindowSystem.h"
24 #include "TextureBinders/X11CopyGLX.h"
25 #include "TextureBinders/X11TextureFromPixmap.h"
26 #include "Log.h"
27 #include <string.h>
28
29 X11GLXRenderer::X11GLXRenderer(Scene* pScene)
30 : BaseRenderer(pScene)
31 , m_pWindowSystem(0)
32 , m_pGraphicSystem(0)
33 , m_width(0)
34 , m_height(0)
35 {
36 }
37
38 bool X11GLXRenderer::start(int width, int height, const char* displayname)
39 {
40     bool result = false;
41     ITextureBinder *binder = NULL;
42     LOG_DEBUG("X11GLXRenderer", "creating X11GLXRenderer");
43     m_width = width;
44     m_height = height;
45
46     // create X11 windows, register as composite manager etc
47     m_pWindowSystem  = new X11WindowSystem(displayname, width, height, m_pScene, GLXGraphicsystem::GetMatchingVisual);
48     m_pGraphicSystem = new GLXGraphicsystem(width, height);
49     m_pGraphicSystem->setBaseWindowSystem(m_pWindowSystem);
50
51     LOG_DEBUG("X11GLXRenderer", "init windowsystem");
52     if ( m_pWindowSystem->init(m_pGraphicSystem ) )
53     {
54         Display* x11Display = m_pWindowSystem->getNativeDisplayHandle();
55         if (x11Display)
56         {
57             GLXFBConfig *currentConfig = m_pGraphicSystem->GetMatchingPixmapConfig(x11Display);
58             if (currentConfig)
59             {
60                 LOG_INFO("X11GLXRenderer", "Initialization successful.");
61 #ifdef WITH_FORCE_COPY
62                 binder = new X11CopyGLX(x11Display);
63 #else // WITH_FORCE_COPY
64                 if (m_pGraphicSystem->isZeroCopyEnabled())
65                 {
66                     binder = new X11TextureFromPixmap(x11Display, *currentConfig);
67                 }
68                 else
69                 {
70                     binder = new X11CopyGLX(x11Display);
71                 }
72 #endif // WITH_FORCE_COPY
73                 if ( binder != NULL )
74                 {
75                     m_pGraphicSystem->setTextureBinder(binder);
76                     result = m_pWindowSystem->start();
77                 }
78             }
79         }
80     }
81     return result;
82 }
83
84 void X11GLXRenderer::stop()
85 {
86     m_pWindowSystem->stop();
87 }
88
89 X11GLXRenderer::~X11GLXRenderer()
90 {
91     delete m_pWindowSystem;
92 }
93
94 void X11GLXRenderer::doScreenShot(std::string fileToSave)
95 {
96     m_pWindowSystem->doScreenShot(fileToSave);
97 }
98
99 void X11GLXRenderer::doScreenShotOfLayer(std::string fileToSave,uint id)
100 {
101     m_pWindowSystem->doScreenShotOfLayer(fileToSave,id);
102 }
103
104 void X11GLXRenderer::doScreenShotOfSurface(std::string fileToSave, uint id, uint layer_id){
105     m_pWindowSystem->doScreenShotOfSurface(fileToSave,id,layer_id);
106 }
107
108 uint X11GLXRenderer::getNumberOfHardwareLayers(uint screenID)
109 {
110     uint screen_id;
111     screen_id = screenID;
112     return 0; // TODO
113 }
114
115 uint* X11GLXRenderer::getScreenResolution(uint screenID)
116 {
117     uint screen_id;
118     screen_id = screenID;
119     
120     uint * resolution = new uint[2];
121     resolution[0] = m_width;
122     resolution[1] = m_height;
123     return resolution;
124 }
125
126 uint* X11GLXRenderer::getScreenIDs(uint* length)
127 {
128     Display* x11Display = m_pWindowSystem->getNativeDisplayHandle();
129     if (!x11Display)
130     {
131         return NULL;
132     }
133     // Screens in X11 can be addresses/accessed by just the number - we must only know how many there are
134     uint numberOfScreens = ScreenCount(x11Display);
135     uint* screenIDS = new uint[numberOfScreens];
136     for (uint i = 0; i < numberOfScreens; i++)
137     {
138         screenIDS[i] = i;
139     }
140     *length = numberOfScreens;
141     return screenIDS;
142 }
143
144 void X11GLXRenderer::signalWindowSystemRedraw()
145 {
146     m_pWindowSystem->signalRedrawEvent();
147 }
148
149 void X11GLXRenderer::forceCompositionWindowSystem()
150 {
151     m_pWindowSystem->m_damaged = true;
152 }
153
154 extern "C" IRenderer* createX11GLXRenderer(Scene* pScene) {
155     return new X11GLXRenderer(pScene);
156 }
157
158 extern "C" void destroyX11GLXRenderer(X11GLXRenderer* p)
159 {
160     delete p;
161 }