Skip to content

Commit fa7f53e

Browse files
committed
8235147: Release HDC from passiveDCList sooner
Reviewed-by: serb, jdv
1 parent f916df3 commit fa7f53e

2 files changed

Lines changed: 29 additions & 7 deletions

File tree

src/java.desktop/windows/native/libawt/windows/awt_Component.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1374,7 +1374,7 @@ LRESULT AwtComponent::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
13741374
{
13751375
HDC hDC;
13761376
// First, release the DCs scheduled for deletion
1377-
ReleaseDCList(GetHWnd(), passiveDCList);
1377+
ReleaseDCList(passiveDCList);
13781378

13791379
GetDCReturnStruct *returnStruct = new GetDCReturnStruct;
13801380
returnStruct->gdiLimitReached = FALSE;
@@ -1402,7 +1402,7 @@ LRESULT AwtComponent::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
14021402
{
14031403
HDC hDC = (HDC)wParam;
14041404
MoveDCToPassiveList(hDC, GetHWnd());
1405-
ReleaseDCList(GetHWnd(), passiveDCList);
1405+
ReleaseDCList(passiveDCList);
14061406
mr = mrConsume;
14071407
break;
14081408
}
@@ -1411,7 +1411,7 @@ LRESULT AwtComponent::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
14111411
// Called during Component destruction. Gets current list of
14121412
// DC's associated with Component and releases each DC.
14131413
ReleaseDCList(GetHWnd(), activeDCList);
1414-
ReleaseDCList(GetHWnd(), passiveDCList);
1414+
ReleaseDCList(passiveDCList);
14151415
mr = mrConsume;
14161416
break;
14171417
}
@@ -7436,6 +7436,19 @@ DCItem *DCList::RemoveAllDCs(HWND hWnd)
74367436
return newListPtr;
74377437
}
74387438

7439+
/**
7440+
* Remove all DCs from the DC list. Return the list of those
7441+
* DC's to the caller (which will then probably want to
7442+
* call ReleaseDC() for the returned DCs).
7443+
*/
7444+
DCItem *DCList::RemoveAllDCs()
7445+
{
7446+
listLock.Enter();
7447+
DCItem *newListPtr = head;
7448+
head = NULL;
7449+
listLock.Leave();
7450+
return newListPtr;
7451+
}
74397452

74407453
/**
74417454
* Realize palettes of all existing HDC objects
@@ -7458,8 +7471,7 @@ void MoveDCToPassiveList(HDC hDC, HWND hWnd) {
74587471
}
74597472
}
74607473

7461-
void ReleaseDCList(HWND hwnd, DCList &list) {
7462-
DCItem *removedDCs = list.RemoveAllDCs(hwnd);
7474+
static void ReleaseDCList(DCItem *removedDCs) {
74637475
while (removedDCs) {
74647476
DCItem *tmpDCList = removedDCs;
74657477
DASSERT(::GetObjectType(tmpDCList->hDC) == OBJ_DC);
@@ -7473,3 +7485,11 @@ void ReleaseDCList(HWND hwnd, DCList &list) {
74737485
delete tmpDCList;
74747486
}
74757487
}
7488+
7489+
void ReleaseDCList(HWND hwnd, DCList &list) {
7490+
ReleaseDCList(list.RemoveAllDCs(hwnd));
7491+
}
7492+
7493+
void ReleaseDCList(DCList &list) {
7494+
ReleaseDCList(list.RemoveAllDCs());
7495+
}

src/java.desktop/windows/native/libawt/windows/awt_Component.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 1996, 2016, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -923,10 +923,12 @@ class DCList {
923923
void AddDCItem(DCItem *newItem);
924924
DCItem *RemoveDC(HDC hDC, HWND hWnd);
925925
DCItem *RemoveAllDCs(HWND hWnd);
926+
DCItem *RemoveAllDCs();
926927
void RealizePalettes(int screen);
927928
};
928929

929930
void ReleaseDCList(HWND hwnd, DCList &list);
931+
void ReleaseDCList(DCList &list);
930932
void MoveDCToPassiveList(HDC hDC, HWND hWnd);
931933

932934
#include "ObjectList.h"

0 commit comments

Comments
 (0)