/*=========================================================================*\
Copyright (c) Microsoft Corporation. All rights reserved.
File: D2D1_1Helper.h
Module Name: D2D
Description: Helper files over the D2D interfaces and APIs.
\*=========================================================================*/
#pragma once
#ifndef _D2D1_1HELPER_H_
#define _D2D1_1HELPER_H_
#ifndef _D2D1_1_H_
#include <d2d1_1.h>
#endif // #ifndef _D2D1_H_
#ifndef D2D_USE_C_DEFINITIONS
#include <winapifamily.h>
#pragma region Application Family
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP)
namespace
{
template
<>
struct
<
>
{
typedef
;
typedef
;
};
template
<>
struct
<
>
{
typedef
;
typedef
;
};
class
:
public
{
public
:
inline
(
,
,
,
,
,
,
,
,
,
,
,
)
{
=
;
=
;
=
;
=
;
=
;
=
;
=
;
=
;
=
;
=
;
=
;
=
;
}
inline
()
{
=
1
;
=
0
;
=
0
;
=
0
;
=
1
;
=
0
;
=
0
;
=
0
;
=
1
;
=
0
;
=
0
;
=
0
;
}
};
class
:
public
{
public
:
inline
(
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
)
{
=
;
=
;
=
;
=
;
=
;
=
;
=
;
=
;
=
;
=
;
=
;
=
;
=
;
=
;
=
;
=
;
}
inline
()
{
=
1
;
=
0
;
=
0
;
=
0
;
=
0
;
=
1
;
=
0
;
=
0
;
=
0
;
=
0
;
=
1
;
=
0
;
=
0
;
=
0
;
=
0
;
=
1
;
}
inline
bool
(
const
&
)
const
{
return
==
.
&&
==
.
&&
==
.
&&
==
.
&&
==
.
&&
==
.
&&
==
.
&&
==
.
&&
==
.
&&
==
.
&&
==
.
&&
==
.
&&
==
.
&&
==
.
&&
==
.
&&
==
.
;
}
inline
bool
(
const
&
)
const
{
return
!(*
this
);
}
static
inline
(
,
,
)
{
;
translation
.
=
1.0
;
translation
.
=
0.0
;
translation
.
=
0.0
;
translation
.
=
0.0
;
translation
.
=
0.0
;
translation
.
=
1.0
;
translation
.
=
0.0
;
translation
.
=
0.0
;
translation
.
=
0.0
;
translation
.
=
0.0
;
translation
.
=
1.0
;
translation
.
=
0.0
;
translation
.
=
;
translation
.
=
;
translation
.
=
;
translation
.
=
1.0
;
return
translation
;
}
static
inline
(
,
,
)
{
;
scale
.
=
;
scale
.
=
0.0
;
scale
.
=
0.0
;
scale
.
=
0.0
;
scale
.
=
0.0
;
scale
.
=
;
scale
.
=
0.0
;
scale
.
=
0.0
;
scale
.
=
0.0
;
scale
.
=
0.0
;
scale
.
=
;
scale
.
=
0.0
;
scale
.
=
0.0
;
scale
.
=
0.0
;
scale
.
=
0.0
;
scale
.
=
1.0
;
return
scale
;
}
static
inline
(
)
{
=
* (
3.141592654f
/
180.0f
);
=
0.0
;
=
0.0
;
(
angleInRadian
, &
sinAngle
, &
cosAngle
);
(
1
,
0
,
0
,
0
,
0
,
cosAngle
,
sinAngle
,
0
,
0
, -
sinAngle
,
cosAngle
,
0
,
0
,
0
,
0
,
1
);
return
rotationX
;
}
static
inline
(
)
{
=
* (
3.141592654f
/
180.0f
);
=
0.0
;
=
0.0
;
(
angleInRadian
, &
sinAngle
, &
cosAngle
);
(
cosAngle
,
0
, -
sinAngle
,
0
,
0
,
1
,
0
,
0
,
sinAngle
,
0
,
cosAngle
,
0
,
0
,
0
,
0
,
1
);
return
rotationY
;
}
static
inline
(
)
{
=
* (
3.141592654f
/
180.0f
);
=
0.0
;
=
0.0
;
(
angleInRadian
, &
sinAngle
, &
cosAngle
);
(
cosAngle
,
sinAngle
,
0
,
0
,
-
sinAngle
,
cosAngle
,
0
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
1
);
return
rotationZ
;
}
static
inline
(
,
,
,
)
{
=
(
,
,
);
/=
magnitude
;
/=
magnitude
;
/=
magnitude
;
=
* (
3.141592654f
/
180.0f
);
=
0.0
;
=
0.0
;
(
angleInRadian
, &
sinAngle
, &
cosAngle
);
=
1
-
cosAngle
;
(
1
+
oneMinusCosAngle
* (
*
-
1
),
*
sinAngle
+
oneMinusCosAngle
*
*
,
-
*
sinAngle
+
oneMinusCosAngle
*
*
,
0
,
-
*
sinAngle
+
oneMinusCosAngle
*
*
,
1
+
oneMinusCosAngle
* (
*
-
1
),
*
sinAngle
+
oneMinusCosAngle
*
*
,
0
,
*
sinAngle
+
oneMinusCosAngle
*
*
,
-
*
sinAngle
+
oneMinusCosAngle
*
*
,
1
+
oneMinusCosAngle
* (
*
-
1
) ,
0
,
0
,
0
,
0
,
1
);
return
rotationArb
;
}
static
inline
(
)
{
=
* (
3.141592654f
/
180.0f
);
=
(
angleInRadian
);
(
1
,
0
,
0
,
0
,
tanAngle
,
1
,
0
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
1
);
return
skewX
;
}
static
inline
(
)
{
=
* (
3.141592654f
/
180.0f
);
=
(
angleInRadian
);
(
1
,
tanAngle
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
1
);
return
skewY
;
}
static
inline
(
)
{
float
=
0
;
if
(
>
0
)
{
proj
= -
1
/
;
}
(
1
,
0
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
1
,
proj
,
0
,
0
,
0
,
1
);
return
projection
;
}
static
inline
const
*
(
const
*
)
{
return
static_cast
<
const
*>(
);
}
static
inline
*
(
*
)
{
return
static_cast
<
*>(
);
}
inline
()
const
{
=
* (
* (
*
-
*
) -
* (
*
-
*
) +
* (
*
-
*
));
=
* (
* (
*
-
*
) -
* (
*
-
*
) +
* (
*
-
*
));
=
* (
* (
*
-
*
) -
* (
*
-
*
) +
* (
*
-
*
));
=
* (
* (
*
-
*
) -
* (
*
-
*
) +
* (
*
-
*
));
return
minor1
-
minor2
+
minor3
-
minor4
;
}
inline
bool
()
const
{
return
==
1.f
&&
==
0.f
&&
==
0.f
&&
==
0.f
&&
==
0.f
&&
==
1.f
&&
==
0.f
&&
==
0.f
&&
==
0.f
&&
==
0.f
&&
==
1.f
&&
==
0.f
&&
==
0.f
&&
==
0.f
&&
==
0.f
&&
==
1.f
;
}
inline
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MATRIX_3X2_F &transform = D2D1::IdentityMatrix(),
=
D2D1_PRIMITIVE_BLEND_SOURCE_OVER
,
=
)
{
D2D1_DRAWING_STATE_DESCRIPTION1
;
drawingStateDescription1
.
=
;
drawingStateDescription1
.
=
;
drawingStateDescription1
.
=
;
drawingStateDescription1
.
=
;
drawingStateDescription1
.
;
drawingStateDescription1
.
=
;
drawingStateDescription1
.
=
;
return
drawingStateDescription1
;
}
D2D1_DRAWING_STATE_DESCRIPTION1
(
_In_ const D2D1_DRAWING_STATE_DESCRIPTION &desc,
const
D2D1_DRAWING_STATE_DESCRIPTION
&
,
=
D2D1_PRIMITIVE_BLEND_SOURCE_OVER
,
=
)
{
D2D1_DRAWING_STATE_DESCRIPTION1
;
drawingStateDescription1
.
=
.
;
drawingStateDescription1
.
=
.
;
drawingStateDescription1
.
=
.
;
drawingStateDescription1
.
=
.
;
drawingStateDescription1
.
.
;
drawingStateDescription1
.
=
;
drawingStateDescription1
.
=
;
return
drawingStateDescription1
;
}
(
=
,
_In_ CONST D2D1_PIXEL_FORMAT pixelFormat = D2D1::PixelFormat(),
=
96.0f
,
=
96.0f
,
_In_opt_ ID2D1ColorContext *colorContext = NULL
)
{
=
{
,
,
,
,
};
return
bitmapProperties
;
}
(
_In_ CONST D2D1_RECT_F &contentBounds = D2D1::InfiniteRect(),
_In_opt_ ID2D1Geometry *geometricMask = NULL,
=
D2D1_ANTIALIAS_MODE_PER_PRIMITIVE
,
=
D2D1
::
(),
=
1.0
,
_In_opt_ ID2D1Brush *opacityBrush = NULL,
=
)
{
= {
0
};
layerParameters
.
;
layerParameters
.
=
;
layerParameters
.
=
;
layerParameters
.
;
layerParameters
.
=
;
layerParameters
.
=
;
layerParameters
.
=
;
return
layerParameters
;
}
D2D1_STROKE_STYLE_PROPERTIES1
(
=
,
=
,
=
,
=
,
=
10.0f
,
=
,
=
0.0f
,
D2D1_STROKE_TRANSFORM_TYPE
=
D2D1_STROKE_TRANSFORM_TYPE_NORMAL
)
{
D2D1_STROKE_STYLE_PROPERTIES1
;
strokeStyleProperties
.
=
;
strokeStyleProperties
.
=
;
strokeStyleProperties
.
=
;
strokeStyleProperties
.
=
;
strokeStyleProperties
.
=
;
strokeStyleProperties
.
=
;
strokeStyleProperties
.
=
;
strokeStyleProperties
.
=
;
return
strokeStyleProperties
;
}
D2D1_IMAGE_BRUSH_PROPERTIES
(
,
=
,
=
,
=
D2D1_INTERPOLATION_MODE_LINEAR
)
{
D2D1_IMAGE_BRUSH_PROPERTIES
;
imageBrushProperties
.
=
;
imageBrushProperties
.
=
;
imageBrushProperties
.
=
;
imageBrushProperties
.
;
return
imageBrushProperties
;
}
D2D1_BITMAP_BRUSH_PROPERTIES1
(
=
,
=
,
=
D2D1_INTERPOLATION_MODE_LINEAR
)
{
D2D1_BITMAP_BRUSH_PROPERTIES1
;
bitmapBrush1Properties
.
=
;
bitmapBrush1Properties
.
=
;
bitmapBrush1Properties
.
=
;
return
bitmapBrush1Properties
;
}
D2D1_PRINT_CONTROL_PROPERTIES
(
D2D1_PRINT_FONT_SUBSET_MODE
=
D2D1_PRINT_FONT_SUBSET_MODE_DEFAULT
,
=
150.0f
,
=
)
{
D2D1_PRINT_CONTROL_PROPERTIES
;
printControlProps
.
=
;
printControlProps
.
=
;
printControlProps
.
=
;
return
printControlProps
;
}
(
,
)
{
;
renderingControls
.
=
;
renderingControls
.
;
return
renderingControls
;
}
D2D1_EFFECT_INPUT_DESCRIPTION
(
*
,
,
)
{
D2D1_EFFECT_INPUT_DESCRIPTION
;
description
.
=
;
description
.
=
;
description
.
;
return
description
;
}
(
,
,
D2D1_DEVICE_CONTEXT_OPTIONS
)
{
;
creationProperties
.
=
;
creationProperties
.
=
;
creationProperties
.
=
;
return
creationProperties
;
}
(
=
0.0f
,
=
0.0f
)
{
= {
,
};
return
vec2
;
}
(
=
0.0f
,
=
0.0f
,
=
0.0f
)
{
= {
,
,
};
return
vec3
;
}
(
=
0.0f
,
=
0.0f
,
=
0.0f
,
=
0.0f
)
{
= {
,
,
,
};
return
vec4
;
}
(
=
0
,
=
0
)
{
return
<
>(
,
);
}
(
=
0.f
,
=
0.f
,
=
0.f
,
=
0.f
)
{
return
<
>(
,
,
,
);
}
SetDpiCompensatedEffectInput
(
_In_ ID2D1DeviceContext *deviceContext,
_In_ ID2D1Effect *effect,
,
_In_opt_ ID2D1Bitmap *inputBitmap,
=
D2D1_INTERPOLATION_MODE_LINEAR
,
=
)
{
ID2D1Effect *dpiCompensationEffect = NULL;
if
(!
)
{
effect->SetInput(inputIndex, NULL);
return
hr
;
}
hr
=
->
(
CLSID_D2D1DpiCompensation
, &
dpiCompensationEffect
);
{
{
dpiCompensationEffect
->
(
0
,
);
;
->
(&
bitmapDpi
.
, &
bitmapDpi
.
);
hr
=
dpiCompensationEffect
->
(
D2D1_DPICOMPENSATION_PROP_INPUT_DPI
,
bitmapDpi
);
}
{
hr
=
dpiCompensationEffect
->
(
D2D1_DPICOMPENSATION_PROP_INTERPOLATION_MODE
,
);
}
{
hr
=
dpiCompensationEffect
->
(
D2D1_DPICOMPENSATION_PROP_BORDER_MODE
,
);
}
{
->
(
,
dpiCompensationEffect
);
}
if
(
dpiCompensationEffect
)
{
dpiCompensationEffect
->
();
}
}
return
hr
;
}
}
#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) */
#pragma endregion
#endif // #ifndef D2D_USE_C_DEFINITIONS
#endif // #ifndef _D2D1_HELPER_H_