046b47b65e7b37236404400f31ba823b88f9d0bb
2 * Copyright © 2017 Lima Project
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:
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
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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
28 #include "c11/threads.h"
29 #include "util/u_hash_table.h"
30 #include "util/u_pointer.h"
31 #include "renderonly/renderonly.h"
33 #include "lima_drm_public.h"
35 #include "lima/lima_screen.h"
37 static struct hash_table
*fd_tab
= NULL
;
38 static mtx_t lima_screen_mutex
= _MTX_INITIALIZER_NP
;
41 lima_drm_screen_destroy(struct pipe_screen
*pscreen
)
43 struct lima_screen
*screen
= lima_screen(pscreen
);
47 mtx_lock(&lima_screen_mutex
);
48 destroy
= --screen
->refcnt
== 0;
50 _mesa_hash_table_remove_key(fd_tab
, intptr_to_pointer(fd
));
51 mtx_unlock(&lima_screen_mutex
);
54 pscreen
->destroy
= screen
->winsys_priv
;
55 pscreen
->destroy(pscreen
);
61 lima_drm_screen_create(int fd
)
63 struct pipe_screen
*pscreen
= NULL
;
65 mtx_lock(&lima_screen_mutex
);
67 fd_tab
= util_hash_table_create_fd_keys();
72 pscreen
= util_hash_table_get(fd_tab
, intptr_to_pointer(fd
));
74 lima_screen(pscreen
)->refcnt
++;
76 int dup_fd
= fcntl(fd
, F_DUPFD_CLOEXEC
, 3);
78 pscreen
= lima_screen_create(dup_fd
, NULL
);
80 _mesa_hash_table_insert(fd_tab
, intptr_to_pointer(dup_fd
), pscreen
);
82 /* Bit of a hack, to avoid circular linkage dependency,
83 * ie. pipe driver having to call in to winsys, we
84 * override the pipe drivers screen->destroy():
86 lima_screen(pscreen
)->winsys_priv
= pscreen
->destroy
;
87 pscreen
->destroy
= lima_drm_screen_destroy
;
92 mtx_unlock(&lima_screen_mutex
);
97 lima_drm_screen_create_renderonly(struct renderonly
*ro
)
99 return lima_screen_create(fcntl(ro
->gpu_fd
, F_DUPFD_CLOEXEC
, 3), ro
);