Re: Question about the GdkGC



Tom Liu wrote:

Ok I understand why create GdkGC and use GdkGC both need the GdkDrawable
parameter because one created GC can apply to multiple window.

But how about the performance?
I saw a program need to draw 10 color on a drawable. They just create 10
GC! And they nevery release these GC.
It this right way to do so? Should I create one GC and change the colors
when need it?

I am a windows programmer, usually when I need to draw something in the
window, I just get a gc, change color, draw, change color back, release
gc.

Looks gtk work like this. Create multiple GC, use these when needed over and over again.
This is a question about load balancing and resource consumtion; I really suggest
that the application developer (you) consider the context of the application
before deciding what is the optimal proceedure.

If you rarely ever need to draw; you might want to <allocate-setup colours-draw-release> If you want to maintain a framerate; you might want to have multiple GC's ready and just <draw> You might also come to the conclusion that in your application; having a few GC's always present is a negligable amount of memory to "waste" and do it what ever way is fastest to develop ;-)

Regards,
                               -Tristan




-----Original Message-----
From: gtk-app-devel-list-admin gnome org
[mailto:gtk-app-devel-list-admin gnome org] On Behalf Of Tristan Van
Berkom
Sent: Wednesday, November 12, 2003 11:56 AM
To: Tom Liu
Cc: gtk-app-devel-list gnome org
Subject: Re: Question about the GdkGC

Tom Liu wrote:

When I create a GdkGC, I have to give a GdkDrawable to attach this GC,
But when I draw line or rectangle, I still need the GdkDrawable as
parameter.

You need to provide a GdkDrawable so that the GdkGC can reference a
colormap; the colormap is created when you create a GdkDrawable
and; if I'm not mistaken; thats because creating the colormap requires
some knowlage of the rendering architechture (Win or XFree86)
(and thats handled at the GdkDrawable level).

Is these because one GdkGC can work on multile GdkDrawable after it
created?


Yes it can.

Another question: the CreateGC and releaseGC is a expensive job? Should
I create and release it every time I need to draw or just keep a global
copy for better performance.


A GdkGC is like a structure that holds a bunch of paramaters
to draw with when using any GdkDrawables; instead of passing
alot of arguments to the drawing functions; the arguments that
probably won't change from one function call to the next; are
stored in the graphics context.

Does that help ?

Regards,
                                               -Tristan







[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]