Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / devs / monitors / IntelGMA / galliumclass.c
blob5bd9d5cdace58a1de4470125cb1370bb248696f8
1 /*
2 Copyright © 2011-2015, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 0
8 #include <aros/debug.h>
9 #include <aros/libcall.h>
10 #include <aros/asmcall.h>
11 #include <aros/symbolsets.h>
12 #include <utility/tagitem.h>
14 #include <proto/oop.h>
15 #include <proto/exec.h>
16 #include <proto/utility.h>
18 #include <hidd/gallium.h>
19 #include <proto/graphics.h>
21 #include "intelG45_intern.h"
22 #include "aros_winsys.h"
23 #include "gallium_intern.h"
24 #include "intelG45_regs.h"
26 #include "i915/i915_public.h"
27 #include "i915/i915_resource.h"
28 #include "util/u_memory.h"
29 #include "util/u_atomic.h"
30 #include "util/u_inlines.h"
31 #include "i915/i915_winsys.h"
32 #include "i915/i915_debug.h"
34 const struct OOP_InterfaceDescr Gallium_ifdescr[];
35 extern OOP_AttrBase MetaAttrBase;
36 OOP_AttrBase HiddGalliumAttrBase;
37 APTR i915MemPool;
39 extern ULONG allocated_mem;
40 extern struct g45staticdata sd;
41 #define sd ((struct g45staticdata*)&(sd))
43 struct Hidd915WinSys
45 struct HIDDT_WinSys base;
46 struct pipe_screen *pscreen;
49 static INLINE struct Hidd915WinSys *
50 Hidd915WinSys(struct pipe_winsys *ws)
52 return (struct Hidd915WinSys *)ws;
55 static VOID
56 HIDD915DestroyWinSys(struct pipe_winsys *ws)
58 struct Hidd915WinSys *hiddws = Hidd915WinSys(ws);
59 FREE(hiddws);
62 static VOID
63 HIDD915FlushFrontBuffer( struct pipe_screen *screen,
64 struct pipe_resource *resource,
65 unsigned level, unsigned layer,
66 void *winsys_drawable_handle )
68 /* No Op */
71 BOOL InitGalliumClass()
73 if( sd->force_gallium
74 || sd->ProductID == 0x2582 // GMA 900
75 || sd->ProductID == 0x2782
76 || sd->ProductID == 0x2592
77 || sd->ProductID == 0x2792
78 || sd->ProductID == 0x2772 // GMA 950
79 || sd->ProductID == 0x2776
80 || sd->ProductID == 0x27A2
81 || sd->ProductID == 0x27A6
82 || sd->ProductID == 0x27AE
83 || sd->ProductID == 0x2972 // GMA 3000
84 || sd->ProductID == 0x2973
85 || sd->ProductID == 0x2992
86 || sd->ProductID == 0x2993
88 CloseLibrary( OpenLibrary("gallium.library",0)); // ???
90 if((HiddGalliumAttrBase = OOP_ObtainAttrBase(IID_Hidd_Gallium)))
92 struct TagItem Gallium_tags[] =
94 {aMeta_SuperID , (IPTR)CLID_Hidd_Gallium },
95 {aMeta_InterfaceDescr, (IPTR)Gallium_ifdescr },
96 {aMeta_InstSize , sizeof(struct HIDDGalliumData)},
97 {aMeta_ID , (IPTR)CLID_Hidd_Gallium_IntelGMA},
98 {TAG_DONE, 0}
101 sd->basegallium = OOP_FindClass(CLID_Hidd_Gallium);
103 sd->galliumclass = OOP_NewObject(NULL, CLID_HiddMeta, Gallium_tags);
104 if (sd->galliumclass)
106 sd->galliumclass->UserData = sd;
107 OOP_AddClass(sd->galliumclass);
108 i915MemPool = CreatePool(MEMF_PUBLIC | MEMF_CLEAR | MEMF_SEM_PROTECTED, 32 * 1024, 16 * 1024);
110 init_aros_winsys();
111 bug("i915 gallium init OK\n");
112 return TRUE;
115 OOP_ReleaseAttrBase(IID_Hidd_Gallium);
119 return FALSE;
123 /* PUBLIC METHODS */
124 OOP_Object *METHOD(i915Gallium, Root, New)
126 D(bug("[i915gallium] New\n"));
127 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg) msg);
128 if(o)
133 return o;
137 VOID METHOD(i915Gallium, Root, Get)
139 ULONG idx;
140 D(bug("[i915gallium] get\n"));
141 if (IS_GALLIUM_ATTR(msg->attrID, idx))
143 switch (idx)
145 /* Overload the property */
146 case aoHidd_Gallium_GalliumInterfaceVersion:
147 *msg->storage = GALLIUM_INTERFACE_VERSION;
148 return;
152 /* Use parent class for all other properties */
153 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
156 APTR METHOD(i915Gallium, Hidd_Gallium, CreatePipeScreen)
159 bug("[i915gallium] CreatePipeScreen currently allocated_mem %d\n",allocated_mem);
161 struct Hidd915WinSys *hiddws;
162 struct aros_winsys *aws;
163 struct pipe_winsys *ws;
165 aws = winsys_create();
167 if (!aws) {
168 return NULL;
171 hiddws = CALLOC_STRUCT(Hidd915WinSys);
172 if (!hiddws) {
173 return NULL;
176 ws = &hiddws->base.base;
177 ws->destroy = HIDD915DestroyWinSys;
179 hiddws->pscreen = i915_screen_create( &aws->base );
180 if (!hiddws->pscreen) {
181 ws->destroy(ws);
182 return NULL;
185 hiddws->pscreen->flush_frontbuffer = HIDD915FlushFrontBuffer;
186 hiddws->pscreen->winsys = (struct pipe_winsys*)hiddws;
187 /* Preserve pointer to HIDD driver */
188 hiddws->base.driver = o;
190 return hiddws->pscreen;
194 VOID METHOD(i915Gallium, Hidd_Gallium, DisplayResource)
196 // bug("[i915gallium] DisplayResource\n");
198 #ifndef GALLIUM_SIMULATION
199 OOP_Object *bm = HIDD_BM_OBJ(msg->bitmap);
200 GMABitMap_t *bm_dst;
202 // if (!((IPTR)bm == (IPTR)sd.BMClass) ) return; // Check if bitmap is really intelGFX bitmap
204 bm_dst = OOP_INST_DATA(OOP_OCLASS(bm), bm);
205 struct i915_texture *tex = i915_texture(msg->resource);
207 IF_BAD_MAGIC(tex->buffer) return;
209 LOCK_BITMAP_BM(bm_dst)
211 uint32_t br00, br13, br22, br23, br09, br11, br26, br12;
212 int mode = 3;
214 br00 = (2 << 29) | (0x53 << 22) | (6);
215 if (bm_dst->bpp == 4)
216 br00 |= 3 << 20;
218 br13 = bm_dst->pitch | ROP_table[mode].rop;
219 if (bm_dst->bpp == 4)
220 br13 |= 3 << 24;
221 else if (bm_dst->bpp == 2)
222 br13 |= 1 << 24;
224 br22 = msg->dstx | (msg->dsty << 16);
225 br23 = (msg->dstx + msg->width) | (msg->dsty + msg->height) << 16;
226 br09 = bm_dst->framebuffer;
228 br11 = tex->stride;
229 br26 = msg->srcx | (msg->srcy << 16);
230 br12 = (IPTR)tex->buffer->map - (IPTR)sd->Card.Framebuffer;
232 while(buffer_is_busy(0,tex->buffer)){};
234 LOCK_HW
235 START_RING(8);
236 OUT_RING(br00);
237 OUT_RING(br13);
238 OUT_RING(br22);
239 OUT_RING(br23);
240 OUT_RING(br09);
241 OUT_RING(br26);
242 OUT_RING(br11);
243 OUT_RING(br12);
244 ADVANCE_RING();
245 //DO_FLUSH();
246 UNLOCK_HW
247 UNLOCK_BITMAP_BM(bm_dst)
248 #endif
249 destroy_unused_buffers();
253 static const struct OOP_MethodDescr Gallium_Root_descr[] =
255 {(OOP_MethodFunc)i915Gallium__Root__New, moRoot_New},
256 {(OOP_MethodFunc)i915Gallium__Root__Get, moRoot_Get},
257 {NULL, 0}
260 static const struct OOP_MethodDescr Gallium_Hidd_Gallium_descr[] =
262 {(OOP_MethodFunc)i915Gallium__Hidd_Gallium__CreatePipeScreen, moHidd_Gallium_CreatePipeScreen},
263 {(OOP_MethodFunc)i915Gallium__Hidd_Gallium__DisplayResource, moHidd_Gallium_DisplayResource},
264 {NULL, 0}
267 const struct OOP_InterfaceDescr Gallium_ifdescr[] =
269 {(struct OOP_MethodDescr*)Gallium_Root_descr, IID_Root, 2},
270 {(struct OOP_MethodDescr*)Gallium_Hidd_Gallium_descr, IID_Hidd_Gallium, 2},
271 {NULL, NULL,0}