Fix DuplicateCode score for fastpath and tracepath 60/240860/3 submit/tizen/20200818.051921
authorXuelian <xuelian.bai@samsung.com>
Wed, 12 Aug 2020 15:59:30 +0000 (23:59 +0800)
committerXuelian <xuelian.bai@samsung.com>
Wed, 12 Aug 2020 16:19:19 +0000 (00:19 +0800)
Create functions for duplicated code:
_dump_glue_ctx_list
_init_objid_array
DuplicatedCode Score: 4.55->4.63

Change-Id: I57c6c1a1b45bf45f5148fee4c1649bb562432bb9
Signed-off-by: Xuelian Bai <xuelian.bai@samsung.com>
src/modules/coregl_fastpath_egl.c
src/modules/coregl_fastpath_gl.c
src/modules/coregl_tracepath.c
src/modules/coregl_tracepath_egl.c
src/modules/coregl_tracepath_gl.c

index 830d260..c9abbaf 100644 (file)
@@ -17,6 +17,29 @@ General_Trace_List *glue_ctx_trace_list = NULL;
 General_Trace_List *context_state_trace_list = NULL;
 int current_gl_api_version = 0;
 
+static void
+_dump_glue_ctx_list(GLContextState *cur_cstate)
+{
+       General_Trace_List *current = NULL;
+       current = glue_ctx_trace_list;
+
+       while (current != NULL) {
+               GLGlueContext *cur_gctx = (GLGlueContext *)current->value;
+
+               if (cur_gctx->cstate == cur_cstate) {
+                       TRACE("    -%c GlueCTX [%12p] : EGLDPY=[%12p] TID=[%12d] <MC count [%10d]>",
+                                 (cur_cstate->data == cur_gctx) ? '>' : '-',
+                                 cur_gctx,
+                                 cur_gctx->rdpy,
+                                 cur_gctx->thread_id,
+                                 cur_gctx->used_count);
+
+                       TRACE(" <Ref [%2d]>\E[0m\n", cur_gctx->ref_count);
+               }
+
+               current = current->next;
+       }
+}
 
 static void
 _dump_thread_state_list(MY_MODULE_TSTATE *tstate)
@@ -68,27 +91,7 @@ _dump_thread_state_list(MY_MODULE_TSTATE *tstate)
                                                  cur_cstate->ref_count);
 
                                        // Binded Glue Context List
-                                       {
-                                               General_Trace_List *current = NULL;
-                                               current = glue_ctx_trace_list;
-
-                                               while (current != NULL) {
-                                                       GLGlueContext *cur_gctx = (GLGlueContext *)current->value;
-
-                                                       if (cur_gctx->cstate == cur_cstate) {
-                                                               TRACE("    -%c GlueCTX [%12p] : EGLDPY=[%12p] TID=[%12d] <MC count [%10d]>",
-                                                                         (cur_cstate->data == cur_gctx) ? '>' : '-',
-                                                                         cur_gctx,
-                                                                         cur_gctx->rdpy,
-                                                                         cur_gctx->thread_id,
-                                                                         cur_gctx->used_count);
-
-                                                               TRACE(" <Ref [%2d]>\E[0m\n", cur_gctx->ref_count);
-                                                       }
-
-                                                       current = current->next;
-                                               }
-                                       }
+                                       _dump_glue_ctx_list(cur_cstate);
                                }
 
                                current = current->next;
@@ -138,27 +141,7 @@ _dump_not_binded_ctx_state_list()
                                  cur_cstate->ref_count);
 
                        // Binded Glue Context List
-                       {
-                               General_Trace_List *current = NULL;
-                               current = glue_ctx_trace_list;
-
-                               while (current != NULL) {
-                                       GLGlueContext *cur_gctx = (GLGlueContext *)current->value;
-
-                                       if (cur_gctx->cstate == cur_cstate) {
-                                               TRACE("    -%c GlueCTX [%12p] : EGLDPY=[%12p] TID=[%12d] <MC count [%10d]>",
-                                                         (cur_cstate->data == cur_gctx) ? '>' : '-',
-                                                         cur_gctx,
-                                                         cur_gctx->rdpy,
-                                                         cur_gctx->thread_id,
-                                                         cur_gctx->used_count);
-
-                                               TRACE(" <Ref [%2d]>\E[0m\n", cur_gctx->ref_count);
-                                       }
-
-                                       current = current->next;
-                               }
-                       }
+                       _dump_glue_ctx_list(cur_cstate);
                }
 
                current = current->next;
