On Sat, Jul 18, 2009 at 20:49, RALOVICH,
Kristóf<[email protected]> wrote:
> On Fri, Jul 10, 2009 at 19:56, Eric Anholt<[email protected]> wrote:
>> On Fri, 2009-07-10 at 11:24 +0200, RALOVICH, Kristóf wrote:
>>> Please don't applies these right now. I am in the process of revising
>>> them since there might be a simpler approach to the problem.
>>
>> Excellent, I'd been delaying reviewing it because it looked more
>> complicated than I hoped :)
>>
>> --
>> Eric Anholt
>> [email protected]                         [email protected]
>>
>>
>>
>
> I have broken up the patches into smaller, independent ones. Attached
> to my following mails.
>
> Thanks,
> Kristof
>

Please review!

Thanks,
Kristof
From fc97b9c39f6b3808af016d4cf1a75e597334d5f6 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?RALOVICH,=20Krist=C3=B3f?= <[email protected]>
Date: Sat, 18 Jul 2009 23:44:18 +0200
Subject: [PATCH] glx: Release unrefrenced DRI configs.

This includes destroying those that are unmatched during
dri2CreateScreen().
---
 src/glx/x11/dri2_glx.c   |    4 +++
 src/glx/x11/dri_common.c |   47 ++++++++++++++++++++++++++++++++++++++++++++++
 src/glx/x11/dri_common.h |    6 +++++
 3 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/src/glx/x11/dri2_glx.c b/src/glx/x11/dri2_glx.c
index f4865ae..5d779c4 100644
--- a/src/glx/x11/dri2_glx.c
+++ b/src/glx/x11/dri2_glx.c
@@ -28,6 +28,7 @@
  *
  * Authors:
  *   Kristian Høgsberg ([email protected])
+ *   RALOVICH, Kristóf <[email protected]>
  */
 
 #ifdef GLX_DIRECT_RENDERING
@@ -488,6 +489,9 @@ static __GLXDRIscreen *dri2CreateScreen(__GLXscreenConfigs *psc, int screen,
     psc->configs = driConvertConfigs(psc->core, psc->configs, driver_configs);
     psc->visuals = driConvertConfigs(psc->core, psc->visuals, driver_configs);
 
+    driDestroyUnmatchedConfigs(psc->core, psc->visuals, psc->configs, driver_configs);
+    free(driver_configs);
+
     psp->destroyScreen = dri2DestroyScreen;
     psp->createContext = dri2CreateContext;
     psp->createDrawable = dri2CreateDrawable;
diff --git a/src/glx/x11/dri_common.c b/src/glx/x11/dri_common.c
index 6de4111..68a3a76 100644
--- a/src/glx/x11/dri_common.c
+++ b/src/glx/x11/dri_common.c
@@ -31,6 +31,7 @@
  *   Kevin E. Martin <[email protected]>
  *   Brian Paul <[email protected]>
  *   Kristian Høgsberg ([email protected])
+ *   RALOVICH, Kristóf <[email protected]>
  */
 
 #ifdef GLX_DIRECT_RENDERING
@@ -294,6 +295,9 @@ createDriMode(const __DRIcoreExtension *core,
     if (driConfigs[i] == NULL)
 	return NULL;
 
+    /* Now modes == driconfigs[i], equality is defined by
+     * driConfigEqual(). */
+
     config = Xmalloc(sizeof *config);
     if (config == NULL)
 	return NULL;
@@ -328,6 +332,49 @@ driConvertConfigs(const __DRIcoreExtension *core,
     return head.next;
 }
 
+/**
+ * Free driver_configs[i] where createDriMode() didn't find a match.
+ */
+_X_HIDDEN
+void
+driDestroyUnmatchedConfigs(const __DRIcoreExtension *core,
+                           __GLcontextModes *visuals,
+                           __GLcontextModes *fbconfigs,
+                           __DRIconfig     **driver_configs)
+{
+  int n = 0;
+  for( ; driver_configs[n]; n++) {
+  }
+
+  int *matched = calloc(1, n*sizeof(int));
+
+  __GLcontextModes* m;
+  for(m = visuals; m; m = m->next) {
+    for(unsigned int i = 0; driver_configs[i]; i++) {
+      if(driConfigEqual(core, m, driver_configs[i])) {
+        matched[i]++;
+        break;
+      }
+    }
+  }
+  for(m = fbconfigs; m; m = m->next) {
+    for(unsigned int i = 0; driver_configs[i]; i++) {
+      if(driConfigEqual(core, m, driver_configs[i])) {
+        matched[i]++;
+        break;
+      }
+    }
+  }
+
+  for(unsigned int i = 0; driver_configs[i]; i++) {
+    if(matched[i] < 1) {
+      free(driver_configs[i]);
+    }
+  }
+
+  free(matched);
+}
+
 _X_HIDDEN void
 driBindExtensions(__GLXscreenConfigs *psc, int dri2)
 {
diff --git a/src/glx/x11/dri_common.h b/src/glx/x11/dri_common.h
index 61ac9c6..34ab6c9 100644
--- a/src/glx/x11/dri_common.h
+++ b/src/glx/x11/dri_common.h
@@ -31,6 +31,7 @@
  *   Kevin E. Martin <[email protected]>
  *   Brian Paul <[email protected]>
  *   Kristian Høgsberg ([email protected])
+ *   RALOVICH, Kristóf <[email protected]>
  */
 
 #ifndef _DRI_COMMON_H
@@ -48,6 +49,11 @@ extern __GLcontextModes *driConvertConfigs(const __DRIcoreExtension * core,
                                            __GLcontextModes * modes,
                                            const __DRIconfig ** configs);
 
+extern void driDestroyUnmatchedConfigs(const __DRIcoreExtension *core,
+                                       __GLcontextModes *visuals,
+                                       __GLcontextModes *fbconfigs,
+                                       __DRIconfig     **driver_configs);
+
 extern const __DRIsystemTimeExtension systemTimeExtension;
 
 extern void InfoMessageF(const char *f, ...);
-- 
1.6.3.3

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Mesa3d-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to