Bug fix in screenshot for layer & surface
authorRahul Singhal <rasinghal@nvidia.com>
Thu, 1 Sep 2011 12:14:18 +0000 (17:44 +0530)
committerMichael Schuldt <michael.schuldt@bmw-carit.de>
Tue, 6 Sep 2011 06:32:08 +0000 (08:32 +0200)
This change checks for the following:
1. Whether the requested layer is part of the current render order.
2. Whether the requested surafce belongs to a layer that is part of
the current render order.

Now a surface's screenshot will be exactly similar to the way it
appears on the screen currently (minus the effect of other surfaces
part of the same layer).

LayerManagerCommands/src/ScreenShotCommand.cpp
LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/BaseWindowSystem.h
LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/X11WindowSystem.h
LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp
LayerManagerPlugins/Renderers/Platform/GLXRenderer/include/X11GLXRenderer.h
LayerManagerPlugins/Renderers/Platform/GLXRenderer/src/X11GLXRenderer.cpp
LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/include/X11GLESRenderer.h
LayerManagerPlugins/Renderers/Platform/X11GLESRenderer/src/X11GLESRenderer.cpp
LayerManagerService/include/IRenderer.h

index 8217a5b..a7c4695 100644 (file)
@@ -34,6 +34,7 @@ ExecutionResult ScreenShotCommand::execute(ICommandExecutor* executor)
     RendererList& m_rendererList = *(executor->getRendererList());
 
     bool status = false;
+    unsigned int layer_id = 0;
 
     LOG_INFO("LayerManager","making screenshot, output file: " << m_filename);
 
@@ -45,11 +46,53 @@ ExecutionResult ScreenShotCommand::execute(ICommandExecutor* executor)
             break;
 
         case ScreenshotOfLayer:
-            status = scene.getLayer(m_id);
+            if (scene.getLayer(m_id))
+            {
+                LayerListConstIterator iter = scene.getCurrentRenderOrder().begin();
+                LayerListConstIterator iterEnd = scene.getCurrentRenderOrder().end();
+                for (; iter != iterEnd; ++iter)
+                {
+                    if ((*iter)->getID() == m_id)
+                    {
+                        status = true;
+                        break;
+                    }
+                }
+                if (!status)
+                {
+                    LOG_WARNING("LayerManager","Requested layer: " << m_id << " does not belong to the current render order");
+                }
+            }
             break;
 
         case ScreenshotOfSurface:
-            status = scene.getSurface(m_id);
+            if (scene.getSurface(m_id))
+            {
+                LayerListConstIterator iter = scene.getCurrentRenderOrder().begin();
+                LayerListConstIterator iterEnd = scene.getCurrentRenderOrder().end();
+                for (; iter != iterEnd; ++iter)
+                {
+                    SurfaceListConstIterator s_iter = (*iter)->getAllSurfaces().begin();
+                    SurfaceListConstIterator s_iterEnd = (*iter)->getAllSurfaces().end();
+                    for (; s_iter != s_iterEnd; ++s_iter)
+                    {
+                        if ((*s_iter)->getID() == m_id)
+                        {
+                            layer_id = (*iter)->getID();
+                            status = true;
+                            break;
+                        }
+                    }
+                    if (status)
+                    {
+                        break;
+                    }
+                }
+                if (!status)
+                {
+                    LOG_WARNING("LayerManager","Requested surface: " << m_id << " does not belong to a layer which is part of the current render order");
+                }
+            }
             break;
 
         case ScreenShotNone:
@@ -88,7 +131,7 @@ ExecutionResult ScreenShotCommand::execute(ICommandExecutor* executor)
 
             case ScreenshotOfSurface:
             {
-                renderer->doScreenShotOfSurface(m_filename, m_id);
+                renderer->doScreenShotOfSurface(m_filename, m_id, layer_id);
                 break;
             }
 
index 6a6a70b..8687e00 100644 (file)
@@ -40,7 +40,7 @@ public:
     virtual void allocatePlatformSurface(Surface *surface) = 0;
     virtual void doScreenShot(std::string fileName) = 0;
     virtual void doScreenShotOfLayer(std::string fileName, const uint id) = 0;
-    virtual void doScreenShotOfSurface(std::string fileName, const uint id) = 0;
+    virtual void doScreenShotOfSurface(std::string fileName, const uint id, const uint layer_id) = 0;
 
 protected:
     Scene* m_pScene;
index 3294c3b..8b4136c 100644 (file)
@@ -54,12 +54,13 @@ public:
     virtual void allocatePlatformSurface(Surface *surface);
     void doScreenShot(std::string fileName);
     void doScreenShotOfLayer(std::string fileName, const uint id);
-    void doScreenShotOfSurface(std::string fileName, const uint id);
+    void doScreenShotOfSurface(std::string fileName, const uint id, const uint layer_id);
 
 private:
     ScreenShotType takeScreenshot;
     std::string screenShotFile;
-    uint screenShotID;
+    uint screenShotSurfaceID;
+    uint screenShotLayerID;
     const char* displayname;
     GetVisualInfoFunction getVisualFunc;
     BaseGraphicSystem<Display*, Window>* graphicSystem;
