gallium: add flags parameter to pipe_screen::context_create
[mesa.git] / src / gallium / state_trackers / vdpau / device.c
index 98106a1c70246d73d45e2c9e4549a00ae11f39a2..31c95054f569e13068e6c3ad0201bfe3639e2345 100644 (file)
@@ -18,7 +18,7 @@
  * 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 NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS 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.
 
 #include "util/u_memory.h"
 #include "util/u_debug.h"
+#include "util/u_format.h"
 #include "util/u_sampler.h"
 
-#include "vl_winsys.h"
-
 #include "vdpau_private.h"
 
 /**
@@ -43,6 +42,8 @@ vdp_imp_device_create_x11(Display *display, int screen, VdpDevice *device,
                           VdpGetProcAddress **get_proc_address)
 {
    struct pipe_screen *pscreen;
+   struct pipe_resource *res, res_tmpl;
+   struct pipe_sampler_view sv_tmpl;
    vlVdpDevice *dev = NULL;
    VdpStatus ret;
 
@@ -60,6 +61,8 @@ vdp_imp_device_create_x11(Display *display, int screen, VdpDevice *device,
       goto no_dev;
    }
 
+   pipe_reference_init(&dev->reference, 1);
+
    dev->vscreen = vl_screen_create(display, screen);
    if (!dev->vscreen) {
       ret = VDP_STATUS_RESOURCES;
@@ -67,12 +70,54 @@ vdp_imp_device_create_x11(Display *display, int screen, VdpDevice *device,
    }
 
    pscreen = dev->vscreen->pscreen;
-   dev->context = pscreen->context_create(pscreen, dev->vscreen);
+   dev->context = pscreen->context_create(pscreen, dev->vscreen, 0);
    if (!dev->context) {
       ret = VDP_STATUS_RESOURCES;
       goto no_context;
    }
 
+   if (!pscreen->get_param(pscreen, PIPE_CAP_NPOT_TEXTURES)) {
+      ret = VDP_STATUS_NO_IMPLEMENTATION;
+      goto no_context;
+   }
+
+   memset(&res_tmpl, 0, sizeof(res_tmpl));
+
+   res_tmpl.target = PIPE_TEXTURE_2D;
+   res_tmpl.format = PIPE_FORMAT_R8G8B8A8_UNORM;
+   res_tmpl.width0 = 1;
+   res_tmpl.height0 = 1;
+   res_tmpl.depth0 = 1;
+   res_tmpl.array_size = 1;
+   res_tmpl.bind = PIPE_BIND_SAMPLER_VIEW;
+   res_tmpl.usage = PIPE_USAGE_DEFAULT;
+
+   if (!CheckSurfaceParams(pscreen, &res_tmpl)) {
+      ret = VDP_STATUS_NO_IMPLEMENTATION;
+      goto no_resource;
+   }
+
+   res = pscreen->resource_create(pscreen, &res_tmpl);
+   if (!res) {
+      ret = VDP_STATUS_RESOURCES;
+      goto no_resource;
+   }
+
+   memset(&sv_tmpl, 0, sizeof(sv_tmpl));
+   u_sampler_view_default_template(&sv_tmpl, res, res->format);
+
+   sv_tmpl.swizzle_r = PIPE_SWIZZLE_ONE;
+   sv_tmpl.swizzle_g = PIPE_SWIZZLE_ONE;
+   sv_tmpl.swizzle_b = PIPE_SWIZZLE_ONE;
+   sv_tmpl.swizzle_a = PIPE_SWIZZLE_ONE;
+
+   dev->dummy_sv = dev->context->create_sampler_view(dev->context, res, &sv_tmpl);
+   pipe_resource_reference(&res, NULL);
+   if (!dev->dummy_sv) {
+      ret = VDP_STATUS_RESOURCES;
+      goto no_resource;
+   }
+
    *device = vlAddDataHTAB(dev);
    if (*device == 0) {
       ret = VDP_STATUS_ERROR;
@@ -80,13 +125,16 @@ vdp_imp_device_create_x11(Display *display, int screen, VdpDevice *device,
    }
 
    vl_compositor_init(&dev->compositor, dev->context);
+   pipe_mutex_init(dev->mutex);
 
    *get_proc_address = &vlVdpGetProcAddress;
 
    return VDP_STATUS_OK;
 
 no_handle:
-   /* Destroy vscreen */
+   pipe_sampler_view_reference(&dev->dummy_sv, NULL);
+no_resource:
+   dev->context->destroy(dev->context);
 no_context:
    vl_screen_destroy(dev->vscreen);
 no_vscreen:
