Skip to content

Commit 5f38f4a

Browse files
committed
Further round of kill redundant video_driver_get_size calls
1 parent f548180 commit 5f38f4a

4 files changed

Lines changed: 38 additions & 21 deletions

File tree

gfx/common/gdi_defines.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ typedef struct gdi
4141
unsigned video_height;
4242
unsigned screen_width;
4343
unsigned screen_height;
44+
/* Surface (window) size last published via video_driver_set_size,
45+
* tracked here so gdi_alive can read it without locking. Distinct
46+
* from video_width / video_height which is the core's frame size. */
47+
unsigned full_width;
48+
unsigned full_height;
4449

4550
unsigned menu_width;
4651
unsigned menu_height;

gfx/drivers/gdi_gfx.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,8 @@ static void *gdi_init(const video_info_t *video,
573573
video_driver_set_size(temp_width, temp_height);
574574
else
575575
video_driver_get_size(&temp_width, &temp_height);
576+
gdi->full_width = temp_width;
577+
gdi->full_height = temp_height;
576578

577579
RARCH_LOG("[GDI] Using resolution %ux%u.\n", temp_width, temp_height);
578580

@@ -793,17 +795,25 @@ static bool gdi_alive(void *data)
793795
bool quit = false;
794796
bool resize = false;
795797
bool ret = false;
798+
gdi_t *gdi = (gdi_t*)data;
796799

797-
/* Needed because some context drivers don't track their sizes */
798-
video_driver_get_size(&temp_width, &temp_height);
800+
/* Read from local bookkeeping rather than video_st (which would
801+
* acquire context_lock + display_lock). gdi->full_{width,height}
802+
* is written at every set_size call site in this driver. */
803+
temp_width = gdi->full_width;
804+
temp_height = gdi->full_height;
799805

800806
win32_check_window(NULL,
801807
&quit, &resize, &temp_width, &temp_height);
802808

803809
ret = !quit;
804810

805811
if (temp_width != 0 && temp_height != 0)
812+
{
806813
video_driver_set_size(temp_width, temp_height);
814+
gdi->full_width = temp_width;
815+
gdi->full_height = temp_height;
816+
}
807817

808818
return ret;
809819
}

gfx/drivers/gl1.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,8 @@ static void *gl1_init(const video_info_t *video,
12871287
video_driver_set_size(temp_width, temp_height);
12881288
else
12891289
video_driver_get_size(&temp_width, &temp_height);
1290+
gl1->vp.full_width = temp_width;
1291+
gl1->vp.full_height = temp_height;
12901292

12911293
RARCH_LOG("[GL1] Using resolution %ux%u.\n", temp_width, temp_height);
12921294

@@ -2008,8 +2010,11 @@ static bool gl1_alive(void *data)
20082010
bool ret = false;
20092011
gl1_t *gl1 = (gl1_t*)data;
20102012

2011-
/* Needed because some context drivers don't track their sizes */
2012-
video_driver_get_size(&temp_width, &temp_height);
2013+
/* Read from local bookkeeping rather than video_st (which would
2014+
* acquire context_lock + display_lock). gl1->vp.full_* is
2015+
* written at every set_size call site in this driver. */
2016+
temp_width = gl1->vp.full_width;
2017+
temp_height = gl1->vp.full_height;
20132018

20142019
gl1->ctx_driver->check_window(gl1->ctx_data,
20152020
&quit, &resize, &temp_width, &temp_height);
@@ -2020,7 +2025,11 @@ static bool gl1_alive(void *data)
20202025
ret = !quit;
20212026

20222027
if (temp_width != 0 && temp_height != 0)
2028+
{
20232029
video_driver_set_size(temp_width, temp_height);
2030+
gl1->vp.full_width = temp_width;
2031+
gl1->vp.full_height = temp_height;
2032+
}
20242033

20252034
return ret;
20262035
}
@@ -2098,19 +2107,17 @@ static void gl1_set_rotation(void *data,
20982107

20992108
static void gl1_viewport_info(void *data, struct video_viewport *vp)
21002109
{
2101-
unsigned width, height;
21022110
unsigned top_y, top_dist;
21032111
gl1_t *gl1 = (gl1_t*)data;
21042112

2105-
video_driver_get_size(&width, &height);
2106-
2113+
/* gl1->vp carries full_width/full_height (written at every
2114+
* set_size call site), so the struct copy populates them
2115+
* directly without a video_driver_get_size round-trip. */
21072116
*vp = gl1->vp;
2108-
vp->full_width = width;
2109-
vp->full_height = height;
21102117

21112118
/* Adjust as GL viewport is bottom-up. */
21122119
top_y = vp->y + vp->height;
2113-
top_dist = height - top_y;
2120+
top_dist = vp->full_height - top_y;
21142121
vp->y = top_dist;
21152122
}
21162123

@@ -2135,16 +2142,13 @@ static bool gl1_read_viewport(void *data, uint8_t *buffer, bool is_idle)
21352142
/* Clamp to the region glReadPixels actually wrote.
21362143
* gl1_readback() clamps its read to
21372144
* min(vp.{w,h}, video_{width,height}), where video_{width,height}
2138-
* come from video_info and ultimately video_driver_get_size().
2145+
* come from the surface size kept in gl1->vp.full_*.
21392146
* gl1->video_{width,height} holds the core's frame size, not the
2140-
* window size, so we re-query here to match. Not a hot path. */
2141-
unsigned vd_w = 0;
2142-
unsigned vd_h = 0;
2143-
unsigned rb_w = 0;
2144-
unsigned rb_h = 0;
2145-
video_driver_get_size(&vd_w, &vd_h);
2146-
rb_w = (gl1->vp.width > vd_w) ? vd_w : gl1->vp.width;
2147-
rb_h = (gl1->vp.height > vd_h) ? vd_h : gl1->vp.height;
2147+
* window size, so we read the surface size from gl1->vp.full_*. */
2148+
unsigned vd_w = gl1->vp.full_width;
2149+
unsigned vd_h = gl1->vp.full_height;
2150+
unsigned rb_w = (gl1->vp.width > vd_w) ? vd_w : gl1->vp.width;
2151+
unsigned rb_h = (gl1->vp.height > vd_h) ? vd_h : gl1->vp.height;
21482152
video_frame_convert_rgba_to_bgr(
21492153
(const void*)gl1->readback_buffer_screenshot,
21502154
buffer,

gfx/drivers/vg.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,6 @@ static void *vg_init(const video_info_t *video,
175175
win_width, win_height, video->fullscreen))
176176
goto error;
177177

178-
video_driver_get_size(&temp_width, &temp_height);
179-
180178
temp_width = 0;
181179
temp_height = 0;
182180
mode_width = 0;

0 commit comments

Comments
 (0)