Use KWin effect to grab also alpha channel in KSnapshot
Review Request #4814 - Created Aug. 1, 2010 and submitted
This patch makes KSnapshot use KWin's new Screenshot effect to create screenshots of windows. The screenshot effect uses an offscreen OpenGL framebuffer object and renders the window including the decoration shadow (glow) into this framebuffer object. This allows to only get the window (without other windows on top) and the alpha channel and of course the shadow. I decided to use DBus instead of passing around X properties as I think it is the more convenient API and easier to understand. Especially the introspection is quite handy in this case as it allows to test if the screenshot effect is available. As the screenshot is captured during KWin's next rendering pass, I decided to use the backfiring signal instead of using a blocking DBus call. If this approach is acceptable I will extend the screenshot effect to support not including the decoration. KSnapshot is currently not able to handle the alpha channel in the preview. Translucent pixels are black. When saving everything is fine (see attached screenshot). If I get directions I will have a look at it :-) It might also be an idea to check the availability of the screenshot effect before taking the screenshot and a fallback if the DBus connection fails.
i really like the idea, but as to the implementation in ksnapshot: is there any real use case for _not_ grabbing the alpha channel? is there any use case for not using kwin's snapshot feature if it is enabled? i can't think of any myself, but maybe i'm not thinking of some particular use cases? if there aren't any, then i'd prefer to see it non-configurable in ksnapshot. in that case, captureAlphaChannel() would become an internally used bool member called sth like m_useCompositeManager. beyond that, is there any reason why this can't be used for all types of snapshots, and not just for "window under cursor"? does it work with the "include mouse cursor" feature as well? summary: i like the concept a lot, perhaps needs some tidying on the ksnapshot side first though.
Review request changed
* Screenshot effect supports including decoration and mouse pointer * Removed UI option in ksnapshot * Removed shortcut from screenshot effect
Revision 2 (+157 -37)
Review request changed
remove black background behind the transparent area caused by the black blurred area in the preview (see new attached screenshot). There is one thing I need to add that is a fallback when KWin cannot grab the screenshot which is not that unlikely as the effect uses framebuffer objects which are maybe supported in current mesa drivers. So kwin will first notice that it does not work when it is tried to grab a screenshot. My idea to solve this problem is to return a null pixmap handle and use the normal grab code in ksnapshot in that case. Nevertheless I would like to submit the changes so far :-)