Belarusian
[AROS.git] / rom / graphics / openmonitor.c
blob2db48f02396d8bf4c868ad6d0d53366ea139faca
1 /*
2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics function OpenMonitor()
6 Lang: english
7 */
9 #include <aros/atomic.h>
10 #include <aros/debug.h>
11 #include <graphics/monitor.h>
12 #include <proto/oop.h>
14 #include "graphics_intern.h"
15 #include "dispinfo.h"
17 /*****************************************************************************
19 NAME */
20 #include <proto/graphics.h>
22 AROS_LH2(struct MonitorSpec *, OpenMonitor,
24 /* SYNOPSIS */
25 AROS_LHA(STRPTR, monitor_name, A1),
26 AROS_LHA(ULONG, display_id, D0),
28 /* LOCATION */
29 struct GfxBase *, GfxBase, 119, Graphics)
31 /* FUNCTION
33 INPUTS
34 monitor_name - pointer to a null terminated string
35 display_id - optional 32 bit monitor/mode identifier
37 RESULT
38 mspc - pointer to an open MonitorSpec structure
39 NULL if MonitorSpec could not be opened
41 NOTES
43 EXAMPLE
45 BUGS
47 SEE ALSO
48 CloseMonitor(), graphics/monitor.h
50 INTERNALS
51 Currently display_id parameter is ignored because all display modes
52 are served by the same driver (which is the defailt one).
53 In future this will change.
55 HISTORY
58 ******************************************************************************/
60 AROS_LIBFUNC_INIT
62 struct MonitorSpec *mspc = NULL;
64 D(bug("[GFX] OpenMonitor(%s)\n", monitor_name));
66 if (monitor_name) {
67 if (stricmp(monitor_name, DEFAULT_MONITOR_NAME)) {
68 ObtainSemaphoreShared(GfxBase->MonitorListSemaphore);
70 /* TODO: use FindName() here, however this is possible only after switch to
71 ABI v1 (because otherwise struct Node and struct ExtendedNode have different layout */
72 for (mspc = (struct MonitorSpec *)GfxBase->MonitorList.lh_Head; mspc->ms_Node.xln_Succ; mspc = (struct MonitorSpec *)mspc->ms_Node.xln_Succ) {
73 if (!strcmp(monitor_name, mspc->ms_Node.xln_Name)) {
74 D(bug("[OpenMonitor] Found spec 0x%p\n", mspc));
75 break;
79 ReleaseSemaphore(GfxBase->MonitorListSemaphore);
81 if (!mspc->ms_Node.xln_Succ) {
82 D(bug("[OpenMonitor] Monitor not found\n"));
83 return NULL;
85 } else
86 mspc = GfxBase->default_monitor;
87 } else if (display_id != INVALID_ID) {
88 struct MonitorInfo info;
90 if (GetDisplayInfoData(NULL, (UBYTE *)&info, sizeof(info), DTAG_MNTR, display_id) >= offsetof(struct MonitorInfo, ViewPosition))
91 mspc = info.Mspc;
92 } else
93 mspc = GfxBase->default_monitor;
95 if (mspc)
96 AROS_ATOMIC_INC(mspc->ms_OpenCount);
98 return mspc;
100 AROS_LIBFUNC_EXIT
101 } /* OpenMonitor */