Beispiel #1
0
static void obs_free_graphics()
{
	struct obs_video *video = &obs->video;
	size_t i;

	if (video->graphics) {
		int cur_texture = video->cur_texture;
		gs_entercontext(video->graphics);

		if (video->copy_mapped)
			stagesurface_unmap(video->copy_surfaces[cur_texture]);

		for (i = 0; i < NUM_TEXTURES; i++) {
			stagesurface_destroy(video->copy_surfaces[i]);
			texture_destroy(video->render_textures[i]);
			texture_destroy(video->output_textures[i]);

			video->copy_surfaces[i]   = NULL;
			video->render_textures[i] = NULL;
			video->output_textures[i] = NULL;
		}

		effect_destroy(video->default_effect);
		video->default_effect = NULL;

		gs_leavecontext();

		gs_destroy(video->graphics);
		video->graphics = NULL;
		video->cur_texture = 0;
	}
}
bool
texture_resize_capacity(Texture_data *data, const size_t size_hint)
{
  assert(data);
  assert(size_hint > data->size); // Will slice data

  // Create new data.
  Texture_data new_data;
  const bool created_new = texture_create(&new_data, size_hint);

  // Failed to resize.
  if(!created_new)
  {
    texture_destroy(&new_data);
    return false;
  }

  // Copy over data
  {
    memcpy(new_data.keys, data->keys, sizeof(uint32_t) * data->size);
    memcpy(new_data.field_name, data->field_name, sizeof(char) * data->size * 32);
    memcpy(new_data.field_texture, data->field_texture, sizeof(Ogl::Texture) * data->size * 1);
    memcpy(new_data.field_render_target, data->field_render_target, sizeof(Ogl::Frame_buffer) * data->size * 1);
  }

  // Swap ptrs
  {
    uint32_t *old_keys = data->keys;
    data->keys = new_data.keys;
    new_data.keys = old_keys;

    char *old_name = data->field_name;
    data->field_name = new_data.field_name;
    new_data.field_name = old_name;

    Ogl::Texture *old_texture = data->field_texture;
    data->field_texture = new_data.field_texture;
    new_data.field_texture = old_texture;

    Ogl::Frame_buffer *old_render_target = data->field_render_target;
    data->field_render_target = new_data.field_render_target;
    new_data.field_render_target = old_render_target;
  }

  // Set the Capacity
  {
    size_t *capacity = const_cast<size_t*>(&data->capacity);
    *capacity = new_data.capacity;
  }

  // Destroy new data
  texture_destroy(&new_data);

  return true;
}
Beispiel #3
0
static void DestroyBackground2D(SFNode *node)
{
	M_Background2D *top;
	Background2DStack *ptr;
	BackgroundStatus *status;
	
	ptr = (Background2DStack *) Node_GetPrivate(node);

	DeleteDrawableNode(ptr->node);


	while (ChainGetCount(ptr->surfaces_links)) {
		status = ChainGetEntry(ptr->surfaces_links, 0);
		ChainDeleteEntry(ptr->surfaces_links, 0);
		ChainDeleteItem(status->bind_stack, node);

		/*force bind - bindable nodes are the only cases where we generate eventIn in the scene graph*/
		if (ChainGetCount(status->bind_stack)) {
			top = ChainGetEntry(status->bind_stack, 0);
			if (!top->set_bind) {
				top->set_bind = 1;
				if (top->on_set_bind) top->on_set_bind((SFNode *) top);
			}
		}
		free(status);
	}

	texture_destroy(&ptr->txh);
	DeleteChain(ptr->surfaces_links);
	free(ptr);
}
Beispiel #4
0
static void obs_source_destroy(obs_source_t source)
{
	size_t i;

	if (source->filter_parent)
		obs_source_filter_remove(source->filter_parent, source);

	for (i = 0; i < source->filters.num; i++)
		obs_source_release(source->filters.array[i]);

	for (i = 0; i < source->audio_wait_buffer.num; i++)
		audiobuf_free(source->audio_wait_buffer.array+i);
	for (i = 0; i < source->video_frames.num; i++)
		source_frame_destroy(source->video_frames.array[i]);

	gs_entercontext(obs->video.graphics);
	texture_destroy(source->output_texture);
	gs_leavecontext();

	if (source->data)
		source->callbacks.destroy(source->data);

	bfree(source->audio_data.data);
	audio_line_destroy(source->audio_line);
	audio_resampler_destroy(source->resampler);

	da_free(source->video_frames);
	da_free(source->audio_wait_buffer);
	da_free(source->filters);
	pthread_mutex_destroy(&source->filter_mutex);
	pthread_mutex_destroy(&source->audio_mutex);
	pthread_mutex_destroy(&source->video_mutex);
	dstr_free(&source->settings);
	bfree(source);
}
bool
texture_create(Texture_data *data, const size_t size_hint)
{
  assert(data);
  assert(size_hint);

  // Size up the capacity
  {
    size_t *capacity = const_cast<size_t*>(&data->capacity);
    *capacity = size_hint;
  }

  // Allocate memory
  bool all_alloc = true;
  {
    // Alloc keys
    if(all_alloc)
    {
      data->keys = new uint32_t[size_hint];
      assert(data->keys);
      if(!data->keys) { all_alloc = false; }
      else { memset(data->keys, 0, sizeof(uint32_t) * size_hint); }
    }

    // Alloc space for name
    if(all_alloc)
    {
      data->field_name = new char[size_hint * 32];
      assert(data->field_name);
      if(!data->field_name) { all_alloc = false; }
      else { memset(data->field_name, 0, sizeof(char) * size_hint * 32); }
    }

    // Alloc space for texture
    if(all_alloc)
    {
      data->field_texture = new Ogl::Texture[size_hint * 1];
      assert(data->field_texture);
      if(!data->field_texture) { all_alloc = false; }
      else { memset(data->field_texture, 0, sizeof(Ogl::Texture) * size_hint * 1); }
    }

    // Alloc space for render_target
    if(all_alloc)
    {
      data->field_render_target = new Ogl::Frame_buffer[size_hint * 1];
      assert(data->field_render_target);
      if(!data->field_render_target) { all_alloc = false; }
      else { memset(data->field_render_target, 0, sizeof(Ogl::Frame_buffer) * size_hint * 1); }
    }
  }

  // Failed so clean up.
  if(!all_alloc)
  {
    texture_destroy(data);
  }

  return all_alloc;
}
Beispiel #6
0
static void image_source_update(void *data, obs_data_t settings)
{
	struct image_source *context = data;
	const char *file = obs_data_getstring(settings, "file");

	gs_entercontext(obs_graphics());

	if (context->tex) {
		texture_destroy(context->tex);
		context->tex = NULL;
	}

	if (file) {
		context->tex = gs_create_texture_from_file(file);
		if (context->tex) {
			context->cx = texture_getwidth(context->tex);
			context->cy = texture_getheight(context->tex);
		} else {
			warn("failed to load texture '%s'", file);
			context->cx = 0;
			context->cy = 0;
		}
	}

	gs_leavecontext();
}
Beispiel #7
0
void sprite_destroy(Sprite* sprite) {
    texture_destroy(sprite->texture);
    int i;
    for(i = 0; i < NB_VERTEX_ATTRIB; ++i) {
        buffer_destroy(sprite->attributes[i].buffer);
    }
    free(sprite);
}
Beispiel #8
0
AS3_Val destroyTexture( void* self, AS3_Val args )
{
	Texture *texture = AS3_PtrValue(args);

	texture_destroy(&texture);

	return 0;
}
Beispiel #9
0
/* ...deallocate texture data */
static void __destroy_sv_texture(gpointer data, GstMiniObject *obj)
{
    GstBuffer      *buffer = (GstBuffer *)obj;
    vsink_meta_t   *meta = gst_buffer_get_vsink_meta(buffer);

    TRACE(DEBUG, _b("destroy texture referenced by meta: %p:%p"), meta, meta->priv);
    
    /* ...destroy texture */
    texture_destroy(meta->priv);
}
Beispiel #10
0
static void image_source_destroy(void *data)
{
	struct image_source *context = data;

	gs_entercontext(obs_graphics());
	texture_destroy(context->tex);
	gs_leavecontext();

	bfree(context);
}
XCompcapMain::~XCompcapMain()
{
	ObsGsContextHolder obsctx;

	if (p->tex) {
		texture_destroy(p->tex);
		p->tex = 0;
	}

	xcc_cleanup(p);

	delete p;
}
Beispiel #12
0
static void random_destroy(void *data)
{
	struct random_tex *rt = data;

	if (rt) {
		gs_entercontext(obs_graphics());

		texture_destroy(rt->texture);
		bfree(rt);

		gs_leavecontext();
	}
}
Beispiel #13
0
/* ...deallocate texture data */
static void __destroy_od_texture(gpointer data, GstMiniObject *obj)
{
    GstBuffer      *buffer = (GstBuffer *)obj;
    vsink_meta_t   *vmeta = gst_buffer_get_vsink_meta(buffer);
    objdet_meta_t  *ometa = gst_buffer_get_objdet_meta(buffer);

    TRACE(DEBUG, _b("destroy texture referenced by meta: %p:%p"), vmeta, vmeta->priv);

    /* ...destroy memory mapping */
    texture_unmap(ometa->buf);

    /* ...destroy texture */
    texture_destroy(vmeta->priv);
}
Beispiel #14
0
static void obs_free_video(void)
{
	struct obs_core_video *video = &obs->video;

	if (video->video) {
		obs_display_free(&video->main_display);
		video_output_close(video->video);
		video->video = NULL;

		if (!video->graphics)
			return;

		gs_entercontext(video->graphics);

		if (video->mapped_surface) {
			stagesurface_unmap(video->mapped_surface);
			video->mapped_surface = NULL;
		}

		for (size_t i = 0; i < NUM_TEXTURES; i++) {
			stagesurface_destroy(video->copy_surfaces[i]);
			texture_destroy(video->render_textures[i]);
			texture_destroy(video->convert_textures[i]);
			texture_destroy(video->output_textures[i]);
			source_frame_free(&video->convert_frames[i]);

			video->copy_surfaces[i]    = NULL;
			video->render_textures[i]  = NULL;
			video->convert_textures[i] = NULL;
			video->output_textures[i]  = NULL;
		}

		gs_leavecontext();

		video->cur_texture = 0;
	}
}
Beispiel #15
0
void text_renderer_destroy(text_renderer_p renderer) {
	texture_destroy(renderer->texture);
	
	for(size_t i = 0; i < renderer->lines->length; i++)
		array_destroy( array_elem(renderer->lines, text_renderer_line_t, i).cells );
	array_destroy(renderer->lines);
	
	for(hash_elem_t e = hash_start(renderer->fonts); e != NULL; e = hash_next(renderer->fonts, e))
		text_renderer_font_destroy(renderer, hash_key(e));
	hash_destroy(renderer->fonts);
	
	FT_Error error = FT_Done_FreeType(renderer->freetype);
	if (error)
		printf("FT_Done_FreeType error\n");
}
Beispiel #16
0
static bool set_texture_size(obs_source_t source, struct source_frame *frame)
{
    if (source->output_texture) {
        uint32_t width  = texture_getwidth(source->output_texture);
        uint32_t height = texture_getheight(source->output_texture);

        if (width == frame->width && height == frame->height)
            return true;
    }

    texture_destroy(source->output_texture);
    source->output_texture = gs_create_texture(frame->width, frame->height,
                             GS_RGBA, 1, NULL, GS_DYNAMIC);

    return source->output_texture != NULL;
}
Beispiel #17
0
void dc_capture_free(struct dc_capture *capture)
{
	if (capture->hdc) {
		SelectObject(capture->hdc, capture->old_bmp);
		DeleteDC(capture->hdc);
		DeleteObject(capture->bmp);
	}

	gs_entercontext(obs_graphics());

	for (size_t i = 0; i < capture->num_textures; i++)
		texture_destroy(capture->textures[i]);

	gs_leavecontext();

	memset(capture, 0, sizeof(struct dc_capture));
}
Beispiel #18
0
static inline bool set_async_texture_size(struct obs_source *source,
		struct source_frame *frame)
{
	enum convert_type prev, cur;
	prev = get_convert_type(source->async_format);
	cur  = get_convert_type(frame->format);
	if (source->async_texture) {
		if (source->async_width  == frame->width &&
		    source->async_height == frame->height &&
		    prev == cur)
			return true;
	}