index 85e4d51..3d24422 100644 (file)
@@ -601,7 +601,7 @@ void X11WindowSystem::Screenshot()
                RedrawAllLayers();
        }else if(takeScreenshot==ScreenshotOfLayer){
                LOG_DEBUG("X11WindowSystem", "Taking screenshot of layer");
-               Layer* currentLayer = m_pScene->getLayer(screenShotID);
+               Layer* currentLayer = m_pScene->getLayer(screenShotLayerID);
                if (currentLayer!=NULL){
                        graphicSystem->beginLayer(currentLayer);
                        graphicSystem->renderLayer();
@@ -609,22 +609,13 @@ void X11WindowSystem::Screenshot()
                }
        }else if(takeScreenshot==ScreenshotOfSurface){
                LOG_DEBUG("X11WindowSystem", "Taking screenshot of surface");
-               Surface* currentSurface = m_pScene->getSurface(screenShotID);
-               if (NULL!=currentSurface){
-                       Layer* l = m_pScene->createLayer(GraphicalObject::INVALID_ID);
-            l->OriginalSourceWidth = windowWidth;
-            l->OriginalSourceHeight = windowHeight;
-                       l->setOpacity(1.0);
-                       l->setDestinationRegion(Rectangle(0,0,windowWidth,windowHeight));
-                       l->setSourceRegion(Rectangle(0,0,windowWidth,windowHeight));
-                       graphicSystem->beginLayer(l);
-                       graphicSystem->renderSurface(currentSurface);
-                       graphicSystem->endLayer();
-                       m_pScene->removeLayer(l);
-                       // layer is deleted in removeLayer.
-               }else{
-                       LOG_ERROR("X11WindowSystem", "Could not take screenshot of non existing surface");
-               }
+        Layer* currentLayer = m_pScene->getLayer(screenShotLayerID);
+               Surface* currentSurface = m_pScene->getSurface(screenShotSurfaceID);
+               if (currentLayer!=NULL && currentSurface!=NULL){
+            graphicSystem->beginLayer(currentLayer);
+            graphicSystem->renderSurface(currentSurface);
+            graphicSystem->endLayer();
+        }
        }
 
        graphicSystem->saveScreenShotOfFramebuffer(screenShotFile);
@@ -1014,13 +1005,14 @@ void X11WindowSystem::doScreenShotOfLayer(std::string fileName, const uint id)
 {
     takeScreenshot = ScreenshotOfLayer;
     screenShotFile = fileName;
-    screenShotID = id;
+    screenShotLayerID = id;
 }
 
-void X11WindowSystem::doScreenShotOfSurface(std::string fileName, const uint id)
+void X11WindowSystem::doScreenShotOfSurface(std::string fileName, const uint id, const uint layer_id)
 {
     takeScreenshot = ScreenshotOfSurface;
     screenShotFile = fileName;
-    screenShotID = id;
+    screenShotSurfaceID = id;
+    screenShotLayerID = layer_id;
 }
 
index b09f9d3..f66a409 100644 (file)
@@ -32,7 +32,7 @@ public:
     virtual ~X11GLXRenderer();
     void doScreenShot(std::string fileToSave);
     void doScreenShotOfLayer(std::string fileToSave, uint id);
-    void doScreenShotOfSurface(std::string fileToSave, uint id);
+    void doScreenShotOfSurface(std::string fileToSave, uint id, uint layer_id);
     uint getNumberOfHardwareLayers(uint screenID);
     uint* getScreenResolution(uint screenID);
     uint* getScreenIDs(uint* length);
index 7c2d096..9bede7d 100644 (file)
@@ -93,8 +93,8 @@ void X11GLXRenderer::doScreenShotOfLayer(std::string fileToSave,uint id)
     m_pWindowSystem->doScreenShotOfLayer(fileToSave,id);
 }
 
-void X11GLXRenderer::doScreenShotOfSurface(std::string fileToSave, uint id){
-    m_pWindowSystem->doScreenShotOfSurface(fileToSave,id);
+void X11GLXRenderer::doScreenShotOfSurface(std::string fileToSave, uint id, uint layer_id){
+    m_pWindowSystem->doScreenShotOfSurface(fileToSave,id,layer_id);
 }
 
 uint X11GLXRenderer::getNumberOfHardwareLayers(uint screenID)
index 95e1132..c4a4316 100644 (file)
@@ -33,7 +33,7 @@ public:
     void stop();
     void doScreenShot(std::string fileToSave);
     void doScreenShotOfLayer(std::string fileToSave, uint id);
-    void doScreenShotOfSurface(std::string fileToSave, uint id);
+    void doScreenShotOfSurface(std::string fileToSave, uint id, uint layer_id);
     uint getNumberOfHardwareLayers(uint screenID);
     uint* getScreenResolution(uint screenID);
     uint* getScreenIDs(uint* length);
index 55d57a1..a24444e 100644 (file)
@@ -103,9 +103,9 @@ void X11GLESRenderer::doScreenShotOfLayer(std::string fileToSave, uint id)
     m_pWindowSystem->doScreenShotOfLayer(fileToSave,id);
 }
 
-void X11GLESRenderer::doScreenShotOfSurface(std::string fileToSave, uint id)
+void X11GLESRenderer::doScreenShotOfSurface(std::string fileToSave, uint id, uint layer_id)
 {
-    m_pWindowSystem->doScreenShotOfSurface(fileToSave,id);
+    m_pWindowSystem->doScreenShotOfSurface(fileToSave,id,layer_id);
 }
 
 uint X11GLESRenderer::getNumberOfHardwareLayers(uint screenID)
index 78da4d0..4d0d7bf 100644 (file)
@@ -51,7 +51,7 @@ public:
 
     virtual void doScreenShot(std::string fileToSave) = 0;
     virtual void doScreenShotOfLayer(std::string fileToSave, const unsigned int id) = 0;
-    virtual void doScreenShotOfSurface(std::string fileToSave, const unsigned int id) = 0;
+    virtual void doScreenShotOfSurface(std::string fileToSave, const unsigned int id, const unsigned int layer_id) = 0;
 
     virtual unsigned int getLayerTypeCapabilities(LayerType layertype) = 0;