cairo graphics 0.9 intersection II



/* Jeffrin Jose Licensed GPL v3 Copyright
August 2010 GPL --> http://www.gnu.org/copyleft/gpl.html */
// module do_draw

//do_draw will be executed in a separate thread whenever we would like to update
//our animation
void *do_draw(void *ptr){

currently_drawing = 1;

int width, height;
gdk_threads_enter();
gdk_drawable_get_size(pixmap, &width, &height);
gdk_threads_leave();

//create a gtk-independant surface to draw on
cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cairo_t *cr = cairo_create(cst);

//Vertical Line
cairo_move_to(cr, 200,30);
cairo_line_to(cr,200,200);

//Horizontal Line
cairo_move_to(cr, 50,120);
cairo_line_to(cr,350,120);

//do some time-consuming drawing
static int i = 0;
++i; i = i % 300; //give a little movement to our animation
cairo_set_source_rgb (cr, .9, .9, .9);
cairo_paint(cr);
cairo_set_source_rgb (cr, 0.8, 0.5, 0.9);
cairo_move_to(cr, 50,50);
int j,k;
/* for(k=0; k<100; ++k){*/ //lets just redraw lots of times to use a lot of proc power
for(j=0; j < 100; j++){
cairo_set_source_rgb (cr, 0.8, 0.5, 0.9);
cairo_move_to(cr, 100,76);
/* cairo_line_to(cr,200+i,100);*/
/* cairo_arc(cr,300+i,100,4,0, 2*M_PI);*/
/* cairo_arc(cr,70+i,100,40,0,2*M_PI);*/
if ( i < 100)
cairo_arc(cr, 100+i,76,0,0,0);
/* cairo_rectangle(cr,50+i,50+i,50,50); */

cairo_stroke(cr);
}
/* }*/
cairo_destroy(cr);
//When dealing with gdkPixmap's, we need to make sure not to
//access them from outside gtk_main().
gdk_threads_enter();

cairo_t *cr_pixmap = gdk_cairo_create(pixmap);
cairo_set_source_surface (cr_pixmap, cst, 0, 0);
cairo_paint(cr_pixmap);
cairo_destroy(cr_pixmap);

gdk_threads_leave();

cairo_surface_destroy(cst);

currently_drawing = 0;

return NULL;
}

deadlock

Dead lock

Nonatomic actions introduce the possibility that the protocol can
deadlock, meaning that it reaches a state where it cannot continue.

Now, on the context of congestion control deadlock is acheived
when the packets in the interconnect can make no forward progress
no matter what sequence of events happens.

References :
Snooping Protocols.
Congestion Control.
Computer Architecture: A Quantitative Approach, Third Edition

cairo graphics 0.8 (intersection)



/* Jeffrin Jose Licensed GPL v3 Copyright
August 2010 GPL --> http://www.gnu.org/copyleft/gpl.html */

#include
#include
#include
#include

//the global pixmap that will serve as our buffer
static GdkPixmap *pixmap = NULL;

gboolean on_window_configure_event(GtkWidget * da, GdkEventConfigure * event, gpointer user_data){
static int oldw = 0;
static int oldh = 0;
//make our selves a properly sized pixmap if our window has been resized
if (oldw != event->width || oldh != event->height){
//create our new pixmap with the correct size.
GdkPixmap *tmppixmap = gdk_pixmap_new(da->window, event->width, event->height, -1);
//copy the contents of the old pixmap to the new pixmap. This keeps ugly uninitialized
//pixmaps from being painted upon resize
int minw = oldw, minh = oldh;
if( event->width width; }
if( event->height height; }
gdk_draw_drawable(tmppixmap, da->style->fg_gc[GTK_WIDGET_STATE(da)], pixmap, 0, 0, 0, 0, minw, minh);
//we're done with our old pixmap, so we can get rid of it and replace it with our properly-sized one.
g_object_unref(pixmap);
pixmap = tmppixmap;
}
oldw = event->width;
oldh = event->height;
return TRUE;
}

gboolean on_window_expose_event(GtkWidget * da, GdkEventExpose * event, gpointer user_data){
gdk_draw_drawable(da->window,
da->style->fg_gc[GTK_WIDGET_STATE(da)], pixmap,
// Only copy the area that was exposed.
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height);
return TRUE;
}

