radeonsi: add 2d tiling support for texture v3
[mesa.git] / src / gallium / state_trackers / vdpau / bitmap.c
index c2c8a448ce625d56c62e1126c08656e1f048452b..469f3e8996424338ae5494aaaed8b6c5a9936a30 100644 (file)
@@ -69,7 +69,6 @@ vlVdpBitmapSurfaceCreate(VdpDevice device,
    vlsurface->device = dev;
 
    memset(&res_tmpl, 0, sizeof(res_tmpl));
-
    res_tmpl.target = PIPE_TEXTURE_2D;
    res_tmpl.format = FormatRGBAToPipe(rgba_format);
    res_tmpl.width0 = width;
@@ -78,30 +77,33 @@ vlVdpBitmapSurfaceCreate(VdpDevice device,
    res_tmpl.array_size = 1;
    res_tmpl.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
    res_tmpl.usage = frequently_accessed ? PIPE_USAGE_DYNAMIC : PIPE_USAGE_STATIC;
+
+   pipe_mutex_lock(dev->mutex);
    res = pipe->screen->resource_create(pipe->screen, &res_tmpl);
    if (!res) {
+      pipe_mutex_unlock(dev->mutex);
       FREE(dev);
+      FREE(vlsurface);
       return VDP_STATUS_RESOURCES;
    }
 
-   memset(&sv_templ, 0, sizeof(sv_templ));
-   u_sampler_view_default_template(&sv_templ, res, res->format);
+   vlVdpDefaultSamplerViewTemplate(&sv_templ, res);
    vlsurface->sampler_view = pipe->create_sampler_view(pipe, res, &sv_templ);
+
+   pipe_resource_reference(&res, NULL);
+   pipe_mutex_unlock(dev->mutex);
+
    if (!vlsurface->sampler_view) {
-      pipe_resource_reference(&res, NULL);
       FREE(dev);
       return VDP_STATUS_RESOURCES;
    }
 
    *surface = vlAddDataHTAB(vlsurface);
    if (*surface == 0) {
-      pipe_resource_reference(&res, NULL);
       FREE(dev);
       return VDP_STATUS_ERROR;
    }
 
-   pipe_resource_reference(&res, NULL);
-
    return VDP_STATUS_OK;
 }
 
@@ -117,9 +119,9 @@ vlVdpBitmapSurfaceDestroy(VdpBitmapSurface surface)
    if (!vlsurface)
       return VDP_STATUS_INVALID_HANDLE;
 
-   vlVdpResolveDelayedRendering(vlsurface->device, NULL, NULL);
-
+   pipe_mutex_lock(vlsurface->device->mutex);
    pipe_sampler_view_reference(&vlsurface->sampler_view, NULL);
+   pipe_mutex_unlock(vlsurface->device->mutex);
 
    vlRemoveDataHTAB(surface);
    FREE(vlsurface);
@@ -136,10 +138,23 @@ vlVdpBitmapSurfaceGetParameters(VdpBitmapSurface surface,
                                 uint32_t *width, uint32_t *height,
                                 VdpBool *frequently_accessed)
 {
+   vlVdpBitmapSurface *vlsurface;
+   struct pipe_resource *res;
+
+   vlsurface = vlGetDataHTAB(surface);
+   if (!vlsurface)
+      return VDP_STATUS_INVALID_HANDLE;
+
    if (!(rgba_format && width && height && frequently_accessed))
       return VDP_STATUS_INVALID_POINTER;
 
-   return VDP_STATUS_NO_IMPLEMENTATION;
+   res = vlsurface->sampler_view->texture;
+   *rgba_format = PipeToFormatRGBA(res->format);
+   *width = res->width0;
+   *height = res->height0;
+   *frequently_accessed = res->usage == PIPE_USAGE_DYNAMIC;
+
+   return VDP_STATUS_OK;
 }
 
 /**
@@ -165,24 +180,16 @@ vlVdpBitmapSurfacePutBitsNative(VdpBitmapSurface surface,
 
    pipe = vlsurface->device->context;
 
-   vlVdpResolveDelayedRendering(vlsurface->device, NULL, NULL);
+   pipe_mutex_lock(vlsurface->device->mutex);
 
-   dst_box.x = 0;
-   dst_box.y = 0;
-   dst_box.z = 0;
-   dst_box.width = vlsurface->sampler_view->texture->width0;
-   dst_box.height = vlsurface->sampler_view->texture->height0;
-   dst_box.depth = 1;
-
-   if (destination_rect) {
-      dst_box.x = MIN2(destination_rect->x0, destination_rect->x1);
-      dst_box.y = MIN2(destination_rect->y0, destination_rect->y1);
-      dst_box.width = abs(destination_rect->x1 - destination_rect->x0);
-      dst_box.height = abs(destination_rect->y1 - destination_rect->y0);
-   }
+   vlVdpResolveDelayedRendering(vlsurface->device, NULL, NULL);
 
+   dst_box = RectToPipeBox(destination_rect, vlsurface->sampler_view->texture);
    pipe->transfer_inline_write(pipe, vlsurface->sampler_view->texture, 0,
                                PIPE_TRANSFER_WRITE, &dst_box, *source_data,
                                *source_pitches, 0);
+
+   pipe_mutex_unlock(vlsurface->device->mutex);
+
    return VDP_STATUS_OK;
 }