[comp.sys.amiga.tech] Clipping? Questions and recommendations.

sutela@utu.fi (Kari Sutela) (03/03/90)

Basically, I'd like to see your opinions on the best method for performing
clipping. I understand Intuition windows perform clipping automatically. Is
this true regardless of the window type (SIMPLEREFRESH etc.)?

I guess, the simplest method would be using a GZZ-window, but the manuals
say something about performance disadvantages. Anyway, for this application,
I'd like to provide zooming, so I must be able handle some kind of refreshing
and resizing. So, a SIMPLEREFRESH window would do just as well. But I don't
want to perform software clipping, and I don't know how to define a clipping
region (I don't want to draw all over the window borders). I have read the
old Libraries&Devices (the new one isn't available in Finland, yet) but,
to be honest, I didn't quite understand the part about clipping regions.

Should I just take the easy way out and use GZZ-windows or do they really
cause a significant performance decrease? Any help (a small example) on
clipping regions would also be nice.

- Kari Sutela	sutela@polaris.utu.fi OR sutela@kontu.utu.fi OR
		sutela@tucos.utu.fi

micke@slaka.sirius.se (Mikael Karlsson) (03/05/90)

In article <9993@cbmvax.commodore.com> ken@cbmvax.commodore.com (Ken Farinsky - CATS) writes:
> >Basically, I'd like to see your opinions on the best method for performing
> >clipping. I understand Intuition windows perform clipping automatically. Is
> >this true regardless of the window type (SIMPLEREFRESH etc.)?
>[Advice on how to use clipping regions]

I want to write a program with one user interface task and one drawer
task. The UI task sends drawing commands to the drawer task.
The UI task opens a window and initializes the drawer task by giving
it a copy of the window's RastPort.

Now for the question:
Is it possible to have two tasks draw into the same window (RastPort)
where each task uses different clipping regions?
Can each task add it's own clipping in some way?


--

 \_/   Mikael Karlsson, Lovsattersvagen 10, S-585 98  LINKOPING, SWEDEN
  V                           | micke@slaka.sirius.se
  |      Absolut Software     | micke@slaka.UUCP
 ~~~                          | {mcvax,seismo}!sunic!liuida!slaka!micke

ken@cbmvax.commodore.com (Ken Farinsky - CATS) (03/06/90)

In article <1990Mar3.110330.6134@utu.fi> sutela@utu.fi (Kari Sutela) writes:
>Basically, I'd like to see your opinions on the best method for performing
>clipping. I understand Intuition windows perform clipping automatically. Is
>this true regardless of the window type (SIMPLEREFRESH etc.)?

GimmeZeroZero windows will slow down the whole intuition interface once
you open a few of them.  Use the user clip rects, which were added in
1.2.  The following is a excerpt from the Addison Wesley RKM, Libs & Devs,
this should work (if I cut it correctly):

Here is some sample code for clipping windows:

/*-----------------------------------------------------------------
** UnclipWindow()
**
** routine to remove a clipping region installed by ClipWindow() or
** ClipWindowToBorders(), disposing of the installed region and
** reinstalling the region removed.
*/
void UnclipWindow(struct Window *win, struct Region *prev_region)
{
register struct Region     *old_region ;

/* remove any old region by installing a NULL,
** then dispose of the old region if one was there.
*/
if (NULL != (old_region = InstallClipRegion(win->WLayer, prev_region)))
    DisposeRegion(old_region) ;
}

/*-----------------------------------------------------------------
** ClipWindow()
** clip a window to a specified rectangle (given by upper left and
** lower right corner.  the removed region is returned so that it
** can be re-installed later.
*/
struct Region *ClipWindow(struct Window *win,
               LONG minX, LONG minY, LONG maxX, LONG maxY)
{
register struct Region     *new_region ;
register struct Region     *old_region ;

struct Rectangle    my_rectangle ;

/* set up the limits for the clip */
my_rectangle.MinX = minX ;
my_rectangle.MinY = minY ;
my_rectangle.MaxX = maxX ;
my_rectangle.MaxY = maxY ;

/* get a new region and OR in the limits. */
new_region = NewRegion() ;
OrRectRegion(new_region, &my_rectangle) ;

/* install the new region, and dispose of any existing region */
return(InstallClipRegion(win->WLayer, new_region));
}

/*-----------------------------------------------------------------
** ClipWindowToBorders()
** clip a window to its borders.
** the removed region is returned so that it can be re-installed later.
*/
struct Region *ClipWindowToBorders(struct Window *win)
{
register struct Region     *new_region ;
register struct Region     *old_region ;

struct Rectangle            my_rectangle ;

/* set up the limits for the clip */
my_rectangle.MinX = win->BorderLeft - 1 ;
my_rectangle.MinY = win->BorderTop - 1 ;
my_rectangle.MaxX = win->Width - win->BorderRight ;
my_rectangle.MaxY = win->Height - win->BorderBottom ;

/* get a new region and OR in the limits. */
new_region = NewRegion() ;
OrRectRegion(new_region, &my_rectangle) ;

/* install the new region, and dispose of any existing region */
return(InstallClipRegion(win->WLayer, new_region));
}

-- 
--------------------------------------------------------------
Ken Farinsky -- CATS               Commodore Business Machines
PHONE 215-431-9421         UUCP  ...{uunet,rutgers}!cbmvax!ken
--------------------------------------------------------------

peter@cbmvax.commodore.com (Peter Cherna) (03/09/90)

In article <27831.AA27831@slaka.sirius.se> micke@slaka.sirius.se (Mikael Karlsson) writes:
>I want to write a program with one user interface task and one drawer
>task. The UI task sends drawing commands to the drawer task.
>The UI task opens a window and initializes the drawer task by giving
>it a copy of the window's RastPort.
>
>Now for the question:
>Is it possible to have two tasks draw into the same window (RastPort)
>where each task uses different clipping regions?

The graphics library call InstallClipRegion() operates on a per-layer
basis.  Since your two tasks share a layer, they would share a clip
region.  So to have them use different clipping regions, there would
have to be some kind of locking protocol between them, say a semaphore,
which each of your tasks would have to obtain before installing its
clipping region and hold through its rendering operations, then remove
the clipping region and release the semaphore.

>--
>
> \_/   Mikael Karlsson, Lovsattersvagen 10, S-585 98  LINKOPING, SWEDEN
>  V                           | micke@slaka.sirius.se
>  |      Absolut Software     | micke@slaka.UUCP
> ~~~                          | {mcvax,seismo}!sunic!liuida!slaka!micke

     Peter
--
     Peter Cherna, Software Engineer, Commodore-Amiga, Inc.
     {uunet|rutgers}!cbmvax!peter    peter@cbmvax.cbm.commodore.com
My opinions do not necessarily represent the opinions of my employer.

hcobb@walt.cc.utexas.edu (Henry J. Cobb) (03/09/90)

In article <10056@cbmvax.commodore.com>, peter@cbmvax (Peter Cherna) writes:
>
<The graphics library call InstallClipRegion() operates on a per-layer
<basis.  Since your two tasks share a layer, they would share a clip
<region.  So to have them use different clipping regions, there would
<have to be some kind of locking protocol between them, say a semaphore,
<which each of your tasks would have to obtain before installing its
<clipping region and hold through its rendering operations, then remove
<the clipping region and release the semaphore.
<

	My copy of RKM: Includes & Autodocs shows this to be a function
in layers.library.

	The Autodoc says to call InstallClipRegion(l,NULL) to "tidy up"
when through.  Is there anyway to tell if the Clip region is set to its
default (NULL) value?

	Does this NULL value indicate that there is some sort of array 
somewhere where we can store our "commonly used" clipping regions and
rapidly select from them?

	Lastly, how much "effort" does this call require?  Would it hurt
alot to call it before drawing each line?

	Henry J. Cobb	hcobb@ccwf.cc.utexas.edu