commit e52798423a42df725b4a528852a254ac5e44621a
parent b5f5dc9b09650f030c0ef2a3e41531d90891fa31
Author: Michael Forney <mforney@mforney.org>
Date: Fri, 31 Jan 2014 12:11:24 -0800
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.
Diffstat:
15 files changed, 47 insertions(+), 35 deletions(-)
diff --git a/buffered_surface.c b/buffered_surface.c
@@ -44,11 +44,12 @@ struct buffered_surface
uint32_t width, height;
enum wld_format format;
+ uint32_t flags;
};
struct wld_surface * buffered_surface_create
(struct wld_context * context, uint32_t width, uint32_t height,
- uint32_t format, struct wld_buffer_socket * buffer_socket)
+ uint32_t format, uint32_t flags, struct wld_buffer_socket * buffer_socket)
{
struct buffered_surface * surface;
@@ -65,6 +66,7 @@ struct wld_surface * buffered_surface_create
surface->width = width;
surface->height = height;
surface->format = format;
+ surface->flags = flags;
return &surface->base;
}
@@ -118,7 +120,7 @@ struct wld_buffer * surface_back(struct wld_surface * base)
buffer = wld_create_buffer(surface->context,
surface->width, surface->height,
- surface->format);
+ surface->format, surface->flags);
if (!buffer)
goto error0;
diff --git a/context.c b/context.c
@@ -38,9 +38,9 @@ struct wld_renderer * wld_create_renderer(struct wld_context * context)
EXPORT
struct wld_buffer * wld_create_buffer(struct wld_context * context,
uint32_t width, uint32_t height,
- uint32_t format)
+ uint32_t format, uint32_t flags)
{
- return context->impl->create_buffer(context, width, height, format);
+ return context->impl->create_buffer(context, width, height, format, flags);
}
EXPORT
@@ -56,9 +56,9 @@ struct wld_buffer * wld_import_buffer(struct wld_context * context,
EXPORT
struct wld_surface * wld_create_surface(struct wld_context * context,
uint32_t width, uint32_t height,
- uint32_t format)
+ uint32_t format, uint32_t flags)
{
- return context->impl->create_surface(context, width, height, format);
+ return context->impl->create_surface(context, width, height, format, flags);
}
EXPORT
diff --git a/drm.h b/drm.h
@@ -34,6 +34,12 @@ enum wld_drm_object_type
WLD_DRM_OBJECT_GEM_NAME = 0x00010002
};
+enum wld_drm_flags
+{
+ WLD_DRM_FLAG_SCANOUT = 0x1,
+ WLD_DRM_FLAG_TILED = 0x2
+};
+
/**
* Create a new WLD context from an opened DRM device file descriptor.
*/
diff --git a/dumb.c b/dumb.c
@@ -101,7 +101,7 @@ static struct wld_buffer * new_buffer(struct dumb_context * context,
struct wld_buffer * context_create_buffer(struct wld_context * base,
uint32_t width, uint32_t height,
- uint32_t format)
+ uint32_t format, uint32_t flags)
{
struct dumb_context * context = dumb_context(base);
struct wld_buffer * buffer;
diff --git a/intel.c b/intel.c
@@ -131,7 +131,7 @@ static struct wld_buffer * new_buffer(uint32_t width, uint32_t height,
struct wld_buffer * context_create_buffer(struct wld_context * base,
uint32_t width, uint32_t height,
- uint32_t format)
+ uint32_t format, uint32_t flags)
{
struct intel_context * context = intel_context(base);
struct wld_buffer * buffer;
diff --git a/interface/context.h b/interface/context.h
@@ -25,14 +25,14 @@ static struct wld_renderer * context_create_renderer
(struct wld_context * context);
static struct wld_buffer * context_create_buffer
(struct wld_context * context,
- uint32_t width, uint32_t height, uint32_t format);
+ uint32_t width, uint32_t height, uint32_t format, uint32_t flags);
static struct wld_buffer * context_import_buffer
(struct wld_context * context, uint32_t type, union wld_object object,
uint32_t width, uint32_t height, uint32_t format, uint32_t pitch);
#ifdef CONTEXT_IMPLEMENTS_CREATE_SURFACE
static struct wld_surface * context_create_surface
(struct wld_context * context,
- uint32_t width, uint32_t height, uint32_t format);
+ uint32_t width, uint32_t height, uint32_t format, uint32_t flags);
#endif
static void context_destroy(struct wld_context * context);
diff --git a/nouveau.c b/nouveau.c
@@ -290,34 +290,32 @@ static inline uint32_t roundup(uint32_t value, uint32_t alignment)
struct wld_buffer * context_create_buffer(struct wld_context * base,
uint32_t width, uint32_t height,
- uint32_t format)
+ uint32_t format, uint32_t flags)
{
struct nouveau_context * context = nouveau_context(base);
struct nouveau_buffer * buffer;
uint32_t bpp = format_bytes_per_pixel(format),
- pitch = roundup(width * bpp, 64), flags;
+ pitch = roundup(width * bpp, 64), bo_flags;
union nouveau_bo_config config = { };
if (!(buffer = new_buffer(context, width, height, format, pitch)))
goto error0;
- flags = NOUVEAU_BO_VRAM;
+ bo_flags = NOUVEAU_BO_VRAM;
- /* FIXME: Only need CONTIG for scanout buffers */
- flags |= NOUVEAU_BO_CONTIG;
+ if (flags & WLD_DRM_FLAG_SCANOUT)
+ bo_flags |= NOUVEAU_BO_CONTIG;
- /* FIXME: Use tiling
- if (height > 0x40)
+ if (height > 0x40 && !(flags & WLD_FLAG_MAP))
{
config.nvc0.tile_mode = 0x40;
config.nvc0.memtype = 0xfe;
height = roundup(height, 0x80);
}
else
- */
- flags |= NOUVEAU_BO_MAP;
+ bo_flags |= NOUVEAU_BO_MAP;
- if (nouveau_bo_new(context->device, flags, 0, pitch * height,
+ if (nouveau_bo_new(context->device, bo_flags, 0, pitch * height,
&config, &buffer->bo) != 0)
{
goto error1;
diff --git a/pixman.c b/pixman.c
@@ -105,7 +105,7 @@ static struct wld_buffer * new_buffer(pixman_image_t * image)
struct wld_buffer * context_create_buffer(struct wld_context * context,
uint32_t width, uint32_t height,
- uint32_t format)
+ uint32_t format, uint32_t flags)
{
struct wld_buffer * buffer;
pixman_image_t * image;
diff --git a/surface.c b/surface.c
@@ -25,9 +25,9 @@
struct wld_surface * default_create_surface(struct wld_context * context,
uint32_t width, uint32_t height,
- uint32_t format)
+ uint32_t format, uint32_t flags)
{
- return buffered_surface_create(context, width, height, format, NULL);
+ return buffered_surface_create(context, width, height, format, flags, NULL);
}
void surface_initialize(struct wld_surface * surface,
diff --git a/wayland-drm.c b/wayland-drm.c
@@ -191,7 +191,7 @@ struct wld_renderer * context_create_renderer(struct wld_context * base)
struct wld_buffer * context_create_buffer(struct wld_context * base,
uint32_t width, uint32_t height,
- uint32_t format)
+ uint32_t format, uint32_t flags)
{
struct drm_context * context = drm_context(base);
struct wld_buffer * buffer;
@@ -202,7 +202,8 @@ struct wld_buffer * context_create_buffer(struct wld_context * base,
if (!wld_wayland_drm_has_format(base, format))
goto error0;
- buffer = wld_create_buffer(context->driver_context, width, height, format);
+ buffer = wld_create_buffer(context->driver_context, width, height,
+ format, flags);
if (!buffer)
goto error0;
diff --git a/wayland-shm.c b/wayland-shm.c
@@ -160,7 +160,7 @@ struct wld_renderer * context_create_renderer(struct wld_context * context)
struct wld_buffer * context_create_buffer(struct wld_context * base,
uint32_t width, uint32_t height,
- uint32_t format)
+ uint32_t format, uint32_t flags)
{
struct shm_context * context = shm_context(base);
struct shm_buffer * buffer;
diff --git a/wayland.c b/wayland.c
@@ -158,7 +158,7 @@ struct wld_context * wld_wayland_create_context
EXPORT
struct wld_surface * wld_wayland_create_surface(struct wld_context * context,
uint32_t width, uint32_t height,
- uint32_t format,
+ uint32_t format, uint32_t flags,
struct wl_surface * wl)
{
struct wayland_buffer_socket * socket;
@@ -172,7 +172,7 @@ struct wld_surface * wld_wayland_create_surface(struct wld_context * context,
socket->queue = ((struct wayland_context *) context)->queue;
socket->display = ((struct wayland_context *) context)->display;
socket->surface = buffered_surface_create(context, width, height, format,
- &socket->base);
+ flags, &socket->base);
if (!socket->surface)
goto error1;
diff --git a/wayland.h b/wayland.h
@@ -67,7 +67,7 @@ struct wld_context * wld_wayland_create_context
struct wld_surface * wld_wayland_create_surface(struct wld_context * context,
uint32_t width, uint32_t height,
- uint32_t format,
+ uint32_t format, uint32_t flags,
struct wl_surface * surface);
#endif
diff --git a/wld-private.h b/wld-private.h
@@ -86,7 +86,7 @@ struct wld_context_impl
struct wld_renderer * (* create_renderer)(struct wld_context * context);
struct wld_buffer * (* create_buffer)(struct wld_context * context,
uint32_t width, uint32_t height,
- uint32_t format);
+ uint32_t format, uint32_t flags);
struct wld_buffer * (* import_buffer)(struct wld_context * context,
uint32_t type,
union wld_object object,
@@ -94,7 +94,7 @@ struct wld_context_impl
uint32_t format, uint32_t pitch);
struct wld_surface * (* create_surface)(struct wld_context * context,
uint32_t width, uint32_t height,
- uint32_t format);
+ uint32_t format, uint32_t flags);
void (* destroy)(struct wld_context * context);
};
@@ -229,11 +229,11 @@ void default_copy_region(struct wld_renderer * renderer,
struct wld_surface * default_create_surface(struct wld_context * context,
uint32_t width, uint32_t height,
- uint32_t format);
+ uint32_t format, uint32_t flags);
struct wld_surface * buffered_surface_create(struct wld_context * context,
uint32_t width, uint32_t height,
- uint32_t format,
+ uint32_t format, uint32_t flags,
struct wld_buffer_socket * socket);
void context_initialize(struct wld_context * context,
diff --git a/wld.h b/wld.h
@@ -45,6 +45,11 @@ enum wld_format
WLD_FORMAT_ARGB8888 = __WLD_FOURCC('A', 'R', '2', '4')
};
+enum wld_flags
+{
+ WLD_FLAG_MAP = 0x1 << 16
+};
+
bool wld_lookup_named_color(const char * name, uint32_t * color);
/**** WLD Context ****/
@@ -70,7 +75,7 @@ struct wld_renderer * wld_create_renderer(struct wld_context * context);
struct wld_buffer * wld_create_buffer(struct wld_context * context,
uint32_t width, uint32_t height,
- uint32_t format);
+ uint32_t format, uint32_t flags);
struct wld_buffer * wld_import_buffer(struct wld_context * context,
uint32_t type, union wld_object object,
@@ -79,7 +84,7 @@ struct wld_buffer * wld_import_buffer(struct wld_context * context,
struct wld_surface * wld_create_surface(struct wld_context * context,
uint32_t width, uint32_t height,
- uint32_t format);
+ uint32_t format, uint32_t flags);
void wld_destroy_context(struct wld_context * context);