Skip to content

Commit 6701f93

Browse files
Wohlstandslouken
authored andcommitted
Vita Render: Limit the scope of cliprect to viewport
Don't allow cliprect be larger than viewport's scope
1 parent 1c09a71 commit 6701f93

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

src/render/vitagxm/SDL_render_vita_gxm.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,35 @@ static int VITA_GXM_RenderClear(SDL_Renderer *renderer, SDL_RenderCommand *cmd)
826826
return 0;
827827
}
828828

829+
static void ClampCliprectToViewport(SDL_Rect *clip, const SDL_Rect *viewport)
830+
{
831+
int max_x_v, max_y_v, max_x_c, max_y_c;
832+
833+
if (clip->x < 0) {
834+
clip->w += clip->x;
835+
clip->x = 0;
836+
}
837+
838+
if (clip->y < 0) {
839+
clip->h += clip->y;
840+
clip->y = 0;
841+
}
842+
843+
max_x_c = clip->x + clip->w;
844+
max_y_c = clip->y + clip->h;
845+
846+
max_x_v = viewport->x + viewport->w;
847+
max_y_v = viewport->y + viewport->h;
848+
849+
if (max_x_c > max_x_v) {
850+
clip->w -= (max_x_v - max_x_c);
851+
}
852+
853+
if (max_y_c > max_y_v) {
854+
clip->h -= (max_y_v - max_y_c);
855+
}
856+
}
857+
829858
static int SetDrawState(VITA_GXM_RenderData *data, const SDL_RenderCommand *cmd)
830859
{
831860
SDL_Texture *texture = cmd->data.draw.texture;
@@ -869,8 +898,12 @@ static int SetDrawState(VITA_GXM_RenderData *data, const SDL_RenderCommand *cmd)
869898
}
870899

871900
if ((data->drawstate.cliprect_enabled || data->drawstate.viewport_is_set) && data->drawstate.cliprect_dirty) {
872-
const SDL_Rect *rect = &data->drawstate.cliprect;
873-
set_clip_rectangle(data, rect->x, rect->y, rect->x + rect->w, rect->y + rect->h);
901+
SDL_Rect rect;
902+
SDL_copyp(&rect, &data->drawstate.cliprect);
903+
if (data->drawstate.viewport_is_set) {
904+
ClampCliprectToViewport(&rect, &data->drawstate.viewport);
905+
}
906+
set_clip_rectangle(data, rect.x, rect.y, rect.x + rect.w, rect.y + rect.h);
874907
data->drawstate.cliprect_dirty = SDL_FALSE;
875908
}
876909

0 commit comments

Comments
 (0)