st/hgl: Move st_visual create/destroy into hgl state_tracker
authorAlexander von Gluck IV <kallisti5@unixzen.com>
Fri, 29 Aug 2014 15:06:09 +0000 (15:06 +0000)
committerAlexander von Gluck IV <kallisti5@unixzen.com>
Sat, 30 Aug 2014 23:35:24 +0000 (19:35 -0400)
src/gallium/state_trackers/hgl/hgl.c
src/gallium/state_trackers/hgl/hgl_context.h
src/gallium/targets/haiku-softpipe/GalliumContext.cpp
src/gallium/targets/haiku-softpipe/GalliumContext.h

index 66abc61cb2d417c940ab03ef5592e5b5f77c254b..ce2ffb1d418833cfa277e5564bdf6a5e79754c2c 100644 (file)
@@ -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);
+}
index a520d490e522f028d982e001b5ebbb64e08ea494..1d9841468ae57dd1fd83a4f4df06a09dc16149d3 100644 (file)
@@ -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 */
index ed4171282d88de566f1f64a3b3e24e1424c15449..5df5234bcbc939c287015f99352f2adaef8e58e5 100644 (file)
@@ -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);
index cf8895e68266b3fa9a5a9e12b1e82da27f88a603..6f8a4d0bda3d72697ca55eded8edce9052a3f8ed 100644 (file)
@@ -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; };