add necessary tasklist spinlocks
[AROS.git] / rom / intuition / rethinkdisplay.c
blobe2dc7ac282620c5fe93786f8243070798b8d3742
1 /*
2 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
3 Copyright © 2001-2003, The MorphOS Development Team. All Rights Reserved.
4 $Id$
5 */
7 #include <intuition/pointerclass.h>
8 #include <proto/graphics.h>
10 #include "intuition_intern.h"
11 #include "inputhandler.h"
12 #include "monitorclass_private.h"
14 /*****************************************************************************
16 NAME */
17 #include <proto/intuition.h>
19 AROS_LH0(LONG, RethinkDisplay,
21 /* SYNOPSIS */
23 /* LOCATION */
24 struct IntuitionBase *, IntuitionBase, 65, Intuition)
26 /* FUNCTION
27 Check and update, i.e. redisplay the whole Intuition display.
29 INPUTS
30 None.
32 RESULT
33 Zero for success, non-zero for failure.
35 NOTES
37 EXAMPLE
39 BUGS
41 SEE ALSO
42 RemakeDisplay(), MakeScreen(), graphics.library/MakeVPort(),
43 graphics.library/MrgCop(), graphics.library/LoadView()
45 INTERNALS
47 *****************************************************************************/
49 AROS_LIBFUNC_INIT
51 struct RethinkDisplayActionMsg msg;
53 msg.lock = TRUE;
54 DoSyncAction((APTR)int_RethinkDisplay, &msg.msg, IntuitionBase);
56 return msg.failure;
58 AROS_LIBFUNC_EXIT
59 } /* RethinkDisplay */
62 void int_RethinkDisplay(struct RethinkDisplayActionMsg *msg,struct IntuitionBase *IntuitionBase)
64 struct GfxBase *GfxBase = GetPrivIBase(IntuitionBase)->GfxBase;
65 struct Screen *screen;
66 struct ViewPort *viewport;
67 struct ViewPort **viewportptr;
68 UWORD modes;
69 LONG failure = 0;
70 ULONG ilock = 0;
72 if (msg->lock)
73 ilock = LockIBase(0);
75 screen = IntuitionBase->FirstScreen;
77 DEBUG_RETHINKDISPLAY(dprintf("RethinkDisplay: screen 0x%lx\n",screen));
79 if (screen == NULL)
81 DEBUG_RETHINKDISPLAY(dprintf("RethinkDisplay: LoadView(NULL)\n"));
82 IntuitionBase->ViewLord.ViewPort = NULL;
83 LoadView(NULL);
85 else
87 /* Find visible screens */
88 DEBUG_RETHINKDISPLAY(dprintf("RethinkDisplay: Find visible screens\n"));
90 screen->ViewPort.Modes |= SPRITES;
91 screen->ViewPort.Modes &= ~VP_HIDE;
93 /* Not needed. Perhaps... Pavel Fedin <pavel_fedin@mail.ru>
94 if (!(GetPrivScreen(screen)->SpecialFlags & SF_Compose)) {
95 while ((screen = screen->NextScreen))
96 screen->ViewPort.Modes |= VP_HIDE;
99 /* Build the list of viewports in the view */
100 DEBUG_RETHINKDISPLAY(dprintf("RethinkDisplay: Building viewports list\n"));
101 viewportptr = &IntuitionBase->ViewLord.ViewPort;
102 for (screen = IntuitionBase->FirstScreen; screen; screen = screen->NextScreen)
104 GetPrivScreen(screen)->GammaControl.Active = FALSE;
106 if ((screen->ViewPort.Modes & VP_HIDE) == 0)
108 DEBUG_RETHINKDISPLAY(bug("RethinkDisplay: Adding ViewPort 0x%p for screen 0x%p\n", &screen->ViewPort, screen));
109 *viewportptr = &screen->ViewPort;
110 viewportptr = &screen->ViewPort.Next;
113 *viewportptr = NULL;
115 /* Find view mode */
116 DEBUG_RETHINKDISPLAY(dprintf("RethinkDisplay: Find view mode\n"));
117 modes = (IntuitionBase->ViewLord.Modes & ~LACE) | SPRITES;
118 for (viewport = IntuitionBase->ViewLord.ViewPort; viewport; viewport = viewport->Next) {
119 modes |= viewport->Modes & LACE;
122 /* Reinitialize the view */
123 IntuitionBase->ViewLord.DxOffset = 0; /***/
124 IntuitionBase->ViewLord.DyOffset = 0; /***/
125 IntuitionBase->ViewLord.Modes = modes;
126 screen = IntuitionBase->FirstScreen;
127 #ifdef __MORPHOS__
128 GetPrivIBase(IntuitionBase)->ViewLordExtra->Monitor = GetPrivScreen(screen)->Monitor;
129 #endif
130 /* Rebuild copper lists for screens needing a mode change */
132 DEBUG_RETHINKDISPLAY(dprintf("RethinkDisplay: Making viewports\n"));
133 for (viewport = IntuitionBase->ViewLord.ViewPort; viewport; viewport = viewport->Next)
135 if ((viewport->Modes ^ modes) & LACE)
137 LONG error;
139 viewport->Modes = (viewport->Modes & ~LACE) | (modes & LACE);
140 error = MakeVPort(&IntuitionBase->ViewLord, viewport);
142 if (error)
143 failure = error;
147 if (!failure)
149 failure = MrgCop(&IntuitionBase->ViewLord);
151 if (!failure)
153 struct MinNode *m;
155 DEBUG_RETHINKDISPLAY(dprintf("RethinkDisplay: LoadView ViewLord 0x%lx\n",&IntuitionBase->ViewLord));
157 ObtainSemaphore(&GetPrivIBase(IntuitionBase)->ViewLordLock);
158 LoadView(&IntuitionBase->ViewLord);
161 * Set gamma correction for all displays.
162 * We do it after LoadView() because some video chipsets reuse the
163 * same registers for both LUT palette and gamma table. Consequently,
164 * we may need to reload gamma table after the mode has been changed.
166 ObtainSemaphoreShared(&GetPrivIBase(IntuitionBase)->MonitorListSem);
168 for (m = GetPrivIBase(IntuitionBase)->MonitorList.mlh_Head;
169 m->mln_Succ; m = m->mln_Succ)
171 screen = FindFirstScreen((Object *)m, IntuitionBase);
173 if (screen)
175 GetPrivScreen(screen)->GammaControl.Active = TRUE;
176 DoMethod((Object *)m, MM_SetScreenGamma, &GetPrivScreen(screen)->GammaControl, TRUE);
180 ReleaseSemaphore(&GetPrivIBase(IntuitionBase)->MonitorListSem);
181 ReleaseSemaphore(&GetPrivIBase(IntuitionBase)->ViewLordLock);
183 DEBUG_INIT(dprintf("RethinkDisplay: ActiveScreen %p Pointer %p Sprite %p\n",
184 IntuitionBase->ActiveScreen,
185 GetPrivScreen(IntuitionBase->ActiveScreen)->Pointer,
186 GetPrivScreen(IntuitionBase->ActiveScreen)->Pointer->sprite));
191 if (!failure)
193 /* validate screen positions, scrolling limits are not necessarily same anymore. */
194 for (screen = IntuitionBase->FirstScreen; screen; screen = screen->NextScreen)
196 if ((screen->ViewPort.Modes & VP_HIDE) == 0)
198 ScreenPosition( screen, SPOS_RELATIVE, 0,0,0,0 );
201 /* Ensure that empty displays get normal pointer */
202 ResetPointer(IntuitionBase);
205 if (msg->lock)
206 UnlockIBase(ilock);
208 DEBUG_RETHINKDISPLAY(dprintf("RethinkDisplay: failure 0x%lx\n",failure));
210 msg->failure = failure;