Microsoft DirectX 8.1 (C++)

Supplying a Custom Allocator-Presenter

This topic applies to Windows XP Home Edition and Windows XP Professional only.

The Allocator-Presenter is responsible for allocating DirectDraw surfaces and “presenting” the video frames for rendering. In the vast majority of scenarios, the functionality of the default Allocator-Presenter will be more than sufficient for an application’s needs. But by plugging in a custom Allocator-Presenter, an application can obtain direct access to the video bits and completely control the rendering process.  (This is referred to as “renderless mode” above, since the application, and not the VMR, is now doing the rendering.) The trade-off for this increased power is that the application must manage the added complexity DirectDraw surface management.

Using a custom allocator-presenter

The preceding figure shows the communication interfaces used by the VMR and the Allocator Presenter. A custom  Allocator Presenter that overrides all of the default allocation and presentation functionality must implement IVMRImagePresenter and IVMRSurfaceAllocator, and optionally IVMRWindowlessControl. To replace the default Allocator Presenter, an application calls IVMRSurfaceAllocatorNotify::AdviseSurfaceAllocator method and passes in a pointer to the new Allocator Presenter in response to this call, the VMR will call the Allocator Presenter's IVMRSurfaceAllocator::AdviseNotify method to provide the pointer to the VMR's IVMRSurfaceAllocatorNotify interface. The Allocator Presenter will use this interface pointer when passing events to the VMR with the IVMRSurfaceAllocatorNotify::NotifyEvent method. This technique is demonstrated in the TxtPlayer Sample application.

As an alternate solution, an application can use both its own Allocator Presenter and the default Allocator Presenter. In this scenario, the custom Allocator Presenter handles only those calls where custom functionality is needed, and passes the rest of the calls from the VMR through to the default Allocator Presenter. In many cases, an application is probably most interested in overriding the IVMRImagePresenter interface.

Using two allocator-presenters

To use both a custom Allocator Presenter and the default Allocator Presenter, an application would first call IVMRSurfaceAllocatorNotify::AdviseSurfaceAllocator to provide a pointer to the new Allocator Presenter. This causes the default Allocator Presenter to be destroyed, so the application must create another instance of it by calling QueryInterface on the VMR and requesting the IVMRSurfaceAllocator interface.  As shown in the figure above, the custom Allocator Presenter overrides the IVMRImagePresenter interface methods, and simply passes all calls to the IVMRSurfaceAllocator interface through to the default implementation. The figure also shows the IVMRWindowlessControl interface as being implemented on the Allocator Presenter. This technique is demonstrated in the Renderless Sample application.