1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
/*
PsychSourceGL/Source/Common/Screen/SCREENClose.c
AUTHORS:
Allen.Ingling@nyu.edu awi
mario.kleiner at tuebingen.mpg.de mk
PLATFORMS:
All.
HISTORY:
07/26/02 awi Created from OpenWindow
01/30/05 mk Closes/Deletes all textures, if no windowOrTextureIndex provided. "CloseAllTextures" - Functionality.
01/18/08 mk Closes/Deletes all textures or offscreen windows if a vector of handles is passed.
DESCRIPTION:
Close named onscreen windows, offscreen windows, proxy windows or textures.
Batch close all offscreen windows, proxies and textures with a single convenience call on request.
TO DO:
*/
#include "Screen.h"
// If you change the useString then also change the corresponding synopsis string in ScreenSynopsis.c
static char useString[] = "Screen('Close', [windowOrTextureIndex or list of textureIndices/offscreenWindowIndices]);";
static char synopsisString[] =
"Close an onscreen or offscreen window or a texture. If the optional windowOrTextureIndex isn't "
"provided, then all textures and offscreen windows are closed/deleted while regular onscreen "
"windows are left open. If you want to close a subset of your offscreen windows or textures, but "
"not all of them you can also pass in a vector of texture/offscreen window handles and all handles "
"in the vector will be closed. ";
static char seeAlsoString[] = "OpenWindow, OpenOffscreenWindow";
PsychError SCREENClose(void)
{
PsychWindowRecordType *windowRecord;
int screenNumber;
PsychWindowRecordType **windowRecordArray;
int i, numWindows;
int *winHandles;
windowRecord=NULL;
//all subfunctions should have these two lines.
PsychPushHelp(useString, synopsisString, seeAlsoString);
if(PsychIsGiveHelp()){PsychGiveHelp();return(PsychError_none);};
PsychErrorExit(PsychCapNumInputArgs(1)); //The maximum number of inputs
PsychErrorExit(PsychRequireNumInputArgs(0)); //The minimum required number of inputs
PsychErrorExit(PsychCapNumOutputArgs(0)); //The maximum number of outputs
// First try to alloc in a whole list of handles:
winHandles = NULL;
numWindows = 0;
PsychAllocInIntegerListArg(1, FALSE, &numWindows, &winHandles);
// None, One or many handles?
if (winHandles && (numWindows > 1)) {
// Multiple window handles provided: Iterate over them and close them all:
for(i=0; i < numWindows; i++) {
// Iterate over all handles, ignore all but texture/offscreen window handles:
if (IsWindowIndex(winHandles[i]) && (PsychError_none == FindWindowRecord(winHandles[i], &windowRecord)) &&
(windowRecord->windowType == kPsychTexture)) {
// Ok its a texture or offscreen window - We close it:
PsychCloseWindow(windowRecord);
}
}
return(PsychError_none);
}
// Either none or exactly one window handle provided...
// Try to get the window record or exit with an error if the windex was bogus.
PsychAllocInWindowRecordArg(kPsychUseDefaultArgPosition, kPsychArgOptional, &windowRecord);
// Window handle of a specific window provided?
if (windowRecord==NULL) {
// No window handle provided: In this case, we close/destroy all textures:
PsychCreateVolatileWindowRecordPointerList(&numWindows, &windowRecordArray);
for(i=0;i<numWindows;i++) {
if ((windowRecordArray[i]->windowType == kPsychTexture) && !(windowRecordArray[i]->specialflags & kPsychDontDeleteOnClose)) PsychCloseWindow(windowRecordArray[i]);
}
PsychDestroyVolatileWindowRecordPointerList(windowRecordArray);
return(PsychError_none);
}
// Window handle of a specific window or texture provided: Close it...
if (PsychIsLastOnscreenWindow(windowRecord)) {
// Do Screen('CloseAll') style cleanup to release and cleanup everything:
ScreenCloseAllWindows();
}
else {
// Not the last onscreen window. Be more specific in cleanup:
if (PsychIsOnscreenWindow(windowRecord)) {
screenNumber = windowRecord->screenNumber;
PsychCloseWindow(windowRecord);
// Are there more onscreen windows associated with the screen of our just
// closed onscreen window?
PsychCreateVolatileWindowRecordPointerList(&numWindows, &windowRecordArray);
for(i = 0; i < numWindows; i++) {
if (PsychIsOnscreenWindow(windowRecordArray[i]) && (windowRecordArray[i]->screenNumber == screenNumber))
screenNumber = -1;
}
PsychDestroyVolatileWindowRecordPointerList(windowRecordArray);
// Was our window the last one on its screen screenNumber?
if (screenNumber != -1) {
// Yes. This screen is done. Finish it up:
if(PsychIsScreenCaptured(screenNumber)) {
PsychRestoreScreenSettings(screenNumber);
PsychReleaseScreen(screenNumber);
}
}
}
else {
PsychCloseWindow(windowRecord);
}
}
return(PsychError_none);
}
|