ID2D1Factory interface

Creates Direct2D resources.

Methods

The ID2D1Factory interface has these methods.

Method Description
ID2D1Factory::GetDesktopDpi Retrieves the current desktop dots per inch (DPI). To refresh this value, call ReloadSystemMetrics.
ID2D1Factory::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
            );

Requirements

   
Minimum supported client Windows 7, Windows Vista with SP2 and Platform Update for Windows Vista [desktop apps | UWP apps]
Minimum supported server Windows Server 2008 R2, Windows Server 2008 with SP2 and Platform Update for Windows Server 2008 [desktop apps | UWP apps]
Target Platform Windows
Header d2d1.h

See Also

Direct2D Overview

Direct2D QuickStart

Getting Started with Direct2D

IUnknown

Multithreaded Direct2D Apps

Resources Overview