Skip to content

Commit f548180

Browse files
committed
Kill more video_driver_get_size calls now in d3d9
1 parent 5a60e25 commit f548180

3 files changed

Lines changed: 67 additions & 44 deletions

File tree

gfx/common/d3d9_common.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,21 +336,24 @@ void d3d9_make_d3dpp(d3d9_video_t *d3d,
336336
if (!windowed_enable)
337337
{
338338
#ifdef _XBOX
339-
/* Xbox: query the actual display size and publish it to
340-
* video_st. Use the same values directly for the d3dpp
341-
* back-buffer rather than reading them back via
342-
* video_driver_get_size (which would just return what we
343-
* just wrote -- nothing else writes video_st->width /
344-
* height except the video drivers themselves). */
339+
/* Xbox: query the actual display size, publish it to video_st
340+
* and track it in d3d->vp.full_width/full_height so subsequent
341+
* read sites can pull from the local field instead of locking
342+
* video_st. */
345343
unsigned width = 0;
346344
unsigned height = 0;
347345
d3d9_get_video_size(d3d, &width, &height);
348346
video_driver_set_size(width, height);
347+
d3d->vp.full_width = width;
348+
d3d->vp.full_height = height;
349349
d3dpp->BackBufferWidth = width;
350350
d3dpp->BackBufferHeight = height;
351351
#else
352-
video_driver_get_size(&d3dpp->BackBufferWidth,
353-
&d3dpp->BackBufferHeight);
352+
/* Non-Xbox: by the time make_d3dpp runs, d3d9_*_init_internal
353+
* has already published the size and written d3d->vp.
354+
* full_width/full_height; read from there. */
355+
d3dpp->BackBufferWidth = d3d->vp.full_width;
356+
d3dpp->BackBufferHeight = d3d->vp.full_height;
354357
#endif
355358
}
356359

gfx/drivers/d3d9cg.c

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,7 +1489,8 @@ static void d3d9_cg_font_render_msg(
14891489
if (!d3d || !font || !msg || !*msg)
14901490
return;
14911491

1492-
video_driver_get_size(&width, &height);
1492+
width = d3d->vp.full_width;
1493+
height = d3d->vp.full_height;
14931494
if (!width || !height)
14941495
return;
14951496

@@ -1657,8 +1658,8 @@ static void d3d9_cg_font_render_msg(
16571658
float _inv_vp_w, _inv_vp_h;
16581659
float _inv_tex_w, _inv_tex_h;
16591660
const struct font_glyph *_glyph_q = NULL;
1660-
unsigned _rl_width = 0;
1661-
unsigned _rl_height = 0;
1661+
unsigned _rl_width = d3d->vp.full_width;
1662+
unsigned _rl_height = d3d->vp.full_height;
16621663
int _rx, _ry;
16631664
unsigned _vert_count = 0;
16641665
Vertex *_verts = NULL;
@@ -1668,7 +1669,6 @@ static void d3d9_cg_font_render_msg(
16681669
float _rl_pos_y = drop_pos_y;
16691670
D3DCOLOR _rl_color = color_dark;
16701671

1671-
video_driver_get_size(&_rl_width, &_rl_height);
16721672
if (_rl_width && _rl_height)
16731673
{
16741674
_verts = d3d9_cg_font_get_scratch(font, _rl_msg_len * 6);
@@ -1771,8 +1771,8 @@ static void d3d9_cg_font_render_msg(
17711771
float _inv_vp_w, _inv_vp_h;
17721772
float _inv_tex_w, _inv_tex_h;
17731773
const struct font_glyph *_glyph_q = NULL;
1774-
unsigned _rl_width = 0;
1775-
unsigned _rl_height = 0;
1774+
unsigned _rl_width = d3d->vp.full_width;
1775+
unsigned _rl_height = d3d->vp.full_height;
17761776
int _rx, _ry;
17771777
unsigned _vert_count = 0;
17781778
Vertex *_verts = NULL;
@@ -1782,7 +1782,6 @@ static void d3d9_cg_font_render_msg(
17821782
float _rl_pos_y = line_y;
17831783
D3DCOLOR _rl_color = color;
17841784

1785-
video_driver_get_size(&_rl_width, &_rl_height);
17861785
if (_rl_width && _rl_height)
17871786
{
17881787
_verts = d3d9_cg_font_get_scratch(font, _rl_msg_len * 6);
@@ -3664,7 +3663,10 @@ static void d3d9_cg_set_viewport(void *data,
36643663
int y = 0;
36653664
struct video_viewport vp;
36663665

3667-
video_driver_get_size(&width, &height);
3666+
/* Width/height parameters are intentionally overwritten here:
3667+
* the caller's values are not used (pre-existing behaviour). */
3668+
width = d3d->vp.full_width;
3669+
height = d3d->vp.full_height;
36683670

36693671
vp.full_width = width;
36703672
vp.full_height = height;
@@ -3712,7 +3714,6 @@ static void d3d9_cg_set_viewport(void *data,
37123714

37133715
static bool d3d9_cg_initialize(d3d9_video_t *d3d, const video_info_t *info)
37143716
{
3715-
unsigned width, height;
37163717
bool ret = true;
37173718
settings_t *settings = config_get_ptr();
37183719

@@ -3747,9 +3748,10 @@ static bool d3d9_cg_initialize(d3d9_video_t *d3d, const video_info_t *info)
37473748
return false;
37483749
}
37493750

3750-
video_driver_get_size(&width, &height);
3751+
/* d3d->vp.full_* was written by the caller (d3d9_cg_init_internal
3752+
* has already called set_size at this point). */
37513753
d3d9_cg_set_viewport(d3d,
3752-
width, height, false, true);
3754+
d3d->vp.full_width, d3d->vp.full_height, false, true);
37533755

37543756
font_driver_init_osd(d3d, info,
37553757
false,
@@ -3974,6 +3976,8 @@ static bool d3d9_cg_init_internal(d3d9_video_t *d3d,
39743976
unsigned new_width = info->fullscreen ? full_x : info->width;
39753977
unsigned new_height = info->fullscreen ? full_y : info->height;
39763978
video_driver_set_size(new_width, new_height);
3979+
d3d->vp.full_width = new_width;
3980+
d3d->vp.full_height = new_height;
39773981

39783982
#ifdef HAVE_WINDOW
39793983
/* Use new_width / new_height directly rather than reading
@@ -4832,6 +4836,8 @@ static void d3d9_cg_set_resize(d3d9_video_t *d3d,
48324836
d3d->video_info.width = new_width;
48334837
d3d->video_info.height = new_height;
48344838
video_driver_set_size(new_width, new_height);
4839+
d3d->vp.full_width = new_width;
4840+
d3d->vp.full_height = new_height;
48354841
}
48364842

48374843
static bool d3d9_cg_alive(void *data)
@@ -4843,8 +4849,11 @@ static bool d3d9_cg_alive(void *data)
48434849
bool resize = false;
48444850
d3d9_video_t *d3d = (d3d9_video_t*)data;
48454851

4846-
/* Needed because some context drivers don't track their sizes */
4847-
video_driver_get_size(&temp_width, &temp_height);
4852+
/* Read from local bookkeeping rather than video_st (which would
4853+
* acquire context_lock + display_lock). d3d->vp.full_* is
4854+
* written at every set_size call site in this driver. */
4855+
temp_width = d3d->vp.full_width;
4856+
temp_height = d3d->vp.full_height;
48484857

48494858
win32_check_window(NULL, &quit, &resize, &temp_width, &temp_height);
48504859

@@ -4862,7 +4871,11 @@ static bool d3d9_cg_alive(void *data)
48624871

48634872
if ( temp_width != 0 &&
48644873
temp_height != 0)
4874+
{
48654875
video_driver_set_size(temp_width, temp_height);
4876+
d3d->vp.full_width = temp_width;
4877+
d3d->vp.full_height = temp_height;
4878+
}
48664879

48674880
return ret;
48684881
}
@@ -4890,18 +4903,15 @@ void d3d9_cg_set_rotation(void *data, unsigned rot)
48904903

48914904
void d3d9_cg_viewport_info(void *data, struct video_viewport *vp)
48924905
{
4893-
unsigned width, height;
48944906
d3d9_video_t *d3d = (d3d9_video_t*)data;
48954907

4896-
video_driver_get_size(&width, &height);
4897-
48984908
vp->x = d3d->out_vp.X;
48994909
vp->y = d3d->out_vp.Y;
49004910
vp->width = d3d->out_vp.Width;
49014911
vp->height = d3d->out_vp.Height;
49024912

4903-
vp->full_width = width;
4904-
vp->full_height = height;
4913+
vp->full_width = d3d->vp.full_width;
4914+
vp->full_height = d3d->vp.full_height;
49054915
}
49064916

49074917
static INLINE bool d3d9_cg_device_get_render_target_data(
@@ -4915,15 +4925,14 @@ static INLINE bool d3d9_cg_device_get_render_target_data(
49154925

49164926
bool d3d9_cg_read_viewport(void *data, uint8_t *buffer, bool is_idle)
49174927
{
4918-
unsigned width, height;
49194928
D3DLOCKED_RECT rect;
49204929
LPDIRECT3DSURFACE9 target = NULL;
49214930
LPDIRECT3DSURFACE9 dest = NULL;
49224931
bool ret = true;
49234932
d3d9_video_t *d3d = (d3d9_video_t*)data;
49244933
LPDIRECT3DDEVICE9 d3dr = d3d->dev;
4925-
4926-
video_driver_get_size(&width, &height);
4934+
unsigned width = d3d->vp.full_width;
4935+
unsigned height = d3d->vp.full_height;
49274936

49284937
if (
49294938
!SUCCEEDED(IDirect3DDevice9_GetRenderTarget(d3dr, 0, (LPDIRECT3DSURFACE9*)&target))

gfx/drivers/d3d9hlsl.c

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,7 +1606,8 @@ static void d3d9_font_render_msg(
16061606
if (!d3d)
16071607
return;
16081608

1609-
video_driver_get_size(&width, &height);
1609+
width = d3d->vp.full_width;
1610+
height = d3d->vp.full_height;
16101611
if (!width || !height)
16111612
return;
16121613

@@ -6901,7 +6902,10 @@ static void d3d9_hlsl_set_viewport(void *data,
69016902
int y = 0;
69026903
struct video_viewport vp;
69036904

6904-
video_driver_get_size(&width, &height);
6905+
/* Width/height parameters are intentionally overwritten here:
6906+
* the caller's values are not used (pre-existing behaviour). */
6907+
width = d3d->vp.full_width;
6908+
height = d3d->vp.full_height;
69056909

69066910
vp.full_width = width;
69076911
vp.full_height = height;
@@ -6963,7 +6967,6 @@ static void d3d9_hlsl_set_osd_msg(void *data,
69636967
static bool d3d9_hlsl_initialize(
69646968
d3d9_video_t *d3d, const video_info_t *info)
69656969
{
6966-
unsigned width, height;
69676970
bool ret = true;
69686971

69696972
if (!d3d->d3d9)
@@ -6998,9 +7001,10 @@ static bool d3d9_hlsl_initialize(
69987001
return false;
69997002
}
70007003

7001-
video_driver_get_size(&width, &height);
7004+
/* d3d->vp.full_* was written by the caller (d3d9_hlsl_init_internal
7005+
* has already called set_size at this point). */
70027006
d3d9_hlsl_set_viewport(d3d,
7003-
width, height, false, true);
7007+
d3d->vp.full_width, d3d->vp.full_height, false, true);
70047008

70057009
font_driver_init_osd(d3d, info,
70067010
false,
@@ -7200,6 +7204,8 @@ static bool d3d9_hlsl_init_internal(d3d9_video_t *d3d,
72007204
unsigned new_width = info->fullscreen ? full_x : info->width;
72017205
unsigned new_height = info->fullscreen ? full_y : info->height;
72027206
video_driver_set_size(new_width, new_height);
7207+
d3d->vp.full_width = new_width;
7208+
d3d->vp.full_height = new_height;
72037209

72047210
#ifdef HAVE_WINDOW
72057211
/* Use new_width / new_height directly rather than reading
@@ -7285,18 +7291,15 @@ static void *d3d9_hlsl_init(const video_info_t *info,
72857291

72867292
static void d3d9_hlsl_viewport_info(void *data, struct video_viewport *vp)
72877293
{
7288-
unsigned width, height;
72897294
d3d9_video_t *d3d = (d3d9_video_t*)data;
72907295

7291-
video_driver_get_size(&width, &height);
7292-
72937296
vp->x = d3d->out_vp.X;
72947297
vp->y = d3d->out_vp.Y;
72957298
vp->width = d3d->out_vp.Width;
72967299
vp->height = d3d->out_vp.Height;
72977300

7298-
vp->full_width = width;
7299-
vp->full_height = height;
7301+
vp->full_width = d3d->vp.full_width;
7302+
vp->full_height = d3d->vp.full_height;
73007303
}
73017304

73027305
#ifdef HAVE_OVERLAY
@@ -8173,6 +8176,8 @@ static void d3d9_hlsl_set_resize(d3d9_video_t *d3d,
81738176
d3d->video_info.width = new_width;
81748177
d3d->video_info.height = new_height;
81758178
video_driver_set_size(new_width, new_height);
8179+
d3d->vp.full_width = new_width;
8180+
d3d->vp.full_height = new_height;
81768181
}
81778182

81788183
static bool d3d9_hlsl_alive(void *data)
@@ -8184,8 +8189,11 @@ static bool d3d9_hlsl_alive(void *data)
81848189
bool resize = false;
81858190
d3d9_video_t *d3d = (d3d9_video_t*)data;
81868191

8187-
/* Needed because some context drivers don't track their sizes */
8188-
video_driver_get_size(&temp_width, &temp_height);
8192+
/* Read from local bookkeeping rather than video_st (which would
8193+
* acquire context_lock + display_lock). d3d->vp.full_* is
8194+
* written at every set_size call site in this driver. */
8195+
temp_width = d3d->vp.full_width;
8196+
temp_height = d3d->vp.full_height;
81898197

81908198
win32_check_window(NULL, &quit, &resize, &temp_width, &temp_height);
81918199

@@ -8203,7 +8211,11 @@ static bool d3d9_hlsl_alive(void *data)
82038211

82048212
if ( temp_width != 0 &&
82058213
temp_height != 0)
8214+
{
82068215
video_driver_set_size(temp_width, temp_height);
8216+
d3d->vp.full_width = temp_width;
8217+
d3d->vp.full_height = temp_height;
8218+
}
82078219

82088220
return ret;
82098221
}
@@ -8264,15 +8276,14 @@ static INLINE bool d3d9_hlsl_device_get_render_target_data(
82648276

82658277
static bool d3d9_hlsl_read_viewport(void *data, uint8_t *buffer, bool is_idle)
82668278
{
8267-
unsigned width, height;
82688279
D3DLOCKED_RECT rect;
82698280
LPDIRECT3DSURFACE9 target = NULL;
82708281
LPDIRECT3DSURFACE9 dest = NULL;
82718282
bool ret = true;
82728283
d3d9_video_t *d3d = (d3d9_video_t*)data;
82738284
LPDIRECT3DDEVICE9 d3dr = d3d->dev;
8274-
8275-
video_driver_get_size(&width, &height);
8285+
unsigned width = d3d->vp.full_width;
8286+
unsigned height = d3d->vp.full_height;
82768287

82778288
if (
82788289
!(d3dr &&

0 commit comments

Comments
 (0)