st/nine: Use fixed size arrays for swapchain buffers
authorAxel Davy <axel.davy@ens.fr>
Sat, 7 May 2016 14:14:00 +0000 (16:14 +0200)
committerAxel Davy <axel.davy@ens.fr>
Mon, 10 Oct 2016 21:43:49 +0000 (23:43 +0200)
Signed-off-by: Axel Davy <axel.davy@ens.fr>
src/gallium/state_trackers/nine/swapchain9.c
src/gallium/state_trackers/nine/swapchain9.h

index e672f948b04d2b3452af33618e237759ed4687cb..3106063237009f9bcb22c62f23fa9aeef65469b8 100644 (file)
@@ -113,7 +113,6 @@ NineSwapChain9_Resize( struct NineSwapChain9 *This,
                        D3DDISPLAYMODEEX *mode )
 {
     struct NineDevice9 *pDevice = This->base.device;
-    struct NineSurface9 **bufs;
     D3DSURFACE_DESC desc;
     HRESULT hr;
     struct pipe_resource *resource, tmplt;
@@ -244,6 +243,8 @@ NineSwapChain9_Resize( struct NineSwapChain9 *This,
     desc.Width = pParams->BackBufferWidth;
     desc.Height = pParams->BackBufferHeight;
 
+    memset(This->tasks, 0, sizeof(This->tasks));
+
     if (This->pool) {
         _mesa_threadpool_destroy(This, This->pool);
         This->pool = NULL;
@@ -254,52 +255,24 @@ NineSwapChain9_Resize( struct NineSwapChain9 *This,
     if (!This->pool)
         This->enable_threadpool = FALSE;
 
-    This->tasks = REALLOC(This->tasks,
-                          oldBufferCount * sizeof(struct threadpool_task *),
-                          newBufferCount * sizeof(struct threadpool_task *));
-    memset(This->tasks, 0, newBufferCount * sizeof(struct threadpool_task *));
-
     for (i = 0; i < oldBufferCount; i++) {
         ID3DPresent_DestroyD3DWindowBuffer(This->present, This->present_handles[i]);
         This->present_handles[i] = NULL;
-        if (This->present_buffers)
+        if (This->present_buffers[i])
             pipe_resource_reference(&(This->present_buffers[i]), NULL);
     }
 
-    if (!has_present_buffers && This->present_buffers) {
-        FREE(This->present_buffers);
-        This->present_buffers = NULL;
-    }
-
     if (newBufferCount != oldBufferCount) {
         for (i = newBufferCount; i < oldBufferCount;
              ++i)
             NineUnknown_Detach(NineUnknown(This->buffers[i]));
 
-        bufs = REALLOC(This->buffers,
-                       oldBufferCount * sizeof(This->buffers[0]),
-                       newBufferCount * sizeof(This->buffers[0]));
-        if (!bufs)
-            return E_OUTOFMEMORY;
-        This->buffers = bufs;
-        This->present_handles = REALLOC(This->present_handles,
-                                        oldBufferCount * sizeof(D3DWindowBuffer *),
-                                        newBufferCount * sizeof(D3DWindowBuffer *));
         for (i = oldBufferCount; i < newBufferCount; ++i) {
             This->buffers[i] = NULL;
             This->present_handles[i] = NULL;
         }
     }
 
-    if (has_present_buffers &&
-        (newBufferCount != oldBufferCount || !This->present_buffers)) {
-        This->present_buffers = REALLOC(This->present_buffers,
-                                        This->present_buffers == NULL ? 0 :
-                                        oldBufferCount * sizeof(struct pipe_resource *),
-                                        newBufferCount * sizeof(struct pipe_resource *));
-        memset(This->present_buffers, 0, newBufferCount * sizeof(struct pipe_resource *));
-    }
-
     for (i = 0; i < newBufferCount; ++i) {
         tmplt.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET;
         tmplt.nr_samples = pParams->MultiSampleType;
@@ -509,15 +482,13 @@ NineSwapChain9_dtor( struct NineSwapChain9 *This )
     if (This->pool)
         _mesa_threadpool_destroy(This, This->pool);
 
-    if (This->buffers) {
+    if (This->buffers[0]) {
         for (i = 0; i < This->params.BackBufferCount; i++) {
             NineUnknown_Release(NineUnknown(This->buffers[i]));
             ID3DPresent_DestroyD3DWindowBuffer(This->present, This->present_handles[i]);
-            if (This->present_buffers)
+            if (This->present_buffers[i])
                 pipe_resource_reference(&(This->present_buffers[i]), NULL);
         }
-        FREE(This->buffers);
-        FREE(This->present_buffers);
     }
     if (This->zsbuf)
         NineUnknown_Destroy(NineUnknown(This->zsbuf));
@@ -689,7 +660,7 @@ present( struct NineSwapChain9 *This,
     if (This->params.SwapEffect == D3DSWAPEFFECT_DISCARD)
         handle_draw_cursor_and_hud(This, resource);
 
-    if (This->present_buffers) {
+    if (This->present_buffers[0]) {
         memset(&blit, 0, sizeof(blit));
         blit.src.resource = resource;
         blit.src.level = 0;
@@ -821,7 +792,7 @@ NineSwapChain9_Present( struct NineSwapChain9 *This,
                 This->buffers[This->params.BackBufferCount], res);
             pipe_resource_reference(&res, NULL);
 
-            if (This->present_buffers) {
+            if (This->present_buffers[0]) {
                 pipe_resource_reference(&res, This->present_buffers[0]);
                 for (i = 1; i <= This->params.BackBufferCount; i++)
                     pipe_resource_reference(&(This->present_buffers[i-1]), This->present_buffers[i]);
index f3efe268239e7219db0cb4400dfc36338dbe3776..551c74486e3339984a2a52061f789ed74a1792b7 100644 (file)
@@ -55,9 +55,9 @@ struct NineSwapChain9
     BOOL implicit;
 
     /* buffer handles */
-    struct NineSurface9 **buffers; /* 0 to BackBufferCount-1 : the back buffers. BackBufferCount : additional buffer */
-    struct pipe_resource **present_buffers;
-    D3DWindowBuffer **present_handles;
+    struct NineSurface9 *buffers[D3DPRESENT_BACK_BUFFERS_MAX_EX + 1]; /* 0 to BackBufferCount-1 : the back buffers. BackBufferCount : additional buffer */
+    struct pipe_resource *present_buffers[D3DPRESENT_BACK_BUFFERS_MAX_EX + 1];
+    D3DWindowBuffer *present_handles[D3DPRESENT_BACK_BUFFERS_MAX_EX + 1];
 
     struct pipe_fence_handle *swap_fences[DRI_SWAP_FENCES_MAX];
     unsigned int cur_fences;
@@ -72,7 +72,7 @@ struct NineSwapChain9
     D3DGAMMARAMP gamma;
 
     struct threadpool *pool;
-    struct threadpool_task **tasks;
+    struct threadpool_task *tasks[D3DPRESENT_BACK_BUFFERS_MAX_EX + 1];
     BOOL enable_threadpool;
 };