haiku: fix build
authorX512 <danger_mail@list.ru>
Thu, 10 Mar 2022 15:48:05 +0000 (00:48 +0900)
committerMarge Bot <emma+marge@anholt.net>
Sat, 18 Feb 2023 00:44:43 +0000 (00:44 +0000)
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21079>

src/gallium/frontends/hgl/bitmap_wrapper.cpp [deleted file]
src/gallium/frontends/hgl/bitmap_wrapper.h [deleted file]
src/gallium/frontends/hgl/hgl.c
src/gallium/frontends/hgl/hgl_context.h
src/gallium/frontends/hgl/meson.build
src/gallium/winsys/sw/hgl/hgl_sw_winsys.cpp
src/gallium/winsys/sw/hgl/hgl_sw_winsys.h
src/util/macros.h
src/util/u_math.h

diff --git a/src/gallium/frontends/hgl/bitmap_wrapper.cpp b/src/gallium/frontends/hgl/bitmap_wrapper.cpp
deleted file mode 100644 (file)
index ef81edc..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2009 Artur Wyszynski <harakash@gmail.com>
- * Copyright 2013 Alexander von Gluck IV <kallisti5@unixzen.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- **************************************************************************/
-
-
-#include <stdio.h>
-#include <interface/Bitmap.h>
-#include <storage/File.h>
-#include <support/String.h>
-#include <translation/BitmapStream.h>
-#include <translation/TranslatorRoster.h>
-
-#include "bitmap_wrapper.h"
-
-
-extern "C" {
-static int frameNo = 0;
-
-
-Bitmap*
-create_bitmap(int32 width, int32 height, color_space colorSpace)
-{
-       BBitmap *bb = new BBitmap(BRect(0, 0, width, height), colorSpace);
-       if (bb)
-               return (Bitmap*)bb;
-       return NULL;
-}
-
-
-void
-get_bitmap_size(const Bitmap* bitmap, int32* width, int32* height)
-{
-       BBitmap *bb = (BBitmap*)bitmap;
-       if (bb && width && height) {
-               uint32 w = bb->Bounds().IntegerWidth() + 1;
-               uint32 h = bb->Bounds().IntegerHeight() + 1;
-               *width = w;
-               *height = h;
-       }
-}
-
-
-color_space
-get_bitmap_color_space(const Bitmap* bitmap)
-{
-       BBitmap *bb = (BBitmap*)bitmap;
-       if (bb)
-               return bb->ColorSpace();
-       return B_NO_COLOR_SPACE;
-}
-
-
-void
-copy_bitmap_bits(const Bitmap* bitmap, void* data, int32 length)
-{
-       BBitmap *bb = (BBitmap*)bitmap;
-
-       // We assume the data is 1:1 the format of the bitmap
-       if (bb)
-               bb->ImportBits(data, length, bb->BytesPerRow(), 0, bb->ColorSpace());
-}
-
-
-void
-import_bitmap_bits(const Bitmap* bitmap, void* data, int32 length,
-       unsigned srcStride, color_space srcColorSpace)
-{
-       BBitmap *bb = (BBitmap*)bitmap;
-
-       // Import image and adjust image format from source to dest
-       if (bb)
-               bb->ImportBits(data, length, srcStride, 0, srcColorSpace);
-}
-
-
-void
-delete_bitmap(Bitmap* bitmap)
-{
-       BBitmap *bb = (BBitmap*)bitmap;
-       delete bb;
-}
-
-
-int32
-get_bitmap_bytes_per_row(const Bitmap* bitmap)
-{
-       BBitmap *bb = (BBitmap*)bitmap;
-       if (bb)
-               return bb->BytesPerRow();
-       return 0;
-}
-
-
-int32
-get_bitmap_bits_length(const Bitmap* bitmap)
-{
-       BBitmap *bb = (BBitmap*)bitmap;
-       if (bb)
-               return bb->BitsLength();
-       return 0;
-}
-
-
-void
-dump_bitmap(const Bitmap* bitmap)
-{
-       BBitmap *bb = (BBitmap*)bitmap;
-       if (!bb)
-               return;
-
-       BString filename("/boot/home/frame_");
-       filename << (int32)frameNo << ".png";
-
-       BTranslatorRoster *roster = BTranslatorRoster::Default();
-       BBitmapStream stream(bb);
-       BFile dump(filename, B_CREATE_FILE | B_WRITE_ONLY);
-
-       roster->Translate(&stream, NULL, NULL, &dump, 0);
-
-       frameNo++;
-}
-
-}
diff --git a/src/gallium/frontends/hgl/bitmap_wrapper.h b/src/gallium/frontends/hgl/bitmap_wrapper.h
deleted file mode 100644 (file)
index 65ba140..0000000
+++ /dev/null
@@ -1,62 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2009 Artur Wyszynski <harakash@gmail.com>
- * Copyright 2013 Alexander von Gluck IV <kallisti5@unixzen.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the
- * "Software"), to deal in the Software without restriction, including
- * without limitation the rights to use, copy, modify, merge, publish,
- * distribute, sub license, and/or sell copies of the Software, and to
- * permit persons to whom the Software is furnished to do so, subject to
- * the following conditions:
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
- * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
- *
- * The above copyright notice and this permission notice (including the
- * next paragraph) shall be included in all copies or substantial portions
- * of the Software.
- *
- **************************************************************************/
-#ifndef __BBITMAP_WRAPPER_H__
-#define __BBITMAP_WRAPPER_H__
-
-
-#include <interface/GraphicsDefs.h>
-#include <support/SupportDefs.h>
-
-
-typedef void Bitmap;
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-Bitmap* create_bitmap(int32 width, int32 height, color_space colorSpace);
-void delete_bitmap(Bitmap* bitmap);
-
-void copy_bitmap_bits(const Bitmap* bitmap, void* data, int32 length);
-void import_bitmap_bits(const Bitmap* bitmap, void* data, int32 length,
-       unsigned srcStride, color_space srcColorSpace);
-
-void get_bitmap_size(const Bitmap* bitmap, int32* width, int32* height);
-color_space get_bitmap_color_space(const Bitmap* bitmap);
-int32 get_bitmap_bytes_per_row(const Bitmap* bitmap);
-int32 get_bitmap_bits_length(const Bitmap* bitmap);
-
-void dump_bitmap(const Bitmap* bitmap);
-
-
-#ifdef __cplusplus
-}
-#endif
-
-
-#endif /* __BBITMAP_WRAPPER_H__ */
index f1a6d92..7fd5745 100644 (file)
@@ -16,6 +16,7 @@
 #include "util/format/u_format.h"
 #include "util/u_memory.h"
 #include "util/u_inlines.h"
