2006-07-05 12:30:03 +00:00
|
|
|
/*****************************************************************
|
|
|
|
KWin - the KDE window manager
|
|
|
|
This file is part of the KDE project.
|
|
|
|
|
|
|
|
Copyright (C) 2006 Lubos Lunak <l.lunak@kde.org>
|
|
|
|
|
|
|
|
You can Freely distribute this program under the GNU General Public
|
|
|
|
License. See the file "COPYING" for the exact licensing terms.
|
|
|
|
******************************************************************/
|
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
/*
|
|
|
|
This is the XRender-based compositing code. The primary compositing
|
|
|
|
backend is the OpenGL-based one, which should be more powerful
|
|
|
|
and also possibly better documented. This backend is mostly for cases
|
|
|
|
when the OpenGL backend cannot be used for some reason (insufficient
|
|
|
|
performance, no usable OpenGL support at all, etc.)
|
|
|
|
The plan is to keep it around as long as needed/possible, but if it
|
|
|
|
proves to be too much hassle it will be dropped in the future.
|
|
|
|
|
|
|
|
Docs:
|
|
|
|
|
|
|
|
XRender (the protocol, but the function calls map to it):
|
2007-01-15 14:58:35 +00:00
|
|
|
http://gitweb.freedesktop.org/?p=xorg/proto/renderproto.git;a=blob_plain;hb=HEAD;f=renderproto.txt
|
2006-10-29 19:23:45 +00:00
|
|
|
|
|
|
|
XFixes (again, the protocol):
|
2007-01-15 14:58:35 +00:00
|
|
|
http://gitweb.freedesktop.org/?p=xorg/proto/fixesproto.git;a=blob_plain;hb=HEAD;f=fixesproto.txt
|
2006-10-29 19:23:45 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2006-07-05 12:30:03 +00:00
|
|
|
#include "scene_xrender.h"
|
|
|
|
|
2006-07-05 13:26:08 +00:00
|
|
|
#ifdef HAVE_XRENDER
|
|
|
|
|
|
|
|
#include "toplevel.h"
|
2006-10-07 21:21:02 +00:00
|
|
|
#include "client.h"
|
2007-01-22 22:51:30 +00:00
|
|
|
#include "deleted.h"
|
2006-07-06 09:55:10 +00:00
|
|
|
#include "effects.h"
|
2006-07-05 13:26:08 +00:00
|
|
|
|
2006-07-05 12:30:03 +00:00
|
|
|
namespace KWinInternal
|
|
|
|
{
|
|
|
|
|
|
|
|
//****************************************
|
|
|
|
// SceneXrender
|
|
|
|
//****************************************
|
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
// kDebug() support for the XserverRegion type
|
2006-09-30 15:40:03 +00:00
|
|
|
struct RegionDebug
|
|
|
|
{
|
|
|
|
RegionDebug( XserverRegion r ) : rr( r ) {}
|
|
|
|
XserverRegion rr;
|
|
|
|
};
|
2006-10-29 19:23:45 +00:00
|
|
|
|
2006-09-30 15:40:03 +00:00
|
|
|
#ifdef NDEBUG
|
|
|
|
inline
|
|
|
|
kndbgstream& operator<<( kndbgstream& stream, RegionDebug ) { return stream; }
|
|
|
|
#else
|
|
|
|
kdbgstream& operator<<( kdbgstream& stream, RegionDebug r )
|
|
|
|
{
|
|
|
|
if( r.rr == None )
|
|
|
|
return stream << "EMPTY";
|
|
|
|
int num;
|
|
|
|
XRectangle* rects = XFixesFetchRegion( display(), r.rr, &num );
|
|
|
|
if( rects == NULL || num == 0 )
|
|
|
|
return stream << "EMPTY";
|
|
|
|
for( int i = 0;
|
|
|
|
i < num;
|
|
|
|
++i )
|
|
|
|
stream << "[" << rects[ i ].x << "+" << rects[ i ].y << " " << rects[ i ].width << "x" << rects[ i ].height << "]";
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-10-14 22:08:51 +00:00
|
|
|
Picture SceneXrender::buffer;
|
2006-10-21 18:07:00 +00:00
|
|
|
ScreenPaintData SceneXrender::screen_paint;
|
2006-10-14 22:08:51 +00:00
|
|
|
|
2006-07-05 13:26:08 +00:00
|
|
|
SceneXrender::SceneXrender( Workspace* ws )
|
|
|
|
: Scene( ws )
|
|
|
|
{
|
2006-10-29 19:23:45 +00:00
|
|
|
// create XRender picture for the root window
|
2006-07-05 13:26:08 +00:00
|
|
|
format = XRenderFindVisualFormat( display(), DefaultVisual( display(), DefaultScreen( display())));
|
2006-12-03 13:38:16 +00:00
|
|
|
if( wspace->createOverlay())
|
|
|
|
{
|
|
|
|
wspace->setupOverlay( None );
|
|
|
|
front = XRenderCreatePicture( display(), wspace->overlayWindow(), format, 0, NULL );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
XRenderPictureAttributes pa;
|
|
|
|
pa.subwindow_mode = IncludeInferiors;
|
|
|
|
front = XRenderCreatePicture( display(), rootWindow(), format, CPSubwindowMode, &pa );
|
|
|
|
}
|
2006-07-05 13:26:08 +00:00
|
|
|
createBuffer();
|
|
|
|
}
|
|
|
|
|
|
|
|
SceneXrender::~SceneXrender()
|
|
|
|
{
|
|
|
|
XRenderFreePicture( display(), front );
|
|
|
|
XRenderFreePicture( display(), buffer );
|
2006-12-03 13:38:16 +00:00
|
|
|
wspace->destroyOverlay();
|
2006-10-14 22:08:51 +00:00
|
|
|
for( QMap< Toplevel*, Window >::Iterator it = windows.begin();
|
|
|
|
it != windows.end();
|
2006-07-05 20:52:57 +00:00
|
|
|
++it )
|
|
|
|
(*it).free();
|
2006-07-05 13:26:08 +00:00
|
|
|
}
|
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
// the entry point for painting
|
2006-10-16 10:12:48 +00:00
|
|
|
void SceneXrender::paint( QRegion damage, ToplevelList toplevels )
|
2006-07-05 13:26:08 +00:00
|
|
|
{
|
2006-10-16 10:12:48 +00:00
|
|
|
foreach( Toplevel* c, toplevels )
|
|
|
|
{
|
|
|
|
assert( windows.contains( c ));
|
|
|
|
stacking_order.append( &windows[ c ] );
|
|
|
|
}
|
2006-10-24 13:38:31 +00:00
|
|
|
int mask = 0;
|
|
|
|
paintScreen( &mask, &damage );
|
2006-10-16 18:46:07 +00:00
|
|
|
if( mask & PAINT_SCREEN_REGION )
|
2006-10-16 10:12:48 +00:00
|
|
|
{
|
|
|
|
// Use the damage region as the clip region for the root window
|
|
|
|
XserverRegion front_region = toXserverRegion( damage );
|
|
|
|
XFixesSetPictureClipRegion( display(), front, 0, 0, front_region );
|
|
|
|
XFixesDestroyRegion( display(), front_region );
|
|
|
|
// copy composed buffer to the root window
|
|
|
|
XFixesSetPictureClipRegion( display(), buffer, 0, 0, None );
|
|
|
|
XRenderComposite( display(), PictOpSrc, buffer, None, front, 0, 0, 0, 0, 0, 0, displayWidth(), displayHeight());
|
2006-10-21 18:07:00 +00:00
|
|
|
XFixesSetPictureClipRegion( display(), front, 0, 0, None );
|
2006-10-16 10:12:48 +00:00
|
|
|
XFlush( display());
|
|
|
|
}
|
2006-10-14 22:08:51 +00:00
|
|
|
else
|
2006-10-16 10:12:48 +00:00
|
|
|
{
|
|
|
|
// copy composed buffer to the root window
|
|
|
|
XRenderComposite( display(), PictOpSrc, buffer, None, front, 0, 0, 0, 0, 0, 0, displayWidth(), displayHeight());
|
|
|
|
XFlush( display());
|
|
|
|
}
|
2006-11-24 21:28:00 +00:00
|
|
|
// do cleanup
|
|
|
|
stacking_order.clear();
|
2006-07-05 13:26:08 +00:00
|
|
|
}
|
|
|
|
|
2006-10-21 18:07:00 +00:00
|
|
|
void SceneXrender::paintGenericScreen( int mask, ScreenPaintData data )
|
|
|
|
{
|
|
|
|
screen_paint = data; // save, transformations will be done when painting windows
|
2006-12-04 18:30:41 +00:00
|
|
|
if( false ) // TODO never needed?
|
|
|
|
Scene::paintGenericScreen( mask, data );
|
|
|
|
else
|
|
|
|
paintTransformedScreen( mask );
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Try to do optimized painting even with transformations. Since only scaling
|
|
|
|
and translation are supported by the painting code, clipping can be done
|
|
|
|
manually to avoid having to paint everything in every pass. Whole screen
|
|
|
|
still need to be painted but e.g. obscured windows don't. So this below
|
|
|
|
is basically paintSimpleScreen() with extra code to compute clipping correctly.
|
|
|
|
|
|
|
|
This code assumes that the only transformations possible with XRender are those
|
|
|
|
provided by Window/ScreenPaintData, In the (very unlikely?) case more is needed
|
|
|
|
then paintGenericScreen() needs to be used.
|
|
|
|
*/
|
|
|
|
void SceneXrender::paintTransformedScreen( int orig_mask )
|
|
|
|
{
|
|
|
|
QRegion region( 0, 0, displayWidth(), displayHeight());
|
|
|
|
QList< Phase2Data > phase2;
|
|
|
|
// Draw each opaque window top to bottom, subtracting the bounding rect of
|
|
|
|
// each window from the clip region after it's been drawn.
|
|
|
|
for( int i = stacking_order.count() - 1; // top to bottom
|
|
|
|
i >= 0;
|
|
|
|
--i )
|
|
|
|
{
|
|
|
|
Window* w = static_cast< Window* >( stacking_order[ i ] );
|
|
|
|
if( !w->isVisible())
|
|
|
|
continue;
|
|
|
|
if( region.isEmpty()) // completely clipped
|
|
|
|
continue;
|
|
|
|
int mask = orig_mask | ( w->isOpaque() ? PAINT_WINDOW_OPAQUE : PAINT_WINDOW_TRANSLUCENT );
|
|
|
|
QRegion damage = region;
|
|
|
|
// preparation step
|
2007-01-22 22:57:22 +00:00
|
|
|
effects->prePaintWindow( effectWindow( w ), &mask, &damage, time_diff );
|
2006-12-04 18:30:41 +00:00
|
|
|
// If the window is transparent, the transparent part will be done
|
|
|
|
// in the 2nd pass.
|
|
|
|
if( mask & PAINT_WINDOW_TRANSLUCENT )
|
|
|
|
phase2.prepend( Phase2Data( w, region, mask ));
|
|
|
|
if( mask & PAINT_WINDOW_OPAQUE )
|
|
|
|
{
|
|
|
|
w->setTransformedShape( QRegion());
|
|
|
|
paintWindow( w, mask, region );
|
|
|
|
// If the window is not transparent at all, it can clip windows below.
|
|
|
|
if( ( mask & PAINT_WINDOW_TRANSLUCENT ) == 0 )
|
|
|
|
region -= w->transformedShape();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Fill any areas of the root window not covered by windows
|
|
|
|
paintBackground( region );
|
|
|
|
// Now walk the list bottom to top, drawing translucent windows.
|
|
|
|
// That we draw bottom to top is important now since we're drawing translucent objects
|
|
|
|
// and also are clipping only by opaque windows.
|
|
|
|
foreach( Phase2Data d, phase2 )
|
|
|
|
{
|
|
|
|
Scene::Window* w = d.window;
|
|
|
|
paintWindow( w, d.mask, d.region );
|
|
|
|
}
|
2006-10-21 18:07:00 +00:00
|
|
|
}
|
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
// fill the screen background
|
2006-10-15 07:41:19 +00:00
|
|
|
void SceneXrender::paintBackground( QRegion region )
|
2006-07-05 20:52:57 +00:00
|
|
|
{
|
2006-10-21 18:07:00 +00:00
|
|
|
if( region != infiniteRegion())
|
|
|
|
{
|
|
|
|
XserverRegion background_region = toXserverRegion( region );
|
|
|
|
XFixesSetPictureClipRegion( display(), buffer, 0, 0, background_region );
|
|
|
|
XFixesDestroyRegion( display(), background_region );
|
|
|
|
}
|
2006-10-14 22:08:51 +00:00
|
|
|
XRenderColor col = { 0xffff, 0xffff, 0xffff, 0xffff };
|
|
|
|
XRenderFillRectangle( display(), PictOpSrc, buffer, &col, 0, 0, displayWidth(), displayHeight());
|
2006-10-21 18:07:00 +00:00
|
|
|
XFixesSetPictureClipRegion( display(), buffer, 0, 0, None );
|
2006-07-05 20:52:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SceneXrender::windowGeometryShapeChanged( Toplevel* c )
|
|
|
|
{
|
2006-10-14 22:08:51 +00:00
|
|
|
if( !windows.contains( c )) // this is ok, shape is not valid by default
|
2006-07-05 20:52:57 +00:00
|
|
|
return;
|
2006-10-14 22:08:51 +00:00
|
|
|
Window& w = windows[ c ];
|
|
|
|
w.discardPicture();
|
|
|
|
w.discardShape();
|
|
|
|
w.discardAlpha();
|
2006-07-05 20:52:57 +00:00
|
|
|
}
|
2006-07-13 17:24:29 +00:00
|
|
|
|
2006-07-05 20:52:57 +00:00
|
|
|
void SceneXrender::windowOpacityChanged( Toplevel* c )
|
|
|
|
{
|
2006-10-14 22:08:51 +00:00
|
|
|
if( !windows.contains( c )) // this is ok, alpha is created on demand
|
2006-07-05 20:52:57 +00:00
|
|
|
return;
|
2006-10-14 22:08:51 +00:00
|
|
|
Window& w = windows[ c ];
|
|
|
|
w.discardAlpha();
|
2006-07-05 20:52:57 +00:00
|
|
|
}
|
|
|
|
|
2007-01-22 22:51:30 +00:00
|
|
|
void SceneXrender::windowClosed( Toplevel* c, Deleted* deleted )
|
|
|
|
{
|
|
|
|
assert( windows.contains( c ));
|
|
|
|
if( deleted != NULL )
|
|
|
|
{ // replace c with deleted
|
|
|
|
Window& w = windows[ c ];
|
|
|
|
w.updateToplevel( deleted );
|
|
|
|
windows[ deleted ] = w;
|
|
|
|
windows.remove( c );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
windows[ c ].free();
|
|
|
|
windows.remove( c );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneXrender::windowDeleted( Deleted* c )
|
2006-07-05 20:52:57 +00:00
|
|
|
{
|
2006-10-14 22:08:51 +00:00
|
|
|
assert( windows.contains( c ));
|
|
|
|
windows[ c ].free();
|
|
|
|
windows.remove( c );
|
2006-07-05 20:52:57 +00:00
|
|
|
}
|
|
|
|
|
2006-09-29 19:05:36 +00:00
|
|
|
void SceneXrender::windowAdded( Toplevel* c )
|
|
|
|
{
|
2006-10-14 22:08:51 +00:00
|
|
|
assert( !windows.contains( c ));
|
|
|
|
windows[ c ] = Window( c );
|
2006-09-29 19:05:36 +00:00
|
|
|
}
|
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
// Create the compositing buffer. The root window is not double-buffered,
|
|
|
|
// so it is done manually using this buffer,
|
2006-07-05 20:52:57 +00:00
|
|
|
void SceneXrender::createBuffer()
|
|
|
|
{
|
|
|
|
if( buffer != None )
|
|
|
|
XRenderFreePicture( display(), buffer );
|
|
|
|
Pixmap pixmap = XCreatePixmap( display(), rootWindow(), displayWidth(), displayHeight(), QX11Info::appDepth());
|
|
|
|
buffer = XRenderCreatePicture( display(), pixmap, format, 0, 0 );
|
|
|
|
XFreePixmap( display(), pixmap ); // The picture owns the pixmap now
|
|
|
|
}
|
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
// Convert QRegion to XserverRegion. This code uses XserverRegion
|
|
|
|
// only when really necessary as the shared implementation uses
|
|
|
|
// QRegion.
|
2006-10-15 07:41:19 +00:00
|
|
|
XserverRegion SceneXrender::toXserverRegion( QRegion region )
|
|
|
|
{
|
|
|
|
QVector< QRect > rects = region.rects();
|
|
|
|
XRectangle* xr = new XRectangle[ rects.count() ];
|
|
|
|
for( int i = 0;
|
|
|
|
i < rects.count();
|
|
|
|
++i )
|
|
|
|
{
|
|
|
|
xr[ i ].x = rects[ i ].x();
|
|
|
|
xr[ i ].y = rects[ i ].y();
|
|
|
|
xr[ i ].width = rects[ i ].width();
|
|
|
|
xr[ i ].height = rects[ i ].height();
|
|
|
|
}
|
|
|
|
XserverRegion ret = XFixesCreateRegion( display(), xr, rects.count());
|
|
|
|
delete[] xr;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2006-10-15 08:58:38 +00:00
|
|
|
//****************************************
|
|
|
|
// SceneXrender::Window
|
|
|
|
//****************************************
|
|
|
|
|
2006-10-14 22:08:51 +00:00
|
|
|
SceneXrender::Window::Window( Toplevel* c )
|
2006-10-15 08:58:38 +00:00
|
|
|
: Scene::Window( c )
|
2006-07-13 17:24:29 +00:00
|
|
|
, _picture( None )
|
2006-10-14 22:08:51 +00:00
|
|
|
, format( XRenderFindVisualFormat( display(), c->visual()))
|
2006-07-05 20:52:57 +00:00
|
|
|
, alpha( None )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-10-14 22:08:51 +00:00
|
|
|
void SceneXrender::Window::free()
|
2006-07-05 20:52:57 +00:00
|
|
|
{
|
2006-10-14 22:08:51 +00:00
|
|
|
discardPicture();
|
|
|
|
discardAlpha();
|
|
|
|
discardShape();
|
2006-07-06 18:22:01 +00:00
|
|
|
}
|
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
// Create XRender picture for the pixmap with the window contents.
|
2006-10-14 22:08:51 +00:00
|
|
|
Picture SceneXrender::Window::picture()
|
2006-07-13 17:24:29 +00:00
|
|
|
{
|
2006-10-14 22:08:51 +00:00
|
|
|
if( !toplevel->damage().isEmpty() && _picture != None )
|
2006-10-07 21:20:23 +00:00
|
|
|
{
|
|
|
|
XRenderFreePicture( display(), _picture );
|
|
|
|
_picture = None;
|
|
|
|
}
|
2006-07-13 17:24:29 +00:00
|
|
|
if( _picture == None && format != NULL )
|
2006-10-07 21:20:23 +00:00
|
|
|
{
|
2006-10-29 19:23:45 +00:00
|
|
|
// Get the pixmap with the window contents.
|
2007-01-12 23:21:36 +00:00
|
|
|
Pixmap pix = toplevel->windowPixmap();
|
2006-10-29 19:23:45 +00:00
|
|
|
// HACK the same alpha clear hack like with opengl, see there
|
2006-10-14 22:08:51 +00:00
|
|
|
Client* c = dynamic_cast< Client* >( toplevel );
|
2006-10-07 21:21:02 +00:00
|
|
|
bool alpha_clear = c != NULL && c->hasAlpha() && !c->noBorder();
|
|
|
|
#define ALPHA_CLEAR_COPY
|
|
|
|
#ifdef ALPHA_CLEAR_COPY
|
|
|
|
if( alpha_clear )
|
|
|
|
{
|
|
|
|
Pixmap p2 = XCreatePixmap( display(), pix, c->width(), c->height(), 32 );
|
|
|
|
GC gc = XCreateGC( display(), pix, 0, NULL );
|
|
|
|
XCopyArea( display(), pix, p2, gc, 0, 0, c->width(), c->height(), 0, 0 );
|
|
|
|
pix = p2;
|
|
|
|
XFreeGC( display(), gc );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
if( alpha_clear )
|
|
|
|
{
|
|
|
|
XGCValues gcv;
|
|
|
|
gcv.foreground = 0xff000000;
|
|
|
|
gcv.plane_mask = 0xff000000;
|
|
|
|
GC gc = XCreateGC( display(), pix, GCPlaneMask | GCForeground, &gcv );
|
|
|
|
XFillRectangle( display(), pix, gc, 0, 0, c->width(), c->clientPos().y());
|
|
|
|
XFillRectangle( display(), pix, gc, 0, 0, c->clientPos().x(), c->height());
|
|
|
|
int tw = c->clientPos().x() + c->clientSize().width();
|
|
|
|
int th = c->clientPos().y() + c->clientSize().height();
|
|
|
|
XFillRectangle( display(), pix, gc, 0, th, c->width(), c->height() - th );
|
|
|
|
XFillRectangle( display(), pix, gc, tw, 0, c->width() - tw, c->height());
|
|
|
|
XFreeGC( display(), gc );
|
|
|
|
}
|
2006-10-07 21:20:23 +00:00
|
|
|
_picture = XRenderCreatePicture( display(), pix, format, 0, 0 );
|
2006-10-07 21:21:02 +00:00
|
|
|
#ifdef ALPHA_CLEAR_COPY
|
|
|
|
if( alpha_clear )
|
2007-01-12 23:21:36 +00:00
|
|
|
XFreePixmap( display(), pix );
|
2006-10-07 21:21:02 +00:00
|
|
|
#endif
|
2006-11-24 21:28:00 +00:00
|
|
|
toplevel->resetDamage( toplevel->rect());
|
2006-10-07 21:20:23 +00:00
|
|
|
}
|
2006-07-13 17:24:29 +00:00
|
|
|
return _picture;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-14 22:08:51 +00:00
|
|
|
void SceneXrender::Window::discardPicture()
|
2006-07-13 17:24:29 +00:00
|
|
|
{
|
2006-10-14 22:08:51 +00:00
|
|
|
if( _picture != None )
|
|
|
|
XRenderFreePicture( display(), _picture );
|
|
|
|
_picture = None;
|
2006-07-13 17:24:29 +00:00
|
|
|
}
|
|
|
|
|
2006-10-14 22:08:51 +00:00
|
|
|
void SceneXrender::Window::discardAlpha()
|
2006-07-13 17:24:29 +00:00
|
|
|
{
|
2006-10-14 22:08:51 +00:00
|
|
|
if( alpha != None )
|
|
|
|
XRenderFreePicture( display(), alpha );
|
|
|
|
alpha = None;
|
2006-07-13 17:24:29 +00:00
|
|
|
}
|
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
// Create XRender picture for the alpha mask.
|
2006-10-22 10:15:19 +00:00
|
|
|
Picture SceneXrender::Window::alphaMask( double opacity )
|
2006-07-13 17:24:29 +00:00
|
|
|
{
|
2006-10-22 10:15:19 +00:00
|
|
|
if( isOpaque() && opacity == 1.0 )
|
2006-07-13 17:24:29 +00:00
|
|
|
return None;
|
2006-10-22 10:15:19 +00:00
|
|
|
if( alpha != None && alpha_cached_opacity != opacity )
|
2006-07-13 17:24:29 +00:00
|
|
|
{
|
|
|
|
if( alpha != None )
|
|
|
|
XRenderFreePicture( display(), alpha );
|
|
|
|
alpha = None;
|
|
|
|
}
|
|
|
|
if( alpha != None )
|
|
|
|
return alpha;
|
2006-10-22 10:15:19 +00:00
|
|
|
if( opacity == 1.0 )
|
2006-10-07 21:19:23 +00:00
|
|
|
{ // no need to create alpha mask
|
|
|
|
alpha_cached_opacity = 1.0;
|
|
|
|
return None;
|
|
|
|
}
|
2006-10-29 19:23:45 +00:00
|
|
|
// Create a 1x1 8bpp pixmap containing the given opacity in the alpha channel.
|
2006-07-13 17:24:29 +00:00
|
|
|
Pixmap pixmap = XCreatePixmap( display(), rootWindow(), 1, 1, 8 );
|
|
|
|
XRenderPictFormat* format = XRenderFindStandardFormat( display(), PictStandardA8 );
|
|
|
|
XRenderPictureAttributes pa;
|
|
|
|
pa.repeat = True;
|
|
|
|
alpha = XRenderCreatePicture( display(), pixmap, format, CPRepeat, &pa );
|
|
|
|
XFreePixmap( display(), pixmap );
|
|
|
|
XRenderColor col;
|
2006-10-22 10:15:19 +00:00
|
|
|
col.alpha = int( opacity * 0xffff );
|
|
|
|
alpha_cached_opacity = opacity;
|
2006-07-13 17:24:29 +00:00
|
|
|
XRenderFillRectangle( display(), PictOpSrc, alpha, &col, 0, 0, 1, 1 );
|
|
|
|
return alpha;
|
|
|
|
}
|
|
|
|
|
2006-10-29 19:23:45 +00:00
|
|
|
// paint the window
|
2006-10-22 10:15:19 +00:00
|
|
|
void SceneXrender::Window::performPaint( int mask, QRegion region, WindowPaintData data )
|
2006-07-13 17:24:29 +00:00
|
|
|
{
|
2006-12-04 18:30:41 +00:00
|
|
|
setTransformedShape( QRegion()); // maybe nothing will be painted
|
2006-10-29 19:23:45 +00:00
|
|
|
// check if there is something to paint
|
2006-10-22 10:15:19 +00:00
|
|
|
bool opaque = isOpaque() && data.opacity == 1.0;
|
2006-10-16 18:46:07 +00:00
|
|
|
if( mask & ( PAINT_WINDOW_OPAQUE | PAINT_WINDOW_TRANSLUCENT ))
|
2006-10-14 22:08:51 +00:00
|
|
|
{}
|
2006-10-16 18:46:07 +00:00
|
|
|
else if( mask & PAINT_WINDOW_OPAQUE )
|
2006-10-14 22:08:51 +00:00
|
|
|
{
|
2006-10-22 10:15:19 +00:00
|
|
|
if( !opaque )
|
2006-10-14 22:08:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-10-16 18:46:07 +00:00
|
|
|
else if( mask & PAINT_WINDOW_TRANSLUCENT )
|
2006-10-14 22:08:51 +00:00
|
|
|
{
|
2006-10-22 10:15:19 +00:00
|
|
|
if( opaque )
|
2006-10-14 22:08:51 +00:00
|
|
|
return;
|
|
|
|
}
|
2006-10-21 18:07:00 +00:00
|
|
|
if( region != infiniteRegion())
|
|
|
|
{
|
|
|
|
XserverRegion clip_region = toXserverRegion( region );
|
|
|
|
XFixesSetPictureClipRegion( display(), buffer, 0, 0, clip_region );
|
|
|
|
XFixesDestroyRegion( display(), clip_region );
|
|
|
|
}
|
2006-10-29 19:23:45 +00:00
|
|
|
Picture pic = picture(); // get XRender picture
|
2006-10-14 22:08:51 +00:00
|
|
|
if( pic == None ) // The render format can be null for GL and/or Xv visuals
|
|
|
|
return;
|
2006-10-29 19:23:45 +00:00
|
|
|
// do required transformations
|
2006-10-21 18:07:00 +00:00
|
|
|
int x = toplevel->x();
|
|
|
|
int y = toplevel->y();
|
2006-12-03 13:32:52 +00:00
|
|
|
int width = toplevel->width();
|
|
|
|
int height = toplevel->height();
|
2006-12-03 13:37:44 +00:00
|
|
|
double xscale = 1;
|
|
|
|
double yscale = 1;
|
2006-12-04 18:30:41 +00:00
|
|
|
transformed_shape = shape();
|
2006-10-22 10:15:19 +00:00
|
|
|
if( mask & PAINT_WINDOW_TRANSFORMED )
|
|
|
|
{
|
2006-12-03 13:37:44 +00:00
|
|
|
xscale *= data.xScale;
|
|
|
|
yscale *= data.yScale;
|
2006-10-22 10:15:19 +00:00
|
|
|
x += data.xTranslate;
|
|
|
|
y += data.yTranslate;
|
|
|
|
}
|
2006-12-03 13:37:44 +00:00
|
|
|
if( mask & PAINT_SCREEN_TRANSFORMED )
|
|
|
|
{
|
|
|
|
xscale *= screen_paint.xScale;
|
|
|
|
yscale *= screen_paint.yScale;
|
|
|
|
x = int( x * screen_paint.xScale );
|
|
|
|
y = int( y * screen_paint.yScale );
|
|
|
|
x += screen_paint.xTranslate;
|
|
|
|
y += screen_paint.yTranslate;
|
|
|
|
}
|
|
|
|
if( yscale != 1 || xscale != 1 )
|
2006-12-03 13:32:52 +00:00
|
|
|
{
|
|
|
|
XTransform xform = {{
|
2006-12-03 13:37:44 +00:00
|
|
|
{ XDoubleToFixed( 1 / xscale ), XDoubleToFixed( 0 ), XDoubleToFixed( 0 ) },
|
|
|
|
{ XDoubleToFixed( 0 ), XDoubleToFixed( 1 / yscale ), XDoubleToFixed( 0 ) },
|
2006-12-03 13:32:52 +00:00
|
|
|
{ XDoubleToFixed( 0 ), XDoubleToFixed( 0 ), XDoubleToFixed( 1 ) }
|
|
|
|
}};
|
|
|
|
XRenderSetPictureTransform( display(), pic, &xform );
|
2006-12-03 13:37:44 +00:00
|
|
|
width = (int)(width * xscale);
|
|
|
|
height = (int)(height * yscale);
|
2006-12-03 13:38:57 +00:00
|
|
|
if( options->smoothScale == 1 ) // only when forced, it's slow
|
2006-12-04 18:35:08 +00:00
|
|
|
XRenderSetPictureFilter( display(), pic, const_cast< char* >( "good" ), NULL, 0 );
|
2006-12-04 18:30:41 +00:00
|
|
|
// transform the shape for clipping in paintTransformedScreen()
|
|
|
|
QVector< QRect > rects = transformed_shape.rects();
|
|
|
|
for( int i = 0;
|
|
|
|
i < rects.count();
|
|
|
|
++i )
|
|
|
|
{
|
|
|
|
QRect& r = rects[ i ];
|
|
|
|
r = QRect( int( r.x() * xscale ), int( r.y() * yscale ),
|
|
|
|
int( r.width() * xscale ), int( r.height() * xscale ));
|
|
|
|
}
|
|
|
|
transformed_shape.setRects( rects.constData(), rects.count());
|
2006-12-03 13:32:52 +00:00
|
|
|
}
|
2006-12-04 18:30:41 +00:00
|
|
|
if( x != toplevel->x() || y != toplevel->y())
|
|
|
|
transformed_shape.translate( x, y );
|
2006-10-22 10:15:19 +00:00
|
|
|
if( opaque )
|
2006-10-14 22:08:51 +00:00
|
|
|
{
|
|
|
|
XRenderComposite( display(), PictOpSrc, pic, None, buffer, 0, 0, 0, 0,
|
2006-12-03 13:32:52 +00:00
|
|
|
x, y, width, height);
|
2006-10-14 22:08:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-10-22 10:15:19 +00:00
|
|
|
Picture alpha = alphaMask( data.opacity );
|
2006-10-14 22:08:51 +00:00
|
|
|
XRenderComposite( display(), PictOpOver, pic, alpha, buffer, 0, 0, 0, 0,
|
2006-12-03 13:32:52 +00:00
|
|
|
x, y, width, height);
|
2006-12-04 18:30:41 +00:00
|
|
|
transformed_shape = QRegion();
|
2006-12-03 13:32:52 +00:00
|
|
|
}
|
2006-12-03 13:37:44 +00:00
|
|
|
if( xscale != 1 || yscale != 1 )
|
2006-12-03 13:32:52 +00:00
|
|
|
{
|
|
|
|
XTransform xform = {{
|
|
|
|
{ XDoubleToFixed( 1 ), XDoubleToFixed( 0 ), XDoubleToFixed( 0 ) },
|
|
|
|
{ XDoubleToFixed( 0 ), XDoubleToFixed( 1 ), XDoubleToFixed( 0 ) },
|
|
|
|
{ XDoubleToFixed( 0 ), XDoubleToFixed( 0 ), XDoubleToFixed( 1 ) }
|
|
|
|
}};
|
|
|
|
XRenderSetPictureTransform( display(), pic, &xform );
|
2006-12-03 13:38:57 +00:00
|
|
|
if( options->smoothScale == 1 )
|
2006-12-04 18:35:08 +00:00
|
|
|
XRenderSetPictureFilter( display(), pic, const_cast< char* >( "fast" ), NULL, 0 );
|
2006-10-14 22:08:51 +00:00
|
|
|
}
|
|
|
|
XFixesSetPictureClipRegion( display(), buffer, 0, 0, None );
|
2006-07-13 17:24:29 +00:00
|
|
|
}
|
|
|
|
|
2006-07-05 12:30:03 +00:00
|
|
|
} // namespace
|
2006-07-05 13:26:08 +00:00
|
|
|
#endif
|