* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* DRI2 flush extension.
*/
static void
-dri2_flush_drawable(__DRIdrawable *draw)
+dri2_flush_drawable(__DRIdrawable *dPriv)
{
+ dri_flush(dPriv->driContextPriv, dPriv, __DRI2_FLUSH_DRAWABLE, 0);
}
static void
dri2_invalidate_drawable(__DRIdrawable *dPriv)
{
struct dri_drawable *drawable = dri_drawable(dPriv);
- struct dri_context *ctx = drawable->context;
dri2InvalidateDrawable(dPriv);
- drawable->dPriv->lastStamp = *drawable->dPriv->pStamp;
+ drawable->dPriv->lastStamp = drawable->dPriv->dri2.stamp;
- if (ctx)
- ctx->st->notify_invalid_framebuffer(ctx->st, &drawable->base);
+ p_atomic_inc(&drawable->base.stamp);
}
static const __DRI2flushExtension dri2FlushExtension = {
{ __DRI2_FLUSH, __DRI2_FLUSH_VERSION },
dri2_flush_drawable,
dri2_invalidate_drawable,
+ dri_flush,
};
/**
*/
static __DRIbuffer *
dri2_drawable_get_buffers(struct dri_drawable *drawable,
- const enum st_attachment_type *statts,
+ const enum st_attachment_type *atts,
unsigned *count)
{
__DRIdrawable *dri_drawable = drawable->dPriv;
for (i = 0; i < *count; i++) {
enum pipe_format format;
unsigned bind;
- int att, bpp;
+ int att, depth;
- dri_drawable_get_format(drawable, statts[i], &format, &bind);
+ dri_drawable_get_format(drawable, atts[i], &format, &bind);
if (format == PIPE_FORMAT_NONE)
continue;
- switch (statts[i]) {
+ switch (atts[i]) {
case ST_ATTACHMENT_FRONT_LEFT:
/* already added */
if (!with_format)
case ST_ATTACHMENT_BACK_RIGHT:
att = __DRI_BUFFER_BACK_RIGHT;
break;
- case ST_ATTACHMENT_DEPTH_STENCIL:
- att = __DRI_BUFFER_DEPTH_STENCIL;
- break;
default:
- att = -1;
- break;
+ continue;
}
- bpp = util_format_get_blocksizebits(format);
+ /*
+ * In this switch statement we must support all formats that
+ * may occur as the stvis->color_format.
+ */
+ switch(format) {
+ case PIPE_FORMAT_B8G8R8A8_UNORM:
+ depth = 32;
+ break;
+ case PIPE_FORMAT_B8G8R8X8_UNORM:
+ depth = 24;
+ break;
+ case PIPE_FORMAT_B5G6R5_UNORM:
+ depth = 16;
+ break;
+ default:
+ depth = util_format_get_blocksizebits(format);
+ assert(!"Unexpected format in dri2_drawable_get_buffers()");
+ }
- if (att >= 0) {
- attachments[num_attachments++] = att;
- if (with_format) {
- attachments[num_attachments++] = bpp;
- }
+ attachments[num_attachments++] = att;
+ if (with_format) {
+ attachments[num_attachments++] = depth;
}
}
&num_buffers, dri_drawable->loaderPrivate);
}
- if (buffers) {
- /* set one cliprect to cover the whole dri_drawable */
- dri_drawable->x = 0;
- dri_drawable->y = 0;
- dri_drawable->backX = 0;
- dri_drawable->backY = 0;
- dri_drawable->numClipRects = 1;
- dri_drawable->pClipRects[0].x1 = 0;
- dri_drawable->pClipRects[0].y1 = 0;
- dri_drawable->pClipRects[0].x2 = dri_drawable->w;
- dri_drawable->pClipRects[0].y2 = dri_drawable->h;
- dri_drawable->numBackClipRects = 1;
- dri_drawable->pBackClipRects[0].x1 = 0;
- dri_drawable->pBackClipRects[0].y1 = 0;
- dri_drawable->pBackClipRects[0].x2 = dri_drawable->w;
- dri_drawable->pBackClipRects[0].y2 = dri_drawable->h;
-
+ if (buffers)
*count = num_buffers;
- }
return buffers;
}
*/
static void
dri2_drawable_process_buffers(struct dri_drawable *drawable,
- __DRIbuffer *buffers, unsigned count)
+ __DRIbuffer *buffers, unsigned buffer_count,
+ const enum st_attachment_type *atts,
+ unsigned att_count)
{
struct dri_screen *screen = dri_screen(drawable->sPriv);
__DRIdrawable *dri_drawable = drawable->dPriv;
struct pipe_resource templ;
struct winsys_handle whandle;
- boolean have_depth = FALSE;
+ boolean alloc_depthstencil = FALSE;
unsigned i, bind;
- if (drawable->old_num == count &&
+ if (drawable->old_num == buffer_count &&
drawable->old_w == dri_drawable->w &&
drawable->old_h == dri_drawable->h &&
- memcmp(drawable->old, buffers, sizeof(__DRIbuffer) * count) == 0)
+ memcmp(drawable->old, buffers, sizeof(__DRIbuffer) * buffer_count) == 0)
return;
for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
pipe_resource_reference(&drawable->textures[i], NULL);
+ for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
+ pipe_resource_reference(&drawable->msaa_textures[i], NULL);
memset(&templ, 0, sizeof(templ));
templ.target = screen->target;
memset(&whandle, 0, sizeof(whandle));
- for (i = 0; i < count; i++) {
+ /* Process DRI-provided buffers and get pipe_resources. */
+ for (i = 0; i < buffer_count; i++) {
__DRIbuffer *buf = &buffers[i];
enum st_attachment_type statt;
enum pipe_format format;
switch (buf->attachment) {
case __DRI_BUFFER_FRONT_LEFT:
if (!screen->auto_fake_front) {
- statt = ST_ATTACHMENT_INVALID;
- break;
+ continue; /* invalid attachment */
}
/* fallthrough */
case __DRI_BUFFER_FAKE_FRONT_LEFT:
case __DRI_BUFFER_BACK_LEFT:
statt = ST_ATTACHMENT_BACK_LEFT;
break;
- case __DRI_BUFFER_DEPTH:
- case __DRI_BUFFER_DEPTH_STENCIL:
- case __DRI_BUFFER_STENCIL:
- /* use only the first depth/stencil buffer */
- if (!have_depth) {
- have_depth = TRUE;
- statt = ST_ATTACHMENT_DEPTH_STENCIL;
- }
- else {
- statt = ST_ATTACHMENT_INVALID;
- }
- break;
default:
- statt = ST_ATTACHMENT_INVALID;
- break;
+ continue; /* invalid attachment */
}
dri_drawable_get_format(drawable, statt, &format, &bind);
- if (statt == ST_ATTACHMENT_INVALID || format == PIPE_FORMAT_NONE)
+ if (format == PIPE_FORMAT_NONE)
continue;
templ.format = format;
drawable->textures[statt] =
screen->base.screen->resource_from_handle(screen->base.screen,
&templ, &whandle);
+ assert(drawable->textures[statt]);
+ }
+
+ /* Allocate private MSAA colorbuffers. */
+ if (drawable->stvis.samples > 1) {
+ for (i = 0; i < att_count; i++) {
+ enum st_attachment_type att = atts[i];
+
+ if (drawable->textures[att]) {
+ templ.format = drawable->textures[att]->format;
+ templ.bind = drawable->textures[att]->bind;
+ templ.nr_samples = drawable->stvis.samples;
+
+ drawable->msaa_textures[att] =
+ screen->base.screen->resource_create(screen->base.screen,
+ &templ);
+ assert(drawable->msaa_textures[att]);
+ }
+ }
+ }
+
+ /* See if we need a depth-stencil buffer. */
+ for (i = 0; i < att_count; i++) {
+ if (atts[i] == ST_ATTACHMENT_DEPTH_STENCIL) {
+ alloc_depthstencil = TRUE;
+ break;
+ }
}
- drawable->old_num = count;
+ /* Allocate a private depth-stencil buffer. */
+ if (alloc_depthstencil) {
+ enum pipe_format format;
+ unsigned bind;
+
+ dri_drawable_get_format(drawable, ST_ATTACHMENT_DEPTH_STENCIL,
+ &format, &bind);
+ if (format) {
+ templ.format = format;
+ templ.bind = bind;
+
+ if (drawable->stvis.samples > 1) {
+ templ.nr_samples = drawable->stvis.samples;
+ drawable->msaa_textures[ST_ATTACHMENT_DEPTH_STENCIL] =
+ screen->base.screen->resource_create(screen->base.screen,
+ &templ);
+ assert(drawable->msaa_textures[ST_ATTACHMENT_DEPTH_STENCIL]);
+ }
+ else {
+ templ.nr_samples = 0;
+ drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL] =
+ screen->base.screen->resource_create(screen->base.screen,
+ &templ);
+ assert(drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL]);
+ }
+ }
+ }
+
+ drawable->old_num = buffer_count;
drawable->old_w = dri_drawable->w;
drawable->old_h = dri_drawable->h;
- memcpy(drawable->old, buffers, sizeof(__DRIbuffer) * count);
+ memcpy(drawable->old, buffers, sizeof(__DRIbuffer) * buffer_count);
}
static __DRIbuffer *
struct dri_screen *screen = dri_screen(sPriv);
struct dri2_buffer *buffer;
struct pipe_resource templ;
- enum st_attachment_type statt;
enum pipe_format pf;
unsigned bind = 0;
struct winsys_handle whandle;
switch (attachment) {
case __DRI_BUFFER_FRONT_LEFT:
case __DRI_BUFFER_FAKE_FRONT_LEFT:
- statt = ST_ATTACHMENT_FRONT_LEFT;
bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
break;
case __DRI_BUFFER_BACK_LEFT:
- statt = ST_ATTACHMENT_BACK_LEFT;
bind = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
break;
case __DRI_BUFFER_DEPTH:
case __DRI_BUFFER_DEPTH_STENCIL:
case __DRI_BUFFER_STENCIL:
- statt = ST_ATTACHMENT_DEPTH_STENCIL;
bind = PIPE_BIND_DEPTH_STENCIL; /* XXX sampler? */
break;
- default:
- statt = ST_ATTACHMENT_INVALID;
- break;
}
+ /* because we get the handle and stride */
+ bind |= PIPE_BIND_SHARED;
+
switch (format) {
case 32:
+ pf = PIPE_FORMAT_B8G8R8A8_UNORM;
+ break;
+ case 24:
pf = PIPE_FORMAT_B8G8R8X8_UNORM;
break;
case 16:
buffer->resource =
screen->base.screen->resource_create(screen->base.screen, &templ);
- if (!buffer->resource)
+ if (!buffer->resource) {
+ FREE(buffer);
return NULL;
+ }
memset(&whandle, 0, sizeof(whandle));
whandle.type = DRM_API_HANDLE_TYPE_SHARED;
static void
dri2_allocate_textures(struct dri_drawable *drawable,
const enum st_attachment_type *statts,
- unsigned count)
+ unsigned statts_count)
{
__DRIbuffer *buffers;
- unsigned num_buffers = count;
+ unsigned num_buffers = statts_count;
buffers = dri2_drawable_get_buffers(drawable, statts, &num_buffers);
if (buffers)
- dri2_drawable_process_buffers(drawable, buffers, num_buffers);
+ dri2_drawable_process_buffers(drawable, buffers, num_buffers,
+ statts, statts_count);
}
static void
-dri2_flush_frontbuffer(struct dri_drawable *drawable,
+dri2_flush_frontbuffer(struct dri_context *ctx,
+ struct dri_drawable *drawable,
enum st_attachment_type statt)
{
__DRIdrawable *dri_drawable = drawable->dPriv;
struct __DRIdri2LoaderExtensionRec *loader = drawable->sPriv->dri2.loader;
- if (loader->flushFrontBuffer == NULL)
+ if (statt != ST_ATTACHMENT_FRONT_LEFT)
return;
- if (statt == ST_ATTACHMENT_FRONT_LEFT) {
+ if (drawable->stvis.samples > 1) {
+ struct pipe_context *pipe = ctx->st->pipe;
+
+ dri_msaa_resolve(ctx, drawable, ST_ATTACHMENT_FRONT_LEFT);
+ pipe->flush(pipe, NULL, 0);
+ }
+
+ if (loader->flushFrontBuffer) {
loader->flushFrontBuffer(dri_drawable, dri_drawable->loaderPrivate);
}
}
+static void
+dri2_update_tex_buffer(struct dri_drawable *drawable,
+ struct dri_context *ctx,
+ struct pipe_resource *res)
+{
+ /* no-op */
+}
+
static __DRIimage *
dri2_lookup_egl_image(struct dri_screen *screen, void *handle)
{
case __DRI_IMAGE_FORMAT_ARGB8888:
pf = PIPE_FORMAT_B8G8R8A8_UNORM;
break;
+ case __DRI_IMAGE_FORMAT_ABGR8888:
+ pf = PIPE_FORMAT_R8G8B8A8_UNORM;
+ break;
default:
pf = PIPE_FORMAT_NONE;
break;
img->level = 0;
img->layer = 0;
+ img->dri_format = format;
img->loader_private = loaderPrivate;
return img;
case __DRI_IMAGE_FORMAT_ARGB8888:
pf = PIPE_FORMAT_B8G8R8A8_UNORM;
break;
+ case __DRI_IMAGE_FORMAT_ABGR8888:
+ pf = PIPE_FORMAT_R8G8B8A8_UNORM;
+ break;
default:
pf = PIPE_FORMAT_NONE;
break;
img->level = 0;
img->layer = 0;
+ img->dri_format = format;
+ img->dri_components = 0;
img->loader_private = loaderPrivate;
return img;
image->texture, &whandle);
*value = whandle.handle;
return GL_TRUE;
+ case __DRI_IMAGE_ATTRIB_FORMAT:
+ *value = image->dri_format;
+ return GL_TRUE;
+ case __DRI_IMAGE_ATTRIB_WIDTH:
+ *value = image->texture->width0;
+ return GL_TRUE;
+ case __DRI_IMAGE_ATTRIB_HEIGHT:
+ *value = image->texture->height0;
+ return GL_TRUE;
+ case __DRI_IMAGE_ATTRIB_COMPONENTS:
+ if (image->dri_components == 0)
+ return GL_FALSE;
+ *value = image->dri_components;
+ return GL_TRUE;
default:
return GL_FALSE;
}
pipe_resource_reference(&img->texture, image->texture);
img->level = image->level;
img->layer = image->layer;
+ /* This should be 0 for sub images, but dup is also used for base images. */
+ img->dri_components = image->dri_components;
img->loader_private = loaderPrivate;
return img;
}
+static GLboolean
+dri2_validate_usage(__DRIimage *image, unsigned int use)
+{
+ /*
+ * Gallium drivers are bad at adding usages to the resources
+ * once opened again in another process, which is the main use
+ * case for this, so we have to lie.
+ */
+ if (image != NULL)
+ return GL_TRUE;
+ else
+ return GL_FALSE;
+}
+
+static __DRIimage *
+dri2_from_names(__DRIscreen *screen, int width, int height, int format,
+ int *names, int num_names, int *strides, int *offsets,
+ void *loaderPrivate)
+{
+ __DRIimage *img;
+ int stride, dri_components;
+
+ if (num_names != 1)
+ return NULL;
+ if (offsets[0] != 0)
+ return NULL;
+
+ switch(format) {
+ case __DRI_IMAGE_FOURCC_RGB565:
+ format = __DRI_IMAGE_FORMAT_RGB565;
+ dri_components = __DRI_IMAGE_COMPONENTS_RGB;
+ break;
+ case __DRI_IMAGE_FOURCC_ARGB8888:
+ format = __DRI_IMAGE_FORMAT_ARGB8888;
+ dri_components = __DRI_IMAGE_COMPONENTS_RGBA;
+ break;
+ case __DRI_IMAGE_FOURCC_XRGB8888:
+ format = __DRI_IMAGE_FORMAT_XRGB8888;
+ dri_components = __DRI_IMAGE_COMPONENTS_RGB;
+ break;
+ case __DRI_IMAGE_FOURCC_ABGR8888:
+ format = __DRI_IMAGE_FORMAT_ABGR8888;
+ dri_components = __DRI_IMAGE_COMPONENTS_RGBA;
+ break;
+ case __DRI_IMAGE_FOURCC_XBGR8888:
+ format = __DRI_IMAGE_FORMAT_XBGR8888;
+ dri_components = __DRI_IMAGE_COMPONENTS_RGB;
+ break;
+ default:
+ return NULL;
+ }
+
+ /* Strides are in bytes not pixels. */
+ stride = strides[0] /4;
+
+ img = dri2_create_image_from_name(screen, width, height, format,
+ names[0], stride, loaderPrivate);
+ if (img == NULL)
+ return NULL;
+
+ img->dri_components = dri_components;
+ return img;
+}
+
+static __DRIimage *
+dri2_from_planar(__DRIimage *image, int plane, void *loaderPrivate)
+{
+ __DRIimage *img;
+
+ if (plane != 0)
+ return NULL;
+
+ if (image->dri_components == 0)
+ return NULL;
+
+ img = dri2_dup_image(image, loaderPrivate);
+ if (img == NULL)
+ return NULL;
+
+ /* set this to 0 for sub images. */
+ img->dri_components = 0;
+ return img;
+}
+
static void
dri2_destroy_image(__DRIimage *img)
{
}
static struct __DRIimageExtensionRec dri2ImageExtension = {
- { __DRI_IMAGE, __DRI_IMAGE_VERSION },
+ { __DRI_IMAGE, 5 },
dri2_create_image_from_name,
dri2_create_image_from_renderbuffer,
dri2_destroy_image,
dri2_create_image,
dri2_query_image,
dri2_dup_image,
+ dri2_validate_usage,
+ dri2_from_names,
+ dri2_from_planar,
};
/*
*/
static const __DRIextension *dri_screen_extensions[] = {
- &driReadDrawableExtension,
- &driCopySubBufferExtension.base,
- &driSwapControlExtension.base,
- &driMediaStreamCounterExtension.base,
&driTexBufferExtension.base,
&dri2FlushExtension.base,
&dri2ImageExtension.base,
&dri2ConfigQueryExtension.base,
+ &dri2ThrottleExtension.base,
NULL
};
const __DRIconfig **configs;
struct dri_screen *screen;
struct pipe_screen *pscreen;
+ const struct drm_conf_ret *throttle_ret = NULL;
screen = CALLOC_STRUCT(dri_screen);
if (!screen)
screen->sPriv = sPriv;
screen->fd = sPriv->fd;
- sPriv->private = (void *)screen;
- sPriv->extensions = dri_screen_extensions;
+ sPriv->driverPrivate = (void *)screen;
pscreen = driver_descriptor.create_screen(screen->fd);
+ if (driver_descriptor.configuration)
+ throttle_ret = driver_descriptor.configuration(DRM_CONF_THROTTLE);
+
+ if (throttle_ret && throttle_ret->val.val_int != -1) {
+ screen->throttling_enabled = TRUE;
+ screen->default_throttle_frames = throttle_ret->val.val_int;
+ }
+
+ sPriv->extensions = dri_screen_extensions;
+
/* dri_init_screen_helper checks pscreen for us */
- configs = dri_init_screen_helper(screen, pscreen, 32);
+ configs = dri_init_screen_helper(screen, pscreen);
if (!configs)
goto fail;
return NULL;
}
-static boolean
-dri2_create_context(gl_api api, const struct gl_config * visual,
- __DRIcontext * cPriv, void *sharedContextPrivate)
-{
- struct dri_context *ctx = NULL;
-
- if (!dri_create_context(api, visual, cPriv, sharedContextPrivate))
- return FALSE;
-
- ctx = cPriv->driverPrivate;
-
- return TRUE;
-}
-
static boolean
dri2_create_buffer(__DRIscreen * sPriv,
__DRIdrawable * dPriv,
drawable->allocate_textures = dri2_allocate_textures;
drawable->flush_frontbuffer = dri2_flush_frontbuffer;
+ drawable->update_tex_buffer = dri2_update_tex_buffer;
return TRUE;
}
* DRI versions differ in their implementation of init_screen and swap_buffers.
*/
const struct __DriverAPIRec driDriverAPI = {
- .InitScreen = NULL,
- .InitScreen2 = dri2_init_screen,
+ .InitScreen = dri2_init_screen,
.DestroyScreen = dri_destroy_screen,
- .CreateContext = dri2_create_context,
+ .CreateContext = dri_create_context,
.DestroyContext = dri_destroy_context,
.CreateBuffer = dri2_create_buffer,
.DestroyBuffer = dri_destroy_buffer,
.MakeCurrent = dri_make_current,
.UnbindContext = dri_unbind_context,
- .GetSwapInfo = NULL,
- .GetDrawableMSC = NULL,
- .WaitForMSC = NULL,
-
- .SwapBuffers = NULL,
- .CopySubBuffer = NULL,
-
.AllocateBuffer = dri2_allocate_buffer,
.ReleaseBuffer = dri2_release_buffer,
};
/* This is the table of extensions that the loader will dlsym() for. */
PUBLIC const __DRIextension *__driDriverExtensions[] = {
&driCoreExtension.base,
- &driLegacyExtension.base,
&driDRI2Extension.base,
NULL
};