Ben's Page-Flipping on the Mac Page


What is page-flipping?

Note: This page is a little out of date. It deals with a technique that's only useful under Classic MacOS on older video cards. I am interested in what can be done with the new CoreGraphics APIs. OpenGL should either use page-flipping or extremely fast blits between front and back buffers transparently. Still, I keep this page around for historical interest.

Some video drivers allow Mac applications to access multiple video pages on a video card. You "Page Flip" to switch between the pages. You can flip which page you want to draw to, and you can flip which page you want to show.

What is the advantage of page-flipping?

The main advantage is that you can draw to a different video page than the one displayed. This is called double buffering, with both buffers on the video card-- sometimes called "hardware double buffering." Hardware double buffering allows you to avoid a glitch called tearing. Denis Pelli provides a great description of tearing in PsychToolbox's MovieTearDemo:

The tear is a discontinuity in time. The movie above the tear is delayed by one frame relative to what's displayed below the tear. This is invisible if the movie is static, but produces a glaring break in a moving object. Your video card has enough video memory to store one frame. The reading of video memory is an autonomous free-running process that drives the intensity and position of the monitor's video beam in a raster scan that paints the screen from top to bottom. The tear is the result of the computer writing to the same video memory that the video beam is reading. The computer is racing with the video beam from the top to the bottom of your screen. The beam has a head start, but your computer is slightly faster. The tear occurs when your computer passes the beam. Below the tear you see the contents of the new frame, just written by your computer into the frame store. Above the tear you are seeing the contents of the previous frame.

Geoff Stahl <gstahl@apple.com> of Apple has often pointed out on the Mac-Games-Developer list that page-flipping won't completely solve a tearing problem:

Tearing is not specifically caused by lack of page flipping, it is caused by lack of VBL syncing (or long blit times, which is very unusual for a VRAM to VRAM blit, which would be the same as a flip basically). If you flip a page and it is not synced with the VBL you will get tearing just as with a blit to the front buffer.

Page-Flipping Discussion

Read the best discussion on the topic yet, including tips and historical info from Apple engineers circa March 2001 at the Mac-Games-Dev archives.
A result of this discussion was this great page here by Kent Miller of Apple and Chris Bentley of ATI.

Which Mac video drivers support page-flipping?

If you know of any others, let me know.

What do you mean, "the standard method" ?

Apple's documentation ("Designing Cards and Drivers") describes the standard method (under MacOS Classic, that is), which is to make driver-level calls via control and status codes. The litmus test for page-flipping is whether the driver provides access to more than one page. The cscGetPages status code returns the number of pages.

How can I check if my video driver supports page-flipping via the standard method?

Well, you can write a small program (see Denis Pelli's GDVideo.c, part of VideoToolbox to help you do so), or if you have a PowerPC-based Mac you can download my program GetPages which does just that and returns the number of pages along with their base addresses. If you have MATLAB you can download my DriverPages suite and do the check from within MATLAB using the PageCount function. See the download section below.

It looks like my video driver(s) don't page-flip via the standard method. What other methods are there?

Apple's DrawSprocket will use page-flipping on some Apple drivers even though they don't report more than one page via the standard method. For instance, the video driver supplied with the 73/75/76/85/8600 will page-flip using DrawSprocket if you have 4 MB of VRAM (2 MB is standard, so you'll have to upgrade).

Download Section

GetPages

Reports how many video pages are available for each of your installed video drivers, and reports the pages' base addresses.
Requires: A PowerPC-based Mac.

GetPages.sit.hqx [about 30K]

DriverPages

A set of 3 new MATLAB commands (PageCount, DrawToPage, and ShowPage) that perform the driver-level calls necessary for page-flipping using the standard method. Also includes a demo on page-flipping called FlipDemo.
Requires: MATLAB, PsychToolbox, and a PowerPC based Mac.
(To be useful, DrawToPage and ShowPage require a video driver that can page-flip.)

DriverPages.sit.hqx [about 20K]

If you want a 68k version of any of the above files email me.

DrawSprocketTest

Apple's example of how DrawSprocket will perform on your main screen. Check out option 5 to see if the page flipping option is enabled in the best context returned for games, and if the pageCount variable is greater than one. Try option 7 to see if tearing occurs using the optimized drawing routines.
Requires: DrawSprocket, and a PowerPC based Mac.

DrawSprocketTest.sit.hqx [about 900K]

Thanks

None of this would be possible or have occurred to me if it weren't for the excellent work of David Brainard, Denis Pelli and others on the VideoToolbox and PsychToolbox packages. Thanks also to posters on the mac-games-dev list.
Up
Last updated 10/2001
bdsinger@princeton.edu