Piotr Caban : gdi32: Share font_gamma_ramp structure between all DCs.

Alexandre Julliard julliard at winehq.org
Thu Sep 24 15:49:05 CDT 2020


Module: wine
Branch: master
Commit: 2370e7b9a14f461cb4cedd29114b8268158e450d
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=2370e7b9a14f461cb4cedd29114b8268158e450d

Author: Piotr Caban <piotr at codeweavers.com>
Date:   Wed Sep 23 17:44:57 2020 +0200

gdi32: Share font_gamma_ramp structure between all DCs.

Signed-off-by: Piotr Caban <piotr at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/gdi32/dc.c            |  1 -
 dlls/gdi32/dibdrv/dibdrv.h |  2 +-
 dlls/gdi32/font.c          | 18 ++++++++++++------
 dlls/gdi32/gdi_private.h   |  2 +-
 4 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/dlls/gdi32/dc.c b/dlls/gdi32/dc.c
index c24b96e275..230f1949e8 100644
--- a/dlls/gdi32/dc.c
+++ b/dlls/gdi32/dc.c
@@ -168,7 +168,6 @@ static void free_dc_state( DC *dc )
     if (dc->hVisRgn) DeleteObject( dc->hVisRgn );
     if (dc->region) DeleteObject( dc->region );
     if (dc->path) free_gdi_path( dc->path );
-    HeapFree( GetProcessHeap(), 0, dc->font_gamma_ramp );
     HeapFree( GetProcessHeap(), 0, dc );
 }
 
diff --git a/dlls/gdi32/dibdrv/dibdrv.h b/dlls/gdi32/dibdrv/dibdrv.h
index 98e1b0fba9..5369776484 100644
--- a/dlls/gdi32/dibdrv/dibdrv.h
+++ b/dlls/gdi32/dibdrv/dibdrv.h
@@ -88,7 +88,7 @@ struct intensity_range
 struct font_intensities
 {
     struct intensity_range ranges[17];
-    struct font_gamma_ramp *gamma_ramp;
+    const struct font_gamma_ramp *gamma_ramp;
 };
 
 typedef struct dibdrv_physdev
diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c
index e099bec5e8..a71b24423a 100644
--- a/dlls/gdi32/font.c
+++ b/dlls/gdi32/font.c
@@ -730,20 +730,17 @@ static void update_font_code_page( DC *dc, HANDLE font )
     TRACE("charset %d => cp %d\n", charset, dc->font_code_page);
 }
 
-static struct font_gamma_ramp *get_font_gamma_ramp( void )
+static BOOL WINAPI fill_font_gamma_ramp( INIT_ONCE *once, void *param, void **context )
 {
     static const WCHAR desktopW[] = { 'C','o','n','t','r','o','l',' ','P','a','n','e','l','\\',
                                       'D','e','s','k','t','o','p',0 };
     static const WCHAR smoothing_gamma[] = { 'F','o','n','t','S','m','o','o','t','h','i','n','g',
                                              'G','a','m','m','a',0 };
+    struct font_gamma_ramp *ramp = param;
     const DWORD gamma_default = 1400;
-    struct font_gamma_ramp *ramp;
     DWORD  i, gamma;
     HKEY key;
 
-    ramp = HeapAlloc( GetProcessHeap(), 0, sizeof(*ramp) );
-    if ( ramp == NULL) return NULL;
-
     gamma = gamma_default;
     if (RegOpenKeyW( HKEY_CURRENT_USER, desktopW, &key ) == ERROR_SUCCESS)
     {
@@ -768,7 +765,16 @@ static struct font_gamma_ramp *get_font_gamma_ramp( void )
     ramp->gamma = gamma;
     TRACE("gamma %d\n", ramp->gamma);
 
-    return ramp;
+    return TRUE;
+}
+
+static struct font_gamma_ramp *get_font_gamma_ramp( void )
+{
+    static INIT_ONCE init_once = INIT_ONCE_STATIC_INIT;
+    static struct font_gamma_ramp ramp;
+
+    InitOnceExecuteOnce( &init_once, fill_font_gamma_ramp, &ramp, NULL );
+    return &ramp;
 }
 
 /***********************************************************************
diff --git a/dlls/gdi32/gdi_private.h b/dlls/gdi32/gdi_private.h
index 4bb4661966..7f83732372 100644
--- a/dlls/gdi32/gdi_private.h
+++ b/dlls/gdi32/gdi_private.h
@@ -99,7 +99,7 @@ typedef struct tagDC
 
     struct gdi_path *path;
 
-    struct font_gamma_ramp *font_gamma_ramp;
+    const struct font_gamma_ramp *font_gamma_ramp;
 
     UINT          font_code_page;
     WORD          ROPmode;




More information about the wine-cvs mailing list