[haiku-commits] haiku: hrev44925 - src/add-ons/opengl/swpipe

  • From: kallisti5@xxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 29 Nov 2012 06:33:49 +0100 (CET)

hrev44925 adds 2 changesets to branch 'master'
old head: 50af89af0b2da34d548c1f1bdc8f2479a7407d2e
new head: 84169234d73e76c672a465302fbf27da70c3e70d
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=8416923+%5E50af89a

----------------------------------------------------------------------------

caa23ee: swpipe: First work on winsys calls
  
  * Move winsys code into a new file given the size
  * Try to fill in as much logic as I can on creating
    and destroying the Gallium displaytarget

8416923: swpipe: Cleanup, code correction
  
  * Remove error text as giving SetCurrentContext
    a NULL bitmap isn't a critical error.
  * Ensure old front buffer is flushed on SetCurrentContext
  * Small style fix

                          [ Alexander von Gluck IV <kallisti5@xxxxxxxxxxx> ]

----------------------------------------------------------------------------

4 files changed, 248 insertions(+), 108 deletions(-)
src/add-ons/opengl/swpipe/GalliumContext.cpp | 112 +-----------
src/add-ons/opengl/swpipe/Jamfile            |   3 +-
src/add-ons/opengl/swpipe/SoftwareWinsys.cpp | 206 +++++++++++++++++++++++
src/add-ons/opengl/swpipe/SoftwareWinsys.h   |  35 ++++

############################################################################

Commit:      caa23ee333814b10f3b040b76d273159872aa2fd
URL:         http://cgit.haiku-os.org/haiku/commit/?id=caa23ee
Author:      Alexander von Gluck IV <kallisti5@xxxxxxxxxxx>
Date:        Thu Nov 29 03:43:51 2012 UTC

swpipe: First work on winsys calls

* Move winsys code into a new file given the size
* Try to fill in as much logic as I can on creating
  and destroying the Gallium displaytarget

----------------------------------------------------------------------------

diff --git a/src/add-ons/opengl/swpipe/GalliumContext.cpp 
b/src/add-ons/opengl/swpipe/GalliumContext.cpp
index 0ebc111..d048841 100644
--- a/src/add-ons/opengl/swpipe/GalliumContext.cpp
+++ b/src/add-ons/opengl/swpipe/GalliumContext.cpp
@@ -13,6 +13,7 @@
 #include "GLView.h"
 
 #include "bitmap_wrapper.h"
+#include "SoftwareWinsys.h"
 extern "C" {
 #include "glapi/glapi.h"
 #include "main/context.h"
@@ -136,96 +137,6 @@ round_up(unsigned n, unsigned multiple)
 }
 
 
