[Mesa-dev] [PATCH 2/2] st/hgl: Move st_visual create/destroy into hgl state_tracker

Alexander von Gluck IV kallisti5 at unixzen.com
Fri Aug 29 08:07:44 PDT 2014


---
 src/gallium/state_trackers/hgl/hgl.c               |  103 +++++++++++++++++++-
 src/gallium/state_trackers/hgl/hgl_context.h       |    4 +
 .../targets/haiku-softpipe/GalliumContext.cpp      |  102 +------------------
 .../targets/haiku-softpipe/GalliumContext.h        |    2 -
 4 files changed, 111 insertions(+), 100 deletions(-)

diff --git a/src/gallium/state_trackers/hgl/hgl.c b/src/gallium/state_trackers/hgl/hgl.c
index 66abc61..ce2ffb1 100644
--- a/src/gallium/state_trackers/hgl/hgl.c
+++ b/src/gallium/state_trackers/hgl/hgl.c
@@ -8,6 +8,8 @@
  */
 
 
+#include "GLView.h"
+
 #include "main/context.h"
 #include "main/framebuffer.h"
 #include "main/renderbuffer.h"
@@ -134,7 +136,7 @@ hgl_st_framebuffer_validate(struct st_context_iface *stctx,
 static int
 hgl_st_manager_get_param(struct st_manager *smapi, enum st_manager_param param)
 {
-    CALLED();
+	CALLED();
 
 	switch (param) {
 		case ST_MANAGER_BROKEN_INVALIDATE:
@@ -215,3 +217,102 @@ hgl_destroy_st_manager(struct st_manager *manager)
 	if (manager)
 		FREE(manager);
 }
+
+
+struct st_visual*
+hgl_create_st_visual(ulong options)
+{
+	struct st_visual* visual = CALLOC_STRUCT(st_visual);
+	if (!visual) {
+		ERROR("%s: Couldn't allocate st_visual\n", __func__);
+		return NULL;
+	}
+
+	// Calculate visual configuration
+	const GLboolean rgbFlag     = ((options & BGL_INDEX) == 0);
+	const GLboolean alphaFlag   = ((options & BGL_ALPHA) == BGL_ALPHA);
+	const GLboolean dblFlag     = ((options & BGL_DOUBLE) == BGL_DOUBLE);
+	const GLboolean stereoFlag  = false;
+	const GLint depth           = (options & BGL_DEPTH) ? 24 : 0;
+	const GLint stencil         = (options & BGL_STENCIL) ? 8 : 0;
+	const GLint accum           = (options & BGL_ACCUM) ? 16 : 0;
+	const GLint red             = rgbFlag ? 8 : 5;
+	const GLint green           = rgbFlag ? 8 : 5;
+	const GLint blue            = rgbFlag ? 8 : 5;
+	const GLint alpha           = alphaFlag ? 8 : 0;
+
+	TRACE("rgb      :\t%d\n", (bool)rgbFlag);
+	TRACE("alpha    :\t%d\n", (bool)alphaFlag);
+	TRACE("dbl      :\t%d\n", (bool)dblFlag);
+	TRACE("stereo   :\t%d\n", (bool)stereoFlag);
+	TRACE("depth    :\t%d\n", depth);
+	TRACE("stencil  :\t%d\n", stencil);
+	TRACE("accum    :\t%d\n", accum);
+	TRACE("red      :\t%d\n", red);
+	TRACE("green    :\t%d\n", green);
+	TRACE("blue     :\t%d\n", blue);
+	TRACE("alpha    :\t%d\n", alpha);
+
+	// Determine color format
+	if (red == 8) {
+		if (alpha == 8)
+			visual->color_format = PIPE_FORMAT_A8R8G8B8_UNORM;
+		else
+			visual->color_format = PIPE_FORMAT_X8R8G8B8_UNORM;
+	} else {
+		// TODO: I think this should be RGB vs BGR
+		visual->color_format = PIPE_FORMAT_B5G6R5_UNORM;
+    }
+
+	// Determine depth stencil format
+	switch (depth) {
+		default:
+		case 0:
+			visual->depth_stencil_format = PIPE_FORMAT_NONE;
+			break;
+		case 16:
+			visual->depth_stencil_format = PIPE_FORMAT_Z16_UNORM;
+			break;
+		case 24:
+			if ((options & BGL_STENCIL) != 0)
+				visual->depth_stencil_format = PIPE_FORMAT_S8_UINT_Z24_UNORM;
+			else
+				visual->depth_stencil_format = PIPE_FORMAT_X8Z24_UNORM;
+			break;
+		case 32:
+			visual->depth_stencil_format = PIPE_FORMAT_Z32_UNORM;
+			break;
+	}
+
+	visual->accum_format = (options & BGL_ACCUM)
+		? PIPE_FORMAT_R16G16B16A16_SNORM : PIPE_FORMAT_NONE;
+
+	visual->buffer_mask |= ST_ATTACHMENT_FRONT_LEFT_MASK;
+	visual->render_buffer = ST_ATTACHMENT_FRONT_LEFT;
+
+	if (dblFlag) {
+		visual->buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK;
+		visual->render_buffer = ST_ATTACHMENT_BACK_LEFT;
+	}
+
+	if (stereoFlag) {
+		visual->buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK;
+		if (dblFlag)
+			visual->buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK;
+    }
+
+	if ((options & BGL_DEPTH) || (options & BGL_STENCIL))
+		visual->buffer_mask |= ST_ATTACHMENT_DEPTH_STENCIL_MASK;
+
+	return visual;
+}
+
+
+void
+hgl_destroy_st_visual(struct st_visual* visual)
+{
+	CALLED();
+
+	if (visual)
+		FREE(visual);
+}
diff --git a/src/gallium/state_trackers/hgl/hgl_context.h b/src/gallium/state_trackers/hgl/hgl_context.h
index a520d49..1d98414 100644
--- a/src/gallium/state_trackers/hgl/hgl_context.h
+++ b/src/gallium/state_trackers/hgl/hgl_context.h
@@ -80,5 +80,9 @@ struct hgl_buffer* hgl_create_st_framebuffer(struct hgl_context* context);
 struct st_manager* hgl_create_st_manager(struct pipe_screen* screen);
 void hgl_destroy_st_manager(struct st_manager *manager);
 
+// hgl state_tracker visual
+struct st_visual* hgl_create_st_visual(ulong options);
+void hgl_destroy_st_visual(struct st_visual* visual);
+
 
 #endif /* HGL_CONTEXT_H */
diff --git a/src/gallium/targets/haiku-softpipe/GalliumContext.cpp b/src/gallium/targets/haiku-softpipe/GalliumContext.cpp
index ed41712..5df5234 100644
--- a/src/gallium/targets/haiku-softpipe/GalliumContext.cpp
+++ b/src/gallium/targets/haiku-softpipe/GalliumContext.cpp
@@ -103,95 +103,6 @@ GalliumContext::~GalliumContext()
 }
 
 
-struct st_visual*
-GalliumContext::CreateVisual()
-{
-	struct st_visual* visual = CALLOC_STRUCT(st_visual);
-	if (!visual) {
-		ERROR("%s: Couldn't allocate st_visual\n", __func__);
-		return NULL;
-	}
-
-	// Calculate visual configuration
-	const GLboolean rgbFlag		= ((fOptions & BGL_INDEX) == 0);
-	const GLboolean alphaFlag	= ((fOptions & BGL_ALPHA) == BGL_ALPHA);
-	const GLboolean dblFlag		= ((fOptions & BGL_DOUBLE) == BGL_DOUBLE);
-	const GLboolean stereoFlag	= false;
-	const GLint depth			= (fOptions & BGL_DEPTH) ? 24 : 0;
-	const GLint stencil			= (fOptions & BGL_STENCIL) ? 8 : 0;
-	const GLint accum			= (fOptions & BGL_ACCUM) ? 16 : 0;
-	const GLint red				= rgbFlag ? 8 : 5;
-	const GLint green			= rgbFlag ? 8 : 5;
-	const GLint blue			= rgbFlag ? 8 : 5;
-	const GLint alpha			= alphaFlag ? 8 : 0;
-
-	TRACE("rgb      :\t%d\n", (bool)rgbFlag);
-	TRACE("alpha    :\t%d\n", (bool)alphaFlag);
-	TRACE("dbl      :\t%d\n", (bool)dblFlag);
-	TRACE("stereo   :\t%d\n", (bool)stereoFlag);
-	TRACE("depth    :\t%d\n", depth);
-	TRACE("stencil  :\t%d\n", stencil);
-	TRACE("accum    :\t%d\n", accum);
-	TRACE("red      :\t%d\n", red);
-	TRACE("green    :\t%d\n", green);
-	TRACE("blue     :\t%d\n", blue);
-	TRACE("alpha    :\t%d\n", alpha);
-
-	// Determine color format
-	if (red == 8) {
-		if (alpha == 8)
-			visual->color_format = PIPE_FORMAT_A8R8G8B8_UNORM;
-		else
-			visual->color_format = PIPE_FORMAT_X8R8G8B8_UNORM;
-	} else {
-		// TODO: I think this should be RGB vs BGR
-		visual->color_format = PIPE_FORMAT_B5G6R5_UNORM;
-	}
-
-	// Determine depth stencil format
-	switch (depth) {
-		default:
-		case 0:
-			visual->depth_stencil_format = PIPE_FORMAT_NONE;
-			break;
-		case 16:
-			visual->depth_stencil_format = PIPE_FORMAT_Z16_UNORM;
-			break;
-		case 24:
-			if ((fOptions & BGL_STENCIL) != 0)
-				visual->depth_stencil_format = PIPE_FORMAT_S8_UINT_Z24_UNORM;
-			else
-				visual->depth_stencil_format = PIPE_FORMAT_X8Z24_UNORM;
-			break;
-		case 32:
-			visual->depth_stencil_format = PIPE_FORMAT_Z32_UNORM;
-			break;
-	}
-
-	visual->accum_format = (fOptions & BGL_ACCUM)
-		? PIPE_FORMAT_R16G16B16A16_SNORM : PIPE_FORMAT_NONE;
-
-	visual->buffer_mask |= ST_ATTACHMENT_FRONT_LEFT_MASK;
-	visual->render_buffer = ST_ATTACHMENT_FRONT_LEFT;
-
-	if (dblFlag) {
-		visual->buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK;
-		visual->render_buffer = ST_ATTACHMENT_BACK_LEFT;
-	}
-
-	if (stereoFlag) {
-		visual->buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK;
-		if (dblFlag)
-			visual->buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK;
-	}
-
-	if ((fOptions & BGL_DEPTH) || (fOptions & BGL_STENCIL)) 
-		visual->buffer_mask |= ST_ATTACHMENT_DEPTH_STENCIL_MASK;
-
-	return visual;
-}
-
-
 status_t
 GalliumContext::CreateScreen()
 {
@@ -251,12 +162,9 @@ GalliumContext::CreateContext(Bitmap *bitmap)
 	context->manager = hgl_create_st_manager(fScreen);
 
 	// Create state tracker visual
-	context->stVisual = CreateVisual();
-	if (context->stVisual == NULL) {
-		ERROR("%s: Couldn't create state_tracker visual!\n", __func__);
-		return -1;
-	}
+	context->stVisual = hgl_create_st_visual(fOptions);
 
+	// Create state tracker framebuffers
 	context->draw = hgl_create_st_framebuffer(context);
 	context->read = hgl_create_st_framebuffer(context);
 
@@ -310,7 +218,7 @@ GalliumContext::CreateContext(Bitmap *bitmap)
 				break;
 		}
 
-		FREE(context->stVisual);
+		hgl_destroy_st_visual(context->stVisual);
 		FREE(context);
 		return -1;
 	}
