~ubuntu-branches/ubuntu/trusty/psychtoolbox-3/trusty-proposed

« back to all changes in this revision

Viewing changes to PsychSourceGL/Source/Common/Screen/SCREENResolutions.c

  • Committer: Package Import Robot
  • Author(s): Yaroslav Halchenko
  • Date: 2013-11-19 23:34:50 UTC
  • mfrom: (3.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20131119233450-f7nf92vb8qavjmk8
Tags: 3.0.11.20131017.dfsg1-3
Upload to unsable since fresh glew has arrived to sid!

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
 
25
25
#include "Screen.h"
26
26
 
 
27
#if PSYCH_SYSTEM == PSYCH_OSX
 
28
// Need these includes to make setting display brightness work:
 
29
#include <IOKit/graphics/IOGraphicsLib.h>
 
30
#endif
 
31
 
27
32
const char *FieldNames[]={"width", "height", "pixelSize", "hz"};
28
33
 
29
34
PsychError SCREENConfigureDisplay(void)
36
41
                                        "'Brightness': Return or set brightness of an attached display device. Many displays and systems don't support this function. "
37
42
                    " brightness values are in the range 0.0 to 1.0 from darkest to brightest. Returns old brightness setting.\n"
38
43
                                        "'NumberOutputs': Return number of active separate display outputs for given screen 'screenNumber'.\n"
 
44
                                        "'Capture': Capture output 'outputId' of a screen 'screenNumber' for exclusive use by Psychtoolbox.\n"
 
45
                                        "'Release': Release output 'outputId' of a screen 'screenNumber' from exclusive use by Psychtoolbox.\n"
 
46
                                        "Please note that 'Capture' and 'Release' are automatically applied to a display output as appropriate "
 
47
                                        "whenever a fullscreen onscreen window is opened or closed on a display. You usually don't need to call "
 
48
                                        "these functions yourself, in fact, you even shouldn't call them yourself usually, as wrong use of the "
 
49
                                        "functions can cause graphics malfunctions or even a freeze of the display or GUI, forcing you to kill "
 
50
                                        "Matlab or Octave as a last resort to regain control over your displays. The main purpose of these "
 
51
                                        "functions is to temporarily block all graphics operations or display updates on displays that are not "
 
52
                                        "used for visual stimulation, ie., not covered by fullscreen onscreen windows. This prevents other running "
 
53
                                        "applications from interfering with your experiment script by preventing them to take up valuable resources "
 
54
                                        "on the graphics card. Display capture is not supported on all operating systems in all modes of operation. "
 
55
                                        "If the functions get called on an unsupported configuration, they silently return and simply do nothing."
 
56
                                        "\n\n"
39
57
                                        "'Scanout': Retrieve or set scanout parameters for a given output 'outputId' of screen 'screenNumber'. "
40
58
                                        "Returns a struct 'oldSettings' with the current settings for that output. Only supported on Linux.\n"
41
59
                                        "It returns and accepts the following optional parameters:\n"
47
65
 
48
66
        const char *OutputFieldNames[]={"width", "height", "pixelSize", "hz", "xStart", "yStart"};
49
67
        char *settingName = NULL;
50
 
        PsychGenericScriptType *oldResStructArray;
51
68
        int screenNumber, outputId;
 
69
 
 
70
    #if PSYCH_SYSTEM == PSYCH_LINUX
 
71
        PsychGenericScriptType *oldResStructArray;
52
72
        int newWidth, newHeight, newHz, newBpp, newX, newY;
53
73
        psych_bool rc;
54
 
        
 
74
    #endif
 
75
 
55
76
        // All sub functions should have these two lines
56
77
        PsychPushHelp(useString, synopsisString, seeAlsoString);
57
78
        if(PsychIsGiveHelp()) { PsychGiveHelp(); return(PsychError_none); };
124
145
                // Map screenNumber and outputIdx to dpy, rootwindow and RandR output:
125
146
                PsychGetCGDisplayIDFromScreenNumber(&dpy, screenNumber);
126
147
 
 
148
        PsychLockDisplay();
127
149
                backlight_new    = XInternAtom(dpy, "Backlight", True);
128
150
                backlight_legacy = XInternAtom(dpy, "BACKLIGHT", True);
 
151
        PsychUnlockDisplay();
 
152
 
129
153
                if (backlight_new == None && backlight_legacy == None) {
130
154
                        PsychErrorExitMsg(PsychError_user, "Failed to query current display brightness from system. System does not support brightness query and setting.");
131
155
                }
132
156
 
133
157
                screen = PsychGetXScreenIdForScreen(screenNumber);
 
158
 
 
159
        PsychLockDisplay();
134
160
                Window root = RootWindow(dpy, screen);
135
161
                XRRScreenResources *resources = XRRGetScreenResources(dpy, root);
 
162
        PsychUnlockDisplay();
 
163
 
136
164
                if (resources == NULL) PsychErrorExitMsg(PsychError_user, "Failed to query current display brightness from system. Feature not supported.");
137
165
                if (outputId < 0 || outputId >= resources->noutput) PsychErrorExitMsg(PsychError_user, "Invalid video output specified!");
138
166
                RROutput output = resources->outputs[outputId];
148
176
                double cur, new;
149
177
                double min, max;
150
178
    
 
179
        PsychLockDisplay();
 
180
 
151
181
                backlight = backlight_new;
152
182
                if (!backlight || XRRGetOutputProperty(dpy, output, backlight, 0, 4, False, False, None, &actual_type, &actual_format, &nitems, &bytes_after, &prop) != Success) {
153
183
                        backlight = backlight_legacy;
154
 
                        if (!backlight || XRRGetOutputProperty(dpy, output, backlight, 0, 4, False, False, None, &actual_type, &actual_format, &nitems, &bytes_after, &prop) != Success)
 
184
                        if (!backlight || XRRGetOutputProperty(dpy, output, backlight, 0, 4, False, False, None, &actual_type, &actual_format, &nitems, &bytes_after, &prop) != Success) {
 
185
                PsychUnlockDisplay();
155
186
                                PsychErrorExitMsg(PsychError_user, "Failed to query current display brightness from system. Unsupported feature?");
 
187
            }
156
188
                }
157
189
 
158
190
                if (actual_type != XA_INTEGER || nitems != 1 || actual_format != 32) {
159
191
                        XFree(prop);
 
192
            PsychUnlockDisplay();
160
193
                        PsychErrorExitMsg(PsychError_user, "Failed to query current display brightness from system. Unsupported feature?");
161
194
                } else {
162
195
                        value = *((long *) prop);
195
228
                        XFree(info);
196
229
                } else {
197
230
                        if (info) XFree(info);
 
231
            PsychUnlockDisplay();
198
232
                        PsychErrorExitMsg(PsychError_user, "Failed to query current display brightness from system. Unsupported feature?");
199
233
                }
200
234
 
201
235
                XRRFreeScreenResources(resources);
202
236
 
 
237
        PsychUnlockDisplay();
 
238
 
203
239
                #endif
204
240
 
205
241
                #if PSYCH_SYSTEM == PSYCH_WINDOWS
222
258
                return(PsychError_none);
223
259
        }