-/* winsys hooks */
-
-
-static void
-hook_winsys_destroy(struct sw_winsys* winsys)
-{
-       CALLED();
-       FREE(winsys);
-}
-
-
-static boolean
-hook_winsys_is_displaytarget_format_supported(struct sw_winsys* winsys,
-       unsigned tex_usage, enum pipe_format format)
-{
-       CALLED();
-       // TODO STUB
-       return false;
-}
-
-
-static struct sw_displaytarget*
-hook_winsys_displaytarget_create(struct sw_winsys* winsys, unsigned tex_usage,
-       enum pipe_format format, unsigned width, unsigned height,
-       unsigned alignment, unsigned* stride)
-{
-       CALLED();
-       // TODO STUB
-       return NULL;
-}
-
-
-static struct sw_displaytarget*
-hook_winsys_displaytarget_from_handle(struct sw_winsys* winsys,
-       const struct pipe_resource* templat, struct winsys_handle* whandle,
-       unsigned* stride)
-{
-       CALLED();
-       // TODO STUB
-       return NULL;
-}
-
-
-static boolean
-hook_winsys_displaytarget_get_handle(struct sw_winsys* winsys,
-       struct sw_displaytarget* disptarget, struct winsys_handle* whandle)
-{
-       CALLED();
-       // TODO STUB
-       return false;
-}
-
-
-static void*
-hook_winsys_displaytarget_map(struct sw_winsys* winsys,
-       struct sw_displaytarget* disptarget, unsigned flags)
-{
-       CALLED();
-       // TODO STUB
-       return NULL;
-}
-
-
-static void
-hook_winsys_displaytarget_unmap(struct sw_winsys* winsys,
-       struct sw_displaytarget* disptarget)
-{
-       CALLED();
-       // TODO STUB
-}
-
-
-static void
-hook_winsys_displaytarget_display(struct sw_winsys* winsys,
-       struct sw_displaytarget* disptarget, void* context_private)
-{
-       CALLED();
-       // TODO STUB
-}
-
-
-static void
-hook_winsys_displaytarget_destroy(struct sw_winsys* winsys,
-       struct sw_displaytarget* disptarget)
-{
-       CALLED();
-       // TODO STUB
-}
-
-
 static int
 hook_stm_get_param(struct st_manager *smapi, enum st_manager_param param)
 {
@@ -282,26 +193,14 @@ GalliumContext::CreateScreen()
 {
        CALLED();
 
-       struct sw_winsys* winsys = CALLOC_STRUCT(sw_winsys);
+       // Allocate winsys and attach callback hooks
+       struct sw_winsys* winsys = winsys_connect_hooks();
 
        if (!winsys) {
-               ERROR("%s: Couldn't alloc sw_winsys!\n", __FUNCTION__);
+               ERROR("%s: Couldn't allocate sw_winsys!\n", __func__);
                return B_ERROR;
        }
 
-       // Attach winsys hooks for Haiku
-       // gdi_create_sw_winsys is a good Mesa example
-       winsys->destroy = hook_winsys_destroy;
-       winsys->is_displaytarget_format_supported
-               = hook_winsys_is_displaytarget_format_supported;
-       winsys->displaytarget_create = hook_winsys_displaytarget_create;
-       winsys->displaytarget_from_handle = 
hook_winsys_displaytarget_from_handle;
-       winsys->displaytarget_get_handle = hook_winsys_displaytarget_get_handle;
-       winsys->displaytarget_map = hook_winsys_displaytarget_map;
-       winsys->displaytarget_unmap = hook_winsys_displaytarget_unmap;
-       winsys->displaytarget_display = hook_winsys_displaytarget_display;
-       winsys->displaytarget_destroy = hook_winsys_displaytarget_destroy;
-
        #if USE_LLVMPIPE
        fScreen = llvmpipe_create_screen(winsys);
        #endif
diff --git a/src/add-ons/opengl/swpipe/Jamfile 
b/src/add-ons/opengl/swpipe/Jamfile
index 106dc1e..33be124 100644
--- a/src/add-ons/opengl/swpipe/Jamfile
+++ b/src/add-ons/opengl/swpipe/Jamfile
@@ -7,7 +7,8 @@ UseHeaders [ FDirName $(HAIKU_MESA_DIR) src mapi ] ;
 UseHeaders [ FDirName $(HAIKU_MESA_DIR) src mesa ] ;
 
 local sources =
-       SoftwareRenderer.cpp 
+       SoftwareRenderer.cpp
+       SoftwareWinsys.cpp
        GalliumContext.cpp
        bitmap_wrapper.cpp ;
 
diff --git a/src/add-ons/opengl/swpipe/SoftwareWinsys.cpp 
b/src/add-ons/opengl/swpipe/SoftwareWinsys.cpp
new file mode 100644
index 0000000..efcdcbb
--- /dev/null
+++ b/src/add-ons/opengl/swpipe/SoftwareWinsys.cpp
@@ -0,0 +1,206 @@
+/*
+ * Copyright 2006-2012, Haiku, Inc. All rights reserved.
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ *             Artur Wyszynski, harakash@xxxxxxxxx
+ *             Alexander von Gluck IV, kallisti5@xxxxxxxxxxx
+ */
+
+
+#include "SoftwareWinsys.h"
+
+#include <stdio.h>
+
+#include "bitmap_wrapper.h"
+extern "C" {
+#include "state_tracker/st_api.h"
+#include "state_tracker/sw_winsys.h"
+#include "util/u_format.h"
+#include "util/u_math.h"
+#include "util/u_memory.h"
+}
+
+
+#define TRACE_CONTEXT
+#ifdef TRACE_CONTEXT
+#      define TRACE(x...) printf("GalliumContext: " x)
+#      define CALLED() TRACE("CALLED: %s\n", __PRETTY_FUNCTION__)
+#else
+#      define TRACE(x...)
+#      define CALLED()
+#endif
+#define ERROR(x...) printf("GalliumContext: " x)
+
+
+// Cast
+static INLINE struct haiku_displaytarget*
+cast_haiku_displaytarget(struct sw_displaytarget* target)
+{
+       return (struct haiku_displaytarget *)target;
+}
+
+
+static void
+hook_winsys_destroy(struct sw_winsys* winsys)
+{
+       CALLED();
+       FREE(winsys);
+}
+
+
+static boolean
+hook_winsys_is_displaytarget_format_supported(struct sw_winsys* winsys,
+       unsigned textureUsage, enum pipe_format format)
+{
+       CALLED();
+       // TODO STUB
+       return true;
+}
+
+
+static struct sw_displaytarget*
+hook_winsys_displaytarget_create(struct sw_winsys* winsys,
+       unsigned textureUsage, enum pipe_format format, unsigned width,
+       unsigned height, unsigned alignment, unsigned* stride)
+{
+       CALLED();
+
+       struct haiku_displaytarget* haikuDisplayTarget
+               = CALLOC_STRUCT(haiku_displaytarget);
+
+       if (!haikuDisplayTarget) {
+               ERROR("%s: Couldn't allocate Haiku display target!\n",
+                       __func__);
+               return NULL;
+       }
+
+       haikuDisplayTarget->format = format;
+       haikuDisplayTarget->width = width;
+       haikuDisplayTarget->height = height;
+
+       //unsigned bitsPerPixel = util_format_get_blocksizebits(format);
+       unsigned colorsPerPalette = util_format_get_blocksize(format);
+
+       haikuDisplayTarget->stride = align(width * colorsPerPalette, alignment);
+       haikuDisplayTarget->size = haikuDisplayTarget->stride * height;
+
+       haikuDisplayTarget->data
+               = align_malloc(haikuDisplayTarget->size, alignment);
+
+       if (!haikuDisplayTarget->data) {
+               ERROR("%s: Couldn't allocate Haiku display target data!\n",
+                       __func__);
+               FREE(haikuDisplayTarget);
+               return NULL;
+       }
+
+       *stride = haikuDisplayTarget->stride;
+
+       // Cast to ghost sw_displaytarget type
+       return (struct sw_displaytarget*)haikuDisplayTarget;
+}
+
+
+static void
+hook_winsys_displaytarget_destroy(struct sw_winsys* winsys,
+       struct sw_displaytarget* displayTarget)
+{
+       CALLED();
+
+       struct haiku_displaytarget* haikuDisplayTarget
+               = cast_haiku_displaytarget(displayTarget);
+
+       if (!haikuDisplayTarget) {
+               ERROR("%s: Attempt to destroy non-existant display target!\n",
+                       __func__);
+               return;
+       }
+       
+       if (haikuDisplayTarget->data != NULL)
+               align_free(haikuDisplayTarget->data);
+
+       FREE(haikuDisplayTarget);
+}
+
+
+static struct sw_displaytarget*
+hook_winsys_displaytarget_from_handle(struct sw_winsys* winsys,
+       const struct pipe_resource* templat, struct winsys_handle* whandle,
+       unsigned* stride)
+{
+       CALLED();
+       return NULL;
+}
+
+
+static boolean
+hook_winsys_displaytarget_get_handle(struct sw_winsys* winsys,
+       struct sw_displaytarget* displayTarget, struct winsys_handle* whandle)
+{
+       CALLED();
+       return FALSE;
+}
+
+
+static void*
+hook_winsys_displaytarget_map(struct sw_winsys* winsys,
+       struct sw_displaytarget* displayTarget, unsigned flags)
+{
+       CALLED();
+       struct haiku_displaytarget* haikuDisplayTarget
+               = cast_haiku_displaytarget(displayTarget);
+
+       return haikuDisplayTarget->data;
+}
+
+
+static void
+hook_winsys_displaytarget_unmap(struct sw_winsys* winsys,
+       struct sw_displaytarget* disptarget)
+{
+       return;
+}
+
+
+static void
+hook_winsys_displaytarget_display(struct sw_winsys* winsys,
+       struct sw_displaytarget* displayTarget, void* contextPrivate)
+{
+       CALLED();
+
+       //struct haiku_displaytarget* haikuDisplayTarget
+       //      = cast_haiku_displaytarget(displayTarget);
+
+       // GDI copies data from haikuDisplayTarget->data into
+       // a Bitmap casted from contextPrivate.. need to investigate
+       // this.
+
+       return;
+}
+
+
+struct sw_winsys*
+winsys_connect_hooks()
+{
+       CALLED();
+
+       struct sw_winsys* winsys = CALLOC_STRUCT(sw_winsys);
+
+       if (!winsys)
+               return NULL;
+       
+       // Attach winsys hooks for Haiku
+       winsys->destroy = hook_winsys_destroy;
+       winsys->is_displaytarget_format_supported
+               = hook_winsys_is_displaytarget_format_supported;
+       winsys->displaytarget_create = hook_winsys_displaytarget_create;
+       winsys->displaytarget_from_handle = 
hook_winsys_displaytarget_from_handle;
+       winsys->displaytarget_get_handle = hook_winsys_displaytarget_get_handle;
+       winsys->displaytarget_map = hook_winsys_displaytarget_map;
+       winsys->displaytarget_unmap = hook_winsys_displaytarget_unmap;
+       winsys->displaytarget_display = hook_winsys_displaytarget_display;
+       winsys->displaytarget_destroy = hook_winsys_displaytarget_destroy;
+
+       return winsys;
+}
\ No newline at end of file
diff --git a/src/add-ons/opengl/swpipe/SoftwareWinsys.h 
b/src/add-ons/opengl/swpipe/SoftwareWinsys.h
new file mode 100644
index 0000000..a3497bf
--- /dev/null
+++ b/src/add-ons/opengl/swpipe/SoftwareWinsys.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2006-2012, Haiku, Inc. All rights reserved.
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ *             Alexander von Gluck IV, kallisti5@xxxxxxxxxxx
+ */
+#ifndef SOFTWAREWINSYS_H
+#define SOFTWAREWINSYS_H
+
+
+extern "C" {
+#include "pipe/p_defines.h"
+#include "state_tracker/st_api.h"
+#include "state_tracker/sw_winsys.h"
+}
+
+
+struct haiku_displaytarget
+{
+       enum pipe_format format;
+       unsigned width;
+       unsigned height;
+       unsigned stride;
+
+       unsigned size;
+
+       void* data;
+};
+
+struct sw_winsys* winsys_connect_hooks();
+
+
+#endif
\ No newline at end of file

############################################################################

Revision:    hrev44925
Commit:      84169234d73e76c672a465302fbf27da70c3e70d
URL:         http://cgit.haiku-os.org/haiku/commit/?id=8416923
Author:      Alexander von Gluck IV <kallisti5@xxxxxxxxxxx>
Date:        Thu Nov 29 05:02:24 2012 UTC

swpipe: Cleanup, code correction

* Remove error text as giving SetCurrentContext
  a NULL bitmap isn't a critical error.
* Ensure old front buffer is flushed on SetCurrentContext
* Small style fix

----------------------------------------------------------------------------

diff --git a/src/add-ons/opengl/swpipe/GalliumContext.cpp 
b/src/add-ons/opengl/swpipe/GalliumContext.cpp
index d048841..8bf28b8 100644
--- a/src/add-ons/opengl/swpipe/GalliumContext.cpp
+++ b/src/add-ons/opengl/swpipe/GalliumContext.cpp
@@ -425,7 +425,6 @@ GalliumContext::SetCurrentContext(Bitmap *bitmap, 
context_id contextID)
        struct st_api* api = context->api;
 
        if (!bitmap) {
-               ERROR("%s: Invalid bitmap provided!\n", __func__);
                api->make_current(context->api, NULL, NULL, NULL);
                return B_ERROR;
        }
@@ -435,7 +434,7 @@ GalliumContext::SetCurrentContext(Bitmap *bitmap, 
context_id contextID)
 
        if (oldContextID > 0 && oldContextID != contextID) {
                fContext[oldContextID]->st->flush(fContext[oldContextID]->st,
-                       0, NULL);
+                       ST_FLUSH_FRONT, NULL);
        }
 
        // TODO: WinSysDrawBuffer & WinSysReadBuffer?
diff --git a/src/add-ons/opengl/swpipe/SoftwareWinsys.h 
b/src/add-ons/opengl/swpipe/SoftwareWinsys.h
index a3497bf..2cf1b8e 100644
--- a/src/add-ons/opengl/swpipe/SoftwareWinsys.h
+++ b/src/add-ons/opengl/swpipe/SoftwareWinsys.h
@@ -28,6 +28,7 @@ struct haiku_displaytarget
        void* data;
 };
 
+
 struct sw_winsys* winsys_connect_hooks();
 
 


Other related posts:

  • » [haiku-commits] haiku: hrev44925 - src/add-ons/opengl/swpipe - kallisti5