Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / hidds / nouveau / nouveaugalliumclass.c
blob1e86d8712fc6c8b9238d75b3ecdf3740217b4ba3
1 /*
2 Copyright 2010-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "nouveau_intern.h"
8 #include <aros/debug.h>
9 #include <proto/oop.h>
11 #include "util/u_memory.h"
12 #include "util/u_inlines.h"
13 #include "nouveau/nouveau_winsys.h"
14 #include "nv50/nv50_resource.h"
15 #include "nvfx/nvfx_resource.h"
16 #include "nvc0/nvc0_resource.h"
18 #undef HiddGalliumAttrBase
19 #define HiddGalliumAttrBase (SD(cl)->galliumAttrBase)
21 struct HiddNouveauWinSys
23 struct HIDDT_WinSys base;
24 struct pipe_screen *pscreen;
27 static INLINE struct HiddNouveauWinSys *
28 HiddNouveauWinSys(struct pipe_winsys *ws)
30 return (struct HiddNouveauWinSys *)ws;
33 static VOID
34 HIDDNouveauFlushFrontBuffer( struct pipe_screen *screen,
35 struct pipe_resource *resource,
36 unsigned level, unsigned layer,
37 void *winsys_drawable_handle )
39 /* No Op */
42 static VOID
43 HIDDNouveauDestroyWinSys(struct pipe_winsys *ws)
45 struct HiddNouveauWinSys *nvws = HiddNouveauWinSys(ws);
47 FREE(nvws);
50 /* Wraps the nouveau_bo from resource into 2D bitmap class data */
51 static BOOL
52 HIDDNouveauWrapResource(struct CardData * carddata, struct pipe_resource * resource,
53 struct HIDDNouveauBitMapData * bmdata)
55 struct nouveau_bo * bo = NULL;
56 ULONG pitch = 0; ULONG depth = 0;
58 /* Get buffer object and pitch */
59 switch(carddata->architecture)
61 case NV_ARCH_30:
62 case NV_ARCH_40:
63 bo = nvfx_resource(resource)->bo;
64 pitch = ((struct nvfx_miptree *)resource)->linear_pitch;
65 break;
66 case NV_ARCH_50:
67 bo = nv50_miptree(resource)->base.bo;
68 pitch = nv50_miptree(resource)->level[0].pitch;
69 break;
70 case NV_ARCH_C0:
71 bo = nvc0_miptree(resource)->base.bo;
72 pitch = nvc0_miptree(resource)->level[0].pitch;
73 break;
76 if ((bo == NULL) || (pitch == 0))
77 return FALSE;
79 switch(resource->format)
81 case PIPE_FORMAT_B8G8R8A8_UNORM:
82 case PIPE_FORMAT_A8R8G8B8_UNORM:
83 /* For purpose of blitting render buffer to screen, 32-bit render
84 buffer is treated as 24-bit surface. This is needed so that checks
85 (src->depth == dst->depth) pass. */
86 case PIPE_FORMAT_B8G8R8X8_UNORM:
87 case PIPE_FORMAT_X8R8G8B8_UNORM:
88 depth = 24;
89 break;
90 case PIPE_FORMAT_B5G5R5A1_UNORM:
91 case PIPE_FORMAT_B4G4R4A4_UNORM:
92 case PIPE_FORMAT_B5G6R5_UNORM:
93 depth = 16;
94 break;
95 default:
96 depth = 0;
97 break;
100 if (depth == 0)
101 return FALSE;
103 /* Set all fields */
104 bmdata->bo = bo;
105 bmdata->width = resource->width0;
106 bmdata->height = resource->height0;
107 bmdata->depth = depth;
108 if (bmdata->depth == 16)
109 bmdata->bytesperpixel = 2;
110 else
111 bmdata->bytesperpixel = 4;
112 bmdata->pitch = pitch;
113 bmdata->fbid = 0; /* Default value */
114 InitSemaphore(&bmdata->semaphore);
116 return TRUE;
120 /* METHODS */
121 OOP_Object *METHOD(NouveauGallium, Root, New)
123 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg) msg);
125 if(o)
127 /* Check if chipset support hardware 3D via gallium */
128 if ((SD(cl)->carddata.dev == NULL) || (SD(cl)->carddata.dev->chipset < 0x30))
130 OOP_MethodID dispose_mid;
131 dispose_mid = OOP_GetMethodID(IID_Root, moRoot_Dispose);
132 OOP_CoerceMethod(cl, o, (OOP_Msg) & dispose_mid);
133 o = NULL;
137 return o;
140 VOID METHOD(NouveauGallium, Root, Get)
142 ULONG idx;
144 if (IS_GALLIUM_ATTR(msg->attrID, idx))
146 switch (idx)
148 /* Overload the property */
149 case aoHidd_Gallium_GalliumInterfaceVersion:
150 *msg->storage = GALLIUM_INTERFACE_VERSION;
151 return;
155 /* Use parent class for all other properties */
156 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
159 APTR METHOD(NouveauGallium, Hidd_Gallium, CreatePipeScreen)
161 struct HiddNouveauWinSys *nvws;
162 struct pipe_winsys *ws;
163 struct nouveau_device *dev = SD(cl)->carddata.dev;
164 struct pipe_screen *(*init)(struct pipe_winsys *,
165 struct nouveau_device *);
167 switch (dev->chipset & 0xf0)
169 case 0x30:
170 case 0x40:
171 case 0x60:
172 init = nvfx_screen_create;
173 break;
174 case 0x50:
175 case 0x80:
176 case 0x90:
177 case 0xa0:
178 init = nv50_screen_create;
179 break;
180 case 0xc0:
181 init = nvc0_screen_create;
182 break;
183 default:
184 D(bug("%s: unknown chipset nv%02x\n", __func__,
185 dev->chipset));
186 return NULL;
190 nvws = CALLOC_STRUCT(HiddNouveauWinSys);
191 if (!nvws) {
192 return NULL;
194 ws = &nvws->base.base;
195 ws->destroy = HIDDNouveauDestroyWinSys;
197 nvws->pscreen = init(ws, dev);
198 if (!nvws->pscreen) {
199 ws->destroy(ws);
200 return NULL;
203 nvws->pscreen->flush_frontbuffer = HIDDNouveauFlushFrontBuffer;
205 /* Preserve pointer to HIDD driver */
206 nvws->base.driver = o;
208 return nvws->pscreen;
211 VOID METHOD(NouveauGallium, Hidd_Gallium, DisplayResource)
213 struct CardData * carddata = &(SD(cl)->carddata);
214 struct HIDDNouveauBitMapData srcdata;
215 OOP_Object * bm = HIDD_BM_OBJ(msg->bitmap);
216 struct HIDDNouveauBitMapData * dstdata;
218 if (!IS_NOUVEAU_BM_CLASS(OOP_OCLASS(bm))) /* Check if bitmap is really nouveau bitmap */
219 return;
221 dstdata = OOP_INST_DATA(OOP_OCLASS(bm), bm);
223 if (!HIDDNouveauWrapResource(carddata, msg->resource, &srcdata))
224 return;
226 /* srcdata does not require a lock, because it's a local object that is
227 access only by one task at a time */
228 LOCK_BITMAP_BM(dstdata)
229 /* XXX HACK XXX */
230 /* HACK: there seems to something wrong with blitting method. Without this
231 mapping, the blitting is jittering with high frame frames. Probably some
232 flush is missing somewhere and doing a mapping executes this missing flush
234 MAP_BUFFER_BM(dstdata)
235 /* XXX HACK XXX */
236 UNMAP_BUFFER_BM(dstdata)
238 switch(carddata->architecture)
240 case NV_ARCH_30:
241 case NV_ARCH_40:
242 HIDDNouveauNV04CopySameFormat(carddata, &srcdata, dstdata,
243 msg->srcx, msg->srcy, msg->dstx, msg->dsty, msg->width, msg->height,
244 0x03 /* vHidd_GC_DrawMode_Copy */);
245 break;
246 case NV_ARCH_50:
247 HIDDNouveauNV50CopySameFormat(carddata, &srcdata, dstdata,
248 msg->srcx, msg->srcy, msg->dstx, msg->dsty, msg->width, msg->height,
249 0x03 /* vHidd_GC_DrawMode_Copy */);
250 break;
251 case NV_ARCH_C0:
252 HIDDNouveauNVC0CopySameFormat(carddata, &srcdata, dstdata,
253 msg->srcx, msg->srcy, msg->dstx, msg->dsty, msg->width, msg->height,
254 0x03 /* vHidd_GC_DrawMode_Copy */);
255 default:
256 /* TODO: Report error */
257 break;
261 UNLOCK_BITMAP_BM(dstdata)