commit b1a964a
Michael Forney
·
2013-07-19 07:32:57 +0000 UTC
parent 93c2137
Use PRIME buffer sharing
3 files changed,
+32,
-11
+1,
-1
1@@ -46,7 +46,7 @@ struct drm_drawable
2 struct wld_drawable base;
3
4 unsigned long pitch;
5- uint32_t name;
6+ int fd;
7 };
8
9 _Static_assert(offsetof(struct drm_drawable, base) == 0,
M
intel.c
+3,
-2
1@@ -25,6 +25,7 @@
2 #include "drm-private.h"
3 #include "wld-private.h"
4
5+#include <unistd.h>
6 #include <intelbatch/batch.h>
7 #include <intelbatch/blt.h>
8 #include <intelbatch/mi.h>
9@@ -118,8 +119,7 @@ struct wld_drawable * wld_intel_create_drawable
10 intel->bo = drm_intel_bo_alloc_tiled(context->bufmgr, "drawable",
11 width, height, 4,
12 &tiling_mode, &intel->drm.pitch, 0);
13-
14- drm_intel_bo_flink(intel->bo, &intel->drm.name);
15+ drm_intel_bo_gem_export_to_prime(intel->bo, &intel->drm.fd);
16
17 return &intel->drm.base;
18 }
19@@ -210,6 +210,7 @@ void intel_destroy(struct wld_drawable * drawable)
20 {
21 struct intel_drawable * intel = (void *) drawable;
22 drm_intel_bo_unreference(intel->bo);
23+ close(intel->drm.fd);
24 free(intel);
25 }
26
+28,
-8
1@@ -41,6 +41,7 @@ struct wld_drm_context
2 struct wl_drm * wl;
3 struct wl_registry * registry;
4 struct wl_array formats;
5+ uint32_t capabilities;
6 int fd;
7 bool authenticated;
8
9@@ -55,6 +56,8 @@ static void registry_global(void * data, struct wl_registry * registry,
10 static void drm_device(void * data, struct wl_drm * wl, const char * name);
11 static void drm_format(void * data, struct wl_drm * wl, uint32_t format);
12 static void drm_authenticated(void * data, struct wl_drm * wl);
13+static void drm_capabilities(void * data, struct wl_drm * wl,
14+ uint32_t capabilities);
15
16 const struct wld_wayland_interface wayland_drm_interface = {
17 .create_context = (wayland_create_context_func_t) &wld_drm_create_context,
18@@ -70,7 +73,8 @@ const static struct wl_registry_listener registry_listener = {
19 const static struct wl_drm_listener drm_listener = {
20 .device = &drm_device,
21 .format = &drm_format,
22- .authenticated = &drm_authenticated
23+ .authenticated = &drm_authenticated,
24+ .capabilities = &drm_capabilities
25 };
26
27 const static struct wld_drm_interface * drm_interfaces[] = {
28@@ -128,6 +132,7 @@ struct wld_drm_context * wld_drm_create_context(struct wl_display * display,
29
30 drm->wl = NULL;
31 drm->fd = -1;
32+ drm->capabilities = 0;
33 wl_array_init(&drm->formats);
34
35 drm->registry = wl_display_get_registry(display);
36@@ -149,9 +154,15 @@ struct wld_drm_context * wld_drm_create_context(struct wl_display * display,
37
38 wl_drm_add_listener(drm->wl, &drm_listener, drm);
39
40- /* Wait for DRM device. */
41+ /* Wait for DRM capabilities and device. */
42 wayland_roundtrip(display, queue);
43
44+ if (!(drm->capabilities & WL_DRM_CAPABILITY_PRIME))
45+ {
46+ DEBUG("No PRIME support\n");
47+ goto error3;
48+ }
49+
50 if (drm->fd == -1)
51 {
52 DEBUG("No DRM device\n");
53@@ -244,10 +255,12 @@ struct wld_drawable * wld_drm_create_drawable(struct wld_drm_context * drm,
54 drawable1 = (void *) drm->interface->create_drawable(drm->context,
55 width, height, format);
56
57- buffer0 = wl_drm_create_buffer(drm->wl, drawable0->name, width, height,
58- drawable0->pitch, format);
59- buffer1 = wl_drm_create_buffer(drm->wl, drawable1->name, width, height,
60- drawable1->pitch, format);
61+ buffer0 = wl_drm_create_prime_buffer(drm->wl, drawable0->fd, width, height,
62+ format, 0, drawable0->pitch,
63+ 0, 0, 0, 0);
64+ buffer1 = wl_drm_create_prime_buffer(drm->wl, drawable1->fd, width, height,
65+ format, 0, drawable1->pitch,
66+ 0, 0, 0, 0);
67
68 return wld_wayland_create_drawable_from_buffers(surface,
69 buffer0, &drawable0->base,
70@@ -259,8 +272,8 @@ void registry_global(void * data, struct wl_registry * registry, uint32_t name,
71 {
72 struct wld_drm_context * drm = data;
73
74- if (strcmp(interface, "wl_drm") == 0)
75- drm->wl = wl_registry_bind(registry, name, &wl_drm_interface, 1);
76+ if (strcmp(interface, "wl_drm") == 0 && version >= 2)
77+ drm->wl = wl_registry_bind(registry, name, &wl_drm_interface, 2);
78 }
79
80 void drm_device(void * data, struct wl_drm * wl, const char * name)
81@@ -294,3 +307,10 @@ void drm_authenticated(void * data, struct wl_drm * wl)
82 drm->authenticated = true;
83 }
84
85+void drm_capabilities(void * data, struct wl_drm * wl, uint32_t capabilities)
86+{
87+ struct wld_drm_context * drm = data;
88+
89+ drm->capabilities = capabilities;
90+}
91+