[comp.sys.apple2] off-screen grafports ... solved but more problems.

acmfiu@serss0.fiu.edu (ACMFIU) (02/23/91)

I have finally figured out how to create and draw to off-screen grafports.
However, i'm still having problems. Now, my problem is with copying the
contents of my windows pixelimage to the off-screen grafport and back.
here's a sample of what my code looks like:

void
foo (void)
{
	GrafPort *g1, g2;
	LocInfo g2_locinfo = { mode640, NULL, 160, 0, 0, 200, 640 };

	g1 = GetPort ();
	g2_locinfo.ptrToPixImage = *NewHandle (0x8000, userid, attrPage +
						attrLocked, NULL);
	OpenPort (&g2);
	SetPortLoc (&g2_locinfo);
	SetPort (&g2);
	PPToPort (&g1->portInfo, &g1->portInfo.boundsRect, 0, 0, modeCopy);

	/* i then draw to the off-screen grafport */

	SetPort (g1);
	PPToPort (&g2.portInfo, &g2.portInfo.boundsRect, 0, 0, modeCopy);
	ClosePort (&g2);
	DisposeHandle (FindHandle (g2_locinfo.ptrToPixImage));
}

now, my window which is set to the current grafport before this routine is
called is created via NewWindow with bounds being { 20, 0, 200, 640 }. Now,
the problem here is that after the update to the off-screen grafport is
done and i draw back onto my on-screen window, the off-screen grafport's
contents don't get drawn fully into the window. by that i mean i see the
menu bar on the screen which also gets drawn into the window. i think this
is a problem with PPToPort but i can't figure out what the problem is. if
i set the coordinates of the window to { 0, 0, 200, 640 } then everything
works. also, if my window is defined as before and the off-screen grafport's
locinfo boundsRect is defined as { 20, 0, 200, 640 }, this doesn't work as
if both off-screen/on-screen boundsRect were defined to be { 0, 0, 200, 640 }.

also, the update to the screen is SLOW. i can't stand it. you can *see* the
update to the window. i thought it was suppose to be *BANG*, screen update.
however, this doesn't work at all. i'm getting real tired of these toolsets.
right now i just want to write my own graphic routines and forget about
everything else, because i want and need speed for this program. however,
because this is my first venture into the toolsets (and QD is the only toolset
i hate so far), i am probably doing something wrong. how can i squeeze more
speed out of QD.

please help, i need it.

albert

ps. i would like to thank Julian Pugh (he wrote GSNumerics) for his help
    on the off-screen grafport.

toddpw@nntp-server.caltech.edu (Todd P. Whitesel) (02/23/91)

WHAT SPECIFICALLY ARE YOU TRYING TO DO??

If you're trying to update a given window faster, then your best bet is
to allocate an offscreen image, DRAW INTO IT, and COPY IT TO THE WINDOW in
your window's update routine.

DO NOT copy things FROM a window, all you will get is the visible region of
your window and whatever else is on the screen.

I'm mailing you a copy of IIgs tech note #80. In a nutshell, the Locinfo
record describes the actual pixmap the grafport will draw into, and windows
contain the Locinfo record of the screen. Quickdraw supports clipping so the
window manager can exploit it to prevent multiple overlapping windows from
drawing on top of each other on the same screeen.

As was just posted by a guy from Apple, QD's biggest slowdown comes from trying
to draw lots of objects without overwriting pixels outside your window's visRgn
-- allocating an offscreen grafport and drawing into it avoids the clipping
overhead except for the last step which is doing a pixel copy from the
offscreen grafport to the window. If this is slower than your original update
routine then you have two options:
	don't bother using an offscreen grafport
	Use your own drawing routines ON THE OFFSCREEN GRAFPORT and use QD to
copy the image you drew into your window.

Todd Whitesel
toddpw @ tybalt.caltech.edu