DIRECTORY TerminalIO, CD USING [DesignRect, Rect, Design], CDInline, CDDraw; CDDrawImpl: CEDAR MONITOR IMPORTS CDInline, TerminalIO EXPORTS CDDraw = BEGIN CommandTable: TYPE = REF CTableRep; CommType: TYPE = CDDraw.CommType; Comm: TYPE = CDDraw.Comm; maxC: CARDINAL = 50; CTableRep: PUBLIC TYPE = RECORD [ cnt, in, out: CARDINAL, commandAvail: CONDITION, desgn: CD.Design, deviceClip: CD.DesignRect, comm: ARRAY [0..maxC) OF Comm, stopFlag: REF BOOLEAN, -- must be monitored inlist: BOOLEAN _ FALSE, deleted: BOOLEAN _ FALSE, alldoneToBeReported: BOOLEAN _ FALSE ]; TableList: TYPE = LIST OF CommandTable; tableList: TableList_NIL; InsertList: INTERNAL PROC [ct: CommandTable] = BEGIN IF NOT ct.inlist THEN { tableList _ CONS[ct, tableList]; ct.inlist _ TRUE; }; END; RemoveList: INTERNAL PROC [ct: CommandTable] = BEGIN IF ct.inlist THEN { ct.inlist _ FALSE; IF tableList.first=ct THEN tableList _ tableList.rest ELSE FOR l: TableList _ tableList, l.rest WHILE l.rest#NIL DO IF l.rest.first=ct THEN {l.rest _ l.rest.rest; EXIT} ENDLOOP }; END; CreateCommandTable: PUBLIC ENTRY PROC [design: CD.Design, clip: CD.DesignRect, cleanStopFlag: REF BOOLEAN] RETURNS [CommandTable] = BEGIN ct: CommandTable ~ NEW[CTableRep]; TerminalIO.WriteRope["Create a viewer\n"]; ct.cnt _ ct.in _ ct.out _ 0; ct.deviceClip _ clip; ct.desgn _ design; ct.deleted _ ct.inlist _ ct.alldoneToBeReported _ FALSE; ct.stopFlag _ cleanStopFlag; -- assigns addresses ct.stopFlag^ _ FALSE; InsertList[ct]; RETURN [ct] END; ModifyCommandTable: PUBLIC ENTRY PROC [design: CD.Design, ct: CommandTable, clip: CD.DesignRect] = BEGIN InternalFlush[ct]; ct.deviceClip _ clip; ct.desgn _ design; IF CDInline.NonEmpty[clip] THEN InsertList[ct] ELSE RemoveList[ct] END; DestroyCommandTable: PUBLIC ENTRY PROC [ct: CommandTable] = BEGIN ct.deleted _ TRUE; InternalFlush[ct]; RemoveList[ct]; ct.desgn _ NIL; END; InsertCommand: PUBLIC ENTRY PROC [ct: CommandTable, c: Comm] = BEGIN IF ct.inlist THEN InternalInsertCommand[ct, c] END; InternalInsertCommand: INTERNAL PROC [ct: CommandTable, c: Comm] = BEGIN IF (ct.cnt>=maxC) OR (c.cmd=all) THEN {c _ Comm[cmd: all, erase: TRUE, rect: ct.deviceClip]; InternalFlush[ct]}; IF ct.deleted THEN ERROR; -- at least until it is known IF c.cmd=disapearforever THEN ERROR; -- at least until it is known IF c.cmd=alldone THEN ERROR; -- at least until it is known ct.alldoneToBeReported _ TRUE; IF (ct.cnt=1) AND (ct.comm[ct.out].cmd=all) THEN RETURN; IF c.cmd=rect THEN { IF CDInline.Intersect[c.rect, ct.deviceClip] THEN { j: CARDINAL _ ct.out; c.rect _ CDInline.Intersection[c.rect, ct.deviceClip]; THROUGH [0..ct.cnt) DO IF ct.comm[j].cmd=rect THEN { IF CDInline.Inside[c.rect, ct.comm[j].rect] THEN {ct.comm[j].erase _ ct.comm[j].erase OR c.erase; RETURN}; IF CDInline.Inside[ct.comm[j].rect, c.rect] THEN {ct.comm[j].erase _ ct.comm[j].erase OR c.erase; ct.comm[j].rect _ c.rect; RETURN}; }; j _ (j+1) MOD maxC; ENDLOOP } ELSE RETURN; }; ct.cnt _ ct.cnt+1; ct.comm[ct.in] _ c; ct.in _ (ct.in+1) MOD maxC; NOTIFY ct.commandAvail; END; InsertCommandAll: PUBLIC ENTRY PROC [design: CD.Design, c: Comm] = BEGIN FOR lst: TableList _ tableList, lst.rest WHILE lst#NIL DO IF lst.first.desgn=design THEN InternalInsertCommand[lst.first, c]; ENDLOOP END; FetchCommand: PUBLIC ENTRY PROC [ct: CommandTable] RETURNS [c: Comm] = BEGIN ct.stopFlag^ _ FALSE; WHILE ct.cnt<=0 DO IF ct.deleted THEN InsertDisappear[ct] ELSE IF ct.alldoneToBeReported THEN InsertAlldone[ct] ELSE WAIT ct.commandAvail; ct.stopFlag^ _ FALSE; ENDLOOP; ct.cnt _ ct.cnt-1; c _ ct.comm[ct.out]; ct.out _ (ct.out+1) MOD maxC; END; FlushCommands: PUBLIC ENTRY PROC [ct: CommandTable]= BEGIN InternalFlush[ct] END; InternalFlush: INTERNAL PROC [ct: CommandTable] = BEGIN ct.cnt _ ct.in _ ct.out _ 0; ct.stopFlag^ _ TRUE; ct.alldoneToBeReported _ FALSE; NOTIFY ct.commandAvail; END; InsertDisappear: INTERNAL PROC [ct: CommandTable] = BEGIN ct.out _ 0; ct.cnt _ 1; ct.comm[0] _ Comm[cmd: disapearforever, erase: FALSE, rect: [1,1,0,0]]; ct.in _ (1 MOD maxC); END; InsertAlldone: INTERNAL PROC [ct: CommandTable] = BEGIN ct.alldoneToBeReported _ FALSE; ct.out _ 0; ct.cnt _ 1; ct.comm[0] _ Comm[cmd: alldone, erase: FALSE, rect: [1,1,0,0]]; ct.in _ (1 MOD maxC); END; END. 2CDDrawImpl.mesa (part of Chipndale) by Christian Jacobi July 6, 1983 5:09 pm last edited Christian Jacobi September 7, 1983 9:43 am -- request to stop the execution of (only!) the current command -- tableList#NIL; otherwise nothing too delete! not ct.inlist --cleanStopFlag^ tells any drawing process to stop volunterly and to fetch the next --command. --cleanStopFlag^ must not be modified any more outside this monitor!! --until DeleteCommandTable is called --Users may request a stop by calling FlushCommands. --changes the clipping aera --no more calls of InsertCommand on ct allowed!! --draw process must disapear from itself, --when draw process dispears and contains nomore --reference of ct, it is subject for garbage collection --The cleanStopFlag is immediately set to TRUE and later --reset to FALSE when the draw --process stopped the current command, if it then fetches another --command it gets the disapearforever command. --this procedure introduces redraw all if table is full --and in removes certain rectangles contained by others --this implies that the module knows the commands --this search for similar commands could be made much better --waits till command is available or CommandTable deleted -- the drawing may stop after some time only, -- and NOT immediately with procedure return ʶ˜Jšœ'™'Jšœ+™+Jšœ8™8J˜šÏk ˜ J˜ Jšœœ˜$J˜ J˜J˜—šÏb œœœ˜Jšœ˜Jšœ ˜—Jš˜J˜Jšœœœ ˜#Jšœ œ˜!Jšœœ˜J˜Jšœœ˜šœ œœœ˜!Jšœœ˜Jšœ œ˜Jšœœ˜Jšœ œ ˜Jšœœ œ˜šœ œœÏc˜+Jšœ?™?—Jšœœœ˜Jšœ œœ˜Jšœœ˜$J˜J˜—Jšœ œœœ˜'Jšœœ˜J˜šÏn œœœ˜.Jš˜šœœ ˜Jšœ œ˜ Jšœ œ˜Jšœ˜—Jšœ˜J˜—š  œœœ˜.Jš˜šœ ˜Jšœ œ˜Jšœ=™=Jšœœ˜5š˜šœ"œœ˜8šœœ˜Jšœœ˜—Jš˜——Jšœ˜—Jšœ˜J˜—š œœœœ œœœœœ˜ƒJšœS™SJšœ ™ JšœE™EJšœ$™$Jšœ4™4Jš˜Jšœœ ˜"J˜*J˜J˜J˜Jšœ2œ˜8JšœŸ˜2Jšœœ˜J˜Jšœ˜ Jšœ˜J˜J˜—š  œœœœ œ!œ˜bJšœ™Jš˜J˜J˜J˜Jšœœ˜.Jšœ˜Jšœ˜J˜—š œœœœ˜;Jšœ0™0Jšœ)™)Jšœ0™0Jšœ8™8Jšœ8™8Jšœ™JšœB™BJšœ.™.Jš˜Jšœ œ˜J˜J˜Jšœ œ˜Jšœ˜J˜J˜—š  œœœœ˜>Jš˜Jšœ œ˜.Jšœ˜J˜—š œœœ˜BJšœ7™7Jšœ7™7Jšœ1™1Jš˜šœœ œ˜&Jšœœ+˜J——Jšœ œœŸ˜7JšœœœŸ˜BšœœœŸ˜:Jšœœ˜Jšœ œœœ˜8šœ ˜šœ+˜3Jšœœ ˜J˜6Jšœ<™<šœ ˜šœ˜šœ*˜0Jšœ%œ œ˜9—šœ*˜0Jšœ%œ ˜1Jšœœ˜"—Jšœ˜—Jšœ œ˜Jš˜—Jš˜—Jšœœ˜ Jšœ˜—J˜J˜Jšœœ˜Jšœ˜Jšœ˜J˜—š  œœœœ œ˜BJš˜šœ&œœ˜9Jšœœ%˜CJš˜—Jšœ˜J˜—š   œœœœœ ˜FJšœ9™9Jšœ˜Jšœœ˜šœ œ˜Jšœ œ˜&šœ˜Jšœœ˜0Jšœœ˜—Jšœœ˜Jšœ˜—J˜J˜Jšœœ˜Jšœ˜J˜—š  œœœœ˜4Jšœ-™-Jšœ,™,Jšœ˜J˜Jšœ˜J˜—š  œœœ˜1Jšœ˜J˜Jšœœ˜Jšœœ˜Jšœ˜Jšœ˜J˜—š œœœ˜3Jš˜J˜ J˜ Jšœ/œ˜GJšœ œ˜Jšœ˜J˜—š  œœœ˜1Jš˜Jšœœ˜J˜ J˜ Jšœ'œ˜?Jšœ œ˜Jšœ˜J˜—Jšœ˜J˜J˜J˜J˜J˜—…—¬”