Reverted r44762 (removal of USB3.0 and HC driver separation work).
[AROS.git] / rom / graphics / graphics_init.c
blob452a72ab34f701656166852438be9d49fade340f
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics library
6 Lang: english
7 */
9 #define DEBUG 0
11 #include <aros/debug.h>
13 #include <exec/resident.h>
14 #include <proto/exec.h>
15 #include <aros/libcall.h>
16 #include <aros/symbolsets.h>
17 #include <hardware/intbits.h>
18 #include <dos/dos.h>
19 #include <exec/execbase.h>
20 #include <exec/memory.h>
21 #include <exec/lists.h>
22 #include <graphics/gfxbase.h>
23 #include <graphics/text.h>
24 #include <graphics/regions.h>
25 #include <proto/graphics.h>
26 #include <utility/utility.h>
28 #include "graphics_intern.h"
29 #include "default_font.h"
30 #include "fakegfxhidd.h"
32 #include LC_LIBDEFS_FILE
34 #include <stdio.h>
36 extern int driver_init (struct GfxBase *);
37 extern void driver_expunge (struct GfxBase *);
39 AROS_UFP4(ULONG, TOF_VBlank,
40 AROS_UFHA(ULONG, dummy, A0),
41 AROS_UFHA(void *, data, A1),
42 AROS_UFHA(ULONG, dummy2, A5),
43 AROS_UFHA(struct ExecBase *, SysBase, A6));
45 #ifndef SYSFONTNAME
46 # define SYSFONTNAME "topaz.font"
47 #endif
49 BOOL InitROMFont(struct GfxBase *);
51 static int GfxInit(struct GfxBase *LIBBASE)
53 OOPBase = (APTR)OpenLibrary("oop.library", 41);
54 if (OOPBase == NULL)
55 return FALSE;
57 HiddBitMapBase = OOP_GetMethodID(IID_Hidd_BitMap, 0);
58 HiddColorMapBase = OOP_GetMethodID(IID_Hidd_ColorMap, 0);
59 HiddGfxBase = OOP_GetMethodID(IID_Hidd_Gfx, 0);
60 HiddGCBase = OOP_GetMethodID(IID_Hidd_GC, 0);
61 HiddPlanarBMBase = OOP_GetMethodID(IID_Hidd_PlanarBM, 0);
63 UtilityBase = (APTR)OpenLibrary("utility.library", 0);
64 if (UtilityBase == NULL) {
65 CloseLibrary((APTR)OOPBase);
66 return FALSE;
69 NEWLIST(&LIBBASE->BlitWaitQ);
70 NEWLIST(&LIBBASE->TextFonts);
71 InitSemaphore( &PrivGBase(GfxBase)->hashtab_sema );
72 InitSemaphore( &PrivGBase(GfxBase)->view_sema );
73 InitSemaphore( &PrivGBase(GfxBase)->tfe_hashtab_sema );
74 InitSemaphore( &PrivGBase(GfxBase)->fontsem );
76 NEWLIST(&LIBBASE->MonitorList);
77 LIBBASE->MonitorList.lh_Type = MONITOR_SPEC_TYPE;
78 GfxBase->MonitorListSemaphore = &PrivGBase(GfxBase)->monitors_sema;
79 InitSemaphore(GfxBase->MonitorListSemaphore);
81 LIBBASE->hash_table = AllocMem(GFXASSOCIATE_HASHSIZE * sizeof(APTR), MEMF_CLEAR|MEMF_PUBLIC);
82 if (!LIBBASE->hash_table)
83 return FALSE;
85 LIBBASE->HashTableSemaphore = &PrivGBase(GfxBase)->hashtab_sema;
86 LIBBASE->ActiViewCprSemaphore = &PrivGBase(GfxBase)->view_sema;
88 #if REGIONS_USE_MEMPOOL
89 InitSemaphore( &PrivGBase(GfxBase)->regionsem );
90 if (!(PrivGBase(GfxBase)->regionpool = CreatePool(MEMF_PUBLIC | MEMF_CLEAR,
91 sizeof(struct Region) * 20,
92 sizeof(struct Region) * 20)))
94 return FALSE;
97 NEWLIST(&PrivGBase(GfxBase)->ChunkPoolList);
98 #endif
100 if (!InitROMFont(LIBBASE)) return FALSE;
102 return driver_init (LIBBASE);
105 static int GfxOpen(struct GfxBase *LIBBASE)
107 struct TextFont * def;
109 if (!LIBBASE->DefaultFont)
111 struct TextAttr sysTA;
112 sysTA.ta_Name = (STRPTR)SYSFONTNAME;
113 sysTA.ta_YSize = 8;
114 sysTA.ta_Style = FS_NORMAL;
115 sysTA.ta_Flags = 0;
117 def = OpenFont (&sysTA);
119 if (!def)
120 return 0;
122 LIBBASE->DefaultFont = def;
123 sysTA.ta_YSize = def->tf_YSize;
126 if(LIBBASE->LibNode.lib_OpenCnt == 0)
128 NEWLIST(&LIBBASE->TOF_WaitQ);
129 LIBBASE->vbsrv.is_Code = (APTR)TOF_VBlank;
130 LIBBASE->vbsrv.is_Data = LIBBASE;
131 LIBBASE->vbsrv.is_Node.ln_Name = "Graphics TOF server";
132 LIBBASE->vbsrv.is_Node.ln_Pri = 10;
133 LIBBASE->vbsrv.is_Node.ln_Type = NT_INTERRUPT;
135 /* Add a VBLANK server to take care of TOF waiting tasks. */
136 AddIntServer(INTB_VERTB, &LIBBASE->vbsrv);
139 if (!GfxBase->gb_LayersBase)
140 GfxBase->gb_LayersBase = (ULONG *)OpenLibrary("layers.library", 0);
142 return TRUE;
145 ADD2INITLIB(GfxInit, 0);
146 ADD2OPENLIB(GfxOpen, 0);
148 #undef SysBase
150 AROS_UFH4(ULONG, TOF_VBlank,
151 AROS_UFHA(ULONG, dummy, A0),
152 AROS_UFHA(void *, data, A1),
153 AROS_UFHA(ULONG, dummy2, A5),
154 AROS_UFHA(struct ExecBase *, SysBase, A6))
156 AROS_USERFUNC_INIT
158 struct Node *tNode;
159 struct GfxBase * GfxBase = (struct GfxBase *)data;
161 GfxBase->VBCounter++;
162 if(!IsListEmpty(&GfxBase->TOF_WaitQ))
164 ForeachNode(&GfxBase->TOF_WaitQ, tNode)
166 Signal((struct Task *)tNode->ln_Name, SIGF_SINGLE);
170 return 0;
172 AROS_USERFUNC_EXIT