@@ -371,14 +279,14 @@ GalliumContext::DestroyContext(context_id contextID)
 	if (fContext[contextID]->postProcess)
 		pp_free(fContext[contextID]->postProcess);
 
-	// Delete framebuffer objects
+	// Delete state tracker framebuffer objects
 	if (fContext[contextID]->read)
 		delete fContext[contextID]->read;
 	if (fContext[contextID]->draw)
 		delete fContext[contextID]->draw;
 
 	if (fContext[contextID]->stVisual)
-		FREE(fContext[contextID]->stVisual);
+		hgl_destroy_st_visual(fContext[contextID]->stVisual);
 
 	if (fContext[contextID]->manager)
 		hgl_destroy_st_manager(fContext[contextID]->manager);
diff --git a/src/gallium/targets/haiku-softpipe/GalliumContext.h b/src/gallium/targets/haiku-softpipe/GalliumContext.h
index cf8895e..6f8a4d0 100644
--- a/src/gallium/targets/haiku-softpipe/GalliumContext.h
+++ b/src/gallium/targets/haiku-softpipe/GalliumContext.h
@@ -33,8 +33,6 @@ public:
 		void				Lock();
 		void				Unlock();
 
-		struct st_visual*	CreateVisual();
-
 		context_id			CreateContext(Bitmap* bitmap);
 		void				DestroyContext(context_id contextID);
 		context_id			GetCurrentContext() { return fCurrentContext; };
-- 
1.7.1



More information about the mesa-dev mailing list