mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-06-02 09:57:40 +00:00
extend the code hidden by SDL_HAVE_YUV
This commit is contained in:
parent
ce1883e1e7
commit
3f8b450de2
11 changed files with 93 additions and 38 deletions
|
@ -71,7 +71,9 @@ typedef struct
|
|||
IDirect3DSurface9 *defaultRenderTarget;
|
||||
IDirect3DSurface9 *currentRenderTarget;
|
||||
void* d3dxDLL;
|
||||
#if SDL_HAVE_YUV
|
||||
LPDIRECT3DPIXELSHADER9 shaders[NUM_SHADERS];
|
||||
#endif
|
||||
LPDIRECT3DVERTEXBUFFER9 vertexBuffers[8];
|
||||
size_t vertexBufferSize[8];
|
||||
int currentVertexBuffer;
|
||||
|
@ -95,6 +97,7 @@ typedef struct
|
|||
D3D_TextureRep texture;
|
||||
D3DTEXTUREFILTERTYPE scaleMode;
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
/* YV12 texture support */
|
||||
SDL_bool yuv;
|
||||
D3D_TextureRep utexture;
|
||||
|
@ -102,6 +105,7 @@ typedef struct
|
|||
Uint8 *pixels;
|
||||
int pitch;
|
||||
SDL_Rect locked_rect;
|
||||
#endif
|
||||
} D3D_TextureData;
|
||||
|
||||
typedef struct
|
||||
|
@ -534,7 +538,7 @@ D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
if (D3D_CreateTextureRep(data->device, &texturedata->texture, usage, texture->format, PixelFormatToD3DFMT(texture->format), texture->w, texture->h) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texture->format == SDL_PIXELFORMAT_YV12 ||
|
||||
texture->format == SDL_PIXELFORMAT_IYUV) {
|
||||
texturedata->yuv = SDL_TRUE;
|
||||
|
@ -547,6 +551,7 @@ D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -563,7 +568,7 @@ D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
if (D3D_RecreateTextureRep(data->device, &texturedata->texture) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata->yuv) {
|
||||
if (D3D_RecreateTextureRep(data->device, &texturedata->utexture) < 0) {
|
||||
return -1;
|
||||
|
@ -573,6 +578,7 @@ D3D_RecreateTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -590,7 +596,7 @@ D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
if (D3D_UpdateTextureRep(data->device, &texturedata->texture, rect->x, rect->y, rect->w, rect->h, pixels, pitch) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata->yuv) {
|
||||
/* Skip to the correct offset into the next texture */
|
||||
pixels = (const void*)((const Uint8*)pixels + rect->h * pitch);
|
||||
|
@ -605,6 +611,7 @@ D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -647,7 +654,7 @@ D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
if (!texturedata) {
|
||||
return SDL_SetError("Texture is not currently available");
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
texturedata->locked_rect = *rect;
|
||||
|
||||
if (texturedata->yuv) {
|
||||
|
@ -664,6 +671,9 @@ D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
|
|||
rect->x * SDL_BYTESPERPIXEL(texture->format));
|
||||
*pitch = texturedata->pitch;
|
||||
} else {
|
||||
#else
|
||||
{
|
||||
#endif
|
||||
RECT d3drect;
|
||||
D3DLOCKED_RECT locked;
|
||||
HRESULT result;
|
||||
|
@ -696,7 +706,7 @@ D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
if (!texturedata) {
|
||||
return;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata->yuv) {
|
||||
const SDL_Rect *rect = &texturedata->locked_rect;
|
||||
void *pixels =
|
||||
|
@ -704,6 +714,9 @@ D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
rect->x * SDL_BYTESPERPIXEL(texture->format));
|
||||
D3D_UpdateTexture(renderer, texture, rect, pixels, texturedata->pitch);
|
||||
} else {
|
||||
#else
|
||||
{
|
||||
#endif
|
||||
IDirect3DTexture9_UnlockRect(texturedata->texture.staging, 0);
|
||||
texturedata->texture.dirty = SDL_TRUE;
|
||||
if (data->drawstate.texture == texture) {
|
||||
|
@ -946,7 +959,7 @@ SetupTextureState(D3D_RenderData *data, SDL_Texture * texture, LPDIRECT3DPIXELSH
|
|||
if (BindTextureRep(data->device, &texturedata->texture, 0) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata->yuv) {
|
||||
switch (SDL_GetYUVConversionModeForResolution(texture->w, texture->h)) {
|
||||
case SDL_YUV_CONVERSION_JPEG:
|
||||
|
@ -972,6 +985,7 @@ SetupTextureState(D3D_RenderData *data, SDL_Texture * texture, LPDIRECT3DPIXELSH
|
|||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -990,10 +1004,12 @@ SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
|
|||
if (texture == NULL) {
|
||||
IDirect3DDevice9_SetTexture(data->device, 0, NULL);
|
||||
}
|
||||
#if SDL_HAVE_YUV
|
||||
if ((!newtexturedata || !newtexturedata->yuv) && (oldtexturedata && oldtexturedata->yuv)) {
|
||||
IDirect3DDevice9_SetTexture(data->device, 1, NULL);
|
||||
IDirect3DDevice9_SetTexture(data->device, 2, NULL);
|
||||
}
|
||||
#endif
|
||||
if (texture && SetupTextureState(data, texture, &shader) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -1010,10 +1026,12 @@ SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
|
|||
} else if (texture) {
|
||||
D3D_TextureData *texturedata = (D3D_TextureData *) texture->driverdata;
|
||||
UpdateDirtyTexture(data->device, &texturedata->texture);
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata->yuv) {
|
||||
UpdateDirtyTexture(data->device, &texturedata->utexture);
|
||||
UpdateDirtyTexture(data->device, &texturedata->vtexture);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (blend != data->drawstate.blend) {
|
||||
|
@ -1353,10 +1371,12 @@ D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
renderdata->drawstate.shader = NULL;
|
||||
IDirect3DDevice9_SetPixelShader(renderdata->device, NULL);
|
||||
IDirect3DDevice9_SetTexture(renderdata->device, 0, NULL);
|
||||
#if SDL_HAVE_YUV
|
||||
if (data->yuv) {
|
||||
IDirect3DDevice9_SetTexture(renderdata->device, 1, NULL);
|
||||
IDirect3DDevice9_SetTexture(renderdata->device, 2, NULL);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!data) {
|
||||
|
@ -1364,9 +1384,11 @@ D3D_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture)
|
|||
}
|
||||
|
||||
D3D_DestroyTextureRep(&data->texture);
|
||||
#if SDL_HAVE_YUV
|
||||
D3D_DestroyTextureRep(&data->utexture);
|
||||
D3D_DestroyTextureRep(&data->vtexture);
|
||||
SDL_free(data->pixels);
|
||||
#endif
|
||||
SDL_free(data);
|
||||
texture->driverdata = NULL;
|
||||
}
|
||||
|
@ -1388,12 +1410,14 @@ D3D_DestroyRenderer(SDL_Renderer * renderer)
|
|||
IDirect3DSurface9_Release(data->currentRenderTarget);
|
||||
data->currentRenderTarget = NULL;
|
||||
}
|
||||
#if SDL_HAVE_YUV
|
||||
for (i = 0; i < SDL_arraysize(data->shaders); ++i) {
|
||||
if (data->shaders[i]) {
|
||||
IDirect3DPixelShader9_Release(data->shaders[i]);
|
||||
data->shaders[i] = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
/* Release all vertex buffers */
|
||||
for (i = 0; i < SDL_arraysize(data->vertexBuffers); ++i) {
|
||||
if (data->vertexBuffers[i]) {
|
||||
|
@ -1666,7 +1690,7 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
|
||||
/* Set up parameters for rendering */
|
||||
D3D_InitRenderState(data);
|
||||
|
||||
#if SDL_HAVE_YUV
|
||||
if (caps.MaxSimultaneousTextures >= 3) {
|
||||
int i;
|
||||
for (i = 0; i < SDL_arraysize(data->shaders); ++i) {
|
||||
|
@ -1680,7 +1704,7 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
|
|||
renderer->info.texture_formats[renderer->info.num_texture_formats++] = SDL_PIXELFORMAT_IYUV;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
data->drawstate.blend = SDL_BLENDMODE_INVALID;
|
||||
|
||||
return renderer;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue