Creates Direct2D resources.
When to implement
Custom implementations are not supported.
The ID2D1Factory interface inherits from the IUnknown interface. ID2D1Factory also has these types of members:
The ID2D1Factory interface has these methods.
Creates a render target that draws to a Windows Graphics Device Interface (GDI) device context.
Creates a render target that draws to a DirectX Graphics Infrastructure (DXGI) surface.
Creates an ID2D1EllipseGeometry.
Creates an ID2D1GeometryGroup, which is an object that holds other geometries.
Creates an ID2D1HwndRenderTarget, a render target that renders to a window.
Creates an empty ID2D1PathGeometry.
Creates an ID2D1RectangleGeometry.
Creates an ID2D1RoundedRectangleGeometry.
Creates an ID2D1StrokeStyle that describes start cap, dash pattern, and other features of a stroke.
Transforms the specified geometry and stores the result as an ID2D1TransformedGeometry object.
Creates a render target that renders to a Microsoft Windows Imaging Component (WIC) bitmap.
Retrieves the current desktop dots per inch (DPI). To refresh this value, call ReloadSystemMetrics.
Forces the factory to refresh any system defaults that it might have changed since factory creation.
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.
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.
The following code fragments declare a factory pointer, create a singlethreaded factory instance, and use the factory to create a render target.
// 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 );
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]
- Getting Started with Direct2D
- Direct2D QuickStart
- Direct2D Overview
- Resources Overview
- Multithreaded Direct2D Apps