aboutsummaryrefslogtreecommitdiff
path: root/sys/gio/cursor/doc/giotr.notes
blob: a9221445b05d50e9a5f3a7fc909db7ecf72533cb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
.help GIO Feb85 "Graphics I/O"
.nh
Graphics I/O Dataflow

    The GIO procedures are resident in an external applications task which
does graphics.  GIO writes a GKI instruction stream which, if not sent directly
to a metafile, is sent to one of the standard graphics streams STDGRAPH,
STDIMAGE, or STDPLOT, much as output is sent to STDOUT or STDERR.
The procedure \fBprfilbuf\fR (directory etc$), which reads the command
stream from a subprocess, is resident in the CL and executes all pseudofile
i/o instructions from a subprocess.  Note that \fBprfilbuf\fR is part of the
i/o system of IRAF and operates transparently to the CL.


.ks
.nf
	     GIO(task) ---ipc--> PRFILBUF(CL) --> file (or pipe)
				     |
				     v             external
				   GIOTR ---ipc--> graphics
				     |              kernel
				     v
			       stdgraph kernel
				     |
				     v
				  (zfioty)
			      graphics terminal


		   task     |        cl       |     task
.fi

.ce
Graphics Output Dataflow
.ke


The \fBprfilbuf\fR procedure passes record read or write requests for the
pseudofiles STDIN, STDOUT or STDERR on to file descriptors assigned by the
CL with the \fBprredir\fR procedure at task execution time.  The sole function
of the CL in graphics i/o is to control the redirection of the graphics
i/o streams with \fBprredir\fR.  The CL may redirect any of the graphics
streams, i.e., the user may redirect any graphics stream on the command line
when a command is entered, but by default output is directed to a filter
resident in the CL process.  This filter is a procedure named \fBgiotr\fR.

	giotr (stream, buffer, nchars)

The primary function of GIOTR is to pass metacode instructions on to a kernel.
The instruction stream is scanned and special actions are taken for some of
the GKI control instructions.  In particular, GIOTR must spawn graphics kernel
subprocesses upon demand.  GIOTR is also capabable of performing an
additional transformation upon the drawing instructions before they are passed
to the kernel.  This transformation, known as the \fBworkstation
transformation\fR, maps a rectangular portion of the NDC space into the full
device screen, clipping at the boundary of the viewport into NDC space.
The workstation transformation provides a zoom and pan capability and is
controlled interactively by the user in \fBcursor mode\fR (section 3.3).

As noted earlier, the \fBstdgraph kernel\fR ("fast" kernel) is resident in
the CL process.  This is necessary for efficiency reasons and is desirable
in any case because the CL process owns the graphics device, i.e., the
graphics terminal.  All devices except the user's graphics terminal are
controlled by external graphics kernel processes.  The STDGRAPH kernel is
itself available as an external process and may be called as such to drive
a graphics terminal other than the user terminal (or even to drive the user
terminal if one is willing to shuffle output back through IPC).  A graphics
kernel may support an arbitrary number of devices, and may write to more
than one device simultaneously.  In addition to being called by GIOTR,
a graphics kernel may be called directly as a CL task to process metacode from
either a file or the standard input, e.g., from a pipe.  This offers
additional flexibility as the CL parameter mechanism may then be used to
gain control over metacode translation.

.nh 2
Graphics Stream I/O

    The functions performed by GIOTR are summarized in pseudocode below.
GIOTR maintains a separate descriptor for each of the three graphics streams
and is capable of servicing intermixed i/o requests for all streams
simultaneously.  The information stored in the descriptor
includes the workstation name, process information, WCS storage for
the SETWCS and GETWCS instructions, the workstation transformation,
and the frame buffer, used to spool GKI instructions for cursor mode.


.tp 6
.nf
procedure giotr (fd, buffer, nchars)

fd		graphics stream (STDGRAPH, etc.)
buffer[]	buffer containing GKI metacode instructions
nchars		number of chars to be read or written

begin
	# Note that a GKI instruction may span a buffer boundary.
	# The code which gets the next instruction from the buffer
	# must always return a full instruction, hence some local
	# buffering is required therein to reconstruct instructions.

	while (get next instruction != buffer empty) {

	    # Handle special instructions.
	    switch (instruction) {

	    case GKI_OPENWS:
		if (device not already open) {
		    read graphcap entry for device
		    get process name from graphcap entry
		    if (process not already connected) {
			if (some other process is connected)
			    disconnect current kernel process
			connect new kernel process
		    }
		}
		output instruction
		flush output
		clear frame buffer

	    case GKI_CLOSEWS, GKI_FLUSH:
		output instruction
		flush output

	    case GKI_CANCEL:
		output instruction
		flush output
		clear frame buffer

	    case GKI_SETWCS:
		save WCS in descriptor

	    case GKI_GETWCS:
		write saved WCS to fd
		flush (fd)

	    default:
		append unmodified instruction to frame buffer
		perform workstation transformation upon instruction
		output transformed instruction
	    }
	}
end
.fi


The action implied by "output instruction" above is the following:


