diff options
Diffstat (limited to 'Source/3rdParty/SDL2/src/render')
21 files changed, 234 insertions, 147 deletions
diff --git a/Source/3rdParty/SDL2/src/render/SDL_render.c b/Source/3rdParty/SDL2/src/render/SDL_render.c index 8cd3a7b..4985b16 100644 --- a/Source/3rdParty/SDL2/src/render/SDL_render.c +++ b/Source/3rdParty/SDL2/src/render/SDL_render.c @@ -132,6 +132,16 @@ SDL_GetRenderDriverInfo(int index, SDL_RendererInfo * info) #endif } +static void GetWindowViewportValues(SDL_Renderer *renderer, int *logical_w, int *logical_h, SDL_Rect *viewport, SDL_FPoint *scale) +{ + SDL_LockMutex(renderer->target_mutex); + *logical_w = renderer->target ? renderer->logical_w_backup : renderer->logical_w; + *logical_h = renderer->target ? renderer->logical_h_backup : renderer->logical_h; + *viewport = renderer->target ? renderer->viewport_backup : renderer->viewport; + *scale = renderer->target ? renderer->scale_backup : renderer->scale; + SDL_UnlockMutex(renderer->target_mutex); +} + static int SDLCALL SDL_RendererEventWatch(void *userdata, SDL_Event *event) { @@ -197,35 +207,51 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event) } } else if (event->type == SDL_MOUSEMOTION) { SDL_Window *window = SDL_GetWindowFromID(event->motion.windowID); - if (renderer->logical_w && window == renderer->window) { - event->motion.x -= (int)(renderer->viewport.x * renderer->dpi_scale.x); - event->motion.y -= (int)(renderer->viewport.y * renderer->dpi_scale.y); - event->motion.x = (int)(event->motion.x / (renderer->scale.x * renderer->dpi_scale.x)); - event->motion.y = (int)(event->motion.y / (renderer->scale.y * renderer->dpi_scale.y)); - if (event->motion.xrel > 0) { - event->motion.xrel = SDL_max(1, (int)(event->motion.xrel / (renderer->scale.x * renderer->dpi_scale.x))); - } else if (event->motion.xrel < 0) { - event->motion.xrel = SDL_min(-1, (int)(event->motion.xrel / (renderer->scale.x * renderer->dpi_scale.x))); - } - if (event->motion.yrel > 0) { - event->motion.yrel = SDL_max(1, (int)(event->motion.yrel / (renderer->scale.y * renderer->dpi_scale.y))); - } else if (event->motion.yrel < 0) { - event->motion.yrel = SDL_min(-1, (int)(event->motion.yrel / (renderer->scale.y * renderer->dpi_scale.y))); + if (window == renderer->window) { + int logical_w, logical_h; + SDL_Rect viewport; + SDL_FPoint scale; + GetWindowViewportValues(renderer, &logical_w, &logical_h, &viewport, &scale); + if (logical_w) { + event->motion.x -= (int)(viewport.x * renderer->dpi_scale.x); + event->motion.y -= (int)(viewport.y * renderer->dpi_scale.y); + event->motion.x = (int)(event->motion.x / (scale.x * renderer->dpi_scale.x)); + event->motion.y = (int)(event->motion.y / (scale.y * renderer->dpi_scale.y)); + if (event->motion.xrel > 0) { + event->motion.xrel = SDL_max(1, (int)(event->motion.xrel / (scale.x * renderer->dpi_scale.x))); + } else if (event->motion.xrel < 0) { + event->motion.xrel = SDL_min(-1, (int)(event->motion.xrel / (scale.x * renderer->dpi_scale.x))); + } + if (event->motion.yrel > 0) { + event->motion.yrel = SDL_max(1, (int)(event->motion.yrel / (scale.y * renderer->dpi_scale.y))); + } else if (event->motion.yrel < 0) { + event->motion.yrel = SDL_min(-1, (int)(event->motion.yrel / (scale.y * renderer->dpi_scale.y))); + } } } } else if (event->type == SDL_MOUSEBUTTONDOWN || event->type == SDL_MOUSEBUTTONUP) { SDL_Window *window = SDL_GetWindowFromID(event->button.windowID); - if (renderer->logical_w && window == renderer->window) { - event->button.x -= (int)(renderer->viewport.x * renderer->dpi_scale.x); - event->button.y -= (int)(renderer->viewport.y * renderer->dpi_scale.y); - event->button.x = (int)(event->button.x / (renderer->scale.x * renderer->dpi_scale.x)); - event->button.y = (int)(event->button.y / (renderer->scale.y * renderer->dpi_scale.y)); + if (window == renderer->window) { + int logical_w, logical_h; + SDL_Rect viewport; + SDL_FPoint scale; + GetWindowViewportValues(renderer, &logical_w, &logical_h, &viewport, &scale); + if (logical_w) { + event->button.x -= (int)(viewport.x * renderer->dpi_scale.x); + event->button.y -= (int)(viewport.y * renderer->dpi_scale.y); + event->button.x = (int)(event->button.x / (scale.x * renderer->dpi_scale.x)); + event->button.y = (int)(event->button.y / (scale.y * renderer->dpi_scale.y)); + } } } else if (event->type == SDL_FINGERDOWN || event->type == SDL_FINGERUP || event->type == SDL_FINGERMOTION) { - if (renderer->logical_w) { + int logical_w, logical_h; + SDL_Rect viewport; + SDL_FPoint scale; + GetWindowViewportValues(renderer, &logical_w, &logical_h, &viewport, &scale); + if (logical_w) { int w = 1; int h = 1; SDL_GetRendererOutputSize(renderer, &w, &h); @@ -233,18 +259,18 @@ SDL_RendererEventWatch(void *userdata, SDL_Event *event) event->tfinger.x *= (w - 1); event->tfinger.y *= (h - 1); - event->tfinger.x -= (renderer->viewport.x * renderer->dpi_scale.x); - event->tfinger.y -= (renderer->viewport.y * renderer->dpi_scale.y); - event->tfinger.x = (event->tfinger.x / (renderer->scale.x * renderer->dpi_scale.x)); - event->tfinger.y = (event->tfinger.y / (renderer->scale.y * renderer->dpi_scale.y)); + event->tfinger.x -= (viewport.x * renderer->dpi_scale.x); + event->tfinger.y -= (viewport.y * renderer->dpi_scale.y); + event->tfinger.x = (event->tfinger.x / (scale.x * renderer->dpi_scale.x)); + event->tfinger.y = (event->tfinger.y / (scale.y * renderer->dpi_scale.y)); - if (renderer->logical_w > 1) { - event->tfinger.x = event->tfinger.x / (renderer->logical_w - 1); + if (logical_w > 1) { + event->tfinger.x = event->tfinger.x / (logical_w - 1); } else { event->tfinger.x = 0.5f; } - if (renderer->logical_h > 1) { - event->tfinger.y = event->tfinger.y / (renderer->logical_h - 1); + if (logical_h > 1) { + event->tfinger.y = event->tfinger.y / (logical_h - 1); } else { event->tfinger.y = 0.5f; } @@ -345,6 +371,7 @@ SDL_CreateRenderer(SDL_Window * window, int index, Uint32 flags) if (renderer) { renderer->magic = &renderer_magic; renderer->window = window; + renderer->target_mutex = SDL_CreateMutex(); renderer->scale.x = 1.0f; renderer->scale.y = 1.0f; renderer->dpi_scale.x = 1.0f; @@ -392,6 +419,7 @@ SDL_CreateSoftwareRenderer(SDL_Surface * surface) if (renderer) { renderer->magic = &renderer_magic; + renderer->target_mutex = SDL_CreateMutex(); renderer->scale.x = 1.0f; renderer->scale.y = 1.0f; @@ -493,6 +521,22 @@ GetClosestSupportedFormat(SDL_Renderer * renderer, Uint32 format) return renderer->info.texture_formats[0]; } + +static SDL_ScaleMode SDL_GetScaleMode(void) +{ + const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); + + if (!hint || SDL_strcasecmp(hint, "nearest") == 0) { + return SDL_ScaleModeNearest; + } else if (SDL_strcasecmp(hint, "linear") == 0) { + return SDL_ScaleModeLinear; + } else if (SDL_strcasecmp(hint, "best") == 0) { + return SDL_ScaleModeBest; + } else { + return (SDL_ScaleMode)SDL_atoi(hint); + } +} + SDL_Texture * SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int h) { @@ -534,6 +578,7 @@ SDL_CreateTexture(SDL_Renderer * renderer, Uint32 format, int access, int w, int texture->g = 255; texture->b = 255; texture->a = 255; + texture->scaleMode = SDL_GetScaleMode(); texture->renderer = renderer; texture->next = renderer->textures; if (renderer->textures) { @@ -605,7 +650,7 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface) /* See what the best texture format is */ fmt = surface->format; - if (fmt->Amask || SDL_GetColorKey(surface, NULL) == 0) { + if (fmt->Amask || SDL_HasColorKey(surface)) { needAlpha = SDL_TRUE; } else { needAlpha = SDL_FALSE; @@ -664,7 +709,7 @@ SDL_CreateTextureFromSurface(SDL_Renderer * renderer, SDL_Surface * surface) SDL_GetSurfaceAlphaMod(surface, &a); SDL_SetTextureAlphaMod(texture, a); - if (SDL_GetColorKey(surface, NULL) == 0) { + if (SDL_HasColorKey(surface)) { /* We converted to a texture with alpha format */ SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); } else { @@ -1187,6 +1232,8 @@ SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) } } + SDL_LockMutex(renderer->target_mutex); + if (texture && !renderer->target) { /* Make a backup of the viewport */ renderer->viewport_backup = renderer->viewport; @@ -1199,6 +1246,7 @@ SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) renderer->target = texture; if (renderer->SetRenderTarget(renderer, texture) < 0) { + SDL_UnlockMutex(renderer->target_mutex); return -1; } @@ -1221,6 +1269,9 @@ SDL_SetRenderTarget(SDL_Renderer *renderer, SDL_Texture *texture) renderer->logical_w = renderer->logical_w_backup; renderer->logical_h = renderer->logical_h_backup; } + + SDL_UnlockMutex(renderer->target_mutex); + if (renderer->UpdateViewport(renderer) < 0) { return -1; } @@ -1259,6 +1310,7 @@ UpdateLogicalSize(SDL_Renderer *renderer) hint = SDL_GetHint(SDL_HINT_RENDER_LOGICAL_SIZE_MODE); if (hint && (*hint == '1' || SDL_strcasecmp(hint, "overscan") == 0)) { +#if SDL_VIDEO_RENDER_D3D SDL_bool overscan_supported = SDL_TRUE; /* Unfortunately, Direct3D 9 doesn't support negative viewport numbers which the overscan implementation relies on. @@ -1269,6 +1321,9 @@ UpdateLogicalSize(SDL_Renderer *renderer) if (overscan_supported) { scale_policy = 1; } +#else + scale_policy = 1; +#endif } want_aspect = (float)renderer->logical_w / renderer->logical_h; @@ -2086,6 +2141,10 @@ SDL_DestroyRenderer(SDL_Renderer * renderer) /* It's no longer magical... */ renderer->magic = NULL; + /* Free the target mutex */ + SDL_DestroyMutex(renderer->target_mutex); + renderer->target_mutex = NULL; + /* Free the renderer instance */ renderer->DestroyRenderer(renderer); } diff --git a/Source/3rdParty/SDL2/src/render/SDL_sysrender.h b/Source/3rdParty/SDL2/src/render/SDL_sysrender.h index f0f54c8..940bebc 100644 --- a/Source/3rdParty/SDL2/src/render/SDL_sysrender.h +++ b/Source/3rdParty/SDL2/src/render/SDL_sysrender.h @@ -25,12 +25,20 @@ #include "SDL_render.h" #include "SDL_events.h" +#include "SDL_mutex.h" #include "SDL_yuv_sw_c.h" /* The SDL 2D rendering system */ typedef struct SDL_RenderDriver SDL_RenderDriver; +typedef enum +{ + SDL_ScaleModeNearest, + SDL_ScaleModeLinear, + SDL_ScaleModeBest +} SDL_ScaleMode; + typedef struct { float x; @@ -55,6 +63,7 @@ struct SDL_Texture int h; /**< The height of the texture */ int modMode; /**< The texture modulation mode */ SDL_BlendMode blendMode; /**< The texture blend mode */ + SDL_ScaleMode scaleMode; /**< The texture scale mode */ Uint8 r, g, b, a; /**< Texture modulation values */ SDL_Renderer *renderer; @@ -164,6 +173,7 @@ struct SDL_Renderer /* The list of textures */ SDL_Texture *textures; SDL_Texture *target; + SDL_mutex *target_mutex; Uint8 r, g, b, a; /**< Color for drawing operations values */ SDL_BlendMode blendMode; /**< The drawing blend mode */ diff --git a/Source/3rdParty/SDL2/src/render/SDL_yuv_sw_c.h b/Source/3rdParty/SDL2/src/render/SDL_yuv_sw_c.h index 0dfb5db..34322f2 100644 --- a/Source/3rdParty/SDL2/src/render/SDL_yuv_sw_c.h +++ b/Source/3rdParty/SDL2/src/render/SDL_yuv_sw_c.h @@ -18,6 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_yuv_sw_c_h_ +#define SDL_yuv_sw_c_h_ + #include "../SDL_internal.h" #include "SDL_video.h" @@ -64,4 +68,6 @@ void SDL_SW_DestroyYUVTexture(SDL_SW_YUVTexture * swdata); #define USE_MMX_ASSEMBLY 1 #endif +#endif /* SDL_yuv_sw_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/Source/3rdParty/SDL2/src/render/direct3d/SDL_render_d3d.c b/Source/3rdParty/SDL2/src/render/direct3d/SDL_render_d3d.c index d3be571..69a9dff 100644 --- a/Source/3rdParty/SDL2/src/render/direct3d/SDL_render_d3d.c +++ b/Source/3rdParty/SDL2/src/render/direct3d/SDL_render_d3d.c @@ -664,18 +664,6 @@ D3D_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode) return SDL_TRUE; } -static D3DTEXTUREFILTERTYPE -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return D3DTEXF_POINT; - } else /* if (*hint == '1' || SDL_strcasecmp(hint, "linear") == 0) */ { - return D3DTEXF_LINEAR; - } -} - static int D3D_CreateTextureRep(IDirect3DDevice9 *device, D3D_TextureRep *texture, DWORD usage, Uint32 format, D3DFORMAT d3dfmt, int w, int h) { @@ -829,7 +817,7 @@ D3D_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) if (!texturedata) { return SDL_OutOfMemory(); } - texturedata->scaleMode = GetScaleQuality(); + texturedata->scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? D3DTEXF_POINT : D3DTEXF_LINEAR; texture->driverdata = texturedata; diff --git a/Source/3rdParty/SDL2/src/render/direct3d11/SDL_render_d3d11.c b/Source/3rdParty/SDL2/src/render/direct3d11/SDL_render_d3d11.c index e0ccfc4..7a37039 100644 --- a/Source/3rdParty/SDL2/src/render/direct3d11/SDL_render_d3d11.c +++ b/Source/3rdParty/SDL2/src/render/direct3d11/SDL_render_d3d11.c @@ -1161,17 +1161,6 @@ D3D11_SupportsBlendMode(SDL_Renderer * renderer, SDL_BlendMode blendMode) return SDL_TRUE; } -static D3D11_FILTER -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return D3D11_FILTER_MIN_MAG_MIP_POINT; - } else /* if (*hint == '1' || SDL_strcasecmp(hint, "linear") == 0) */ { - return D3D11_FILTER_MIN_MAG_MIP_LINEAR; - } -} - static int D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) { @@ -1192,7 +1181,7 @@ D3D11_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) SDL_OutOfMemory(); return -1; } - textureData->scaleMode = GetScaleQuality(); + textureData->scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? D3D11_FILTER_MIN_MAG_MIP_POINT : D3D11_FILTER_MIN_MAG_MIP_LINEAR; texture->driverdata = textureData; @@ -2234,8 +2223,6 @@ static int D3D11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_FRect * dstrect) { - D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; - D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata; float minu, maxu, minv, maxv; Float4 color; VertexPositionColor vertices[4]; @@ -2307,8 +2294,6 @@ D3D11_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_FRect * dstrect, const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip) { - D3D11_RenderData *rendererData = (D3D11_RenderData *) renderer->driverdata; - D3D11_TextureData *textureData = (D3D11_TextureData *) texture->driverdata; float minu, maxu, minv, maxv; Float4 color; Float4X4 modelMatrix; diff --git a/Source/3rdParty/SDL2/src/render/metal/SDL_render_metal.m b/Source/3rdParty/SDL2/src/render/metal/SDL_render_metal.m index f7af72d..5b4d8ea 100644 --- a/Source/3rdParty/SDL2/src/render/metal/SDL_render_metal.m +++ b/Source/3rdParty/SDL2/src/render/metal/SDL_render_metal.m @@ -752,8 +752,7 @@ METAL_ActivateRenderCommandEncoder(SDL_Renderer * renderer, MTLLoadAction load) static void METAL_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event) { - if (event->event == SDL_WINDOWEVENT_SIZE_CHANGED || - event->event == SDL_WINDOWEVENT_SHOWN || + if (event->event == SDL_WINDOWEVENT_SHOWN || event->event == SDL_WINDOWEVENT_HIDDEN) { // !!! FIXME: write me } @@ -844,17 +843,24 @@ METAL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) mtltexdesc.height = (texture->h + 1) / 2; mtltexdesc.textureType = MTLTextureType2DArray; mtltexdesc.arrayLength = 2; - mtltexture_uv = [data.mtldevice newTextureWithDescriptor:mtltexdesc]; } else if (nv12) { mtltexdesc.pixelFormat = MTLPixelFormatRG8Unorm; mtltexdesc.width = (texture->w + 1) / 2; mtltexdesc.height = (texture->h + 1) / 2; + } + + if (yuv || nv12) { mtltexture_uv = [data.mtldevice newTextureWithDescriptor:mtltexdesc]; + if (mtltexture_uv == nil) { +#if !__has_feature(objc_arc) + [mtltexture release]; +#endif + return SDL_SetError("Texture allocation failed"); + } } METAL_TextureData *texturedata = [[METAL_TextureData alloc] init]; - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { + if (texture->scaleMode == SDL_ScaleModeNearest) { texturedata.mtlsampler = data.mtlsamplernearest; } else { texturedata.mtlsampler = data.mtlsamplerlinear; @@ -957,8 +963,8 @@ METAL_UpdateTextureYUV(SDL_Renderer * renderer, SDL_Texture * texture, const Uint8 *Vplane, int Vpitch) { @autoreleasepool { METAL_TextureData *texturedata = (__bridge METAL_TextureData *)texture->driverdata; - int Uslice = texture->format == SDL_PIXELFORMAT_YV12 ? 1 : 0; - int Vslice = texture->format == SDL_PIXELFORMAT_YV12 ? 0 : 1; + const int Uslice = 0; + const int Vslice = 1; /* Bail out if we're supposed to update an empty rectangle */ if (rect->w <= 0 || rect->h <= 0) { @@ -1345,10 +1351,23 @@ 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; + + /* Make sure we have a valid MTLTexture to read from, and an active command + * buffer we can wait for. */ METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad); - // !!! FIXME: this probably needs to commit the current command buffer, and probably waitUntilCompleted - METAL_RenderData *data = (__bridge METAL_RenderData *) renderer->driverdata; + /* Wait for the current command buffer to finish, so we don't read from the + * texture before the GPU finishes rendering to it. */ + if (data.mtlcmdencoder) { + [data.mtlcmdencoder endEncoding]; + [data.mtlcmdbuffer commit]; + [data.mtlcmdbuffer waitUntilCompleted]; + + data.mtlcmdencoder = nil; + data.mtlcmdbuffer = nil; + } + id<MTLTexture> mtltexture = data.mtlpassdesc.colorAttachments[0].texture; MTLRegion mtlregion = MTLRegionMake2D(rect->x, rect->y, rect->w, rect->h); @@ -1364,6 +1383,13 @@ METAL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, const Uint32 temp_format = (mtltexture.pixelFormat == MTLPixelFormatBGRA8Unorm) ? SDL_PIXELFORMAT_ARGB8888 : SDL_PIXELFORMAT_ABGR8888; const int status = SDL_ConvertPixels(rect->w, rect->h, temp_format, temp_pixels, temp_pitch, pixel_format, pixels, pitch); SDL_free(temp_pixels); + + /* Set up an active command buffer and encoder once we're done. It will use + * the same texture that was active before (even if it's part of the swap + * chain), since we didn't clear that when waiting for the command buffer to + * complete. */ + METAL_ActivateRenderCommandEncoder(renderer, MTLLoadActionLoad); + return status; }} diff --git a/Source/3rdParty/SDL2/src/render/opengl/SDL_render_gl.c b/Source/3rdParty/SDL2/src/render/opengl/SDL_render_gl.c index 1c379eb..f3e8326 100644 --- a/Source/3rdParty/SDL2/src/render/opengl/SDL_render_gl.c +++ b/Source/3rdParty/SDL2/src/render/opengl/SDL_render_gl.c @@ -703,18 +703,6 @@ convert_format(GL_RenderData *renderdata, Uint32 pixel_format, return SDL_TRUE; } -static GLenum -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return GL_NEAREST; - } else { - return GL_LINEAR; - } -} - static int GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) { @@ -803,7 +791,7 @@ GL_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) data->format = format; data->formattype = type; - scaleMode = GetScaleQuality(); + scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? GL_NEAREST : GL_LINEAR; renderdata->glEnable(data->type); renderdata->glBindTexture(data->type, data->texture); renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, scaleMode); diff --git a/Source/3rdParty/SDL2/src/render/opengl/SDL_shaders_gl.h b/Source/3rdParty/SDL2/src/render/opengl/SDL_shaders_gl.h index 9805c59..3697521 100644 --- a/Source/3rdParty/SDL2/src/render/opengl/SDL_shaders_gl.h +++ b/Source/3rdParty/SDL2/src/render/opengl/SDL_shaders_gl.h @@ -18,6 +18,10 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_shaders_gl_h_ +#define SDL_shaders_gl_h_ + #include "../../SDL_internal.h" /* OpenGL shader implementation */ @@ -44,4 +48,6 @@ extern GL_ShaderContext * GL_CreateShaderContext(void); extern void GL_SelectShader(GL_ShaderContext *ctx, GL_Shader shader); extern void GL_DestroyShaderContext(GL_ShaderContext *ctx); +#endif /* SDL_shaders_gl_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/Source/3rdParty/SDL2/src/render/opengles/SDL_render_gles.c b/Source/3rdParty/SDL2/src/render/opengles/SDL_render_gles.c index d6bfca5..4007dff 100644 --- a/Source/3rdParty/SDL2/src/render/opengles/SDL_render_gles.c +++ b/Source/3rdParty/SDL2/src/render/opengles/SDL_render_gles.c @@ -524,18 +524,6 @@ power_of_2(int input) return value; } -static GLenum -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return GL_NEAREST; - } else { - return GL_LINEAR; - } -} - static int GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) { @@ -603,7 +591,7 @@ GLES_CreateTexture(SDL_Renderer * renderer, SDL_Texture * texture) data->format = format; data->formattype = type; - scaleMode = GetScaleQuality(); + scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? GL_NEAREST : GL_LINEAR; renderdata->glBindTexture(data->type, data->texture); renderdata->glTexParameteri(data->type, GL_TEXTURE_MIN_FILTER, scaleMode); renderdata->glTexParameteri(data->type, GL_TEXTURE_MAG_FILTER, scaleMode); diff --git a/Source/3rdParty/SDL2/src/render/opengles2/SDL_render_gles2.c b/Source/3rdParty/SDL2/src/render/opengles2/SDL_render_gles2.c index 0cd388c..fe51b9a 100644 --- a/Source/3rdParty/SDL2/src/render/opengles2/SDL_render_gles2.c +++ b/Source/3rdParty/SDL2/src/render/opengles2/SDL_render_gles2.c @@ -553,18 +553,6 @@ static void GLES2_UnlockTexture(SDL_Renderer *renderer, SDL_Texture *texture); static int GLES2_SetRenderTarget(SDL_Renderer * renderer, SDL_Texture * texture); static void GLES2_DestroyTexture(SDL_Renderer *renderer, SDL_Texture *texture); -static GLenum -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return GL_NEAREST; - } else { - return GL_LINEAR; - } -} - static int GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) { @@ -625,7 +613,7 @@ GLES2_CreateTexture(SDL_Renderer *renderer, SDL_Texture *texture) data->nv12 = ((texture->format == SDL_PIXELFORMAT_NV12) || (texture->format == SDL_PIXELFORMAT_NV21)); data->texture_u = 0; data->texture_v = 0; - scaleMode = GetScaleQuality(); + scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? GL_NEAREST : GL_LINEAR; /* Allocate a blob for image renderdata */ if (texture->access == SDL_TEXTUREACCESS_STREAMING) { @@ -731,6 +719,10 @@ GLES2_TexSubImage2D(GLES2_DriverContext *data, GLenum target, GLint xoffset, GLi int src_pitch; int y; + if ((width == 0) || (height == 0) || (bpp == 0)) { + return 0; /* nothing to do */ + } + /* Reformat the texture data into a tightly packed array */ src_pitch = width * bpp; src = (Uint8 *)pixels; @@ -1542,7 +1534,7 @@ GLES2_UpdateVertexBuffer(SDL_Renderer *renderer, GLES2_Attribute attr, GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; #if !SDL_GLES2_USE_VBOS - data->glVertexAttribPointer(attr, attr == GLES2_ATTRIBUTE_ANGLE ? 1 : 2, GL_FLOAT, GL_FALSE, 0, vertexData); + data->glVertexAttribPointer(attr, 2, GL_FLOAT, GL_FALSE, 0, vertexData); #else if (!data->vertex_buffers[attr]) { data->glGenBuffers(1, &data->vertex_buffers[attr]); @@ -1557,7 +1549,7 @@ GLES2_UpdateVertexBuffer(SDL_Renderer *renderer, GLES2_Attribute attr, data->glBufferSubData(GL_ARRAY_BUFFER, 0, dataSizeInBytes, vertexData); } - data->glVertexAttribPointer(attr, attr == GLES2_ATTRIBUTE_ANGLE ? 1 : 2, GL_FLOAT, GL_FALSE, 0, 0); + data->glVertexAttribPointer(attr, 2, GL_FLOAT, GL_FALSE, 0, 0); #endif return 0; @@ -1873,8 +1865,9 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect GLfloat vertices[8]; GLfloat texCoords[8]; GLfloat translate[8]; - GLfloat fAngle[4]; + GLfloat fAngle[8]; GLfloat tmp; + float radian_angle; GLES2_ActivateRenderer(renderer); @@ -1884,7 +1877,11 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_CENTER); data->glEnableVertexAttribArray(GLES2_ATTRIBUTE_ANGLE); - fAngle[0] = fAngle[1] = fAngle[2] = fAngle[3] = (GLfloat)(360.0f - angle); + + radian_angle = (float)(M_PI * (360.0 - angle) / 180.0); + fAngle[0] = fAngle[2] = fAngle[4] = fAngle[6] = (GLfloat)SDL_sin(radian_angle); + /* render expects cos value - 1 (see GLES2_VertexSrc_Default_) */ + fAngle[1] = fAngle[3] = fAngle[5] = fAngle[7] = (GLfloat)SDL_cos(radian_angle) - 1.0f; /* Calculate the center of rotation */ translate[0] = translate[2] = translate[4] = translate[6] = (center->x + dstrect->x); translate[1] = translate[3] = translate[5] = translate[7] = (center->y + dstrect->y); @@ -1913,7 +1910,7 @@ GLES2_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect data->glVertexAttribPointer(GLES2_ATTRIBUTE_CENTER, 2, GL_FLOAT, GL_FALSE, 0, translate); data->glVertexAttribPointer(GLES2_ATTRIBUTE_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices);*/ - GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_ANGLE, fAngle, 4 * sizeof(GLfloat)); + GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_ANGLE, fAngle, 8 * sizeof(GLfloat)); GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_CENTER, translate, 8 * sizeof(GLfloat)); GLES2_UpdateVertexBuffer(renderer, GLES2_ATTRIBUTE_POSITION, vertices, 8 * sizeof(GLfloat)); @@ -1940,6 +1937,7 @@ GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, { GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888; + size_t buflen; void *temp_pixels; int temp_pitch; Uint8 *src, *dst, *tmp; @@ -1949,7 +1947,12 @@ GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, GLES2_ActivateRenderer(renderer); temp_pitch = rect->w * SDL_BYTESPERPIXEL(temp_format); - temp_pixels = SDL_malloc(rect->h * temp_pitch); + buflen = (size_t) (rect->h * temp_pitch); + if (buflen == 0) { + return 0; /* nothing to do. */ + } + + temp_pixels = SDL_malloc(buflen); if (!temp_pixels) { return SDL_OutOfMemory(); } diff --git a/Source/3rdParty/SDL2/src/render/opengles2/SDL_shaders_gles2.c b/Source/3rdParty/SDL2/src/render/opengles2/SDL_shaders_gles2.c index b0bcdff..f428a49 100644 --- a/Source/3rdParty/SDL2/src/render/opengles2/SDL_shaders_gles2.c +++ b/Source/3rdParty/SDL2/src/render/opengles2/SDL_shaders_gles2.c @@ -30,20 +30,24 @@ /************************************************************************************************* * Vertex/fragment shader source * *************************************************************************************************/ - +/* Notes on a_angle: + * It is a vector containing sin and cos for rotation matrix + * To get correct rotation for most cases when a_angle is disabled cos + value is decremented by 1.0 to get proper output with 0.0 which is + default value +*/ static const Uint8 GLES2_VertexSrc_Default_[] = " \ uniform mat4 u_projection; \ attribute vec2 a_position; \ attribute vec2 a_texCoord; \ - attribute float a_angle; \ + attribute vec2 a_angle; \ attribute vec2 a_center; \ varying vec2 v_texCoord; \ \ void main() \ { \ - float angle = radians(a_angle); \ - float c = cos(angle); \ - float s = sin(angle); \ + float s = a_angle[0]; \ + float c = a_angle[1] + 1.0; \ mat2 rotationMatrix = mat2(c, -s, s, c); \ vec2 position = rotationMatrix * (a_position - a_center) + a_center; \ v_texCoord = a_texCoord; \ diff --git a/Source/3rdParty/SDL2/src/render/psp/SDL_render_psp.c b/Source/3rdParty/SDL2/src/render/psp/SDL_render_psp.c index 38f893e..babc252 100644 --- a/Source/3rdParty/SDL2/src/render/psp/SDL_render_psp.c +++ b/Source/3rdParty/SDL2/src/render/psp/SDL_render_psp.c @@ -187,18 +187,6 @@ TextureNextPow2(unsigned int w) static int -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return GU_NEAREST; /* GU_NEAREST good for tile-map */ - } else { - return GU_LINEAR; /* GU_LINEAR good for scaling */ - } -} - -static int PixelFormatToPSPFMT(Uint32 format) { switch (format) { @@ -514,7 +502,7 @@ void TextureActivate(SDL_Texture * texture) { PSP_TextureData *psp_texture = (PSP_TextureData *) texture->driverdata; - int scaleMode = GetScaleQuality(); + int scaleMode = (texture->scaleMode == SDL_ScaleModeNearest) ? GU_NEAREST : GU_LINEAR; /* Swizzling is useless with small textures. */ if (texture->w >= 16 || texture->h >= 16) diff --git a/Source/3rdParty/SDL2/src/render/software/SDL_blendfillrect.h b/Source/3rdParty/SDL2/src/render/software/SDL_blendfillrect.h index 262210f..3cac834 100644 --- a/Source/3rdParty/SDL2/src/render/software/SDL_blendfillrect.h +++ b/Source/3rdParty/SDL2/src/render/software/SDL_blendfillrect.h @@ -18,10 +18,16 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_blendfillrect_h_ +#define SDL_blendfillrect_h_ + #include "../../SDL_internal.h" extern int SDL_BlendFillRect(SDL_Surface * dst, const SDL_Rect * rect, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); extern int SDL_BlendFillRects(SDL_Surface * dst, const SDL_Rect * rects, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +#endif /* SDL_blendfillrect_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/Source/3rdParty/SDL2/src/render/software/SDL_blendline.h b/Source/3rdParty/SDL2/src/render/software/SDL_blendline.h index 82072cb..a48a498 100644 --- a/Source/3rdParty/SDL2/src/render/software/SDL_blendline.h +++ b/Source/3rdParty/SDL2/src/render/software/SDL_blendline.h @@ -18,10 +18,16 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_blendline_h_ +#define SDL_blendline_h_ + #include "../../SDL_internal.h" extern int SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); extern int SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +#endif /* SDL_blendline_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/Source/3rdParty/SDL2/src/render/software/SDL_blendpoint.h b/Source/3rdParty/SDL2/src/render/software/SDL_blendpoint.h index dd9e49c..188557c 100644 --- a/Source/3rdParty/SDL2/src/render/software/SDL_blendpoint.h +++ b/Source/3rdParty/SDL2/src/render/software/SDL_blendpoint.h @@ -18,10 +18,16 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_blendpoint_h_ +#define SDL_blendpoint_h_ + #include "../../SDL_internal.h" extern int SDL_BlendPoint(SDL_Surface * dst, int x, int y, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); extern int SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +#endif /* SDL_blendpoint_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/Source/3rdParty/SDL2/src/render/software/SDL_drawline.h b/Source/3rdParty/SDL2/src/render/software/SDL_drawline.h index 9395d50..4e8e2bd 100644 --- a/Source/3rdParty/SDL2/src/render/software/SDL_drawline.h +++ b/Source/3rdParty/SDL2/src/render/software/SDL_drawline.h @@ -18,10 +18,16 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_drawline_h_ +#define SDL_drawline_h_ + #include "../../SDL_internal.h" extern int SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color); extern int SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color); +#endif /* SDL_drawline_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/Source/3rdParty/SDL2/src/render/software/SDL_drawpoint.h b/Source/3rdParty/SDL2/src/render/software/SDL_drawpoint.h index c366700..454774d 100644 --- a/Source/3rdParty/SDL2/src/render/software/SDL_drawpoint.h +++ b/Source/3rdParty/SDL2/src/render/software/SDL_drawpoint.h @@ -18,10 +18,16 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ + +#ifndef SDL_drawpoint_h_ +#define SDL_drawpoint_h_ + #include "../../SDL_internal.h" extern int SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color); extern int SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color); +#endif /* SDL_drawpoint_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/Source/3rdParty/SDL2/src/render/software/SDL_render_sw.c b/Source/3rdParty/SDL2/src/render/software/SDL_render_sw.c index 89e54b8..709dfe8 100644 --- a/Source/3rdParty/SDL2/src/render/software/SDL_render_sw.c +++ b/Source/3rdParty/SDL2/src/render/software/SDL_render_sw.c @@ -588,18 +588,6 @@ SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, } static int -GetScaleQuality(void) -{ - const char *hint = SDL_GetHint(SDL_HINT_RENDER_SCALE_QUALITY); - - if (!hint || *hint == '0' || SDL_strcasecmp(hint, "nearest") == 0) { - return 0; - } else { - return 1; - } -} - -static int SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_FRect * dstrect, const double angle, const SDL_FPoint * center, const SDL_RendererFlip flip) @@ -669,6 +657,11 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, blitRequired = SDL_TRUE; } + /* srcrect is not selecting the whole src surface, so cropping is needed */ + if (!(srcrect->w == src->w && srcrect->h == src->h && srcrect->x == 0 && srcrect->y == 0)) { + blitRequired = SDL_TRUE; + } + /* The color and alpha modulation has to be applied before the rotation when using the NONE and MOD blend modes. */ if ((blendmode == SDL_BLENDMODE_NONE || blendmode == SDL_BLENDMODE_MOD) && (alphaMod & rMod & gMod & bMod) != 255) { applyModulation = SDL_TRUE; @@ -717,7 +710,7 @@ SW_RenderCopyEx(SDL_Renderer * renderer, SDL_Texture * texture, if (!retval) { SDLgfx_rotozoomSurfaceSizeTrig(tmp_rect.w, tmp_rect.h, angle, &dstwidth, &dstheight, &cangle, &sangle); - src_rotated = SDLgfx_rotateSurface(src_clone, angle, dstwidth/2, dstheight/2, GetScaleQuality(), flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL, dstwidth, dstheight, cangle, sangle); + src_rotated = SDLgfx_rotateSurface(src_clone, angle, dstwidth/2, dstheight/2, (texture->scaleMode == SDL_ScaleModeNearest) ? 0 : 1, flip & SDL_FLIP_HORIZONTAL, flip & SDL_FLIP_VERTICAL, dstwidth, dstheight, cangle, sangle); if (src_rotated == NULL) { retval = -1; } diff --git a/Source/3rdParty/SDL2/src/render/software/SDL_render_sw_c.h b/Source/3rdParty/SDL2/src/render/software/SDL_render_sw_c.h index 8f065de..f228517 100644 --- a/Source/3rdParty/SDL2/src/render/software/SDL_render_sw_c.h +++ b/Source/3rdParty/SDL2/src/render/software/SDL_render_sw_c.h @@ -19,6 +19,11 @@ 3. This notice may not be removed or altered from any source distribution. */ +#ifndef SDL_render_sw_c_h_ +#define SDL_render_sw_c_h_ + extern SDL_Renderer * SW_CreateRendererForSurface(SDL_Surface * surface); +#endif /* SDL_render_sw_c_h_ */ + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/Source/3rdParty/SDL2/src/render/software/SDL_rotate.c b/Source/3rdParty/SDL2/src/render/software/SDL_rotate.c index 4476204..09e099c 100644 --- a/Source/3rdParty/SDL2/src/render/software/SDL_rotate.c +++ b/Source/3rdParty/SDL2/src/render/software/SDL_rotate.c @@ -83,7 +83,9 @@ static Uint32 _colorkey(SDL_Surface *src) { Uint32 key = 0; - SDL_GetColorKey(src, &key); + if (SDL_HasColorKey(src)) { + SDL_GetColorKey(src, &key); + } return key; } @@ -424,8 +426,10 @@ SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, if (src == NULL) return NULL; - if (SDL_GetColorKey(src, &colorkey) == 0) { - colorKeyAvailable = SDL_TRUE; + if (SDL_HasColorKey(src)) { + if (SDL_GetColorKey(src, &colorkey) == 0) { + colorKeyAvailable = SDL_TRUE; + } } /* This function requires a 32-bit surface or 8-bit surface with a colorkey */ diff --git a/Source/3rdParty/SDL2/src/render/software/SDL_rotate.h b/Source/3rdParty/SDL2/src/render/software/SDL_rotate.h index 2bf2ea8..54c0927 100644 --- a/Source/3rdParty/SDL2/src/render/software/SDL_rotate.h +++ b/Source/3rdParty/SDL2/src/render/software/SDL_rotate.h @@ -19,6 +19,9 @@ 3. This notice may not be removed or altered from any source distribution. */ +#ifndef SDL_rotate_h_ +#define SDL_rotate_h_ + #ifndef MIN #define MIN(a,b) (((a) < (b)) ? (a) : (b)) #endif @@ -26,3 +29,4 @@ extern SDL_Surface *SDLgfx_rotateSurface(SDL_Surface * src, double angle, int centerx, int centery, int smooth, int flipx, int flipy, int dstwidth, int dstheight, double cangle, double sangle); extern void SDLgfx_rotozoomSurfaceSizeTrig(int width, int height, double angle, int *dstwidth, int *dstheight, double *cangle, double *sangle); +#endif /* SDL_rotate_h_ */ |