mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-04-30 11:14:21 +00:00
Clang-Tidy fixes (#6725)
This commit is contained in:
@@ -1331,7 +1331,7 @@ SDL_CreateTexture(SDL_Renderer *renderer, Uint32 format, int access, int w, int
|
||||
} else if (access == SDL_TEXTUREACCESS_STREAMING) {
|
||||
/* The pitch is 4 byte aligned */
|
||||
texture->pitch = (((w * SDL_BYTESPERPIXEL(format)) + 3) & ~3);
|
||||
texture->pixels = SDL_calloc(1, texture->pitch * h);
|
||||
texture->pixels = SDL_calloc(1, (size_t)texture->pitch * h);
|
||||
if (!texture->pixels) {
|
||||
SDL_DestroyTexture(texture);
|
||||
return NULL;
|
||||
@@ -1666,7 +1666,7 @@ static int SDL_UpdateTextureYUV(SDL_Texture *texture, const SDL_Rect *rect,
|
||||
} else {
|
||||
/* Use a temporary buffer for updating */
|
||||
const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
|
||||
const size_t alloclen = rect->h * temp_pitch;
|
||||
const size_t alloclen = (size_t)rect->h * temp_pitch;
|
||||
if (alloclen > 0) {
|
||||
void *temp_pixels = SDL_malloc(alloclen);
|
||||
if (temp_pixels == NULL) {
|
||||
@@ -1706,7 +1706,7 @@ static int SDL_UpdateTextureNative(SDL_Texture *texture, const SDL_Rect *rect,
|
||||
} else {
|
||||
/* Use a temporary buffer for updating */
|
||||
const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
|
||||
const size_t alloclen = rect->h * temp_pitch;
|
||||
const size_t alloclen = (size_t)rect->h * temp_pitch;
|
||||
if (alloclen > 0) {
|
||||
void *temp_pixels = SDL_malloc(alloclen);
|
||||
if (temp_pixels == NULL) {
|
||||
@@ -1800,7 +1800,7 @@ static int SDL_UpdateTextureYUVPlanar(SDL_Texture *texture, const SDL_Rect *rect
|
||||
} else {
|
||||
/* Use a temporary buffer for updating */
|
||||
const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
|
||||
const size_t alloclen = rect->h * temp_pitch;
|
||||
const size_t alloclen = (size_t)rect->h * temp_pitch;
|
||||
if (alloclen > 0) {
|
||||
void *temp_pixels = SDL_malloc(alloclen);
|
||||
if (temp_pixels == NULL) {
|
||||
@@ -1850,7 +1850,7 @@ static int SDL_UpdateTextureNVPlanar(SDL_Texture *texture, const SDL_Rect *rect,
|
||||
} else {
|
||||
/* Use a temporary buffer for updating */
|
||||
const int temp_pitch = (((rect->w * SDL_BYTESPERPIXEL(native->format)) + 3) & ~3);
|
||||
const size_t alloclen = rect->h * temp_pitch;
|
||||
const size_t alloclen = (size_t)rect->h * temp_pitch;
|
||||
if (alloclen > 0) {
|
||||
void *temp_pixels = SDL_malloc(alloclen);
|
||||
if (temp_pixels == NULL) {
|
||||
@@ -2292,9 +2292,9 @@ static int UpdateLogicalSize(SDL_Renderer *renderer, SDL_bool flush_viewport_cmd
|
||||
|
||||
if (renderer->integer_scale) {
|
||||
if (want_aspect > real_aspect) {
|
||||
scale = (float)(w / renderer->logical_w);
|
||||
scale = (float)(w) / renderer->logical_w;
|
||||
} else {
|
||||
scale = (float)(h / renderer->logical_h);
|
||||
scale = (float)(h) / renderer->logical_h;
|
||||
}
|
||||
|
||||
if (scale < 1.0f) {
|
||||
@@ -2431,10 +2431,12 @@ int SDL_RenderSetViewport(SDL_Renderer *renderer, const SDL_Rect *rect)
|
||||
if (SDL_GetRendererOutputSize(renderer, &w, &h) < 0) {
|
||||
return -1;
|
||||
}
|
||||
renderer->viewport.x = (double)0;
|
||||
renderer->viewport.y = (double)0;
|
||||
renderer->viewport.x = 0.0;
|
||||
renderer->viewport.y = 0.0;
|
||||
/* NOLINTBEGIN(clang-analyzer-core.uninitialized.Assign): SDL_GetRendererOutputSize cannot fail */
|
||||
renderer->viewport.w = (double)w;
|
||||
renderer->viewport.h = (double)h;
|
||||
/* NOLINTEND(clang-analyzer-core.uninitialized.Assign) */
|
||||
}
|
||||
retval = QueueCmdSetViewport(renderer);
|
||||
return retval < 0 ? retval : FlushRenderCommandsIfNotBatching(renderer);
|
||||
|
||||
@@ -141,7 +141,7 @@ int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
|
||||
if (rect->x == 0 && rect->y == 0 &&
|
||||
rect->w == swdata->w && rect->h == swdata->h) {
|
||||
SDL_memcpy(swdata->pixels, pixels,
|
||||
(swdata->h * swdata->w) + 2 * ((swdata->h + 1) / 2) * ((swdata->w + 1) / 2));
|
||||
(size_t)(swdata->h * swdata->w) + 2 * ((swdata->h + 1) / 2) * ((swdata->w + 1) / 2));
|
||||
} else {
|
||||
Uint8 *src, *dst;
|
||||
int row;
|
||||
@@ -193,7 +193,7 @@ int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
|
||||
dst =
|
||||
swdata->planes[0] + rect->y * swdata->pitches[0] +
|
||||
rect->x * 2;
|
||||
length = 4 * ((rect->w + 1) / 2);
|
||||
length = 4 * (((size_t)rect->w + 1) / 2);
|
||||
for (row = 0; row < rect->h; ++row) {
|
||||
SDL_memcpy(dst, src, length);
|
||||
src += pitch;
|
||||
@@ -205,7 +205,7 @@ int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
|
||||
{
|
||||
if (rect->x == 0 && rect->y == 0 && rect->w == swdata->w && rect->h == swdata->h) {
|
||||
SDL_memcpy(swdata->pixels, pixels,
|
||||
(swdata->h * swdata->w) + 2 * ((swdata->h + 1) / 2) * ((swdata->w + 1) / 2));
|
||||
(size_t)(swdata->h * swdata->w) + 2 * ((swdata->h + 1) / 2) * ((swdata->w + 1) / 2));
|
||||
} else {
|
||||
|
||||
Uint8 *src, *dst;
|
||||
@@ -226,7 +226,7 @@ int SDL_SW_UpdateYUVTexture(SDL_SW_YUVTexture *swdata, const SDL_Rect *rect,
|
||||
src = (Uint8 *)pixels + rect->h * pitch;
|
||||
dst = swdata->pixels + swdata->h * swdata->w;
|
||||
dst += 2 * ((rect->y + 1) / 2) * ((swdata->w + 1) / 2) + 2 * (rect->x / 2);
|
||||
length = 2 * ((rect->w + 1) / 2);
|
||||
length = 2 * (((size_t)rect->w + 1) / 2);
|
||||
for (row = 0; row < (rect->h + 1) / 2; ++row) {
|
||||
SDL_memcpy(dst, src, length);
|
||||
src += 2 * ((pitch + 1) / 2);
|
||||
|
||||
@@ -477,9 +477,9 @@ static int D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *textur
|
||||
}
|
||||
|
||||
d3drect.left = x;
|
||||
d3drect.right = x + w;
|
||||
d3drect.right = (LONG)x + w;
|
||||
d3drect.top = y;
|
||||
d3drect.bottom = y + h;
|
||||
d3drect.bottom = (LONG)y + h;
|
||||
|
||||
result = IDirect3DTexture9_LockRect(texture->staging, 0, &locked, &d3drect, 0);
|
||||
if (FAILED(result)) {
|
||||
@@ -490,7 +490,7 @@ static int D3D_UpdateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *textur
|
||||
dst = (Uint8 *)locked.pBits;
|
||||
length = w * SDL_BYTESPERPIXEL(texture->format);
|
||||
if (length == pitch && length == locked.Pitch) {
|
||||
SDL_memcpy(dst, src, length * h);
|
||||
SDL_memcpy(dst, src, (size_t)length * h);
|
||||
} else {
|
||||
if (length > pitch) {
|
||||
length = pitch;
|
||||
@@ -673,7 +673,7 @@ static int D3D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
||||
}
|
||||
}
|
||||
*pixels =
|
||||
(void *)((Uint8 *)texturedata->pixels + rect->y * texturedata->pitch +
|
||||
(void *)(texturedata->pixels + rect->y * texturedata->pitch +
|
||||
rect->x * SDL_BYTESPERPIXEL(texture->format));
|
||||
*pitch = texturedata->pitch;
|
||||
} else
|
||||
@@ -688,9 +688,9 @@ static int D3D_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
||||
}
|
||||
|
||||
d3drect.left = rect->x;
|
||||
d3drect.right = rect->x + rect->w;
|
||||
d3drect.right = (LONG)rect->x + rect->w;
|
||||
d3drect.top = rect->y;
|
||||
d3drect.bottom = rect->y + rect->h;
|
||||
d3drect.bottom = (LONG)rect->y + rect->h;
|
||||
|
||||
result = IDirect3DTexture9_LockRect(texturedata->texture.staging, 0, &locked, &d3drect, 0);
|
||||
if (FAILED(result)) {
|
||||
@@ -714,7 +714,7 @@ static void D3D_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
if (texturedata->yuv) {
|
||||
const SDL_Rect *rect = &texturedata->locked_rect;
|
||||
void *pixels =
|
||||
(void *)((Uint8 *)texturedata->pixels + rect->y * texturedata->pitch +
|
||||
(void *)(texturedata->pixels + rect->y * texturedata->pitch +
|
||||
rect->x * SDL_BYTESPERPIXEL(texture->format));
|
||||
D3D_UpdateTexture(renderer, texture, rect, pixels, texturedata->pitch);
|
||||
} else
|
||||
@@ -1083,10 +1083,10 @@ static int SetDrawState(D3D_RenderData *data, const SDL_RenderCommand *cmd)
|
||||
const SDL_Rect *viewport = &data->drawstate.viewport;
|
||||
const SDL_Rect *rect = &data->drawstate.cliprect;
|
||||
RECT d3drect;
|
||||
d3drect.left = viewport->x + rect->x;
|
||||
d3drect.top = viewport->y + rect->y;
|
||||
d3drect.right = viewport->x + rect->x + rect->w;
|
||||
d3drect.bottom = viewport->y + rect->y + rect->h;
|
||||
d3drect.left = (LONG)viewport->x + rect->x;
|
||||
d3drect.top = (LONG)viewport->y + rect->y;
|
||||
d3drect.right = (LONG)viewport->x + rect->x + rect->w;
|
||||
d3drect.bottom = (LONG)viewport->y + rect->y + rect->h;
|
||||
IDirect3DDevice9_SetScissorRect(data->device, &d3drect);
|
||||
data->drawstate.cliprect_dirty = SDL_FALSE;
|
||||
}
|
||||
@@ -1236,7 +1236,8 @@ static int D3D_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd, v
|
||||
const Vertex *verts = (Vertex *)(((Uint8 *)vertices) + first);
|
||||
|
||||
/* DirectX 9 has the same line rasterization semantics as GDI,
|
||||
so we need to close the endpoint of the line with a second draw call. */
|
||||
so we need to close the endpoint of the line with a second draw call.
|
||||
NOLINTNEXTLINE(clang-analyzer-core.NullDereference): FIXME: Can verts truly not be NULL ? */
|
||||
const SDL_bool close_endpoint = ((count == 2) || (verts[0].x != verts[count - 1].x) || (verts[0].y != verts[count - 1].y));
|
||||
|
||||
SetDrawState(data, cmd);
|
||||
@@ -1323,9 +1324,9 @@ static int D3D_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
||||
}
|
||||
|
||||
d3drect.left = rect->x;
|
||||
d3drect.right = rect->x + rect->w;
|
||||
d3drect.right = (LONG)rect->x + rect->w;
|
||||
d3drect.top = rect->y;
|
||||
d3drect.bottom = rect->y + rect->h;
|
||||
d3drect.bottom = (LONG)rect->y + rect->h;
|
||||
|
||||
result = IDirect3DSurface9_LockRect(surface, &locked, &d3drect, D3DLOCK_READONLY);
|
||||
if (FAILED(result)) {
|
||||
|
||||
@@ -699,9 +699,9 @@ static int D3D11_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rec
|
||||
switch (rotation) {
|
||||
case DXGI_MODE_ROTATION_IDENTITY:
|
||||
outRect->left = sdlRect->x;
|
||||
outRect->right = sdlRect->x + sdlRect->w;
|
||||
outRect->right = (LONG)sdlRect->x + sdlRect->w;
|
||||
outRect->top = sdlRect->y;
|
||||
outRect->bottom = sdlRect->y + sdlRect->h;
|
||||
outRect->bottom = (LONG)sdlRect->y + sdlRect->h;
|
||||
if (includeViewportOffset) {
|
||||
outRect->left += viewport->x;
|
||||
outRect->right += viewport->x;
|
||||
@@ -711,7 +711,7 @@ static int D3D11_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rec
|
||||
break;
|
||||
case DXGI_MODE_ROTATION_ROTATE270:
|
||||
outRect->left = sdlRect->y;
|
||||
outRect->right = sdlRect->y + sdlRect->h;
|
||||
outRect->right = (LONG)sdlRect->y + sdlRect->h;
|
||||
outRect->top = viewport->w - sdlRect->x - sdlRect->w;
|
||||
outRect->bottom = viewport->w - sdlRect->x;
|
||||
break;
|
||||
@@ -725,7 +725,7 @@ static int D3D11_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rec
|
||||
outRect->left = viewport->h - sdlRect->y - sdlRect->h;
|
||||
outRect->right = viewport->h - sdlRect->y;
|
||||
outRect->top = sdlRect->x;
|
||||
outRect->bottom = sdlRect->x + sdlRect->h;
|
||||
outRect->bottom = (LONG)sdlRect->x + sdlRect->h;
|
||||
break;
|
||||
default:
|
||||
return SDL_SetError("The physical display is in an unknown or unsupported rotation");
|
||||
@@ -932,7 +932,7 @@ static HRESULT D3D11_CreateWindowSizeDependentResources(SDL_Renderer *renderer)
|
||||
#endif
|
||||
} else {
|
||||
result = D3D11_CreateSwapChain(renderer, w, h);
|
||||
if (FAILED(result)) {
|
||||
if (FAILED(result) || data->swapChain == NULL) {
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
@@ -1299,7 +1299,7 @@ static int D3D11_UpdateTextureInternal(D3D11_RenderData *rendererData, ID3D11Tex
|
||||
dst = textureMemory.pData;
|
||||
length = w * bpp;
|
||||
if (length == pitch && length == textureMemory.RowPitch) {
|
||||
SDL_memcpy(dst, src, length * h);
|
||||
SDL_memcpy(dst, src, (size_t)length * h);
|
||||
} else {
|
||||
if (length > (UINT)pitch) {
|
||||
length = pitch;
|
||||
@@ -1450,7 +1450,7 @@ static int D3D11_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
||||
}
|
||||
textureData->locked_rect = *rect;
|
||||
*pixels =
|
||||
(void *)((Uint8 *)textureData->pixels + rect->y * textureData->pitch +
|
||||
(void *)(textureData->pixels + rect->y * textureData->pitch +
|
||||
rect->x * SDL_BYTESPERPIXEL(texture->format));
|
||||
*pitch = textureData->pitch;
|
||||
return 0;
|
||||
@@ -1521,7 +1521,7 @@ static void D3D11_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
if (textureData->yuv || textureData->nv12) {
|
||||
const SDL_Rect *rect = &textureData->locked_rect;
|
||||
void *pixels =
|
||||
(void *)((Uint8 *)textureData->pixels + rect->y * textureData->pitch +
|
||||
(void *)(textureData->pixels + rect->y * textureData->pitch +
|
||||
rect->x * SDL_BYTESPERPIXEL(texture->format));
|
||||
D3D11_UpdateTexture(renderer, texture, rect, pixels, textureData->pitch);
|
||||
return;
|
||||
|
||||
@@ -1101,9 +1101,9 @@ static int D3D12_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rec
|
||||
switch (rotation) {
|
||||
case DXGI_MODE_ROTATION_IDENTITY:
|
||||
outRect->left = sdlRect->x;
|
||||
outRect->right = sdlRect->x + sdlRect->w;
|
||||
outRect->right = (LONG)sdlRect->x + sdlRect->w;
|
||||
outRect->top = sdlRect->y;
|
||||
outRect->bottom = sdlRect->y + sdlRect->h;
|
||||
outRect->bottom = (LONG)sdlRect->y + sdlRect->h;
|
||||
if (includeViewportOffset) {
|
||||
outRect->left += viewport->x;
|
||||
outRect->right += viewport->x;
|
||||
@@ -1113,7 +1113,7 @@ static int D3D12_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rec
|
||||
break;
|
||||
case DXGI_MODE_ROTATION_ROTATE270:
|
||||
outRect->left = sdlRect->y;
|
||||
outRect->right = sdlRect->y + sdlRect->h;
|
||||
outRect->right = (LONG)sdlRect->y + sdlRect->h;
|
||||
outRect->top = viewport->w - sdlRect->x - sdlRect->w;
|
||||
outRect->bottom = viewport->w - sdlRect->x;
|
||||
break;
|
||||
@@ -1127,7 +1127,7 @@ static int D3D12_GetViewportAlignedD3DRect(SDL_Renderer *renderer, const SDL_Rec
|
||||
outRect->left = viewport->h - sdlRect->y - sdlRect->h;
|
||||
outRect->right = viewport->h - sdlRect->y;
|
||||
outRect->top = sdlRect->x;
|
||||
outRect->bottom = sdlRect->x + sdlRect->h;
|
||||
outRect->bottom = (LONG)sdlRect->x + sdlRect->h;
|
||||
break;
|
||||
default:
|
||||
return SDL_SetError("The physical display is in an unknown or unsupported rotation");
|
||||
@@ -1299,7 +1299,7 @@ static HRESULT D3D12_CreateWindowSizeDependentResources(SDL_Renderer *renderer)
|
||||
/* Set the proper rotation for the swap chain. */
|
||||
if (WIN_IsWindows8OrGreater()) {
|
||||
if (data->swapEffect == DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL) {
|
||||
result = D3D_CALL(data->swapChain, SetRotation, data->rotation);
|
||||
result = D3D_CALL(data->swapChain, SetRotation, data->rotation); /* NOLINT(clang-analyzer-core.NullDereference) */
|
||||
if (FAILED(result)) {
|
||||
WIN_SetErrorFromHRESULT(SDL_COMPOSE_ERROR("IDXGISwapChain4::SetRotation"), result);
|
||||
goto done;
|
||||
@@ -1317,7 +1317,7 @@ static HRESULT D3D12_CreateWindowSizeDependentResources(SDL_Renderer *renderer)
|
||||
goto done;
|
||||
}
|
||||
#else
|
||||
result = D3D_CALL(data->swapChain, GetBuffer,
|
||||
result = D3D_CALL(data->swapChain, GetBuffer, /* NOLINT(clang-analyzer-core.NullDereference) */
|
||||
i,
|
||||
D3D_GUID(SDL_IID_ID3D12Resource),
|
||||
(void **)&data->renderTargets[i]);
|
||||
@@ -1730,7 +1730,7 @@ static int D3D12_UpdateTextureInternal(D3D12_RenderData *rendererData, ID3D12Res
|
||||
dst = textureMemory;
|
||||
length = w * bpp;
|
||||
if (length == pitch && length == pitchedDesc.RowPitch) {
|
||||
SDL_memcpy(dst, src, length * h);
|
||||
SDL_memcpy(dst, src, (size_t)length * h);
|
||||
} else {
|
||||
if (length > (UINT)pitch) {
|
||||
length = pitch;
|
||||
@@ -1903,7 +1903,7 @@ static int D3D12_LockTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
||||
}
|
||||
textureData->lockedRect = *rect;
|
||||
*pixels =
|
||||
(void *)((Uint8 *)textureData->pixels + rect->y * textureData->pitch +
|
||||
(void *)(textureData->pixels + rect->y * textureData->pitch +
|
||||
rect->x * SDL_BYTESPERPIXEL(texture->format));
|
||||
*pitch = textureData->pitch;
|
||||
return 0;
|
||||
@@ -2014,7 +2014,7 @@ static void D3D12_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
if (textureData->yuv || textureData->nv12) {
|
||||
const SDL_Rect *rect = &textureData->lockedRect;
|
||||
void *pixels =
|
||||
(void *)((Uint8 *)textureData->pixels + rect->y * textureData->pitch +
|
||||
(void *)(textureData->pixels + rect->y * textureData->pitch +
|
||||
rect->x * SDL_BYTESPERPIXEL(texture->format));
|
||||
D3D12_UpdateTexture(renderer, texture, rect, pixels, textureData->pitch);
|
||||
return;
|
||||
|
||||
@@ -146,7 +146,7 @@ typedef struct METAL_ShaderPipelines
|
||||
|
||||
@interface METAL_TextureData : NSObject
|
||||
@property(nonatomic, retain) id<MTLTexture> mtltexture;
|
||||
@property(nonatomic, retain) id<MTLTexture> mtltexture_uv;
|
||||
@property(nonatomic, retain) id<MTLTexture> mtltextureUv;
|
||||
@property(nonatomic, retain) id<MTLSamplerState> mtlsampler;
|
||||
@property(nonatomic, assign) SDL_MetalFragmentFunction fragmentFunction;
|
||||
#if SDL_HAVE_YUV
|
||||
@@ -551,13 +551,14 @@ static SDL_bool METAL_SupportsBlendMode(SDL_Renderer *renderer, SDL_BlendMode bl
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
static int
|
||||
METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
{
|
||||
@autoreleasepool {
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->driverdata;
|
||||
MTLPixelFormat pixfmt;
|
||||
MTLTextureDescriptor *mtltexdesc;
|
||||
id<MTLTexture> mtltexture, mtltexture_uv;
|
||||
id<MTLTexture> mtltexture, mtltextureUv;
|
||||
BOOL yuv, nv12;
|
||||
METAL_TextureData *texturedata;
|
||||
|
||||
@@ -597,7 +598,7 @@ static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
return SDL_SetError("Texture allocation failed");
|
||||
}
|
||||
|
||||
mtltexture_uv = nil;
|
||||
mtltextureUv = nil;
|
||||
#if SDL_HAVE_YUV
|
||||
yuv = (texture->format == SDL_PIXELFORMAT_IYUV) || (texture->format == SDL_PIXELFORMAT_YV12);
|
||||
nv12 = (texture->format == SDL_PIXELFORMAT_NV12) || (texture->format == SDL_PIXELFORMAT_NV21);
|
||||
@@ -615,8 +616,8 @@ static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
}
|
||||
|
||||
if (yuv || nv12) {
|
||||
mtltexture_uv = [data.mtldevice newTextureWithDescriptor:mtltexdesc];
|
||||
if (mtltexture_uv == nil) {
|
||||
mtltextureUv = [data.mtldevice newTextureWithDescriptor:mtltexdesc];
|
||||
if (mtltextureUv == nil) {
|
||||
return SDL_SetError("Texture allocation failed");
|
||||
}
|
||||
}
|
||||
@@ -628,7 +629,7 @@ static int METAL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
texturedata.mtlsampler = data.mtlsamplerlinear;
|
||||
}
|
||||
texturedata.mtltexture = mtltexture;
|
||||
texturedata.mtltexture_uv = mtltexture_uv;
|
||||
texturedata.mtltextureUv = mtltextureUv;
|
||||
#if SDL_HAVE_YUV
|
||||
texturedata.yuv = yuv;
|
||||
texturedata.nv12 = nv12;
|
||||
@@ -777,13 +778,13 @@ static int METAL_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
||||
|
||||
/* Skip to the correct offset into the next texture */
|
||||
pixels = (const void *)((const Uint8 *)pixels + rect->h * pitch);
|
||||
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture_uv, UVrect, Uslice, pixels, UVpitch) < 0) {
|
||||
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, Uslice, pixels, UVpitch) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Skip to the correct offset into the next texture */
|
||||
pixels = (const void *)((const Uint8 *)pixels + UVrect.h * UVpitch);
|
||||
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture_uv, UVrect, Vslice, pixels, UVpitch) < 0) {
|
||||
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, Vslice, pixels, UVpitch) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -794,7 +795,7 @@ static int METAL_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
||||
|
||||
/* Skip to the correct offset into the next texture */
|
||||
pixels = (const void *)((const Uint8 *)pixels + rect->h * pitch);
|
||||
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture_uv, UVrect, 0, pixels, UVpitch) < 0) {
|
||||
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, 0, pixels, UVpitch) < 0) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -826,10 +827,10 @@ static int METAL_UpdateTextureYUV(SDL_Renderer *renderer, SDL_Texture *texture,
|
||||
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture, *rect, 0, Yplane, Ypitch) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture_uv, UVrect, Uslice, Uplane, Upitch)) {
|
||||
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, Uslice, Uplane, Upitch)) {
|
||||
return -1;
|
||||
}
|
||||
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture_uv, UVrect, Vslice, Vplane, Vpitch)) {
|
||||
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, Vslice, Vplane, Vpitch)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -857,7 +858,7 @@ static int METAL_UpdateTextureNV(SDL_Renderer *renderer, SDL_Texture *texture,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltexture_uv, UVrect, 0, UVplane, UVpitch) < 0) {
|
||||
if (METAL_UpdateTextureInternal(renderer, texturedata, texturedata.mtltextureUv, UVrect, 0, UVplane, UVpitch) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -949,7 +950,7 @@ static void METAL_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
sourceBytesPerRow:UVpitch
|
||||
sourceBytesPerImage:UVpitch * UVrect.h
|
||||
sourceSize:MTLSizeMake(UVrect.w, UVrect.h, 1)
|
||||
toTexture:texturedata.mtltexture_uv
|
||||
toTexture:texturedata.mtltextureUv
|
||||
destinationSlice:Uslice
|
||||
destinationLevel:0
|
||||
destinationOrigin:MTLOriginMake(UVrect.x, UVrect.y, 0)];
|
||||
@@ -959,7 +960,7 @@ static void METAL_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
sourceBytesPerRow:UVpitch
|
||||
sourceBytesPerImage:UVpitch * UVrect.h
|
||||
sourceSize:MTLSizeMake(UVrect.w, UVrect.h, 1)
|
||||
toTexture:texturedata.mtltexture_uv
|
||||
toTexture:texturedata.mtltextureUv
|
||||
destinationSlice:Vslice
|
||||
destinationLevel:0
|
||||
destinationOrigin:MTLOriginMake(UVrect.x, UVrect.y, 0)];
|
||||
@@ -973,7 +974,7 @@ static void METAL_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
sourceBytesPerRow:UVpitch
|
||||
sourceBytesPerImage:0
|
||||
sourceSize:MTLSizeMake(UVrect.w, UVrect.h, 1)
|
||||
toTexture:texturedata.mtltexture_uv
|
||||
toTexture:texturedata.mtltextureUv
|
||||
destinationSlice:0
|
||||
destinationLevel:0
|
||||
destinationOrigin:MTLOriginMake(UVrect.x, UVrect.y, 0)];
|
||||
@@ -1308,7 +1309,7 @@ static SDL_bool SetCopyState(SDL_Renderer *renderer, const SDL_RenderCommand *cm
|
||||
[data.mtlcmdencoder setFragmentTexture:texturedata.mtltexture atIndex:0];
|
||||
#if SDL_HAVE_YUV
|
||||
if (texturedata.yuv || texturedata.nv12) {
|
||||
[data.mtlcmdencoder setFragmentTexture:texturedata.mtltexture_uv atIndex:1];
|
||||
[data.mtlcmdencoder setFragmentTexture:texturedata.mtltextureUv atIndex:1];
|
||||
[data.mtlcmdencoder setFragmentBuffer:data.mtlbufconstants offset:texturedata.conversionBufferOffset atIndex:1];
|
||||
}
|
||||
#endif
|
||||
@@ -1466,14 +1467,16 @@ static int METAL_RunCommandQueue(SDL_Renderer *renderer, SDL_RenderCommand *cmd,
|
||||
}
|
||||
}
|
||||
|
||||
static int METAL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
||||
Uint32 pixel_format, void *pixels, int pitch)
|
||||
static int
|
||||
METAL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
||||
Uint32 pixel_format, void *pixels, int pitch)
|
||||
{
|
||||
@autoreleasepool {
|
||||
METAL_RenderData *data = (__bridge METAL_RenderData *)renderer->driverdata;
|
||||
id<MTLTexture> mtltexture;
|
||||
MTLRegion mtlregion;
|
||||
int temp_pitch, status;
|
||||
size_t temp_pitch;
|
||||
int status;
|
||||
Uint32 temp_format;
|
||||
void *temp_pixels;
|
||||
if (!METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad, NULL, nil)) {
|
||||
@@ -1505,7 +1508,7 @@ static int METAL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
||||
mtlregion = MTLRegionMake2D(rect->x, rect->y, rect->w, rect->h);
|
||||
|
||||
// we only do BGRA8 or RGBA8 at the moment, so 4 will do.
|
||||
temp_pitch = rect->w * 4;
|
||||
temp_pitch = rect->w * 4UL;
|
||||
temp_pixels = SDL_malloc(temp_pitch * rect->h);
|
||||
if (!temp_pixels) {
|
||||
return SDL_OutOfMemory();
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "SDL_internal.h"
|
||||
|
||||
#if SDL_VIDEO_RENDER_OGL && !SDL_RENDER_DISABLED
|
||||
#include "../../video/SDL_sysvideo.h" /* For SDL_GL_SwapWindowWithResult */
|
||||
#include "../../video/SDL_sysvideo.h" /* For SDL_GL_SwapWindowWithResult and SDL_RecreateWindow */
|
||||
#include <SDL3/SDL_opengl.h>
|
||||
#include "../SDL_sysrender.h"
|
||||
#include "SDL_shaders_gl.h"
|
||||
@@ -49,9 +49,6 @@
|
||||
http://developer.apple.com/library/mac/#documentation/GraphicsImaging/Conceptual/OpenGL-MacProgGuide/opengl_texturedata/opengl_texturedata.html
|
||||
*/
|
||||
|
||||
/* Used to re-create the window with OpenGL capability */
|
||||
extern int SDL_RecreateWindow(SDL_Window *window, Uint32 flags);
|
||||
|
||||
static const float inv255f = 1.0f / 255.0f;
|
||||
|
||||
typedef struct GL_FBOList GL_FBOList;
|
||||
@@ -476,7 +473,7 @@ static int GL_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
|
||||
size_t size;
|
||||
data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
|
||||
size = texture->h * data->pitch;
|
||||
size = (size_t)texture->h * data->pitch;
|
||||
if (texture->format == SDL_PIXELFORMAT_YV12 ||
|
||||
texture->format == SDL_PIXELFORMAT_IYUV) {
|
||||
/* Need to add size for the U and V planes */
|
||||
@@ -694,7 +691,7 @@ static int GL_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
||||
GL_TextureData *data = (GL_TextureData *)texture->driverdata;
|
||||
const int texturebpp = SDL_BYTESPERPIXEL(texture->format);
|
||||
|
||||
SDL_assert(texturebpp != 0); /* otherwise, division by zero later. */
|
||||
SDL_assert_release(texturebpp != 0); /* otherwise, division by zero later. */
|
||||
|
||||
GL_ActivateRenderer(renderer);
|
||||
|
||||
@@ -1429,12 +1426,12 @@ static int GL_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
||||
SDL_GetPixelFormatName(temp_format));
|
||||
}
|
||||
|
||||
if (!rect->w || !rect->h) {
|
||||
if (rect->w == 0 || rect->h == 0) {
|
||||
return 0; /* nothing to do. */
|
||||
}
|
||||
|
||||
temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
|
||||
temp_pixels = SDL_malloc(rect->h * temp_pitch);
|
||||
temp_pixels = SDL_malloc((size_t)rect->h * temp_pitch);
|
||||
if (temp_pixels == NULL) {
|
||||
return SDL_OutOfMemory();
|
||||
}
|
||||
|
||||
@@ -470,7 +470,7 @@ static SDL_bool CompileShaderProgram(GL_ShaderContext *ctx, int index, GL_Shader
|
||||
ctx->glUseProgramObjectARB(data->program);
|
||||
for (i = 0; i < num_tmus_bound; ++i) {
|
||||
char tex_name[10];
|
||||
SDL_snprintf(tex_name, SDL_arraysize(tex_name), "tex%d", i);
|
||||
(void)SDL_snprintf(tex_name, SDL_arraysize(tex_name), "tex%d", i);
|
||||
location = ctx->glGetUniformLocationARB(data->program, tex_name);
|
||||
if (location >= 0) {
|
||||
ctx->glUniform1iARB(location, i);
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
#if SDL_VIDEO_RENDER_OGL_ES2 && !SDL_RENDER_DISABLED
|
||||
|
||||
#include "../../video/SDL_sysvideo.h" /* For SDL_GL_SwapWindowWithResult */
|
||||
#include "../../video/SDL_sysvideo.h" /* For SDL_GL_SwapWindowWithResult and SDL_RecreateWindow */
|
||||
#include <SDL3/SDL_opengles2.h>
|
||||
#include "../SDL_sysrender.h"
|
||||
#include "../../video/SDL_blit.h"
|
||||
@@ -45,9 +45,6 @@
|
||||
#define RENDERER_CONTEXT_MAJOR 2
|
||||
#define RENDERER_CONTEXT_MINOR 0
|
||||
|
||||
/* Used to re-create the window with OpenGL ES capability */
|
||||
extern int SDL_RecreateWindow(SDL_Window *window, Uint32 flags);
|
||||
|
||||
/*************************************************************************************************
|
||||
* Context structures *
|
||||
*************************************************************************************************/
|
||||
@@ -1462,7 +1459,7 @@ static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture)
|
||||
if (texture->access == SDL_TEXTUREACCESS_STREAMING) {
|
||||
size_t size;
|
||||
data->pitch = texture->w * SDL_BYTESPERPIXEL(texture->format);
|
||||
size = texture->h * data->pitch;
|
||||
size = (size_t)texture->h * data->pitch;
|
||||
#if SDL_HAVE_YUV
|
||||
if (data->yuv) {
|
||||
/* Need to add size for the U and V planes */
|
||||
@@ -1562,7 +1559,7 @@ static int GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoff
|
||||
Uint32 *blob2 = NULL;
|
||||
#endif
|
||||
Uint8 *src;
|
||||
int src_pitch;
|
||||
size_t src_pitch;
|
||||
int y;
|
||||
|
||||
if ((width == 0) || (height == 0) || (bpp == 0)) {
|
||||
@@ -1570,7 +1567,7 @@ static int GLES2_TexSubImage2D(GLES2_RenderData *data, GLenum target, GLint xoff
|
||||
}
|
||||
|
||||
/* Reformat the texture data into a tightly packed array */
|
||||
src_pitch = width * bpp;
|
||||
src_pitch = (size_t)width * bpp;
|
||||
src = (Uint8 *)pixels;
|
||||
if (pitch != src_pitch) {
|
||||
blob = (Uint8 *)SDL_malloc(src_pitch * height);
|
||||
@@ -1912,7 +1909,7 @@ static int GLES2_RenderReadPixels(SDL_Renderer *renderer, const SDL_Rect *rect,
|
||||
int status;
|
||||
|
||||
temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format);
|
||||
buflen = rect->h * temp_pitch;
|
||||
buflen = (size_t)rect->h * temp_pitch;
|
||||
if (buflen == 0) {
|
||||
return 0; /* nothing to do. */
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ static int SW_UpdateTexture(SDL_Renderer *renderer, SDL_Texture *texture,
|
||||
dst = (Uint8 *)surface->pixels +
|
||||
rect->y * surface->pitch +
|
||||
rect->x * surface->format->BytesPerPixel;
|
||||
length = rect->w * surface->format->BytesPerPixel;
|
||||
length = (size_t)rect->w * surface->format->BytesPerPixel;
|
||||
for (row = 0; row < rect->h; ++row) {
|
||||
SDL_memcpy(dst, src, length);
|
||||
src += pitch;
|
||||
@@ -533,9 +533,9 @@ static int SW_QueueGeometry(SDL_Renderer *renderer, SDL_RenderCommand *cmd, SDL_
|
||||
int i;
|
||||
int count = indices ? num_indices : num_vertices;
|
||||
void *verts;
|
||||
int sz = texture ? sizeof(GeometryCopyData) : sizeof(GeometryFillData);
|
||||
size_t sz = texture != NULL ? sizeof(GeometryCopyData) : sizeof(GeometryFillData);
|
||||
|
||||
verts = (void *)SDL_AllocateRenderVertices(renderer, count * sz, 0, &cmd->data.draw.first);
|
||||
verts = SDL_AllocateRenderVertices(renderer, count * sz, 0, &cmd->data.draw.first);
|
||||
if (verts == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@@ -636,7 +636,7 @@ static void SetDrawState(SDL_Surface *surface, SW_DrawStateCache *drawstate)
|
||||
if (drawstate->surface_cliprect_dirty) {
|
||||
const SDL_Rect *viewport = drawstate->viewport;
|
||||
const SDL_Rect *cliprect = drawstate->cliprect;
|
||||
SDL_assert(viewport != NULL); /* the higher level should have forced a SDL_RENDERCMD_SETVIEWPORT */
|
||||
SDL_assert_release(viewport != NULL); /* the higher level should have forced a SDL_RENDERCMD_SETVIEWPORT */
|
||||
|
||||
if (cliprect != NULL) {
|
||||
SDL_Rect clip_rect;
|
||||
|
||||
@@ -431,7 +431,7 @@ static void transformSurfaceY(SDL_Surface *src, SDL_Surface *dst, int isin, int
|
||||
/*
|
||||
* Clear surface to colorkey
|
||||
*/
|
||||
SDL_memset(pc, (int)(get_colorkey(src) & 0xff), dst->pitch * dst->h);
|
||||
SDL_memset(pc, (int)(get_colorkey(src) & 0xff), (size_t)dst->pitch * dst->h);
|
||||
/*
|
||||
* Iterate through destination surface
|
||||
*/
|
||||
|
||||
@@ -658,7 +658,7 @@ int SDL_SW_BlitTriangle(
|
||||
tmp_info.src_pitch = src_pitch;
|
||||
|
||||
/* dst */
|
||||
tmp_info.dst = (Uint8 *)dst_ptr;
|
||||
tmp_info.dst = dst_ptr;
|
||||
tmp_info.dst_pitch = dst_pitch;
|
||||
|
||||
SDL_BlitTriangle_Slow(&tmp_info, s2_x_area, dstrect, area, bias_w0, bias_w1, bias_w2,
|
||||
@@ -681,7 +681,7 @@ int SDL_SW_BlitTriangle(
|
||||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
TRIANGLE_GET_TEXTCOORD
|
||||
Uint8 *sptr = (Uint8 *)((Uint8 *)src_ptr + srcy * src_pitch);
|
||||
Uint8 *sptr = (Uint8 *)src_ptr + srcy * src_pitch;
|
||||
dptr[0] = sptr[3 * srcx];
|
||||
dptr[1] = sptr[3 * srcx + 1];
|
||||
dptr[2] = sptr[3 * srcx + 2];
|
||||
@@ -699,7 +699,7 @@ int SDL_SW_BlitTriangle(
|
||||
TRIANGLE_BEGIN_LOOP
|
||||
{
|
||||
TRIANGLE_GET_TEXTCOORD
|
||||
Uint8 *sptr = (Uint8 *)((Uint8 *)src_ptr + srcy * src_pitch);
|
||||
Uint8 *sptr = (Uint8 *)src_ptr + srcy * src_pitch;
|
||||
*dptr = sptr[srcx];
|
||||
}
|
||||
TRIANGLE_END_LOOP
|
||||
@@ -838,14 +838,17 @@ static void SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
|
||||
break;
|
||||
case SDL_COPY_ADD:
|
||||
dstR = srcR + dstR;
|
||||
if (dstR > 255)
|
||||
if (dstR > 255) {
|
||||
dstR = 255;
|
||||
}
|
||||
dstG = srcG + dstG;
|
||||
if (dstG > 255)
|
||||
if (dstG > 255) {
|
||||
dstG = 255;
|
||||
}
|
||||
dstB = srcB + dstB;
|
||||
if (dstB > 255)
|
||||
if (dstB > 255) {
|
||||
dstB = 255;
|
||||
}
|
||||
break;
|
||||
case SDL_COPY_MOD:
|
||||
dstR = (srcR * dstR) / 255;
|
||||
@@ -854,17 +857,21 @@ static void SDL_BlitTriangle_Slow(SDL_BlitInfo *info,
|
||||
break;
|
||||
case SDL_COPY_MUL:
|
||||
dstR = ((srcR * dstR) + (dstR * (255 - srcA))) / 255;
|
||||
if (dstR > 255)
|
||||
if (dstR > 255) {
|
||||
dstR = 255;
|
||||
}
|
||||
dstG = ((srcG * dstG) + (dstG * (255 - srcA))) / 255;
|
||||
if (dstG > 255)
|
||||
if (dstG > 255) {
|
||||
dstG = 255;
|
||||
}
|
||||
dstB = ((srcB * dstB) + (dstB * (255 - srcA))) / 255;
|
||||
if (dstB > 255)
|
||||
if (dstB > 255) {
|
||||
dstB = 255;
|
||||
}
|
||||
dstA = ((srcA * dstA) + (dstA * (255 - srcA))) / 255;
|
||||
if (dstA > 255)
|
||||
if (dstA > 255) {
|
||||
dstA = 255;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (FORMAT_HAS_ALPHA(dstfmt_val)) {
|
||||
|
||||
Reference in New Issue
Block a user