Cache visual and depth information in drawing surface since it is not available

when the surface is an offscreen PixMap
This commit is contained in:
spider 1998-06-18 23:00:05 +00:00
parent 3bfaaa037a
commit ddb4ebba46
3 changed files with 19 additions and 14 deletions

View File

@ -33,6 +33,8 @@ typedef struct nsDrawingSurfaceUnix {
Display *display ;
Drawable drawable ;
GC gc ;
Visual * visual ;
PRUint32 depth ;
};
class nsDeviceContextUnix : public nsIDeviceContext

View File

@ -224,7 +224,6 @@ nsresult nsImageUnix::Optimize(nsDrawingSurface aDrawingSurface)
void nsImageUnix::CreateImage(nsDrawingSurface aSurface)
{
XWindowAttributes wa;
PRUint32 wdepth;
Visual * visual ;
PRUint32 format ;
@ -232,23 +231,15 @@ void nsImageUnix::CreateImage(nsDrawingSurface aSurface)
//char * data = (char *) PR_Malloc(sizeof(char) * mWidth * mHeight * mDepth);
if(mImageBits) {
::XGetWindowAttributes(unixdrawing->display,
unixdrawing->drawable,
&wa);
/* XXX What if mDepth != wDepth */
wdepth = wa.depth;
visual = wa.visual;
/* Need to support monochrome too */
if (visual->c_class == TrueColor || visual->c_class == DirectColor)
if (unixdrawing->visual->c_class == TrueColor || unixdrawing->visual->c_class == DirectColor)
format = ZPixmap;
else
format = XYPixmap;
mImage = ::XCreateImage(unixdrawing->display,
visual,
wdepth,
unixdrawing->visual,
unixdrawing->depth,
format,
0,
(char *)mImageBits,

View File

@ -132,6 +132,7 @@ NS_IMPL_RELEASE(nsRenderingContextUnix)
nsresult nsRenderingContextUnix :: Init(nsIDeviceContext* aContext,
nsIWidget *aWindow)
{
if (nsnull == aWindow->GetNativeData(NS_NATIVE_WINDOW))
return NS_ERROR_NOT_INITIALIZED;
@ -144,6 +145,15 @@ nsresult nsRenderingContextUnix :: Init(nsIDeviceContext* aContext,
mRenderingSurface->drawable = (Drawable)aWindow->GetNativeData(NS_NATIVE_WINDOW);
mRenderingSurface->gc = (GC)aWindow->GetNativeData(NS_NATIVE_GRAPHIC);
XWindowAttributes wa;
::XGetWindowAttributes(mRenderingSurface->display,
mRenderingSurface->drawable,
&wa);
mRenderingSurface->visual = wa.visual;
mRenderingSurface->depth = wa.depth;
mFrontBuffer = mRenderingSurface;
((nsDeviceContextUnix *)aContext)->SetDrawingSurface(mRenderingSurface);
@ -482,6 +492,8 @@ nsDrawingSurface nsRenderingContextUnix :: CreateDrawingSurface(nsRect *aBounds)
surface->drawable = p ;
surface->display = mRenderingSurface->display;
surface->gc = mRenderingSurface->gc;
surface->visual = mRenderingSurface->visual;
surface->depth = mRenderingSurface->depth;
return ((nsDrawingSurface)surface);
}
@ -494,8 +506,8 @@ void nsRenderingContextUnix :: DestroyDrawingSurface(nsDrawingSurface aDS)
::XFreePixmap(surface->display, surface->drawable);
//XXX greg, this seems bad. MMP
//if (mRenderingSurface == surface)
//mRenderingSurface = nsnull;
if (mRenderingSurface == surface)
mRenderingSurface = nsnull;
delete aDS;
}