check_gl: cleanup allocated resources 47/20847/1
authorStanislav Vorobiov <s.vorobiov@samsung.com>
Tue, 13 May 2014 06:44:38 +0000 (10:44 +0400)
committerStanislav Vorobiov <s.vorobiov@samsung.com>
Tue, 13 May 2014 07:17:43 +0000 (11:17 +0400)
since check_gl is now being used inside qemu
process we need to cleanup resources allocated by it

Change-Id: Icb5ccf8e7ccc67e57c1ec856a1348c767599a95a
Signed-off-by: Stanislav Vorobiov <s.vorobiov@samsung.com>
tizen/src/check_gl.h
tizen/src/check_gl_cgl.c
tizen/src/check_gl_core.c
tizen/src/check_gl_glx.c
tizen/src/check_gl_wgl.c

index 6750e3ca175dfc24ee4bbcb262cbcce6e0f27905..89594a7a5e44d5cc4f13038a473886d3af8f447b 100644 (file)
@@ -45,11 +45,13 @@ typedef enum
     gl_3_2 = 2
 } gl_version;
 
+int check_gl(void);
+
 void check_gl_log(gl_log_level level, const char *format, ...);
 
 int check_gl_init(void);
 
-int check_gl(void);
+void check_gl_cleanup(void);
 
 struct gl_context *check_gl_context_create(struct gl_context *share_ctx,
                                            gl_version version);
index c7763258078a45fcf18091f9ade3b55680aaa00b..379bab38a94c29467c8ed38a98791ff0f82067f0 100644 (file)
@@ -60,6 +60,10 @@ int check_gl_init(void)
     return 1;
 }
 
+void check_gl_cleanup(void)
+{
+}
+
 struct gl_context *check_gl_context_create(struct gl_context *share_ctx,
                                            gl_version version)
 {
index 6e48d66c8c967569175bd0089bdcd4ed12a2827c..3912a696a4f8d65fd71f340e22ca6a24dbfb5766 100644 (file)
@@ -138,9 +138,10 @@ fail:
 
 int check_gl(void)
 {
-    struct gl_context *ctx_2;
-    struct gl_context *ctx_3_1;
-    struct gl_context *ctx_3_2;
+    int res = 1;
+    struct gl_context *ctx_2 = NULL;
+    struct gl_context *ctx_3_1 = NULL;
+    struct gl_context *ctx_3_2 = NULL;
     int have_es3 = 0;
     int have_es3_compatibility = 0;
     int have_es1 = 0;
@@ -152,7 +153,7 @@ int check_gl(void)
     if (!check_gl_procaddr((void**)&get_string, "glGetString", 0) ||
         !check_gl_procaddr((void**)&get_stringi, "glGetStringi", 1) ||
         !check_gl_procaddr((void**)&get_integerv, "glGetIntegerv", 0)) {
-        return 1;
+        goto out;
     }
 
     ctx_2 = check_gl_version(gl_2);
@@ -161,7 +162,7 @@ int check_gl(void)
 
     if (!ctx_2 && !ctx_3_1 && !ctx_3_2) {
         check_gl_log(gl_info, "Host does not have hardware GL acceleration!");
-        return 1;
+        goto out;
     }
 
     have_es1 = (ctx_2 != NULL);
@@ -247,5 +248,22 @@ int check_gl(void)
 
     check_gl_log(gl_info, "Host has hardware GL acceleration!");
 
-    return 0;
+    res = 0;
+
+out:
+    if (ctx_2) {
+        check_gl_context_destroy(ctx_2);
+    }
+
+    if (ctx_3_1) {
+        check_gl_context_destroy(ctx_3_1);
+    }
+
+    if (ctx_3_2) {
+        check_gl_context_destroy(ctx_3_2);
+    }
+
+    check_gl_cleanup();
+
+    return res;
 }
index f8c13a8245eaf150d39f9c0a89345f0047b3df0a..8034c5c7f084905615586962a6ef724248837529 100644 (file)
@@ -104,7 +104,7 @@ int check_gl_init(void)
 
     if (!handle) {
         check_gl_log(gl_error, "%s", dlerror());
-        return 0;
+        goto fail;
     }
 
     get_proc_address = dlsym(handle, "glXGetProcAddress");
@@ -115,7 +115,7 @@ int check_gl_init(void)
 
     if (!get_proc_address) {
         check_gl_log(gl_error, "%s", dlerror());
-        return 0;
+        goto fail;
     }
 
     GLX_GET_PROC(choose_fb_config, glXChooseFBConfig);
@@ -133,7 +133,7 @@ int check_gl_init(void)
 
     if (!configs || (n <= 0)) {
         check_gl_log(gl_error, "Unable to find suitable FB config");
-        return 0;
+        goto fail;
     }
 
     x_config = configs[0];
@@ -141,6 +141,16 @@ int check_gl_init(void)
     XFree(configs);
 
     return 1;
+
+fail:
+    XCloseDisplay(x_dpy);
+
+    return 0;
+}
+
+void check_gl_cleanup(void)
+{
+    XCloseDisplay(x_dpy);
 }
 
 struct gl_context *check_gl_context_create(struct gl_context *share_ctx,
index f447c5a1dfa6c2376a659ab54bcf86466419dad6..702b555de3b5dbaf873eb9c36d5c4a3120b203e6 100644 (file)
@@ -298,6 +298,17 @@ fail:
     return 0;
 }
 
+void check_gl_cleanup(void)
+{
+    ReleaseDC(win, dc);
+    DestroyWindow(win);
+    delete_context(init_ctx);
+    ReleaseDC(init_win, init_dc);
+    DestroyWindow(init_win);
+
+    UnregisterClassA((LPCTSTR)"CheckGLWinClass", NULL);
+}
+
 struct gl_context *check_gl_context_create(struct gl_context *share_ctx,
                                            gl_version version)
 {