makefiles: Fix the source path for ttf font installs.
[wine.git] / dlls / d2d1 / state_block.c
blob90195fe3b263f5ab5d5a6c5f3efb00b4b92a80c0
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 "config.h"
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_ID2D1DrawingStateBlock(ID2D1DrawingStateBlock *iface)
28 return CONTAINING_RECORD(iface, struct d2d_state_block, ID2D1DrawingStateBlock_iface);
31 static HRESULT STDMETHODCALLTYPE d2d_state_block_QueryInterface(ID2D1DrawingStateBlock *iface, REFIID iid, void **out)
33 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
35 if (IsEqualGUID(iid, &IID_ID2D1DrawingStateBlock)
36 || IsEqualGUID(iid, &IID_ID2D1Resource)
37 || IsEqualGUID(iid, &IID_IUnknown))
39 ID2D1DrawingStateBlock_AddRef(iface);
40 *out = iface;
41 return S_OK;
44 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
46 *out = NULL;
47 return E_NOINTERFACE;
50 static ULONG STDMETHODCALLTYPE d2d_state_block_AddRef(ID2D1DrawingStateBlock *iface)
52 struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock(iface);
53 ULONG refcount = InterlockedIncrement(&state_block->refcount);
55 TRACE("%p increasing refcount to %u.\n", iface, refcount);
57 return refcount;
60 static ULONG STDMETHODCALLTYPE d2d_state_block_Release(ID2D1DrawingStateBlock *iface)
62 struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock(iface);
63 ULONG refcount = InterlockedDecrement(&state_block->refcount);
65 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
67 if (!refcount)
69 if (state_block->text_rendering_params)
70 IDWriteRenderingParams_Release(state_block->text_rendering_params);
71 ID2D1Factory_Release(state_block->factory);
72 HeapFree(GetProcessHeap(), 0, state_block);
75 return refcount;
78 static void STDMETHODCALLTYPE d2d_state_block_GetFactory(ID2D1DrawingStateBlock *iface, ID2D1Factory **factory)
80 struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock(iface);
82 TRACE("iface %p, factory %p.\n", iface, factory);
84 ID2D1Factory_AddRef(*factory = state_block->factory);
87 static void STDMETHODCALLTYPE d2d_state_block_GetDescription(ID2D1DrawingStateBlock *iface,
88 D2D1_DRAWING_STATE_DESCRIPTION *desc)
90 struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock(iface);
92 TRACE("iface %p, desc %p.\n", iface, desc);
94 *desc = state_block->drawing_state;
97 static void STDMETHODCALLTYPE d2d_state_block_SetDescription(ID2D1DrawingStateBlock *iface,
98 const D2D1_DRAWING_STATE_DESCRIPTION *desc)
100 struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock(iface);
102 TRACE("iface %p, desc %p.\n", iface, desc);
104 state_block->drawing_state = *desc;
107 static void STDMETHODCALLTYPE d2d_state_block_SetTextRenderingParams(ID2D1DrawingStateBlock *iface,
108 IDWriteRenderingParams *text_rendering_params)
110 struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock(iface);
112 TRACE("iface %p, text_rendering_params %p.\n", iface, text_rendering_params);
114 if (text_rendering_params)
115 IDWriteRenderingParams_AddRef(text_rendering_params);
116 if (state_block->text_rendering_params)
117 IDWriteRenderingParams_Release(state_block->text_rendering_params);
118 state_block->text_rendering_params = text_rendering_params;
121 static void STDMETHODCALLTYPE d2d_state_block_GetTextRenderingParams(ID2D1DrawingStateBlock *iface,
122 IDWriteRenderingParams **text_rendering_params)
124 struct d2d_state_block *state_block = impl_from_ID2D1DrawingStateBlock(iface);
126 TRACE("iface %p, text_rendering_params %p.\n", iface, text_rendering_params);
128 if ((*text_rendering_params = state_block->text_rendering_params))
129 IDWriteRenderingParams_AddRef(*text_rendering_params);
132 static const struct ID2D1DrawingStateBlockVtbl d2d_state_block_vtbl =
134 d2d_state_block_QueryInterface,
135 d2d_state_block_AddRef,
136 d2d_state_block_Release,
137 d2d_state_block_GetFactory,
138 d2d_state_block_GetDescription,
139 d2d_state_block_SetDescription,
140 d2d_state_block_SetTextRenderingParams,
141 d2d_state_block_GetTextRenderingParams,
144 void d2d_state_block_init(struct d2d_state_block *state_block, ID2D1Factory *factory,
145 const D2D1_DRAWING_STATE_DESCRIPTION *desc, IDWriteRenderingParams *text_rendering_params)
147 static const D2D1_MATRIX_3X2_F identity =
149 1.0f, 0.0f,
150 0.0f, 1.0f,
151 0.0f, 0.0f,
154 state_block->ID2D1DrawingStateBlock_iface.lpVtbl = &d2d_state_block_vtbl;
155 state_block->refcount = 1;
156 ID2D1Factory_AddRef(state_block->factory = factory);
157 if (desc)
158 state_block->drawing_state = *desc;
159 else
160 state_block->drawing_state.transform = identity;
161 if ((state_block->text_rendering_params = text_rendering_params))
162 IDWriteRenderingParams_AddRef(state_block->text_rendering_params);
165 struct d2d_state_block *unsafe_impl_from_ID2D1DrawingStateBlock(ID2D1DrawingStateBlock *iface)
167 if (!iface)
168 return NULL;
169 assert(iface->lpVtbl == &d2d_state_block_vtbl);
170 return CONTAINING_RECORD(iface, struct d2d_state_block, ID2D1DrawingStateBlock_iface);