File: SCREENOpenProxy.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 (105 lines) | stat: -rw-r--r-- 4,887 bytes parent folder | download | duplicates (4)
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
/*
    SCREENOpenProxy.c

    AUTHORS:

        mario.kleiner.de@gmail.com      mk

    PLATFORMS:

        All.

    HISTORY:

        01/25/07    mk        Wrote it.

    DESCRIPTION:

        Create a proxy object. A proxy is a windowRecord (like a texture, offscreen window or
        onscreen window), but without associated image content. Its useful as a container for
        all the typical settings associated with a window or texture. Its main purpose is to
        store additional hook function chains for use with the imaging pipeline. The users
        script can create special proxy objects for different image processing subtasks, attach
        proper user defined hook chains to it, and then switch between different hook chains by
        simply passing different proxy objects to the image processing functions. This way we
        are not limited to a fixed number of imaging hooks but can create new ones dynamically.
*/

#include "Screen.h"

// If you change useString then also change the corresponding synopsis string in ScreenSynopsis.c
static char useString[] = "proxyPtr = Screen('OpenProxy', windowPtr [, imagingmode]);";
//                                                        1            2
static char synopsisString[] =
        "Create a proxy object. A proxy is a windowRecord (like a texture, offscreen window or "
        "onscreen window), but without associated image content. Its useful as a container for "
        "all the typical settings associated with a window or texture. Its main purpose is to "
        "store additional hook function chains for use with the imaging pipeline. The users "
        "script can create special proxy objects for different image processing subtasks, attach "
        "proper user defined hook chains to it, and then switch between different hook chains by "
        "simply passing different proxy objects to the image processing functions. This way we "
        "are not limited to a fixed number of imaging hooks but can create new ones dynamically. "
        "Read 'help PsychGLImageProcessing' for more infos about proxies and the pipeline. "
        "\n\n"
        "'windowPtr' is a handle to an associated parent onscreen window. Just pass the handle of "
        "the onscreen window for which image processing is supposed to take place. The routine "
        "returns a handle 'proxyPtr' to the new proxy object. You can delete proxy objects via "
        "the regular Screen('Close', proxyPtr) or Screen('CloseAll'); command as you would do "
        "with textures or windows. You can add or modify hook functions by passing the 'proxyPtr' "
        "to the Screen('Hookfunction', ...) subfunction. You can apply a proxy via the Screen('TransformTexture') "
        "function. 'imagingmode' flags to define the boundary conditions for image processing. ";

static char seeAlsoString[] = "Hookfunction, TransformTexture";

PsychError SCREENOpenProxy(void)
{
    PsychWindowRecordType *windowRecord, *proxyRecord;
    int imagingmode;

    // All subfunctions should have these two lines.
    PsychPushHelp(useString, synopsisString, seeAlsoString);
    if(PsychIsGiveHelp()) { PsychGiveHelp(); return(PsychError_none); };

    PsychErrorExit(PsychCapNumInputArgs(2));
    PsychErrorExit(PsychRequireNumInputArgs(1));
    PsychErrorExit(PsychCapNumOutputArgs(1));

    // Get the window structure for the onscreen window.
    PsychAllocInWindowRecordArg(1, kPsychArgRequired, &windowRecord);

    // Create proxy object:
    PsychCreateWindowRecord(&proxyRecord);  // This also fills the window index field.

    // Set type:
    proxyRecord->windowType=kPsychProxyWindow;

    // Assign parent window and copy its inheritable properties:
    PsychAssignParentWindow(proxyRecord, windowRecord);

    // Init proxy's rects to parent windows. We could set anything that is a non-empty
    // rect, doesn't need to be the windowRecord's rect, but then why not?
    // Without this, functions like PsychSetupView() might fail due to empty
    // rects triggering OpenGL errors:
    PsychCopyRect(proxyRecord->rect, windowRecord->rect);
    PsychCopyRect(proxyRecord->clientrect, windowRecord->clientrect);

    // Get optional imagingmode argument and assign it:
    imagingmode = 0;
    PsychCopyInIntegerArg(2, FALSE, &imagingmode);
    if (imagingmode < 0)
        PsychErrorExitMsg(PsychError_user, "'imagingmode' argument must be a positive number (>=0).");

    proxyRecord->imagingMode = imagingmode;

    // If this will ever get a backing texture, it will be upright/normalized:
    proxyRecord->textureOrientation = 2;

    // Window ready. Mark it valid and return handle to userspace:
    PsychSetWindowRecordValid(proxyRecord);

    //Return the window index and the rect argument.
    PsychCopyOutDoubleArg(1, FALSE, proxyRecord->windowIndex);

    // Done.
    return(PsychError_none);
}