Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/winsys/freedreno/drm/freedreno_drm_winsys.c
4573 views
1
/*
2
* Copyright (C) 2012 Rob Clark <[email protected]>
3
*
4
* Permission is hereby granted, free of charge, to any person obtaining a
5
* copy of this software and associated documentation files (the "Software"),
6
* to deal in the Software without restriction, including without limitation
7
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
* and/or sell copies of the Software, and to permit persons to whom the
9
* Software is furnished to do so, subject to the following conditions:
10
*
11
* The above copyright notice and this permission notice (including the next
12
* paragraph) shall be included in all copies or substantial portions of the
13
* Software.
14
*
15
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
* SOFTWARE.
22
*
23
* Authors:
24
* Rob Clark <[email protected]>
25
*/
26
27
#include <sys/stat.h>
28
29
#include "pipe/p_context.h"
30
#include "pipe/p_state.h"
31
#include "util/format/u_format.h"
32
#include "util/u_memory.h"
33
#include "util/u_inlines.h"
34
#include "util/u_hash_table.h"
35
#include "util/u_pointer.h"
36
#include "os/os_thread.h"
37
38
#include "freedreno_drm_public.h"
39
40
#include "freedreno/freedreno_screen.h"
41
42
static struct hash_table *fd_tab = NULL;
43
44
static mtx_t fd_screen_mutex = _MTX_INITIALIZER_NP;
45
46
static void
47
fd_drm_screen_destroy(struct pipe_screen *pscreen)
48
{
49
struct fd_screen *screen = fd_screen(pscreen);
50
boolean destroy;
51
52
mtx_lock(&fd_screen_mutex);
53
destroy = --screen->refcnt == 0;
54
if (destroy) {
55
int fd = fd_device_fd(screen->dev);
56
_mesa_hash_table_remove_key(fd_tab, intptr_to_pointer(fd));
57
58
if (!fd_tab->entries) {
59
_mesa_hash_table_destroy(fd_tab, NULL);
60
fd_tab = NULL;
61
}
62
}
63
mtx_unlock(&fd_screen_mutex);
64
65
if (destroy) {
66
pscreen->destroy = screen->winsys_priv;
67
pscreen->destroy(pscreen);
68
}
69
}
70
71
struct pipe_screen *
72
fd_drm_screen_create(int fd, struct renderonly *ro)
73
{
74
struct pipe_screen *pscreen = NULL;
75
76
mtx_lock(&fd_screen_mutex);
77
if (!fd_tab) {
78
fd_tab = util_hash_table_create_fd_keys();
79
if (!fd_tab)
80
goto unlock;
81
}
82
83
pscreen = util_hash_table_get(fd_tab, intptr_to_pointer(fd));
84
if (pscreen) {
85
fd_screen(pscreen)->refcnt++;
86
} else {
87
struct fd_device *dev = fd_device_new_dup(fd);
88
if (!dev)
89
goto unlock;
90
91
pscreen = fd_screen_create(dev, ro);
92
if (pscreen) {
93
int fd = fd_device_fd(dev);
94
95
_mesa_hash_table_insert(fd_tab, intptr_to_pointer(fd), pscreen);
96
97
/* Bit of a hack, to avoid circular linkage dependency,
98
* ie. pipe driver having to call in to winsys, we
99
* override the pipe drivers screen->destroy():
100
*/
101
fd_screen(pscreen)->winsys_priv = pscreen->destroy;
102
pscreen->destroy = fd_drm_screen_destroy;
103
}
104
}
105
106
unlock:
107
mtx_unlock(&fd_screen_mutex);
108
return pscreen;
109
}
110
111