# Timing the copying from off-screen to the on-screen window.

**URL:** <https://psychtoolbox.discourse.group/t/timing-the-copying-from-off-screen-to-the-on-screen-window/1267>\
**Category:** Uncategorized\
**Created:** [November 3, 2005, 5:32pm UTC](https://psychtoolbox.discourse.group/t/timing-the-copying-from-off-screen-to-the-on-screen-window/1267 "2005-11-03T17:32:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [November 3, 2005, 5:32pm UTC](https://psychtoolbox.discourse.group/t/timing-the-copying-from-off-screen-to-the-on-screen-window/1267/1 "2005-11-03T17:32:22Z")

</div>

Hello Users,  
  
I am new to Psychophysical Toolbox and am benchmarking its  
performance ofor my machines, displays, and experimental tasks.  
  
As a quality-assurance test, I tried to display a 32 bit, 1024x786  
movie at 100hz on a PC. This shouldnt work too well; it is a lot of  
memory to copy in 10ms. In fact, even rushed at maximum priority,  
tearing is evident. I was looking for evidence of the failure in time  
stamps from getSecs. Unfortunately, I did not find it; the time  
stamps were consistent with no missed frames! This is unfortunate.  
In my experiments, it is desirable to know when the system is not  
behaving as specified.  
  
To help troubleshoot the problem, I put getSecs commands around the  
SCREEN('copywindow') command. It reported taking between 40 and 80  
microsecnds to copy from an offscreen window to the onscreen one. I  
suspect it takes this duration to issue the command to the video card  
but that copying the window takes considerably longer. My guess is  
that displaying a rushed loop is a parallel process in which Matlab  
issues a command to copy the window to the video card but doesnt wait  
for the actual copying to finish. Hence, all the time stamps are  
determined by waitblanking and indicate no missed frames even though  
the display is not what is specified.  
  
My question is how can I find out, on a frame-by-frame basis, whether  
the latency of copying the window took within the requisite time for  
frame-accurate displays (in a rushed loop). I realize I can look at the  
screen for certain stimuli and see tearing. But I would like a  
frame-by-frame basis for assuring the quality of collected  
experimental data.  
  
I certainly increase the likelihood of frame-accurate displays by  
using 8 bit displays, coding images in lookup tables, or copying  
smaller amounts of memory. As a matter of experimental control, I am  
seeking a frame-by-frame way of knowing whether the computer has  
executed the commands as specified or not. Any help will be greatly  
appreciated.  
  
Thank you,  
Jeff Rouder  
  
ps. Please cc replies to me at [rouderj@...](mailto:rouderj@...)  
  
  
pps.Here is my beginner's quality code. timer1 and timer2 output should  
be in milliseconds.  
  
numtrials=4;  
numImage = 5;  
dur=[1,1,1,1,1];   
bg=0;  
white=255;  
grey=127;  
xc=1024/2;  
yc=768/2;  
rect=[xc-100,yc-300 ,xc+100,yc+300];  
  
w=Screen(0,'OpenWindow',[],[],32);  
HideCursor;  
myscale=(0:255)'\*ones(1,3);  
myscale(2,1:3)=[255 0 0];  
myscale(3,1:3)=[0 255 0];  
SCREEN(w,'SetClut',myscale); %greyscale?  
SCREEN(w,'FillRect',bg);  
waitSecs(1); % Give display a moment to recover from the change of  
pixelSize  
  
for i=1:numImage  
 s(i)=SCREEN(w,'OpenOffscreenWindow',bg);  
end  
  
timer1=1:numImage;  
timer2=1:numImage;  
timer3=1:numImage;  
  
priorityLevel=MaxPriority(0,'WaitBlanking');  
SCREEN(s(1),'FillRect',bg,rect);  
SCREEN(s(2),'FillRect',grey,rect);  
SCREEN(s(3),'FillRect',white,rect);  
SCREEN(s(4),'FillRect',grey,rect);  
SCREEN(s(5),'FillRect',bg,rect);  
  
for t=1:numtrials  
loop={   
 'SCREEN(w,''WaitBlanking'');'  
 'for i=1:numImage;'  
 'timer1(i)=getSecs;'  
 'SCREEN(''CopyWindow'',s(i),w);'  
 'timer2(i)=getSecs;'  
 'timer3(i)=SCREEN(w,''WaitBlanking'',dur(i));'  
 'end;'  
 };   
 SCREEN('Screens');   
 RUSH(loop);  
 waitSecs(.3);  
 end;  
Screen('CloseAll');  
diff(timer1)\*1000  
diff(timer2)\*1000  
timer3  
1000\*(timer2-timer1)
