ID2D1Factory interface

Creates Direct2D resources.

When to implement

Custom implementations are not supported.

Members

The ID2D1Factory interface inherits from the IUnknown interface. ID2D1Factory also has these types of members:

Methods

The ID2D1Factory interface has these methods.

MethodDescription
CreateDCRenderTarget

Creates a render target that draws to a Windows Graphics Device Interface (GDI) device context.

CreateDrawingStateBlock Overloaded.

Creates an ID2D1DrawingStateBlock that can be used with the SaveDrawingState and RestoreDrawingState methods of a render target.

CreateDxgiSurfaceRenderTarget Overloaded.

Creates a render target that draws to a DirectX Graphics Infrastructure (DXGI) surface.

CreateEllipseGeometry Overloaded.

Creates an ID2D1EllipseGeometry.

CreateGeometryGroup

Creates an ID2D1GeometryGroup, which is an object that holds other geometries.

CreateHwndRenderTarget Overloaded.

Creates an ID2D1HwndRenderTarget, a render target that renders to a window.

CreatePathGeometry

Creates an empty ID2D1PathGeometry.

CreateRectangleGeometry Overloaded.

Creates an ID2D1RectangleGeometry.

CreateRoundedRectangleGeometry Overloaded.

Creates an ID2D1RoundedRectangleGeometry.

CreateStrokeStyle Overloaded.

Creates an ID2D1StrokeStyle that describes start cap, dash pattern, and other features of a stroke.

CreateTransformedGeometry Overloaded.

Transforms the specified geometry and stores the result as an ID2D1TransformedGeometry object.

CreateWicBitmapRenderTarget Overloaded.

Creates a render target that renders to a Microsoft Windows Imaging Component (WIC) bitmap.

GetDesktopDpi

Retrieves the current desktop dots per inch (DPI). To refresh this value, call ReloadSystemMetrics.

ReloadSystemMetrics

Forces the factory to refresh any system defaults that it might have changed since factory creation.

 

Remarks

The ID2D1Factory interface is the starting point for using Direct2D; it's what you use to create other Direct2D resources that you can use to draw or describe shapes.

A factory defines a set of CreateResource methods that can produce the following drawing resources:

  • Render targets: objects that render drawing commands.
  • Drawing state blocks: objects that store drawing state information, such as the current transformation and antialiasing mode.
  • Geometries: objects that represent simple and potentially complex shapes.

To create an ID2D1Factory, you use one of the CreateFactory methods. You should retain the ID2D1Factory instance for as long as you use Direct2D resources; in general, you shouldn't need to recreate it when the application is running. For more information about Direct2D resources, see the Resources Overview.

Singlethreaded and Multithreaded Factories

When you create a factory, you can specify whether it is multithreaded or singlethreaded. A singlethreaded factory provides no serialization against any other single threaded instance within Direct2D, so, this mechanism provides a very large degree of scaling on the CPU.

You can also create a multithreaded factory instance. In this case, the factory and all derived objects can be used from any thread and each render target can be rendered to independently. Direct2D serializes calls to these objects, so a single multithreaded Direct2D instance won't scale as well on the CPU as many single threaded instances. However, the resources can be shared within the multithreaded instance.

Note that the qualifier "On the CPU": GPUs generally take advantage of fine-grained parallelism more so than CPUs. For example, multithreaded calls from the CPU might still end up being serialized when being sent to the GPU, however, a whole bank of pixel and vertex shaders will run in parallel to perform the rendering.

See Multithreaded Direct2D Apps for more info.

Examples

The following code fragments declare a factory pointer, create a singlethreaded factory instance, and use the factory to create a render target.


ID2D1Factory* m_pDirect2dFactory;



    // Create a Direct2D factory.
    hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, &m_pDirect2dFactory);



        // Create a Direct2D render target.
        hr = m_pDirect2dFactory->CreateHwndRenderTarget(
            D2D1::RenderTargetProperties(),
            D2D1::HwndRenderTargetProperties(m_hwnd, size),
            &m_pRenderTarget
            );


For the complete code, see the Draw Rectangle Example.

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

Getting Started with Direct2D
Direct2D QuickStart
Direct2D Overview
Resources Overview
Multithreaded Direct2D Apps

 

 

Community Additions

ADD
Show:
© 2014 Microsoft