st/nine: Fix leak with volume dtor
[mesa.git] / src / gallium / state_trackers / nine / volume9.c
index 89565f247320e7236278c747a6f858c076f44861..b579f9205f5a05f0556ca284e17f9a267e34e016 100644 (file)
@@ -77,7 +77,6 @@ NineVolume9_ctor( struct NineVolume9 *This,
 
     pipe_resource_reference(&This->resource, pResource);
 
-    This->pipe = pParams->device->pipe;
     This->transfer = NULL;
     This->lock_count = 0;
 
@@ -166,6 +165,8 @@ NineVolume9_GetContainer( struct NineVolume9 *This,
     DBG("This=%p riid=%p id=%s ppContainer=%p\n",
         This, riid, riid ? GUID_sprintf(guid_str, riid) : "", ppContainer);
 
+    (void)guid_str;
+
     if (!NineUnknown(This)->container)
         return E_NOINTERFACE;
     return NineUnknown_QueryInterface(NineUnknown(This)->container, riid, ppContainer);
@@ -238,6 +239,7 @@ NineVolume9_LockBox( struct NineVolume9 *This,
                      const D3DBOX *pBox,
                      DWORD Flags )
 {
+    struct pipe_context *pipe;
     struct pipe_resource *resource = This->resource;
     struct pipe_box box;
     unsigned usage;
@@ -312,9 +314,10 @@ NineVolume9_LockBox( struct NineVolume9 *This,
         pLockedVolume->pBits =
             NineVolume9_GetSystemMemPointer(This, box.x, box.y, box.z);
     } else {
+        pipe = NineDevice9_GetPipe(This->base.device);
         pLockedVolume->pBits =
-            This->pipe->transfer_map(This->pipe, resource, This->level, usage,
-                                     &box, &This->transfer);
+            pipe->transfer_map(pipe, resource, This->level, usage,
+                               &box, &This->transfer);
         if (!This->transfer) {
             if (Flags & D3DLOCK_DONOTWAIT)
                 return D3DERR_WASSTILLDRAWING;
@@ -336,11 +339,15 @@ NineVolume9_LockBox( struct NineVolume9 *This,
 HRESULT NINE_WINAPI
 NineVolume9_UnlockBox( struct NineVolume9 *This )
 {
+    struct pipe_context *pipe;
+
     DBG("This=%p lock_count=%u\n", This, This->lock_count);
     user_assert(This->lock_count, D3DERR_INVALIDCALL);
     if (This->transfer) {
-        This->pipe->transfer_unmap(This->pipe, This->transfer);
+        pipe = nine_context_get_pipe_acquire(This->base.device);
+        pipe->transfer_unmap(pipe, This->transfer);
         This->transfer = NULL;
+        nine_context_get_pipe_release(This->base.device);
     }
     --This->lock_count;
 
@@ -352,13 +359,14 @@ NineVolume9_UnlockBox( struct NineVolume9 *This )
         u_box_3d(0, 0, 0, This->desc.Width, This->desc.Height, This->desc.Depth,
                  &box);
 
+        pipe = NineDevice9_GetPipe(This->base.device);
         if (!dst) {
-            dst = This->pipe->transfer_map(This->pipe,
-                                           This->resource,
-                                           This->level,
-                                           PIPE_TRANSFER_WRITE |
-                                           PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE,
-                                           &box, &transfer);
+            dst = pipe->transfer_map(pipe,
+                                     This->resource,
+                                     This->level,
+                                     PIPE_TRANSFER_WRITE |
+                                     PIPE_TRANSFER_DISCARD_WHOLE_RESOURCE,
+                                     &box, &transfer);
             if (!dst)
                 return D3D_OK;
         }
@@ -373,10 +381,10 @@ NineVolume9_UnlockBox( struct NineVolume9 *This )
                                         This->layer_stride_conversion,
                                         0, 0, 0,
                                         This->desc.Width, This->desc.Height,
-                                        This->desc.Height);
+                                        This->desc.Depth);
 
         if (!This->data)
-            pipe_transfer_unmap(This->pipe, transfer);
+            pipe_transfer_unmap(pipe, transfer);
     }
 
     return D3D_OK;
@@ -390,7 +398,7 @@ NineVolume9_CopyMemToDefault( struct NineVolume9 *This,
                               unsigned dstx, unsigned dsty, unsigned dstz,
                               struct pipe_box *pSrcBox )
 {
-    struct pipe_context *pipe = This->pipe;
+    struct pipe_context *pipe;
     struct pipe_transfer *transfer = NULL;
     struct pipe_resource *r_dst = This->resource;
     struct pipe_box src_box;
@@ -422,6 +430,8 @@ NineVolume9_CopyMemToDefault( struct NineVolume9 *This,
     dst_box.height = src_box.height;
     dst_box.depth = src_box.depth;
 
+    pipe = NineDevice9_GetPipe(This->base.device);
+
     map = pipe->transfer_map(pipe,
                              r_dst,
                              This->level,
@@ -471,7 +481,7 @@ HRESULT
 NineVolume9_UploadSelf( struct NineVolume9 *This,
                         const struct pipe_box *damaged )
 {
-    struct pipe_context *pipe = This->pipe;
+    struct pipe_context *pipe;
     struct pipe_resource *res = This->resource;
     struct pipe_box box;
     uint8_t *ptr;
@@ -495,6 +505,7 @@ NineVolume9_UploadSelf( struct NineVolume9 *This,
 
     ptr = NineVolume9_GetSystemMemPointer(This, box.x, box.y, box.z);
 
+    pipe = NineDevice9_GetPipe(This->base.device);
     pipe->texture_subdata(pipe, res, This->level, 0, &box,
                           ptr, This->stride, This->layer_stride);