[MPlayer-dev-eng] [PATCH] Direct3D Much better D3D management

Georgi Petrov gogothebee at gmail.com
Thu Nov 27 23:38:04 CET 2008


Ok, I know this patch may seem bigger than the Reimar's requirements.
I can make more smaller patches that accomplish the same in the end if
you wish so.

The main purpose of this patch is to do a much better at D3D's
init/reset/destroy than before and fix 2-3 bugs.

Let me start:

When D3D is initialized, those things are created:

1. The "D3D" itself.
uses priv->d3d_handle

This is handled in preinit to support query of supported formats later.

2. The D3D Device
uses priv->d3d_device

This is initialized in configure_d3d();

3. The offscreen and backbuffer surfaces.
uses priv->d3d_surface
uses priv->d3d_backbuf

This is initialized in create_d3d_surfaces();

So - we have 3 "levels" of D3D initialization before we can render
frames. This is the natural way of initializing D3D.




Remember good this order. We have to handle 2 situations once D3D is
initialized:
1. Window resize / going to/from fullscreen
2. Adapter becoming uncooperative

We handle window resize / going to/from fullscreen in function resize_d3d:

* Destroy the offscreen/backbuffer surfaces
* Do a D3D Reset (which requires that no surfaces are allocated)
* Create both surfaces again.

The whole thing is needed because the Backbuffer surface doesn't
rescale itself and by reseting the D3D device and creating a new
backbuffer surface, it fills the new window's coordinates. About the
offscreen surface - we wouldn't need to destroy and recreate it again
(as it has the non-changing coordinates of the original movie), if
D3D_Reset didn't require that all D3D resources are freed before
calling it. So that's it.

We handle the adapter becoming uncooperative in function reconfigure_d3d:

* This function has new meaning from the previous one. It totally
destroys D3D and recreates it again by doing:

* Destroy the offscreen/backbuffer surfaces
* Destroy the D3D Device created in configure_d3d()
* Stop the whole D3D started in preinit

* Start the whole D3D
* Call configure_d3d()

After calling configure_d3d() we've simulated the initialization after preinit.

Problems fixed:

* Very good D3D initialize / destroy separation
* More meaningful functions:
create_d3d_surfaces()
destroy_d3d_surfaces()
configure_d3d()
resize_d3d()
reconfigure_d3d()
uninit_d3d()

Now each function does exactly what it says. Before the patch
"reconfigure_d3d" used to both destroy and recreate D3D, BUT NOT FROM
THE BEGINNING (ignoring to stop the whole D3D and create it again as
in preinit). It's more guaranteed to work now and called ONLY when the
adapter is uncooperative.

Now resize_d3d does "lightweight" resizing by calling Reset instead of
destroy/create the adapter.

* No need for destroying and recreating the D3D adapter on each resize
or going to/from fullscreen. Before this patch we killed the D3D
Device and created it again.

For fast window resizing this used to happen many times in a second.
Now we call Reset, which based on my test is faster and safer. Before
the patch if you tried to resiz the window too fast, D3D used to fall
into a state, where the D3D Device can't be created again. By calling
Reset this doesn't happen any more AND it's faster/safer.

* Going fullscreen / coming back should be a little faster (again - we
skip D3D Device destroy/create and change it with Reset)

* Fixed a bug when after calling the "previous" reconfigure_d3d() we
didn't allocate new backbuffer after coming from fullscreen (or
something like that, I'm not sure). The problem was that after coming
back from fullscreen AND resizing the window, the backbuffer stayed
with the old dimensions and the image became aliased.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: better_d3d_management.txt
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20081128/20a535bc/attachment.txt>


More information about the MPlayer-dev-eng mailing list