1 /***************************************************************************
3 * Copyright 2010 BMW Car IT GmbH
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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 ****************************************************************************/
20 #include "X11GLXRenderer.h"
22 #include "GraphicSystems/GLXGraphicsystem.h"
23 #include "WindowSystems/X11WindowSystem.h"
24 #include "TextureBinders/X11CopyGLX.h"
25 #include "TextureBinders/X11TextureFromPixmap.h"
29 X11GLXRenderer::X11GLXRenderer(Scene* pScene)
30 : BaseRenderer(pScene)
38 bool X11GLXRenderer::start(int width, int height, const char* displayname)
41 ITextureBinder *binder = NULL;
42 LOG_DEBUG("X11GLXRenderer", "creating X11GLXRenderer");
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);
51 LOG_DEBUG("X11GLXRenderer", "init windowsystem");
52 if ( m_pWindowSystem->init(m_pGraphicSystem ) )
54 Display* x11Display = m_pWindowSystem->getNativeDisplayHandle();
57 GLXFBConfig *currentConfig = m_pGraphicSystem->GetMatchingPixmapConfig(x11Display);
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())
66 binder = new X11TextureFromPixmap(x11Display, *currentConfig);
70 binder = new X11CopyGLX(x11Display);
72 #endif // WITH_FORCE_COPY
75 m_pGraphicSystem->setTextureBinder(binder);
76 result = m_pWindowSystem->start();
84 void X11GLXRenderer::stop()
86 m_pWindowSystem->stop();
89 X11GLXRenderer::~X11GLXRenderer()
91 delete m_pWindowSystem;
94 void X11GLXRenderer::doScreenShot(std::string fileToSave)
96 m_pWindowSystem->doScreenShot(fileToSave);
99 void X11GLXRenderer::doScreenShotOfLayer(std::string fileToSave,uint id)
101 m_pWindowSystem->doScreenShotOfLayer(fileToSave,id);
104 void X11GLXRenderer::doScreenShotOfSurface(std::string fileToSave, uint id, uint layer_id){
105 m_pWindowSystem->doScreenShotOfSurface(fileToSave,id,layer_id);
108 uint X11GLXRenderer::getNumberOfHardwareLayers(uint screenID)
111 screen_id = screenID;
115 uint* X11GLXRenderer::getScreenResolution(uint screenID)
118 screen_id = screenID;
120 uint * resolution = new uint[2];
121 resolution[0] = m_width;
122 resolution[1] = m_height;
126 uint* X11GLXRenderer::getScreenIDs(uint* length)
128 Display* x11Display = m_pWindowSystem->getNativeDisplayHandle();
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++)
140 *length = numberOfScreens;
144 void X11GLXRenderer::signalWindowSystemRedraw()
146 m_pWindowSystem->signalRedrawEvent();
149 void X11GLXRenderer::forceCompositionWindowSystem()
151 m_pWindowSystem->m_damaged = true;
154 extern "C" IRenderer* createX11GLXRenderer(Scene* pScene) {
155 return new X11GLXRenderer(pScene);
158 extern "C" void destroyX11GLXRenderer(X11GLXRenderer* p)