File: WindowHelpers.c

package info (click to toggle)
psychtoolbox-3 3.0.19.14.dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 86,796 kB
  • sloc: ansic: 176,245; cpp: 20,103; objc: 5,393; sh: 2,753; python: 1,397; php: 384; makefile: 193; java: 113
file content (107 lines) | stat: -rw-r--r-- 3,403 bytes parent folder | download | duplicates (5)
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
/*
  PsychToolbox3/Source/Common/WindowHelpers.c

  AUTHORS:
  Allen.Ingling@nyu.edu     awi

  PLATFORMS: This file is included for all targets.

  PROJECTS:
  12/20/02      awi     Screen

  HISTORY:
  12/20/02      awi     Wrote it.
  04/22/05      mk      Bugfix for PsychCheckIfWindowRecordIsValid: Screen('Close', w); Screen('Close', w) caused crash due to NULL-Ptr deref.

  DESCRIPTION:

  Convenience functions for extracting properties of windows from a window index or from a window record pointer.
  Sometimes doing that is a hassle because the properties of the window are actually properties of the associeate screen
  structure, hence we provide these conveience functions.

*/

#include "Screen.h"

void PsychGetRectFromWindowRecord(double *rect, PsychWindowRecordType *windowRecord)
{
    PsychCopyRect(rect, windowRecord->clientrect);
}

int PsychGetNumPlanesFromWindowRecord(PsychWindowRecordType *windowRecord)
{
    return(windowRecord->nrchannels);
}

int PsychGetNumBuffersFromWindowRecord(PsychWindowRecordType *windowRecord)
{
        if(windowRecord->windowType==kPsychSingleBufferOnscreen)
            return(1);
        else if(windowRecord->windowType==kPsychDoubleBufferOnscreen)
            return(2);
        else if(windowRecord->windowType==kPsychVideoMemoryOffscreen)
            return(1);
        else if(windowRecord->windowType==kPsychSystemMemoryOffscreen)
            return(1);
        else{
            PsychErrorExitMsg(PsychError_internal, "illegitimate buffer type");
            return(0); //make the compiler happy
        }
}

void PsychSetWindowRecordValid(PsychWindowRecordType *winRec)
{
    winRec->isValid=TRUE;
}

void PsychCheckIfWindowRecordIsValid(PsychWindowRecordType *winRec)
{
    // MK: Added check for winRec==NULL.
    if(winRec==NULL || !winRec->isValid)
        PsychErrorExit(PsychError_InvalidWindowRecord);
}

psych_bool PsychIsOnscreenWindow(PsychWindowRecordType *windowRecord)
{
    return(windowRecord->windowType==kPsychSingleBufferOnscreen || windowRecord->windowType==kPsychDoubleBufferOnscreen);
}

/*
    PsychIsMatlabOnscreenWindow()

    stand-in for actual detection; No window records will are Matlab windows until we provide a way to 
    grab those, therefore return FALSE.
*/
psych_bool PsychIsMatlabOnscreenWindow(PsychWindowRecordType *windowRecord)
{
    (void) windowRecord;
    return(FALSE);
}

psych_bool PsychIsOffscreenWindow(PsychWindowRecordType *windowRecord)
{
    return(windowRecord->windowType==kPsychVideoMemoryOffscreen || windowRecord->windowType==kPsychSystemMemoryOffscreen ||
           windowRecord->windowType==kPsychTexture);
}

psych_bool PsychIsTexture(PsychWindowRecordType *windowRecord)
{
    return(windowRecord->windowType==kPsychTexture);
}

void PsychSetTextColorInWindowRecord(PsychColorType *textColor,  PsychWindowRecordType *winRec)
{
    memcpy(&(winRec->textAttributes.textColor), textColor, sizeof(PsychColorType));
    PsychCoerceColorMode(&(winRec->textAttributes.textColor));
}

void PsychSetTextBackgroundColorInWindowRecord(PsychColorType *textBackgroundColor,  PsychWindowRecordType *winRec)
{
    memcpy(&(winRec->textAttributes.textBackgroundColor), textBackgroundColor, sizeof(PsychColorType));
    PsychCoerceColorMode(&(winRec->textAttributes.textBackgroundColor));
}

int PsychGetDepthFromWindowRecord(PsychWindowRecordType *winRec)
{
    return(winRec->depth);
}