From caa23ee333814b10f3b040b76d273159872aa2fd Mon Sep 17 00:00:00 2001 From: Alexander von Gluck IV Date: Wed, 28 Nov 2012 21:43:51 -0600 Subject: [PATCH] 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 --- src/add-ons/opengl/swpipe/GalliumContext.cpp | 109 +--------- src/add-ons/opengl/swpipe/Jamfile | 3 +- src/add-ons/opengl/swpipe/SoftwareWinsys.cpp | 206 +++++++++++++++++++ src/add-ons/opengl/swpipe/SoftwareWinsys.h | 34 +++ 4 files changed, 246 insertions(+), 106 deletions(-) create mode 100644 src/add-ons/opengl/swpipe/SoftwareWinsys.cpp create mode 100644 src/add-ons/opengl/swpipe/SoftwareWinsys.h diff --git a/src/add-ons/opengl/swpipe/GalliumContext.cpp b/src/add-ons/opengl/swpipe/GalliumContext.cpp index 0ebc1113fd..d0488411d1 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 106dc1e0ab..33be1244dc 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 0000000000..efcdcbbfc9 --- /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@gmail.com + * Alexander von Gluck IV, kallisti5@unixzen.com + */ + + +#include "SoftwareWinsys.h" + +#include + +#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 0000000000..a3497bfe9e --- /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@unixzen.com + */ +#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