fixed random crashes and strange rendering due to using a destroyed GC.
This commit is contained in:
dinglis%qnx.com 2001-11-05 18:53:03 +00:00
Родитель 370c318591
Коммит dc5689b6c4
6 изменённых файлов: 29 добавлений и 42 удалений

Просмотреть файл

@ -225,7 +225,6 @@ void nsDeviceContextPh :: CommonInit( nsNativeDeviceContext aDC ) {
}
NS_IMETHODIMP nsDeviceContextPh :: CreateRenderingContext( nsIRenderingContext *&aContext ) {
/* I stole this code from windows but its not working yet! */
nsIRenderingContext *pContext;
nsresult rv;
nsDrawingSurfacePh *surf;
@ -237,10 +236,7 @@ NS_IMETHODIMP nsDeviceContextPh :: CreateRenderingContext( nsIRenderingContext *
surf = new nsDrawingSurfacePh();
if( nsnull != surf ) {
/* I think this is a good idea... not sure if mDC is the right one tho... */
PhGC_t * aGC = (PhGC_t *) mDC;
rv = surf->Init(aGC);
rv = surf->Init();
if( NS_OK == rv ) rv = pContext->Init(this, surf);
else rv = NS_ERROR_OUT_OF_MEMORY;
}

Просмотреть файл

@ -89,7 +89,6 @@ nsDrawingSurfacePh :: nsDrawingSurfacePh( )
nsDrawingSurfacePh :: ~nsDrawingSurfacePh( )
{
if(mDrawContext) {
mDrawContext->gc = nsnull; /* because we do not own mGC and mDrawContext->gc, do not allow PhDCRelease to release this, as it belongs to upper classes */
PhDCRelease( mDrawContext ); /* the mDrawContext->gc will be free by the upper classes */
mDrawContext = nsnull;
}
@ -171,6 +170,8 @@ NS_IMETHODIMP nsDrawingSurfacePh :: Lock( PRInt32 aX, PRInt32 aY,
case Pg_IMAGE_DIRECT_555:
bpl = 2;
break;
default:
return NS_ERROR_FAILURE;
}
*aStride = *aWidthBytes = bpl * dst_area.size.w;
@ -224,18 +225,19 @@ NS_IMETHODIMP nsDrawingSurfacePh :: GetPixelFormat( nsPixelFormat *aFormat ) {
}
NS_IMETHODIMP nsDrawingSurfacePh :: Init( PhGC_t * &aGC ) {
mGC = aGC;
NS_IMETHODIMP nsDrawingSurfacePh :: Init( ) {
mGC = PgCreateGC(0);
if( !mGC )
return NS_ERROR_FAILURE;
// PgSetDrawBufferSize(65000);
// this is definatly going to be on the screen, as it will be the window of a widget or something
mIsOffscreen = PR_FALSE;
mDrawContext = nsnull;
return NS_OK;
}
NS_IMETHODIMP nsDrawingSurfacePh :: Init( PhGC_t * &aGC, PRUint32 aWidth, PRUint32 aHeight, PRUint32 aFlags ) {
mGC = aGC;
NS_IMETHODIMP nsDrawingSurfacePh :: Init(PRUint32 aWidth, PRUint32 aHeight, PRUint32 aFlags ) {
mWidth = aWidth;
mHeight = aHeight;
mFlags = aFlags;
@ -249,15 +251,15 @@ NS_IMETHODIMP nsDrawingSurfacePh :: Init( PhGC_t * &aGC, PRUint32 aWidth, PRUint
if( !mDrawContext ) return NS_ERROR_FAILURE;
dc = PhDCSetCurrent(mDrawContext);
PgSetDrawBufferSize(65000);
/// HACK HACK until photon lib is fixed
#if 1
/// HACK HACK until photon lib is fixed
if (mDrawContext->gin.cmd_buffer_size < 12) {
mDrawContext->gin.cmd_buffer_size = 12;
mDrawContext->gin.cmd_ptr = mDrawContext->gin.cmd_buffer + 3;
}
#endif
mGC = PgGetGC();
PhDCSetCurrent(dc);
/* use the gc provided */
PgDestroyGC( mDrawContext->gc );
mDrawContext->gc = mGC;
return NS_OK;
}
@ -279,22 +281,23 @@ int nsDrawingSurfacePh::prefChanged(const char *aPref, void *aClosure)
}
if(surface->mDrawContext) {
PhDrawContext_t *dc;
surface->mDrawContext->gc = nsnull; /* because we do not own mGC and mDrawContext->gc, do not allow PhDCRelease to release this, as it belongs to upper classes */
PhDCRelease( surface->mDrawContext ); /* the mDrawContext->gc will be free by the upper classes */
surface->mDrawContext = nsnull;
surface->mDrawContext->gc = nsnull; /* because we do not want to destroy the one we have since other have it */
PhDCRelease( surface->mDrawContext );
surface->mDrawContext = (PhDrawContext_t *)PdCreateOffscreenContext(0, surface->mWidth, surface->mHeight, 0);
if( !surface->mDrawContext ) return NS_ERROR_FAILURE;
dc = PhDCSetCurrent(surface->mDrawContext);
PgSetDrawBufferSize(65000);
#if 1
/// HACK HACK until photon lib is fixed
if (surface->mDrawContext->gin.cmd_buffer_size < 12) {
surface->mDrawContext->gin.cmd_buffer_size = 12;
surface->mDrawContext->gin.cmd_ptr = surface->mDrawContext->gin.cmd_buffer + 3;
}
#endif
PhDCSetCurrent(dc);
/* use the gc provided */
PgDestroyGC( surface->mDrawContext->gc );
PgDestroyGC(surface->mDrawContext->gc);
surface->mDrawContext->gc = surface->mGC;
/* use the gc provided */
}
return 0;
}

Просмотреть файл

@ -66,10 +66,10 @@ public:
//nsIDrawingSurfacePh interface
/* Initialize a On-Screen Drawing Surface */
NS_IMETHOD Init(PhGC_t * &aGC);
NS_IMETHOD Init();
/* Initizlize a Off-Screen Drawing Surface */
NS_IMETHOD Init(PhGC_t * &aGC, PRUint32 aWidth, PRUint32 aHeight, PRUint32 aFlags);
NS_IMETHOD Init(PRUint32 aWidth, PRUint32 aHeight, PRUint32 aFlags);
/* Make this DrawingSurface active */
NS_IMETHOD Select(void);

Просмотреть файл

@ -60,7 +60,7 @@ public:
* @param aDC HDC to initialize drawing surface with
* @return error status
**/
NS_IMETHOD Init( PhGC_t * &aGC ) = 0;
NS_IMETHOD Init( ) = 0;
/**
* Initialize an offscreen drawing surface using a
@ -75,7 +75,7 @@ public:
* surface created
* @return error status
**/
NS_IMETHOD Init( PhGC_t * &aGC, PRUint32 aWidth, PRUint32 aHeight,
NS_IMETHOD Init( PRUint32 aWidth, PRUint32 aHeight,
PRUint32 aFlags) = 0;
};

Просмотреть файл

@ -90,7 +90,7 @@ nsRenderingContextPh :: nsRenderingContextPh()
mStateCache = new nsVoidArray();
if( mPtGC == nsnull ) mPtGC = PgGetGC();
mPtDC = PhDCGetCurrent();
mInitialized = PR_FALSE;
PushState();
}
@ -118,13 +118,9 @@ nsRenderingContextPh :: ~nsRenderingContextPh()
/* Go back to the default Photon DrawContext */
/* This allows the photon widgets under Viewer to work right */
PhDCSetCurrent(mPtDC);
PgSetGC( mPtGC );
PgSetRegion( mPtGC->rid );
if( mGC ) {
PgDestroyGC( mGC ); /* this causes crashes */
mGC = nsnull;
}
if( mPhotonFontName )
delete [] mPhotonFontName;
}
@ -147,23 +143,15 @@ NS_IMETHODIMP nsRenderingContextPh :: Init( nsIDeviceContext* aContext, nsIWidge
PhRid_t rid = PtWidgetRid( mWidget );
if( rid ) {
mGC = PgCreateGC(0);
if( !mGC )
return NS_ERROR_FAILURE;
PgSetDrawBufferSize(65000);
/* Make sure the new GC is reset to the default settings */
PgDefaultGC( mGC );
mSurface = new nsDrawingSurfacePh();
if( mSurface ) {
res = mSurface->Init( mGC );
res = mSurface->Init();
if( res != NS_OK )
return NS_ERROR_FAILURE;
mOffscreenSurface = mSurface;
NS_ADDREF( mSurface );
mGC = mSurface->GetGC();
/* hack up code to setup new GC for on screen drawing */
PgSetGC( mGC );
PgSetRegion( rid );
@ -614,8 +602,7 @@ NS_IMETHODIMP nsRenderingContextPh :: CreateDrawingSurface( nsRect *aBounds, PRU
nsDrawingSurfacePh *surf = new nsDrawingSurfacePh();
if( surf ) {
NS_ADDREF(surf);
PhGC_t *gc = mSurface->GetGC();
surf->Init( gc, aBounds->width, aBounds->height, aSurfFlags );
surf->Init( aBounds->width, aBounds->height, aSurfFlags );
}
else
return NS_ERROR_FAILURE;

Просмотреть файл

@ -211,6 +211,7 @@ private:
void StopDrawing();
#endif
protected:
PhDrawContext_t *mPtDC;
PhGC_t *mGC;
PhGC_t *mholdGC;
nscolor mCurrentColor;