commit e527984

Michael Forney  ·  2014-01-31 20:11:24 +0000 UTC
parent b5f5dc9
Add flags argument to create_{buffer,surface}

This adds an additional argument to the create_{buffer,surface}. The
upper 16 bits of this number are global flags specified in wld.h, and
the lower 16 bits are implementation-specific flags.

Some drivers, like nouveau, need extra information about intended use
for a buffer in order to create it with the correct settings.
15 files changed,  +47, -35
M drm.h
M dumb.c
M wld.h
+4, -2
 1@@ -44,11 +44,12 @@ struct buffered_surface
 2 
 3     uint32_t width, height;
 4     enum wld_format format;
 5+    uint32_t flags;
 6 };
 7 
 8 struct wld_surface * buffered_surface_create
 9     (struct wld_context * context, uint32_t width, uint32_t height,
10-     uint32_t format, struct wld_buffer_socket * buffer_socket)
11+     uint32_t format, uint32_t flags, struct wld_buffer_socket * buffer_socket)
12 {
13     struct buffered_surface * surface;
14 
15@@ -65,6 +66,7 @@ struct wld_surface * buffered_surface_create
16     surface->width = width;
17     surface->height = height;
18     surface->format = format;
19+    surface->flags = flags;
20 
21     return &surface->base;
22 }
23@@ -118,7 +120,7 @@ struct wld_buffer * surface_back(struct wld_surface * base)
24 
25     buffer = wld_create_buffer(surface->context,
26                                surface->width, surface->height,
27-                               surface->format);
28+                               surface->format, surface->flags);
29 
30     if (!buffer)
31         goto error0;
+4, -4
 1@@ -38,9 +38,9 @@ struct wld_renderer * wld_create_renderer(struct wld_context * context)
 2 EXPORT
 3 struct wld_buffer * wld_create_buffer(struct wld_context * context,
 4                                       uint32_t width, uint32_t height,
 5-                                      uint32_t format)
 6+                                      uint32_t format, uint32_t flags)
 7 {
 8-    return context->impl->create_buffer(context, width, height, format);
 9+    return context->impl->create_buffer(context, width, height, format, flags);
10 }
11 
12 EXPORT
13@@ -56,9 +56,9 @@ struct wld_buffer * wld_import_buffer(struct wld_context * context,
14 EXPORT
15 struct wld_surface * wld_create_surface(struct wld_context * context,
16                                         uint32_t width, uint32_t height,
17-                                        uint32_t format)
18+                                        uint32_t format, uint32_t flags)
19 {
20-    return context->impl->create_surface(context, width, height, format);
21+    return context->impl->create_surface(context, width, height, format, flags);
22 }
23 
24 EXPORT
M drm.h
+6, -0
 1@@ -34,6 +34,12 @@ enum wld_drm_object_type
 2     WLD_DRM_OBJECT_GEM_NAME = 0x00010002
 3 };
 4 
 5+enum wld_drm_flags
 6+{
 7+    WLD_DRM_FLAG_SCANOUT    = 0x1,
 8+    WLD_DRM_FLAG_TILED      = 0x2
 9+};