+#include "state_tracker/st_context.h"
 
 #include "GLView.h"
 
@@ -43,8 +44,7 @@ hgl_st_context(struct st_context *st)
 
 
 // Perform a safe void to hgl_buffer cast
-//static inline struct hgl_buffer*
-struct hgl_buffer*
+static struct hgl_buffer*
 hgl_st_framebuffer(struct pipe_frontend_drawable *drawable)
 {
        struct hgl_buffer* buffer;
@@ -109,17 +109,17 @@ hgl_st_framebuffer_validate_textures(struct pipe_frontend_drawable *drawable,
                enum pipe_format format;
                unsigned bind;
 
-               if (((1 << i) & buffer->visual->buffer_mask) && buffer->textures[i] == NULL) {
+               if (((1 << i) & buffer->visual.buffer_mask) && buffer->textures[i] == NULL) {
                        switch (i) {
                                case ST_ATTACHMENT_FRONT_LEFT:
                                case ST_ATTACHMENT_BACK_LEFT:
                                case ST_ATTACHMENT_FRONT_RIGHT:
                                case ST_ATTACHMENT_BACK_RIGHT:
-                                       format = buffer->visual->color_format;
+                                       format = buffer->visual.color_format;
                                        bind = PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_RENDER_TARGET;
                                        break;
                                case ST_ATTACHMENT_DEPTH_STENCIL:
-                                       format = buffer->visual->depth_stencil_format;
+                                       format = buffer->visual.depth_stencil_format;
                                        bind = PIPE_BIND_DEPTH_STENCIL;
                                        break;
                                default:
@@ -157,7 +157,6 @@ hgl_st_framebuffer_validate(struct st_context *st,
        struct pipe_frontend_drawable *drawable, const enum st_attachment_type *statts,
        unsigned count, struct pipe_resource **out, struct pipe_resource **resolve)
 {
-       struct hgl_context* context;
        struct hgl_buffer* buffer;
        unsigned stAttachmentMask, newMask;
        unsigned i;
@@ -165,7 +164,6 @@ hgl_st_framebuffer_validate(struct st_context *st,
 
        CALLED();
 
-       context = hgl_st_context(st);
        buffer = hgl_st_framebuffer(drawable);
 
        // Build mask of current attachments
@@ -175,16 +173,16 @@ hgl_st_framebuffer_validate(struct st_context *st,
 
        newMask = stAttachmentMask & ~buffer->mask;
 
-       resized = (buffer->width != context->width)
-               || (buffer->height != context->height);
+       resized = (buffer->width != buffer->newWidth)
+               || (buffer->height != buffer->newHeight);
 
        if (resized || newMask) {
                boolean ret;
                TRACE("%s: resize event. old:  %d x %d; new: %d x %d\n", __func__,
-                       buffer->width, buffer->height, context->width, context->height);
+                       buffer->width, buffer->height, buffer->newWidth, buffer->newHeight);
 
                ret = hgl_st_framebuffer_validate_textures(drawable,
-                       context->width, context->height, stAttachmentMask);
+                       buffer->newWidth, buffer->newHeight, stAttachmentMask);
 
                if (!ret)
                        return ret;
@@ -217,22 +215,21 @@ static uint32_t hgl_fb_ID = 0;
  * Create new framebuffer
  */
 struct hgl_buffer *
-hgl_create_st_framebuffer(struct hgl_context* context, void *winsysContext)
+hgl_create_st_framebuffer(struct hgl_display *display, struct st_visual* visual, void *winsysContext)
 {
        struct hgl_buffer *buffer;
        CALLED();
 
        // Our requires before creating a framebuffer
-       assert(context);
-       assert(context->display);
-       assert(context->stVisual);
+       assert(display);
+       assert(visual);
 
        buffer = CALLOC_STRUCT(hgl_buffer);
        assert(buffer);
 
        // Prepare our buffer
-       buffer->visual = context->stVisual;
-       buffer->screen = context->display->fscreen->screen;
+       buffer->visual = *visual;
+       buffer->screen = display->fscreen->screen;
        buffer->winsysContext = winsysContext;
 
        if (buffer->screen->get_param(buffer->screen, PIPE_CAP_NPOT_TEXTURES))
@@ -243,11 +240,11 @@ hgl_create_st_framebuffer(struct hgl_context* context, void *winsysContext)
        // Prepare our frontend interface
        buffer->base.flush_front = hgl_st_framebuffer_flush_front;
        buffer->base.validate = hgl_st_framebuffer_validate;
-       buffer->base.visual = context->stVisual;
+       buffer->base.visual = &buffer->visual;
 
        p_atomic_set(&buffer->base.stamp, 1);
        buffer->base.ID = p_atomic_inc_return(&hgl_fb_ID);
-       buffer->base.fscreen = context->display->fscreen;
+       buffer->base.fscreen = display->fscreen;
 
        return buffer;
 }
@@ -266,14 +263,61 @@ hgl_destroy_st_framebuffer(struct hgl_buffer *buffer)
 }
 
 
-struct st_visual*
-hgl_create_st_visual(ulong options)
+struct hgl_context*
+hgl_create_context(struct hgl_display *display, struct st_visual* visual, struct st_context* shared)
 {
-       struct st_visual* visual;
+       struct hgl_context* context = CALLOC_STRUCT(hgl_context);
+       assert(context);
+       context->display = display;
+
+       struct st_context_attribs attribs;
+       memset(&attribs, 0, sizeof(attribs));
+       attribs.options.force_glsl_extensions_warn = false;
+       attribs.profile = API_OPENGL_COMPAT;
+       attribs.visual = *visual;
+       attribs.major = 1;
+       attribs.minor = 0;
+
+       enum st_context_error result;
+       context->st = st_api_create_context(display->fscreen, &attribs, &result, shared);
+       if (context->st == NULL) {
+               FREE(context);
+               return NULL;
+       }
+
+       assert(!context->st->frontend_context);
+       context->st->frontend_context = (void*)context;
+
+       struct st_context *stContext = (struct st_context*)context->st;
+
+       // Init Gallium3D Post Processing
+       // TODO: no pp filters are enabled yet through postProcessEnable
+       context->postProcess = pp_init(stContext->pipe, context->postProcessEnable, stContext->cso_context, stContext, (void*)st_context_invalidate_state);
+
+       return context;
+}
+
+
+void
+hgl_destroy_context(struct hgl_context* context)
+{
+       if (context->st) {
+               st_context_flush(context->st, 0, NULL, NULL, NULL);
+               st_destroy_context(context->st);
+       }
 
+       if (context->postProcess)
+               pp_free(context->postProcess);
+
+       FREE(context);
+}
+
+
+void
+hgl_get_st_visual(struct st_visual* visual, ulong options)
+{
        CALLED();
 
-       visual = CALLOC_STRUCT(st_visual);
        assert(visual);
 
        // Determine color format
@@ -301,30 +345,19 @@ hgl_create_st_visual(ulong options)
                visual->buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK;
        }
 
-       #if 0
+#if 0
        if ((options & BGL_STEREO) != 0) {
                visual->buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK;
                if ((options & BGL_DOUBLE) != 0)
                        visual->buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK;
-    }
-       #endif
+  }
+#endif
 
        if ((options & BGL_DEPTH) || (options & BGL_STENCIL))
                visual->buffer_mask |= ST_ATTACHMENT_DEPTH_STENCIL_MASK;
 
        TRACE("%s: Visual color format: %s\n", __func__,
                util_format_name(visual->color_format));
-
-       return visual;
-}
-
-
-void
-hgl_destroy_st_visual(struct st_visual* visual)
-{
-       CALLED();
-
-       FREE(visual);
 }
 
 
index 1ac73e5..03e567a 100644 (file)
@@ -16,8 +16,6 @@
 
 #include "frontend/api.h"
 
-#include "bitmap_wrapper.h"
-
 
 #ifdef __cplusplus
 extern "C" {
@@ -32,10 +30,12 @@ typedef int64 context_id;
 struct hgl_buffer
 {
        struct pipe_frontend_drawable base;
-       struct st_visual* visual;
+       struct st_visual visual;
 
        unsigned width;
        unsigned height;
+       unsigned newWidth;
+       unsigned newHeight;
        unsigned mask;
 
        struct pipe_screen* screen;
@@ -43,8 +43,6 @@ struct hgl_buffer
 
        enum pipe_texture_target target;
        struct pipe_resource* textures[ST_ATTACHMENT_COUNT];
-
-       void *map;
 };
 
 
@@ -60,35 +58,21 @@ struct hgl_context
 {
        struct hgl_display* display;
        struct st_context* st;
-       struct st_visual* stVisual;
 
        // Post processing
        struct pp_queue_t* postProcess;
        unsigned int postProcessEnable[PP_FILTERS];
-
-       // Desired viewport size
-       unsigned width;
-       unsigned height;
-
-       mtx_t fbMutex;
-
-       struct hgl_buffer* buffer;
 };
 
-// hgl_buffer from statetracker interface
-struct hgl_buffer* hgl_st_framebuffer(struct pipe_frontend_drawable *drawable);
-
 // hgl framebuffer
-struct hgl_buffer* hgl_create_st_framebuffer(struct hgl_context* context, void *winsysContext);
+struct hgl_buffer* hgl_create_st_framebuffer(struct hgl_display *display, struct st_visual* visual, void *winsysContext);
 void hgl_destroy_st_framebuffer(struct hgl_buffer *buffer);
 
-// hgl manager
-struct pipe_frontend_screen* hgl_create_st_manager(struct hgl_context* screen);
-void hgl_destroy_st_manager(struct pipe_frontend_screen *fscreen);
+struct hgl_context* hgl_create_context(struct hgl_display *display, struct st_visual* visual, struct st_context* shared);
+void hgl_destroy_context(struct hgl_context* context);
 
 // hgl visual
-struct st_visual* hgl_create_st_visual(ulong options);
-void hgl_destroy_st_visual(struct st_visual* visual);
+void hgl_get_st_visual(struct st_visual* visual, ulong options);
 
 // hgl display
 struct hgl_display* hgl_create_display(struct pipe_screen* screen);
index c9a8fa2..3b6348d 100644 (file)
@@ -19,8 +19,6 @@
 # SOFTWARE.
 
 files_libsthgl = files(
-  'bitmap_wrapper.cpp',
-  'bitmap_wrapper.h',
   'hgl_context.h',
   'hgl.c',
 )
index 3c0dc4d..f0f772d 100644 (file)
@@ -132,6 +132,7 @@ hgl_winsys_displaytarget_create(struct sw_winsys* winsys,
                haikuDisplayTarget->data = NULL;
                haikuDisplayTarget->bitmap = new BBitmap(
                        BRect(0, 0, width - 1, height - 1),
+                       0,
                        haikuDisplayTarget->colorSpace,
                        haikuDisplayTarget->stride);
        } else {
@@ -217,8 +218,8 @@ hgl_winsys_displaytarget_display(struct sw_winsys* winsys,
        struct haiku_displaytarget* haikuDisplayTarget
                = hgl_sw_displaytarget(displayTarget);
 
-       HGLWinsysContext *context = (HGLWinsysContext*)contextPrivate;
-       context->Display(haikuDisplayTarget->bitmap, NULL);
+       BitmapHook *context = (BitmapHook*)contextPrivate;
+       context->SetBitmap(haikuDisplayTarget->bitmap);
 }
 
 
index d20c193..3628a8a 100644 (file)
 class BBitmap;
 class BRect;
 
-class HGLWinsysContext {
+class BitmapHook {
 public:
-       virtual void Display(BBitmap *bitmap, BRect *updateRect) = 0;
+       virtual ~BitmapHook() {};
+       virtual void GetSize(uint32_t &width, uint32_t &height) = 0;
+       virtual BBitmap *SetBitmap(BBitmap *bmp) = 0;
 };
 #endif
 
index b00c3d2..672f2a0 100644 (file)
@@ -25,6 +25,9 @@
 #define UTIL_MACROS_H
 
 #include <assert.h>
+#if defined(__HAIKU__)  && !defined(__cplusplus)
+#define static_assert _Static_assert
+#endif
 #include <stddef.h>
 #include <stdint.h>
 #include <stdio.h>
index 317c44f..c01d752 100644 (file)
 #include "util/detect_cc.h"
 #include "util/detect_arch.h"
 
+#ifdef __HAIKU__
+#include <sys/param.h>
+#undef ALIGN
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif