[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference bulova::decw_jan-89_to_nov-90

Title:DECWINDOWS 26-JAN-89 to 29-NOV-90
Notice:See 1639.0 for VMS V5.3 kit; 2043.0 for 5.4 IFT kit
Moderator:STAR::VATNE
Created:Mon Oct 30 1989
Last Modified:Mon Dec 31 1990
Last Successful Update:Fri Jun 06 1997
Number of topics:3726
Total number of notes:19516

3513.0. "Many colors - one graphics context?" by GLORY::MATERNA () Tue Oct 23 1990 17:15

    Is there a way to draw graphs using different colors in the same
    graphics context using Xwindows?
    
    I am creating a strip chart with eight consecutive graphs scrolling in
    a single window.  Right now, the chart uses eight separate graphics
    contexts in this window to allow eight separate colors to be used.
    This is very slow, and I'd like to speed it up.
    
                       f
    Bill
T.RTitleUserPersonal
Name
DateLines
3513.1Time to look a little deeperLOWELL::KLEINTue Oct 23 1990 18:2020
It is unlikely that your performance problem is caused by using separate
GCs.  In fact, this is probably the best way to do it.  You could use a
single GC, and change its colors (foreground/background) dynamically, but
this would only result in more overhead, not less.

Can you describe the performance problems you're having?  Does it seem
related to the scrolling or to the drawing?  How are you drawing the lines?
Are you calling XDrawPoint, XDrawLine, or what?  How are you doing the
scrolling?  XCopyArea?

Have you tried doing the same program but (temporarily) have all the draw
operations use the same GC?  Of course you won't get multiple colors, but
at least you'll be able to eliminate that factor to narrow down on your
performance problem.  If it gets faster, then it may in fact be related
to the multiple GCs.  If it is still slow, then we need to look somewhere
else.

Feel free to post some code fragments if you think that would help.

-steve-
3513.2code, code, codeGLORY::MATERNAWed Oct 24 1990 11:09119
    
    
    
    
    Steve,
    
    
    The slowdown in performance comes from the difference between using the
    X$DRAW_LINE call for each GC and using the X$DRAW_SEGMENTS for
    submitting several lines to be drawn in one call.  The program segment
    here is basically how I tested this difference, and I found that the
    X$DRAW_LINE loop took about 10-15% longer than the X$DRAW_SEGMENTS
    loop, all things being equal.  I haven't gotten into the scrolling
    routines yet, but from what I've read, it will probably be using a
    X$COPY_AREA call, which will mean separate calls for each GC.  I
    anticipate a lot of difference here when I need eight calls instead of
    one!  I guess what I'm looking for is a way to plot in different colors
    using the same GC so that when the time comes for scrolling, I'll only
    need to do the one 'cut' and 'paste'.
    
    
    
    Thanks for replying so fast Steve!  I hope the Fortran doesn't scare
    you away...
    
    
    Bill
    
    
    
    *R*  y_n_colors is set to .FALSE. to run the single-color loop
    *R*  y_n_colors is set to .TRUE. to run the multi-color loop
    *R*  Test data is contained in data(1..8,1..1000)
    *R*      the first argument is the plot number, the second is the data
    *R*  x_mult, y_mult, window_y_len, num_axis are all used to calculate
    *R*       the appropriate coordinates for the point to plot
    *R*  which_axis(1..8) is an array telling which axis a particular plot
    *R*       will be drawn on (i.e. plots can be drawn on any of 8 axes)
    *R*       Each array element contains a # from 1-8 telling which axis
    *R*       that plot will be drawn on.
    *R*  num_axis is the total number of axes on the screen
    
    
    	DO x_count=1,full_screen
    
		IF (.NOT. y_n_colors) THEN

*R* Single color......

		    DO plot_count = 1,num_plots

		    new_y(plot_count) = 
	1		data(which_plot(plot_count),x_count)

		    xvlist(plot_count).x$w_gseg_x1 = 
	1	       NINT(x_mult(plot_type) * (x_count - 1) *
	1	       x_density)

		    xvlist(plot_count).x$w_gseg_y1 = 
	1	       NINT((0.5 * y_mult(plot_type) * old_y(plot_count)
	1	       + window_y_len(plot_type) * which_axis(plot_count)) /
	1	       (num_axis + 1))

		    xvlist(plot_count).x$w_gseg_x2 = 
	1      	       NINT(x_mult(plot_type) * x_count *
	1	       x_density)

		    xvlist(plot_count).x$w_gseg_y2 = 
	1	       NINT((0.5 * y_mult(plot_type) * new_y(plot_count)
	1	       + window_y_len(plot_type) * which_axis(plot_count)) /
	1	       (num_axis + 1))

		    old_y(plot_count) = new_y(plot_count)

		    END DO

*R*  Draw batched segments

		    CALL x$draw_segments( display, window_id, gc_id(1),
	1		xvlist,num_plots )

		ELSE

*R* Multiple colors......

		DO plot_count = 1,num_plots

		    new_y(plot_count) = 
	1		data(which_plot(plot_count),x_count) 
		       first_x =
	1	       NINT(x_mult(plot_type) * (x_count - 1) *
	1	       x_density)

		       first_y =
	1	       NINT((0.5 * y_mult(plot_type) * old_y(plot_count)
	1	       + window_y_len(plot_type) * which_axis(plot_count)) /
	1	       (num_axis + 1))

		       second_x =
	1	       NINT(x_mult(plot_type) * x_count *
	1	       x_density)

		       second_y =
	1	       NINT((0.5 * y_mult(plot_type) * new_y(plot_count)
	1	       + window_y_len(plot_type) * which_axis(plot_count)) /
	1	       (num_axis + 1))

		    old_y(plot_count) = new_y(plot_count)

*R*  Draw a single line

		    CALL x$draw_line( display, window_id, gc_id(plot_count),
	1		first_x,first_y,second_x,second_y )

		END DO
    
          END DO
    
    
3513.3one XCopyArea will cover all your colorsOXNARD::KLEEKen LeeWed Oct 24 1990 14:066
    You should be able to XCopyArea() the whole thing with one GC. 
    XCopyArea() does not use the foreground and background pixels from the
    GC.
    
    Ken
    
3513.4Thanks...GLORY::MATERNAWed Oct 24 1990 15:109
    RE .3
    
    You're right, Ken.  After some tinkering with X$COPY_AREA, I notice
    that it takes not only what was drawn in the GC you specify, but all
    graphics within the area.
    
    Thanks for the help.
    
    Bill
3513.5Inside-out loops?LOWELL::KLEINWed Oct 24 1990 15:4315
It seems that you are drawing all 8 plots at once - drawing
one segment from each plot, and then moving to the second segment from
each plot, and so forth.

If this is true, you should turn your double loop inside-out.  Draw all of
the first plot, then all of the second plot, etc.  Still use XDrawSegments
(or XDrawLines, which should be even more efficient) for all the segments
comprising a single plot.

Watch out for XLib bugs in calls that pass more
than ??? points - there were problems splitting the request if it
exceeded the maximum transport message length.  Stick with, say, 512 points
per requeust and you should not have any trouble.

-steve-