sunxi_mali_ump_dri2.h 5.95 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "uthash.h"

/* 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;
48
49
50
51
52

    ump_secure_id           secure_id;
    unsigned int            pitch;
    unsigned int            cpp;
    unsigned int            offs;
53
54
} UMPBufferInfoRec, *UMPBufferInfoPtr;

55
56
57
58
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
/*
 * 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 */
    int                     buf_request_cnt;
85
86
87

    /* allocated UMP buffer (shared between back and front DRI2 buffers) */
    UMPBufferInfoPtr        ump_mem_buffer_ptr;
88
89
90
91
92
93
94
95
96
97
98
99

    /* 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;
100
101
102
103
104
105
106
107
108
109
110
111

    /*
     * 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
112
113
} DRI2WindowStateRec, *DRI2WindowStatePtr;

114
115
116
117
118
typedef struct {
    int                     overlay_x;
    int                     overlay_y;

    WindowPtr               pOverlayWin;
119
    UMPBufferInfoPtr        pOverlayDirtyUMP;
120
121
122
123
    Bool                    bOverlayWinEnabled;
    Bool                    bOverlayWinOverlapped;
    Bool                    bWalkingAboveOverlayWin;

124
125
126
127
    Bool                    bHardwareCursorIsInUse;
    EnableHWCursorProcPtr   EnableHWCursor;
    DisableHWCursorProcPtr  DisableHWCursor;

128
129
130
    DestroyWindowProcPtr    DestroyWindow;
    PostValidateTreeProcPtr PostValidateTree;
    GetImageProcPtr         GetImage;
131
    DestroyPixmapProcPtr    DestroyPixmap;
132
133

    /* the primary UMP secure id for accessing framebuffer */
134
    ump_secure_id           ump_fb_secure_id;
135
136
137
138
139
140
    /* 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;
141

142
    UMPBufferInfoPtr        HashPixmapToUMP;
143
    DRI2WindowStatePtr      HashWindowState;
144

145
    int                     drm_fd;
146
147
148

    /* Wait for vsync when swapping DRI2 buffers */
    Bool                    bSwapbuffersWait;
149
150
} SunxiMaliDRI2;

151
152
153
SunxiMaliDRI2 *SunxiMaliDRI2_Init(ScreenPtr pScreen,
                                  Bool      bUseOverlay,
                                  Bool      bSwapbuffersWait);
154
155
156
void SunxiMaliDRI2_Close(ScreenPtr pScreen);

#endif