<commit_before>/*
 *			GPAC - Multimedia Framework C SDK
 *
 *			Authors: <NAME>
 *			Copyright (c) Telecom ParisTech 2019
 *			All rights reserved
 *
 *  This file is part of GPAC / JavaScript WebGL bindings
 *
 *  GPAC is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  GPAC is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */


/*
	ANY CHANGE TO THE API MUST BE REFLECTED IN THE DOCUMENTATION IN gpac/share/doc/idl/webgl.idl
	(no way to define inline JS doc with doxygen)
*/

#include <gpac/setup.h>
#ifdef GPAC_HAS_QJS

#if !defined(GPAC_DISABLE_3D) && !defined(GPAC_USE_TINYGL) && !defined(GPAC_USE_GLES1X)

#include "webgl.h"

JSClassID WebGLRenderingContextBase_class_id;

static void webgl_finalize(JSRuntime *rt, JSValue obj)
{
	u32 i, count;
	GF_WebGLContext *glctx = JS_GetOpaque(obj, WebGLRenderingContextBase_class_id);
	if (!glctx) return;
	JS_FreeValueRT(rt, glctx->canvas);
	JS_FreeValueRT(rt, glctx->tex_frame_flush);
	JS_FreeValueRT(rt, glctx->depth_frame_flush);

	count = gf_list_count(glctx->all_objects);
	for (i=0; i<count; i++) {
		GF_WebGLObject *glo = gf_list_get(glctx->all_objects, i);
		glo->par_ctx = NULL;
		if (!JS_IsUndefined(glo->obj))
			JS_FreeValueRT(rt, glo->obj);
	}
	gf_list_del(glctx->all_objects);
	count = gf_list_count(glctx->named_textures);
	for (i=0; i<count; i++) {
		GF_WebGLNamedTexture *named_tx = gf_list_get(glctx->named_textures, i);
		named_tx->par_ctx = NULL;
	}
	gf_list_del(glctx->named_textures);

	glDeleteTextures(1, &glctx->tex_id);
	glDeleteRenderbuffers(1, &glctx->depth_id);
	glDeleteFramebuffers(1, &glctx->fbo_id);
	if (glctx->pix_data) gf_free(glctx->pix_data);
	gf_free(glctx);
}

static void webgl_gc_mark(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func)
{
	u32 i, count;
	GF_WebGLContext *glctx = JS_GetOpaque(val, WebGLRenderingContextBase_class_id);
	if (!glctx) return;
	if (!JS_IsUndefined(glctx->tex_frame_flush))
		JS_MarkValue(rt, glctx->depth_frame_flush, mark_func);
	if (!JS_IsUndefined(glctx->depth_frame_flush))
		JS_MarkValue(rt, glctx->tex_frame_flush, mark_func);
	if (!JS_IsUndefined(glctx->canvas))
		JS_MarkValue(rt, glctx->canvas, mark_func);
	count = gf_list_count(glctx->all_objects);
	for (i=0; i<count; i++) {
		GF_WebGLObject *glo = gf_list_get(glctx->all_objects, i);
		if (!JS_IsUndefined(glo->obj))
			JS_MarkValue(rt, glo->obj, mark_func);
	}
}
JSClassDef WebGLRenderingContextBase_class =<commit_msg>fixed mem leak<commit_after>/*
 *			GPAC - Multimedia Framework C SDK
 *
 *			Authors: <NAME>
 *			Copyright (c) Telecom ParisTech 2019
 *			All rights reserved
 *
 *  This file is part of GPAC / JavaScript WebGL bindings
 *
 *  GPAC is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *
 *  GPAC is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; see the file COPYING.  If not, write to
 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */


/*
	ANY CHANGE TO THE API MUST BE REFLECTED IN THE DOCUMENTATION IN gpac/share/doc/idl/webgl.idl
	(no way to define inline JS doc with doxygen)
*/

#include <gpac/setup.h>
#ifdef GPAC_HAS_QJS

#if !defined(GPAC_DISABLE_3D) && !defined(GPAC_USE_TINYGL) && !defined(GPAC_USE_GLES1X)

#include "webgl.h"

JSClassID WebGLRenderingContextBase_class_id;

static void webgl_finalize(JSRuntime *rt, JSValue obj)
{
	u32 i, count;
	GF_WebGLContext *glctx = JS_GetOpaque(obj, WebGLRenderingContextBase_class_id);
	if (!glctx) return;
	JS_FreeValueRT(rt, glctx->canvas);
	JS_FreeValueRT(rt, glctx->tex_frame_flush);
	JS_FreeValueRT(rt, glctx->depth_frame_flush);

	count = gf_list_count(glctx->all_objects);
	for (i=0; i<count; i++) {
		GF_WebGLObject *glo = gf_list_get(glctx->all_objects, i);
		glo->par_ctx = NULL;
		if (!JS_IsUndefined(glo->obj))
			JS_FreeValueRT(rt, glo->obj);
	}
	gf_list_del(glctx->all_objects);
	count = gf_list_count(glctx->named_textures);
	for (i=0; i<count; i++) {
		GF_WebGLNamedTexture *named_tx = gf_list_get(glctx->named_textures, i);
		named_tx->par_ctx = NULL;
	}
	gf_list_del(glctx->named_textures);

	glDeleteTextures(1, &glctx->tex_id);
	glDeleteRenderbuffers(1, &glctx->depth_id);
	glDeleteFramebuffers(1, &glctx->fbo_id);
	if (glctx->pix_data) gf_free(glctx->pix_data);
	if (glctx->pix_line) gf_free(glctx->pix_line);
	gf_free(glctx);
}

static void webgl_gc_mark(JSRuntime *rt, JSValueConst val, JS_MarkFunc *mark_func)
{
	u32 i, count;
	GF_WebGLContext *glctx = JS_GetOpaque(val, WebGLRenderingContextBase_class_id);
	if (!glctx) return;
	if (!JS_IsUndefined(glctx->tex_frame_flush))
		JS_MarkValue(rt, glctx->depth_frame_flush, mark_func);
	if (!JS_IsUndefined(glctx->depth_frame_flush))
		JS_MarkValue(rt, glctx->tex_frame_flush, mark_func);
	if (!JS_IsUndefined(glctx->canvas))
		JS_MarkValue(rt, glctx->canvas, mark_func);
	count = gf_list_count(glctx->all_objects);
	for (i=0; i<count; i++) {
		GF_WebGLObject *glo = gf_list_get(glctx->all_objects, i);
		if (!JS_IsUndefined(glo->obj))
			JS_MarkValue(rt, glo->obj, mark_func);
	}
}
JSClassDef WebGLRenderingContextBase_class =
{'fraction_non_alphanumeric': 0.11341563786008231, 'fraction_numerical': 0.00823045267489712, 'mean_word_length': 5.131180625630676, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6495149', 'n_tokens_mistral': 2358, 'n_tokens_neox': 2279, 'n_words': 571}