GuiImage::GuiImage(int w, int h, GXColor c) { //image = (u8 *) memalign(32, w * h << 2); image = Xe_CreateTexture(g_pVideoDevice,w,h,0,(XE_FMT_8888|XE_FMT_ARGB),0); width = w; height = h; imageangle = 0; tile = -1; stripe = 0; imgType = IMAGE_COLOR; if (!image) return; buf = (u8*)Xe_Surface_LockRect(g_pVideoDevice,image,0,0,0,0,XE_LOCK_WRITE); int x,y; for (y = 0; y < height; y++) { for (x = 0; x < width; x++) { buf[0] = c.a; buf[1] = c.r; buf[2] = c.g; buf[3] = c.b; buf += 4; } } Xe_Surface_Unlock(g_pVideoDevice,image); }
void osd_xenon_video_hw_init(running_machine &machine) { XenosSurface * fb = Xe_GetFramebufferSurface(g_pVideoDevice); Xe_SetRenderTarget(g_pVideoDevice, fb); LoadShaderEffects(); g_pTexture = Xe_CreateTexture(g_pVideoDevice, XE_W, XE_H, 1, XE_FMT_8888 | XE_FMT_ARGB, 0); screen = (unsigned int*) Xe_Surface_LockRect(g_pVideoDevice, g_pTexture, 0, 0, 0, 0, XE_LOCK_WRITE); Xe_Surface_Unlock(g_pVideoDevice, g_pTexture); g_pTexture->use_filtering = 0; pitch = g_pTexture->wpitch; screen_width = fb->width; screen_height = fb->height; vb = Xe_CreateVertexBuffer(g_pVideoDevice, 65536 * sizeof (MameVerticeFormats)); soft_vb = Xe_CreateVertexBuffer(g_pVideoDevice, 65536 * sizeof (MameVerticeFormats)); float w = fb->width; float h = fb->height; Xe_SetClearColor(g_pVideoDevice, 0); osd_xenon_video_resume(); // on mame exit machine.add_notifier(MACHINE_NOTIFY_EXIT, machine_notify_delegate(FUNC(osd_xenon_video_cleanup), &machine)); }
void XeRefreshTexture(glXeSurface_t * surf) { if (surf->dirty) { Xe_Surface_LockRect(xe, surf->teximg, 0, 0, 0, 0, XE_LOCK_WRITE); Xe_Surface_Unlock(xe, surf->teximg); // surface is now clean surf->dirty = 0; } }
void SYSVideoUpdate() { /* resize uv to viewport */ int vwidth = bitmap.viewport.w + (2 * bitmap.viewport.x); int vheight = bitmap.viewport.h + (2 * bitmap.viewport.y); update_texture_viewport(); int video_filter = getVideoFitler(); // apply video filter switch (video_filter){ case VF_2XSAI: filter_Std2xSaI_ex8(bitmap.data, bitmap.pitch, texture_buffer, vwidth, vheight); g_pTexture->width = vwidth<<1; g_pTexture->height = vheight<<1; break; case VF_BLINEAR: g_pTexture->use_filtering = 0; XeTexSubImage(g_pTexture, bitmap.viewport.x, bitmap.viewport.y, bitmap.viewport.w, bitmap.viewport.h, bitmap.data); g_pTexture->width = vwidth; g_pTexture->height = vheight; break; default: g_pTexture->use_filtering = 1; XeTexSubImage(g_pTexture, bitmap.viewport.x, bitmap.viewport.y, bitmap.viewport.w, bitmap.viewport.h, bitmap.data); g_pTexture->width = vwidth; g_pTexture->height = vheight; break; } // Refresh texture cash Xe_Surface_LockRect(g_pVideoDevice, g_pTexture, 0, 0, 0, 0, XE_LOCK_WRITE); Xe_Surface_Unlock(g_pVideoDevice, g_pTexture); // Select stream and shaders Xe_SetTexture(g_pVideoDevice, 0, g_pTexture); Xe_SetCullMode(g_pVideoDevice, XE_CULL_NONE); Xe_SetStreamSource(g_pVideoDevice, 0, vb, 0, sizeof (DrawVerticeFormats)); Xe_SetShader(g_pVideoDevice, SHADER_TYPE_PIXEL, g_pPixelTexturedShader, 0); Xe_SetShader(g_pVideoDevice, SHADER_TYPE_VERTEX, g_pVertexShader, 0); Xe_SetClearColor(g_pVideoDevice, 0xFF000000); // Draw Xe_DrawPrimitive(g_pVideoDevice, XE_PRIMTYPE_RECTLIST, 0, 1); // Resolve Xe_Resolve(g_pVideoDevice); //while (!Xe_IsVBlank(g_pVideoDevice)); Xe_Sync(g_pVideoDevice); // Reset states Xe_InvalidateState(g_pVideoDevice); }
struct XenosSurface * XeGetBitmapFromMemory(int width, int height, void *pixeldata) { printf("\t\t\tXeGetBitmapFromMemory(int width,int height,void *pixeldata) ...!!\n"); struct XenosSurface *surface = Xe_CreateTexture(xe, width, height, 1, XE_FMT_8888 | XE_FMT_ARGB, 0); Xe_Surface_LockRect(xe, surface, 0, 0, 0, 0, XE_LOCK_WRITE); unsigned long size = (surface->height) * (surface->pitch) + 1; printf("\t\t\tmemcpy ...!!\n"); memcpy(surface->base, pixeldata, size);//Copie la texture en mémoire dans la surface xe Xe_Surface_Unlock(xe, surface); return surface; }
/** * set data for small textures */ void XXsetTextureData(XenosSurface * surf,void * buffer){ u8 * buf = (u8*)buffer; u8 * surfbuf; int j,i; surfbuf=(u8*)Xe_Surface_LockRect(g_pVideoDevice,surf,0,0,0,0,XE_LOCK_WRITE); for(j=0;j<surf->hpitch;++j) for(i=0;i<surf->wpitch;i+=surf->width*4) memcpy(&surfbuf[surf->wpitch*j+i],&buf[surf->width*(j%surf->height)*4],surf->width*4); Xe_Surface_Unlock(g_pVideoDevice,surf); }
static bool xenon360_gfx_frame(void *data, const void *frame, unsigned width, unsigned height, uint64_t frame_count, unsigned pitch, const char *msg, video_frame_info_t *video_info) { gl_t *vid = data; ScreenUv[UV_TOP] = ((float) (width) / (float) XE_W)*2; ScreenUv[UV_LEFT] = ((float) (height) / (float) XE_H)*2; DrawVerticeFormats * Rect = Xe_VB_Lock(vid->gl_device, vid->vb, 0, 3 * sizeof(DrawVerticeFormats), XE_LOCK_WRITE); /* bottom left */ Rect[1].v = ScreenUv[UV_LEFT]; Rect[2].u = ScreenUv[UV_TOP]; Xe_VB_Unlock(vid->gl_device, vid->vb); /* Refresh texture cache */ uint16_t *dst = Xe_Surface_LockRect(vid->gl_device, vid->g_pTexture, 0, 0, 0, 0, XE_LOCK_WRITE); const uint16_t *src = frame; unsigned stride_in = pitch >>1; unsigned stride_out = vid->g_pTexture->wpitch >> 1; unsigned copy_size = width << 1; for (unsigned y = 0; y < height; y++, dst += stride_out, src += stride_in) memcpy(dst, src, copy_size); Xe_Surface_Unlock(vid->gl_device, vid->g_pTexture); /* Reset states */ Xe_InvalidateState(vid->gl_device); Xe_SetClearColor(vid->gl_device, 0); /* Select stream */ Xe_SetTexture(vid->gl_device, 0, vid->g_pTexture); Xe_SetCullMode(vid->gl_device, XE_CULL_NONE); Xe_SetStreamSource(vid->gl_device, 0, vid->vb, 0, sizeof(DrawVerticeFormats)); /* Select shaders */ Xe_SetShader(vid->gl_device, SHADER_TYPE_PIXEL, vid->g_pPixelTexturedShader, 0); Xe_SetShader(vid->gl_device, SHADER_TYPE_VERTEX, vid->g_pVertexShader, 0); #ifdef HAVE_MENU menu_driver_frame(video_info); #endif /* Draw */ Xe_DrawPrimitive(vid->gl_device, XE_PRIMTYPE_TRIANGLELIST, 0, 1); /* Resolve */ Xe_Resolve(vid->gl_device); Xe_Sync(vid->gl_device); return true; }
void osd_xenon_video_init() { g_pVideoDevice = &_xe; Xe_Init(g_pVideoDevice); XenosSurface * fb = Xe_GetFramebufferSurface(g_pVideoDevice); Xe_SetRenderTarget(g_pVideoDevice, fb); static const struct XenosVBFFormat vbf = { 3, { {XE_USAGE_POSITION, 0, XE_TYPE_FLOAT4}, {XE_USAGE_COLOR, 0, XE_TYPE_UBYTE4}, {XE_USAGE_TEXCOORD, 0, XE_TYPE_FLOAT2}, } }; g_pPixelTexturedShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) g_xps_ps_main); Xe_InstantiateShader(g_pVideoDevice, g_pPixelTexturedShader, 0); g_pVertexShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) g_xvs_VSmain); Xe_InstantiateShader(g_pVideoDevice, g_pVertexShader, 0); Xe_ShaderApplyVFetchPatches(g_pVideoDevice, g_pVertexShader, 0, &vbf); g_pTexture = Xe_CreateTexture(g_pVideoDevice, XE_W, XE_H, 1, XE_FMT_8888 | XE_FMT_ARGB, 0); screen = (unsigned int*) Xe_Surface_LockRect(g_pVideoDevice, g_pTexture, 0, 0, 0, 0, XE_LOCK_WRITE); Xe_Surface_Unlock(g_pVideoDevice, g_pTexture); g_pTexture->use_filtering = 0; pitch = g_pTexture->wpitch; screen_width = fb->width; screen_height = fb->height; vb = Xe_CreateVertexBuffer(g_pVideoDevice, 65536 * sizeof (DrawVerticeFormats)); soft_vb = Xe_CreateVertexBuffer(g_pVideoDevice, 65536 * sizeof (DrawVerticeFormats)); float w = fb->width; float h = fb->height; Xe_SetClearColor(g_pVideoDevice, 0); edram_init(g_pVideoDevice); }
static void XeTexSubImage(struct XenosSurface * surf, int xoffset, int yoffset, int width, int height, const void * buffer) { int srcbpp = 4; int dstbpp = 4; if (surf) { uint8_t * surfbuf = (uint8_t*) Xe_Surface_LockRect(g_pVideoDevice, surf, 0, 0, 0, 0, XE_LOCK_WRITE); uint8_t * srcdata = (uint8_t*) buffer; uint8_t * dstdata = surfbuf; int srcbytes = srcbpp; int dstbytes = dstbpp; int y, x; int pitch_d = (surf->wpitch); int pitch_s = (bitmap.pitch); int offset_d = 0; int offset_s = 0; for (y = yoffset; y < (yoffset + height); y++) { offset_d = (y * pitch_d)+(xoffset * dstbytes); offset_s = (y * pitch_s)+(xoffset * srcbytes); dstdata = surfbuf + offset_d; // ok srcdata = buffer + offset_s; // ok for (x = xoffset; x < (xoffset + width); x++) { if (srcbpp == 4 && dstbytes == 4) { dstdata[0] = srcdata[0]; dstdata[1] = srcdata[1]; dstdata[2] = srcdata[2]; dstdata[3] = srcdata[3]; srcdata += srcbytes; dstdata += dstbytes; } } } Xe_Surface_Unlock(g_pVideoDevice, surf); } }
static void MyXeSurfaceUnlock(struct XenosDevice *xe, struct XenosSurface *surface) { return Xe_Surface_Unlock(xe, surface); }
void CreateDisplay(void) { #ifndef LZX_GUI g_pVideoDevice = &_xe; Xe_Init(g_pVideoDevice); #else g_pVideoDevice = getLzxVideoDevice(); #endif fb = Xe_GetFramebufferSurface(g_pVideoDevice); Xe_SetRenderTarget(g_pVideoDevice, fb); /* mame HLSL struct VS_INPUT { float4 Position : POSITION; float4 Color : COLOR0; float2 TexCoord : TEXCOORD0; }; */ static const struct XenosVBFFormat vbf = { 3, { {XE_USAGE_POSITION, 0, XE_TYPE_FLOAT4}, {XE_USAGE_COLOR, 0, XE_TYPE_UBYTE4}, {XE_USAGE_TEXCOORD, 0, XE_TYPE_FLOAT2}, } }; #ifdef MAME_SHADER g_pPixelTexturedShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) g_xps_ps_main); #else g_pPixelTexturedShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) g_xps_PS); #endif //g_pPixelTexturedShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) draw_t_p_psu); Xe_InstantiateShader(g_pVideoDevice, g_pPixelTexturedShader, 0); #ifdef MAME_SHADER g_pVertexShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) g_xvs_vs_main); #else g_pVertexShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) g_xvs_VS); #endif //g_pVertexShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) draw_v_vsu); Xe_InstantiateShader(g_pVideoDevice, g_pVertexShader, 0); Xe_ShaderApplyVFetchPatches(g_pVideoDevice, g_pVertexShader, 0, &vbf); edram_init(g_pVideoDevice); // Create the psxScreen texture if (g_pTexture) Xe_DestroyTexture(g_pVideoDevice, g_pTexture); g_pTexture = Xe_CreateTexture(g_pVideoDevice, psxRealW, psxRealH, 1, XE_FMT_8888 | XE_FMT_ARGB, 0); psxScreen = (unsigned char*) Xe_Surface_LockRect(g_pVideoDevice, g_pTexture, 0, 0, 0, 0, XE_LOCK_WRITE); g_pPitch = g_pTexture->wpitch; Xe_Surface_Unlock(g_pVideoDevice, g_pTexture); memset(psxScreen, 0, 1024 * 512 * 2); // move it to ini file float x = -1.0f; float y = -1.0f; float w = 2.0f; float h = 2.0f; // top left Rect[0].x = x; Rect[0].y = y + h; Rect[0].u = PsxScreenUv[UvBottom]; Rect[0].v = PsxScreenUv[UvRight]; Rect[0].color = 0; // bottom left Rect[1].x = x; Rect[1].y = y; Rect[1].u = PsxScreenUv[UvBottom]; Rect[1].v = PsxScreenUv[UvLeft]; Rect[1].color = 0; // top right Rect[2].x = x + w; Rect[2].y = y + h; Rect[2].u = PsxScreenUv[UvTop]; Rect[2].v = PsxScreenUv[UvRight]; Rect[2].color = 0; // top right Rect[3].x = x + w; Rect[3].y = y + h; Rect[3].u = PsxScreenUv[UvTop]; ; Rect[3].v = PsxScreenUv[UvRight]; Rect[3].color = 0; // bottom left Rect[4].x = x; Rect[4].y = y; Rect[4].u = PsxScreenUv[UvBottom]; Rect[4].v = PsxScreenUv[UvLeft]; Rect[4].color = 0; // bottom right Rect[5].x = x + w; Rect[5].y = y; Rect[5].u = PsxScreenUv[UvTop]; Rect[5].v = PsxScreenUv[UvLeft]; Rect[5].color = 0; int i = 0; for (i = 0; i < 6; i++) { Rect[i].z = 0.0; Rect[i].w = 1.0; } CreateTexture(psxRealW, psxRealH); Xe_SetClearColor(g_pVideoDevice, 0); }
void SYSVideoInit() { g_pVideoDevice = GetVideoDevice(); Xe_SetRenderTarget(g_pVideoDevice, Xe_GetFramebufferSurface(g_pVideoDevice)); if (video_initialised == 0) { // init 2xsai buffer hq_buffer = (unsigned char*) malloc(1024 * 1024 * 4); static const struct XenosVBFFormat vbf = { 3, { {XE_USAGE_POSITION, 0, XE_TYPE_FLOAT4}, {XE_USAGE_COLOR, 0, XE_TYPE_UBYTE4}, {XE_USAGE_TEXCOORD, 0, XE_TYPE_FLOAT2}, } }; g_pPixelTexturedShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) g_xps_PS); Xe_InstantiateShader(g_pVideoDevice, g_pPixelTexturedShader, 0); g_pVertexShader = Xe_LoadShaderFromMemory(g_pVideoDevice, (void*) g_xvs_VS); Xe_InstantiateShader(g_pVideoDevice, g_pVertexShader, 0); Xe_ShaderApplyVFetchPatches(g_pVideoDevice, g_pVertexShader, 0, &vbf); if (g_pTexture == NULL) g_pTexture = Xe_CreateTexture(g_pVideoDevice, XE_W, XE_H, 1, XE_FMT_8888 | XE_FMT_ARGB, 0); texture_buffer = (unsigned char*) Xe_Surface_LockRect(g_pVideoDevice, g_pTexture, 0, 0, 0, 0, XE_LOCK_WRITE); pitch = g_pTexture->wpitch; Xe_Surface_Unlock(g_pVideoDevice, g_pTexture); } memset(hq_buffer, 0, 1024 * 1024 * 4); // disable filtering /* if (config.video_filter) g_pTexture->use_filtering = 1; else g_pTexture->use_filtering = 0; */ /* screen = texture_buffer; * pitch = g_pTexture->wpitch; */ screen = hq_buffer; /* float w = 2.0f; float h = 2.0f; */ if (video_initialised == 0) { // move it to ini file float x = -1.0f; float y = 1.0f; float w = 2.0f; float h = 2.0f; vb = Xe_CreateVertexBuffer(g_pVideoDevice, 3 * sizeof (DrawVerticeFormats)); DrawVerticeFormats *Rect = Xe_VB_Lock(g_pVideoDevice, vb, 0, 3 * sizeof (DrawVerticeFormats), XE_LOCK_WRITE); { // top left Rect[0].x = x; Rect[0].y = y; Rect[0].u = ScreenUv[UvBottom]; Rect[0].v = ScreenUv[UvRight]; Rect[0].color = 0; // bottom left Rect[1].x = x; Rect[1].y = y - h; Rect[1].u = ScreenUv[UvBottom]; Rect[1].v = ScreenUv[UvLeft]; Rect[1].color = 0; // top right Rect[2].x = x + w; Rect[2].y = y; Rect[2].u = ScreenUv[UvTop]; Rect[2].v = ScreenUv[UvRight]; Rect[2].color = 0; int i = 0; for (i = 0; i < 3; i++) { Rect[i].z = 0.0; Rect[i].w = 1.0; } } Xe_VB_Unlock(g_pVideoDevice, vb); } if (video_initialised == 0) video_initialised = 1; }
static struct XenosSurface *loadPNGFromMemory(unsigned char *PNGdata) { int y = 0; int width, height; png_byte color_type; png_byte bit_depth; png_structp png_ptr; png_infop info_ptr; // int number_of_passes; png_bytep * row_pointers; offset = 0; struct file_buffer_t *file; file = (struct file_buffer_t *) malloc(sizeof (struct file_buffer_t)); file->length = 1024 * 1024 * 5; file->data = (unsigned char *) malloc(file->length); //5mo ... file->offset = 0; memcpy(file->data, PNGdata, file->length); /* initialize stuff */ png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (!png_ptr) { printf("[read_png_file] png_create_read_struct failed\n"); return 0; } info_ptr = png_create_info_struct(png_ptr); if (!info_ptr) { printf("[read_png_file] png_create_info_struct failed\n"); return 0; } png_set_read_fn(png_ptr, (png_voidp *) file, png_mem_read); //permet de lire à partir de pngfile buff //png_set_sig_bytes(png_ptr, 8);//on avance de 8 ? png_read_info(png_ptr, info_ptr); width = info_ptr->width; height = info_ptr->height; color_type = info_ptr->color_type; bit_depth = info_ptr->bit_depth; // number_of_passes = png_set_interlace_handling(png_ptr); if (color_type != PNG_COLOR_TYPE_RGB && color_type != PNG_COLOR_TYPE_RGB_ALPHA) { printf("no support :( \n bit_depth = %08x\n", bit_depth); return 0; } if (color_type == PNG_COLOR_TYPE_RGB) png_set_filler(png_ptr, 0xFF, PNG_FILLER_BEFORE); png_set_swap_alpha(png_ptr); png_read_update_info(png_ptr, info_ptr); //On créer la surface struct XenosSurface *surface = Xe_CreateTexture(g_pVideoDevice, width, height, 1, XE_FMT_8888 | XE_FMT_ARGB, 0); uint8_t *data = (uint8_t*) Xe_Surface_LockRect(g_pVideoDevice, surface, 0, 0, 0, 0, XE_LOCK_WRITE); row_pointers = (png_bytep*) malloc(sizeof (png_bytep) * surface->height); for (y = 0; y < surface->height; y++) row_pointers[y] = data + surface->wpitch * y; png_read_image(png_ptr, row_pointers); Xe_Surface_Unlock(g_pVideoDevice, surface); free(file->data); free(file); free(row_pointers); return surface; }
void osd_xenon_update_video(render_primitive_list &primlist) { //primlist->acquire_lock(); currList = &primlist; pre_render(); int minwidth, minheight; int newwidth, newheight; // get the minimum width/height for the current layout xenos_target->compute_minimum_size(minwidth, minheight); // minwidth = screen_width; // minheight = screen_height; // make that the size of our target xenos_target->set_bounds(minwidth, minheight); xenos_target->compute_visible_area(screen_width, screen_height, screen_width / screen_height, xenos_target->orientation(), newwidth, newheight); //ShaderEffects.at(2).Render(minwidth, minheight); ShaderEffects.at(0).Render(minwidth, minheight); Xe_SetStreamSource(g_pVideoDevice, 0, soft_vb, nb_vertices, sizeof (MameVerticeFormats)); vertices = (MameVerticeFormats *) Xe_VB_Lock(g_pVideoDevice, soft_vb, 0, 3 * sizeof (MameVerticeFormats), XE_LOCK_WRITE); //CreateRect(((float) newwidth / (float) screen_width), -((float) newheight / (float) screen_height), vertices); CreateRectHlsl(screen_width, screen_height, vertices); Xe_VB_Unlock(g_pVideoDevice, soft_vb); // update texture //draw32_draw_primitives(primlist, screen, minwidth, minheight, g_pTexture->wpitch / 4); /* loop over the list and render each element */ const render_primitive *prim; void *dstdata = (void *) screen; UINT32 width = minwidth; UINT32 height = minheight; UINT32 pitch = g_pTexture->wpitch / 4; /* for (prim = currList->first(); prim != NULL; prim = prim->next()) { switch (prim->type) { case render_primitive::LINE: draw32_draw_line(prim, dstdata, width, height, pitch); break; case render_primitive::QUAD: if (!prim->texture.base) draw32_draw_rect(prim, dstdata, width, height, pitch); else draw32_setup_and_draw_textured_quad(prim, dstdata, width, height, pitch); break; default: throw emu_fatalerror("Unexpected render_primitive type"); } } * */ software_renderer<UINT32, 0,0,0, 16,8,0>::draw_primitives(primlist, dstdata, width, height, pitch); Xe_Surface_LockRect(g_pVideoDevice, g_pTexture, 0, 0, 0, 0, XE_LOCK_WRITE); Xe_Surface_Unlock(g_pVideoDevice, g_pTexture); // correct texture size g_pTexture->width = minwidth; g_pTexture->height = minheight; // draw Xe_SetTexture(g_pVideoDevice, 0, g_pTexture); Xe_DrawPrimitive(g_pVideoDevice, XE_PRIMTYPE_RECTLIST, 0, 1); render(); }