10+
11 /**
12  * Create a new WLD context from an opened DRM device file descriptor.
13  */
M dumb.c
+1, -1
1@@ -101,7 +101,7 @@ static struct wld_buffer * new_buffer(struct dumb_context * context,
2 
3 struct wld_buffer * context_create_buffer(struct wld_context * base,
4                                           uint32_t width, uint32_t height,
5-                                          uint32_t format)
6+                                          uint32_t format, uint32_t flags)
7 {
8     struct dumb_context * context = dumb_context(base);
9     struct wld_buffer * buffer;
+1, -1
1@@ -131,7 +131,7 @@ static struct wld_buffer * new_buffer(uint32_t width, uint32_t height,
2 
3 struct wld_buffer * context_create_buffer(struct wld_context * base,
4                                           uint32_t width, uint32_t height,
5-                                          uint32_t format)
6+                                          uint32_t format, uint32_t flags)
7 {
8     struct intel_context * context = intel_context(base);
9     struct wld_buffer * buffer;
+2, -2
 1@@ -25,14 +25,14 @@ static struct wld_renderer * context_create_renderer
 2     (struct wld_context * context);
 3 static struct wld_buffer * context_create_buffer
 4     (struct wld_context * context,
 5-     uint32_t width, uint32_t height, uint32_t format);
 6+     uint32_t width, uint32_t height, uint32_t format, uint32_t flags);
 7 static struct wld_buffer * context_import_buffer
 8     (struct wld_context * context, uint32_t type, union wld_object object,
 9      uint32_t width, uint32_t height, uint32_t format, uint32_t pitch);
10 #ifdef CONTEXT_IMPLEMENTS_CREATE_SURFACE
11 static struct wld_surface * context_create_surface
12     (struct wld_context * context,
13-     uint32_t width, uint32_t height, uint32_t format);
14+     uint32_t width, uint32_t height, uint32_t format, uint32_t flags);
15 #endif
16 static void context_destroy(struct wld_context * context);
17 
+8, -10
 1@@ -290,34 +290,32 @@ static inline uint32_t roundup(uint32_t value, uint32_t alignment)
 2 
 3 struct wld_buffer * context_create_buffer(struct wld_context * base,
 4                                           uint32_t width, uint32_t height,
 5-                                          uint32_t format)
 6+                                          uint32_t format, uint32_t flags)
 7 {
 8     struct nouveau_context * context = nouveau_context(base);
 9     struct nouveau_buffer * buffer;
10     uint32_t bpp = format_bytes_per_pixel(format),
11-             pitch = roundup(width * bpp, 64), flags;
12+             pitch = roundup(width * bpp, 64), bo_flags;
13     union nouveau_bo_config config = { };
14 
15     if (!(buffer = new_buffer(context, width, height, format, pitch)))
16         goto error0;
17 
18-    flags = NOUVEAU_BO_VRAM;
19+    bo_flags = NOUVEAU_BO_VRAM;
20 
21-    /* FIXME: Only need CONTIG for scanout buffers */
22-    flags |= NOUVEAU_BO_CONTIG;
23+    if (flags & WLD_DRM_FLAG_SCANOUT)
24+        bo_flags |= NOUVEAU_BO_CONTIG;
25 
26-    /* FIXME: Use tiling
27-    if (height > 0x40)
28+    if (height > 0x40 && !(flags & WLD_FLAG_MAP))
29     {
30         config.nvc0.tile_mode = 0x40;
31         config.nvc0.memtype = 0xfe;
32         height = roundup(height, 0x80);
33     }
34     else
35-    */
36-        flags |= NOUVEAU_BO_MAP;
37+        bo_flags |= NOUVEAU_BO_MAP;
38 
39-    if (nouveau_bo_new(context->device, flags, 0, pitch * height,
40+    if (nouveau_bo_new(context->device, bo_flags, 0, pitch * height,
41                        &config, &buffer->bo) != 0)
42     {
43         goto error1;
+1, -1
1@@ -105,7 +105,7 @@ static struct wld_buffer * new_buffer(pixman_image_t * image)
2 
3 struct wld_buffer * context_create_buffer(struct wld_context * context,
4                                           uint32_t width, uint32_t height,
5-                                          uint32_t format)
6+                                          uint32_t format, uint32_t flags)
7 {
8     struct wld_buffer * buffer;
9     pixman_image_t * image;
+2, -2
 1@@ -25,9 +25,9 @@
 2 
 3 struct wld_surface * default_create_surface(struct wld_context * context,
 4                                             uint32_t width, uint32_t height,
 5-                                            uint32_t format)
 6+                                            uint32_t format, uint32_t flags)
 7 {
 8-    return buffered_surface_create(context, width, height, format, NULL);
 9+    return buffered_surface_create(context, width, height, format, flags, NULL);
10 }
11 
12 void surface_initialize(struct wld_surface * surface,
+3, -2
 1@@ -191,7 +191,7 @@ struct wld_renderer * context_create_renderer(struct wld_context * base)
 2 
 3 struct wld_buffer * context_create_buffer(struct wld_context * base,
 4                                           uint32_t width, uint32_t height,
 5-                                          uint32_t format)
 6+                                          uint32_t format, uint32_t flags)
 7 {
 8     struct drm_context * context = drm_context(base);
 9     struct wld_buffer * buffer;
10@@ -202,7 +202,8 @@ struct wld_buffer * context_create_buffer(struct wld_context * base,
11     if (!wld_wayland_drm_has_format(base, format))
12         goto error0;
13 
14-    buffer = wld_create_buffer(context->driver_context, width, height, format);
15+    buffer = wld_create_buffer(context->driver_context, width, height,
16+                               format, flags);
17 
18     if (!buffer)
19         goto error0;
+1, -1
1@@ -160,7 +160,7 @@ struct wld_renderer * context_create_renderer(struct wld_context * context)
2 
3 struct wld_buffer * context_create_buffer(struct wld_context * base,
4                                           uint32_t width, uint32_t height,
5-                                          uint32_t format)
6+                                          uint32_t format, uint32_t flags)
7 {
8     struct shm_context * context = shm_context(base);
9     struct shm_buffer * buffer;
+2, -2
 1@@ -158,7 +158,7 @@ struct wld_context * wld_wayland_create_context
 2 EXPORT
 3 struct wld_surface * wld_wayland_create_surface(struct wld_context * context,
 4                                                 uint32_t width, uint32_t height,
 5-                                                uint32_t format,
 6+                                                uint32_t format, uint32_t flags,
 7                                                 struct wl_surface * wl)
 8 {
 9     struct wayland_buffer_socket * socket;
10@@ -172,7 +172,7 @@ struct wld_surface * wld_wayland_create_surface(struct wld_context * context,
11     socket->queue = ((struct wayland_context *) context)->queue;
12     socket->display = ((struct wayland_context *) context)->display;
13     socket->surface = buffered_surface_create(context, width, height, format,
14-                                              &socket->base);
15+                                              flags, &socket->base);
16 
17     if (!socket->surface)
18         goto error1;
+1, -1
1@@ -67,7 +67,7 @@ struct wld_context * wld_wayland_create_context
2 
3 struct wld_surface * wld_wayland_create_surface(struct wld_context * context,
4                                                 uint32_t width, uint32_t height,
5-                                                uint32_t format,
6+                                                uint32_t format, uint32_t flags,
7                                                 struct wl_surface * surface);
8 
9 #endif
+4, -4
 1@@ -86,7 +86,7 @@ struct wld_context_impl
 2     struct wld_renderer * (* create_renderer)(struct wld_context * context);
 3     struct wld_buffer * (* create_buffer)(struct wld_context * context,
 4                                           uint32_t width, uint32_t height,
 5-                                          uint32_t format);
 6+                                          uint32_t format, uint32_t flags);
 7     struct wld_buffer * (* import_buffer)(struct wld_context * context,
 8                                           uint32_t type,
 9                                           union wld_object object,
10@@ -94,7 +94,7 @@ struct wld_context_impl
11                                           uint32_t format, uint32_t pitch);
12     struct wld_surface * (* create_surface)(struct wld_context * context,
13                                             uint32_t width, uint32_t height,
14-                                            uint32_t format);
15+                                            uint32_t format, uint32_t flags);
16     void (* destroy)(struct wld_context * context);
17 };
18 
19@@ -229,11 +229,11 @@ void default_copy_region(struct wld_renderer * renderer,
20 
21 struct wld_surface * default_create_surface(struct wld_context * context,
22                                             uint32_t width, uint32_t height,
23-                                            uint32_t format);
24+                                            uint32_t format, uint32_t flags);
25 
26 struct wld_surface * buffered_surface_create(struct wld_context * context,
27                                              uint32_t width, uint32_t height,
28-                                             uint32_t format,
29+                                             uint32_t format, uint32_t flags,
30                                              struct wld_buffer_socket * socket);
31 
32 void context_initialize(struct wld_context * context,
M wld.h
+7, -2
 1@@ -45,6 +45,11 @@ enum wld_format
 2     WLD_FORMAT_ARGB8888 = __WLD_FOURCC('A', 'R', '2', '4')
 3 };
 4 
 5+enum wld_flags
 6+{
 7+    WLD_FLAG_MAP = 0x1 << 16
 8+};
 9+
10 bool wld_lookup_named_color(const char * name, uint32_t * color);
11 
12 /**** WLD Context ****/
13@@ -70,7 +75,7 @@ struct wld_renderer * wld_create_renderer(struct wld_context * context);
14 
15 struct wld_buffer * wld_create_buffer(struct wld_context * context,
16                                       uint32_t width, uint32_t height,
17-                                      uint32_t format);
18+                                      uint32_t format, uint32_t flags);
19 
20 struct wld_buffer * wld_import_buffer(struct wld_context * context,
21                                       uint32_t type, union wld_object object,
22@@ -79,7 +84,7 @@ struct wld_buffer * wld_import_buffer(struct wld_context * context,
23 
24 struct wld_surface * wld_create_surface(struct wld_context * context,
25                                         uint32_t width, uint32_t height,
26-                                        uint32_t format);
27+                                        uint32_t format, uint32_t flags);
28 
29 void wld_destroy_context(struct wld_context * context);
30