Пример #1
0
bool
hsp_make_current(Bitmap *bitmap, uint64 ctxId)
{
	TRACE("%s(bitmap: %p ctxId: %d)\n", __FUNCTION__, bitmap, ctxId);
	struct hsp_context *ctx = NULL;
	GET_CURRENT_CONTEXT(glcurctx);
	GLuint width = 0;
	GLuint height = 0;
	struct hsp_context *curctx;

	if (!hsp_dev) {
		TRACE("%s> there's no hsp_dev so nothing to do\n",
			__FUNCTION__);
		return false;
	}

	pipe_mutex_lock(hsp_dev->mutex);
	ctx = hsp_lookup_context(ctxId);
	pipe_mutex_unlock(hsp_dev->mutex);

	if (ctx == NULL) {
		TRACE("%s> context not found\n", __FUNCTION__);
		return false;
	}

	current_bitmap = bitmap;
	current_ctx_id = ctxId;

	if (glcurctx != NULL) {
		curctx = (struct hsp_context*) glcurctx->DriverCtx;

		if (curctx != ctx)
			st_flush(glcurctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
	}

	if (!bitmap || ctxId == 0) {
		st_make_current(NULL, NULL, NULL);
		return true;
	}

	if (glcurctx != NULL) {
		struct hsp_context *curctx = (struct hsp_context*) glcurctx->DriverCtx;
		if (curctx != NULL && curctx == ctx && ctx->bitmap == bitmap)
			return true;
	}

	if (bitmap != NULL) {
		get_bitmap_size(bitmap, &width, &height);
		TRACE("%s> found bitmap: %p with size: %dx%d\n", __FUNCTION__,
			bitmap, width, height);
	}

	if (ctx != NULL && bitmap != NULL ) {
		GLvisual *visual = &ctx->st->ctx->Visual;
		if (ctx->draw == NULL) {
			ctx->draw = framebuffer_create(bitmap, visual, width /*+ 1*/, height /*+ 1*/);
		}
		if ((hsp_dev->options & BGL_DOUBLE) == BGL_DOUBLE && ctx->read == NULL) {
			ctx->read = framebuffer_create(bitmap, visual, width /*+ 1*/, height /*+ 1*/);
		}
	}

	if (ctx) {
		if (ctx->draw && ctx->read == NULL) {
			st_make_current(ctx->st, ctx->draw->stfb, ctx->draw->stfb);
			framebuffer_resize(ctx->draw, width /*+ 1*/, height /*+ 1*/);
		} else if (ctx && ctx->draw && ctx->read) {
			st_make_current(ctx->st, ctx->draw->stfb, ctx->read->stfb);
			framebuffer_resize(ctx->draw, width /*+ 1*/, height /*+ 1*/);
			framebuffer_resize(ctx->read, width /*+ 1*/, height /*+ 1*/);
		}
		ctx->bitmap = bitmap;
		ctx->st->pipe->priv = bitmap;
	} else {
		st_make_current(NULL, NULL, NULL);
	}

	return true;
}
Пример #2
0
/**
 * Called by the st manager to validate the framebuffer (allocate
 * its resources).
 */
static boolean
hgl_st_framebuffer_validate(struct st_context_iface *stctx,
	struct st_framebuffer_iface *stfbi, const enum st_attachment_type *statts,
	unsigned count, struct pipe_resource **out)
{
	CALLED();

	if (!stfbi) {
		ERROR("%s: Invalid st framebuffer interface!\n", __func__);
		return FALSE;
	}

	struct hgl_context* context = (struct hgl_context*)stfbi->st_manager_private;

	if (!context) {
		ERROR("%s: Couldn't obtain valid hgl_context!\n", __func__);
		return FALSE;
	}

	int32 width = 0;
	int32 height = 0;
	get_bitmap_size(context->bitmap, &width, &height);

	struct pipe_resource templat;
	memset(&templat, 0, sizeof(templat));
	templat.target = PIPE_TEXTURE_RECT;
	templat.width0 = width;
	templat.height0 = height;
	templat.depth0 = 1;
	templat.array_size = 1;
	templat.usage = PIPE_USAGE_DEFAULT;

	if (context->stVisual && context->manager && context->manager->screen) {
		TRACE("%s: Updating resources\n", __func__);
		for (unsigned i = 0; i < count; i++) {
			enum pipe_format format = PIPE_FORMAT_NONE;
			unsigned bind = 0;

			switch(statts[i]) {
				case ST_ATTACHMENT_FRONT_LEFT:
				case ST_ATTACHMENT_BACK_LEFT:
					format = context->stVisual->color_format;
					bind = PIPE_BIND_DISPLAY_TARGET
						| PIPE_BIND_RENDER_TARGET;
					break;
				case ST_ATTACHMENT_DEPTH_STENCIL:
					format = context->stVisual->depth_stencil_format;
					bind = PIPE_BIND_DEPTH_STENCIL;
					break;
				case ST_ATTACHMENT_ACCUM:
					format = context->stVisual->accum_format;
					bind = PIPE_BIND_RENDER_TARGET;
					break;
				default:
					format = PIPE_FORMAT_NONE;
					break;
			}

			if (format != PIPE_FORMAT_NONE) {
				templat.format = format;
				templat.bind = bind;

				struct pipe_screen* screen = context->manager->screen;
				context->textures[i] = screen->resource_create(screen, &templat);
				out[i] = context->textures[i];
			}
		}
	}

	return TRUE;
}