Merge branch 'mesa_7_7_branch'
[mesa.git] / src / gallium / winsys / gdi / gdi_softpipe_winsys.c
index 4924dbf26ac37e92e84426c185961a26cf8753bf..2ad794c3f0fcfca1d1887d5a5dfe517a2dd3c7f1 100644 (file)
 #include "pipe/p_format.h"
 #include "pipe/p_context.h"
 #include "pipe/p_inlines.h"
+#include "util/u_format.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
 #include "softpipe/sp_winsys.h"
 #include "softpipe/sp_texture.h"
-#include "shared/stw_winsys.h"
+#include "stw_winsys.h"
 
 
 struct gdi_softpipe_buffer
@@ -87,8 +88,7 @@ gdi_softpipe_buffer_unmap(struct pipe_winsys *winsys,
 
 
 static void
-gdi_softpipe_buffer_destroy(struct pipe_winsys *winsys,
-                            struct pipe_buffer *buf)
+gdi_softpipe_buffer_destroy(struct pipe_buffer *buf)
 {
    struct gdi_softpipe_buffer *oldBuf = gdi_softpipe_buffer(buf);
 
@@ -118,7 +118,7 @@ gdi_softpipe_buffer_create(struct pipe_winsys *winsys,
 {
    struct gdi_softpipe_buffer *buffer = CALLOC_STRUCT(gdi_softpipe_buffer);
 
-   buffer->base.refcount = 1;
+   pipe_reference_init(&buffer->base.reference, 1);
    buffer->base.alignment = alignment;
    buffer->base.usage = usage;
    buffer->base.size = size;
@@ -143,7 +143,7 @@ gdi_softpipe_user_buffer_create(struct pipe_winsys *winsys,
    if(!buffer)
       return NULL;
 
-   buffer->base.refcount = 1;
+   pipe_reference_init(&buffer->base.reference, 1);
    buffer->base.size = bytes;
    buffer->userBuffer = TRUE;
    buffer->data = ptr;
@@ -152,31 +152,19 @@ gdi_softpipe_user_buffer_create(struct pipe_winsys *winsys,
 }
 
 
-/**
- * Round n up to next multiple.
- */
-static INLINE unsigned
-round_up(unsigned n, unsigned multiple)
-{
-   return (n + multiple - 1) & ~(multiple - 1);
-}
-
-
 static struct pipe_buffer *
 gdi_softpipe_surface_buffer_create(struct pipe_winsys *winsys,
                                    unsigned width, unsigned height,
                                    enum pipe_format format,
                                    unsigned usage,
+                                   unsigned tex_usage,
                                    unsigned *stride)
 {
    const unsigned alignment = 64;
-   struct pipe_format_block block;
-   unsigned nblocksx, nblocksy;
+   unsigned nblocksy;
 
-   pf_get_block(format, &block);
-   nblocksx = pf_get_nblocksx(&block, width);
-   nblocksy = pf_get_nblocksy(&block, height);
-   *stride = round_up(nblocksx * block.size, alignment);
+   nblocksy = util_format_get_nblocksy(format, height);
+   *stride = align(util_format_get_stride(format, width), alignment);
 
    return winsys->buffer_create(winsys, alignment,
                                 usage,
@@ -264,26 +252,29 @@ gdi_softpipe_screen_create(void)
 static struct pipe_context *
 gdi_softpipe_context_create(struct pipe_screen *screen)
 {
-   return softpipe_create(screen, screen->winsys, NULL);
+   return softpipe_create(screen);
 }
 
 
 static void
-gdi_softpipe_flush_frontbuffer(struct pipe_screen *screen,
-                               struct pipe_surface *surface,
-                               HDC hDC)
+gdi_softpipe_present(struct pipe_screen *screen,
+                     struct pipe_surface *surface,
+                     HDC hDC)
 {
+    struct softpipe_texture *texture;
     struct gdi_softpipe_buffer *buffer;
     BITMAPINFO bmi;
 
-    buffer = gdi_softpipe_buffer(softpipe_texture(surface->texture)->buffer);
+    texture = softpipe_texture(surface->texture);
+                                               
+    buffer = gdi_softpipe_buffer(texture->buffer);
 
     memset(&bmi, 0, sizeof(BITMAPINFO));
     bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
-    bmi.bmiHeader.biWidth = surface->stride / pf_get_size(surface->format);
+    bmi.bmiHeader.biWidth = texture->stride[surface->level] / util_format_get_blocksize(surface->format);
     bmi.bmiHeader.biHeight= -(long)surface->height;
     bmi.bmiHeader.biPlanes = 1;
-    bmi.bmiHeader.biBitCount = pf_get_bits(surface->format);
+    bmi.bmiHeader.biBitCount = util_format_get_blocksizebits(surface->format);
     bmi.bmiHeader.biCompression = BI_RGB;
     bmi.bmiHeader.biSizeImage = 0;
     bmi.bmiHeader.biXPelsPerMeter = 0;
@@ -301,7 +292,11 @@ gdi_softpipe_flush_frontbuffer(struct pipe_screen *screen,
 static const struct stw_winsys stw_winsys = {
    &gdi_softpipe_screen_create,
    &gdi_softpipe_context_create,
-   &gdi_softpipe_flush_frontbuffer
+   &gdi_softpipe_present,
+   NULL, /* get_adapter_luid */
+   NULL, /* shared_surface_open */
+   NULL, /* shared_surface_close */
+   NULL  /* compose */
 };
 
 
@@ -310,10 +305,21 @@ DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
 {
    switch (fdwReason) {
    case DLL_PROCESS_ATTACH:
-      return st_init(&stw_winsys);
+      if (!stw_init(&stw_winsys)) {
+         return FALSE;
+      }
+      return stw_init_thread();
+
+   case DLL_THREAD_ATTACH:
+      return stw_init_thread();
+
+   case DLL_THREAD_DETACH:
+      stw_cleanup_thread();
+      break;
 
    case DLL_PROCESS_DETACH:
-      st_cleanup();
+      stw_cleanup_thread();
+      stw_cleanup();
       break;
    }
    return TRUE;