.ks
.nf
	if (kernel is resident in this process)
	    call gki_execute to execute the instruction
	else
	    call write (process, instruction, nchars)
.fi
.ke


The frame buffer (required for cursor mode) will be dynamically allocated and
will be no larger than it has to be, but will have a fixed (user defined)
upper limit, e.g., 128Kb.  The median size for a plot is typically 5-10Kb.
Instructions will be silently discarded if the buffer grows too large.
Buffering can be turned off completely if desired, and will always be turned
off for STDPLOT.

.nh 2
Cursor Mode Details

    Most of the functionality required to implement cursor mode is provided
by GIOTR.  The primary functions of the cursor mode code are to read the
cursor and keystroke, modify the workstation transformation, and redraw the
contents of the frame buffer subject to the new workstation transformation.
Cursor mode does not modify the contents of the frame buffer, except for
possibly appending new graphics instructions to the frame buffer.
A workstation transformation set with cursor mode remains in effect until
the frame buffer is cleared, hence any additional graphics output from the
task which initiated the cursor read (and cursor mode) will undergo the
workstation transformation when drawn.


.nf
# PR_FILBUF -- Fill FIO buffer from an IPC channel subject to the CL/IPC
# protocol for multiplexing pseudofile data streams with the command stream.
# Each process has an associated set of pseudofile streams.  Each pseudofile
# stream is connected to one, and only one, file or pseudofile of another
# process.  I/O requests to XMIT or XFER to an ordinary file are straightforward
# to satisfy.  An i/o request from one pseudofile to another is satisfied
# by posting the request (pushing it on a stack) and redirecting our input
# to the process owning the pseudofile being read or written.  Pseudofile
# requests are then processed from the second process until a request is
# received which satisfies the posted request from the original process.
# When the original request is satisfied it is popped from the stack and input
# will again be taken from the original process.  Note that we cannot write
# directly to the output process since that would violate the IPC protocol
# (the second process may wish to write to its stdout or stderr rather than
# read, etc.: the process must be allowed to complete the original request
# itself).
#
# Request Packet (pushed onto stack for IPC to IPC i/o).
# 
# 	pr		process slot number of process placing the request
# 	iomode		request is a read or a write
# 	count		number of chars to be transferred
# 	ps_server	pseudofile number in server process
# 	ps_receiver	pseudofile number in receiver process
#
# The request packet describes a pending pseudofile i/o request.  The named
# pseudofile in the server process is either reading from or writing to the
# named pseudofile in the receiver process.

int procedure pr_filbuf (fd)

begin
	input = fd (the IPC input channel of a process)

	repeat {
	    get a line from the input file
	    if (neither XMIT nor XFER directive)
		if (request pending)
		    error: IPC protocol corrupted
		else
		    return command

	    if (line is an XMIT directive) {
		if (destination is a file) {
		    # Write from pseudofile to an ordinary file.
		    get data record from input
		    write data record to file

		} else {
		    # Write from pseudofile to another pseudofile.
		    if (XMIT satisfies XFER request on top of stack)
			get data record from input
			write record to stacked process
			restore input to stacked process
			pop request from stack

		    } else {
			# If writing to local kernel GIOTR will return a null
			# length record and we are done.

			get data record from input
			if (writing to a graphics stream)
			    call giotr filter to transform record
			if (anything left to output) {
			    push request on stack
			    switch input to IPC input of receiver process
			}
		    }
		}

	    } else if (line is an XFER directive) {
		if (source is an ordinary file) {
		    # Read from a file.
		    read data record from file
		    write to active process

		} else if (source is another process) {
		    # Read from another pseudofile.
		    if (XFER satisfies XMIT request on top of stack) {
			read record from stacked process
			write to active process
			restore input to stacked process
			pop request from stack
		    } else {
			push request on stack
			switch input to IPC input channel of receiver process
		    }
		}
	    }
	}
end


# GIOTR -- Graphics i/o filter.

procedure giotr (fd, buffer, nchars)

fd		graphics stream (STDGRAPH, etc.)
buffer[]	buffer containing GKI metacode instructions
nchars		number of chars to be read or written

begin
	# Note that a GKI instruction may span a buffer boundary.
	# The code which gets the next instruction from the buffer
	# must always return a full instruction, hence some local
	# buffering is required therein to reconstruct instructions.

	while (buffer not empty) {

	    # Handle special instructions.
	    switch (next_instruction) {

	    case GKI_OPENWS:
		if (device not already open) {
		    read graphcap entry for device
		    get process name from graphcap entry
		    if (process not already connected) {
			if (some other process is connected)
			    disconnect current kernel process
			connect new kernel process
		    }
		}
		output instruction
		flush output
		clear frame buffer

	    case GKI_CLOSEWS, GKI_FLUSH:
		output instruction
		flush output

	    case GKI_CANCEL:
		output instruction
		flush output
		clear frame buffer

	    case GKI_SETWCS:
		save WCS in descriptor

	    case GKI_GETWCS:
		write saved WCS to fd
		flush (fd)

	    default:
		append unmodified instruction to frame buffer
		perform workstation transformation upon instruction
		output transformed instruction
	    }
	}
end