static int SW_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, const void *pixels, int pitch) { if (SDL_ISPIXELFORMAT_FOURCC(texture->format)) { return SDL_SW_UpdateYUVTexture((SDL_SW_YUVTexture *) texture->driverdata, rect, pixels, pitch); } else { SDL_Surface *surface = (SDL_Surface *) texture->driverdata; Uint8 *src, *dst; int row; size_t length; src = (Uint8 *) pixels; dst = (Uint8 *) surface->pixels + rect->y * surface->pitch + rect->x * surface->format->BytesPerPixel; length = rect->w * surface->format->BytesPerPixel; for (row = 0; row < rect->h; ++row) { SDL_memcpy(dst, src, length); src += pitch; dst += surface->pitch; } return 0; } }
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 X11_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, const void *pixels, int pitch) { X11_TextureData *data = (X11_TextureData *) texture->driverdata; if (data->yuv) { if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) { return -1; } UpdateYUVTextureData(texture); return 0; } else { X11_RenderData *renderdata = (X11_RenderData *) renderer->driverdata; if (data->pixels) { Uint8 *src, *dst; int row; size_t length; src = (Uint8 *) pixels; dst = (Uint8 *) data->pixels + rect->y * data->pitch + rect->x * SDL_BYTESPERPIXEL(texture->format); length = rect->w * SDL_BYTESPERPIXEL(texture->format); for (row = 0; row < rect->h; ++row) { SDL_memcpy(dst, src, length); src += pitch; dst += data->pitch; } } else { data->image->width = rect->w; data->image->height = rect->h; data->image->data = (char *) pixels; data->image->bytes_per_line = pitch; XPutImage(renderdata->display, data->pixmap, renderdata->gc, data->image, 0, 0, rect->x, rect->y, rect->w, rect->h); } return 0; } }
static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, const void *pixels, int pitch) { D3D_TextureData *data = (D3D_TextureData *) texture->driverdata; D3D_RenderData *renderdata = (D3D_RenderData *) renderer->driverdata; if (data->yuv) { if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) { return -1; } UpdateYUVTextureData(texture); return 0; } else { #ifdef SDL_MEMORY_POOL_DEFAULT IDirect3DTexture9 *temp; RECT d3drect; D3DLOCKED_RECT locked; const Uint8 *src; Uint8 *dst; int row, length; HRESULT result; result = IDirect3DDevice9_CreateTexture(renderdata->device, texture->w, texture->h, 1, 0, PixelFormatToD3DFMT(texture-> format), D3DPOOL_SYSTEMMEM, &temp, NULL); if (FAILED(result)) { D3D_SetError("CreateTexture()", result); return -1; } d3drect.left = rect->x; d3drect.right = rect->x + rect->w; d3drect.top = rect->y; d3drect.bottom = rect->y + rect->h; result = IDirect3DTexture9_LockRect(temp, 0, &locked, &d3drect, 0); if (FAILED(result)) { IDirect3DTexture9_Release(temp); D3D_SetError("LockRect()", result); return -1; } src = pixels; dst = locked.pBits; length = rect->w * SDL_BYTESPERPIXEL(texture->format); for (row = 0; row < rect->h; ++row) { SDL_memcpy(dst, src, length); src += pitch; dst += locked.Pitch; } IDirect3DTexture9_UnlockRect(temp, 0); result = IDirect3DDevice9_UpdateTexture(renderdata->device, (IDirect3DBaseTexture9 *) temp, (IDirect3DBaseTexture9 *) data->texture); IDirect3DTexture9_Release(temp); if (FAILED(result)) { D3D_SetError("UpdateTexture()", result); return -1; } #else RECT d3drect; D3DLOCKED_RECT locked; const Uint8 *src; Uint8 *dst; int row, length; HRESULT result; d3drect.left = rect->x; d3drect.right = rect->x + rect->w; d3drect.top = rect->y; d3drect.bottom = rect->y + rect->h; result = IDirect3DTexture9_LockRect(data->texture, 0, &locked, &d3drect, 0); if (FAILED(result)) { D3D_SetError("LockRect()", result); return -1; } src = pixels; dst = locked.pBits; length = rect->w * SDL_BYTESPERPIXEL(texture->format); for (row = 0; row < rect->h; ++row) { SDL_memcpy(dst, src, length); src += pitch; dst += locked.Pitch; } IDirect3DTexture9_UnlockRect(data->texture, 0); #endif // SDL_MEMORY_POOL_DEFAULT return 0; } }
static int GDI_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, const void *pixels, int pitch) { GDI_TextureData *data = (GDI_TextureData *) texture->driverdata; if (data->yuv) { if (SDL_SW_UpdateYUVTexture(data->yuv, rect, pixels, pitch) < 0) { return -1; } UpdateYUVTextureData(texture); return 0; } else { GDI_RenderData *renderdata = (GDI_RenderData *) renderer->driverdata; if (data->pixels) { Uint8 *src, *dst; int row; size_t length; src = (Uint8 *) pixels; dst = (Uint8 *) data->pixels + rect->y * data->pitch + rect->x * SDL_BYTESPERPIXEL(texture->format); length = rect->w * SDL_BYTESPERPIXEL(texture->format); for (row = 0; row < rect->h; ++row) { SDL_memcpy(dst, src, length); src += pitch; dst += data->pitch; } if (data->premultiplied) { Uint32 *pixels = (Uint32 *) data->pixels + rect->y * (data->pitch / 4) + rect->x; switch (texture->format) { case SDL_PIXELFORMAT_ARGB8888: SDL_PreMultiplyAlphaARGB8888(rect->w, rect->h, pixels, data->pitch); break; case SDL_PIXELFORMAT_RGBA8888: SDL_PreMultiplyAlphaRGBA8888(rect->w, rect->h, pixels, data->pitch); break; case SDL_PIXELFORMAT_ABGR8888: SDL_PreMultiplyAlphaABGR8888(rect->w, rect->h, pixels, data->pitch); break; case SDL_PIXELFORMAT_BGRA8888: SDL_PreMultiplyAlphaBGRA8888(rect->w, rect->h, pixels, data->pitch); break; } } } else if (rect->w == texture->w && pitch == data->pitch) { #ifndef NO_GETDIBBITS if (!SetDIBits (renderdata->window_hdc, data->hbm, rect->y, rect->h, pixels, renderdata->bmi, DIB_RGB_COLORS)) { WIN_SetError("SetDIBits()"); return -1; } #else SDL_SetError("FIXME: Update Texture"); return -1; #endif } else { SDL_SetError ("FIXME: Need to allocate temporary memory and do GetDIBits() followed by SetDIBits(), since we can only set blocks of scanlines at a time"); return -1; } return 0; } }