static int currently_drawing = 0;
//do_draw will be executed in a separate thread whenever we would like to update
//our animation
void *do_draw(void *ptr){

currently_drawing = 1;

int width, height;
gdk_threads_enter();
gdk_drawable_get_size(pixmap, &width, &height);
gdk_threads_leave();

//create a gtk-independant surface to draw on
cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cairo_t *cr = cairo_create(cst);

cairo_move_to(cr, 400,30);
cairo_line_to(cr,400,200);

//do some time-consuming drawing
static int i = 0;
++i; i = i % 300; //give a little movement to our animation
cairo_set_source_rgb (cr, .9, .9, .9);
cairo_paint(cr);
cairo_set_source_rgb (cr, 0.8, 0.5, 0.9);
cairo_move_to(cr, 50,50);

int j,k;
/* for(k=0; k<100; ++k){*/ //lets just redraw lots of times to use a lot of proc power
for(j=0; j window,700,700,-1);
//because we will be painting our pixmap manually during expose events
//we can turn off gtk's automatic painting and double buffering routines.
gtk_widget_set_app_paintable(window, TRUE);
gtk_widget_set_double_buffered(window, FALSE);

(void)g_timeout_add(33, (GSourceFunc)timer_exe, window);

gtk_main();
gdk_threads_leave();

return 0;
}

window size and…

Window

The set of instructions that is examined for simultaneous execution
is called the window.Each instruction in the window must be kept in
the processor,and the number of comparisons required every clock is
equal to the maximum completion rate times the window size times
the number of operands per instruction (typically 6 * 80 * 2), since
every pending instruction must look at every completing instruction.

Reference :
Limitations on the Window Size and Maximum Issue Count.
Computer Architecture: A Quantitative Approach, Third Edition

cairo graphics 0.7 wheel



/* Jeffrin Jose Licensed GPL v3 Copyright
August 2010 GPL --> http://www.gnu.org/copyleft/gpl.html */

#include
#include
#include
#include

//the global pixmap that will serve as our buffer
static GdkPixmap *pixmap = NULL;

gboolean on_window_configure_event(GtkWidget * da, GdkEventConfigure * event, gpointer user_data){
static int oldw = 0;
static int oldh = 0;
//make our selves a properly sized pixmap if our window has been resized
if (oldw != event->width || oldh != event->height){
//create our new pixmap with the correct size.
GdkPixmap *tmppixmap = gdk_pixmap_new(da->window, event->width, event->height, -1);
//copy the contents of the old pixmap to the new pixmap. This keeps ugly uninitialized
//pixmaps from being painted upon resize
int minw = oldw, minh = oldh;
if( event->width width; }
if( event->height height; }
gdk_draw_drawable(tmppixmap, da->style->fg_gc[GTK_WIDGET_STATE(da)], pixmap, 0, 0, 0, 0, minw, minh);
//we're done with our old pixmap, so we can get rid of it and replace it with our properly-sized one.
g_object_unref(pixmap);
pixmap = tmppixmap;
}
oldw = event->width;
oldh = event->height;
return TRUE;
}

gboolean on_window_expose_event(GtkWidget * da, GdkEventExpose * event, gpointer user_data){
gdk_draw_drawable(da->window,
da->style->fg_gc[GTK_WIDGET_STATE(da)], pixmap,
// Only copy the area that was exposed.
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height);
return TRUE;
}

static int currently_drawing = 0;
//do_draw will be executed in a separate thread whenever we would like to update
//our animation
void *do_draw(void *ptr){

currently_drawing = 1;

int width, height;
gdk_threads_enter();
gdk_drawable_get_size(pixmap, &width, &height);
gdk_threads_leave();

//create a gtk-independant surface to draw on
cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cairo_t *cr = cairo_create(cst);

//do some time-consuming drawing
static int i = 0;
++i; i = i % 300; //give a little movement to our animation
cairo_set_source_rgb (cr, .9, .9, .9);
cairo_paint(cr);
cairo_set_source_rgb (cr, 0.8, 0.5, 0.9);
cairo_move_to(cr, 50,50);

int j,k;
/* for(k=0; k<100; ++k){*/ //lets just redraw lots of times to use a lot of proc power
for(j=0; j window,700,700,-1);
//because we will be painting our pixmap manually during expose events
//we can turn off gtk's automatic painting and double buffering routines.
gtk_widget_set_app_paintable(window, TRUE);
gtk_widget_set_double_buffered(window, FALSE);

(void)g_timeout_add(33, (GSourceFunc)timer_exe, window);

gtk_main();
gdk_threads_leave();

return 0;
}