@@ -100,7 +148,7 @@ no_htab:
 /**
  * Create a VdpPresentationQueueTarget for use with X11.
  */
-PUBLIC VdpStatus
+VdpStatus
 vlVdpPresentationQueueTargetCreateX11(VdpDevice device, Drawable drawable,
                                       VdpPresentationQueueTarget *target)
 {
@@ -118,7 +166,7 @@ vlVdpPresentationQueueTargetCreateX11(VdpDevice device, Drawable drawable,
    if (!pqt)
       return VDP_STATUS_RESOURCES;
 
-   pqt->device = dev;
+   DeviceReference(&pqt->device, dev);
    pqt->drawable = drawable;
 
    *target = vlAddDataHTAB(pqt);
@@ -147,6 +195,7 @@ vlVdpPresentationQueueTargetDestroy(VdpPresentationQueueTarget presentation_queu
       return VDP_STATUS_INVALID_HANDLE;
 
    vlRemoveDataHTAB(presentation_queue_target);
+   DeviceReference(&pqt->device, NULL);
    FREE(pqt);
 
    return VDP_STATUS_OK;
@@ -161,15 +210,26 @@ vlVdpDeviceDestroy(VdpDevice device)
    vlVdpDevice *dev = vlGetDataHTAB(device);
    if (!dev)
       return VDP_STATUS_INVALID_HANDLE;
-      
+
+   vlRemoveDataHTAB(device);
+   DeviceReference(&dev, NULL);
+
+   return VDP_STATUS_OK;
+}
+
+/**
+ * Free a VdpDevice.
+ */
+void
+vlVdpDeviceFree(vlVdpDevice *dev)
+{
+   pipe_mutex_destroy(dev->mutex);
    vl_compositor_cleanup(&dev->compositor);
+   pipe_sampler_view_reference(&dev->dummy_sv, NULL);
    dev->context->destroy(dev->context);
    vl_screen_destroy(dev->vscreen);
-
    FREE(dev);
    vlDestroyHTAB();
-
-   return VDP_STATUS_OK;
 }
 
 /**
@@ -188,7 +248,7 @@ vlVdpGetProcAddress(VdpDevice device, VdpFuncId function_id, void **function_poi
    if (!vlGetFuncFTAB(function_id, function_pointer))
       return VDP_STATUS_INVALID_FUNC_ID;
 
-   VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Got proc adress %p for id %d\n", *function_pointer, function_id);
+   VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Got proc address %p for id %d\n", *function_pointer, function_id);
 
    return VDP_STATUS_OK;
 }
@@ -279,7 +339,7 @@ vlVdpResolveDelayedRendering(vlVdpDevice *dev, struct pipe_surface *surface, str
       dirty_area = &vlsurface->dirty_area;
    }
 
-   vl_compositor_render(cstate, &dev->compositor, surface, dirty_area);
+   vl_compositor_render(cstate, &dev->compositor, surface, dirty_area, true);
 
    dev->delayed_rendering.surface = VDP_INVALID_HANDLE;
    dev->delayed_rendering.cstate = NULL;
@@ -290,8 +350,8 @@ vlVdpResolveDelayedRendering(vlVdpDevice *dev, struct pipe_surface *surface, str
       struct pipe_sampler_view sv_templ;
 
       vlVdpDefaultSamplerViewTemplate(&sv_templ, res);
-      pipe_sampler_view_reference(&vlsurface->sampler_view,
-         dev->context->create_sampler_view(dev->context, res, &sv_templ));
+      pipe_sampler_view_reference(&vlsurface->sampler_view, NULL);
+      vlsurface->sampler_view = dev->context->create_sampler_view(dev->context, res, &sv_templ);
    }
 
    return;