commit d8a80f7
Michael Forney
·
2014-01-14 09:42:35 +0000 UTC
parent 2cf1a72
Style
4 files changed,
+38,
-46
M
dumb.c
+6,
-9
1@@ -105,19 +105,16 @@ struct wld_buffer * context_create_buffer(struct wld_context * base,
2 {
3 struct dumb_context * context = dumb_context(base);
4 struct wld_buffer * buffer;
5- struct drm_mode_create_dumb create_dumb_arg = {
6+ struct drm_mode_create_dumb create_dumb = {
7 .height = height, .width = width,
8 .bpp = format_bytes_per_pixel(format) * 8,
9 };
10- int ret;
11
12- ret = drmIoctl(context->fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb_arg);
13-
14- if (ret != 0)
15+ if (drmIoctl(context->fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb) != 0)
16 goto error0;
17
18 buffer = new_buffer(context, width, height, format,
19- create_dumb_arg.handle, create_dumb_arg.pitch);
20+ create_dumb.handle, create_dumb.pitch);
21
22 if (!buffer)
23 goto error1;
24@@ -126,11 +123,11 @@ struct wld_buffer * context_create_buffer(struct wld_context * base,
25
26 error1:
27 {
28- struct drm_mode_destroy_dumb destroy_dumb_arg = {
29- .handle = create_dumb_arg.handle
30+ struct drm_mode_destroy_dumb destroy_dumb = {
31+ .handle = create_dumb.handle
32 };
33
34- drmIoctl(context->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb_arg);
35+ drmIoctl(context->fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
36 }
37 error0:
38 return NULL;
M
intel.c
+1,
-0
1@@ -60,6 +60,7 @@ IMPL(intel, context)
2 IMPL(intel, renderer)
3 IMPL(intel, buffer)
4
5+/**** DRM driver ****/
6 bool driver_device_supported(uint32_t vendor_id, uint32_t device_id)
7 {
8 return vendor_id == 0x8086;
+23,
-27
1@@ -22,9 +22,9 @@
2 */
3
4 #include "wayland-drm.h"
5-#include "protocol/wayland-drm-client-protocol.h"
6 #include "wayland.h"
7 #include "drm.h"
8+#include "protocol/wayland-drm-client-protocol.h"
9 #include "wayland-private.h"
10 #include "wld-private.h"
11 #include "drm-private.h"
12@@ -84,48 +84,44 @@ EXPORT
13 struct wld_context * wld_wayland_drm_create_context(struct wl_display * display,
14 struct wl_event_queue * queue)
15 {
16- struct drm_context * drm;
17-
18- drm = malloc(sizeof *drm);
19+ struct drm_context * context;
20
21- if (!drm)
22+ if (!(context = malloc(sizeof *context)))
23 goto error0;
24
25- context_initialize(&drm->base, &context_impl);
26- drm->wl = NULL;
27- drm->fd = -1;
28- drm->capabilities = 0;
29- wl_array_init(&drm->formats);
30+ context_initialize(&context->base, &context_impl);
31+ context->wl = NULL;
32+ context->fd = -1;
33+ context->capabilities = 0;
34+ wl_array_init(&context->formats);
35
36- drm->registry = wl_display_get_registry(display);
37-
38- if (!drm->registry)
39+ if (!(context->registry = wl_display_get_registry(display)))
40 goto error1;
41
42- wl_registry_add_listener(drm->registry, ®istry_listener, drm);
43- wl_proxy_set_queue((struct wl_proxy *) drm->registry, queue);
44+ wl_registry_add_listener(context->registry, ®istry_listener, context);
45+ wl_proxy_set_queue((struct wl_proxy *) context->registry, queue);
46
47 /* Wait for wl_drm global. */
48 wayland_roundtrip(display, queue);
49
50- if (!drm->wl)
51+ if (!context->wl)
52 {
53 DEBUG("No wl_drm global\n");
54 goto error2;
55 }
56
57- wl_drm_add_listener(drm->wl, &drm_listener, drm);
58+ wl_drm_add_listener(context->wl, &drm_listener, context);
59
60 /* Wait for DRM capabilities and device. */
61 wayland_roundtrip(display, queue);
62
63- if (!(drm->capabilities & WL_DRM_CAPABILITY_PRIME))
64+ if (!(context->capabilities & WL_DRM_CAPABILITY_PRIME))
65 {
66 DEBUG("No PRIME support\n");
67 goto error3;
68 }
69
70- if (drm->fd == -1)
71+ if (context->fd == -1)
72 {
73 DEBUG("No DRM device\n");
74 goto error3;
75@@ -134,29 +130,29 @@ struct wld_context * wld_wayland_drm_create_context(struct wl_display * display,
76 /* Wait for DRM authentication. */
77 wayland_roundtrip(display, queue);
78
79- if (!drm->authenticated)
80+ if (!context->authenticated)
81 {
82 DEBUG("DRM authentication failed\n");
83 goto error4;
84 }
85
86- if (!(drm->driver_context = wld_drm_create_context(drm->fd)))
87+ if (!(context->driver_context = wld_drm_create_context(context->fd)))
88 {
89 DEBUG("Couldn't initialize context for DRM device\n");
90 goto error4;
91 }
92
93- return &drm->base;
94+ return &context->base;
95
96 error4:
97- close(drm->fd);
98+ close(context->fd);
99 error3:
100- wl_drm_destroy(drm->wl);
101+ wl_drm_destroy(context->wl);
102 error2:
103- wl_registry_destroy(drm->registry);
104+ wl_registry_destroy(context->registry);
105 error1:
106- wl_array_release(&drm->formats);
107- free(drm);
108+ wl_array_release(&context->formats);
109+ free(context);
110 error0:
111 return NULL;
112 }
+8,
-10
1@@ -29,11 +29,11 @@
2 #include "wld-private.h"
3 #include "pixman.h"
4
5+#include <fcntl.h>
6 #include <stdlib.h>
7 #include <string.h>
8-#include <unistd.h>
9-#include <fcntl.h>
10 #include <sys/mman.h>
11+#include <unistd.h>
12 #include <wayland-client.h>
13
14 struct shm_context
15@@ -69,7 +69,7 @@ const static struct wl_shm_listener shm_listener = {
16 .format = &shm_format,
17 };
18
19-static inline uint32_t wayland_format(uint32_t format)
20+static inline uint32_t format_wld_to_shm(uint32_t format)
21 {
22 switch (format)
23 {
24@@ -158,10 +158,8 @@ struct wld_buffer * context_create_buffer(struct wld_context * base,
25 struct wld_exporter * exporter;
26 char name[] = "/tmp/wld-XXXXXX";
27 uint32_t pitch = width * format_bytes_per_pixel(format);
28- uint32_t size = height * pitch;
29+ size_t size = pitch * height;
30 int fd;
31- void * data;
32- uint32_t shm_format = wayland_format(format);
33 union wld_object object;
34 struct wl_shm_pool * pool;
35 struct wl_buffer * wl;
36@@ -176,12 +174,11 @@ struct wld_buffer * context_create_buffer(struct wld_context * base,
37 if (ftruncate(fd, size) < 0)
38 goto error1;
39
40- data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
41+ object.ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
42
43- if (data == MAP_FAILED)
44+ if (object.ptr == MAP_FAILED)
45 goto error1;
46
47- object.ptr = data;
48 buffer = wld_import_buffer(wld_pixman_context, WLD_OBJECT_DATA, object,
49 width, height, format, pitch);
50
51@@ -191,7 +188,8 @@ struct wld_buffer * context_create_buffer(struct wld_context * base,
52 if (!(pool = wl_shm_create_pool(context->wl, fd, size)))
53 goto error3;
54
55- wl = wl_shm_pool_create_buffer(pool, 0, width, height, pitch, shm_format);
56+ wl = wl_shm_pool_create_buffer(pool, 0, width, height, pitch,
57+ format_wld_to_shm(format));
58 wl_shm_pool_destroy(pool);
59
60 if (!wl)