ID2D1DCRenderTarget interface

Issues drawing commands to a GDI device context.

When to implement

Custom implementations are not supported.

Members

The ID2D1DCRenderTarget interface inherits from ID2D1RenderTarget. ID2D1DCRenderTarget also has these types of members:

Methods

The ID2D1DCRenderTarget interface has these methods.

MethodDescription
BindDC

Binds the render target to the device context to which it issues drawing commands.

 

Remarks

Creating ID2D1DCRenderTarget Objects

To create an ID2D1DCRenderTarget, use the ID2D1Factory::CreateDCRenderTarget method.

Before you can render with the DC render target, you must use its BindDC method to associate it with a GDI DC. You do this each time you use a different DC, or the size of the area you want to draw to changes.

To enable the DC render target to work with GDI, set its pixel format to DXGI_FORMAT_B8G8R8A8_UNORM and its alpha mode to D2D1_ALPHA_MODE_PREMULTIPLIED or D2D1_ALPHA_MODE_IGNORE.

Your application should create render targets once and hold onto them for the life of the application or until the render target's EndDraw method returns the D2DERR_RECREATE_TARGET error. When you receive this error, you need to recreate the render target (and any resources it created).

ID2D1DCRenderTargets, GDI Transforms, and Right-to-Left Language Builds of Windows

When you use an ID2D1DCRenderTarget, it renders Direct2D content to an internal bitmap, and then renders the bitmap to the DC with GDI.

It's possible for GDI to apply a GDI transform (through the SetWorldTransform method) or other effect to the same DC used by the render target, in which case GDI transforms the bitmap produced by Direct2D. Using a GDI transform to transform the Direct2D content has the potential to degrade the visual quality of the output, because you're transforming a bitmap for which antialiasing and subpixel positioning have already been calculated.

For example, suppose you use the render target to draw a scene that contains antialiased geometries and text. If you use a GDI transform to apply a scale transform to the DC and scale the scene so that it's 10 times larger, you'll see pixelization and jagged edges. (If, however, you applied a similar transform using Direct2D, the visual quality of the scene would not be degraded.)

In some cases, it might not be obvious that GDI is performing additional processing that might degrade the quality of the Direct2D content. For example, on a right-to-left (RTL) build of Windows, content rendered by an ID2D1DCRenderTarget might be horizontally inverted when GDI copies it to its destination. Whether the content is actually inverted depends on the current settings of the DC.

Depending on the type of content being rendered, you might want to prevent the inversion. If the Direct2D content includes ClearType text, this inversion will degrade the quality of the text.

You can control RTL rendering behavior by using the SetLayout GDI function. To prevent the mirroring, call the SetLayout GDI function and specify LAYOUT_BITMAPORIENTATIONPRESERVED as the only value for the second parameter (do not combine it with LAYOUT_RTL), as shown in the following example:


SetLayout(m_hwnd, LAYOUT_BITMAPORIENTATIONPRESERVED);

Examples

The following code creates a DC render target.


// Create a DC render target.
D2D1_RENDER_TARGET_PROPERTIES props = D2D1::RenderTargetProperties(
    D2D1_RENDER_TARGET_TYPE_DEFAULT,
    D2D1::PixelFormat(
        DXGI_FORMAT_B8G8R8A8_UNORM,
        D2D1_ALPHA_MODE_IGNORE),
    0,
    0,
    D2D1_RENDER_TARGET_USAGE_NONE,
    D2D1_FEATURE_LEVEL_DEFAULT
    );

hr = m_pD2DFactory->CreateDCRenderTarget(&props, &m_pDCRT);


In the preceding code, m_pD2DFactory is a pointer to an ID2D1Factory, and m_pDCRT is a pointer to an ID2D1DCRenderTarget.

The next code example binds a DC to the ID2D1DCRenderTarget.


HRESULT DemoApp::OnRender(const PAINTSTRUCT &ps)
{



// Get the dimensions of the client drawing area.
GetClientRect(m_hwnd, &rc);



// Bind the DC to the DC render target.
hr = m_pDCRT->BindDC(ps.hdc, &rc);


For the complete code, see the Direct2D/GDI Interoperability Sample. For more information about using GDI with Direct2D, see the Direct2D and GDI Interoperation Overview.

Requirements

Minimum supported client

Windows 7, Windows Vista with SP2 and Platform Update for Windows Vista [desktop apps | Windows Store apps]

Minimum supported server

Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Windows Server 2008 [desktop apps | Windows Store apps]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Header

D2d1.h

Library

D2d1.lib

DLL

D2d1.dll

See also

Direct2D and GDI Interoperation Overview
Direct2D/GDI Interoperability Sample

 

 

Community Additions

ADD
Show:
© 2014 Microsoft