XlBitmapImpl.mesa
Copyright Ó 1990, 1991, 1992 by Xerox Corporation. All rights reserved.
Created by Christian Jacobi, October 30, 1990 2:20:01 pm PST
Christian Jacobi, January 4, 1993 12:23 pm PST
Willie-s, October 30, 1991 11:23 am PST
The part of XlBitmapImpl which does NOT use imager device features.
DIRECTORY
Imager,
ImagerSample,
SF,
SFInline,
XlBitmap,
XlBitmapExtras,
XlBitmapPrivate,
XlShmPixmaps;
XlBitmapImpl:
CEDAR
MONITOR
IMPORTS ImagerSample, SFInline, XlShmPixmaps
EXPORTS XlBitmap, XlBitmapExtras =
BEGIN
OPEN XlBitmap, XlBitmapPrivate;
BitmapRep: PUBLIC TYPE = XlBitmapPrivate.BitmapRepDef;
NarrowBitmap:
PUBLIC
PROC [x:
REF
ANY]
RETURNS [XlBitmap.Bitmap] = {
RETURN [ NARROW[x, REF BitmapRep] ]
};
IsBitmap:
PUBLIC
PROC [x:
REF
ANY]
RETURNS [
BOOL] = {
RETURN [ ISTYPE[x, REF BitmapRep] ]
};
Noop: BoxDataProc = {};
CreateFromSM:
PUBLIC
PROC [sm: ImagerSample.RasterSampleMap]
RETURNS [b: Bitmap] = {
b ¬ NEW[BitmapRep ¬ [sm: sm, sz: ImagerSample.GetSize[sm], box: ImagerSample.GetBox[sm]]];
IF b.box.min#[0, 0] THEN ERROR;
};
GetSM:
PUBLIC
PROC [b: Bitmap]
RETURNS [ImagerSample.RasterSampleMap] = {
IF b#NIL THEN RETURN [b.sm] ELSE RETURN [NIL];
};
GetBox:
PUBLIC
PROC [b: Bitmap]
RETURNS [
SF.Box] = {
IF b#NIL THEN RETURN [b.box] ELSE RETURN [emptyBox];
};
Create:
PUBLIC
PROC [size:
SF.Vec, bpp:
NAT ¬ 1, sharedMemory:
BOOL ¬
TRUE]
RETURNS [b: Bitmap] = {
sm: ImagerSample.RasterSampleMap ¬ NIL;
IF sharedMemory
THEN
sm ¬ XlShmPixmaps.NewSharedSampleMap[box: [min: [0, 0], max: size], bitsPerSample: bpp];
IF sm=
NIL
THEN
sm ¬ ImagerSample.NewSampleMap[box: [min: [0, 0], max: size], bitsPerSample: bpp];
b ¬ NEW[BitmapRep ¬ [sm: sm, sz: size, box: [min: [0, 0], max: size]]];
};
SetColormap:
PUBLIC
PROC [bitmap: Bitmap, colormap:
REF] = {
WITH colormap
SELECT
FROM
cme: MapEntries => bitmap.colormapEntries ¬ cme
ENDCASE => {}
};
GetColormap:
PUBLIC
PROC [bitmap: Bitmap]
RETURNS [
REF
ANY] = {
RETURN [bitmap.colormapEntries]
};
RegisterInterceptionProcs:
PUBLIC
ENTRY PROC [bitmap: Bitmap, refresh, preRefresh: BoxDataProc, data:
REF] = {
IF preRefresh#
NIL
THEN {
ok: BOOL ¬ FALSE;
FOR preList: ICClosures ¬ bitmap.preList, preList.rest
WHILE preList#
NIL
DO
IF preList.first.data=data THEN {preList.first.proc ¬ preRefresh; ok ¬ TRUE; EXIT};
ENDLOOP;
IF ~ok AND preRefresh#Noop THEN bitmap.preList ¬ CONS[[preRefresh, data], bitmap.preList]
};
IF refresh#
NIL
THEN {
ok: BOOL ¬ FALSE;
FOR postList: ICClosures ¬ bitmap.postList, postList.rest
WHILE postList#
NIL
DO
IF postList.first.data=data THEN {postList.first.proc ¬ refresh; ok ¬ TRUE; EXIT};
ENDLOOP;
IF ~ok AND preRefresh#Noop THEN bitmap.postList ¬ CONS[[refresh, data], bitmap.postList]
};
};
RemoveInterceptionProcs:
PUBLIC
PROC [bitmap: Bitmap, data:
REF] = {
Entry:
ENTRY PROC [bitmap: Bitmap, data:
REF] = {
ReplaceICClosures:
PROC [c: ICClosures]
RETURNS [new: ICClosures ¬
NIL] = {
--we replace a whole list so we are certainly atomic to interceptions which are not monitored...
FOR l: ICClosures ¬ c, l.rest
WHILE l#
NIL
DO
IF l.first.proc#Noop THEN new ¬ CONS[l.first, new]
ENDLOOP;
};
bitmap.postList ¬ ReplaceICClosures[bitmap.postList];
bitmap.preList ¬ ReplaceICClosures[bitmap.preList];
};
RegisterInterceptionProcs[bitmap, Noop, Noop, data];
Entry[bitmap, data];
};
Refresh:
PUBLIC
PROC [bitmap: Bitmap, box:
SF.Box, delayOk:
BOOL ←
FALSE] = {
PostIntercept[bitmap, box, delayOk];
};
PromiseRepaintLater:
PUBLIC
PROC [bitmap: Bitmap, box:
SF.Box] = {
IF SFInline.Empty[bitmap.delayBox] OR ~SFInline.Inside[inner: box, outer: bitmap.delayBox] THEN bitmap.delayBox ¬ box
};
EndPromiseRepaint:
PUBLIC
PROC [bitmap: Bitmap, box:
SF.Box ¬
SF.maxBox, refresh:
BOOL ¬
TRUE, delayOk:
BOOL ←
FALSE] = {
IF SFInline.Inside[inner: bitmap.delayBox, outer: box]
THEN {
bitmap.delayBox ¬ emptyBox;
IF refresh THEN Refresh[bitmap, box, delayOk];
}
ELSE
IF refresh
THEN {
IF ~SFInline.Inside[inner: box, outer: bitmap.delayBox] THEN Refresh[bitmap, box, delayOk];
};
};
PostIntercept:
PROC [b: Bitmap, box:
SF.Box, delayOk:
BOOL] =
INLINE {
IF ~SFInline.Inside[inner: box, outer: b.delayBox]
THEN
FOR postList: ICClosures ¬ b.postList, postList.rest
WHILE postList#
NIL
DO
postList.first.proc[box, postList.first.data, delayOk];
ENDLOOP;
};
END.