1 /*
2 * Copyright © Microsoft Corporation
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
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #include "pipe/p_screen.h"
25
26 #include "util/u_memory.h"
27 #include "vl/vl_winsys.h"
28
29 #include "target-helpers/sw_helper_public.h"
30 #include "gallium/winsys/sw/kms-dri/kms_dri_sw_winsys.h"
31
32 static void
vl_vgem_drm_screen_destroy(struct vl_screen * vscreen)33 vl_vgem_drm_screen_destroy(struct vl_screen *vscreen)
34 {
35 if (vscreen) {
36 if (vscreen->pscreen)
37 vscreen->pscreen->destroy(vscreen->pscreen);
38 FREE(vscreen);
39 }
40 }
41
42 struct vl_screen *
vl_vgem_drm_screen_create(int fd)43 vl_vgem_drm_screen_create(int fd)
44 {
45 struct vl_screen *vscreen = CALLOC_STRUCT(vl_screen);
46 if (!vscreen)
47 return NULL;
48
49 struct sw_winsys *winsys = kms_dri_create_winsys(fd);
50 if (winsys == NULL)
51 goto release_pipe;
52
53 vscreen->pscreen = sw_screen_create(winsys);
54 if (!vscreen->pscreen)
55 goto release_pipe;
56
57 vscreen->destroy = vl_vgem_drm_screen_destroy;
58 vscreen->texture_from_drawable = NULL;
59 vscreen->get_dirty_area = NULL;
60 vscreen->get_timestamp = NULL;
61 vscreen->set_next_timestamp = NULL;
62 vscreen->get_private = NULL;
63 return vscreen;
64
65 release_pipe:
66 vl_vgem_drm_screen_destroy(vscreen);
67 return NULL;
68 }
69