texture_info *renderer_sdl2::texture_find(const render_primitive &prim, const quad_setup_data &setup) { HashT texhash = texture_compute_hash(prim.texture, prim.flags); texture_info *texture; osd_ticks_t now = osd_ticks(); // find a match for (texture = m_texlist.first(); texture != nullptr; ) if (texture->hash() == texhash && texture->matches(prim, setup)) { /* would we choose another blitter based on performance ? */ if ((texture->m_copyinfo->samples & 0x7f) == 0x7f) { if (texture->m_copyinfo != texture->compute_size_type()) return nullptr; } texture->m_last_access = now; return texture; } else { /* free resources not needed any longer? */ texture_info *expire = texture; texture = texture->next(); if (now - expire->m_last_access > osd_ticks_per_second()) m_texlist.remove(*expire); } // nothing found return nullptr; }
static texture_info *texture_find(sdl_info *sdl, const render_primitive *prim, quad_setup_data *setup) { HashT texhash = texture_compute_hash(&prim->texture, prim->flags); texture_info *texture; osd_ticks_t now = osd_ticks(); // find a match for (texture = sdl->texlist; texture != NULL; ) if (texture->hash == texhash && texture->texinfo.base == prim->texture.base && texture->texinfo.width == prim->texture.width && texture->texinfo.height == prim->texture.height && texture->texinfo.rowpixels == prim->texture.rowpixels && texture->setup.dudx == setup->dudx && texture->setup.dvdx == setup->dvdx && texture->setup.dudy == setup->dudy && texture->setup.dvdy == setup->dvdy && ((texture->flags ^ prim->flags) & (PRIMFLAG_BLENDMODE_MASK | PRIMFLAG_TEXFORMAT_MASK)) == 0) { /* would we choose another blitter ? */ if ((texture->copyinfo->samples & 0x1f) == 0x1f) { if (texture->copyinfo != texture_compute_size_type(sdl->sdl_renderer, &texture->texinfo, texture, prim->flags)) return NULL; #if 0 else { /* reset stats */ texture->copyinfo->samples = 0; texture->copyinfo->time = 0; texture->copyinfo->pixel_count = 0; } #endif } texture->last_access = now; return texture; } else { /* free resources not needed any longer? */ texture_info *expire = texture; texture = texture->next; if (now - expire->last_access > osd_ticks_per_second()) draw13_destroy_texture(sdl, expire); } // nothing found return NULL; }
texture_info::texture_info(renderer_sdl2 *renderer, const render_texinfo &texsource, const quad_setup_data &setup, UINT32 flags) { // fill in the core data m_renderer = renderer; m_hash = texture_compute_hash(texsource, flags); m_flags = flags; m_texinfo = texsource; m_texinfo.seqid = -1; // force set data m_is_rotated = false; m_setup = setup; m_sdl_blendmode = map_blendmode(PRIMFLAG_GET_BLENDMODE(flags)); m_pitch = 0; switch (PRIMFLAG_GET_TEXFORMAT(flags)) { case TEXFORMAT_ARGB32: m_format = SDL_TEXFORMAT_ARGB32; break; case TEXFORMAT_RGB32: m_format = texsource.palette ? SDL_TEXFORMAT_RGB32_PALETTED : SDL_TEXFORMAT_RGB32; break; case TEXFORMAT_PALETTE16: m_format = SDL_TEXFORMAT_PALETTE16; break; case TEXFORMAT_PALETTEA16: m_format = SDL_TEXFORMAT_PALETTE16A; break; case TEXFORMAT_YUY16: m_format = texsource.palette ? SDL_TEXFORMAT_YUY16_PALETTED : SDL_TEXFORMAT_YUY16; break; default: osd_printf_error("Unknown textureformat %d\n", PRIMFLAG_GET_TEXFORMAT(flags)); } if (setup.rotwidth != m_texinfo.width || setup.rotheight != m_texinfo.height || setup.dudx < 0 || setup.dvdy < 0 || (PRIMFLAG_GET_TEXORIENT(flags) != 0)) m_is_rotated = true; else m_is_rotated = false; //m_sdl_access = SDL_TEXTUREACCESS_STATIC; m_sdl_access = SDL_TEXTUREACCESS_STREAMING; // Watch out for 0x0 textures ... if (!m_setup.rotwidth || !m_setup.rotheight) osd_printf_warning("Trying to create texture with zero dim\n"); // set copy_info m_copyinfo = compute_size_type(); m_texture_id = SDL_CreateTexture(m_renderer->m_sdl_renderer, m_copyinfo->dst_fmt, m_sdl_access, m_setup.rotwidth, m_setup.rotheight); if (!m_texture_id) osd_printf_error("Error creating texture: %d x %d, pixelformat %s error: %s\n", m_setup.rotwidth, m_setup.rotheight, m_copyinfo->dstname, SDL_GetError()); if (m_sdl_access == SDL_TEXTUREACCESS_STATIC) { if (m_copyinfo->blitter->m_is_passthrough) m_pixels = nullptr; else m_pixels = malloc(m_setup.rotwidth * m_setup.rotheight * m_copyinfo->blitter->m_dest_bpp); } m_last_access = osd_ticks(); }
static texture_info *texture_create(sdl_window_info *window, const render_texinfo *texsource, quad_setup_data *setup, UINT32 flags) { sdl_info *sdl = (sdl_info *) window->dxdata; texture_info *texture; // allocate a new texture texture = (texture_info *) osd_malloc(sizeof(*texture)); memset(texture, 0, sizeof(*texture)); // fill in the core data texture->hash = texture_compute_hash(texsource, flags); texture->flags = flags; texture->texinfo = *texsource; texture->texinfo.seqid = -1; // force set data texture->is_rotated = FALSE; texture->setup = *setup; texture->sdl_blendmode = map_blendmode(PRIMFLAG_GET_BLENDMODE(flags)); switch (PRIMFLAG_GET_TEXFORMAT(flags)) { case TEXFORMAT_ARGB32: texture->format = SDL_TEXFORMAT_ARGB32; break; case TEXFORMAT_RGB32: texture->format = texsource->palette ? SDL_TEXFORMAT_RGB32_PALETTED : SDL_TEXFORMAT_RGB32; break; case TEXFORMAT_PALETTE16: texture->format = SDL_TEXFORMAT_PALETTE16; break; case TEXFORMAT_PALETTEA16: texture->format = SDL_TEXFORMAT_PALETTE16A; break; case TEXFORMAT_YUY16: texture->format = texsource->palette ? SDL_TEXFORMAT_YUY16_PALETTED : SDL_TEXFORMAT_YUY16; break; default: mame_printf_error("Unknown textureformat %d\n", PRIMFLAG_GET_TEXFORMAT(flags)); } texture->rawwidth = texsource->width; texture->rawheight = texsource->height; if (setup->rotwidth != texture->rawwidth || setup->rotheight != texture->rawheight || setup->dudx < 0 ) texture->is_rotated = TRUE; else texture->is_rotated = FALSE; //texture->sdl_access = SDL_TEXTUREACCESS_STATIC; texture->sdl_access = SDL_TEXTUREACCESS_STREAMING; // Watch out for 0x0 textures ... if (!texture->setup.rotwidth || !texture->setup.rotheight) mame_printf_warning("Trying to create texture with zero dim\n"); // compute the size texture->copyinfo = texture_compute_size_type(sdl->sdl_renderer, texsource, texture, flags); texture->texture_id = SDL_CreateTexture(sdl->sdl_renderer, texture->copyinfo->dst_fmt, texture->sdl_access, texture->setup.rotwidth, texture->setup.rotheight); if (!texture->texture_id) mame_printf_error("Error creating texture: %d x %d, pixelformat %s error: %s\n", texture->setup.rotwidth, texture->setup.rotheight, texture->copyinfo->dstname, SDL_GetError()); if ( (texture->copyinfo->func != NULL) && (texture->sdl_access == SDL_TEXTUREACCESS_STATIC)) { texture->pixels = osd_malloc_array(texture->setup.rotwidth * texture->setup.rotheight * texture->copyinfo->dst_bpp); texture->pixels_own=TRUE; } /* add us to the texture list */ texture->next = sdl->texlist; sdl->texlist = texture; texture->last_access = osd_ticks(); return texture; }