1 /**************************************************************************
2 * Copyright © 2016 VMware, Inc., Palo Alto, CA., USA
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
15 * of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
20 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
23 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 *
25 **************************************************************************/
26 /*
27 * This file contains calls into the RandR1.2 code and modification of core
28 * RandR data structures that probably were never intended from drivers.
29 */
30
31 #ifndef _VMWGFX_RR_INLINES_H_
32 #define _VMWGFX_RR_INLINES_H_
33
34 #include <xf86Crtc.h>
35 #include <xf86RandR12.h>
36
37 #define VMW_DPI 96.
38 #define VMW_INCH_TO_MM 25.4
39
40 /**
41 * vmwgfx_notify_rr - Notify RandR that our configuration has changed.
42 *
43 * @pScreen: Pointer to the affected screen.
44 *
45 * Normally screen configurations are typically only changed using RandR,
46 * so when we do it in an udev handler, we need to notify RandR that we've
47 * made a change, so that it can be propagated to all RandR clients.
48 */
49 static inline void
vmwgfx_notify_rr(ScreenPtr pScreen)50 vmwgfx_notify_rr(ScreenPtr pScreen)
51 {
52 rrScrPriv(pScreen);
53
54
55 /*
56 * We need to update the time-stamps, otherwise X clients that haven't
57 * yet read this config might just overwrite it.
58 * This effectively stops the desktop manager from trying to
59 * outsmart us, since RandR simply doesn't accept requests from
60 * clients that haven't read this config and tag their request with
61 * an earlier timestamp.
62 */
63 pScrPriv->lastSetTime = currentTime;
64 pScrPriv->lastConfigTime = currentTime;
65 #ifdef RANDR_12_INTERFACE
66 xf86RandR12TellChanged(pScreen);
67 #else
68 RRTellChanged(pScreen);
69 #endif
70 }
71
72 /**
73 * vmwgfx_rr_screen_set_size - Use RandR to change the root pixmap dimensions.
74 *
75 * @pScreen: Pointer to the affected screen.
76 *
77 * Returns: TRUE if successful. False otherwise.
78 */
79 static inline Bool
vmwgfx_rr_screen_set_size(ScreenPtr pScreen,int width,int height)80 vmwgfx_rr_screen_set_size(ScreenPtr pScreen, int width, int height)
81 {
82 rrScrPriv(pScreen);
83 float mm_width, mm_height;
84
85 mm_width = ((float) width) * VMW_INCH_TO_MM / VMW_DPI + .5;
86 mm_height = ((float) height) * VMW_INCH_TO_MM / VMW_DPI + .5;
87
88 return pScrPriv->rrScreenSetSize(pScreen, width, height,
89 (int) mm_width, (int) mm_height);
90 }
91
92 #endif
93