Direct3D support for ActiveX controls

This article describes how to use Microsoft Direct3D 11 to present efficient, rotation-aware ActiveX controls.

SurfacePresenterFlip is a feature that extends ActiveX controls, allowing them to take advantage of Direct3D11 (and later) rendering. The Flip in the name refers to the fact that the presentation mechanism is flip-based rather than copy-based. The presentation mechanism is more tightly integrated with DirectComposition to enable better performance. SurfacePresenterFlip is based on the SurfacePresenter mechanism introduced in Windows Internet Explorer 9, but is a distinct contract with different rules and modes of operation.

The following provides more on the new interfaces. Best practice is to use these APIs to build ActiveX controls for a windowless environment.

A code sample is available on the Internet Explorer GitHub site.

Microsoft Edge/ IE interfaces

The following interfaces are implemented by Microsoft Edge and IE.

IViewObjectPresentFlipSite

The IViewObjectPresentFlipSite interface provides the main starting point to use ISurfacePresenterFlip. It Provides the following methods.

Method Description
CreateSurfacePresenterFlip Creates the ISurfacePresenterFlip object, which serves a similar role to IDXGISwapChain and represents a series of buffers used for presentation.
EnterFullScreen Places the ActiveX control into full screen mode.
ExitFullScreen Takes the ActiveX control out full screen mode.
GetBoundingRect Provides the size (in pixels) of the ActiveX control on the screen.
GetDeviceLuid Obtains the locally unique identifier (LUID) of the D3D adapter that Internet Explorer is currently using.
GetFullScreenSize Obtains the size (in pixels) required by the presenter if it were in full screen mode.
GetMetrics Returns the position and size of the ActiveX control (in pixels), and the current scale factor that Internet Explorer is applying to the control.
IsFullScreen Determines if the ActiveX control is in full screen mode.

 

IViewObjectPresentFlipSite2

The IViewObjectPresentFlipSite2 interface adds rotation-awareness functionality to IViewObjectPresentFlipSite and can be obtained via QueryInterface on the IOleClientSite pointer given in IObjectWithSite::SetSite. It provides the following methods.

Method Description
GetRotationForCurrentOutput Obtains Internet Explorer's current output rotation.

 

ISurfacePresenterFlip

ISurfacePresenterFlip is the interface for the object returned from CreateSurfacePresenterFlip. It represents a swap chain very similar to IDXGISwapChain and it is used in a very similar fashion. It provides the following.

Method Description
GetBuffer Gets an interface pointer for the indicated back buffer.
Present Presents the next back buffer to the screen and progresses the swap chain.

 

ISurfacePresenterFlip2

The ISurfacePresenterFlip2 interface adds rotation capabilities to ISurfacePresenterFlip and can be obtained with QueryInterface on the presenter.

Method Description
SetRotation Sets the current DXGI rotation mode of the swap chain.

 

ISurfacePresenterFlipBuffer

ISurfacePresenterFlipBuffer represents the shared buffer between Internet Explorer (MSHTML) and the ActiveX control and is obtained by calling ISurfacePresenterFlip::GetBuffer.

Method Description
BeginDraw Obtains a pointer to the Direct3D surface shared buffer for the ActiveX control to draw to it.
EndDraw Called by the ActiveX control to signal that it has completed drawing to the shared buffer.

 

Interfaces implemented by the control

The following interfaces need to be implemented by the ActiveX control in order to take advantage of the Direct3D11 support provided by the SurfacePresenterFlip feature.

IViewObjectPresentFlip

By implementing the IViewObjectPresentFlip interface, the browser will determine that your control will use ISurfacePresenterFlip for rendering. Controls that implement this interface can only render using ISurfacePresenterFlip, and controls cannot use ISurfacePresenterFlip unless they implement this interface.

Method Description
NotifyRender Called from the browser to notify the control that IE is rendering a frame of content. This can be used by the control to determine when to render (if synchronizing with IE's rendering is its intended behavior).
RenderObjectToBitmap Called from the browser during situations (such as printing) where a bitmap representation of the ActiveX control is needed.
RenderObjectToSharedBuffer Called from the browser to request that the ActiveX control render its current content into the provided hardware buffer.

 

IViewObjectPresentFlip2

The IViewObjectPresentFlip extends the functionality of IViewObjectPresentFlip.

Method Description
NotifyLeavingView Called by the browser when the ActiveX control has left the view and is no longer visible by the user. This can be used by the control to stop rendering content or do other resource reclamation as a result of the control being out of view.

 

IImmersiveUIHandlerSite

ICaretPositionProvider

ITridentTouchInput

ITridentTouchInputSite