void GUIController::update(bool readNES) { void *nesPixels = nullptr; void *overlayPixels = nullptr; int pitch = 0; // Update the overlay if (SDL_LockTexture(m_texOverlay, nullptr, &overlayPixels, &pitch) < 0) return; memcpy(overlayPixels, m_overlay->getPixels(), m_overlay->getDataSize()); SDL_UnlockTexture(m_texOverlay); // Only update the NES image if we have to if (readNES) { if (SDL_LockTexture(m_tex, nullptr, &nesPixels, &pitch) < 0) return; m_state.blit((int32_t*)nesPixels, HQNState::NES_VIDEO_PALETTE, 0, 0, 0, 0); SDL_UnlockTexture(m_tex); } // render to screen SDL_RenderClear(m_renderer); SDL_RenderCopy(m_renderer, m_tex, &NES_BLIT_RECT, &m_nesDest); SDL_RenderCopy(m_renderer, m_texOverlay, nullptr, &m_overlayDest); SDL_RenderPresent(m_renderer); // Process any outstanding events processEvents(); }
void SDLRenderTarget::UploadTexture() { void* pixels = NULL; SDL_LockTexture(texture, NULL, &pixels, &pitch); BlitTexture32((uint8_t*)pixels); SDL_UnlockTexture(texture); }
void Texture::LockedPixels::unlock() { if (m_texture) { SDL_UnlockTexture(m_texture->m_texture.get()); } }
void SDLFilm::afterSet() { if (!texture) return; SDL_FreeFormat(pixelFormat); pixelFormat = nullptr; pixels = nullptr; SDL_UnlockTexture(texture); }
struct graphicstexture *graphicstexture_createHWSDL( struct graphicstexture *gt, void *data, size_t width, size_t height, int format, uint64_t time) { // create hw texture #ifdef DEBUGUPLOADTIMING uint64_t ts1 = time_getMilliseconds(); #endif gt->sdltex = SDL_CreateTexture(mainrenderer, graphicstexture_pixelFormatToSDLFormat(format), SDL_TEXTUREACCESS_STREAMING, gt->width, gt->height); if (!gt->sdltex) { graphicstexture_destroy(gt); return NULL; } #ifdef DEBUGUPLOADTIMING uint64_t ts2 = time_getMilliseconds(); #endif // lock texture void *pixels; int pitch; if (SDL_LockTexture(gt->sdltex, NULL, &pixels, &pitch) != 0) { graphicstexture_destroy(gt); return NULL; } #ifdef DEBUGUPLOADTIMING uint64_t ts3 = time_getMilliseconds(); #endif // copy pixels into texture memcpy(pixels, data, gt->width * gt->height * 4); // FIXME: we probably need to handle pitch here?? #ifdef DEBUGUPLOADTIMING uint64_t ts4 = time_getMilliseconds(); #endif // unlock texture SDL_UnlockTexture(gt->sdltex); #ifdef DEBUGUPLOADTIMING uint64_t ts5 = time_getMilliseconds(); if (ts5-ts1 > 100) { printwarning("[sdltex] texture upload duration: %dms total, " "%dms creation, %dms lock, %dms copy, %dms unlock", (int)(ts5-ts1), (int)(ts2-ts1), (int)(ts3-ts2), (int)(ts4-ts3), (int)(ts5-ts4)); } #endif // set blend mode SDL_SetTextureBlendMode(gt->sdltex, SDL_BLENDMODE_BLEND); return gt; }
static int releaseBuffer_streamRenderer(WVStreamingObject* streamObj, int slotIdx) { StreamRendererPrivate* objPrivate = (StreamRendererPrivate*)streamObj->objPrivate; /* release the textures */ SDL_UnlockTexture(objPrivate->slotTexture[slotIdx]); return 0; }
bool CollisionDetect::pixelCheck(Sprite* sprite1, Sprite* sprite2) { //Kod för pixel rgba separation SDL_Texture* pic = sprite1->getPic()->getPic(); int pitch, w, h; void* pixels; SDL_SetTextureBlendMode(pic, SDL_BLENDMODE_BLEND); SDL_QueryTexture(pic, NULL, NULL, &w, &h); SDL_LockTexture(pic, NULL, &pixels, &pitch); Uint32* uPixels = (Uint32*) pixels; Uint32 alpha1 = SDL_MapRGBA(SDL_GetWindowSurface(sprite1->getWindow())->format, 0xFF, 0xFF, 0XFF, 0x00); SDL_Texture* pic2 = sprite2->getPic()->getPic(); int pitch2, w2, h2; void* pixels2; SDL_SetTextureBlendMode(pic2, SDL_BLENDMODE_BLEND); SDL_QueryTexture(pic2, NULL, NULL, &w2, &h2); SDL_LockTexture(pic2, NULL, &pixels2, &pitch2); Uint32* uPixels2 = (Uint32*) pixels2; bool found = false; int i = 0; while(!found || i < w * h) { if(uPixels[i] != alpha1) if(uPixels2[i] != alpha1) found = true; i++; } SDL_UnlockTexture(pic); SDL_UnlockTexture(pic2); return found; }
void Texture::LoadTexture_fromMemoryPage(const MemoryPage& input_page, const ScreenVideo& makerVideo) throw(Error){ this->Clean(); if(makerVideo.m_renderer==nullptr) throw Error("Texture","LoadTexture_fromMemoryPage","Impossibile caricare una texture con uno specifico renderer nullo!"); if(makerVideo.m_renderer!=m_render) m_render = makerVideo.m_renderer; if(input_page.GetSize()==0) return; if(m_render==nullptr) throw Error("Texture","LoadTexture_fromMemoryPage","Impossibile caricare la texture richiesta!\nRenderer non inizializzato!"); SDL_RWops* data_access = SDL_RWFromConstMem(input_page.Get_PtrMemory(),input_page.GetSize()); if(data_access==nullptr){ throw Error("Texture","LoadTexture_fromMemoryPage","Pagina di memoria corrotta!\n%s",SDL_GetError()); }else{ SDL_Surface* image_load = IMG_Load_RW(data_access,1); if(image_load==nullptr){ throw Error("Texture","LoadTexture_fromMemoryPage","Impossibile caricare correttamente la texture richiesta\n%s",SDL_GetError()); }else{ SDL_Surface* image_opt = SDL_ConvertSurfaceFormat(image_load,SDL_PIXELFORMAT_RGBA8888,0); SDL_FreeSurface(image_load); image_load=nullptr; if(image_opt==nullptr){ throw Error("Texture","LoadTexture_fromMemoryPage","Impossibile ottimizzare correttamente la texture richiesta\n%s",SDL_GetError()); } this->m_texture = SDL_CreateTexture(m_render,SDL_PIXELFORMAT_RGBA8888,SDL_TEXTUREACCESS_STREAMING,image_opt->w,image_opt->h); if(this->m_texture==nullptr){ SDL_FreeSurface(image_opt); throw Error("Texture","LoadTexture_fromMemoryPage","Impossibile creare una texture grafica!\n%s",SDL_GetError()); } void* data_pixel_texture; int pitch_pixel_texture; if(SDL_LockTexture(m_texture,NULL,&data_pixel_texture,&pitch_pixel_texture)!=0){ SDL_FreeSurface(image_opt); SDL_DestroyTexture(m_texture); throw Error("Texture","LoadTexture_fromMemoryPage","Impossibile scrivere la texture grafica!\n%s",SDL_GetError()); } memcpy(data_pixel_texture,image_opt->pixels,image_opt->pitch * image_opt->h); SDL_UnlockTexture(m_texture); data_pixel_texture=nullptr; m_w_size = image_opt->w; m_h_size = image_opt->h; m_w_size_scaled = image_opt->w; m_h_size_scaled = image_opt->h; m_drawnable_area.Set_AllComponent(0,0,image_opt->w,image_opt->h); m_alpha_mod = SDL_ALPHA_OPAQUE; SDL_FreeSurface(image_opt); image_opt=nullptr; SDL_SetTextureBlendMode(m_texture,SDL_BLENDMODE_BLEND); } } }
void vid_draw (int32 x, int32 y, int32 w, int32 h, uint32 *buf) { int32 i; uint32 *pixels; int pitch; SDL_LockTexture(vid_texture, NULL, (void *)&pixels, &pitch); for (i = y; i < (y + h); i++) memcpy (pixels + (i * vid_width) + x, buf, (size_t)w*sizeof(*pixels)); SDL_UnlockTexture(vid_texture); }
void Render_SW_SDL::getPixelData(const PGE_Texture *tx, unsigned char *pixelData) { if(!tx) return; setRenderTexture( ((PGE_Texture *)tx)->texture ); int pitch, w, h, a; void *pixels; SDL_SetTextureBlendMode(m_currentTexture, SDL_BLENDMODE_BLEND); SDL_QueryTexture(m_currentTexture, NULL, &a, &w, &h); SDL_LockTexture(m_currentTexture, NULL, &pixels, &pitch); memcpy( pixelData, pixels, pitch*h); SDL_UnlockTexture(m_currentTexture); setUnbindTexture(); }
void mSDLSWRunloop(struct mSDLRenderer* renderer, void* user) { struct mCoreThread* context = user; SDL_Event event; #if !SDL_VERSION_ATLEAST(2, 0, 0) SDL_Surface* surface = SDL_GetVideoSurface(); #endif while (mCoreThreadIsActive(context)) { while (SDL_PollEvent(&event)) { mSDLHandleEvent(context, &renderer->player, &event); } if (mCoreSyncWaitFrameStart(&context->impl->sync)) { #if SDL_VERSION_ATLEAST(2, 0, 0) SDL_UnlockTexture(renderer->sdlTex); SDL_RenderCopy(renderer->sdlRenderer, renderer->sdlTex, 0, 0); SDL_RenderPresent(renderer->sdlRenderer); int stride; SDL_LockTexture(renderer->sdlTex, 0, (void**) &renderer->outputBuffer, &stride); renderer->core->setVideoBuffer(renderer->core, renderer->outputBuffer, stride / BYTES_PER_PIXEL); #else #ifdef USE_PIXMAN if (renderer->ratio > 1) { pixman_image_composite32(PIXMAN_OP_SRC, renderer->pix, 0, renderer->screenpix, 0, 0, 0, 0, 0, 0, renderer->viewportWidth, renderer->viewportHeight); } #else switch (renderer->ratio) { #if defined(__ARM_NEON) && COLOR_16_BIT case 2: _neon2x(surface->pixels, renderer->outputBuffer, width, height); break; case 4: _neon4x(surface->pixels, renderer->outputBuffer, width, height); break; #endif case 1: break; default: abort(); } #endif SDL_UnlockSurface(surface); SDL_Flip(surface); SDL_LockSurface(surface); #endif } mCoreSyncWaitFrameEnd(&context->impl->sync); } }
//----------------------------------------------------------------------------- void AdScreen::Present(void) { int pitch; void* pixels; SDL_LockTexture(s_pTexture, NULL, &pixels, &pitch); SDL_ConvertPixels( s_pScreen->w, s_pScreen->h, s_pScreen->format->format, s_pScreen->pixels, s_pScreen->pitch, SDL_PIXELFORMAT_RGBA8888, pixels, pitch ); SDL_UnlockTexture(s_pTexture); SDL_RenderCopy(GetRenderer(), s_pTexture, NULL, NULL); SDL_RenderPresent(GetRenderer()); s_iFrames++; s_uiCurrentCount = SDL_GetPerformanceCounter(); s_uiDiffCount = (s_uiCurrentCount-s_uiLastCount); s_uiCountFreq = SDL_GetPerformanceFrequency(); s_fElapsedTime = ((float) s_uiDiffCount/(float) s_uiCountFreq); if((1.0f/60.0f)-s_fElapsedTime > 0) { // NOTE: without this there seems to be a more consistent framerate // but on older computers sometimes the vsync doesn't work right //SDL_Delay((uint32_t) (1000.0f*((1.0f/60.0f)-s_fElapsedTime))); s_fTotTime += 1.0f/60.0f; } else { s_fTotTime += s_fElapsedTime; } s_uiLastCount = s_uiCurrentCount; if(s_fTotTime >= 1.0f) { char strTitle[0x20] = ""; sprintf(strTitle, "%s, FPS: %d", WINDOW_TITLE, s_iFrames); SDL_SetWindowTitle(GetWindow(), strTitle); s_fTotTime = 0; s_iFrames = 0; } }
SDL_Texture* Texture::CopyInternalTexture(const Texture& src) throw(Error){ if(src.m_texture==nullptr || src.m_render==nullptr) return nullptr; SDL_Texture* rts = SDL_CreateTexture(src.m_render,SDL_PIXELFORMAT_RGBA8888,SDL_TEXTUREACCESS_STREAMING,src.m_w_size,src.m_h_size); if(rts==nullptr) throw Error("Texture","CopyInternalTexture","Impossibile inizializzare una texture grafica!\n%s",SDL_GetError()); void* src_pixel_data=nullptr; void* dest_pixel_data=nullptr; int src_pitch=0; int dest_pitch=0; if(SDL_LockTexture(src.m_texture,NULL,&src_pixel_data,&src_pitch)!=0){ SDL_DestroyTexture(rts); throw Error("Texture","CopyInternalTexture","Impossibile accedere ai dati della sorgente!\n%s",SDL_GetError()); } if(SDL_LockTexture(rts,NULL,&dest_pixel_data,&dest_pitch)!=0){ SDL_UnlockTexture(src.m_texture); SDL_DestroyTexture(rts); throw Error("Texture","CopyInternalTexture","Impossibile accedere ai dati della destinazione!\n%s",SDL_GetError()); } try{ memcpy(dest_pixel_data,src_pixel_data,src_pitch * src.m_h_size); }catch(std::exception& err){ SDL_UnlockTexture(src.m_texture); SDL_UnlockTexture(rts); SDL_DestroyTexture(rts); throw Error("Texture","CopyInternalTexture","Impossibile copiare i dati nella destinazione!\n%s",err.what()); } SDL_UnlockTexture(src.m_texture); SDL_UnlockTexture(rts); src_pixel_data=nullptr; dest_pixel_data=nullptr; SDL_SetTextureBlendMode(rts,SDL_BLENDMODE_BLEND); return rts; }
bool LTexture::loadFromFile( std::string path ) { //Get rid of preexisting texture free(); //The final texture SDL_Texture* newTexture = NULL; //Load image at specified path SDL_Surface* loadedSurface = IMG_Load( path.c_str() ); if( loadedSurface == NULL ) { printf( "Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError() ); } else { //Convert surface to display format SDL_Surface* formattedSurface = SDL_ConvertSurface( loadedSurface, SDL_GetWindowSurface( gWindow )->format, NULL ); if( formattedSurface == NULL ) { printf( "Unable to convert loaded surface to display format! SDL Error: %s\n", SDL_GetError() ); } else { //Create blank streamable texture newTexture = SDL_CreateTexture( gRenderer, SDL_GetWindowPixelFormat( gWindow ), SDL_TEXTUREACCESS_STREAMING, formattedSurface->w, formattedSurface->h ); if( newTexture == NULL ) { printf( "Unable to create blank texture! SDL Error: %s\n", SDL_GetError() ); } else { //Lock texture for manipulation SDL_LockTexture( newTexture, NULL, &mPixels, &mPitch ); //Copy loaded/formatted surface pixels memcpy( mPixels, formattedSurface->pixels, formattedSurface->pitch * formattedSurface->h ); //Unlock texture to update SDL_UnlockTexture( newTexture ); mPixels = NULL; //Get image dimensions mWidth = formattedSurface->w; mHeight = formattedSurface->h; } //Get rid of old formatted surface SDL_FreeSurface( formattedSurface ); } //Get rid of old loaded surface SDL_FreeSurface( loadedSurface ); } //Return success mTexture = newTexture; return mTexture != NULL; }
//------------------------------------------------------------------------ void platform_support::update_window() { SDL_UnlockTexture(m_specific->m_texture); SDL_RenderClear(m_specific->m_renderer); SDL_RenderCopy(m_specific->m_renderer, m_specific->m_texture, NULL, NULL); SDL_RenderPresent(m_specific->m_renderer); void* pixels; int pitch; if (SDL_LockTexture(m_specific->m_texture, NULL, &pixels, &pitch) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't lock texture: %s\n", SDL_GetError()); } }
// Copies surface to an existing texture. // Note, texture has to be streaming type int surface_to_texture(surface *src, SDL_Texture *tex, screen_palette *pal, char *remap_table, uint8_t pal_offset) { void *pixels; int pitch; if(SDL_LockTexture(tex, NULL, &pixels, &pitch) == 0) { surface_to_rgba(src, pixels, pal, remap_table, pal_offset); SDL_UnlockTexture(tex); return 0; } PERROR("Failed to lock texture (ptr: %d) for writing: %s", tex, SDL_GetError()); return 1; }
static void sdl_video_render(void) { int index = fs_emu_buffer_lock(); sdl_buffer *buffer = g_buffers + index; SDL_Texture *texture = g_textures[index]; // printf("size %d %d\n", buffer->buffer.width, buffer->buffer.height); // printf("crop %d %d %d %d\n", buffer->buffer.crop.x, buffer->buffer.crop.y, // buffer->buffer.crop.w, buffer->buffer.crop.h); // printf("updating texture (size %d) from buffer %d\n", buffer->size, index); SDL_Rect src_rect; #if 1 src_rect.x = buffer->buffer.crop.x; src_rect.y = buffer->buffer.crop.y; src_rect.w = buffer->buffer.crop.w; src_rect.h = buffer->buffer.crop.h; #else src_rect.x = 0; src_rect.y = 0; src_rect.w = buffer->buffer.width; src_rect.h = buffer->buffer.height; #endif SDL_Rect dst_rect; dst_rect.x = 0; dst_rect.y = 0; dst_rect.w = 752; dst_rect.h = 572; if (buffer->streaming) { SDL_UnlockTexture(texture); } else { SDL_UpdateTexture(texture, &src_rect, buffer->buffer.data + buffer->buffer.crop.y * \ buffer->buffer.stride + buffer->buffer.crop.x * \ buffer->buffer.bpp, buffer->buffer.stride); fs_emu_buffer_unlock(); } SDL_RenderClear(g_renderer); SDL_RenderCopy(g_renderer, texture, &src_rect, &dst_rect); SDL_RenderPresent(g_renderer); if (buffer->streaming) { SDL_LockTexture(texture, NULL, &(buffer->buffer.data), &(buffer->buffer.stride)); fs_emu_buffer_unlock(); } }
bool LTexture::unlockTexture() { bool success = true; if (mPixels == NULL) { printf("Texture is not locked!\n"); success = false; } else { SDL_UnlockTexture(mTexture); mPixels = NULL; mPitch = 0; } return success; }
//----------------- bool CTexture::unlockTexture( ) { bool success = true; //Texture is not locked if( m_pixels == nullptr ) { printf( "Texture is not locked!\n" ); success = false; } //Unlock texture else { SDL_UnlockTexture( m_texture ); m_pixels = nullptr; m_pitch = 0; } return success; }
bool Texture_UnlockTexture(Texture* texture) { bool success = true; if (texture->pixels == nullptr) { SDL_Log("Texture is not locked!\n"); success = false; } else { SDL_UnlockTexture(texture->texture); texture->pixels = nullptr; texture->pitch = 0; } return success; }
static int SDL_UpdateTextureYUV(SDL_Texture * texture, const SDL_Rect * rect, const void *pixels, int pitch) { SDL_Texture *native = texture->native; SDL_Rect full_rect; if (SDL_SW_UpdateYUVTexture(texture->yuv, rect, pixels, pitch) < 0) { return -1; } full_rect.x = 0; full_rect.y = 0; full_rect.w = texture->w; full_rect.h = texture->h; rect = &full_rect; if (texture->access == SDL_TEXTUREACCESS_STREAMING) { /* We can lock the texture and copy to it */ void *native_pixels; int native_pitch; if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) { return -1; } SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, native_pixels, native_pitch); SDL_UnlockTexture(native); } else { /* Use a temporary buffer for updating */ void *temp_pixels; int temp_pitch; temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3); temp_pixels = SDL_malloc(rect->h * temp_pitch); if (!temp_pixels) { SDL_OutOfMemory(); return -1; } SDL_SW_CopyYUVToRGB(texture->yuv, rect, native->format, rect->w, rect->h, temp_pixels, temp_pitch); SDL_UpdateTexture(native, rect, temp_pixels, temp_pitch); SDL_free(temp_pixels); } return 0; }
static int __lua_texture_unlock ( lua_State *_l ) { SDL_Texture *sdl_texture; ex_lua_check_nargs(_l,1); luaL_checktype( _l, 1, LUA_TLIGHTUSERDATA ); sdl_texture = lua_touserdata(_l,1); // if ( __locked_texture != sdl_texture ) { return luaL_error ( _l, "Can't operate different texture at the same time" ); } SDL_UnlockTexture ( __locked_texture ); __locked_texture = NULL; return 0; }
/* * render a frame * args: * frame - pointer to frame data (yuyv format) * width - frame width * height - frame height * * asserts: * poverlay is not nul * frame is not null * * returns: error code */ int render_sdl2_frame(uint8_t *frame, int width, int height) { /*asserts*/ assert(rending_texture != NULL); assert(frame != NULL); float vu_level[2]; render_get_vu_level(vu_level); #ifdef USE_PLANAR_YUV int size = width * height * 3/2; /* for IYUV */ #else int size = width * height * 2; /* 2 bytes per pixel for YUYV */ #endif void* texture_pixels; int pitch; SDL_SetRenderDrawColor(main_renderer, 0, 0, 0, 255); /*black*/ SDL_RenderClear(main_renderer); if (SDL_LockTexture(rending_texture, NULL, &texture_pixels, &pitch)) { fprintf(stderr, "RENDER: couldn't lock texture to write\n"); return -1; } memcpy(texture_pixels, frame, size); /*osd vu meter*/ if(((render_get_osd_mask() & (REND_OSD_VUMETER_MONO | REND_OSD_VUMETER_STEREO))) != 0) render_osd_vu_meter(texture_pixels, width, height, vu_level); /*osd crosshair*/ if(((render_get_osd_mask() & REND_OSD_CROSSHAIR)) != 0) render_osd_crosshair(texture_pixels, width, height); SDL_UnlockTexture(rending_texture); SDL_RenderCopy(main_renderer, rending_texture, NULL, NULL); SDL_RenderPresent(main_renderer); }
void Image::Commit(const Sample& aSample, Color aColor, aq_float aExposure) { mHDRBuffer[(int)aSample.y * mWidth + (int)aSample.x] = aColor; aColor = Color(1.0) - exp(-aColor * aExposure); SDL_Rect UpdateRect; UpdateRect.x = (int)aSample.x; UpdateRect.y = (int)aSample.y; UpdateRect.w = UpdateRect.h = 1; int pitch; void* TexturePixels; SDL_LockTexture(mTexture, &UpdateRect, &TexturePixels, &pitch); *((uint32_t*)TexturePixels) = ColorToRGBA(clamp(pow(aColor, 1.0/2.2), 0, 1)); SDL_UnlockTexture(mTexture); SDL_RenderCopy(mRenderer, mTexture, &UpdateRect, &UpdateRect); }
void Image::Render() { SDL_Rect UpdateRect; UpdateRect.x = 0; UpdateRect.y = 0; UpdateRect.w = mWidth; UpdateRect.h = mHeight; int pitch; void* TexturePixels; SDL_LockTexture(mTexture, &UpdateRect, &TexturePixels, &pitch); for (int i = 0; i < mImageSize; i++) { ((uint32_t*)TexturePixels)[i] = ColorToRGBA(mHDRBuffer[i]); } SDL_UnlockTexture(mTexture); SDL_RenderCopy(mRenderer, mTexture, &UpdateRect, &UpdateRect); }
void VideoRenderer::VideoOut(AVFrame *frame) { uint8_t *pixels; int pitch, size = width_ * height_; SDL_LockTexture(texture_, NULL, (void **) &pixels, &pitch); memcpy(pixels, frame->data[0], size); memcpy(pixels + size, frame->data[2], size / 4); memcpy(pixels + size * 5 / 4, frame->data[1], size / 4); SDL_UnlockTexture(texture_); SDL_UpdateTexture(texture_, NULL, pixels, pitch); // refresh screen SDL_RenderClear(renderer_); SDL_RenderCopy(renderer_, texture_, NULL, NULL); SDL_RenderPresent(renderer_); }
void graphics_present(Environment *environment) { if (environment -> fast_run) {return;} profiler_start(profile_present); void *pixels; int pitch; SDL_Rect rect; rect.x = 0; rect.y = 0; rect.w = environment -> width; rect.h = environment -> height; cairo_surface_flush(environment -> cairo_surface); SDL_UnlockTexture(environment -> base_texture); SDL_RenderCopy(environment -> renderer, environment -> base_texture, &rect, &rect); SDL_RenderPresent(environment -> renderer); SDL_LockTexture(environment -> base_texture, NULL, &pixels, &pitch); profiler_end(profile_present); }
static void save_screenshot(const char *filename) { if ( TCOD_ctx.renderer == TCOD_RENDERER_SDL ) { /* This would be a lot easier if image saving could do textures. */ SDL_Rect rect; SDL_RenderGetViewport(renderer, &rect); Uint32 format = SDL_GetWindowPixelFormat(window); SDL_Texture *texture = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_TARGET, rect.w, rect.h); if (0 != texture) { if (SDL_SetRenderTarget(renderer, texture)) { void *pixels; int pitch, access; actual_rendering(); SDL_SetRenderTarget(renderer, NULL); rect.x = rect.y = rect.w = rect.h = 0; if (-1 != SDL_QueryTexture(texture, &format, &access, &rect.w, &rect.h) && -1 != SDL_LockTexture(texture, NULL, &pixels, &pitch)) { int depth; Uint32 rmask, gmask, bmask, amask; if (SDL_TRUE == SDL_PixelFormatEnumToMasks(format, &depth, &rmask, &gmask, &bmask, &amask)) { SDL_Surface *surface = SDL_CreateRGBSurfaceFrom(pixels, rect.w, rect.h, depth, pitch, rmask, gmask, bmask, amask); TCOD_sys_save_bitmap((void *)surface,filename); SDL_FreeSurface(surface); } else TCOD_LOG(("TCOD_sys_save_screenshot - failed call to SDL_PixelFormatEnumToMasks")); SDL_UnlockTexture(texture); } else TCOD_LOG(("TCOD_sys_save_screenshot - failed call to SDL_QueryTexture or SDL_LockTexture")); } else TCOD_LOG(("TCOD_sys_save_screenshot - failed call to SDL_SetRenderTarget")); SDL_DestroyTexture(texture); } else TCOD_LOG(("TCOD_sys_save_screenshot - failed call to SDL_CreateTexture")); #ifndef NO_OPENGL } else { SDL_Surface *screenshot=(SDL_Surface *)TCOD_opengl_get_screen(); TCOD_sys_save_bitmap((void *)screenshot,filename); SDL_FreeSurface(screenshot); #endif } }
static void SDL_UnlockTextureNative(SDL_Texture * texture) { SDL_Texture *native = texture->native; void *native_pixels; int native_pitch; const SDL_Rect *rect = &texture->locked_rect; const void* pixels = (void *) ((Uint8 *) texture->pixels + rect->y * texture->pitch + rect->x * SDL_BYTESPERPIXEL(texture->format)); int pitch = texture->pitch; if (SDL_LockTexture(native, rect, &native_pixels, &native_pitch) < 0) { return; } SDL_ConvertPixels(rect->w, rect->h, texture->format, pixels, pitch, native->format, native_pixels, native_pitch); SDL_UnlockTexture(native); }
static void SDL_UnlockTextureYUV(SDL_Texture * texture) { SDL_Texture *native = texture->native; void *native_pixels; int native_pitch; SDL_Rect rect; rect.x = 0; rect.y = 0; rect.w = texture->w; rect.h = texture->h; if (SDL_LockTexture(native, &rect, &native_pixels, &native_pitch) < 0) { return; } SDL_SW_CopyYUVToRGB(texture->yuv, &rect, native->format, rect.w, rect.h, native_pixels, native_pitch); SDL_UnlockTexture(native); }