Notes

pixmap - (Contraction of "pixel map"). A 3 dimensional array of bits
corresponding to a 2 dimensional array of pixels. It is used, for example,
in the X Window System to describe a memory region where graphics
can be drawn without affecting the screen. Typically this is used for the
efficient handling of expose events, icon images or for animation.

Reference :
http://encyclopedia2.thefreedictionary.com/pixmap

loop-level parallelism

loop level parallelism

The simplest and the common way to increase the
amount of parallelism available among instructions
is to exploit parallelism among iterations of a loop.
This type of parallelism is often called loop-level
parallelism. Here is a simple example of a loop, which
adds two 1000-element arrays that is completely
parallel.


for (i=1;i<= 1000; i=i+1)
x[i] = x[i] + y[i]

Every iteration of the loop can overlap with
any other iteration although within each loop
iteration there is little or no oppurtunity for overlap.

Reference :
Instruction-Level Parallelism: Concepts and Challenges.
Computer Architecture: A Quantitative Approach, Third Edition

cairo graphics 0.6 Circle animation



/* Jeffrin Jose Licensed GPL v3 Copyright
August 2010 GPL --> http://www.gnu.org/copyleft/gpl.html */

#include
#include
#include

//the global pixmap that will serve as our buffer
static GdkPixmap *pixmap = NULL;

gboolean on_window_configure_event(GtkWidget * da, GdkEventConfigure * event, gpointer user_data){
static int oldw = 0;
static int oldh = 0;
//make our selves a properly sized pixmap if our window has been resized
if (oldw != event->width || oldh != event->height){
//create our new pixmap with the correct size.
GdkPixmap *tmppixmap = gdk_pixmap_new(da->window, event->width, event->height, -1);
//copy the contents of the old pixmap to the new pixmap. This keeps ugly uninitialized
//pixmaps from being painted upon resize
int minw = oldw, minh = oldh;
if( event->width width; }
if( event->height height; }
gdk_draw_drawable(tmppixmap, da->style->fg_gc[GTK_WIDGET_STATE(da)], pixmap, 0, 0, 0, 0, minw, minh);
//we're done with our old pixmap, so we can get rid of it and replace it with our properly-sized one.
g_object_unref(pixmap);
pixmap = tmppixmap;
}
oldw = event->width;
oldh = event->height;
return TRUE;
}

gboolean on_window_expose_event(GtkWidget * da, GdkEventExpose * event, gpointer user_data){
gdk_draw_drawable(da->window,
da->style->fg_gc[GTK_WIDGET_STATE(da)], pixmap,
// Only copy the area that was exposed.
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height);
return TRUE;
}

static int currently_drawing = 0;
//do_draw will be executed in a separate thread whenever we would like to update
//our animation
void *do_draw(void *ptr){

currently_drawing = 1;

int width, height;
gdk_threads_enter();
gdk_drawable_get_size(pixmap, &width, &height);
gdk_threads_leave();

//create a gtk-independant surface to draw on
cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
cairo_t *cr = cairo_create(cst);

//do some time-consuming drawing
static int i = 0;
++i; i = i % 300; //give a little movement to our animation
cairo_set_source_rgb (cr, .9, .9, .9);
cairo_paint(cr);
cairo_set_source_rgb (cr, 0.8, 0.5, 0.9);
cairo_move_to(cr, 50,50);

int j,k;
/* for(k=0; k<100; ++k){*/ //lets just redraw lots of times to use a lot of proc power
for(j=0; j window,700,700,-1);
//because we will be painting our pixmap manually during expose events
//we can turn off gtk's automatic painting and double buffering routines.
gtk_widget_set_app_paintable(window, TRUE);
gtk_widget_set_double_buffered(window, FALSE);

(void)g_timeout_add(33, (GSourceFunc)timer_exe, window);

gtk_main();
gdk_threads_leave();

return 0;
}

context switch

context switch

Multiprogramming leads to the concept of a process.
Metaphorically,a process is a program's breathing air
and living space-that is,a running program plus any
state needed to continue running it.Time- sharing is
a variation of multi-programming that shares the CPU
and memory with several interactive users at the same
time, giving the illusion that all users have their own
computers. Thus at any instance it should be possible
to switch from one process to another. This exchange
is called a process switch or context switch.

Reference:
Protection and Examples of Virtual Memory.
Computer Architecture: A Quantitative Approach, Third Edition