	texture_destroy(source->async_texture);
	texrender_destroy(source->async_convert_texrender);
	source->async_convert_texrender = NULL;

	if (cur != CONVERT_NONE && init_gpu_conversion(source, frame)) {
		source->async_gpu_conversion = true;

		source->async_convert_texrender =
			texrender_create(GS_RGBA, GS_ZS_NONE);

		source->async_texture = gs_create_texture(
				source->async_convert_width,
				source->async_convert_height,
				GS_RGBA, 1, NULL, GS_DYNAMIC);

	} else {
		source->async_gpu_conversion = false;

		source->async_texture = gs_create_texture(
				frame->width, frame->height,
				GS_RGBA, 1, NULL, GS_DYNAMIC);
	}

	if (!source->async_texture)
		return false;

	source->async_width  = frame->width;
	source->async_height = frame->height;
	return true;
}
Beispiel #19
0
void obs_source_destroy(struct obs_source *source)
{
	size_t i;

	if (!source)
		return;

	obs_context_data_remove(&source->context);

	obs_source_dosignal(source, "source_destroy", "destroy");

	if (source->context.data)
		source->info.destroy(source->context.data);

	if (source->filter_parent)
		obs_source_filter_remove(source->filter_parent, source);

	for (i = 0; i < source->filters.num; i++)
		obs_source_release(source->filters.array[i]);

	for (i = 0; i < source->video_frames.num; i++)
		source_frame_destroy(source->video_frames.array[i]);

	gs_entercontext(obs->video.graphics);
	texrender_destroy(source->async_convert_texrender);
	texture_destroy(source->async_texture);
	gs_leavecontext();

	for (i = 0; i < MAX_AV_PLANES; i++)
		bfree(source->audio_data.data[i]);

	audio_line_destroy(source->audio_line);
	audio_resampler_destroy(source->resampler);

	texrender_destroy(source->filter_texrender);
	da_free(source->video_frames);
	da_free(source->filters);
	pthread_mutex_destroy(&source->filter_mutex);
	pthread_mutex_destroy(&source->audio_mutex);
	pthread_mutex_destroy(&source->video_mutex);
	obs_context_data_free(&source->context);
	bfree(source);
}
Beispiel #20
0
void extract_bin_texture(FStream* fs, const char* out_fn)
{
  Texture *myst_img;

  myst_img = myst_read_bin_texture(fs);
  
  if (myst_img != 0){
    FStream* out;

    stream_create(&out);
    stream_make(out, out_fn);

    if (out->handle != 0) {
      myst_write_bin_texture(out, myst_img);
    }
    
    stream_destroy(&out);
  }

  texture_destroy(&myst_img);
}
Beispiel #21
0
/*
 * Create the cursor texture, either by updating if the new cursor has the same
 * size or by creating a new texture if the size is different
 */
