int timer_activate( PtWidget_t *widget, ApInfo_t *apinfo, PtCallbackInfo_t *cbinfo ) { PtArg_t args[1]; float diffsum; clock_t diff_time; isd_poll_all(isdx, &yaw, &pitch, &roll); iyaw = floor(yaw); ipitch = floor(pitch); iroll = floor(roll); PtSetArg(&args[0], Pt_ARG_GAUGE_VALUE, iyaw, 0); PtSetResources(ABW_yaw_meter, 1, args); PtSetArg(&args[0], Pt_ARG_GAUGE_VALUE, ipitch, 0); PtSetResources(ABW_pitch_meter, 1, args); PtSetArg(&args[0], Pt_ARG_GAUGE_VALUE, iroll, 0); PtSetResources(ABW_roll_meter, 1, args); sprintf(yaw_label, "%7.2f", yaw); sprintf(pitch_label, "%7.2f", pitch); sprintf(roll_label, "%7.2f", roll); PtSetArg(&args[0], Pt_ARG_TEXT_STRING, &yaw_label, 1); PtSetResources(ABW_yaw_label, 1, args); PtSetArg(&args[0], Pt_ARG_TEXT_STRING, &pitch_label, 1); PtSetResources(ABW_pitch_label, 1, args); PtSetArg(&args[0], Pt_ARG_TEXT_STRING, &roll_label, 1); PtSetResources(ABW_roll_label, 1, args); diffsum = abs(yaw - lastyaw); diffsum += abs(pitch - lastpitch); diffsum += abs(roll - lastroll); if (diffsum >= REDRAW_THRESHOLD) { lastyaw = yaw; lastpitch = pitch; lastroll = roll; PtDamageWidget(ABW_rawcube); PtFlush(); } last_time = this_time; this_time = clock(); diff_time = this_time - last_time; sprintf(timestring, "%d Hz", CLOCKS_PER_SEC/diff_time); PtSetArg(&args[0], Pt_ARG_TEXT_STRING, ×tring, 1); PtSetResources(ABW_rate_label, 1, args); /* eliminate 'unreferenced' warnings */ widget = widget, apinfo = apinfo, cbinfo = cbinfo; return( Pt_CONTINUE ); }
NS_IMETHODIMP nsWidget::InvalidateRegion( const nsIRegion *aRegion, PRBool aIsSynchronous ) { PhTile_t *tiles = NULL; aRegion->GetNativeRegion( ( void*& ) tiles ); if( tiles ) { PhTranslateTiles( tiles, &mWidget->area.pos ); PtDamageTiles( mWidget, tiles ); if( aIsSynchronous ) PtFlush( ); } return NS_OK; }
NS_METHOD nsWidget::Invalidate( PRBool aIsSynchronous ) { // mWidget will be null during printing if( !mWidget || !PtWidgetIsRealized( mWidget ) ) return NS_OK; PtWidget_t *aWidget = (PtWidget_t *)GetNativeData(NS_NATIVE_WIDGET); PtDamageWidget( aWidget ); if( aIsSynchronous ) PtFlush(); return NS_OK; }
NS_METHOD nsWidget::Invalidate( const nsRect & aRect, PRBool aIsSynchronous ) { if( !mWidget ) return NS_OK; // mWidget will be null during printing if( !PtWidgetIsRealized( mWidget ) ) return NS_OK; PhRect_t prect; prect.ul.x = aRect.x; prect.ul.y = aRect.y; prect.lr.x = prect.ul.x + aRect.width - 1; prect.lr.y = prect.ul.y + aRect.height - 1; if( ! ( mWidget->class_rec->flags & Pt_DISJOINT ) ) PhTranslateRect( &prect, &mWidget->area.pos ); PtDamageExtent( mWidget, &prect ); if( aIsSynchronous ) PtFlush( ); return NS_OK; }
static int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags) { PhDim_t dim; uint64_t OGLAttrib[PH_OGL_MAX_ATTRIBS]; int exposepost=0; int OGLargc; dim.w=width; dim.h=height; if ((oglctx!=NULL) && (oglflags==flags) && (oglbpp==bpp)) { PdOpenGLContextResize(oglctx, &dim); PhDCSetCurrent(oglctx); return 0; } else { if (oglctx!=NULL) { PhDCSetCurrent(NULL); PhDCRelease(oglctx); oglctx=NULL; exposepost=1; } } OGLargc=0; if (this->gl_config.depth_size) { OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DEPTH_BITS; OGLAttrib[OGLargc++]=this->gl_config.depth_size; } if (this->gl_config.stencil_size) { OGLAttrib[OGLargc++]=PHOGL_ATTRIB_STENCIL_BITS; OGLAttrib[OGLargc++]=this->gl_config.stencil_size; } OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FORCE_SW; if (flags & SDL_FULLSCREEN) { OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN; OGLAttrib[OGLargc++]=PHOGL_ATTRIB_DIRECT; OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_BEST; OGLAttrib[OGLargc++]=PHOGL_ATTRIB_FULLSCREEN_CENTER; } OGLAttrib[OGLargc++]=PHOGL_ATTRIB_NONE; if (this->gl_config.double_buffer) { oglctx=PdCreateOpenGLContext(2, &dim, 0, OGLAttrib); } else { oglctx=PdCreateOpenGLContext(1, &dim, 0, OGLAttrib); } if (oglctx==NULL) { SDL_SetError("ph_SetupOpenGLContext(): cannot create OpenGL context !\n"); return (-1); } PhDCSetCurrent(oglctx); PtFlush(); oglflags=flags; oglbpp=bpp; if (exposepost!=0) { /* OpenGL context has been recreated, so report about this fact */ SDL_PrivateExpose(); } return 0; }
static SDL_Surface *ph_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { const struct ColourMasks* mask; /* Lock the event thread, in multi-threading environments */ SDL_Lock_EventThread(); current->flags = flags; /* if we do not have desired fullscreen mode, then fallback into window mode */ if (((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && (ph_GetVideoMode(width, height, bpp)==0)) { current->flags &= ~SDL_FULLSCREEN; current->flags &= ~SDL_NOFRAME; current->flags &= ~SDL_RESIZABLE; } ph_SetupWindow(this, width, height, current->flags); mask = ph_GetColourMasks(bpp); if (mask != NULL) { SDL_ReallocFormat(current, mask->bpp, mask->red, mask->green, mask->blue, 0); } else { SDL_SetError("ph_SetVideoMode(): desired bpp is not supported by photon !\n"); return NULL; } #ifdef HAVE_OPENGL if ((current->flags & SDL_OPENGL)==SDL_OPENGL) { #else if ((current->flags & SDL_OPENGL)==SDL_OPENGL) /* if no built-in OpenGL support */ { SDL_SetError("ph_SetVideoMode(): no OpenGL support, try to recompile library.\n"); current->flags &= ~SDL_OPENGL; return NULL; #endif /* HAVE_OPENGL */ } else { /* Initialize internal variables */ if ((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { if (bpp==8) { desktoppal=SDLPH_PAL_SYSTEM; } current->flags &= ~SDL_RESIZABLE; /* no resize for Direct Context */ current->flags |= SDL_HWSURFACE; } else { /* remove this if we'll support non-fullscreen sw/hw+doublebuf */ current->flags &= ~SDL_DOUBLEBUF; /* Use offscreen memory if SDL_HWSURFACE flag is set */ if ((current->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { if (desktopbpp!=bpp) { current->flags &= ~SDL_HWSURFACE; } } /* using palette emulation code in window mode */ if (bpp==8) { if (desktopbpp>=15) { desktoppal = SDLPH_PAL_EMULATE; } else { desktoppal = SDLPH_PAL_SYSTEM; } } else { desktoppal = SDLPH_PAL_NONE; } } } current->w = width; current->h = height; if (desktoppal==SDLPH_PAL_SYSTEM) { current->flags|=SDL_HWPALETTE; } /* Must call at least once for setup image planes */ if (ph_SetupUpdateFunction(this, current, current->flags)==-1) { return NULL; } /* finish window drawing, if we are not in fullscreen, of course */ if ((current->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) { PtFlush(); } else { PgFlush(); } SDL_Unlock_EventThread(); /* We're done! */ return (current); } static void ph_VideoQuit(_THIS) { /* restore palette */ if (desktopbpp==8) { PgSetPalette(syspalph, 0, -1, 0, 0, 0); PgSetPalette(savedpal, 0, 0, _Pg_MAX_PALETTE, Pg_PALSET_GLOBAL | Pg_PALSET_FORCE_EXPOSE, 0); PgFlush(); } ph_DestroyImage(this, SDL_VideoSurface); if (window) { PtUnrealizeWidget(window); PtDestroyWidget(window); window=NULL; } if (event!=NULL) { free(event); event=NULL; } } static int ph_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) { int i; SDL_Rect updaterect; updaterect.x = updaterect.y = 0; updaterect.w = this->screen->w; updaterect.h = this->screen->h; /* palette emulation code, using palette of the PhImage_t struct */ if (desktoppal==SDLPH_PAL_EMULATE) { if ((SDL_Image) && (SDL_Image->palette)) { for (i=firstcolor; i<firstcolor+ncolors; i++) { syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b); SDL_Image->palette[i] = syspalph[i]; } /* image needs to be redrawn */ this->UpdateRects(this, 1, &updaterect); } } else { if (desktoppal==SDLPH_PAL_SYSTEM) { for (i=firstcolor; i<firstcolor+ncolors; i++) { syspalph[i] = PgRGB(colors[i-firstcolor].r, colors[i-firstcolor].g, colors[i-firstcolor].b); } if ((this->screen->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) { /* window mode must use soft palette */ PgSetPalette(&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0); /* image needs to be redrawn */ this->UpdateRects(this, 1, &updaterect); } else { /* fullscreen mode must use hardware palette */ PgSetPalette(&syspalph[firstcolor], 0, firstcolor, ncolors, Pg_PALSET_GLOBAL, 0); } } else { /* SDLPH_PAL_NONE do nothing */ } } return 1; }
static SDL_Surface* ph_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { const struct ColourMasks* mask; /* Lock the event thread, in multi-threading environments */ SDL_Lock_EventThread(); current->flags = flags; /* if we do not have desired fullscreen mode, then fallback into window mode */ if (((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) && (ph_GetVideoMode(width, height, bpp)==0)) { current->flags &= ~SDL_FULLSCREEN; current->flags &= ~SDL_NOFRAME; current->flags &= ~SDL_RESIZABLE; } ph_SetupWindow(this, width, height, current->flags); mask = ph_GetColourMasks(bpp); if (mask != NULL) { SDL_ReallocFormat(current, mask->bpp, mask->red, mask->green, mask->blue, 0); } else { SDL_SetError("ph_SetVideoMode(): desired bpp is not supported by photon !\n"); return NULL; } if ((current->flags & SDL_OPENGL)==SDL_OPENGL) { #if !SDL_VIDEO_OPENGL /* if no built-in OpenGL support */ SDL_SetError("ph_SetVideoMode(): no OpenGL support, you need to recompile SDL.\n"); current->flags &= ~SDL_OPENGL; return NULL; #endif /* SDL_VIDEO_OPENGL */ } else { /* Initialize internal variables */ if ((current->flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { if (bpp==8) { desktoppal=SDLPH_PAL_SYSTEM; } current->flags &= ~SDL_RESIZABLE; /* no resize for Direct Context */ current->flags |= SDL_HWSURFACE; } else { /* remove this if we'll have support for the non-fullscreen sw/hw+doublebuf one day */ current->flags &= ~SDL_DOUBLEBUF; /* Use offscreen memory if SDL_HWSURFACE flag is set */ if ((current->flags & SDL_HWSURFACE) == SDL_HWSURFACE) { if (desktopbpp!=bpp) { current->flags &= ~SDL_HWSURFACE; } } /* using palette emulation code in window mode */ if (bpp==8) { if (desktopbpp>=15) { desktoppal = SDLPH_PAL_EMULATE; } else { desktoppal = SDLPH_PAL_SYSTEM; } } else { desktoppal = SDLPH_PAL_NONE; } } } current->w = width; current->h = height; if (desktoppal==SDLPH_PAL_SYSTEM) { current->flags|=SDL_HWPALETTE; } /* Must call at least once for setup image planes */ if (ph_SetupUpdateFunction(this, current, current->flags)==-1) { /* Error string was filled in the ph_SetupUpdateFunction() */ return NULL; } /* finish window drawing, if we are not in fullscreen, of course */ if ((current->flags & SDL_FULLSCREEN) != SDL_FULLSCREEN) { PtFlush(); } else { PgFlush(); } visualbpp=bpp; ph_UpdateHWInfo(this); SDL_Unlock_EventThread(); /* We've done! */ return (current); }
int ph_SetupOpenGLContext(_THIS, int width, int height, int bpp, Uint32 flags) { qnxgl_buf_attrib_t qnxgl_attribs[PH_OGL_MAX_ATTRIBS]; qnxgl_buf_attrib_t* qnxgl_attribs_slide; int num_interfaces = 0; int num_buffers = 0; /* Initialize the OpenGL subsystem */ num_interfaces = qnxgl_init(NULL, NULL, 0); if (num_interfaces < 0) { SDL_SetError("ph_SetupOpenGLContext(): cannot initialize OpenGL subsystem !\n"); return -1; } if (num_interfaces == 0) { SDL_SetError("ph_SetupOpenGLContext(): there are no available OpenGL renderers was found !\n"); return -1; } /* Driver is linked */ this->gl_config.driver_loaded=1; /* Initialize the OpenGL context attributes */ qnxgl_attribs_slide=qnxgl_attribs; /* Depth size */ if (this->gl_config.depth_size) { fprintf(stderr, "setted depth size %d\n", this->gl_config.depth_size); qnxgl_attribs_slide = qnxgl_attrib_set_depth(qnxgl_attribs_slide, this->gl_config.depth_size); } /* Stencil size */ if (this->gl_config.stencil_size) { qnxgl_attribs_slide = qnxgl_attrib_set_stencil(qnxgl_attribs_slide, this->gl_config.stencil_size); } /* The sum of the accum bits of each channel */ if ((this->gl_config.accum_red_size != 0) && (this->gl_config.accum_blue_size != 0) && (this->gl_config.accum_green_size != 0)) { qnxgl_attribs_slide = qnxgl_attrib_set_accum(qnxgl_attribs_slide, this->gl_config.accum_red_size + this->gl_config.accum_blue_size + this->gl_config.accum_green_size + this->gl_config.accum_alpha_size); } /* Stereo mode */ if (this->gl_config.stereo) { qnxgl_attribs_slide = qnxgl_attrib_set_stereo(qnxgl_attribs_slide); } /* Fullscreen mode */ if ((flags & SDL_FULLSCREEN) == SDL_FULLSCREEN) { qnxgl_attribs_slide = qnxgl_attrib_set_hint_fullscreen(qnxgl_attribs_slide); } /* Double buffering mode */ if (this->gl_config.double_buffer) { num_buffers=2; } else { num_buffers=1; } /* Loading the function pointers so we can use the extensions */ GLPH_LOAD_FUNCS_GC(oglctx); /* Set the buffers region to be that of our window's region */ qnxgl_attribs_slide = glph_attrib_set_region(qnxgl_attribs_slide, PtWidgetRid(window)); /* End of the attributes array */ qnxgl_attribs_slide = qnxgl_attrib_set_end(qnxgl_attribs_slide); /* Create the buffers with the specified color model */ fprintf(stderr, "ARGB: %d, %d, %d, %d\n", this->gl_config.alpha_size, this->gl_config.red_size, this->gl_config.green_size, this->gl_config.blue_size); oglbuffers = qnxgl_buffers_create( QNXGL_FORMAT_BEST_RGB, /* __QNXGL_BUILD_FORMAT(0, __QNXGL_COLOR_MODEL_RGB, this->gl_config.alpha_size, this->gl_config.red_size, this->gl_config.green_size, this->gl_config.blue_size), */ num_buffers, width, height, qnxgl_attribs, -1); if (oglbuffers == NULL) { SDL_SetError("ph_SetupOpenGLContext(): failed to create OpenGL buffers !\n"); qnxgl_finish(); return -1; } /* Create a QNXGL context for the previously created buffer */ oglctx = qnxgl_context_create(oglbuffers, NULL); if (oglctx == NULL) { SDL_SetError("ph_SetupOpenGLContext(): failed to create OpenGL context !\n"); qnxgl_buffers_destroy(oglbuffers); qnxgl_finish(); return -1; } /* Attempt to make the context current so we can use OpenGL commands */ if (qnxgl_set_current(oglctx) == -1) { SDL_SetError("ph_SetupOpenGLContext(): failed to make the OpenGL context current !\n"); qnxgl_context_destroy(oglctx); qnxgl_buffers_destroy(oglbuffers); qnxgl_finish(); return -1; } PtFlush(); oglflags=flags; oglbpp=bpp; return 0; }