224
260
 
225
 
    
 
261
        // Usercode wants to capture a display screen?
 
262
        if (PsychMatch(settingName, "Capture")) {
 
263
                // Get the screen number from the windowPtrOrScreenNumber.  This also checks to make sure that the specified screen exists.  
 
264
                PsychCopyInScreenNumberArg(2, TRUE, &screenNumber);
 
265
                if(screenNumber==-1) PsychErrorExitMsg(PsychError_user, "The specified onscreen window has no ancestral screen or invalid screen number."); 
 
266
 
 
267
                // This functions is only supported on OSX for the time being, a no-op on other platforms:
 
268
                if ((PSYCH_SYSTEM == PSYCH_OSX) && !PsychIsScreenCaptured(screenNumber)) PsychCaptureScreen(screenNumber);
 
269
 
 
270
                return(PsychError_none);
 
271
        }
 
272
 
 
273
        // Usercode wants to release a display screen?
 
274
        if (PsychMatch(settingName, "Release")) {
 
275
                // Get the screen number from the windowPtrOrScreenNumber.  This also checks to make sure that the specified screen exists.  
 
276
                PsychCopyInScreenNumberArg(2, TRUE, &screenNumber);
 
277
                if(screenNumber==-1) PsychErrorExitMsg(PsychError_user, "The specified onscreen window has no ancestral screen or invalid screen number."); 
 
278
 
 
279
                // This functions is only supported on OSX for the time being, a no-op on other platforms:
 
280
                if ((PSYCH_SYSTEM == PSYCH_OSX) && PsychIsScreenCaptured(screenNumber)) PsychReleaseScreen(screenNumber);
 
281
 
 
282
                return(PsychError_none);
 
283
        }
 
284
 
226
285
#if PSYCH_SYSTEM != PSYCH_LINUX
227
286
        PsychErrorExitMsg(PsychError_unimplemented, "Sorry, this function is only supported on Linux.");
228
287
#else
241
300
 
242
301
        // Query current video mode of this output:
243
302
        XRRCrtcInfo *crtc_info = NULL;
 
303
 
 
304
    PsychLockDisplay();
244
305
        XRRModeInfo *mode = PsychOSGetModeLine(screenNumber, outputId, &crtc_info);
 
306
    PsychUnlockDisplay();
 
307
 
245
308
        if (NULL == mode) PsychErrorExitMsg(PsychError_user, "Could not query video mode for this output. Invalid outputId or unsupported function on this system?");
246
309
 
247
310
        // Get (x,y) top-left corner of crtc's viewport -- panning info: