// this function frees the image given void FreeBuffer(CoolImage *i) { // for blit type 0, we just free the memory previously malloced if (blittype==0) free(i->buffer); else if (blittype==1) PgShmemDestroy(i->buffer); else if (blittype==2) PhDCRelease(i->ctx); // free the structure as well free(i); }
void ph_window_close_display (void) { /* FIXME: free cursors */ int i; widthscale = orig_widthscale; heightscale = orig_heightscale; /* This is only allocated/done if we succeeded to get a window */ if (P_mainWindow) { if (image) { PhDCRelease (image); scaled_buffer_ptr = NULL; image=NULL; } PtUnrealizeWidget(P_mainWindow); P_mainWindow=NULL; } }
void ph_DestroyImage(_THIS, SDL_Surface* screen) { #ifdef HAVE_OPENGL if ((screen->flags & SDL_OPENGL)==SDL_OPENGL) { if (oglctx) { PhDCSetCurrent(NULL); PhDCRelease(oglctx); oglctx=NULL; oglflags=0; oglbpp=0; } return; } #endif /* HAVE_OPENGL */ if (currently_fullscreen) { /* if we right now in 8bpp fullscreen we must release palette */ if ((screen->format->BitsPerPixel==8) && (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_LeaveFullScreen(this); } if (OCImage.offscreen_context != NULL) { PhDCRelease(OCImage.offscreen_context); OCImage.offscreen_context = NULL; OCImage.FrameData0 = NULL; } if (OCImage.offscreen_backcontext != NULL) { PhDCRelease(OCImage.offscreen_backcontext); OCImage.offscreen_backcontext = NULL; OCImage.FrameData1 = NULL; } OCImage.CurrentFrameData = NULL; if (SDL_Image) { /* if palette allocated, free it */ if (SDL_Image->palette) { free(SDL_Image->palette); } PgShmemDestroy(SDL_Image->image); free(SDL_Image); } /* Must be zeroed everytime */ SDL_Image = NULL; if (screen) { screen->pixels = NULL; } }
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; }
int ph_SetupOCImage(_THIS, SDL_Surface *screen) { int type = 0; int bpp; OCImage.flags = screen->flags; bpp=screen->format->BitsPerPixel; /* Determine image type */ switch(bpp) { case 8: { type = Pg_IMAGE_PALETTE_BYTE; } break; case 15:{ type = Pg_IMAGE_DIRECT_555; } break; case 16:{ type = Pg_IMAGE_DIRECT_565; } break; case 24:{ type = Pg_IMAGE_DIRECT_888; } break; case 32:{ type = Pg_IMAGE_DIRECT_8888; } break; default:{ SDL_SetError("ph_SetupOCImage(): unsupported bpp=%d !\n", bpp); return -1; } break; } /* Currently only offscreen contexts with the same bit depth as the * display can be created. */ OCImage.offscreen_context = PdCreateOffscreenContext(0, screen->w, screen->h, Pg_OSC_MEM_PAGE_ALIGN); if (OCImage.offscreen_context == NULL) { SDL_SetError("ph_SetupOCImage(): PdCreateOffscreenContext() function failed !\n"); return -1; } screen->pitch = OCImage.offscreen_context->pitch; OCImage.dc_ptr = (unsigned char *) PdGetOffscreenContextPtr(OCImage.offscreen_context); if (OCImage.dc_ptr == NULL) { SDL_SetError("ph_SetupOCImage(): PdGetOffscreenContextPtr function failed !\n"); PhDCRelease(OCImage.offscreen_context); return -1; } OCImage.FrameData0 = OCImage.dc_ptr; OCImage.CurrentFrameData = OCImage.FrameData0; OCImage.current = 0; PhDCSetCurrent(OCImage.offscreen_context); screen->pixels = OCImage.CurrentFrameData; this->UpdateRects = ph_OCUpdate; return 0; }
/***************************************************************************** * NewPicture: allocate a picture ***************************************************************************** * Returns 0 on success, -1 otherwise *****************************************************************************/ static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic, int index ) { /* We know the chroma, allocate a buffer which will be used * directly by the decoder */ p_pic->p_sys = malloc( sizeof( picture_sys_t ) ); if( p_pic->p_sys == NULL ) { return -1; } switch( p_vout->p_sys->i_mode ) { case MODE_NORMAL_MEM: case MODE_SHARED_MEM: /* create images for [shared] memory blit */ if( !( p_pic->p_sys->p_image = PhCreateImage( NULL, p_vout->p_sys->dim.w, p_vout->p_sys->dim.h, p_vout->p_sys->i_img_type, NULL, 0, p_vout->p_sys->i_mode == MODE_SHARED_MEM ) ) ) { msg_Err( p_vout, "cannot create image" ); free( p_pic->p_sys ); return( -1 ); } p_pic->p->p_pixels = p_pic->p_sys->p_image->image; p_pic->p->i_lines = p_pic->p_sys->p_image->size.h; p_pic->p->i_visible_lines = p_pic->p_sys->p_image->size.h; p_pic->p->i_pitch = p_pic->p_sys->p_image->bpl; p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel; p_pic->p->i_visible_pitch = p_vout->p_sys->i_bytes_per_pixel * p_pic->p_sys->p_image->size.w; p_pic->i_planes = 1; break; case MODE_VIDEO_MEM: /* create offscreen contexts for video memory blit */ if( ( p_pic->p_sys->p_ctx[0] = PdCreateOffscreenContext( 0, p_vout->p_sys->dim.w, p_vout->p_sys->dim.h, Pg_OSC_MEM_PAGE_ALIGN) ) == NULL ) { msg_Err( p_vout, "unable to create offscreen context" ); free( p_pic->p_sys ); return( -1 ); } /* get context pointers */ if( ( p_pic->p_sys->p_buf[0] = PdGetOffscreenContextPtr ( p_pic->p_sys->p_ctx[0] ) ) == NULL ) { msg_Err( p_vout, "unable to get offscreen context ptr" ); PhDCRelease ( p_pic->p_sys->p_ctx[0] ); p_pic->p_sys->p_ctx[0] = NULL; free( p_pic->p_sys ); return( -1 ); } p_vout->p_sys->i_bytes_per_line = p_pic->p_sys->p_ctx[0]->pitch; memset( p_pic->p_sys->p_buf[0], 0, p_vout->p_sys->i_bytes_per_line * p_vout->p_sys->dim.h ); p_pic->p->p_pixels = p_pic->p_sys->p_buf[0]; p_pic->p->i_lines = p_pic->p_sys->p_ctx[0]->dim.h; p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[0]->dim.h; p_pic->p->i_pitch = p_pic->p_sys->p_ctx[0]->pitch; p_pic->p->i_pixel_pitch = p_vout->p_sys->i_bytes_per_pixel; p_pic->p->i_visible_pitch = p_vout->p_sys->i_bytes_per_pixel * p_pic->p_sys->p_ctx[0]->dim.w; p_pic->i_planes = 1; break; case MODE_VIDEO_OVERLAY: if (index == 0) { p_pic->p_sys->p_ctx[Y_PLANE] = p_vout->p_sys->p_channel->yplane1; p_pic->p_sys->p_ctx[U_PLANE] = p_vout->p_sys->p_channel->uplane1; p_pic->p_sys->p_ctx[V_PLANE] = p_vout->p_sys->p_channel->vplane1; } else { p_pic->p_sys->p_ctx[Y_PLANE] = p_vout->p_sys->p_channel->yplane2; p_pic->p_sys->p_ctx[U_PLANE] = p_vout->p_sys->p_channel->uplane2; p_pic->p_sys->p_ctx[V_PLANE] = p_vout->p_sys->p_channel->vplane2; } p_pic->p_sys->p_buf[Y_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[Y_PLANE] ); if( p_pic->p_sys->p_buf[Y_PLANE] == NULL ) { msg_Err( p_vout, "unable to get video channel ctx ptr" ); return( 1 ); } switch (p_vout->p_sys->i_vc_format) { case Pg_VIDEO_FORMAT_YUV420: p_vout->output.i_chroma = VLC_CODEC_I420; p_pic->p_sys->p_buf[U_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[U_PLANE] ); p_pic->p_sys->p_buf[V_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[V_PLANE] ); if( p_pic->p_sys->p_buf[U_PLANE] == NULL || p_pic->p_sys->p_buf[V_PLANE] == NULL ) { msg_Err( p_vout, "unable to get video channel ctx ptr" ); return( 1 ); } p_pic->Y_PIXELS = p_pic->p_sys->p_buf[Y_PLANE]; p_pic->p[Y_PLANE].i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h; p_pic->p[Y_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h; p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch; p_pic->p[Y_PLANE].i_pixel_pitch = 1; p_pic->p[Y_PLANE].i_visible_pitch = p_pic->p[Y_PLANE].i_pitch; p_pic->U_PIXELS = p_pic->p_sys->p_buf[U_PLANE]; p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_ctx[U_PLANE]->dim.h; p_pic->p[U_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[U_PLANE]->dim.h; p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_ctx[U_PLANE]->pitch; p_pic->p[U_PLANE].i_pixel_pitch = 1; p_pic->p[U_PLANE].i_visible_pitch = p_pic->p[U_PLANE].i_pitch; p_pic->V_PIXELS = p_pic->p_sys->p_buf[V_PLANE]; p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_ctx[V_PLANE]->dim.h; p_pic->p[V_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[V_PLANE]->dim.h; p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_ctx[V_PLANE]->pitch; p_pic->p[V_PLANE].i_pixel_pitch = 1; p_pic->p[V_PLANE].i_visible_pitch = p_pic->p[V_PLANE].i_pitch; p_pic->i_planes = 3; break; case Pg_VIDEO_FORMAT_YV12: p_vout->output.i_chroma = VLC_CODEC_YV12; p_pic->p_sys->p_buf[U_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[U_PLANE] ); p_pic->p_sys->p_buf[V_PLANE] = PdGetOffscreenContextPtr( p_pic->p_sys->p_ctx[V_PLANE] ); if( p_pic->p_sys->p_buf[U_PLANE] == NULL || p_pic->p_sys->p_buf[V_PLANE] == NULL ) { msg_Err( p_vout, "unable to get video channel ctx ptr" ); return( 1 ); } p_pic->Y_PIXELS = p_pic->p_sys->p_buf[Y_PLANE]; p_pic->p[Y_PLANE].i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h; p_pic->p[Y_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h; p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch; p_pic->p[Y_PLANE].i_pixel_pitch = 1; p_pic->p[Y_PLANE].i_visible_pitch = p_pic->p[Y_PLANE].i_pitch; p_pic->U_PIXELS = p_pic->p_sys->p_buf[U_PLANE]; p_pic->p[U_PLANE].i_lines = p_pic->p_sys->p_ctx[U_PLANE]->dim.h; p_pic->p[U_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[U_PLANE]->dim.h; p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_ctx[U_PLANE]->pitch; p_pic->p[U_PLANE].i_pixel_pitch = 1; p_pic->p[U_PLANE].i_visible_pitch = p_pic->p[U_PLANE].i_pitch; p_pic->V_PIXELS = p_pic->p_sys->p_buf[V_PLANE]; p_pic->p[V_PLANE].i_lines = p_pic->p_sys->p_ctx[V_PLANE]->dim.h; p_pic->p[V_PLANE].i_visible_lines = p_pic->p_sys->p_ctx[V_PLANE]->dim.h; p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_ctx[V_PLANE]->pitch; p_pic->p[V_PLANE].i_pixel_pitch = 1; p_pic->p[V_PLANE].i_visible_pitch = p_pic->p[V_PLANE].i_pitch; p_pic->i_planes = 3; break; case Pg_VIDEO_FORMAT_UYVY: case Pg_VIDEO_FORMAT_YUY2: if (p_vout->p_sys->i_vc_format == Pg_VIDEO_FORMAT_UYVY) { p_vout->output.i_chroma = VLC_CODEC_UYVY; } else { p_vout->output.i_chroma = VLC_CODEC_YUYV; } p_pic->p->p_pixels = p_pic->p_sys->p_buf[Y_PLANE]; p_pic->p->i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h; p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h; p_pic->p->i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch; p_pic->p->i_pixel_pitch = 4; p_pic->p->i_visible_pitch = p_pic->p->i_pitch; p_pic->i_planes = 1; break; case Pg_VIDEO_FORMAT_RGB555: p_vout->output.i_chroma = VLC_CODEC_RGB15; p_vout->output.i_rmask = 0x001f; p_vout->output.i_gmask = 0x03e0; p_vout->output.i_bmask = 0x7c00; p_pic->p->p_pixels = p_pic->p_sys->p_buf[Y_PLANE]; p_pic->p->i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h; p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h; p_pic->p->i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch; p_pic->p->i_pixel_pitch = 2; p_pic->p->i_visible_pitch = 2 * p_pic->p_sys->p_ctx[Y_PLANE]->dim.w; p_pic->i_planes = 1; break; case Pg_VIDEO_FORMAT_RGB565: p_vout->output.i_chroma = VLC_CODEC_RGB16; p_vout->output.i_rmask = 0x001f; p_vout->output.i_gmask = 0x07e0; p_vout->output.i_bmask = 0xf800; p_pic->p->p_pixels = p_pic->p_sys->p_buf[Y_PLANE]; p_pic->p->i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h; p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h; p_pic->p->i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch; p_pic->p->i_pixel_pitch = 4; p_pic->p->i_visible_pitch = 4 * p_pic->p_sys->p_ctx[Y_PLANE]->dim.w; p_pic->i_planes = 1; break; case Pg_VIDEO_FORMAT_RGB8888: p_vout->output.i_chroma = VLC_CODEC_RGB32; p_vout->output.i_rmask = 0x000000ff; p_vout->output.i_gmask = 0x0000ff00; p_vout->output.i_bmask = 0x00ff0000; p_pic->p->p_pixels = p_pic->p_sys->p_buf[Y_PLANE]; p_pic->p->i_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h; p_pic->p->i_visible_lines = p_pic->p_sys->p_ctx[Y_PLANE]->dim.h; p_pic->p->i_pitch = p_pic->p_sys->p_ctx[Y_PLANE]->pitch; p_pic->p->i_pixel_pitch = 4; p_pic->p->i_visible_pitch = 4 * p_pic->p_sys->p_ctx[Y_PLANE]->dim.w; p_pic->i_planes = 1; break; } #if 0 switch( p_vout->output.i_chroma ) { #ifdef MODULE_NAME_IS_xvideo case VLC_CODEC_Y211: p_pic->p->p_pixels = p_pic->p_sys->p_image->data + p_pic->p_sys->p_image->offsets[0]; p_pic->p->i_lines = p_vout->output.i_height; p_pic->p->i_visible_lines = p_vout->output.i_height; /* XXX: this just looks so plain wrong... check it out ! */ p_pic->p->i_pitch = p_pic->p_sys->p_image->pitches[0] / 4; p_pic->p->i_pixel_pitch = 4; p_pic->p->i_visible_pitch = p_pic->p->i_pitch; p_pic->i_planes = 1; break; #endif #endif default: /* This shouldn't happen ! */ break; } return 0; } /***************************************************************************** * FreePicture: destroy a picture allocated with NewPicture ***************************************************************************** * Destroy XImage AND associated data. If using Shm, detach shared memory * segment from server and process, then free it. The XDestroyImage manpage * says that both the image structure _and_ the data pointed to by the * image structure are freed, so no need to free p_image->data. *****************************************************************************/ static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic ) { if( ( p_vout->p_sys->i_mode == MODE_NORMAL_MEM || p_vout->p_sys->i_mode == MODE_SHARED_MEM ) && p_pic->p_sys->p_image ) { PhReleaseImage( p_pic->p_sys->p_image ); free( p_pic->p_sys->p_image ); } else if( p_vout->p_sys->i_mode == MODE_VIDEO_MEM && p_pic->p_sys->p_ctx[0] ) { PhDCRelease( p_pic->p_sys->p_ctx[0] ); } free( p_pic->p_sys ); } static int ResizeOverlayOutput(vout_thread_t *p_vout) { int i_width, i_height, i_x, i_y; int i_ret; PgScalerProps_t props; props.size = sizeof( props ); props.format = p_vout->p_sys->i_vc_format; props.flags = Pg_SCALER_PROP_SCALER_ENABLE | Pg_SCALER_PROP_DOUBLE_BUFFER; /* enable chroma keying if available */ if( p_vout->p_sys->i_vc_flags & Pg_SCALER_CAP_DST_CHROMA_KEY ) { props.flags |= Pg_SCALER_PROP_CHROMA_ENABLE; } /* set viewport position */ props.viewport.ul.x = p_vout->p_sys->pos.x; props.viewport.ul.y = p_vout->p_sys->pos.y; if( !p_vout->b_fullscreen ) { props.viewport.ul.x += p_vout->p_sys->frame.ul.x; props.viewport.ul.y += p_vout->p_sys->frame.ul.y; } /* set viewport dimension */ vout_PlacePicture( p_vout, p_vout->p_sys->dim.w, p_vout->p_sys->dim.h, &i_x, &i_y, &i_width, &i_height ); props.viewport.ul.x += i_x; props.viewport.ul.y += i_y; props.viewport.lr.x = i_width + props.viewport.ul.x; props.viewport.lr.y = i_height + props.viewport.ul.y; /* set source dimension */ props.src_dim.w = p_vout->output.i_width; props.src_dim.h = p_vout->output.i_height; /* configure scaler channel */ i_ret = PgConfigScalerChannel( p_vout->p_sys->p_channel, &props ); if( i_ret == -1 ) { msg_Err( p_vout, "unable to configure video channel" ); return( 1 ); } return ( 0 ); }
int ph_window_create_display (int bitmap_depth) { PtArg_t arg[9]; PhRect_t rect; PhRegion_t region_info; // Only image_height??!! int image_height; int window_width, window_height; // Create the Photon Window view_size.w = widthscale * visual_width; view_size.h = heightscale * visual_height; image_width = widthscale * visual_width; image_height = heightscale * visual_height; // TODO: Finish always ontop (Make phearbear happy) PtSetArg( &arg[0], Pt_ARG_FILL_COLOR, Pg_TRANSPARENT, 0 ); PtSetArg( &arg[1], Pt_ARG_WINDOW_MANAGED_FLAGS, 0, Ph_WM_MAX | Ph_WM_RESIZE | Ph_WM_MENU | Ph_WM_CLOSE | Ph_WM_HIDE ); PtSetArg( &arg[2], Pt_ARG_DIM, &view_size, 0 ); PtSetArg( &arg[3], Pt_ARG_WINDOW_NOTIFY_FLAGS, Ph_WM_FOCUS, Ph_WM_FOCUS | Ph_WM_RESIZE | Ph_WM_CLOSE ); PtSetArg( &arg[4], Pt_ARG_WINDOW_RENDER_FLAGS, Pt_FALSE, Ph_WM_RENDER_MENU | Ph_WM_RENDER_CLOSE | Ph_WM_RENDER_MAX | Ph_WM_RENDER_MIN | Ph_WM_RENDER_COLLAPSE | Ph_WM_RENDER_RESIZE ); PtSetArg( &arg[5], Pt_ARG_WINDOW_TITLE, title, 0); //PtSetArg( &arg[6], Pt_ARG_WINDOW_STATE, 0, Ph_WM_STATE_ISFRONT ); PtSetParentWidget(NULL); if((P_mainWindow = PtCreateWidget(PtWindow, NULL, 6, arg)) == NULL) fprintf(stderr,"error: could not create main photon window.\n"); /* add raw callback handler */ PtAddEventHandler( P_mainWindow, Ph_EV_BUT_PRESS | Ph_EV_BUT_RELEASE | Ph_EV_BOUNDARY | Ph_EV_EXPOSE | Ph_EV_PTR_MOTION | Ph_EV_KEY | Ph_EV_INFO, I_GetEvent, NULL ); /* set draw buffer size */ PgSetDrawBufferSize( 0xFF00 ); PtRealizeWidget( P_mainWindow ); if (show_cursor == FALSE) { region_info.cursor_type = Ph_CURSOR_NONE; region_info.rid = PtWidgetRid(P_mainWindow); PhRegionChange (Ph_REGION_CURSOR, 0, ®ion_info, NULL, NULL); // turn off cursor } /* create and setup the image */ switch (ph_window_update_method) { case PH_NORMAL: // image = PdCreateOffscreenContext(0, ((view_size.w+7) & ~7), view_size.h, Pg_OSC_MEM_PAGE_ALIGN); image = PdCreateOffscreenContext(0, view_size.w, view_size.h, Pg_OSC_MEM_PAGE_ALIGN); if (image == NULL) { fprintf(stderr_file, "error: failed to create offscreen context\n"); return OSD_NOT_OK; } scaled_buffer_ptr = PdGetOffscreenContextPtr (image); if (!scaled_buffer_ptr) { fprintf (stderr_file, "error: failed get a pointer to offscreen context.\n"); PhDCRelease (image); return OSD_NOT_OK; } depth = 0; switch (image->format) { case Pg_IMAGE_PALETTE_BYTE : // TODO : break; case Pg_IMAGE_DIRECT_565 : depth = 16; pixels_per_line = image->pitch >> 1; break; case Pg_IMAGE_DIRECT_555 : // TODO: break; case Pg_IMAGE_DIRECT_888 : depth = 24; pixels_per_line = image->pitch / 3; break; case Pg_IMAGE_DIRECT_8888 : depth = 32; pixels_per_line = image->pitch >> 2; break; } break; default: fprintf (stderr_file, "error: unknown photon update method, this shouldn't happen\n"); return OSD_NOT_OK; } /* setup the palette_info struct now we have the depth */ if (ph_init_palette_info() != OSD_OK) return OSD_NOT_OK; fprintf(stderr_file, "Actual bits per pixel = %d...\n", depth); if (bitmap_depth == 32) { if (depth == 32) ph_window_update_display_func = ph_window_update_32_to_32bpp_direct; } else if (bitmap_depth == 16) { switch(depth) { case 16: ph_window_update_display_func = ph_window_update_16_to_16bpp; break; case 24: ph_window_update_display_func = ph_window_update_16_to_24bpp; break; case 32: ph_window_update_display_func = ph_window_update_16_to_32bpp; break; } } if (ph_window_update_display_func == NULL) { fprintf(stderr_file, "error: unsupported\n"); return OSD_NOT_OK; } fprintf(stderr_file, "Ok\n"); return OSD_OK; }
/* * Create a display screen, or window, large enough to accomodate a bitmap * of the given dimensions. */ int I_GetEvent(PtWidget_t *widget, void *data, PtCallbackInfo_t *cbinfo, int bitmap_depth ) { int mask=FALSE; int kdosomething=FALSE; PhKeyEvent_t *kevent; PhPointerEvent_t *pevent; int keycode,code; int *pt; struct xmame_keyboard_event mame_key_event; char keyname[16+1]; mame_key_event.press = FALSE; switch (cbinfo->event->type) { case Ph_EV_KEY: { kevent = PhGetData (cbinfo->event); if (PkIsFirstDown (kevent->key_flags)) { mask=TRUE; mame_key_event.press=TRUE; kdosomething = TRUE; } else if (!PkIsKeyDown(kevent->key_flags)) kdosomething = TRUE; if (kdosomething) { if (kevent->key_flags & Pk_KF_Cap_Valid) keycode = kevent->key_cap; else goto getevent_done; if ((keycode & 0xF000) == 0xF000) { pt=extended_code_table; keycode &= 0x00FF; } else { pt=code_table; } mame_key_event.scancode = *(pt+keycode); if (PhKeyToMb (keyname, kevent) == -1) { keyname[0]=0; } mame_key_event.unicode = keyname[0]; //phkey [ *(pt+keycode) ] = mask; xmame_keyboard_register_event(&mame_key_event); } break; } case Ph_EV_BUT_PRESS: pevent = PhGetData( cbinfo->event ); if (pevent->buttons & Ph_BUTTON_SELECT) { mouse_data[0].buttons[0] = TRUE; } if (pevent->buttons & Ph_BUTTON_MENU) { mouse_data[0].buttons[1] = TRUE; } if (pevent->buttons & Ph_BUTTON_ADJUST) { mouse_data[0].buttons[2] = TRUE; } break; case Ph_EV_BUT_RELEASE: if( cbinfo->event->subtype != Ph_EV_RELEASE_REAL ) break; pevent = PhGetData( cbinfo->event ); if (pevent->buttons & Ph_BUTTON_SELECT) { mouse_data[0].buttons[0] = FALSE; } if (pevent->buttons & Ph_BUTTON_MENU) { mouse_data[0].buttons[1] = FALSE; } if (pevent->buttons & Ph_BUTTON_ADJUST) { mouse_data[0].buttons[2] = FALSE; } break; case Ph_EV_PTR_MOTION_NOBUTTON: case Ph_EV_PTR_MOTION_BUTTON: if (ph_grab_mouse == FALSE) { pevent = PhGetData( cbinfo->event ); update_mouse=TRUE; mouse_data[0].deltas[0] = pevent->pos.x-current_mouse[0]; mouse_data[0].deltas[1] = pevent->pos.y-current_mouse[1]; current_mouse[0] = pevent->pos.x; current_mouse[1] = pevent->pos.y; } break; case Ph_EV_EXPOSE: if (ph_video_mode==0) { ph_window_refresh_screen(); PgFlush(); } break; case Ph_EV_INFO: { switch (cbinfo->event->subtype) { case Ph_OFFSCREEN_INVALID : fprintf (stderr,"info: got offscreen invalid\n"); if (image != NULL) { fprintf(stderr,"info: creating new image\n"); PhDCRelease(image); image = PdCreateOffscreenContext(0, view_size.w, view_size.h, Pg_OSC_MEM_PAGE_ALIGN); if (image == NULL) { fprintf(stderr_file, "error: failed to create offscreen context\n"); exit(1); } scaled_buffer_ptr = PdGetOffscreenContextPtr (image); if (!scaled_buffer_ptr) { fprintf (stderr_file, "error: failed get a pointer to offscreen context.\n"); PhDCRelease (image); exit(1); } depth = 0; switch (image->format) { case Pg_IMAGE_PALETTE_BYTE : // TODO : break; case Pg_IMAGE_DIRECT_565 : depth = 16; pixels_per_line = image->pitch >> 1; break; case Pg_IMAGE_DIRECT_555 : // TODO: break; case Pg_IMAGE_DIRECT_888 : depth = 24; pixels_per_line = image->pitch / 3; break; case Pg_IMAGE_DIRECT_8888 : depth = 32; pixels_per_line = image->pitch >> 2; break; } ph_init_palette_info(); ph_window_update_display_func=NULL; if (bitmap_depth == 16) { switch(depth) { case 16: ph_window_update_display_func = ph_window_update_16_to_16bpp; break; case 24: ph_window_update_display_func = ph_window_update_16_to_24bpp; break; case 32: ph_window_update_display_func = ph_window_update_16_to_32bpp; break; } } if (ph_window_update_display_func == NULL) { fprintf(stderr_file, "error: Unsupported\n"); exit(1); } } break; } } break; }