crypt32: Make helper for copying CMSG_CMS_SIGNER_INFO attributes more generic.
[wine.git] / dlls / d2d1 / state_block.c
blob501d94ae3ee060caec7baf4df6bfa9dc7d6a6031
1 /*
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
19 #include "d2d1_private.h"
21 WINE_DEFAULT_DEBUG_CHANNEL(d2d);
23 static inline struct d2d_state_block *impl_from_ID2D1DrawingStateBlock1(ID2D1DrawingStateBlock1 *iface)
25 return CONTAINING_RECORD(iface, struct d2d_state_block, ID2D1DrawingStateBlock1_iface);
28 static HRESULT STDMETHODCALLTYPE d2d_state_block_QueryInterface(ID2D1DrawingStateBlock1 *iface, REFIID iid, void **out)
30 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
32 if (IsEqualGUID(iid, &IID_ID2D1DrawingStateBlock1)
33 || IsEqualGUID(iid, &IID_ID2D1DrawingStateBlock)
34 || IsEqualGUID(iid, &IID_ID2D1Resource)
35 || IsEqualGUID(iid, &IID_IUnknown))
37 ID2D1DrawingStateBlock1_AddRef(iface);
38 *out = iface;
39 return S_OK;
42 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
44 *out = NULL;
45 return E_NOINTERFACE;
48 static ULONG STDMETHODCALLTYPE d2d_state_block_AddRef(ID2D1DrawingStateBlock1 *iface)
50 struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
51 ULONG refcount = InterlockedIncrement(&state_block->refcount);
53 TRACE("%p increasing refcount to %u.\n", iface, refcount);
55 return refcount;
58 static ULONG STDMETHODCALLTYPE d2d_state_block_Release(ID2D1DrawingStateBlock1 *iface)
60 struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
61 ULONG refcount = InterlockedDecrement(&state_block->refcount);
63 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
65 if (!refcount)
67 if (state_block->text_rendering_params)
68 IDWriteRenderingParams_Release(state_block->text_rendering_params);
69 ID2D1Factory_Release(state_block->factory);
70 heap_free(state_block);
73 return refcount;
76 static void STDMETHODCALLTYPE d2d_state_block_GetFactory(ID2D1DrawingStateBlock1 *iface, ID2D1Factory **factory)
78 struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
80 TRACE("iface %p, factory %p.\n", iface, factory);
82 ID2D1Factory_AddRef(*factory = state_block->factory);
85 static void STDMETHODCALLTYPE d2d_state_block_GetDescription(ID2D1DrawingStateBlock1 *iface,
86 D2D1_DRAWING_STATE_DESCRIPTION *desc)
88 struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
90 TRACE("iface %p, desc %p.\n", iface, desc);
92 memcpy(desc, &state_block->drawing_state, sizeof(*desc));
95 static void STDMETHODCALLTYPE d2d_state_block_SetDescription(ID2D1DrawingStateBlock1 *iface,
96 const D2D1_DRAWING_STATE_DESCRIPTION *desc)
98 struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
100 TRACE("iface %p, desc %p.\n", iface, desc);
102 memcpy(&state_block->drawing_state, desc, sizeof(*desc));
105 static void STDMETHODCALLTYPE d2d_state_block_SetTextRenderingParams(ID2D1DrawingStateBlock1 *iface,
106 IDWriteRenderingParams *text_rendering_params)
108 struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
110 TRACE("iface %p, text_rendering_params %p.\n", iface, text_rendering_params);
112 if (text_rendering_params)
113 IDWriteRenderingParams_AddRef(text_rendering_params);
114 if (state_block->text_rendering_params)
115 IDWriteRenderingParams_Release(state_block->text_rendering_params);
116 state_block->text_rendering_params = text_rendering_params;
119 static void STDMETHODCALLTYPE d2d_state_block_GetTextRenderingParams(ID2D1DrawingStateBlock1 *iface,
120 IDWriteRenderingParams **text_rendering_params)
122 struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
124 TRACE("iface %p, text_rendering_params %p.\n", iface, text_rendering_params);
126 if ((*text_rendering_params = state_block->text_rendering_params))
127 IDWriteRenderingParams_AddRef(*text_rendering_params);
130 static void STDMETHODCALLTYPE d2d_state_block_GetDescription1(ID2D1DrawingStateBlock1 *iface,
131 D2D1_DRAWING_STATE_DESCRIPTION1 *desc)
133 struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
135 TRACE("iface %p, desc %p.\n", iface, desc);
137 *desc = state_block->drawing_state;
140 static void STDMETHODCALLTYPE d2d_state_block_SetDescription1(ID2D1DrawingStateBlock1 *iface,
141 const D2D1_DRAWING_STATE_DESCRIPTION1 *desc)
143 struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock1(iface);
145 TRACE("iface %p, desc %p.\n", iface, desc);
147 state_block->drawing_state = *desc;
150 static const struct ID2D1DrawingStateBlock1Vtbl d2d_state_block_vtbl =
152 d2d_state_block_QueryInterface,
153 d2d_state_block_AddRef,
154 d2d_state_block_Release,
155 d2d_state_block_GetFactory,
156 d2d_state_block_GetDescription,
157 d2d_state_block_SetDescription,
158 d2d_state_block_SetTextRenderingParams,
159 d2d_state_block_GetTextRenderingParams,
160 d2d_state_block_GetDescription1,
161 d2d_state_block_SetDescription1,
164 void d2d_state_block_init(struct d2d_state_block *state_block, ID2D1Factory *factory,
165 const D2D1_DRAWING_STATE_DESCRIPTION1 *desc, IDWriteRenderingParams *text_rendering_params)
167 static const D2D1_MATRIX_3X2_F identity =
169 1.0f, 0.0f,
170 0.0f, 1.0f,
171 0.0f, 0.0f,
172 }}};
174 state_block->ID2D1DrawingStateBlock1_iface.lpVtbl = &d2d_state_block_vtbl;
175 state_block->refcount = 1;
176 ID2D1Factory_AddRef(state_block->factory = factory);
177 if (desc)
178 state_block->drawing_state = *desc;
179 else
180 state_block->drawing_state.transform = identity;
181 if ((state_block->text_rendering_params = text_rendering_params))
182 IDWriteRenderingParams_AddRef(state_block->text_rendering_params);
185 struct d2d_state_block *unsafe_impl_from_ID2D1DrawingStateBlock(ID2D1DrawingStateBlock *iface)
187 if (!iface)
188 return NULL;
189 assert(iface->lpVtbl == (ID2D1DrawingStateBlockVtbl *)&d2d_state_block_vtbl);
190 return CONTAINING_RECORD(iface, struct d2d_state_block, ID2D1DrawingStateBlock1_iface);