VirtualBox

source: vbox/trunk/src/VBox/Devices/Input/DrvMouseQueue.cpp@ 47143

Last change on this file since 47143 was 46932, checked in by vboxsync, 11 years ago

Devices/Input/UsbMouse: add multi-touch mode to pfnReportModes in PDM.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 11.9 KB
Line 
1/* $Id: DrvMouseQueue.cpp 46932 2013-07-03 13:02:28Z vboxsync $ */
2/** @file
3 * VBox input devices: Mouse queue driver
4 */
5
6/*
7 * Copyright (C) 2006-2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19/*******************************************************************************
20* Header Files *
21*******************************************************************************/
22#define LOG_GROUP LOG_GROUP_DRV_MOUSE_QUEUE
23#include <VBox/vmm/pdmdrv.h>
24#include <iprt/assert.h>
25#include <iprt/uuid.h>
26
27#include "VBoxDD.h"
28
29
30
31/*******************************************************************************
32* Structures and Typedefs *
33*******************************************************************************/
34/**
35 * Mouse queue driver instance data.
36 *
37 * @implements PDMIMOUSECONNECTOR
38 * @implements PDMIMOUSEPORT
39 */
40typedef struct DRVMOUSEQUEUE
41{
42 /** Pointer to the driver instance structure. */
43 PPDMDRVINS pDrvIns;
44 /** Pointer to the mouse port interface of the driver/device above us. */
45 PPDMIMOUSEPORT pUpPort;
46 /** Pointer to the mouse port interface of the driver/device below us. */
47 PPDMIMOUSECONNECTOR pDownConnector;
48 /** Our mouse connector interface. */
49 PDMIMOUSECONNECTOR IConnector;
50 /** Our mouse port interface. */
51 PDMIMOUSEPORT IPort;
52 /** The queue handle. */
53 PPDMQUEUE pQueue;
54 /** Discard input when this flag is set.
55 * We only accept input when the VM is running. */
56 bool fInactive;
57} DRVMOUSEQUEUE, *PDRVMOUSEQUEUE;
58
59
60/**
61 * Mouse queue item.
62 */
63typedef struct DRVMOUSEQUEUEITEM
64{
65 /** The core part owned by the queue manager. */
66 PDMQUEUEITEMCORE Core;
67 uint32_t fAbs;
68 int32_t iDeltaX;
69 int32_t iDeltaY;
70 int32_t iDeltaZ;
71 int32_t iDeltaW;
72 uint32_t fButtonStates;
73 uint32_t uX;
74 uint32_t uY;
75} DRVMOUSEQUEUEITEM, *PDRVMOUSEQUEUEITEM;
76
77
78
79/* -=-=-=-=- IBase -=-=-=-=- */
80
81/**
82 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
83 */
84static DECLCALLBACK(void *) drvMouseQueueQueryInterface(PPDMIBASE pInterface, const char *pszIID)
85{
86 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
87 PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
88 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
89 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUSEPORT, &pThis->IPort);
90 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUSECONNECTOR, &pThis->IConnector);
91 return NULL;
92}
93
94
95/* -=-=-=-=- IMousePort -=-=-=-=- */
96
97/** Converts a pointer to DRVMOUSEQUEUE::Port to a DRVMOUSEQUEUE pointer. */
98#define IMOUSEPORT_2_DRVMOUSEQUEUE(pInterface) ( (PDRVMOUSEQUEUE)((char *)(pInterface) - RT_OFFSETOF(DRVMOUSEQUEUE, IPort)) )
99
100
101/**
102 * @interface_method_impl{PDMIMOUSEPORT,pfnPutEvent}
103 */
104static DECLCALLBACK(int) drvMouseQueuePutEvent(PPDMIMOUSEPORT pInterface, int32_t iDeltaX, int32_t iDeltaY, int32_t iDeltaZ, int32_t iDeltaW, uint32_t fButtonStates)
105{
106 PDRVMOUSEQUEUE pDrv = IMOUSEPORT_2_DRVMOUSEQUEUE(pInterface);
107 if (pDrv->fInactive)
108 return VINF_SUCCESS;
109
110 PDRVMOUSEQUEUEITEM pItem = (PDRVMOUSEQUEUEITEM)PDMQueueAlloc(pDrv->pQueue);
111 if (pItem)
112 {
113 pItem->fAbs = 0;
114 pItem->iDeltaX = iDeltaX;
115 pItem->iDeltaY = iDeltaY;
116 pItem->iDeltaZ = iDeltaZ;
117 pItem->iDeltaW = iDeltaW;
118 pItem->fButtonStates = fButtonStates;
119 pItem->uX = 0;
120 pItem->uY = 0;
121 PDMQueueInsert(pDrv->pQueue, &pItem->Core);
122 return VINF_SUCCESS;
123 }
124 return VERR_PDM_NO_QUEUE_ITEMS;
125}
126
127/**
128 * @interface_method_impl{PDMIMOUSEPORT,pfnPutEventAbs}
129 */
130static DECLCALLBACK(int) drvMouseQueuePutEventAbs(PPDMIMOUSEPORT pInterface, uint32_t uX, uint32_t uY, int32_t iDeltaZ, int32_t iDeltaW, uint32_t fButtonStates)
131{
132 PDRVMOUSEQUEUE pDrv = IMOUSEPORT_2_DRVMOUSEQUEUE(pInterface);
133 if (pDrv->fInactive)
134 return VINF_SUCCESS;
135
136 PDRVMOUSEQUEUEITEM pItem = (PDRVMOUSEQUEUEITEM)PDMQueueAlloc(pDrv->pQueue);
137 if (pItem)
138 {
139 pItem->fAbs = 1;
140 pItem->iDeltaX = 0;
141 pItem->iDeltaY = 0;
142 pItem->iDeltaZ = iDeltaZ;
143 pItem->iDeltaW = iDeltaW;
144 pItem->fButtonStates = fButtonStates;
145 pItem->uX = uX;
146 pItem->uY = uY;
147 PDMQueueInsert(pDrv->pQueue, &pItem->Core);
148 return VINF_SUCCESS;
149 }
150 return VERR_PDM_NO_QUEUE_ITEMS;
151}
152
153
154/* -=-=-=-=- IConnector -=-=-=-=- */
155
156#define PPDMIMOUSECONNECTOR_2_DRVMOUSEQUEUE(pInterface) ( (PDRVMOUSEQUEUE)((char *)(pInterface) - RT_OFFSETOF(DRVMOUSEQUEUE, IConnector)) )
157
158
159/**
160 * Pass absolute mode status changes from the guest through to the frontend
161 * driver.
162 *
163 * @param pInterface Pointer to the mouse connector interface structure.
164 * @param fRel Is relative reporting supported?
165 * @param fAbs Is absolute reporting supported?
166 * @param fMT Is multi-touch reporting supported?
167 */
168static DECLCALLBACK(void) drvMousePassThruReportModes(PPDMIMOUSECONNECTOR pInterface, bool fRel, bool fAbs, bool fMT)
169{
170 PDRVMOUSEQUEUE pDrv = PPDMIMOUSECONNECTOR_2_DRVMOUSEQUEUE(pInterface);
171 pDrv->pDownConnector->pfnReportModes(pDrv->pDownConnector, fRel, fAbs, fMT);
172}
173
174
175
176/* -=-=-=-=- queue -=-=-=-=- */
177
178/**
179 * Queue callback for processing a queued item.
180 *
181 * @returns Success indicator.
182 * If false the item will not be removed and the flushing will stop.
183 * @param pDrvIns The driver instance.
184 * @param pItemCore Pointer to the queue item to process.
185 */
186static DECLCALLBACK(bool) drvMouseQueueConsumer(PPDMDRVINS pDrvIns, PPDMQUEUEITEMCORE pItemCore)
187{
188 PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
189 PDRVMOUSEQUEUEITEM pItem = (PDRVMOUSEQUEUEITEM)pItemCore;
190 int rc;
191 if (!pItem->fAbs)
192 rc = pThis->pUpPort->pfnPutEvent(pThis->pUpPort, pItem->iDeltaX, pItem->iDeltaY, pItem->iDeltaZ, pItem->iDeltaW, pItem->fButtonStates);
193 else
194 rc = pThis->pUpPort->pfnPutEventAbs(pThis->pUpPort, pItem->uX, pItem->uY, pItem->iDeltaZ, pItem->iDeltaW, pItem->fButtonStates);
195 return RT_SUCCESS(rc);
196}
197
198
199/* -=-=-=-=- driver interface -=-=-=-=- */
200
201/**
202 * Power On notification.
203 *
204 * @returns VBox status.
205 * @param pDrvIns The drive instance data.
206 */
207static DECLCALLBACK(void) drvMouseQueuePowerOn(PPDMDRVINS pDrvIns)
208{
209 PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
210 pThis->fInactive = false;
211}
212
213
214/**
215 * Reset notification.
216 *
217 * @returns VBox status.
218 * @param pDrvIns The drive instance data.
219 */
220static DECLCALLBACK(void) drvMouseQueueReset(PPDMDRVINS pDrvIns)
221{
222 //PDRVKBDQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVKBDQUEUE);
223 /** @todo purge the queue on reset. */
224}
225
226
227/**
228 * Suspend notification.
229 *
230 * @returns VBox status.
231 * @param pDrvIns The drive instance data.
232 */
233static DECLCALLBACK(void) drvMouseQueueSuspend(PPDMDRVINS pDrvIns)
234{
235 PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
236 pThis->fInactive = true;
237}
238
239
240/**
241 * Resume notification.
242 *
243 * @returns VBox status.
244 * @param pDrvIns The drive instance data.
245 */
246static DECLCALLBACK(void) drvMouseQueueResume(PPDMDRVINS pDrvIns)
247{
248 PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
249 pThis->fInactive = false;
250}
251
252
253/**
254 * Power Off notification.
255 *
256 * @param pDrvIns The drive instance data.
257 */
258static DECLCALLBACK(void) drvMouseQueuePowerOff(PPDMDRVINS pDrvIns)
259{
260 PDRVMOUSEQUEUE pThis = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
261 pThis->fInactive = true;
262}
263
264
265/**
266 * Construct a mouse driver instance.
267 *
268 * @copydoc FNPDMDRVCONSTRUCT
269 */
270static DECLCALLBACK(int) drvMouseQueueConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
271{
272 PDRVMOUSEQUEUE pDrv = PDMINS_2_DATA(pDrvIns, PDRVMOUSEQUEUE);
273 LogFlow(("drvMouseQueueConstruct: iInstance=%d\n", pDrvIns->iInstance));
274 PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
275
276 /*
277 * Validate configuration.
278 */
279 if (!CFGMR3AreValuesValid(pCfg, "QueueSize\0Interval\0"))
280 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
281
282 /*
283 * Init basic data members and interfaces.
284 */
285 pDrv->fInactive = true;
286 /* IBase. */
287 pDrvIns->IBase.pfnQueryInterface = drvMouseQueueQueryInterface;
288 /* IMouseConnector. */
289 pDrv->IConnector.pfnReportModes = drvMousePassThruReportModes;
290 /* IMousePort. */
291 pDrv->IPort.pfnPutEvent = drvMouseQueuePutEvent;
292 pDrv->IPort.pfnPutEventAbs = drvMouseQueuePutEventAbs;
293
294 /*
295 * Get the IMousePort interface of the above driver/device.
296 */
297 pDrv->pUpPort = PDMIBASE_QUERY_INTERFACE(pDrvIns->pUpBase, PDMIMOUSEPORT);
298 if (!pDrv->pUpPort)
299 {
300 AssertMsgFailed(("Configuration error: No mouse port interface above!\n"));
301 return VERR_PDM_MISSING_INTERFACE_ABOVE;
302 }
303
304 /*
305 * Attach driver below and query it's connector interface.
306 */
307 PPDMIBASE pDownBase;
308 int rc = PDMDrvHlpAttach(pDrvIns, fFlags, &pDownBase);
309 if (RT_FAILURE(rc))
310 {
311 AssertMsgFailed(("Failed to attach driver below us! rc=%Rra\n", rc));
312 return rc;
313 }
314 pDrv->pDownConnector = PDMIBASE_QUERY_INTERFACE(pDownBase, PDMIMOUSECONNECTOR);
315 if (!pDrv->pDownConnector)
316 {
317 AssertMsgFailed(("Configuration error: No mouse connector interface below!\n"));
318 return VERR_PDM_MISSING_INTERFACE_BELOW;
319 }
320
321 /*
322 * Create the queue.
323 */
324 uint32_t cMilliesInterval = 0;
325 rc = CFGMR3QueryU32(pCfg, "Interval", &cMilliesInterval);
326 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
327 cMilliesInterval = 0;
328 else if (RT_FAILURE(rc))
329 {
330 AssertMsgFailed(("Configuration error: 32-bit \"Interval\" -> rc=%Rrc\n", rc));
331 return rc;
332 }
333
334 uint32_t cItems = 0;
335 rc = CFGMR3QueryU32(pCfg, "QueueSize", &cItems);
336 if (rc == VERR_CFGM_VALUE_NOT_FOUND)
337 cItems = 128;
338 else if (RT_FAILURE(rc))
339 {
340 AssertMsgFailed(("Configuration error: 32-bit \"QueueSize\" -> rc=%Rrc\n", rc));
341 return rc;
342 }
343
344 rc = PDMDrvHlpQueueCreate(pDrvIns, sizeof(DRVMOUSEQUEUEITEM), cItems, cMilliesInterval, drvMouseQueueConsumer, "Mouse", &pDrv->pQueue);
345 if (RT_FAILURE(rc))
346 {
347 AssertMsgFailed(("Failed to create driver: cItems=%d cMilliesInterval=%d rc=%Rrc\n", cItems, cMilliesInterval, rc));
348 return rc;
349 }
350
351 return VINF_SUCCESS;
352}
353
354
355/**
356 * Mouse queue driver registration record.
357 */
358const PDMDRVREG g_DrvMouseQueue =
359{
360 /* u32Version */
361 PDM_DRVREG_VERSION,
362 /* szName */
363 "MouseQueue",
364 /* szRCMod */
365 "",
366 /* szR0Mod */
367 "",
368 /* pszDescription */
369 "Mouse queue driver to plug in between the key source and the device to do queueing and inter-thread transport.",
370 /* fFlags */
371 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
372 /* fClass. */
373 PDM_DRVREG_CLASS_MOUSE,
374 /* cMaxInstances */
375 ~0U,
376 /* cbInstance */
377 sizeof(DRVMOUSEQUEUE),
378 /* pfnConstruct */
379 drvMouseQueueConstruct,
380 /* pfnRelocate */
381 NULL,
382 /* pfnDestruct */
383 NULL,
384 /* pfnIOCtl */
385 NULL,
386 /* pfnPowerOn */
387 drvMouseQueuePowerOn,
388 /* pfnReset */
389 drvMouseQueueReset,
390 /* pfnSuspend */
391 drvMouseQueueSuspend,
392 /* pfnResume */
393 drvMouseQueueResume,
394 /* pfnAttach */
395 NULL,
396 /* pfnDetach */
397 NULL,
398 /* pfnPowerOff */
399 drvMouseQueuePowerOff,
400 /* pfnSoftReset */
401 NULL,
402 /* u32EndVersion */
403 PDM_DRVREG_VERSION
404};
405
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette