2 * Copyright 2015 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/port.h"
22 #include "d2d1_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d2d
);
26 static inline struct d2d_state_block
*impl_from_ID2D1DrawingStateBlock1(ID2D1DrawingStateBlock1
*iface
)
28 return CONTAINING_RECORD(iface
, struct d2d_state_block
, ID2D1DrawingStateBlock1_iface
);
31 static HRESULT STDMETHODCALLTYPE
d2d_state_block_QueryInterface(ID2D1DrawingStateBlock1
*iface
, REFIID iid
, void **out
)
33 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
35 if (IsEqualGUID(iid
, &IID_ID2D1DrawingStateBlock1
)
36 || IsEqualGUID(iid
, &IID_ID2D1DrawingStateBlock
)
37 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
38 || IsEqualGUID(iid
, &IID_IUnknown
))
40 ID2D1DrawingStateBlock1_AddRef(iface
);
45 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
51 static ULONG STDMETHODCALLTYPE
d2d_state_block_AddRef(ID2D1DrawingStateBlock1
*iface
)
53 struct d2d_state_block
*state_block
= impl_from_ID2D1DrawingStateBlock1(iface
);
54 ULONG refcount
= InterlockedIncrement(&state_block
->refcount
);
56 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
61 static ULONG STDMETHODCALLTYPE
d2d_state_block_Release(ID2D1DrawingStateBlock1
*iface
)
63 struct d2d_state_block
*state_block
= impl_from_ID2D1DrawingStateBlock1(iface
);
64 ULONG refcount
= InterlockedDecrement(&state_block
->refcount
);
66 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
70 if (state_block
->text_rendering_params
)
71 IDWriteRenderingParams_Release(state_block
->text_rendering_params
);
72 ID2D1Factory_Release(state_block
->factory
);
73 heap_free(state_block
);
79 static void STDMETHODCALLTYPE
d2d_state_block_GetFactory(ID2D1DrawingStateBlock1
*iface
, ID2D1Factory
**factory
)
81 struct d2d_state_block
*state_block
= impl_from_ID2D1DrawingStateBlock1(iface
);
83 TRACE("iface %p, factory %p.\n", iface
, factory
);
85 ID2D1Factory_AddRef(*factory
= state_block
->factory
);
88 static void STDMETHODCALLTYPE
d2d_state_block_GetDescription(ID2D1DrawingStateBlock1
*iface
,
89 D2D1_DRAWING_STATE_DESCRIPTION
*desc
)
91 struct d2d_state_block
*state_block
= impl_from_ID2D1DrawingStateBlock1(iface
);
93 TRACE("iface %p, desc %p.\n", iface
, desc
);
95 memcpy(desc
, &state_block
->drawing_state
, sizeof(*desc
));
98 static void STDMETHODCALLTYPE
d2d_state_block_SetDescription(ID2D1DrawingStateBlock1
*iface
,
99 const D2D1_DRAWING_STATE_DESCRIPTION
*desc
)
101 struct d2d_state_block
*state_block
= impl_from_ID2D1DrawingStateBlock1(iface
);
103 TRACE("iface %p, desc %p.\n", iface
, desc
);
105 memcpy(&state_block
->drawing_state
, desc
, sizeof(*desc
));
108 static void STDMETHODCALLTYPE
d2d_state_block_SetTextRenderingParams(ID2D1DrawingStateBlock1
*iface
,
109 IDWriteRenderingParams
*text_rendering_params
)
111 struct d2d_state_block
*state_block
= impl_from_ID2D1DrawingStateBlock1(iface
);
113 TRACE("iface %p, text_rendering_params %p.\n", iface
, text_rendering_params
);
115 if (text_rendering_params
)
116 IDWriteRenderingParams_AddRef(text_rendering_params
);
117 if (state_block
->text_rendering_params
)
118 IDWriteRenderingParams_Release(state_block
->text_rendering_params
);
119 state_block
->text_rendering_params
= text_rendering_params
;
122 static void STDMETHODCALLTYPE
d2d_state_block_GetTextRenderingParams(ID2D1DrawingStateBlock1
*iface
,
123 IDWriteRenderingParams
**text_rendering_params
)
125 struct d2d_state_block
*state_block
= impl_from_ID2D1DrawingStateBlock1(iface
);
127 TRACE("iface %p, text_rendering_params %p.\n", iface
, text_rendering_params
);
129 if ((*text_rendering_params
= state_block
->text_rendering_params
))
130 IDWriteRenderingParams_AddRef(*text_rendering_params
);
133 static void STDMETHODCALLTYPE
d2d_state_block_GetDescription1(ID2D1DrawingStateBlock1
*iface
,
134 D2D1_DRAWING_STATE_DESCRIPTION1
*desc
)
136 struct d2d_state_block
*state_block
= impl_from_ID2D1DrawingStateBlock1(iface
);
138 TRACE("iface %p, desc %p.\n", iface
, desc
);
140 *desc
= state_block
->drawing_state
;
143 static void STDMETHODCALLTYPE
d2d_state_block_SetDescription1(ID2D1DrawingStateBlock1
*iface
,
144 const D2D1_DRAWING_STATE_DESCRIPTION1
*desc
)
146 struct d2d_state_block
*state_block
= impl_from_ID2D1DrawingStateBlock1(iface
);
148 TRACE("iface %p, desc %p.\n", iface
, desc
);
150 state_block
->drawing_state
= *desc
;
153 static const struct ID2D1DrawingStateBlock1Vtbl d2d_state_block_vtbl
=
155 d2d_state_block_QueryInterface
,
156 d2d_state_block_AddRef
,
157 d2d_state_block_Release
,
158 d2d_state_block_GetFactory
,
159 d2d_state_block_GetDescription
,
160 d2d_state_block_SetDescription
,
161 d2d_state_block_SetTextRenderingParams
,
162 d2d_state_block_GetTextRenderingParams
,
163 d2d_state_block_GetDescription1
,
164 d2d_state_block_SetDescription1
,
167 void d2d_state_block_init(struct d2d_state_block
*state_block
, ID2D1Factory
*factory
,
168 const D2D1_DRAWING_STATE_DESCRIPTION1
*desc
, IDWriteRenderingParams
*text_rendering_params
)
170 static const D2D1_MATRIX_3X2_F identity
=
177 state_block
->ID2D1DrawingStateBlock1_iface
.lpVtbl
= &d2d_state_block_vtbl
;
178 state_block
->refcount
= 1;
179 ID2D1Factory_AddRef(state_block
->factory
= factory
);
181 state_block
->drawing_state
= *desc
;
183 state_block
->drawing_state
.transform
= identity
;
184 if ((state_block
->text_rendering_params
= text_rendering_params
))
185 IDWriteRenderingParams_AddRef(state_block
->text_rendering_params
);
188 struct d2d_state_block
*unsafe_impl_from_ID2D1DrawingStateBlock(ID2D1DrawingStateBlock
*iface
)
192 assert(iface
->lpVtbl
== (ID2D1DrawingStateBlockVtbl
*)&d2d_state_block_vtbl
);
193 return CONTAINING_RECORD(iface
, struct d2d_state_block
, ID2D1DrawingStateBlock1_iface
);