1 /* WinRT Windows.Gaming.Input implementation
3 * Copyright 2022 RĂ©mi Bernon for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 WINE_DEFAULT_DEBUG_CHANNEL(input
);
27 IRampForceEffect IRampForceEffect_iface
;
28 IWineForceFeedbackEffectImpl
*IWineForceFeedbackEffectImpl_inner
;
32 static inline struct ramp_effect
*impl_from_IRampForceEffect( IRampForceEffect
*iface
)
34 return CONTAINING_RECORD( iface
, struct ramp_effect
, IRampForceEffect_iface
);
37 static HRESULT WINAPI
effect_QueryInterface( IRampForceEffect
*iface
, REFIID iid
, void **out
)
39 struct ramp_effect
*impl
= impl_from_IRampForceEffect( iface
);
41 TRACE( "iface %p, iid %s, out %p.\n", iface
, debugstr_guid( iid
), out
);
43 if (IsEqualGUID( iid
, &IID_IUnknown
) ||
44 IsEqualGUID( iid
, &IID_IInspectable
) ||
45 IsEqualGUID( iid
, &IID_IAgileObject
) ||
46 IsEqualGUID( iid
, &IID_IRampForceEffect
))
48 IInspectable_AddRef( (*out
= &impl
->IRampForceEffect_iface
) );
52 return IWineForceFeedbackEffectImpl_QueryInterface( impl
->IWineForceFeedbackEffectImpl_inner
, iid
, out
);
55 static ULONG WINAPI
effect_AddRef( IRampForceEffect
*iface
)
57 struct ramp_effect
*impl
= impl_from_IRampForceEffect( iface
);
58 ULONG ref
= InterlockedIncrement( &impl
->ref
);
59 TRACE( "iface %p increasing refcount to %lu.\n", iface
, ref
);
63 static ULONG WINAPI
effect_Release( IRampForceEffect
*iface
)
65 struct ramp_effect
*impl
= impl_from_IRampForceEffect( iface
);
66 ULONG ref
= InterlockedDecrement( &impl
->ref
);
68 TRACE( "iface %p decreasing refcount to %lu.\n", iface
, ref
);
72 /* guard against re-entry if inner releases an outer iface */
73 InterlockedIncrement( &impl
->ref
);
74 IWineForceFeedbackEffectImpl_Release( impl
->IWineForceFeedbackEffectImpl_inner
);
81 static HRESULT WINAPI
effect_GetIids( IRampForceEffect
*iface
, ULONG
*iid_count
, IID
**iids
)
83 FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface
, iid_count
, iids
);
87 static HRESULT WINAPI
effect_GetRuntimeClassName( IRampForceEffect
*iface
, HSTRING
*class_name
)
89 return WindowsCreateString( RuntimeClass_Windows_Gaming_Input_ForceFeedback_RampForceEffect
,
90 ARRAY_SIZE(RuntimeClass_Windows_Gaming_Input_ForceFeedback_RampForceEffect
),
94 static HRESULT WINAPI
effect_GetTrustLevel( IRampForceEffect
*iface
, TrustLevel
*trust_level
)
96 FIXME( "iface %p, trust_level %p stub!\n", iface
, trust_level
);
100 static HRESULT WINAPI
effect_SetParameters( IRampForceEffect
*iface
, Vector3 start_vector
, Vector3 end_vector
, TimeSpan duration
)
102 WineForceFeedbackEffectParameters params
=
106 .type
= WineForceFeedbackEffectType_Ramp
,
107 .start_vector
= start_vector
,
108 .end_vector
= end_vector
,
109 .duration
= duration
,
114 struct ramp_effect
*impl
= impl_from_IRampForceEffect( iface
);
116 TRACE( "iface %p, start_vector %s, end_vector %s, duration %I64u.\n", iface
,
117 debugstr_vector3( &start_vector
), debugstr_vector3( &end_vector
), duration
.Duration
);
119 return IWineForceFeedbackEffectImpl_put_Parameters( impl
->IWineForceFeedbackEffectImpl_inner
, params
, NULL
);
122 static HRESULT WINAPI
effect_SetParametersWithEnvelope( IRampForceEffect
*iface
, Vector3 start_vector
, Vector3 end_vector
, FLOAT attack_gain
,
123 FLOAT sustain_gain
, FLOAT release_gain
, TimeSpan start_delay
,
124 TimeSpan attack_duration
, TimeSpan sustain_duration
,
125 TimeSpan release_duration
, UINT32 repeat_count
)
127 WineForceFeedbackEffectParameters params
=
131 .type
= WineForceFeedbackEffectType_Ramp
,
132 .start_vector
= start_vector
,
133 .end_vector
= end_vector
,
134 .duration
= {attack_duration
.Duration
+ sustain_duration
.Duration
+ release_duration
.Duration
},
135 .start_delay
= start_delay
,
136 .repeat_count
= repeat_count
,
137 .gain
= sustain_gain
,
140 WineForceFeedbackEffectEnvelope envelope
=
142 .attack_gain
= attack_gain
,
143 .release_gain
= release_gain
,
144 .attack_duration
= attack_duration
,
145 .release_duration
= release_duration
,
147 struct ramp_effect
*impl
= impl_from_IRampForceEffect( iface
);
149 TRACE( "iface %p, start_vector %s, end_vector %s, attack_gain %f, sustain_gain %f, release_gain %f, start_delay %I64u, attack_duration %I64u, "
150 "sustain_duration %I64u, release_duration %I64u, repeat_count %u.\n", iface
, debugstr_vector3( &start_vector
), debugstr_vector3( &end_vector
),
151 attack_gain
, sustain_gain
, release_gain
, start_delay
.Duration
, attack_duration
.Duration
, sustain_duration
.Duration
,
152 release_duration
.Duration
, repeat_count
);
154 return IWineForceFeedbackEffectImpl_put_Parameters( impl
->IWineForceFeedbackEffectImpl_inner
, params
, &envelope
);
157 static const struct IRampForceEffectVtbl effect_vtbl
=
159 effect_QueryInterface
,
162 /* IInspectable methods */
164 effect_GetRuntimeClassName
,
165 effect_GetTrustLevel
,
166 /* IRampForceEffect methods */
167 effect_SetParameters
,
168 effect_SetParametersWithEnvelope
,
173 IActivationFactory IActivationFactory_iface
;
177 static inline struct ramp_factory
*impl_from_IActivationFactory( IActivationFactory
*iface
)
179 return CONTAINING_RECORD( iface
, struct ramp_factory
, IActivationFactory_iface
);
182 static HRESULT WINAPI
activation_QueryInterface( IActivationFactory
*iface
, REFIID iid
, void **out
)
184 struct ramp_factory
*impl
= impl_from_IActivationFactory( iface
);
186 TRACE( "iface %p, iid %s, out %p.\n", iface
, debugstr_guid( iid
), out
);
188 if (IsEqualGUID( iid
, &IID_IUnknown
) ||
189 IsEqualGUID( iid
, &IID_IInspectable
) ||
190 IsEqualGUID( iid
, &IID_IAgileObject
) ||
191 IsEqualGUID( iid
, &IID_IActivationFactory
))
193 IInspectable_AddRef( (*out
= &impl
->IActivationFactory_iface
) );
197 FIXME( "%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid( iid
) );
199 return E_NOINTERFACE
;
202 static ULONG WINAPI
activation_AddRef( IActivationFactory
*iface
)
204 struct ramp_factory
*impl
= impl_from_IActivationFactory( iface
);
205 ULONG ref
= InterlockedIncrement( &impl
->ref
);
206 TRACE( "iface %p increasing refcount to %lu.\n", iface
, ref
);
210 static ULONG WINAPI
activation_Release( IActivationFactory
*iface
)
212 struct ramp_factory
*impl
= impl_from_IActivationFactory( iface
);
213 ULONG ref
= InterlockedDecrement( &impl
->ref
);
214 TRACE( "iface %p decreasing refcount to %lu.\n", iface
, ref
);
218 static HRESULT WINAPI
activation_GetIids( IActivationFactory
*iface
, ULONG
*iid_count
, IID
**iids
)
220 FIXME( "iface %p, iid_count %p, iids %p stub!\n", iface
, iid_count
, iids
);
224 static HRESULT WINAPI
activation_GetRuntimeClassName( IActivationFactory
*iface
, HSTRING
*class_name
)
226 FIXME( "iface %p, class_name %p stub!\n", iface
, class_name
);
230 static HRESULT WINAPI
activation_GetTrustLevel( IActivationFactory
*iface
, TrustLevel
*trust_level
)
232 FIXME( "iface %p, trust_level %p stub!\n", iface
, trust_level
);
236 static HRESULT WINAPI
activation_ActivateInstance( IActivationFactory
*iface
, IInspectable
**instance
)
238 struct ramp_effect
*impl
;
241 TRACE( "iface %p, instance %p.\n", iface
, instance
);
243 if (!(impl
= calloc( 1, sizeof(struct ramp_effect
) ))) return E_OUTOFMEMORY
;
244 impl
->IRampForceEffect_iface
.lpVtbl
= &effect_vtbl
;
247 if (FAILED(hr
= force_feedback_effect_create( WineForceFeedbackEffectType_Ramp
, (IInspectable
*)&impl
->IRampForceEffect_iface
,
248 &impl
->IWineForceFeedbackEffectImpl_inner
)))
254 *instance
= (IInspectable
*)&impl
->IRampForceEffect_iface
;
255 TRACE( "created RampForceEffect %p\n", *instance
);
259 static const struct IActivationFactoryVtbl activation_vtbl
=
261 activation_QueryInterface
,
264 /* IInspectable methods */
266 activation_GetRuntimeClassName
,
267 activation_GetTrustLevel
,
268 /* IActivationFactory methods */
269 activation_ActivateInstance
,
272 static struct ramp_factory ramp_statics
=
278 IInspectable
*ramp_effect_factory
= (IInspectable
*)&ramp_statics
.IActivationFactory_iface
;