From e30240d4e8ebcf50df4a42504306046ee969c52f Mon Sep 17 00:00:00 2001 From: Rahul Singhal Date: Mon, 25 Jun 2012 13:10:54 +0530 Subject: [PATCH] LayerManagerCommands: Add SurfaceRemoveNativeContentCommand Using this command a client can remove the native content associated with a surface. This can be used if multiple windows need to be used with the same surface. TODO: The backend for wayland needs to be filled in. --- LayerManagerClient/ilmClient/include/ilm_client.h | 9 +++ .../ilmClient/src/generic_ilm_client.c | 17 ++++++ .../include/SurfaceRemoveNativeContentCommand.h | 69 ++++++++++++++++++++++ .../src/SurfaceRemoveNativeContentCommand.cpp | 60 +++++++++++++++++++ .../include/GenericCommunicator.h | 2 + .../src/GenericCommunicator.cpp | 18 ++++++ .../IpcModules/DbusIpcModule/src/introspection.c | 1 + .../WindowSystems/WaylandBaseWindowSystem.h | 1 + .../include/WindowSystems/X11WindowSystem.h | 1 + .../src/WindowSystems/WaylandBaseWindowSystem.cpp | 22 +++++++ .../Graphic/src/WindowSystems/X11WindowSystem.cpp | 25 ++++++++ 11 files changed, 225 insertions(+) create mode 100644 LayerManagerCommands/include/SurfaceRemoveNativeContentCommand.h create mode 100644 LayerManagerCommands/src/SurfaceRemoveNativeContentCommand.cpp diff --git a/LayerManagerClient/ilmClient/include/ilm_client.h b/LayerManagerClient/ilmClient/include/ilm_client.h index 5125668..e43e0e1 100644 --- a/LayerManagerClient/ilmClient/include/ilm_client.h +++ b/LayerManagerClient/ilmClient/include/ilm_client.h @@ -511,6 +511,15 @@ ilmErrorTypes ilm_surfaceInitialize(t_ilm_surface *pSurfaceId); ilmErrorTypes ilm_surfaceSetNativeContent(t_ilm_nativehandle nativehandle, t_ilm_int width, t_ilm_int height, ilmPixelFormat pixelFormat, t_ilm_surface surfaceId); /** + * \brief Remove the native content of a surface + * \ingroup ilmClient + * \param[in] surfaceId The ID of the surface + * \return ILM_SUCCESS if the method call was successful + * \return ILM_FAILED if the client can not call the method on the service. + */ +ilmErrorTypes ilm_surfaceRemoveNativeContent(t_ilm_surface surfaceId); + +/** * \brief Remove a surface * \ingroup ilmClient * \param[in] surfaceId The id of the surface to be removed diff --git a/LayerManagerClient/ilmClient/src/generic_ilm_client.c b/LayerManagerClient/ilmClient/src/generic_ilm_client.c index f13720c..3d6ff95 100644 --- a/LayerManagerClient/ilmClient/src/generic_ilm_client.c +++ b/LayerManagerClient/ilmClient/src/generic_ilm_client.c @@ -956,6 +956,23 @@ ilmErrorTypes ilm_surfaceSetNativeContent(t_ilm_nativehandle nativehandle, t_ilm return returnValue; } +ilmErrorTypes ilm_surfaceRemoveNativeContent(t_ilm_surface surfaceId) +{ + LOG_ENTER_FUNCTION; + ilmErrorTypes returnValue = ILM_FAILED; + + if (gIpcModule.createMessage("RemoveSurfaceNativeContent\0") + && gIpcModule.appendUint(surfaceId) + && gIpcModule.sendMessage() + && gIpcModule.receiveMessage(gReceiveTimeout) + && !gIpcModule.isErrorMessage()) + { + returnValue = ILM_SUCCESS; + } + + return returnValue; +} + ilmErrorTypes ilm_surfaceRemove(t_ilm_surface surfaceId) { LOG_ENTER_FUNCTION; diff --git a/LayerManagerCommands/include/SurfaceRemoveNativeContentCommand.h b/LayerManagerCommands/include/SurfaceRemoveNativeContentCommand.h new file mode 100644 index 0000000..40bd212 --- /dev/null +++ b/LayerManagerCommands/include/SurfaceRemoveNativeContentCommand.h @@ -0,0 +1,69 @@ +/*************************************************************************** +* +* Copyright 2010,2011 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. +* +****************************************************************************/ + +#ifndef _SURFACEREMOVENATIVECONTENTCOMMAND_H_ +#define _SURFACEREMOVENATIVECONTENTCOMMAND_H_ + +#include "BaseCommandAsynchronous.h" +#include "PixelFormat.h" +#include "IScene.h" + +class SurfaceRemoveNativeContentCommand : public BaseCommandAsynchronous +{ +public: + /*! + * \action This command removes the native content (application content) + * of a surface within the GENIVI LayerManagement + * \frequency Typically should not be needed unless a client wants to + * re-use the surface with multiple contents. + * \param[in] surfaceId id of surface + * \ingroup Commands + */ + SurfaceRemoveNativeContentCommand(unsigned int surfaceId); + + /** + * \brief default destructor + */ + virtual ~SurfaceRemoveNativeContentCommand() {} + + /** + * \brief Execute this command. + * \param[in] executor Pointer to instance executing the LayerManagement COmmands + * \return ExecutionSuccess: execution successful + * \return ExecutionSuccessRedraw: execution successful and screen needs to be redrawn + * \return ExecutionFailed: execution failed + * \return ExecutionFailedRedraw: execution unsuccessful and screen needs to be redrawn + */ + virtual ExecutionResult execute(ICommandExecutor* executor); + + /** + * \brief Get description string for this command. + * \return String object with description of this command object + */ + virtual const std::string getString(); + +private: + uint m_surfaceId; + + // for unit testing + //template friend class SurfaceSetRenderBufferCommandEqMatcherP4; +}; + + +#endif /* _SURFACEREMOVENATIVECONTENTCOMMAND_H_ */ diff --git a/LayerManagerCommands/src/SurfaceRemoveNativeContentCommand.cpp b/LayerManagerCommands/src/SurfaceRemoveNativeContentCommand.cpp new file mode 100644 index 0000000..44a449e --- /dev/null +++ b/LayerManagerCommands/src/SurfaceRemoveNativeContentCommand.cpp @@ -0,0 +1,60 @@ +/*************************************************************************** +* +* Copyright 2010,2011 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 "SurfaceRemoveNativeContentCommand.h" +#include "ICommandExecutor.h" +#include "Scene.h" +#include +#include "stdio.h" + +SurfaceRemoveNativeContentCommand::SurfaceRemoveNativeContentCommand(unsigned int surfaceId) +: m_surfaceId(surfaceId) +{ +} + +ExecutionResult SurfaceRemoveNativeContentCommand::execute(ICommandExecutor* executor) +{ + Scene& scene = *(executor->getScene()); + ExecutionResult result = ExecutionFailed; + + Surface* surface = scene.getSurface(m_surfaceId); + + if (surface) + { + if(surface->hasNativeContent()) + { + surface->removeNativeContent(); + result = ExecutionSuccessRedraw; + } + else + { + result = ExecutionSuccess; + } + } + + return result; +} + +const std::string SurfaceRemoveNativeContentCommand::getString() +{ + std::stringstream description; + description << "SurfaceRemoveNativeContentCommand(" + << "surfaceId=" << m_surfaceId + << ")"; + return description.str(); +} diff --git a/LayerManagerPlugins/Communicators/GenericCommunicator/include/GenericCommunicator.h b/LayerManagerPlugins/Communicators/GenericCommunicator/include/GenericCommunicator.h index 45b2890..15d637a 100644 --- a/LayerManagerPlugins/Communicators/GenericCommunicator/include/GenericCommunicator.h +++ b/LayerManagerPlugins/Communicators/GenericCommunicator/include/GenericCommunicator.h @@ -86,6 +86,7 @@ #include "LayerDumpCommand.h" #include "SurfaceDumpCommand.h" #include "SurfaceSetNativeContentCommand.h" +#include "SurfaceRemoveNativeContentCommand.h" class GenericCommunicator; @@ -135,6 +136,7 @@ public: void InitializeSurfaceFromId(); void CreateSurfaceFromId(); void SetSurfaceNativeContent(); + void RemoveSurfaceNativeContent(); void RemoveSurface(); void CreateLayer(); void CreateLayerFromId(); diff --git a/LayerManagerPlugins/Communicators/GenericCommunicator/src/GenericCommunicator.cpp b/LayerManagerPlugins/Communicators/GenericCommunicator/src/GenericCommunicator.cpp index bf40b92..d8ab2c4 100644 --- a/LayerManagerPlugins/Communicators/GenericCommunicator/src/GenericCommunicator.cpp +++ b/LayerManagerPlugins/Communicators/GenericCommunicator/src/GenericCommunicator.cpp @@ -78,6 +78,7 @@ GenericCommunicator::GenericCommunicator(ICommandExecutor* executor) { "InitializeSurface", &GenericCommunicator::InitializeSurface }, { "InitializeSurfaceFromId", &GenericCommunicator::InitializeSurfaceFromId }, { "SetSurfaceNativeContent", &GenericCommunicator::SetSurfaceNativeContent }, + { "RemoveSurfaceNativeContent", &GenericCommunicator::RemoveSurfaceNativeContent }, { "RemoveSurface", &GenericCommunicator::RemoveSurface }, { "CreateLayer", &GenericCommunicator::CreateLayer }, { "CreateLayerFromId", &GenericCommunicator::CreateLayerFromId }, @@ -736,6 +737,23 @@ void GenericCommunicator::SetSurfaceNativeContent() } } +void GenericCommunicator::RemoveSurfaceNativeContent() +{ + uint id = 0; + m_ipcModule.getUint(&id); + + t_ilm_bool status = m_executor->execute(new SurfaceRemoveNativeContentCommand(id)); + if (status) + { + m_ipcModule.createMessage((char*)__FUNCTION__); + m_ipcModule.sendMessage(); + } + else + { + m_ipcModule.sendError(RESSOURCE_ALREADY_INUSE); + } +} + void GenericCommunicator::RemoveSurface() { uint param = 0; diff --git a/LayerManagerPlugins/IpcModules/DbusIpcModule/src/introspection.c b/LayerManagerPlugins/IpcModules/DbusIpcModule/src/introspection.c index 9715910..852787f 100644 --- a/LayerManagerPlugins/IpcModules/DbusIpcModule/src/introspection.c +++ b/LayerManagerPlugins/IpcModules/DbusIpcModule/src/introspection.c @@ -117,6 +117,7 @@ void generateString(char* msgBuffer) { "InitializeSurface", "", "u" }, { "InitializeSurfaceFromId", "u", "u" }, { "SetSurfaceNativeContent", "uuuuu", "" }, + { "RemoveSurfaceNativeContent", "u", "" }, { "RemoveSurface", "u", "" }, { "CreateLayer", "", "u" }, { "CreateLayerFromId", "u", "u" }, diff --git a/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/WaylandBaseWindowSystem.h b/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/WaylandBaseWindowSystem.h index b97a044..98d7940 100644 --- a/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/WaylandBaseWindowSystem.h +++ b/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/WaylandBaseWindowSystem.h @@ -67,6 +67,7 @@ public: WaylandWindowSystemStates getSystemState(); struct wl_display* getNativeDisplayHandle(); virtual void allocatePlatformSurface(Surface *surface); + virtual void deallocatePlatformSurface(Surface *surface); void doScreenShot(std::string fileName); void doScreenShotOfLayer(std::string fileName, const uint id); void doScreenShotOfSurface(std::string fileName, const uint id, const uint layer_id); diff --git a/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/X11WindowSystem.h b/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/X11WindowSystem.h index 2c8435e..3f7bea2 100644 --- a/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/X11WindowSystem.h +++ b/LayerManagerPlugins/Renderers/Graphic/include/WindowSystems/X11WindowSystem.h @@ -55,6 +55,7 @@ public: Display* getNativeDisplayHandle(); Window getCompositorNativeWindowHandle(); virtual void allocatePlatformSurface(Surface *surface); + virtual void deallocatePlatformSurface(Surface *surface); void doScreenShot(std::string fileName); void doScreenShotOfLayer(std::string fileName, const uint id); void doScreenShotOfSurface(std::string fileName, const uint id, const uint layer_id); diff --git a/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/WaylandBaseWindowSystem.cpp b/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/WaylandBaseWindowSystem.cpp index 131ee97..c7b443a 100644 --- a/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/WaylandBaseWindowSystem.cpp +++ b/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/WaylandBaseWindowSystem.cpp @@ -230,6 +230,10 @@ void WaylandBaseWindowSystem::checkForNewSurface() { allocatePlatformSurface(*currentS); } + else // While we are at it, also cleanup any stale native content + { + deallocatePlatformSurface(*currentS); + } } } m_pScene->unlockScene(); @@ -1161,6 +1165,24 @@ void WaylandBaseWindowSystem::allocatePlatformSurface(Surface* surface) LOG_INFO("WaylandBaseWindowSystem","allocatePlatformSurface end"); } +void WaylandBaseWindowSystem::deallocatePlatformSurface(Surface* surface) +{ + LOG_DEBUG("WaylandBaseWindowSystem","deallocatePlatformSurface begin"); + WaylandPlatformSurface* nativeSurface = (WaylandPlatformSurface*)surface->platform; + if (nativeSurface) + { + LOG_DEBUG("WaylandBaseWindowSystem","destroyingnative surface"); +#if 0 // TODO + graphicSystem->getTextureBinder()->destroyClientBuffer(surface); + + surface->renderPropertyChanged = true; + delete surface->platform; + surface->platform = NULL; +#endif + } + LOG_DEBUG("WaylandBaseWindowSystem","deallocatePlatformSurface end"); +} + void WaylandBaseWindowSystem::doScreenShot(std::string fileName) { m_takeScreenshot = ScreenshotOfDisplay; diff --git a/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp b/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp index 46ad9b7..8a79819 100644 --- a/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp +++ b/LayerManagerPlugins/Renderers/Graphic/src/WindowSystems/X11WindowSystem.cpp @@ -237,6 +237,10 @@ void X11WindowSystem::checkForNewSurfaceNativeContent() { allocatePlatformSurface(*currentS); } + else // While we are at it, also cleanup any stale native content + { + deallocatePlatformSurface(*currentS); + } } } m_pScene->unlockScene(); @@ -1120,6 +1124,27 @@ void X11WindowSystem::allocatePlatformSurface(Surface* surface) LOG_DEBUG("X11WindowSystem","allocatePlatformSurface end"); } +void X11WindowSystem::deallocatePlatformSurface(Surface* surface) +{ + LOG_DEBUG("X11WindowSystem","deallocatePlatformSurface begin"); + XPlatformSurface* nativeSurface = (XPlatformSurface*)surface->platform; + if (nativeSurface) + { + LOG_DEBUG("X11WindowSystem","destroyingnative surface"); + graphicSystem->getTextureBinder()->destroyClientBuffer(surface); + + if (nativeSurface->pixmap) + { + int result = XFreePixmap(x11Display, nativeSurface->pixmap); + } + + surface->renderPropertyChanged = true; + delete surface->platform; + surface->platform = NULL; + } + LOG_DEBUG("X11WindowSystem","deallocatePlatformSurface end"); +} + void X11WindowSystem::doScreenShot(std::string fileName) { takeScreenshot = ScreenshotOfDisplay; -- 2.7.4