commit 17319a1
Michael Forney
·
2013-09-05 08:59:00 +0000 UTC
parent 50e7d71
drm: Add buffer import support
4 files changed,
+115,
-10
+8,
-0
1@@ -32,6 +32,12 @@ typedef void * (* drm_create_context_func_t)(int drm_fd);
2 typedef void (* drm_destroy_context_func_t)(void * context);
3 typedef struct drm_drawable * (* drm_create_drawable_func_t)
4 (void * context, uint32_t width, uint32_t height, uint32_t format);
5+typedef struct drm_drawable * (* drm_import_func_t)
6+ (void * context, uint32_t width, uint32_t height, uint32_t format,
7+ int prime_fd, unsigned long pitch);
8+typedef struct drm_drawable * (* drm_import_gem_func_t)
9+ (void * context, uint32_t width, uint32_t height, uint32_t format,
10+ uint32_t gem_name, unsigned long pitch);
11 typedef int (* drm_export_func_t)(struct drm_drawable * drawable);
12
13 struct wld_drm_interface
14@@ -40,6 +46,8 @@ struct wld_drm_interface
15 drm_create_context_func_t create_context;
16 drm_destroy_context_func_t destroy_context;
17 drm_create_drawable_func_t create_drawable;
18+ drm_import_func_t import;
19+ drm_import_gem_func_t import_gem;
20 drm_export_func_t export;
21 };
22
M
drm.c
+26,
-0
1@@ -130,6 +130,32 @@ struct wld_drawable * wld_drm_create_drawable(struct wld_drm_context * drm,
2 return finish_drawable(drm, drawable);
3 }
4
5+struct wld_drawable * wld_drm_import(struct wld_drm_context * drm,
6+ uint32_t width, uint32_t height,
7+ uint32_t format,
8+ int prime_fd, unsigned long pitch)
9+{
10+ struct drm_drawable * drawable;
11+
12+ drawable = drm->interface->import(drm->context, width, height, format,
13+ prime_fd, pitch);
14+
15+ return finish_drawable(drm, drawable);
16+}
17+
18+struct wld_drawable * wld_drm_import_gem(struct wld_drm_context * drm,
19+ uint32_t width, uint32_t height,
20+ uint32_t format,
21+ uint32_t gem_name, unsigned long pitch)
22+{
23+ struct drm_drawable * drawable;
24+
25+ drawable = drm->interface->import_gem(drm->context, width, height, format,
26+ gem_name, pitch);
27+
28+ return finish_drawable(drm, drawable);
29+}
30+
31 int wld_drm_export(struct wld_drawable * drawable)
32 {
33 struct drm_drawable * drm_drawable = (void *) drawable;
M
drm.h
+19,
-0
1@@ -46,6 +46,25 @@ struct wld_drawable * wld_drm_create_drawable(struct wld_drm_context * drm,
2 uint32_t width, uint32_t height,
3 uint32_t format);
4
5+/**
6+ * Create a new DRM drawable by importing a PRIME file descriptor.
7+ */
8+struct wld_drawable * wld_drm_import(struct wld_drm_context * context,
9+ uint32_t width, uint32_t height,
10+ uint32_t format,
11+ int prime_fd, unsigned long pitch);
12+
13+/**
14+ * Create a new DRM drawable by importing a GEM name.
15+ *
16+ * This is provided for compatibility with clients that don't support PRIME.
17+ * You should use wld_drm_import_drawable and PRIME if possible.
18+ */
19+struct wld_drawable * wld_drm_import_gem(struct wld_drm_context * context,
20+ uint32_t width, uint32_t height,
21+ uint32_t format, uint32_t gem_name,
22+ unsigned long pitch);
23+
24 /**
25 * Export a DRM drawable to a PRIME file descriptor.
26 *
M
intel.c
+62,
-10
1@@ -72,6 +72,12 @@ static bool intel_device_supported(uint32_t vendor_id, uint32_t device_id);
2 static struct drm_drawable * intel_create_drawable
3 (struct wld_intel_context * context, uint32_t width, uint32_t height,
4 uint32_t format);
5+static struct drm_drawable * intel_import
6+ (struct wld_intel_context * context, uint32_t width, uint32_t height,
7+ uint32_t format, int prime_fd, unsigned long pitch);
8+static struct drm_drawable * intel_import_gem
9+ (struct wld_intel_context * context, uint32_t width, uint32_t height,
10+ uint32_t format, uint32_t gem_name, unsigned long pitch);
11 static int intel_export(struct drm_drawable * drawable);
12
13 const static struct wld_draw_interface intel_draw = {
14@@ -89,6 +95,8 @@ const struct wld_drm_interface intel_drm = {
15 .create_context = (drm_create_context_func_t) &intel_create_context,
16 .destroy_context = (drm_destroy_context_func_t) &intel_destroy_context,
17 .create_drawable = (drm_create_drawable_func_t) &intel_create_drawable,
18+ .import = (drm_import_func_t) &intel_import,
19+ .import_gem = (drm_import_gem_func_t) &intel_import_gem,
20 .export = (drm_export_func_t) &intel_export,
21 };
22
23@@ -118,26 +126,70 @@ void intel_destroy_context(struct wld_intel_context * context)
24 free(context);
25 }
26
27-struct drm_drawable * intel_create_drawable
28- (struct wld_intel_context * context, uint32_t width, uint32_t height,
29- uint32_t format)
30+static struct intel_drawable * new_drawable(struct wld_intel_context * context,
31+ uint32_t width, uint32_t height)
32 {
33 struct intel_drawable * intel;
34- uint32_t tiling_mode = I915_TILING_X, pitch;
35
36- intel = malloc(sizeof *intel);
37-
38- if (!intel)
39+ if (!(intel = malloc(sizeof *intel)))
40 return NULL;
41
42 intel->drm.base.interface = &intel_draw;
43 intel->drm.base.width = width;
44 intel->drm.base.height = height;
45-
46 intel->context = context;
47+
48+ return intel;
49+}
50+
51+struct drm_drawable * intel_create_drawable
52+ (struct wld_intel_context * context, uint32_t width, uint32_t height,
53+ uint32_t format)
54+{
55+ struct intel_drawable * intel;
56+ uint32_t tiling_mode = I915_TILING_X;
57+
58+ if (!(intel = new_drawable(context, width, height)))
59+ return NULL;
60+
61 intel->bo = drm_intel_bo_alloc_tiled(context->bufmgr, "drawable",
62- width, height, 4,
63- &tiling_mode, &intel->drm.base.pitch, 0);
64+ width, height, 4, &tiling_mode,
65+ &intel->drm.base.pitch, 0);
66+
67+ return &intel->drm;
68+}
69+
70+struct drm_drawable * intel_import(struct wld_intel_context * context,
71+ uint32_t width, uint32_t height,
72+ uint32_t format,
73+ int prime_fd, unsigned long pitch)
74+{
75+ struct intel_drawable * intel;
76+ uint32_t size = width * height * 4;
77+
78+ if (!(intel = new_drawable(context, width, height)))
79+ return NULL;
80+
81+ intel->drm.base.pitch = pitch;
82+ intel->bo = drm_intel_bo_gem_create_from_prime(context->bufmgr,
83+ prime_fd, size);
84+
85+ return &intel->drm;
86+}
87+
88+struct drm_drawable * intel_import_gem(struct wld_intel_context * context,
89+ uint32_t width, uint32_t height,
90+ uint32_t format,
91+ uint32_t gem_name, unsigned long pitch)
92+{
93+ struct intel_drawable * intel;
94+
95+ if (!(intel = new_drawable(context, width, height)))
96+ return NULL;
97+
98+ intel->drm.base.pitch = pitch;
99+ intel->bo = drm_intel_bo_gem_create_from_name(context->bufmgr, "drawable",
100+ gem_name);
101
102 return &intel->drm;
103 }