sunxi_mali_ump_dri2.h 6.14 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
/*
 * Copyright © 2013 Siarhei Siamashka <siarhei.siamashka@gmail.com>
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 */

#ifndef SUNXI_MALI_UMP_DRI2_H
#define SUNXI_MALI_UMP_DRI2_H

#include <ump/ump.h>
#include <ump/ump_ref_drv.h>

30
31
#include "uthash.h"

32
33
34
#define UMPBUF_MUST_BE_ODD_FRAME  1
#define UMPBUF_MUST_BE_EVEN_FRAME 2

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/* Data structure with the information about an UMP buffer */
typedef struct
{
    /* The migrated pixmap (may be NULL if it is a window) */
    PixmapPtr               pPixmap;
    int                     BackupDevKind;
    void                   *BackupDevPrivatePtr;
    int                     refcount;
    UT_hash_handle          hh;

    ump_handle              handle;
    size_t                  size;
    uint8_t                *addr;
    int                     depth;
    size_t                  width;
    size_t                  height;
51
    int                     extra_flags;
52
53
54
55
56

    ump_secure_id           secure_id;
    unsigned int            pitch;
    unsigned int            cpp;
    unsigned int            offs;
57
58
} UMPBufferInfoRec, *UMPBufferInfoPtr;

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * DRI2 related bookkeeping for windows. Because Mali r3p0 blob has
 * quirks and needs workarounds, we can't fully rely on the Xorg DRI2
 * framework. But instead have to predict what is happening on the
 * client side based on the typical blob behavior.
 *
 * The blob is doing something like this:
 *  1. Requests BackLeft DRI2 buffer (buffer A) and renders to it
 *  2. Swaps buffers
 *  3. Requests BackLeft DRI2 buffer (buffer B)
 *  4. Checks window geometry, and if it has changed - go back to step 1.
 *  5. Renders to the current back buffer (either buffer A or B)
 *  6. Swaps buffers
 *  7. Go back to step 4
 *
 * The main problem is that The Mali blob ignores DRI2-InvalidateBuffers
 * events and just uses GetGeometry polling to check whether the window
 * size has changed. Unfortunately this is racy and we may end up with a
 * size mismatch between buffer A and buffer B. This is particularly easy
 * to trigger when the window size changes exactly between steps 1 and 3.
 * See test/gles-yellow-blue-flip.c program which demonstrates this.
 */
typedef struct
{
    UT_hash_handle          hh;
    DrawablePtr             pDraw;
    /* width and height must be the same for back and front buffers */
    int                     width, height;
    /* the number of back buffer requests */
88
89
90
    unsigned int            buf_request_cnt;
    /* the number of back/front buffer swaps */
    unsigned int            buf_swap_cnt;
91
92
93

    /* allocated UMP buffer (shared between back and front DRI2 buffers) */
    UMPBufferInfoPtr        ump_mem_buffer_ptr;
94
95
96
97
98
99
100
101
102
103
104
105

    /* UMP buffers for hardware overlay and double buffering */
    UMPBufferInfoPtr        ump_back_buffer_ptr;
    UMPBufferInfoPtr        ump_front_buffer_ptr;

    /*
     * The queue for incoming UMP buffers. We need to have it because DRI2
     * buffer requests and buffer swaps sometimes may come out of order.
     */
    UMPBufferInfoPtr        ump_queue[16];
    int                     ump_queue_head;
    int                     ump_queue_tail;
106
107
108
109
110
111
112
113
114
115
116
117

    /*
     * In the case DEBUG_WITH_RGB_PATTERN is defined, we add extra debugging
     * code for verifying that for each new frame, the background color is
     * changed as "R -> G -> B -> R -> G -> B -> ..." pattern and there are
     * no violations of this color change order. It is intended to be used
     * together with "test/gles-rgb-cycle-demo.c" program, which can generate
     * such pattern.
     */
#ifdef DEBUG_WITH_RGB_PATTERN
    char                    rgb_pattern_state;
#endif
118
119
} DRI2WindowStateRec, *DRI2WindowStatePtr;

120
121
122
123
124
typedef struct {
    int                     overlay_x;
    int                     overlay_y;

    WindowPtr               pOverlayWin;
125
    UMPBufferInfoPtr        pOverlayDirtyUMP;
126
127
128
129
    Bool                    bOverlayWinEnabled;
    Bool                    bOverlayWinOverlapped;
    Bool                    bWalkingAboveOverlayWin;

130
131
132
133
    Bool                    bHardwareCursorIsInUse;
    EnableHWCursorProcPtr   EnableHWCursor;
    DisableHWCursorProcPtr  DisableHWCursor;

134
135
136
    DestroyWindowProcPtr    DestroyWindow;
    PostValidateTreeProcPtr PostValidateTree;
    GetImageProcPtr         GetImage;
137
    DestroyPixmapProcPtr    DestroyPixmap;
138
139

    /* the primary UMP secure id for accessing framebuffer */
140
    ump_secure_id           ump_fb_secure_id;
141
142
143
144
145
146
    /* the alternative UMP secure id used for the window resize workaround */
    ump_secure_id           ump_alternative_fb_secure_id;
    /* the UMP secure id for a dummy buffer */
    ump_secure_id           ump_null_secure_id;
    ump_handle              ump_null_handle1;
    ump_handle              ump_null_handle2;
147

148
    UMPBufferInfoPtr        HashPixmapToUMP;
149
    DRI2WindowStatePtr      HashWindowState;
150

151
    int                     drm_fd;
152
153
154

    /* Wait for vsync when swapping DRI2 buffers */
    Bool                    bSwapbuffersWait;
155
156
} SunxiMaliDRI2;

157
158
159
SunxiMaliDRI2 *SunxiMaliDRI2_Init(ScreenPtr pScreen,
                                  Bool      bUseOverlay,
                                  Bool      bSwapbuffersWait);
160
161
162
void SunxiMaliDRI2_Close(ScreenPtr pScreen);

#endif