index c3b909c..0bf5258 100644 (file)
@@ -511,6 +511,20 @@ finish:
        _COREGL_FASTPATH_FUNC_END();
 }
 
+static GLuint *_init_objid_array(GLGlueContext *current_ctx, GLsizei n, const GLuint *item)
+{
+       GLuint *objid_array = NULL;
+       if (n < 0) {
+               _set_gl_error(GL_INVALID_VALUE);
+               return NULL;
+       }
+       if (n == 0 || item == NULL) return NULL;
+
+       AST(current_ctx->ostate.shared != NULL);
+
+       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
+       return objid_array;
+}
 
 void
 fastpath_glGenTextures(GLsizei n, GLuint *textures)
@@ -522,16 +536,10 @@ fastpath_glGenTextures(GLsizei n, GLuint *textures)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (n < 0) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
-       if (n == 0) goto finish;
-       if (textures == NULL) goto finish;
+       objid_array = _init_objid_array(current_ctx, n, textures);
 
-       AST(current_ctx->ostate.shared != NULL);
-
-       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
+       if (!objid_array)
+               goto finish;
 
        IF_GL_SUCCESS(_orig_fastpath_glGenTextures(n, objid_array)) {
                for (i = 0; i < n; i++) {
@@ -695,17 +703,11 @@ fastpath_glDeleteTextures(GLsizei n, const GLuint *textures)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (n < 0) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
-       if (n == 0) goto finish;
-       if (textures == NULL) goto finish;
+       objid_array = _init_objid_array(current_ctx, n, textures);
 
-       AST(current_ctx->ostate.shared != NULL);
+       if (!objid_array)
+               goto finish;
 
-       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
-       if (objid_array == NULL) goto finish;
        {
                int real_n = 0;
 
@@ -925,16 +927,10 @@ fastpath_glGenBuffers(GLsizei n, GLuint *buffers)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (n < 0) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
-       if (n == 0) goto finish;
-       if (buffers == NULL) goto finish;
-
-       AST(current_ctx->ostate.shared != NULL);
+       objid_array = _init_objid_array(current_ctx, n, buffers);
 
-       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
+       if (!objid_array)
+               goto finish;
 
        IF_GL_SUCCESS(_orig_fastpath_glGenBuffers(n, objid_array)) {
                for (i = 0; i < n; i++) {
@@ -1367,20 +1363,8 @@ fastpath_glDeleteBuffers(GLsizei n, const GLuint *buffers)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (n < 0) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       } else if (n == 0) {
-               goto finish;
-       }
-
-       if (buffers == NULL) {
-               goto finish;
-       }
-
-       AST(current_ctx->ostate.shared != NULL);
+       objid_array = _init_objid_array(current_ctx, n, buffers);
 
-       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
        if (objid_array == NULL) {
                goto finish;
        }
@@ -1439,16 +1423,11 @@ _fp_glGenFramebuffers(GLsizei n, GLuint *framebuffers, FASTPATH_FUNC_TYPE ftype)
        DEFINE_FASTPAH_GL_FUNC();
        INIT_FASTPATH_GL_FUNC();
 
-       if (n < 0) {
-               _set_gl_error(GL_INVALID_VALUE);
+       objid_array = _init_objid_array(current_ctx, n, framebuffers);
+
+       if (objid_array == NULL) {
                goto finish;
        }
-       if (n == 0) goto finish;
-       if (framebuffers == NULL) goto finish;
-
-       AST(current_ctx->ostate.shared != NULL);
-
-       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
 
        _get_gl_error();
        switch (ftype) {
@@ -1630,16 +1609,8 @@ _fp_glDeleteFramebuffers(GLsizei n, const GLuint *framebuffers, FASTPATH_FUNC_TY
        DEFINE_FASTPAH_GL_FUNC();
        INIT_FASTPATH_GL_FUNC();
 
-       if (n < 0) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
-       if (n == 0) goto finish;
-       if (framebuffers == NULL) goto finish;
-
-       AST(current_ctx->ostate.shared != NULL);
+       objid_array = _init_objid_array(current_ctx, n, framebuffers);
 
-       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
        if (objid_array == NULL) goto finish;
        {
                int real_n = 0;
@@ -1725,16 +1696,11 @@ _fp_glGenRenderbuffers(GLsizei n, GLuint *renderbuffers, FASTPATH_FUNC_TYPE ftyp
        DEFINE_FASTPAH_GL_FUNC();
        INIT_FASTPATH_GL_FUNC();
 
-       if (n < 0) {
-               _set_gl_error(GL_INVALID_VALUE);
+       objid_array = _init_objid_array(current_ctx, n, renderbuffers);
+
+       if (objid_array == NULL) {
                goto finish;
        }
-       if (n == 0) goto finish;
-       if (renderbuffers == NULL) goto finish;
-
-       AST(current_ctx->ostate.shared != NULL);
-
-       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
 
        _get_gl_error();
        switch (ftype) {
@@ -2089,16 +2055,8 @@ fastpath_glShaderBinary(GLsizei n, const GLuint *shaders, GLenum binaryformat,
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (n < 0) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
-       if (n == 0) goto finish;
-       if (shaders == NULL) goto finish;
-
-       AST(current_ctx->ostate.shared != NULL);
+       objid_array = _init_objid_array(current_ctx, n, shaders);
 
-       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
        if (objid_array == NULL) goto finish;
 
        for (i = 0; i < n; i++) {
@@ -5011,16 +4969,9 @@ _fp_glGenQueries(GLsizei n, GLuint *ids, FASTPATH_FUNC_TYPE ftype)
        DEFINE_FASTPAH_GL_FUNC();
        INIT_FASTPATH_GL_FUNC();
 
-       if (n < 0) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
-       if (n == 0) goto finish;
-       if (ids == NULL) goto finish;
-
-       AST(current_ctx->ostate.shared != NULL);
+       objid_array = _init_objid_array(current_ctx, n, ids);
 
-       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
+       if (objid_array == NULL) goto finish;
 
        _get_gl_error();
        switch (ftype) {
@@ -5071,16 +5022,8 @@ _fp_glDeleteQueries(GLsizei n, const GLuint *ids, FASTPATH_FUNC_TYPE ftype)
        DEFINE_FASTPAH_GL_FUNC();
        INIT_FASTPATH_GL_FUNC();
 
-       if (n < 0) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
-       if (n == 0) goto finish;
-       if (ids == NULL) goto finish;
-
-       AST(current_ctx->ostate.shared != NULL);
+       objid_array = _init_objid_array(current_ctx, n, ids);
 
-       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
        if (objid_array == NULL) goto finish;
 
        for (i = 0; i < n; i++) {
@@ -5356,16 +5299,9 @@ _fp_glGenVertexArrays(GLsizei n, GLuint *arrays, FASTPATH_FUNC_TYPE ftype)
        DEFINE_FASTPAH_GL_FUNC();
        INIT_FASTPATH_GL_FUNC();
 
-       if (n < 0) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
-       if (n == 0) goto finish;
-       if (arrays == NULL) goto finish;
+       objid_array = _init_objid_array(current_ctx, n, arrays);
 
-       AST(current_ctx->ostate.shared != NULL);
-
-       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
+       if (objid_array == NULL) goto finish;
 
        _get_gl_error();
        switch (ftype) {
@@ -5623,16 +5559,9 @@ fastpath_glGenTransformFeedbacks(GLsizei n, GLuint *ids)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (n < 0) {
-               _set_gl_error(GL_INVALID_VALUE);
+       objid_array = _init_objid_array(current_ctx, n, ids);
+       if (!objid_array)
                goto finish;
-       }
-       if (n == 0) goto finish;
-       if (ids == NULL) goto finish;
-
-       AST(current_ctx->ostate.shared != NULL);
-
-       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
 
        IF_GL_SUCCESS(_orig_fastpath_glGenTransformFeedbacks(n, objid_array)) {
                for (i = 0; i < n; i++) {
@@ -5808,17 +5737,9 @@ fastpath_glDeleteTransformFeedbacks(GLsizei n, const GLuint *ids)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (n < 0) {
-               _set_gl_error(GL_INVALID_VALUE);
+       objid_array = _init_objid_array(current_ctx, n, ids);
+       if (!objid_array)
                goto finish;
-       }
-       if (n == 0) goto finish;
-       if (ids == NULL) goto finish;
-
-       AST(current_ctx->ostate.shared != NULL);
-
-       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
-       if (objid_array == NULL) goto finish;
        {
                int real_n = 0;
 
@@ -6341,16 +6262,9 @@ fastpath_glGenSamplers(GLsizei n, GLuint *samplers)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (n < 0) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
-       if (n == 0) goto finish;
-       if (samplers == NULL) goto finish;
-
-       AST(current_ctx->ostate.shared != NULL);
+       objid_array = _init_objid_array(current_ctx, n, samplers);
 
-       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
+       if (objid_array == NULL) goto finish;
 
        IF_GL_SUCCESS(_orig_fastpath_glGenSamplers(n, objid_array)) {
                for (i = 0; i < n; i++) {
@@ -6428,16 +6342,8 @@ fastpath_glDeleteSamplers(GLsizei n, const GLuint *samplers)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (n < 0) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
-       if (n == 0) goto finish;
-       if (samplers == NULL) goto finish;
-
-       AST(current_ctx->ostate.shared != NULL);
+       objid_array = _init_objid_array(current_ctx, n, samplers);
 
-       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
        if (objid_array == NULL) goto finish;
        {
                int real_n = 0;
@@ -6790,17 +6696,8 @@ fastpath_glDeleteProgramPipelines(GLsizei n, GLuint const *pipelines)
        _COREGL_FASTPATH_FUNC_BEGIN();
        INIT_FASTPATH_GL_FUNC();
 
-       if (n < 0 || pipelines == NULL) {
-               _set_gl_error(GL_INVALID_VALUE);
-               goto finish;
-       }
+       objid_array = _init_objid_array(current_ctx, n, pipelines);
 
-       if (n == 0)
-               goto finish;
-
-       AST(current_ctx->ostate.shared != NULL);
-
-       objid_array = (GLuint *)calloc(1, sizeof(GLuint) * n);
        if (objid_array == NULL) goto finish;
        {
                int real_n = 0;
index 1f54506..00fcda1 100644 (file)
@@ -1228,6 +1228,37 @@ struct png_state {
        void (*dl_png_write_end) (png_structp png_ptr, png_infop info_ptr);
 };
 
+static GLboolean
+_validate_surface_param(Surface_Data *sdata, char name[], int *alldumpcount, int force_output)
+{
+       if (sdata->width <= 0 || sdata->height <= 0 || sdata->channel <= 0) {
+               return EGL_FALSE;
+       }
+
+       if (trace_surface_filter_size_w > 0 && trace_surface_filter_size_h > 0 &&
+                       (trace_surface_filter_size_w != sdata->width || trace_surface_filter_size_h != sdata->height)) {
+               return EGL_FALSE;
+       }
+
+       if ((trace_surface_filter_period_begin > 0 ||
+                       trace_surface_filter_period_end > 0) &&
+                       (trace_surface_filter_period_begin > *alldumpcount ||
+                        trace_surface_filter_period_end < *alldumpcount)) {
+               *alldumpcount = *alldumpcount + 1;
+               sdata->dump_count++;
+               return EGL_FALSE;
+       }
+
+       TRACE("\E[40;31;1m[[TRACE SURFACE]] : '%s' is dumped (%dx%dx%d).\E[0m\n", name,
+                 sdata->width, sdata->height, sdata->channel);
+       if (trace_surface_print_only_flag == 1 && force_output == 0) {
+               *alldumpcount = *alldumpcount + 1;
+               sdata->dump_count++;
+               return EGL_FALSE;
+       }
+       return EGL_TRUE;
+}
+
 static int
 _dump_surface_egl(Surface_Data *sdata, char name[], unsigned char **data, int *alldumpcount, int force_output)
 {
@@ -1260,32 +1291,8 @@ _dump_surface_egl(Surface_Data *sdata, char name[], unsigned char **data, int *a
                sdata->channel = 0;
        }
 
-       if (sdata->width <= 0 || sdata->height <= 0 || sdata->channel <= 0) {
-               return EGL_FALSE;
-       }
-
-       if (trace_surface_filter_size_w > 0 && trace_surface_filter_size_h > 0 &&
-                       (trace_surface_filter_size_w != sdata->width || trace_surface_filter_size_h != sdata->height)) {
-               return EGL_FALSE;
-       }
-
-       if ((trace_surface_filter_period_begin > 0 ||
-                       trace_surface_filter_period_end > 0) &&
-                       (trace_surface_filter_period_begin > *alldumpcount ||
-                        trace_surface_filter_period_end < *alldumpcount)) {
-               *alldumpcount = *alldumpcount + 1;
-               sdata->dump_count++;
-               return EGL_FALSE;
-       }
-
-       TRACE("\E[40;31;1m[[TRACE SURFACE]] : '%s' is dumped (%dx%dx%d).\E[0m\n",
-                 name, sdata->width, sdata->height, sdata->channel);
-
-       if (trace_surface_print_only_flag == 1 && force_output == 0) {
-               *alldumpcount = *alldumpcount + 1;
-               sdata->dump_count++;
+       if (_validate_surface_param(sdata, name, alldumpcount, force_output) == EGL_FALSE)
                return EGL_FALSE;
-       }
 
        *data = (unsigned char *)calloc(1, sdata->width * sdata->height * sdata->channel * sizeof(unsigned char));
        if (*data == NULL) {
@@ -1346,31 +1353,8 @@ _dump_surface_fbo(Surface_Data *sdata, char name[], unsigned char **data, int *a
                        sdata->channel = 3;
                }
 
-               if (sdata->width <= 0 || sdata->height <= 0 || sdata->channel <= 0) {
-                       return EGL_FALSE;
-               }
-
-               if (trace_surface_filter_size_w > 0 && trace_surface_filter_size_h > 0 &&
-                               (trace_surface_filter_size_w != sdata->width || trace_surface_filter_size_h != sdata->height)) {
+               if (_validate_surface_param(sdata, name, alldumpcount, force_output) == EGL_FALSE)
                        return EGL_FALSE;
-               }
-
-               if ((trace_surface_filter_period_begin > 0 ||
-                               trace_surface_filter_period_end > 0) &&
-                               (trace_surface_filter_period_begin > *alldumpcount ||
-                                trace_surface_filter_period_end < *alldumpcount)) {
-                       *alldumpcount = *alldumpcount + 1;
-                       sdata->dump_count++;
-                       return EGL_FALSE;
-               }
-
-               TRACE("\E[40;31;1m[[TRACE SURFACE]] : '%s' is dumped (%dx%dx%d).\E[0m\n", name,
-                         sdata->width, sdata->height, sdata->channel);
-               if (trace_surface_print_only_flag == 1 && force_output == 0) {
-                       *alldumpcount = *alldumpcount + 1;
-                       sdata->dump_count++;
-                       return EGL_FALSE;
-               }
 
                if (sdata->channel == 3) {
                        sdata->channel = 4;
index 9dd4602..f6e8274 100644 (file)
@@ -802,6 +802,22 @@ finish:
        return ret;
 }
 
+static void
+_trace_after_swap()
+{
+       if (unlikely(get_trace_api_frame_flag() == 1)) {
+               if (unlikely(get_trace_api_all_flag() == 1)) {
+                       _COREGL_TRACE_API_OUTPUT(1);
+               } else {
+                       _COREGL_TRACE_API_OUTPUT(0);
+               }
+               _COREGL_TRACE_API_RESET_FRAME();
+       } else {
+               _COREGL_TRACE_API_OUTPUT(0);
+       }
+       _COREGL_TRACE_MEM_OUTPUT(0);
+}
+
 EGLBoolean
 tracepath_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
 {
@@ -816,17 +832,7 @@ tracepath_eglSwapBuffers(EGLDisplay dpy, EGLSurface surface)
 
 finish:
        _COREGL_TRACEPATH_FUNC_END();
-       if (unlikely(get_trace_api_frame_flag() == 1)) {
-               if (unlikely(get_trace_api_all_flag() == 1)) {
-                       _COREGL_TRACE_API_OUTPUT(1);
-               } else {
-                       _COREGL_TRACE_API_OUTPUT(0);
-               }
-               _COREGL_TRACE_API_RESET_FRAME();
-       } else {
-               _COREGL_TRACE_API_OUTPUT(0);
-       }
-       _COREGL_TRACE_MEM_OUTPUT(0);
+       _trace_after_swap();
        return ret;
 }
 
@@ -845,17 +851,7 @@ tracepath_eglSwapBuffersWithDamageEXT(EGLDisplay dpy, EGLSurface surface,
 
 finish:
        _COREGL_TRACEPATH_FUNC_END();
-       if (unlikely(get_trace_api_frame_flag() == 1)) {
-               if (unlikely(get_trace_api_all_flag() == 1)) {
-                       _COREGL_TRACE_API_OUTPUT(1);
-               } else {
-                       _COREGL_TRACE_API_OUTPUT(0);
-               }
-               _COREGL_TRACE_API_RESET_FRAME();
-       } else {
-               _COREGL_TRACE_API_OUTPUT(0);
-       }
-       _COREGL_TRACE_MEM_OUTPUT(0);
+       _trace_after_swap();
        return ret;
 }
 
@@ -874,17 +870,7 @@ tracepath_eglSwapBuffersRegionEXT(EGLDisplay dpy, EGLSurface surface,
 
 finish:
        _COREGL_TRACEPATH_FUNC_END();
-       if (unlikely(get_trace_api_frame_flag() == 1)) {
-               if (unlikely(get_trace_api_all_flag() == 1)) {
-                       _COREGL_TRACE_API_OUTPUT(1);
-               } else {
-                       _COREGL_TRACE_API_OUTPUT(0);
-               }
-               _COREGL_TRACE_API_RESET_FRAME();
-       } else {
-               _COREGL_TRACE_API_OUTPUT(0);
-       }
-       _COREGL_TRACE_MEM_OUTPUT(0);
+       _trace_after_swap();
        return ret;
 }
 
index a4a05ed..29e9f16 100644 (file)
@@ -2293,17 +2293,10 @@ finish:
        _COREGL_TRACEPATH_FUNC_END();
 }
 
-void
-tracepath_glDrawArrays(GLenum mode, GLint first, GLsizei count)
-{
-       _COREGL_TRACEPATH_FUNC_BEGIN();
-       _orig_tracepath_glDrawArrays(mode, first, count);
-
-       goto finish;
-
-finish:
-       _COREGL_TRACEPATH_FUNC_END();
 #ifdef COREGL_TRACEPATH_TRACE_SURFACE_INFO
+static void
+_trace_surface_draw()
+{
        if (get_trace_surface_flag() == 1) {
                GLint fbname = _COREGL_INT_INIT_VALUE;
                _orig_tracepath_glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbname);
@@ -2324,6 +2317,21 @@ finish:
                                                                                _orig_tracepath_eglGetCurrentSurface(EGL_DRAW), 0, 0, 0, 0, 0, 0, NULL);
                }
        }
+}
+#endif // COREGL_TRACEPATH_TRACE_SURFACE_INFO
+
+void
+tracepath_glDrawArrays(GLenum mode, GLint first, GLsizei count)
+{
+       _COREGL_TRACEPATH_FUNC_BEGIN();
+       _orig_tracepath_glDrawArrays(mode, first, count);
+
+       goto finish;
+
+finish:
+       _COREGL_TRACEPATH_FUNC_END();
+#ifdef COREGL_TRACEPATH_TRACE_SURFACE_INFO
+       _trace_surface_draw();
 #endif // COREGL_TRACEPATH_TRACE_SURFACE_INFO
 }
 
@@ -2339,26 +2347,7 @@ tracepath_glDrawElements(GLenum mode, GLsizei count, GLenum type,
 finish:
        _COREGL_TRACEPATH_FUNC_END();
 #ifdef COREGL_TRACEPATH_TRACE_SURFACE_INFO
-       if (get_trace_surface_flag() == 1) {
-               GLint fbname = _COREGL_INT_INIT_VALUE;
-               _orig_tracepath_glGetIntegerv(GL_FRAMEBUFFER_BINDING, &fbname);
-               AST(fbname != _COREGL_INT_INIT_VALUE);
-               if (fbname == 0) {
-                       char name[256];
-                       EGLint btype;
-                       _orig_tracepath_eglQuerySurface(_orig_tracepath_eglGetCurrentDisplay(),
-                                                                                       _orig_tracepath_eglGetCurrentSurface(EGL_DRAW), EGL_RENDER_BUFFER, &btype);
-                       if (btype == EGL_SINGLE_BUFFER)
-                               snprintf(name, sizeof(name), "EGLPIXMAP_%p",
-                                                _orig_tracepath_eglGetCurrentSurface(EGL_DRAW));
-                       else
-                               snprintf(name, sizeof(name), "EGLWINDOW_%p",
-                                                _orig_tracepath_eglGetCurrentSurface(EGL_DRAW));
-                       tracepath_surface_trace_add(name, _orig_tracepath_eglGetCurrentDisplay(),
-                                                                               _orig_tracepath_eglGetCurrentContext(),
-                                                                               _orig_tracepath_eglGetCurrentSurface(EGL_DRAW), 0, 0, 0, 0, 0, 0, NULL);
-               }
-       }
+               _trace_surface_draw();
 #endif // COREGL_TRACEPATH_TRACE_SURFACE_INFO
 }
 
@@ -3111,6 +3100,39 @@ finish:
        _COREGL_TRACEPATH_FUNC_END();
 }
 
+static void
+_trace_renderbuffer(GLenum internalformat, GLsizei width, GLsizei height)
+{
+#ifdef COREGL_TRACEPATH_TRACE_MEMUSE_INFO
+               if (get_trace_mem_flag() == 1) {
+                       MY_MODULE_TSTATE* tstate = _get_my_state();
+                       if (tstate && tstate->ctx != NULL) {
+                               struct _Glbuf_Data data = _get_glbuf_data(GL_RENDERBUFFER_BINDING, internalformat);
+                               _add_glbuf_object(tstate->ctx->sostate->glbuf_rb, data.obj_idx, "Renderbuffer", width,
+                                                                 height, data.bpp, data.format);
+                       }
+               }
+#endif // COREGL_TRACEPATH_TRACE_MEMUSE_INFO
+#ifdef COREGL_TRACEPATH_TRACE_SURFACE_INFO
+               if (get_trace_surface_flag() == 1) {
+                       MY_MODULE_TSTATE* tstate = _get_my_state();
+                       if (tstate && tstate->ctx != NULL) {
+                               int objidx = _COREGL_INT_INIT_VALUE;
+                               _orig_tracepath_glGetIntegerv(GL_RENDERBUFFER_BINDING, &objidx);
+                               AST(objidx != _COREGL_INT_INIT_VALUE);
+
+                               {
+                                       int channel = _get_channel_by_format(internalformat);
+                                       char name[256];
+                                       snprintf(name, sizeof(name), "FBORB_%d", objidx);
+                                       tracepath_surface_trace_add(name, tstate->ctx->dpy, tstate->ctx->handle,
+                                                                                               tstate->surf_draw, -1, 0, objidx, width, height, channel, NULL);
+                               }
+                       }
+               }
+#endif // COREGL_TRACEPATH_TRACE_SURFACE_INFO
+}
+
 void
 tracepath_glRenderbufferStorage(GLenum target, GLenum internalformat,
                                                                GLsizei width, GLsizei height)
@@ -3123,34 +3145,7 @@ tracepath_glRenderbufferStorage(GLenum target, GLenum internalformat,
 
 finish:
        _COREGL_TRACEPATH_FUNC_END();
-#ifdef COREGL_TRACEPATH_TRACE_MEMUSE_INFO
-       if (get_trace_mem_flag() == 1) {
-               MY_MODULE_TSTATE* tstate = _get_my_state();
-               if (tstate && tstate->ctx != NULL) {
-                       struct _Glbuf_Data data = _get_glbuf_data(GL_RENDERBUFFER_BINDING, internalformat);
-                       _add_glbuf_object(tstate->ctx->sostate->glbuf_rb, data.obj_idx, "Renderbuffer", width,
-                                                         height, data.bpp, data.format);
-               }
-       }
-#endif // COREGL_TRACEPATH_TRACE_MEMUSE_INFO
-#ifdef COREGL_TRACEPATH_TRACE_SURFACE_INFO
-       if (get_trace_surface_flag() == 1) {
-               MY_MODULE_TSTATE* tstate = _get_my_state();
-               if (tstate && tstate->ctx != NULL) {
-                       int objidx = _COREGL_INT_INIT_VALUE;
-                       _orig_tracepath_glGetIntegerv(GL_RENDERBUFFER_BINDING, &objidx);
-                       AST(objidx != _COREGL_INT_INIT_VALUE);
-
-                       {
-                               int channel = _get_channel_by_format(internalformat);
-                               char name[256];
-                               snprintf(name, sizeof(name), "FBORB_%d", objidx);
-                               tracepath_surface_trace_add(name, tstate->ctx->dpy, tstate->ctx->handle,
-                                                                                       tstate->surf_draw, -1, 0, objidx, width, height, channel, NULL);
-                       }
-               }
-       }
-#endif // COREGL_TRACEPATH_TRACE_SURFACE_INFO
+       _trace_renderbuffer(internalformat, width, height);
 }
 
 void
@@ -4176,34 +4171,8 @@ _tp_glRenderbufferStorageMultisample(GLenum target, GLsizei samples,
        goto finish;
 
 finish:
-#ifdef COREGL_TRACEPATH_TRACE_MEMUSE_INFO
-       if (get_trace_mem_flag() == 1) {
-               MY_MODULE_TSTATE* tstate = _get_my_state();
-               if (tstate && tstate->ctx != NULL) {
-                       struct _Glbuf_Data data = _get_glbuf_data(GL_RENDERBUFFER_BINDING, internalformat);
-                       _add_glbuf_object(tstate->ctx->sostate->glbuf_rb, data.obj_idx, "Renderbuffer", width,
-                                                         height, data.bpp, data.format);
-               }
-       }
-#endif // COREGL_TRACEPATH_TRACE_MEMUSE_INFO
-#ifdef COREGL_TRACEPATH_TRACE_SURFACE_INFO
-       if (get_trace_surface_flag() == 1) {
-               MY_MODULE_TSTATE* tstate = _get_my_state();
-               if (tstate && tstate->ctx != NULL) {
-                       int objidx = _COREGL_INT_INIT_VALUE;
-                       _orig_tracepath_glGetIntegerv(GL_RENDERBUFFER_BINDING, &objidx);
-                       AST(objidx != _COREGL_INT_INIT_VALUE);
+       _trace_renderbuffer(internalformat, width, height);
 
-                       {
-                               int channel = _get_channel_by_format(internalformat);
-                               char name[256];
-                               snprintf(name, sizeof(name), "FBORB_0x%X", objidx);
-                               tracepath_surface_trace_add(name, tstate->ctx->dpy, tstate->ctx->handle,
-                                                                                       tstate->surf_draw, -1, 0, objidx, width, height, channel, NULL);
-                       }
-               }
-       }
-#endif // COREGL_TRACEPATH_TRACE_SURFACE_INFO
 }
 
 void