/***************************************************************************
-*
-* Copyright 2010 BMW Car IT GmbH
-*
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*
-****************************************************************************/
+ *
+ * Copyright 2010 BMW Car IT GmbH
+ *
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ ****************************************************************************/
#include "GraphicSystems/GLESGraphicSystem.h"
-
+#include "IlmMatrix.h"
#include "string.h"
#include "EGL/egl.h"
#include "GLES2/gl2.h"
+#include "Bitmap.h"
static const float vertices[8*12] = {
- 0.0, 0.0,
- 1.0, 0.0,
- 1.0, 1.0,
- 1.0, 1.0,
- 0.0, 1.0,
- 0.0, 0.0,
-
- 0.0, 0.0,
- 1.0, 0.0,
- 1.0, 1.0,
- 1.0, 1.0,
- 0.0, 1.0,
- 0.0, 0.0,
-
- 0.0, 0.0,
- 1.0, 0.0,
- 1.0, 1.0,
- 1.0, 1.0,
- 0.0, 1.0,
- 0.0, 0.0,
-
- 1.0, 0.0,
- 1.0, 1.0,
- 0.0, 1.0,
- 0.0, 1.0,
- 0.0, 0.0,
- 1.0, 0.0,
-
- 0.0, 0.0,
- 1.0, 0.0,
- 1.0, 1.0,
- 1.0, 1.0,
- 0.0, 1.0,
- 0.0, 0.0,
-
- 1.0, 1.0,
- 0.0, 1.0,
- 0.0, 0.0,
- 0.0, 0.0,
- 1.0, 0.0,
- 1.0, 1.0,
-
- 0.0, 0.0,
- 1.0, 0.0,
- 1.0, 1.0,
- 1.0, 1.0,
- 0.0, 1.0,
- 0.0, 0.0,
-
- 0.0, 1.0,
- 0.0, 0.0,
- 1.0, 0.0,
- 1.0, 0.0,
- 1.0, 1.0,
- 0.0, 1.0
+ 0.0, 0.0,
+ 1.0, 0.0,
+ 1.0, 1.0,
+ 1.0, 1.0,
+ 0.0, 1.0,
+ 0.0, 0.0,
+
+ 0.0, 0.0,
+ 1.0, 0.0,
+ 1.0, 1.0,
+ 1.0, 1.0,
+ 0.0, 1.0,
+ 0.0, 0.0,
+
+ 0.0, 0.0,
+ 1.0, 0.0,
+ 1.0, 1.0,
+ 1.0, 1.0,
+ 0.0, 1.0,
+ 0.0, 0.0,
+
+ 1.0, 0.0,
+ 1.0, 1.0,
+ 0.0, 1.0,
+ 0.0, 1.0,
+ 0.0, 0.0,
+ 1.0, 0.0,
+
+ 0.0, 0.0,
+ 1.0, 0.0,
+ 1.0, 1.0,
+ 1.0, 1.0,
+ 0.0, 1.0,
+ 0.0, 0.0,
+
+ 1.0, 1.0,
+ 0.0, 1.0,
+ 0.0, 0.0,
+ 0.0, 0.0,
+ 1.0, 0.0,
+ 1.0, 1.0,
+
+ 0.0, 0.0,
+ 1.0, 0.0,
+ 1.0, 1.0,
+ 1.0, 1.0,
+ 0.0, 1.0,
+ 0.0, 0.0,
+
+ 0.0, 1.0,
+ 0.0, 0.0,
+ 1.0, 0.0,
+ 1.0, 0.0,
+ 1.0, 1.0,
+ 0.0, 1.0
};
-GLESGraphicsystem::GLESGraphicsystem(PfnShaderProgramCreator shaderProgram, ITextureBinder* binder ) : m_shaderCreatorFunc(shaderProgram){
- LOG_DEBUG("GLESGraphicsystem", "creating GLESGraphicsystem");
- m_binder = binder;
+GLESGraphicsystem::GLESGraphicsystem(PfnShaderProgramCreator shaderProgram, ITextureBinder* binder ) : m_shaderCreatorFunc(shaderProgram), takescreenshot(false){
+ LOG_DEBUG("GLESGraphicsystem", "creating GLESGraphicsystem");
+ m_binder = binder;
};
bool GLESGraphicsystem::init(void* displayPtr, void* WIndowIDPtr,int WindowHeight, int WindowWidth){
- EGLNativeDisplayType display = *(EGLNativeDisplayType*)displayPtr;
- LOG_DEBUG("GLESGraphicsystem", "Using EGLNativeDisplay:" << display);
- EGLNativeWindowType WIndowID = *(EGLNativeWindowType*)WIndowIDPtr;
- LOG_DEBUG("GLESGraphicsystem", "Using EGLNativeWindow:" << WIndowID);
-
- EGLint iMajorVersion, iMinorVersion;
- LOG_DEBUG("GLESGraphicsystem", "Getting EGL Display");
- m_eglDisplay = eglGetDisplay(display);
-
- LOG_DEBUG("GLESGraphicsystem", "Initialising EGL");
- if (!eglInitialize(m_eglDisplay, &iMajorVersion, &iMinorVersion))
- return false;
-
- LOG_DEBUG("GLESGraphicsystem", "Binding GLES API");
- eglBindAPI(EGL_OPENGL_ES_API);
-
- EGLint pi32ConfigAttribs[]={
- EGL_SURFACE_TYPE,EGL_WINDOW_BIT | EGL_PIXMAP_BIT,
- EGL_RENDERABLE_TYPE,EGL_OPENGL_ES2_BIT,
- EGL_ALPHA_SIZE,8,
- EGL_NONE
- };
-
- LOG_DEBUG("GLESGraphicsystem", "EGLChooseConfig");
- int iConfigs;
- if (!eglChooseConfig(m_eglDisplay, pi32ConfigAttribs, &m_eglConfig, 1, &iConfigs) || (iConfigs != 1))
- {
- LOG_DEBUG("GLESGraphicsystem", "Error: eglChooseConfig() failed.");
- return false;
- }
- EGLint id =0;
- eglGetConfigAttrib(m_eglDisplay, m_eglConfig, EGL_CONFIG_ID, &id);
-
- LOG_DEBUG("GLESGraphicsystem", "Config chosen:" << id);
- LOG_DEBUG("GLESGraphicsystem", "Create Window surface");
-
- m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, WIndowID, NULL);
- if (!m_eglSurface){
- LOG_DEBUG("GLESGraphicsystem", "create unsucessfull");
- }else{
- LOG_DEBUG("GLESGraphicsystem", "create successfull");
- }
- EGLint contextAttrs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
- m_eglContext = eglCreateContext(m_eglDisplay,
- m_eglConfig,
- NULL,
- contextAttrs);
- if (!m_eglContext)
+ EGLNativeDisplayType display = *(EGLNativeDisplayType*)displayPtr;
+ LOG_DEBUG("GLESGraphicsystem", "Using EGLNativeDisplay:" << display);
+ EGLNativeWindowType WIndowID = *(EGLNativeWindowType*)WIndowIDPtr;
+ LOG_DEBUG("GLESGraphicsystem", "Using EGLNativeWindow:" << WIndowID);
+
+ EGLint iMajorVersion, iMinorVersion;
+ LOG_DEBUG("GLESGraphicsystem", "Getting EGL Display");
+ m_eglDisplay = eglGetDisplay(display);
+
+ LOG_DEBUG("GLESGraphicsystem", "Initialising EGL");
+ if (!eglInitialize(m_eglDisplay, &iMajorVersion, &iMinorVersion))
+ return false;
+
+ LOG_DEBUG("GLESGraphicsystem", "Binding GLES API");
+ eglBindAPI(EGL_OPENGL_ES_API);
+
+ EGLint pi32ConfigAttribs[]={
+ EGL_SURFACE_TYPE,EGL_WINDOW_BIT | EGL_PIXMAP_BIT,
+ EGL_RENDERABLE_TYPE,EGL_OPENGL_ES2_BIT,
+ EGL_ALPHA_SIZE,8,
+ EGL_NONE
+ };
+
+ LOG_DEBUG("GLESGraphicsystem", "EGLChooseConfig");
+ int iConfigs;
+ if (!eglChooseConfig(m_eglDisplay, pi32ConfigAttribs, &m_eglConfig, 1, &iConfigs) || (iConfigs != 1))
+ {
+ LOG_DEBUG("GLESGraphicsystem", "Error: eglChooseConfig() failed.");
+ return false;
+ }
+ EGLint id =0;
+ eglGetConfigAttrib(m_eglDisplay, m_eglConfig, EGL_CONFIG_ID, &id);
+
+ LOG_DEBUG("GLESGraphicsystem", "Config chosen:" << id);
+ LOG_DEBUG("GLESGraphicsystem", "Create Window surface");
+
+ m_eglSurface = eglCreateWindowSurface(m_eglDisplay, m_eglConfig, WIndowID, NULL);
+ if (!m_eglSurface){
+ LOG_DEBUG("GLESGraphicsystem", "create unsucessfull");
+ }else{
+ LOG_DEBUG("GLESGraphicsystem", "create successfull");
+ }
+ EGLint contextAttrs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE };
+ m_eglContext = eglCreateContext(m_eglDisplay,
+ m_eglConfig,
+ NULL,
+ contextAttrs);
+ if (!m_eglContext)
{
- LOG_ERROR("GLESGraphicsystem","EGL couldn't create context\n");
- return false;
+ LOG_ERROR("GLESGraphicsystem","EGL couldn't create context\n");
+ return false;
}
- LOG_INFO("GLESGraphicsystem", "EGL make current ...");
- // Make the context and surface current for rendering
- EGLBoolean eglStatus = false;
- eglStatus = eglMakeCurrent(m_eglDisplay,
- m_eglSurface, m_eglSurface,
- m_eglContext);
- LOG_INFO("GLESGraphicsystem", "made current");
+ LOG_INFO("GLESGraphicsystem", "EGL make current ...");
+ // Make the context and surface current for rendering
+ EGLBoolean eglStatus = false;
+ eglStatus = eglMakeCurrent(m_eglDisplay,
+ m_eglSurface, m_eglSurface,
+ m_eglContext);
+ LOG_INFO("GLESGraphicsystem", "made current");
- if (!initOpenGLES(WindowWidth,WindowHeight) )
- {
- return false;
- }
- return true;
+ if (!initOpenGLES(WindowWidth,WindowHeight) )
+ {
+ return false;
+ }
+ return true;
}
void GLESGraphicsystem::clearBackground()
{
- glClear(GL_COLOR_BUFFER_BIT);
+ glClear(GL_COLOR_BUFFER_BIT);
}
void GLESGraphicsystem::swapBuffers()
{
- eglSwapBuffers(m_eglDisplay,m_eglSurface);
+ eglSwapBuffers(m_eglDisplay,m_eglSurface);
+ // check if we are ordered to take screenshot at next possible moment
+ // taking right after swap ensures that we obtain full image
+ if (takescreenshot){
+ takescreenshot = false;
+ saveScreenShot();
+ }
}
void GLESGraphicsystem::drawSurface(Layer* currentLayer,Surface* surface)
{
- ShaderProgram::CommonUniforms uniforms;
- Shader* layerShader = currentLayer->getShader();
- if (!layerShader)
- {
- // use default shader if no custom shader is assigned to this layer
- layerShader = defaultShader;
- }
- Shader* shader = (surface)->getShader();
- if (!shader)
- {
- // use layer shader if no custom shader is assigned to this surface
- shader = layerShader;
- }
- Rectangle dest = (surface)->getDestinationRegion();
- Rectangle src = (surface)->getSourceRegion();
- float surfaceXOfScreen = (float) dest.x / m_displayWidth;
- float surfaceYOfScreen = (float) dest.y / m_displayHeight;
- float surfaceWidthOfScreen = (float) dest.width / m_displayWidth;
- float surfaceHeightOfScreen = (float) dest.height / m_displayHeight;
-
- float sourceViewportWidthPercent = (float)src.width/(surface)->OriginalSourceWidth;
- float sourceViewportHeightpercent = (float)src.height/(surface)->OriginalSourceHeight;
- float sourceViewportXPercent = (float)src.x/(surface)->OriginalSourceWidth;
- float sourceViewportYPercent = (float)src.y/(surface)->OriginalSourceHeight;
-
- // LOG_INFO("GLESGraphicsystem", "Binding Buffer");
- glBindBuffer(GL_ARRAY_BUFFER,m_vbo);
-
- // LOG_INFO("GLESGraphicsystem", "Binding Buffer done");
- shader->use();
-
- // LOG_INFO("GLESGraphicsystem", "Update Uniforms");
- // update all common uniforms
- uniforms.x = surfaceXOfScreen;
- uniforms.y = surfaceYOfScreen;
- uniforms.width = surfaceWidthOfScreen;
- uniforms.height = surfaceHeightOfScreen;
- uniforms.opacity = (surface)->getOpacity() * currentLayer->getOpacity();
- uniforms.texRange[0] = sourceViewportWidthPercent;
- uniforms.texRange[1] = sourceViewportHeightpercent;
- uniforms.texOffset[0] = sourceViewportXPercent;
- uniforms.texOffset[1] = -sourceViewportYPercent;
- uniforms.texUnit = 0;
-
- // LOG_INFO("GLESGraphicsystem", "Load Common Uniforms");
- shader->loadCommonUniforms(uniforms);
-
- // LOG_INFO("GLESGraphicsystem", "Load Custom Uniforms");
- // update all custom defined uniforms
- shader->loadUniforms();
- /* Bind texture and set section */
- glActiveTexture(GL_TEXTURE0);
- m_binder->bindSurfaceTexture(surface);
-
- // rotated positions are saved sequentially in vbo
- // offset in multiples of 12 decide rotation
- int orientation = (surface)->getOrientation() + (currentLayer)->getOrientation();
- orientation %= 4;
- int index = orientation * 12;
-// LOG_INFO("GLESGraphicsystem", "Drawing surface");
- // Draw two triangles
- glDrawArrays(GL_TRIANGLES, 0, 6);
- // get the next surface
- glBindBuffer(GL_ARRAY_BUFFER,NULL);
-// LOG_INFO("GLESGraphicsystem", "Drawing surface done");
-// LOG_INFO("GLESGraphicsystem", "Drawing surface done now checking for error");
- GLenum status = glGetError();
+ GLint index = 0;
+ IlmMatrix layerMatrix;
+ IlmMatrixIdentity(layerMatrix);
+ Rectangle layerdest = (currentLayer)->getDestinationRegion();
+ Rectangle layersrc = (currentLayer)->getSourceRegion();
+
+ float scalex = (float)layerdest.width / (float) m_displayWidth;
+ float scaley = (float)layerdest.height / (float) m_displayHeight;
+ ShaderProgram::CommonUniforms uniforms;
+#ifdef DRAW_LAYER_DEBUG
+ ShaderProgram::CommonUniforms layeruniforms;
+#endif
+ Shader* layerShader = currentLayer->getShader();
+ if (!layerShader)
+ {
+ // use default shader if no custom shader is assigned to this layer
+ layerShader = m_defaultShader;
+ }
+ Shader* shader = (surface)->getShader();
+ if (!shader)
+ {
+ // use layer shader if no custom shader is assigned to this surface
+ shader = layerShader;
+ }
+ Rectangle dest = (surface)->getDestinationRegion();
+ Rectangle src = (surface)->getSourceRegion();
+
+
+ float surfaceXOfScreen = (float) dest.x / (float) layerdest.width + (float) layerdest.x / m_displayWidth ;
+ float surfaceYOfScreen = (float) dest.y / (float) layerdest.height + (float) layerdest.y / m_displayHeight ;
+ float surfaceWidthOfScreen = ((float) dest.width / m_displayWidth ) * scalex;
+ float surfaceHeightOfScreen = ((float) dest.height / m_displayHeight ) * scaley;
+
+ float sourceViewportWidthPercent = (float)src.width/(surface)->OriginalSourceWidth;
+ float sourceViewportHeightpercent = (float)src.height/(surface)->OriginalSourceHeight;
+ float sourceViewportXPercent = (float)src.x/(surface)->OriginalSourceWidth;
+ float sourceViewportYPercent = (float)src.y/(surface)->OriginalSourceHeight;
+
+ glBindBuffer(GL_ARRAY_BUFFER,m_vbo);
+ IlmMatrixRotateZ(layerMatrix,currentLayer->getOrientation()*90.0f);
+ /* update all common uniforms */
+ uniforms.x = surfaceXOfScreen;
+ uniforms.y = surfaceYOfScreen;
+ uniforms.width = surfaceWidthOfScreen;
+ uniforms.height = surfaceHeightOfScreen;
+ uniforms.opacity = (surface)->getOpacity() * currentLayer->getOpacity();
+ uniforms.texRange[0] = sourceViewportWidthPercent;
+ uniforms.texRange[1] = sourceViewportHeightpercent;
+ uniforms.texOffset[0] = sourceViewportXPercent;
+ uniforms.texOffset[1] = -sourceViewportYPercent;
+ uniforms.texUnit = 0;
+ uniforms.matrix = &layerMatrix.f[0];
+
+#ifdef DRAW_LAYER_DEBUG
+ layeruniforms.x = (float) layerdest.x / m_displayWidth;
+ layeruniforms.y = (float) layerdest.y / m_displayHeight;
+ layeruniforms.width = (float)layerdest.width / m_displayWidth;
+ layeruniforms.height = (float)layerdest.height / m_displayHeight;
+ layeruniforms.opacity = currentLayer->getOpacity();
+ layeruniforms.matrix = &layerMatrix.f[0];
+ m_layerShader->use();
+ m_layerShader->loadCommonUniforms(layeruniforms);
+ m_layerShader->loadUniforms();
+
+ glDrawArrays(GL_TRIANGLES, 0, 6);
+#endif
+ shader->use();
+
+ /* load common uniforms */
+ shader->loadCommonUniforms(uniforms);
+
+
+ /* update all custom defined uniforms */
+ shader->loadUniforms();
+ /* Bind texture and set section */
+ glActiveTexture(GL_TEXTURE0);
+ m_binder->bindSurfaceTexture(surface);
+
+ /* rotated positions are saved sequentially in vbo
+ offset in multiples of 12 decide rotation */
+ /* Draw two triangles */
+ int orientation = (surface)->getOrientation();
+ orientation %= 4;
+ index = orientation * 12;
+
+ glDrawArrays(GL_TRIANGLES, index, 6);
+
+ glBindBuffer(GL_ARRAY_BUFFER,NULL);
+
+ GLenum status = glGetError();
}
bool GLESGraphicsystem::initOpenGLES(EGLint displayWidth,EGLint displayHeight)
{
- LOG_DEBUG("GLESGraphicsystem", "initEGL");
- bool result = true;
- ShaderProgramFactory::setCreatorFunc(m_shaderCreatorFunc);
- defaultShader = Shader::createShader("default", "default");
- if (!defaultShader)
+ LOG_DEBUG("GLESGraphicsystem", "initEGL");
+ bool result = true;
+ ShaderProgramFactory::setCreatorFunc(m_shaderCreatorFunc);
+ m_defaultShader = Shader::createShader("default", "default");
+#ifdef DRAW_LAYER_DEBUG
+ m_layerShader = Shader::createShader("renderer_layer.glslv", "renderer_layer.glslf");
+#endif
+ if (
+ !m_defaultShader
+#ifdef DRAW_LAYER_DEBUG
+ || !m_layerShader
+#endif
+ )
{
- LOG_ERROR("GLESGraphicsystem", "Failed to create and link default shader program");
- delete defaultShader;
- result = false;
+ LOG_ERROR("GLESGraphicsystem", "Failed to create and link default shader program");
+ delete m_defaultShader;
+ result = false;
}
- else
- {
- LOG_INFO("GLESGraphicsystem", "Default Shader successfully applied");
- glGenBuffers(1,&m_vbo);
- glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
- glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)(sizeof(float) *12));
- glEnableVertexAttribArray(1);
-
- glEnable (GL_BLEND);
- glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- m_blendingStatus = true;
- glClearColor(1.0, 0.0, 0.0, 1.0);
- resize(displayWidth,displayHeight);
- }
- return result;
+ else
+ {
+ LOG_INFO("GLESGraphicsystem", "Default Shader successfully applied");
+ glGenBuffers(1,&m_vbo);
+ glBindBuffer(GL_ARRAY_BUFFER, m_vbo);
+ glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
+ glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
+ glEnableVertexAttribArray(0);
+ glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, (void*)(sizeof(float) *12));
+ glEnableVertexAttribArray(1);
+
+ glEnable (GL_BLEND);
+ glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ m_blendingStatus = true;
+ glClearColor(1.0, 1.0, 1.0, 1.0);
+ resize(displayWidth,displayHeight);
+ }
+ return result;
}
void GLESGraphicsystem::resize(EGLint displayWidth,EGLint displayHeight)
{
- m_displayWidth = displayWidth;
- m_displayHeight = displayHeight;
- glViewport(0, 0, m_displayWidth, m_displayHeight);
+ m_displayWidth = displayWidth;
+ m_displayHeight = displayHeight;
+ glViewport(0, 0, m_displayWidth, m_displayHeight);
+}
+
+void GLESGraphicsystem::saveScreenShot(){
+ {
+ // clear error if any
+ int error = glGetError();
+ LOG_DEBUG("BaseGraphicSystem","taking screenshot and saving it to:" << screenShotFile);
+
+ GLint viewport[4];
+ glGetIntegerv(GL_VIEWPORT,viewport); // x,y,width,height
+ error = glGetError();
+ if (error != GL_NO_ERROR)
+ LOG_DEBUG("BaseGraphicSystem","error getting dimensions");
+ int WINDOW_WIDTH= viewport[2];
+ int WINDOW_HEIGHT= viewport[3];
+ LOG_DEBUG("BaseGraphicSystem","Screenshot: " << WINDOW_WIDTH << " * " << WINDOW_HEIGHT);
+ char *buffer = (char *)malloc(WINDOW_WIDTH * WINDOW_HEIGHT * 4 * sizeof(char));
+ glReadPixels(0,0,WINDOW_WIDTH,WINDOW_HEIGHT,GL_RGBA,GL_UNSIGNED_BYTE, buffer);
+ error = glGetError();
+ if (error != GL_NO_ERROR)
+ LOG_DEBUG("BaseGraphicSystem","error reading pixels for screenshot: " << error);
+ // convert to RGB for bitmap
+ int pixelcount = WINDOW_WIDTH * WINDOW_HEIGHT;
+ char *rgbbuffer = (char *)malloc(pixelcount*3 * sizeof(char));
+ for (int row=0;row<WINDOW_HEIGHT;row++ ){
+ for (int col=0;col<WINDOW_WIDTH;col++){
+ int offset = row*WINDOW_WIDTH+col;
+ rgbbuffer[offset*3] = buffer[offset*4+2];
+ rgbbuffer[offset*3+1] = buffer[offset*4+1];
+ rgbbuffer[offset*3+2] = buffer[offset*4];
+ }
+ }
+
+ writeBitmap(screenShotFile,rgbbuffer,WINDOW_WIDTH,WINDOW_HEIGHT);
+ free(buffer);
+ }
+}
+
+void GLESGraphicsystem::doScreenShot(std::string fileToSave){
+ screenShotFile = fileToSave;
+ takescreenshot=true;
}
};
+X11WindowSystem::~X11WindowSystem(){
+ delete graphicSystem;
+}
+
XVisualInfo* X11WindowSystem::getDefaultVisual(Display *dpy)
{
XVisualInfo* windowVis = new XVisualInfo();
const std::map<int,Surface*> surfaces = layerlist->getAllSurfaces();
for(std::map<int, Surface*>::const_iterator currentS = surfaces.begin(); currentS != surfaces.end(); currentS++){
Surface* currentSurface = (*currentS).second;
- XPlatformSurface* x11surf = NULL;
- if (NULL != currentSurface->platform){
- x11surf = (XPlatformSurface*)currentSurface->platform;
- if (currentSurface->nativeHandle == w){
- LOG_DEBUG("X11WindowSystem", "surface " << currentSurface->getID() << " corresponds to window" << w);
- return currentSurface;
- }
- }
+ LOG_DEBUG("X11WindowSystem", "CurrentSurface surface for window " << currentSurface->getID());
+ LOG_DEBUG("X11WindowSystem", "CurrentSurface nativeHandle " << currentSurface->nativeHandle);
+ if (currentSurface->nativeHandle == w){
+ LOG_DEBUG("X11WindowSystem", "surface " << currentSurface->getID() << " corresponds to window" << w);
+ return currentSurface;
+ }
}
LOG_DEBUG("X11WindowSystem", "could not find surface for window " << w);
return NULL;
LOG_DEBUG("X11WindowSystem", "Done mapping");
}
}
- LOG_INFO("EglXCompositeRenderer","mapping end");
+ LOG_INFO("X11WindowSystem","mapping end");
}
void X11WindowSystem::UnMapWindow(Window window){
}
void X11WindowSystem::DestroyWindow(Window window){
- if (isWindowValid(window)){
+ if (isWindowValid(window))
+ {
LOG_DEBUG("X11WindowSystem", "Destroying Surface for window " << window);
Surface* surface = getSurfaceForWindow(window);
if (surface==NULL){
}
graphicSystem->m_binder->destroyClientBuffer(surface);
UnMapWindow(window);
- layerlist->removeSurface(surface);
- LOG_DEBUG("X11WindowSystem", "Removed Surface " << surface->getID());
- }
+ LOG_DEBUG("X11WindowSystem", "Removed Surface " << surface->getID());
+ layerlist->lockList();
+ layerlist->removeSurface(surface);
+ layerlist->unlockList();
+ }
}
bool
return result;
}
-
-
-
bool X11WindowSystem::CreateCompositorWindow()
{
LOG_DEBUG("X11WindowSystem", "Get root window");
0, windowVis->depth, InputOutput,
windowVis->visual, CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &attr);
-
if (!CompositorWindow)
{
LOG_ERROR("X11WindowSystem", "Could not create window");
{
// draw all the layers
graphicSystem->clearBackground();
+ /*LOG_INFO("X11WindowSystem","Locking List");*/
+ layerlist->lockList();
std::list<Layer*> layers = layerlist->getCurrentRenderOrder();
- for(std::list<Layer*>::const_iterator current = layers.begin(); current != layers.end(); current++){
+ for(std::list<Layer*>::const_iterator current = layers.begin(); current != layers.end(); current++)
+ {
Layer* currentLayer = (Layer*)*current;
- if ((*currentLayer).visibility && (*currentLayer).opacity>0.0f){
- // glRotated(-90*currentLayer->getOrientation(),0,0,1.0);
- // draw all the surfaces of the layer
+ if ((*currentLayer).visibility && (*currentLayer).opacity>0.0f)
+ {
+ /*LOG_INFO("X11WindowSystem","Draw Layer " << currentLayer->getID());*/
std::list<Surface*> surfaces = currentLayer->surfaces;
- for(std::list<Surface*>::const_iterator currentS = surfaces.begin(); currentS != surfaces.end(); currentS++){
- if ((*currentS)->visibility && (*currentS)->opacity>0.0f){
+ for(std::list<Surface*>::const_iterator currentS = surfaces.begin(); currentS != surfaces.end(); currentS++)
+ {
+ /*LOG_INFO("X11WindowSystem","Surface to draw " << (*currentS)->getID());*/
+ if ((*currentS)->visibility && (*currentS)->opacity>0.0f)
+ {
Surface* currentSurface = (Surface*)*currentS;
XPlatformSurface* nativeSurface = (XPlatformSurface*)currentSurface->platform;
if (NULL==nativeSurface)
{
- LOG_INFO("X11WindowSystem","creating native surface for new window");
+ /*LOG_INFO("X11WindowSystem","creating native surface for new window");*/
// this surface does not have a native platform surface attached yet!
NewWindow(currentSurface,currentSurface->nativeHandle);
MapWindow(currentSurface->nativeHandle);
}
+ /*LOG_INFO("X11WindowSystem","Drawing Layer begin");*/
graphicSystem->drawSurface(currentLayer,currentSurface);
-
- }
- }
- }
- }
-
+ /*LOG_INFO("X11WindowSystem","Drawing Layer end");*/
+ }
+ }
+ }
+ }
if (debugMode)
{
printDebug(200,windowHeight-40);
{
LOG_INFO("X11WindowSystem",floatStringBuffer);
}
- graphicSystem->swapBuffers();
+ layerlist->unlockList();
+ /*LOG_INFO("X11WindowSystem","UnLocking List");*/
+ graphicSystem->swapBuffers();
}
int
XMapRaised(x11Display, w);
}
}
+ XFree(name);
}
XFree(children);
XUngrabServer (x11Display);
Layer* defaultLayer;
// run the main event loop while rendering
- bool running = windowsys->m_success;
+ windowsys->m_running = m_success;
gettimeofday(&tv0, NULL);
FramesPerFPS = 30;
if (windowsys->debugMode)
{
- defaultLayer = windowsys->layerlist->createLayer();
+ defaultLayer = windowsys->layerlist->createLayer(-1);
defaultLayer->setOpacity(1.0);
defaultLayer->setDestinationRegion(Rectangle(0,0,windowsys->resolutionWidth,windowsys->resolutionHeight));
defaultLayer->setSourceRegion(Rectangle(0,0,windowsys->resolutionWidth,windowsys->resolutionHeight));
windowsys->layerlist->getCurrentRenderOrder().push_back(defaultLayer);
}
LOG_DEBUG("X11WindowSystem", "Enter render loop");
- while (running)
+ while (windowsys->m_running)
{
if ( XPending(windowsys->x11Display) > 0) {
XEvent event;
if (windowsys->debugMode)
{
LOG_DEBUG("X11WindowSystem", "CreateNotify Event");
- Surface* s = windowsys->layerlist->createSurface();
+ Surface* s = windowsys->layerlist->createSurface(-1);
s->setOpacity(1.0);
windowsys->NewWindow(s, event.xcreatewindow.window);
defaultLayer->addSurface(s);
}
windowsys->Redraw();
}
+ windowsys->cleanup();
LOG_INFO("X11WindowSystem", "Renderer thread finished");
return NULL;
}
+void X11WindowSystem::cleanup(){
+ LOG_INFO("X11WindowSystem", "Cleanup");
+ Window root = RootWindow(x11Display, 0);
+ XCompositeUnredirectSubwindows(x11Display,root,CompositeRedirectManual);
+ XDestroyWindow(x11Display,CompositorWindow);
+ XCloseDisplay(x11Display);
+ m_initialized = false;
+ m_running = false;
+}
+
bool X11WindowSystem::start(int displayWidth, int displayHeight, const char* DisplayName){
LOG_INFO("X11WindowSystem", "Starting / Creating thread");
- pthread_t renderThread;
X11WindowSystem *renderer = this;
resolutionWidth = displayWidth;
resolutionHeight = displayHeight;
LOG_INFO("X11WindowSystem","Start complete " << m_initialized << " success " << m_success);
return m_success;
}
+
+void X11WindowSystem::stop(){
+ LOG_INFO("X11WindowSystem","Stopping..");
+ this->m_running = false;
+ pthread_join(renderThread,NULL);
+}
+