Implemented SDL_UpdateYUVTexture() for Direct3D
authorSam Lantinga <slouken@libsdl.org>
Sat, 28 Sep 2013 14:06:55 -0700
changeset 7761bddbfca922cd
parent 7760 63b519624589
child 7762 51abf7664304
Implemented SDL_UpdateYUVTexture() for Direct3D
src/render/SDL_render.c
src/render/direct3d/SDL_render_d3d.c
     1.1 --- a/src/render/SDL_render.c	Sat Sep 28 14:06:51 2013 -0700
     1.2 +++ b/src/render/SDL_render.c	Sat Sep 28 14:06:55 2013 -0700
     1.3 @@ -901,8 +901,12 @@
     1.4          SDL_assert(!texture->native);
     1.5          renderer = texture->renderer;
     1.6          SDL_assert(renderer->UpdateTextureYUV);
     1.7 -        return renderer->UpdateTextureYUV(renderer, texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
     1.8 -    }
     1.9 +		if (renderer->UpdateTextureYUV) {
    1.10 +			return renderer->UpdateTextureYUV(renderer, texture, rect, Yplane, Ypitch, Uplane, Upitch, Vplane, Vpitch);
    1.11 +		} else {
    1.12 +			return SDL_Unsupported();
    1.13 +		}
    1.14 +	}
    1.15  }
    1.16  
    1.17  static int
     2.1 --- a/src/render/direct3d/SDL_render_d3d.c	Sat Sep 28 14:06:51 2013 -0700
     2.2 +++ b/src/render/direct3d/SDL_render_d3d.c	Sat Sep 28 14:06:55 2013 -0700
     2.3 @@ -211,6 +211,11 @@
     2.4  static int D3D_UpdateTexture(SDL_Renderer * renderer, SDL_Texture * texture,
     2.5                               const SDL_Rect * rect, const void *pixels,
     2.6                               int pitch);
     2.7 +static int D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
     2.8 +                                const SDL_Rect * rect,
     2.9 +                                const Uint8 *Yplane, int Ypitch,
    2.10 +                                const Uint8 *Uplane, int Upitch,
    2.11 +                                const Uint8 *Vplane, int Vpitch);
    2.12  static int D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    2.13                             const SDL_Rect * rect, void **pixels, int *pitch);
    2.14  static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
    2.15 @@ -599,6 +604,7 @@
    2.16      renderer->WindowEvent = D3D_WindowEvent;
    2.17      renderer->CreateTexture = D3D_CreateTexture;
    2.18      renderer->UpdateTexture = D3D_UpdateTexture;
    2.19 +	renderer->UpdateTextureYUV = D3D_UpdateTextureYUV;
    2.20      renderer->LockTexture = D3D_LockTexture;
    2.21      renderer->UnlockTexture = D3D_UnlockTexture;
    2.22      renderer->SetRenderTarget = D3D_SetRenderTarget;
    2.23 @@ -1017,6 +1023,36 @@
    2.24  }
    2.25  
    2.26  static int
    2.27 +D3D_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture,
    2.28 +                     const SDL_Rect * rect,
    2.29 +                     const Uint8 *Yplane, int Ypitch,
    2.30 +                     const Uint8 *Uplane, int Upitch,
    2.31 +                     const Uint8 *Vplane, int Vpitch)
    2.32 +{
    2.33 +	D3D_TextureData *data = (D3D_TextureData *) texture->driverdata;
    2.34 +	SDL_bool full_texture = SDL_FALSE;
    2.35 +
    2.36 +#ifdef USE_DYNAMIC_TEXTURE
    2.37 +	if (texture->access == SDL_TEXTUREACCESS_STREAMING &&
    2.38 +		rect->x == 0 && rect->y == 0 &&
    2.39 +		rect->w == texture->w && rect->h == texture->h) {
    2.40 +			full_texture = SDL_TRUE;
    2.41 +	}
    2.42 +#endif
    2.43 +
    2.44 +	if (D3D_UpdateTextureInternal(data->texture, texture->format, full_texture, rect->x, rect->y, rect->w, rect->h, Yplane, Ypitch) < 0) {
    2.45 +		return -1;
    2.46 +	}
    2.47 +	if (D3D_UpdateTextureInternal(data->utexture, texture->format, full_texture, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Uplane, Upitch) < 0) {
    2.48 +		return -1;
    2.49 +	}
    2.50 +	if (D3D_UpdateTextureInternal(data->vtexture, texture->format, full_texture, rect->x / 2, rect->y / 2, rect->w / 2, rect->h / 2, Vplane, Vpitch) < 0) {
    2.51 +		return -1;
    2.52 +	}
    2.53 +	return 0;
    2.54 +}
    2.55 +
    2.56 +static int
    2.57  D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
    2.58                  const SDL_Rect * rect, void **pixels, int *pitch)
    2.59  {