static void xcursor_create(xcursor_t *data, XFixesCursorImage *xc) {
	uint32_t *pixels = xcursor_pixels(xc);

	if (data->tex
	&& data->last_height == xc->width
	&& data->last_width == xc->height) {
		texture_setimage(data->tex, (void **) pixels,
			xc->width * sizeof(uint32_t), False);
	} else {
		if (data->tex)
			texture_destroy(data->tex);

		data->tex = gs_create_texture(xc->width, xc->height,
			GS_BGRA, 1, (const void **) &pixels, GS_DYNAMIC);
	}

	bfree(pixels);

	data->last_serial = xc->cursor_serial;
	data->last_width = xc->width;
	data->last_height = xc->height;
}
Beispiel #22
0
static void obs_source_destroy(obs_source_t source)
{
	size_t i;

	obs_source_dosignal(source, "source-destroy");

	if (source->filter_parent)
		obs_source_filter_remove(source->filter_parent, source);

	for (i = 0; i < source->filters.num; i++)
		obs_source_release(source->filters.array[i]);

	for (i = 0; i < source->video_frames.num; i++)
		source_frame_destroy(source->video_frames.array[i]);

	gs_entercontext(obs->video.graphics);
	texture_destroy(source->output_texture);
	gs_leavecontext();

	if (source->data)
		source->callbacks.destroy(source->data);

	bfree(source->audio_data.data);
	audio_line_destroy(source->audio_line);
	audio_resampler_destroy(source->resampler);

	proc_handler_destroy(source->procs);
	signal_handler_destroy(source->signals);

	da_free(source->video_frames);
	da_free(source->filters);
	pthread_mutex_destroy(&source->filter_mutex);
	pthread_mutex_destroy(&source->audio_mutex);
	pthread_mutex_destroy(&source->video_mutex);
	obs_data_release(source->settings);
	bfree(source->name);
	bfree(source);
}
static void xcc_cleanup(XCompcapMain_private *p)
{
	if (p->gltex) {
		texture_destroy(p->gltex);
		p->gltex = 0;
	}

	if (p->glxpixmap) {
		glXDestroyPixmap(xdisp, p->glxpixmap);
		p->glxpixmap = 0;
	}

	if (p->pixmap) {
		XFreePixmap(xdisp, p->pixmap);
		p->pixmap = 0;
	}

	if (p->win) {
		XCompositeUnredirectWindow(xdisp, p->win,
				CompositeRedirectAutomatic);
		XSelectInput(xdisp, p->win, 0);
		p->win = 0;
	}
}
void XCompcapMain::updateSettings(obs_data_t settings)
{
	PLock lock(&p->lock);
	XErrorLock xlock;
	ObsGsContextHolder obsctx;

	blog(LOG_DEBUG, "Settings updating");

	Window prevWin = p->win;

	xcc_cleanup(p);

	if (settings) {
		const char *windowName = obs_data_getstring(settings,
				"capture_window");

		p->win = getWindowFromString(windowName);

		p->cut_top = obs_data_getint(settings, "cut_top");
		p->cut_left = obs_data_getint(settings, "cut_left");
		p->cut_right = obs_data_getint(settings, "cut_right");
		p->cut_bot = obs_data_getint(settings, "cut_bot");
		p->lockX = obs_data_getbool(settings, "lock_x");
		p->swapRedBlue = obs_data_getbool(settings, "swap_redblue");
	} else {
		p->win = prevWin;
	}

	xlock.resetError();

	XCompositeRedirectWindow(xdisp, p->win, CompositeRedirectAutomatic);

	if (xlock.gotError()) {
		blog(LOG_ERROR, "XCompositeRedirectWindow failed: %s",
				xlock.getErrorText().c_str());
		return;
	}

	XSelectInput(xdisp, p->win, StructureNotifyMask);
	XSync(xdisp, 0);

	XWindowAttributes attr;
	if (!XGetWindowAttributes(xdisp, p->win, &attr)) {
		p->win = 0;
		p->width = 0;
		p->height = 0;
		return;
	}

	gs_color_format cf = GS_RGBA;

	p->width = attr.width;
	p->height = attr.height;

	if (p->cut_top + p->cut_bot < (int)p->height) {
		p->cur_cut_top = p->cut_top;
		p->cur_cut_bot = p->cut_bot;
	} else {
		p->cur_cut_top = 0;
		p->cur_cut_bot = 0;
	}

	if (p->cut_left + p->cut_right < (int)p->width) {
		p->cur_cut_left = p->cut_left;
		p->cur_cut_right = p->cut_right;
	} else {
		p->cur_cut_left = 0;
		p->cur_cut_right = 0;
	}

	if (p->tex)
		texture_destroy(p->tex);

	uint8_t *texData = new uint8_t[width() * height() * 4];

	for (unsigned int i = 0; i < width() * height() * 4; i += 4) {
		texData[i + 0] = p->swapRedBlue ? 0 : 0xFF;
		texData[i + 1] = 0;
		texData[i + 2] = p->swapRedBlue ? 0xFF : 0;
		texData[i + 3] = 0xFF;
	}

	const uint8_t* texDataArr[] = { texData, 0 };

	p->tex = gs_create_texture(width(), height(), cf, 1,
			texDataArr, 0);

	delete[] texData;

	if (p->swapRedBlue) {
		GLuint tex = *(GLuint*)texture_getobj(p->tex);
		glBindTexture(GL_TEXTURE_2D, tex);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_B, GL_RED);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R, GL_BLUE);
		glBindTexture(GL_TEXTURE_2D, 0);
	}

	const int attrs[] =
	{
		GLX_BIND_TO_TEXTURE_RGBA_EXT, GL_TRUE,
		GLX_DRAWABLE_TYPE, GLX_PIXMAP_BIT,
		GLX_BIND_TO_TEXTURE_TARGETS_EXT, GLX_TEXTURE_2D_BIT_EXT,
		GLX_DOUBLEBUFFER, GL_FALSE,
		None
	};

	int nelem = 0;
	GLXFBConfig* configs = glXChooseFBConfig(xdisp,
			XCompcap::getRootWindowScreen(attr.root),
			attrs, &nelem);

	if (nelem <= 0) {
		blog(LOG_ERROR, "no matching fb config found");
		p->win = 0;
		p->height = 0;
		p->width = 0;
		return;
	}

	glXGetFBConfigAttrib(xdisp, configs[0], GLX_Y_INVERTED_EXT, &nelem);
	p->inverted = nelem != 0;

	xlock.resetError();

	p->pixmap = XCompositeNameWindowPixmap(xdisp, p->win);

	if (xlock.gotError()) {
		blog(LOG_ERROR, "XCompositeNameWindowPixmap failed: %s",
				xlock.getErrorText().c_str());
		p->pixmap = 0;
		XFree(configs);
		return;
	}

	const int attribs[] =
	{
		GLX_TEXTURE_TARGET_EXT, GLX_TEXTURE_2D_EXT,
		GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT,
		None
	};

	p->glxpixmap = glXCreatePixmap(xdisp, configs[0], p->pixmap, attribs);

	if (xlock.gotError()) {
		blog(LOG_ERROR, "glXCreatePixmap failed: %s",
				xlock.getErrorText().c_str());
		XFreePixmap(xdisp, p->pixmap);
		XFree(configs);
		p->pixmap = 0;
		p->glxpixmap = 0;
		return;
	}

	XFree(configs);

	p->gltex = gs_create_texture(p->width, p->height, cf, 1, 0,
			GS_GL_DUMMYTEX);

	GLuint gltex = *(GLuint*)texture_getobj(p->gltex);
	glBindTexture(GL_TEXTURE_2D, gltex);
	glXBindTexImageEXT(xdisp, p->glxpixmap, GLX_FRONT_LEFT_EXT, NULL);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
Beispiel #25
0
void xcursor_destroy(xcursor_t *data) {
	if (data->tex)
		texture_destroy(data->tex);
	bfree(data);
}
Beispiel #26
0
void tilemap_destroy(struct tilemap *t)
{
    texture_destroy(&t->map.texture);
    texture_destroy(&t->atlas.texture);
    memset(t, 0, sizeof (*t));
}