From 1941e8443b676ec7471e64f3cb4fbf544e99e5b6 Mon Sep 17 00:00:00 2001 From: miroslawzn Date: Wed, 8 Dec 2010 15:15:49 -0800 Subject: [PATCH] 6859086: Dialog created by JOptionPane.showMessageDialog does not repaint sometimes Reviewed-by: bae, chrisphi --- .../java2d/windows/GDIWindowSurfaceData.cpp | 18 +++++++++++++++++- .../sun/java2d/windows/GDIWindowSurfaceData.h | 12 ++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/windows/native/sun/java2d/windows/GDIWindowSurfaceData.cpp b/src/windows/native/sun/java2d/windows/GDIWindowSurfaceData.cpp index 21b944d20..5ddf0d76f 100644 --- a/src/windows/native/sun/java2d/windows/GDIWindowSurfaceData.cpp +++ b/src/windows/native/sun/java2d/windows/GDIWindowSurfaceData.cpp @@ -54,6 +54,7 @@ static HPEN nullpen; static jclass xorCompClass; static jboolean beingShutdown = JNI_FALSE; +static volatile LONG timeStamp = 0; extern CriticalSection windowMoveLock; extern "C" @@ -90,12 +91,24 @@ void SetupThreadGraphicsInfo(JNIEnv *env, GDIWinSDOps *wsdo) { HDC oldhDC = info->hDC; // the hDC is NULL for offscreen surfaces - we don't store it // in TLS as it must be created new every time. - if (((oldhDC == NULL) && wsdo->window != NULL) || (info->wsdo != wsdo)) { + + if( ((oldhDC == NULL) && wsdo->window != NULL) || + (info->wsdo != wsdo) || + (info->wsdoTimeStamp != wsdo->timeStamp) ) + { // Init graphics state, either because this is our first time // using it in this thread or because this thread is now // dealing with a different window than it was last time. + //check extra condition: + //(info->wsdoTimeStamp != wsdo->timeStamp). + //Checking memory addresses (info->wsdo != wsdo) will not detect + //that wsdo points to a newly allocated structure in case + //that structure just got allocated at a "recycled" memory location + //which previously was pointed by info->wsdo + //see bug# 6859086 + // Release cached DC. We use deferred DC releasing mechanism because // the DC is associated with cached wsdo and component peer, // which may've been disposed by this time, and we have @@ -157,7 +170,9 @@ void SetupThreadGraphicsInfo(JNIEnv *env, GDIWinSDOps *wsdo) { info->xorcolor = 0; info->patrop = PATCOPY; + //store the address and time stamp of newly allocated GDIWinSDOps structure info->wsdo = wsdo; + info->wsdoTimeStamp = wsdo->timeStamp; } } @@ -367,6 +382,7 @@ Java_sun_java2d_windows_GDIWindowSurfaceData_initOps(JNIEnv *env, jobject wsd, JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed."); return; } + wsdo->timeStamp = InterlockedIncrement(&timeStamp); //creation time stamp wsdo->sdOps.Lock = GDIWinSD_Lock; wsdo->sdOps.GetRasInfo = GDIWinSD_GetRasInfo; wsdo->sdOps.Unlock = GDIWinSD_Unlock; diff --git a/src/windows/native/sun/java2d/windows/GDIWindowSurfaceData.h b/src/windows/native/sun/java2d/windows/GDIWindowSurfaceData.h index a70b9bf21..8c0bcc3cd 100644 --- a/src/windows/native/sun/java2d/windows/GDIWindowSurfaceData.h +++ b/src/windows/native/sun/java2d/windows/GDIWindowSurfaceData.h @@ -148,6 +148,11 @@ typedef void InvalidateSDFunc(JNIEnv *env, */ struct _GDIWinSDOps { SurfaceDataOps sdOps; + LONG timeStamp; // creation time stamp. + // Doesn't store a real time - + // just counts creation events of this structure + // made by GDIWindowSurfaceData_initOps() + // see bug# 6859086 jboolean invalid; GetDCFunc *GetDC; ReleaseDCFunc *ReleaseDC; @@ -192,6 +197,13 @@ extern "C" { typedef struct { HDC hDC; GDIWinSDOps *wsdo; + LONG wsdoTimeStamp; // wsdo creation time stamp. + // Other threads may deallocate wsdo + // and then allocate a new GDIWinSDOps + // structure at the same memory location. + // Time stamp is the only way to detect if + // wsdo got changed. + // see bug# 6859086 RECT bounds; jobject clip; jobject comp; -- GitLab