xenocara/xserver/composite/compwindow.c

793 lines
24 KiB
C
Raw Normal View History

2006-11-26 11:13:41 -07:00
/*
2011-11-05 07:32:40 -06:00
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
2006-11-26 11:13:41 -07:00
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
2006-11-26 11:13:41 -07:00
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
2006-11-26 11:13:41 -07:00
*
* Copyright © 2003 Keith Packard
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of Keith Packard not be used in
* advertising or publicity pertaining to distribution of the software without
* specific, written prior permission. Keith Packard makes no
* representations about the suitability of this software for any purpose. It
* is provided "as is" without express or implied warranty.
*
* KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
* EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
* PERFORMANCE OF THIS SOFTWARE.
*/
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif
#include "compint.h"
2011-11-05 07:32:40 -06:00
#ifdef PANORAMIX
#include "panoramiXsrv.h"
#endif
2006-11-26 11:13:41 -07:00
#ifdef COMPOSITE_DEBUG
static int
compCheckWindow(WindowPtr pWin, pointer data)
2006-11-26 11:13:41 -07:00
{
ScreenPtr pScreen = pWin->drawable.pScreen;
PixmapPtr pWinPixmap = (*pScreen->GetWindowPixmap) (pWin);
PixmapPtr pParentPixmap =
pWin->parent ? (*pScreen->GetWindowPixmap) (pWin->parent) : 0;
PixmapPtr pScreenPixmap = (*pScreen->GetScreenPixmap) (pScreen);
if (!pWin->parent) {
assert(pWin->redirectDraw == RedirectDrawNone);
assert(pWinPixmap == pScreenPixmap);
2006-11-26 11:13:41 -07:00
}
else if (pWin->redirectDraw != RedirectDrawNone) {
assert(pWinPixmap != pParentPixmap);
assert(pWinPixmap != pScreenPixmap);
2006-11-26 11:13:41 -07:00
}
else {
assert(pWinPixmap == pParentPixmap);
2006-11-26 11:13:41 -07:00
}
assert(0 < pWinPixmap->refcnt && pWinPixmap->refcnt < 3);
assert(0 < pScreenPixmap->refcnt && pScreenPixmap->refcnt < 3);
2006-11-26 11:13:41 -07:00
if (pParentPixmap)
assert(0 <= pParentPixmap->refcnt && pParentPixmap->refcnt < 3);
2006-11-26 11:13:41 -07:00
return WT_WALKCHILDREN;
}
void
compCheckTree(ScreenPtr pScreen)
2006-11-26 11:13:41 -07:00
{
WalkTree(pScreen, compCheckWindow, 0);
2006-11-26 11:13:41 -07:00
}
#endif
typedef struct _compPixmapVisit {
WindowPtr pWindow;
PixmapPtr pPixmap;
2006-11-26 11:13:41 -07:00
} CompPixmapVisitRec, *CompPixmapVisitPtr;
static Bool
compRepaintBorder(ClientPtr pClient, pointer closure)
2006-11-26 11:13:41 -07:00
{
2007-11-24 10:55:21 -07:00
WindowPtr pWindow;
int rc =
dixLookupWindow(&pWindow, (XID) (intptr_t) closure, pClient,
DixWriteAccess);
2006-11-26 11:13:41 -07:00
2007-11-24 10:55:21 -07:00
if (rc == Success) {
RegionRec exposed;
2006-11-26 11:13:41 -07:00
RegionNull(&exposed);
RegionSubtract(&exposed, &pWindow->borderClip, &pWindow->winSize);
miPaintWindow(pWindow, &exposed, PW_BORDER);
RegionUninit(&exposed);
2006-11-26 11:13:41 -07:00
}
return TRUE;
}
static int
compSetPixmapVisitWindow(WindowPtr pWindow, pointer data)
2006-11-26 11:13:41 -07:00
{
CompPixmapVisitPtr pVisit = (CompPixmapVisitPtr) data;
ScreenPtr pScreen = pWindow->drawable.pScreen;
2006-11-26 11:13:41 -07:00
2007-11-24 10:55:21 -07:00
if (pWindow != pVisit->pWindow && pWindow->redirectDraw != RedirectDrawNone)
return WT_DONTWALKCHILDREN;
2006-11-26 11:13:41 -07:00
(*pScreen->SetWindowPixmap) (pWindow, pVisit->pPixmap);
/*
* Recompute winSize and borderSize. This is duplicate effort
* when resizing pixmaps, but necessary when changing redirection.
* Might be nice to fix this.
*/
SetWinSize(pWindow);
SetBorderSize(pWindow);
if (HasBorder(pWindow))
QueueWorkProc(compRepaintBorder, serverClient,
(pointer) (intptr_t) pWindow->drawable.id);
2006-11-26 11:13:41 -07:00
return WT_WALKCHILDREN;
}
void
compSetPixmap(WindowPtr pWindow, PixmapPtr pPixmap)
2006-11-26 11:13:41 -07:00
{
CompPixmapVisitRec visitRec;
2006-11-26 11:13:41 -07:00
visitRec.pWindow = pWindow;
visitRec.pPixmap = pPixmap;
TraverseTree(pWindow, compSetPixmapVisitWindow, (pointer) &visitRec);
compCheckTree(pWindow->drawable.pScreen);
2006-11-26 11:13:41 -07:00
}
Bool
compCheckRedirect(WindowPtr pWin)
2006-11-26 11:13:41 -07:00
{
CompWindowPtr cw = GetCompWindow(pWin);
CompScreenPtr cs = GetCompScreen(pWin->drawable.pScreen);
Bool should;
2006-11-26 11:13:41 -07:00
should = pWin->realized && (pWin->drawable.class != InputOnly) &&
(cw != NULL) && (pWin->parent != NULL);
2006-11-26 11:13:41 -07:00
/* Never redirect the overlay window */
if (cs->pOverlayWin != NULL) {
if (pWin == cs->pOverlayWin) {
should = FALSE;
}
}
if (should != (pWin->redirectDraw != RedirectDrawNone)) {
if (should)
return compAllocPixmap(pWin);
else {
ScreenPtr pScreen = pWin->drawable.pScreen;
PixmapPtr pPixmap = (*pScreen->GetWindowPixmap) (pWin);
compSetParentPixmap(pWin);
compRestoreWindow(pWin, pPixmap);
(*pScreen->DestroyPixmap) (pPixmap);
}
}
else if (should) {
if (cw->update == CompositeRedirectAutomatic)
pWin->redirectDraw = RedirectDrawAutomatic;
else
pWin->redirectDraw = RedirectDrawManual;
2006-11-26 11:13:41 -07:00
}
return TRUE;
}
static int
updateOverlayWindow(ScreenPtr pScreen)
{
CompScreenPtr cs;
WindowPtr pWin; /* overlay window */
XID vlist[2];
int w = pScreen->width;
int h = pScreen->height;
2011-11-05 07:32:40 -06:00
#ifdef PANORAMIX
if (!noPanoramiXExtension) {
w = PanoramiXPixWidth;
h = PanoramiXPixHeight;
}
2011-11-05 07:32:40 -06:00
#endif
cs = GetCompScreen(pScreen);
if ((pWin = cs->pOverlayWin) != NULL) {
if ((pWin->drawable.width == w) && (pWin->drawable.height == h))
return Success;
/* Let's resize the overlay window. */
vlist[0] = w;
vlist[1] = h;
return ConfigureWindow(pWin, CWWidth | CWHeight, vlist, wClient(pWin));
}
/* Let's be on the safe side and not assume an overlay window is
always allocated. */
return Success;
}
2006-11-26 11:13:41 -07:00
Bool
compPositionWindow(WindowPtr pWin, int x, int y)
2006-11-26 11:13:41 -07:00
{
ScreenPtr pScreen = pWin->drawable.pScreen;
CompScreenPtr cs = GetCompScreen(pScreen);
Bool ret = TRUE;
2006-11-26 11:13:41 -07:00
pScreen->PositionWindow = cs->PositionWindow;
/*
* "Shouldn't need this as all possible places should be wrapped
*
compCheckRedirect (pWin);
2006-11-26 11:13:41 -07:00
*/
#ifdef COMPOSITE_DEBUG
2007-11-24 10:55:21 -07:00
if ((pWin->redirectDraw != RedirectDrawNone) !=
(pWin->viewable && (GetCompWindow(pWin) != NULL)))
OsAbort();
2006-11-26 11:13:41 -07:00
#endif
if (pWin->redirectDraw != RedirectDrawNone) {
PixmapPtr pPixmap = (*pScreen->GetWindowPixmap) (pWin);
int bw = wBorderWidth(pWin);
int nx = pWin->drawable.x - bw;
int ny = pWin->drawable.y - bw;
if (pPixmap->screen_x != nx || pPixmap->screen_y != ny) {
pPixmap->screen_x = nx;
pPixmap->screen_y = ny;
pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
}
2006-11-26 11:13:41 -07:00
}
if (!(*pScreen->PositionWindow) (pWin, x, y))
ret = FALSE;
2006-11-26 11:13:41 -07:00
cs->PositionWindow = pScreen->PositionWindow;
pScreen->PositionWindow = compPositionWindow;
compCheckTree(pWin->drawable.pScreen);
if (updateOverlayWindow(pScreen) != Success)
ret = FALSE;
2006-11-26 11:13:41 -07:00
return ret;
}
Bool
compRealizeWindow(WindowPtr pWin)
2006-11-26 11:13:41 -07:00
{
ScreenPtr pScreen = pWin->drawable.pScreen;
CompScreenPtr cs = GetCompScreen(pScreen);
Bool ret = TRUE;
2006-11-26 11:13:41 -07:00
pScreen->RealizeWindow = cs->RealizeWindow;
compCheckRedirect(pWin);
2006-11-26 11:13:41 -07:00
if (!(*pScreen->RealizeWindow) (pWin))
ret = FALSE;
2006-11-26 11:13:41 -07:00
cs->RealizeWindow = pScreen->RealizeWindow;
pScreen->RealizeWindow = compRealizeWindow;
compCheckTree(pWin->drawable.pScreen);
2006-11-26 11:13:41 -07:00
return ret;
}
Bool
compUnrealizeWindow(WindowPtr pWin)
2006-11-26 11:13:41 -07:00
{
ScreenPtr pScreen = pWin->drawable.pScreen;
CompScreenPtr cs = GetCompScreen(pScreen);
Bool ret = TRUE;
2006-11-26 11:13:41 -07:00
pScreen->UnrealizeWindow = cs->UnrealizeWindow;
compCheckRedirect(pWin);
2006-11-26 11:13:41 -07:00
if (!(*pScreen->UnrealizeWindow) (pWin))
ret = FALSE;
2006-11-26 11:13:41 -07:00
cs->UnrealizeWindow = pScreen->UnrealizeWindow;
pScreen->UnrealizeWindow = compUnrealizeWindow;
compCheckTree(pWin->drawable.pScreen);
2006-11-26 11:13:41 -07:00
return ret;
}
/*
* Called after the borderClip for the window has settled down
* We use this to make sure our extra borderClip has the right origin
*/
void
compClipNotify(WindowPtr pWin, int dx, int dy)
2006-11-26 11:13:41 -07:00
{
ScreenPtr pScreen = pWin->drawable.pScreen;
CompScreenPtr cs = GetCompScreen(pScreen);
CompWindowPtr cw = GetCompWindow(pWin);
if (cw) {
if (cw->borderClipX != pWin->drawable.x ||
cw->borderClipY != pWin->drawable.y) {
RegionTranslate(&cw->borderClip,
pWin->drawable.x - cw->borderClipX,
pWin->drawable.y - cw->borderClipY);
cw->borderClipX = pWin->drawable.x;
cw->borderClipY = pWin->drawable.y;
}
2006-11-26 11:13:41 -07:00
}
if (cs->ClipNotify) {
pScreen->ClipNotify = cs->ClipNotify;
(*pScreen->ClipNotify) (pWin, dx, dy);
cs->ClipNotify = pScreen->ClipNotify;
pScreen->ClipNotify = compClipNotify;
2006-11-26 11:13:41 -07:00
}
}
/*
* Returns TRUE if the window needs server-provided automatic redirect,
* which is true if the child and parent aren't both regular or ARGB visuals
*/
static Bool
compIsAlternateVisual(ScreenPtr pScreen, XID visual)
2006-11-26 11:13:41 -07:00
{
CompScreenPtr cs = GetCompScreen(pScreen);
int i;
2006-11-26 11:13:41 -07:00
for (i = 0; i < cs->numAlternateVisuals; i++)
if (cs->alternateVisuals[i] == visual)
return TRUE;
2006-11-26 11:13:41 -07:00
return FALSE;
}
static Bool
compImplicitRedirect(WindowPtr pWin, WindowPtr pParent)
2006-11-26 11:13:41 -07:00
{
if (pParent) {
ScreenPtr pScreen = pWin->drawable.pScreen;
XID winVisual = wVisual(pWin);
XID parentVisual = wVisual(pParent);
if (winVisual != parentVisual &&
(compIsAlternateVisual(pScreen, winVisual) ||
compIsAlternateVisual(pScreen, parentVisual)))
return TRUE;
2006-11-26 11:13:41 -07:00
}
return FALSE;
}
static void
compFreeOldPixmap(WindowPtr pWin)
2006-11-26 11:13:41 -07:00
{
ScreenPtr pScreen = pWin->drawable.pScreen;
if (pWin->redirectDraw != RedirectDrawNone) {
CompWindowPtr cw = GetCompWindow(pWin);
if (cw->pOldPixmap) {
(*pScreen->DestroyPixmap) (cw->pOldPixmap);
cw->pOldPixmap = NullPixmap;
}
2006-11-26 11:13:41 -07:00
}
}
void
compMoveWindow(WindowPtr pWin, int x, int y, WindowPtr pSib, VTKind kind)
{
ScreenPtr pScreen = pWin->drawable.pScreen;
CompScreenPtr cs = GetCompScreen(pScreen);
2006-11-26 11:13:41 -07:00
pScreen->MoveWindow = cs->MoveWindow;
(*pScreen->MoveWindow) (pWin, x, y, pSib, kind);
cs->MoveWindow = pScreen->MoveWindow;
pScreen->MoveWindow = compMoveWindow;
compFreeOldPixmap(pWin);
compCheckTree(pScreen);
2006-11-26 11:13:41 -07:00
}
void
compResizeWindow(WindowPtr pWin, int x, int y,
unsigned int w, unsigned int h, WindowPtr pSib)
2006-11-26 11:13:41 -07:00
{
ScreenPtr pScreen = pWin->drawable.pScreen;
CompScreenPtr cs = GetCompScreen(pScreen);
2006-11-26 11:13:41 -07:00
pScreen->ResizeWindow = cs->ResizeWindow;
(*pScreen->ResizeWindow) (pWin, x, y, w, h, pSib);
cs->ResizeWindow = pScreen->ResizeWindow;
pScreen->ResizeWindow = compResizeWindow;
compFreeOldPixmap(pWin);
compCheckTree(pWin->drawable.pScreen);
2006-11-26 11:13:41 -07:00
}
void
compChangeBorderWidth(WindowPtr pWin, unsigned int bw)
2006-11-26 11:13:41 -07:00
{
ScreenPtr pScreen = pWin->drawable.pScreen;
CompScreenPtr cs = GetCompScreen(pScreen);
2006-11-26 11:13:41 -07:00
pScreen->ChangeBorderWidth = cs->ChangeBorderWidth;
(*pScreen->ChangeBorderWidth) (pWin, bw);
cs->ChangeBorderWidth = pScreen->ChangeBorderWidth;
pScreen->ChangeBorderWidth = compChangeBorderWidth;
compFreeOldPixmap(pWin);
compCheckTree(pWin->drawable.pScreen);
2006-11-26 11:13:41 -07:00
}
void
compReparentWindow(WindowPtr pWin, WindowPtr pPriorParent)
2006-11-26 11:13:41 -07:00
{
ScreenPtr pScreen = pWin->drawable.pScreen;
CompScreenPtr cs = GetCompScreen(pScreen);
2006-11-26 11:13:41 -07:00
pScreen->ReparentWindow = cs->ReparentWindow;
/*
* Remove any implicit redirect due to synthesized visual
*/
if (compImplicitRedirect(pWin, pPriorParent))
compUnredirectWindow(serverClient, pWin, CompositeRedirectAutomatic);
2006-11-26 11:13:41 -07:00
/*
* Handle subwindows redirection
*/
compUnredirectOneSubwindow(pPriorParent, pWin);
compRedirectOneSubwindow(pWin->parent, pWin);
2006-11-26 11:13:41 -07:00
/*
* Add any implict redirect due to synthesized visual
*/
if (compImplicitRedirect(pWin, pWin->parent))
compRedirectWindow(serverClient, pWin, CompositeRedirectAutomatic);
2006-11-26 11:13:41 -07:00
/*
* Allocate any necessary redirect pixmap
* (this actually should never be true; pWin is always unmapped)
*/
compCheckRedirect(pWin);
2006-11-26 11:13:41 -07:00
/*
* Reset pixmap pointers as appropriate
*/
2007-11-24 10:55:21 -07:00
if (pWin->parent && pWin->redirectDraw == RedirectDrawNone)
compSetPixmap(pWin, (*pScreen->GetWindowPixmap) (pWin->parent));
2006-11-26 11:13:41 -07:00
/*
* Call down to next function
*/
if (pScreen->ReparentWindow)
(*pScreen->ReparentWindow) (pWin, pPriorParent);
2006-11-26 11:13:41 -07:00
cs->ReparentWindow = pScreen->ReparentWindow;
pScreen->ReparentWindow = compReparentWindow;
compCheckTree(pWin->drawable.pScreen);
2006-11-26 11:13:41 -07:00
}
void
compCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr prgnSrc)
2006-11-26 11:13:41 -07:00
{
ScreenPtr pScreen = pWin->drawable.pScreen;
CompScreenPtr cs = GetCompScreen(pScreen);
int dx = 0, dy = 0;
if (pWin->redirectDraw != RedirectDrawNone) {
PixmapPtr pPixmap = (*pScreen->GetWindowPixmap) (pWin);
CompWindowPtr cw = GetCompWindow(pWin);
assert(cw->oldx != COMP_ORIGIN_INVALID);
assert(cw->oldy != COMP_ORIGIN_INVALID);
if (cw->pOldPixmap) {
/*
* Ok, the old bits are available in pOldPixmap and
* need to be copied to pNewPixmap.
*/
RegionRec rgnDst;
PixmapPtr pPixmap = (*pScreen->GetWindowPixmap) (pWin);
GCPtr pGC;
dx = ptOldOrg.x - pWin->drawable.x;
dy = ptOldOrg.y - pWin->drawable.y;
RegionTranslate(prgnSrc, -dx, -dy);
RegionNull(&rgnDst);
RegionIntersect(&rgnDst, &pWin->borderClip, prgnSrc);
RegionTranslate(&rgnDst, -pPixmap->screen_x, -pPixmap->screen_y);
dx = dx + pPixmap->screen_x - cw->oldx;
dy = dy + pPixmap->screen_y - cw->oldy;
pGC = GetScratchGC(pPixmap->drawable.depth, pScreen);
if (pGC) {
BoxPtr pBox = RegionRects(&rgnDst);
int nBox = RegionNumRects(&rgnDst);
ValidateGC(&pPixmap->drawable, pGC);
while (nBox--) {
(void) (*pGC->ops->CopyArea) (&cw->pOldPixmap->drawable,
&pPixmap->drawable,
pGC,
pBox->x1 + dx, pBox->y1 + dy,
pBox->x2 - pBox->x1,
pBox->y2 - pBox->y1,
pBox->x1, pBox->y1);
pBox++;
}
FreeScratchGC(pGC);
}
return;
}
dx = pPixmap->screen_x - cw->oldx;
dy = pPixmap->screen_y - cw->oldy;
ptOldOrg.x += dx;
ptOldOrg.y += dy;
2006-11-26 11:13:41 -07:00
}
2006-11-26 11:13:41 -07:00
pScreen->CopyWindow = cs->CopyWindow;
if (ptOldOrg.x != pWin->drawable.x || ptOldOrg.y != pWin->drawable.y) {
if (dx || dy)
RegionTranslate(prgnSrc, dx, dy);
(*pScreen->CopyWindow) (pWin, ptOldOrg, prgnSrc);
if (dx || dy)
RegionTranslate(prgnSrc, -dx, -dy);
2006-11-26 11:13:41 -07:00
}
else {
ptOldOrg.x -= dx;
ptOldOrg.y -= dy;
RegionTranslate(prgnSrc,
pWin->drawable.x - ptOldOrg.x,
pWin->drawable.y - ptOldOrg.y);
DamageDamageRegion(&pWin->drawable, prgnSrc);
2006-11-26 11:13:41 -07:00
}
cs->CopyWindow = pScreen->CopyWindow;
pScreen->CopyWindow = compCopyWindow;
compCheckTree(pWin->drawable.pScreen);
2006-11-26 11:13:41 -07:00
}
Bool
compCreateWindow(WindowPtr pWin)
2006-11-26 11:13:41 -07:00
{
ScreenPtr pScreen = pWin->drawable.pScreen;
CompScreenPtr cs = GetCompScreen(pScreen);
Bool ret;
2006-11-26 11:13:41 -07:00
pScreen->CreateWindow = cs->CreateWindow;
ret = (*pScreen->CreateWindow) (pWin);
if (pWin->parent && ret) {
CompSubwindowsPtr csw = GetCompSubwindows(pWin->parent);
CompClientWindowPtr ccw;
(*pScreen->SetWindowPixmap) (pWin,
(*pScreen->GetWindowPixmap) (pWin->
parent));
if (csw)
for (ccw = csw->clients; ccw; ccw = ccw->next)
compRedirectWindow(clients[CLIENT_ID(ccw->id)],
pWin, ccw->update);
if (compImplicitRedirect(pWin, pWin->parent))
compRedirectWindow(serverClient, pWin, CompositeRedirectAutomatic);
2006-11-26 11:13:41 -07:00
}
cs->CreateWindow = pScreen->CreateWindow;
pScreen->CreateWindow = compCreateWindow;
compCheckTree(pWin->drawable.pScreen);
2006-11-26 11:13:41 -07:00
return ret;
}
Bool
compDestroyWindow(WindowPtr pWin)
2006-11-26 11:13:41 -07:00
{
ScreenPtr pScreen = pWin->drawable.pScreen;
CompScreenPtr cs = GetCompScreen(pScreen);
CompWindowPtr cw;
CompSubwindowsPtr csw;
Bool ret;
2006-11-26 11:13:41 -07:00
pScreen->DestroyWindow = cs->DestroyWindow;
while ((cw = GetCompWindow(pWin)))
FreeResource(cw->clients->id, RT_NONE);
while ((csw = GetCompSubwindows(pWin)))
FreeResource(csw->clients->id, RT_NONE);
2011-11-05 07:32:40 -06:00
if (pWin->redirectDraw != RedirectDrawNone) {
PixmapPtr pPixmap = (*pScreen->GetWindowPixmap) (pWin);
compSetParentPixmap(pWin);
(*pScreen->DestroyPixmap) (pPixmap);
2011-11-05 07:32:40 -06:00
}
2006-11-26 11:13:41 -07:00
ret = (*pScreen->DestroyWindow) (pWin);
cs->DestroyWindow = pScreen->DestroyWindow;
pScreen->DestroyWindow = compDestroyWindow;
/* compCheckTree (pWin->drawable.pScreen); can't check -- tree isn't good*/
return ret;
}
void
compSetRedirectBorderClip(WindowPtr pWin, RegionPtr pRegion)
2006-11-26 11:13:41 -07:00
{
CompWindowPtr cw = GetCompWindow(pWin);
RegionRec damage;
2006-11-26 11:13:41 -07:00
RegionNull(&damage);
2006-11-26 11:13:41 -07:00
/*
* Align old border clip with new border clip
*/
RegionTranslate(&cw->borderClip,
pWin->drawable.x - cw->borderClipX,
pWin->drawable.y - cw->borderClipY);
2006-11-26 11:13:41 -07:00
/*
* Compute newly visible portion of window for repaint
*/
RegionSubtract(&damage, pRegion, &cw->borderClip);
2006-11-26 11:13:41 -07:00
/*
* Report that as damaged so it will be redrawn
*/
DamageDamageRegion(&pWin->drawable, &damage);
RegionUninit(&damage);
2006-11-26 11:13:41 -07:00
/*
* Save the new border clip region
*/
RegionCopy(&cw->borderClip, pRegion);
2006-11-26 11:13:41 -07:00
cw->borderClipX = pWin->drawable.x;
cw->borderClipY = pWin->drawable.y;
}
RegionPtr
compGetRedirectBorderClip(WindowPtr pWin)
2006-11-26 11:13:41 -07:00
{
CompWindowPtr cw = GetCompWindow(pWin);
2006-11-26 11:13:41 -07:00
return &cw->borderClip;
}
static void
compWindowUpdateAutomatic(WindowPtr pWin)
2006-11-26 11:13:41 -07:00
{
CompWindowPtr cw = GetCompWindow(pWin);
ScreenPtr pScreen = pWin->drawable.pScreen;
WindowPtr pParent = pWin->parent;
PixmapPtr pSrcPixmap = (*pScreen->GetWindowPixmap) (pWin);
PictFormatPtr pSrcFormat = PictureWindowFormat(pWin);
PictFormatPtr pDstFormat = PictureWindowFormat(pWin->parent);
int error;
RegionPtr pRegion = DamageRegion(cw->damage);
PicturePtr pSrcPicture = CreatePicture(0, &pSrcPixmap->drawable,
pSrcFormat,
0, 0,
serverClient,
&error);
XID subwindowMode = IncludeInferiors;
PicturePtr pDstPicture = CreatePicture(0, &pParent->drawable,
pDstFormat,
CPSubwindowMode,
&subwindowMode,
serverClient,
&error);
2006-11-26 11:13:41 -07:00
/*
* First move the region from window to screen coordinates
*/
RegionTranslate(pRegion, pWin->drawable.x, pWin->drawable.y);
2006-11-26 11:13:41 -07:00
/*
* Clip against the "real" border clip
*/
RegionIntersect(pRegion, pRegion, &cw->borderClip);
2006-11-26 11:13:41 -07:00
/*
* Now translate from screen to dest coordinates
*/
RegionTranslate(pRegion, -pParent->drawable.x, -pParent->drawable.y);
2006-11-26 11:13:41 -07:00
/*
* Clip the picture
*/
SetPictureClipRegion(pDstPicture, 0, 0, pRegion);
2006-11-26 11:13:41 -07:00
/*
* And paint
*/
CompositePicture(PictOpSrc, pSrcPicture, 0, pDstPicture,
0, 0, /* src_x, src_y */
0, 0, /* msk_x, msk_y */
pSrcPixmap->screen_x - pParent->drawable.x,
pSrcPixmap->screen_y - pParent->drawable.y,
pSrcPixmap->drawable.width, pSrcPixmap->drawable.height);
FreePicture(pSrcPicture, 0);
FreePicture(pDstPicture, 0);
2006-11-26 11:13:41 -07:00
/*
* Empty the damage region. This has the nice effect of
* rendering the translations above harmless
*/
DamageEmpty(cw->damage);
2006-11-26 11:13:41 -07:00
}
2011-11-05 07:32:40 -06:00
static void
compPaintWindowToParent(WindowPtr pWin)
2006-11-26 11:13:41 -07:00
{
compPaintChildrenToWindow(pWin);
2006-11-26 11:13:41 -07:00
if (pWin->redirectDraw != RedirectDrawNone) {
CompWindowPtr cw = GetCompWindow(pWin);
2006-11-26 11:13:41 -07:00
if (cw->damaged) {
compWindowUpdateAutomatic(pWin);
cw->damaged = FALSE;
}
2006-11-26 11:13:41 -07:00
}
}
2011-11-05 07:32:40 -06:00
void
compPaintChildrenToWindow(WindowPtr pWin)
2011-11-05 07:32:40 -06:00
{
WindowPtr pChild;
if (!pWin->damagedDescendants)
return;
2011-11-05 07:32:40 -06:00
for (pChild = pWin->lastChild; pChild; pChild = pChild->prevSib)
compPaintWindowToParent(pChild);
2011-11-05 07:32:40 -06:00
pWin->damagedDescendants = FALSE;
}
2006-11-26 11:13:41 -07:00
WindowPtr
CompositeRealChildHead(WindowPtr pWin)
2006-11-26 11:13:41 -07:00
{
WindowPtr pChild, pChildBefore;
CompScreenPtr cs;
if (!pWin->parent &&
(screenIsSaved == SCREEN_SAVER_ON) &&
(HasSaverWindow(pWin->drawable.pScreen))) {
2006-11-26 11:13:41 -07:00
/* First child is the screen saver; see if next child is the overlay */
pChildBefore = pWin->firstChild;
pChild = pChildBefore->nextSib;
2006-11-26 11:13:41 -07:00
}
else {
pChildBefore = NullWindow;
pChild = pWin->firstChild;
2006-11-26 11:13:41 -07:00
}
if (!pChild) {
return NullWindow;
2006-11-26 11:13:41 -07:00
}
2006-11-26 11:13:41 -07:00
cs = GetCompScreen(pWin->drawable.pScreen);
if (pChild == cs->pOverlayWin) {
return pChild;
}
else {
return pChildBefore;
2006-11-26 11:13:41 -07:00
}
}
int
compConfigNotify(WindowPtr pWin, int x, int y, int w, int h,
int bw, WindowPtr pSib)
{
ScreenPtr pScreen = pWin->drawable.pScreen;
CompScreenPtr cs = GetCompScreen(pScreen);
Bool ret = 0;
WindowPtr pParent = pWin->parent;
int draw_x, draw_y;
Bool alloc_ret;
if (cs->ConfigNotify) {
pScreen->ConfigNotify = cs->ConfigNotify;
ret = (*pScreen->ConfigNotify) (pWin, x, y, w, h, bw, pSib);
cs->ConfigNotify = pScreen->ConfigNotify;
pScreen->ConfigNotify = compConfigNotify;
if (ret)
return ret;
}
if (pWin->redirectDraw == RedirectDrawNone)
return Success;
compCheckTree(pScreen);
draw_x = pParent->drawable.x + x + bw;
draw_y = pParent->drawable.y + y + bw;
alloc_ret = compReallocPixmap(pWin, draw_x, draw_y, w, h, bw);
if (alloc_ret == FALSE)
return BadAlloc;
return Success;
}