Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / hidds / softpipe / softpipegalliumclass.c
blobe6d4c8a5033b790aa7c4f8b8612b1a25a8200151
1 /*
2 Copyright 2010, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <hidd/gallium.h>
7 #include <proto/oop.h>
8 #include <aros/debug.h>
10 #include <gallium/pipe/p_screen.h>
11 #include "softpipe/sp_texture.h"
12 #include "softpipe/sp_public.h"
13 #include "softpipe/sp_screen.h"
14 #include "util/u_format.h"
15 #include "util/u_math.h"
16 #include "state_tracker/sw_winsys.h"
18 #include "softpipe_intern.h"
20 #include <proto/cybergraphics.h>
21 #include <proto/graphics.h>
22 #include <cybergraphx/cybergraphics.h>
24 #if (AROS_BIG_ENDIAN == 1)
25 #define AROS_PIXFMT RECTFMT_RAW /* Big Endian Archs. */
26 #else
27 #define AROS_PIXFMT RECTFMT_BGRA32 /* Little Endian Archs. */
28 #endif
30 #define CyberGfxBase (&BASE(cl->UserData)->sd)->SoftpipeCyberGfxBase
32 #undef HiddGalliumAttrBase
33 #define HiddGalliumAttrBase (SD(cl)->hiddGalliumAB)
35 struct HiddSoftpipeWinSys
37 struct HIDDT_WinSys base;
38 struct sw_winsys swws;
41 /* Displaytarget support code */
42 struct HiddSoftpipeDisplaytarget
44 APTR data;
47 struct HiddSoftpipeDisplaytarget * HiddSoftpipeDisplaytarget(struct sw_displaytarget * dt)
49 return (struct HiddSoftpipeDisplaytarget *)dt;
52 static struct sw_displaytarget *
53 HiddSoftpipeCreateDisplaytarget(struct sw_winsys *winsys, unsigned tex_usage,
54 enum pipe_format format, unsigned width, unsigned height,
55 unsigned alignment, unsigned *stride)
57 struct HiddSoftpipeDisplaytarget * spdt =
58 AllocVec(sizeof(struct HiddSoftpipeDisplaytarget), MEMF_PUBLIC | MEMF_CLEAR);
60 *stride = align(util_format_get_stride(format, width), alignment);
61 spdt->data = AllocVec(*stride * height, MEMF_PUBLIC | MEMF_CLEAR);
63 return (struct sw_displaytarget *)spdt;
66 static void
67 HiddSoftpipeDestroyDisplaytarget(struct sw_winsys *ws, struct sw_displaytarget *dt)
69 struct HiddSoftpipeDisplaytarget * spdt = HiddSoftpipeDisplaytarget(dt);
71 if (spdt)
73 FreeVec(spdt->data);
74 FreeVec(spdt);
78 static void *
79 HiddSoftpipeMapDisplaytarget(struct sw_winsys *ws, struct sw_displaytarget *dt,
80 unsigned flags)
82 struct HiddSoftpipeDisplaytarget * spdt = HiddSoftpipeDisplaytarget(dt);
83 return spdt->data;
86 static void
87 HiddSoftpipeUnMapDisplaytarget(struct sw_winsys *ws, struct sw_displaytarget *dt)
89 /* No op */
92 /* Displaytarget support code ends */
94 static struct HiddSoftpipeWinSys *
95 HiddSoftpipeCreateSoftpipeWinSys(void)
97 struct HiddSoftpipeWinSys * ws = NULL;
99 ws = (struct HiddSoftpipeWinSys *)AllocVec
100 (sizeof(struct HiddSoftpipeWinSys), MEMF_PUBLIC|MEMF_CLEAR);
102 /* Fill in this struct with callbacks that pipe will need to
103 * communicate with the window system, buffer manager, etc.
106 /* Since Mesa 7.9 softpipe mo longer uses pipe_winsys - it uses sw_winsys */
107 ws->base.base.buffer_create = NULL;
108 ws->base.base.user_buffer_create = NULL;
109 ws->base.base.buffer_map = NULL;
110 ws->base.base.buffer_unmap = NULL;
111 ws->base.base.buffer_destroy = NULL;
112 ws->base.base.surface_buffer_create = NULL;
113 ws->base.base.fence_reference = NULL;
114 ws->base.base.fence_signalled = NULL;
115 ws->base.base.fence_finish = NULL;
116 ws->base.base.flush_frontbuffer = NULL;
117 ws->base.base.get_name = NULL;
118 ws->base.base.destroy = NULL;
120 /* Fill in with functions is displaytarget is ever used*/
121 ws->swws.destroy = NULL;
122 ws->swws.is_displaytarget_format_supported = NULL;
123 ws->swws.displaytarget_create = HiddSoftpipeCreateDisplaytarget;
124 ws->swws.displaytarget_from_handle = NULL;
125 ws->swws.displaytarget_get_handle = NULL;
126 ws->swws.displaytarget_map = HiddSoftpipeMapDisplaytarget;
127 ws->swws.displaytarget_unmap = HiddSoftpipeUnMapDisplaytarget;
128 ws->swws.displaytarget_display = NULL;
129 ws->swws.displaytarget_destroy = HiddSoftpipeDestroyDisplaytarget;
131 return ws;
134 OOP_Object *METHOD(SoftpipeGallium, Root, New)
136 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg) msg);
138 return o;
141 VOID METHOD(SoftpipeGallium, Root, Get)
143 ULONG idx;
145 if (IS_GALLIUM_ATTR(msg->attrID, idx))
147 switch (idx)
149 /* Overload the property */
150 case aoHidd_Gallium_GalliumInterfaceVersion:
151 *msg->storage = GALLIUM_INTERFACE_VERSION;
152 return;
156 /* Use parent class for all other properties */
157 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
160 APTR METHOD(SoftpipeGallium, Hidd_Gallium, CreatePipeScreen)
162 struct HiddSoftpipeWinSys * softpipews;
163 struct pipe_screen *screen;
165 softpipews = HiddSoftpipeCreateSoftpipeWinSys();
166 if (softpipews == NULL)
167 return NULL;
169 screen = softpipe_create_screen(&softpipews->swws);
170 if (screen == NULL)
171 goto fail;
173 /* Force a pipe_winsys pointer (Mesa 7.9 or never) */
174 screen->winsys = (struct pipe_winsys *)softpipews;
176 /* Preserve pointer to HIDD driver */
177 softpipews->base.driver = o;
179 return screen;
181 fail:
182 if (softpipews && softpipews->base.base.destroy)
183 softpipews->base.base.destroy((struct pipe_winsys *)softpipews);
185 return NULL;
188 VOID METHOD(SoftpipeGallium, Hidd_Gallium, DisplayResource)
190 struct softpipe_resource * spr = softpipe_resource(msg->resource);
191 struct sw_winsys * swws = softpipe_screen(spr->base.screen)->winsys;
192 struct RastPort * rp = CreateRastPort();
193 APTR * data = spr->data;
195 if ((data == NULL) && (spr->dt != NULL))
196 data = swws->displaytarget_map(swws, spr->dt, 0);
198 if (data)
200 rp->BitMap = msg->bitmap;
202 WritePixelArray(
203 data,
204 msg->srcx,
205 msg->srcy,
206 spr->stride[0],
207 rp,
208 msg->dstx,
209 msg->dsty,
210 msg->width,
211 msg->height,
212 AROS_PIXFMT);
215 if ((spr->data == NULL) && (data != NULL))
216 swws->displaytarget_unmap(swws, spr->dt);
218 FreeRastPort(rp);