cairo graphics 0.5 (arc )



/* Jeffrin Jose Licensed GPL v3 Copyright
August 2010 GPL --> http://www.gnu.org/copyleft/gpl.html */

#include

int
main ()
{
int i;
cairo_surface_t *surface =
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 800, 600);
cairo_t *cr =
cairo_create (surface);

cairo_set_font_size (cr, 32.0);
cairo_set_source_rgb (cr, 0.3, 0.8, 0.7);
cairo_set_line_width(cr,1.0);

for (i=0;i<100;i++)
{
/* cairo_move_to(cr,30+i,60);
cairo_line_to(cr,30+i,60+i);*/
/* cairo_rectangle(cr,100,100,10+i,10+i);*/
cairo_arc(cr,100,100,60,50,10);
/* cairo_line_to(cr,40,200); */

cairo_stroke(cr);
/* cairo_surface_flush(surface); */
/* usleep(100000);*/
}

/* cairo_rectangle(cr,30,20,67,70);*/
/* cairo_stroke(cr);*/

cairo_destroy (cr);
cairo_surface_write_to_png (surface, "imagecairo-arc.png");
cairo_surface_destroy (surface);
return 0;
}

Output

https://beautifulworknew.wordpress.com/wp-content/uploads/2021/03/05e40-cairoarc1.pngwp-content/uploads/2010/08/imagecairo-arc.png

cairo graphics 0.4 (line work animation)



/* http://cairographics.org/threaded_animation_with_cairo/ */
/* Hack by Jeffrin Jose Licensed GPL v3 Copyright
August 2010 GPL --> http://www.gnu.org/copyleft/gpl.html */

#include
#include
#include

//the global pixmap that will serve as our buffer
static GdkPixmap *pixmap = NULL;

gboolean on_window_configure_event(GtkWidget * da,
GdkEventConfigure * event, gpointer user_data){
static int oldw = 0;
static int oldh = 0;
//make our selves a properly sized pixmap if our window has been
resized
if (oldw != event->width || oldh != event->height){
//create our new pixmap with the correct size.
GdkPixmap *tmppixmap = gdk_pixmap_new(da->window, event->width,
event->height, -1);
//copy the contents of the old pixmap to the new pixmap. This keeps
ugly uninitialized
//pixmaps from being painted upon resize
int minw = oldw, minh = oldh;
if( event->width width; }
if( event->height height; }
gdk_draw_drawable(tmppixmap, da->style-
>fg_gc[GTK_WIDGET_STATE(da)], pixmap, 0, 0, 0, 0, minw, minh);
//we're done with our old pixmap, so we can get rid of it and replace it
with our properly-sized one.
g_object_unref(pixmap);
pixmap = tmppixmap;
}
oldw = event->width;
oldh = event->height;
return TRUE;
}

gboolean on_window_expose_event(GtkWidget * da, GdkEventExpose *
event, gpointer user_data){
gdk_draw_drawable(da->window,
da->style->fg_gc[GTK_WIDGET_STATE(da)], pixmap,
// Only copy the area that was exposed.
event->area.x, event->area.y,
event->area.x, event->area.y,
event->area.width, event->area.height);
return TRUE;
}

static int currently_drawing = 0;
//do_draw will be executed in a separate thread whenever we would like
to update
//our animation
void *do_draw(void *ptr){

currently_drawing = 1;

int width, height;
gdk_threads_enter();
gdk_drawable_get_size(pixmap, &width, &height);
gdk_threads_leave();

//create a gtk-independant surface to draw on
cairo_surface_t *cst = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
width, height);
cairo_t *cr = cairo_create(cst);

//do some time-consuming drawing
static int i = 0;
++i; i = i % 300; //give a little movement to our animation
cairo_set_source_rgb (cr, .9, .9, .9);
cairo_paint(cr);
cairo_set_source_rgb (cr, 0.8, 0.5, 0.9);
cairo_move_to(cr, 50,50);

int j,k;
/* for(k=0; k<100; ++k){*/ //lets just redraw lots of times to use a
lot of proc power
for(j=0; j window,700,700,-1);
//because we will be painting our pixmap manually during expose events
//we can turn off gtk's automatic painting and double buffering routines.
gtk_widget_set_app_paintable(window, TRUE);
gtk_widget_set_double_buffered(window, FALSE);

(void)g_timeout_add(33, (GSourceFunc)timer_exe, window);

gtk_main();
gdk_threads_leave();

return 0;
}