gallium: Port timing functions to WinCE.
[mesa.git] / src / gallium / auxiliary / util / p_tile.c
index 91283a9ab08396c3d30a4f7dafefeb6ac0dda560..5728757d2fb492a2f98a15cdc070eb9a2367cb67 100644 (file)
@@ -50,6 +50,7 @@ pipe_get_tile_raw(struct pipe_context *pipe,
                   uint x, uint y, uint w, uint h,
                   void *p, int dst_stride)
 {
+   struct pipe_screen *screen = pipe->screen;
    const uint cpp = ps->cpp;
    const ubyte *pSrc;
    const uint src_stride = ps->pitch * cpp;
@@ -63,7 +64,11 @@ pipe_get_tile_raw(struct pipe_context *pipe,
    if (pipe_clip_tile(x, y, &w, &h, ps))
       return;
 
-   pSrc = (const ubyte *) pipe_surface_map(ps) + (y * ps->pitch + x) * cpp;
+   pSrc = (const ubyte *) screen->surface_map(screen, ps,
+                                              PIPE_BUFFER_USAGE_CPU_READ);
+   assert(pSrc);                /* XXX: proper error handling! */
+
+   pSrc += (y * ps->pitch + x) * cpp;
    pDest = (ubyte *) p;
 
    for (i = 0; i < h; i++) {
@@ -72,7 +77,7 @@ pipe_get_tile_raw(struct pipe_context *pipe,
       pSrc += src_stride;
    }
 
-   pipe_surface_unmap(ps);
+   screen->surface_unmap(screen, ps);
 }
 
 
@@ -86,6 +91,7 @@ pipe_put_tile_raw(struct pipe_context *pipe,
                   uint x, uint y, uint w, uint h,
                   const void *p, int src_stride)
 {
+   struct pipe_screen *screen = pipe->screen;
    const uint cpp = ps->cpp;
    const ubyte *pSrc;
    const uint dst_stride = ps->pitch * cpp;
@@ -100,7 +106,11 @@ pipe_put_tile_raw(struct pipe_context *pipe,
       return;
 
    pSrc = (const ubyte *) p;
-   pDest = (ubyte *) pipe_surface_map(ps) + (y * ps->pitch + x) * cpp;
+
+   pDest = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_WRITE);
+   assert(pDest);               /* XXX: proper error handling */
+
+   pDest += (y * ps->pitch + x) * cpp;
 
    for (i = 0; i < h; i++) {
       memcpy(pDest, pSrc, w * cpp);
@@ -108,7 +118,7 @@ pipe_put_tile_raw(struct pipe_context *pipe,
       pSrc += src_stride;
    }
 
-   pipe_surface_unmap(ps);
+   screen->surface_unmap(screen, ps);
 }
 
 
@@ -385,7 +395,7 @@ z16_get_tile_rgba(ushort *src,
 
 
 
-/*** PIPE_FORMAT_U_L8 ***/
+/*** PIPE_FORMAT_L8_UNORM ***/
 
 static void
 l8_get_tile_rgba(ubyte *src,
@@ -408,7 +418,7 @@ l8_get_tile_rgba(ubyte *src,
 }
 
 
-/*** PIPE_FORMAT_U_A8 ***/
+/*** PIPE_FORMAT_A8_UNORM ***/
 
 static void
 a8_get_tile_rgba(ubyte *src,
@@ -476,7 +486,7 @@ r16g16b16a16_put_tile_rgba(short *dst,
 
 
 
-/*** PIPE_FORMAT_U_I8 ***/
+/*** PIPE_FORMAT_I8_UNORM ***/
 
 static void
 i8_get_tile_rgba(ubyte *src,
@@ -499,7 +509,7 @@ i8_get_tile_rgba(ubyte *src,
 }
 
 
-/*** PIPE_FORMAT_U_A8_L8 ***/
+/*** PIPE_FORMAT_A8L8_UNORM ***/
 
 static void
 a8_l8_get_tile_rgba(ushort *src,
@@ -708,16 +718,16 @@ pipe_get_tile_rgba(struct pipe_context *pipe,
    case PIPE_FORMAT_R5G6B5_UNORM:
       r5g6b5_get_tile_rgba((ushort *) packed, w, h, p, dst_stride);
       break;
-   case PIPE_FORMAT_U_L8:
+   case PIPE_FORMAT_L8_UNORM:
       l8_get_tile_rgba((ubyte *) packed, w, h, p, dst_stride);
       break;
-   case PIPE_FORMAT_U_A8:
+   case PIPE_FORMAT_A8_UNORM:
       a8_get_tile_rgba((ubyte *) packed, w, h, p, dst_stride);
       break;
-   case PIPE_FORMAT_U_I8:
+   case PIPE_FORMAT_I8_UNORM:
       i8_get_tile_rgba((ubyte *) packed, w, h, p, dst_stride);
       break;
-   case PIPE_FORMAT_U_A8_L8:
+   case PIPE_FORMAT_A8L8_UNORM:
       a8_l8_get_tile_rgba((ushort *) packed, w, h, p, dst_stride);
       break;
    case PIPE_FORMAT_R16G16B16A16_SNORM:
@@ -730,6 +740,7 @@ pipe_get_tile_rgba(struct pipe_context *pipe,
       z32_get_tile_rgba((unsigned *) packed, w, h, p, dst_stride);
       break;
    case PIPE_FORMAT_S8Z24_UNORM:
+   case PIPE_FORMAT_X8Z24_UNORM:
       s8z24_get_tile_rgba((unsigned *) packed, w, h, p, dst_stride);
       break;
    case PIPE_FORMAT_Z24S8_UNORM:
@@ -786,16 +797,16 @@ pipe_put_tile_rgba(struct pipe_context *pipe,
       break;
    case PIPE_FORMAT_R8G8B8A8_UNORM:
       break;
-   case PIPE_FORMAT_U_L8:
+   case PIPE_FORMAT_L8_UNORM:
       /*l8_put_tile_rgba((ubyte *) packed, w, h, p, src_stride);*/
       break;
-   case PIPE_FORMAT_U_A8:
+   case PIPE_FORMAT_A8_UNORM:
       /*a8_put_tile_rgba((ubyte *) packed, w, h, p, src_stride);*/
       break;
-   case PIPE_FORMAT_U_I8:
+   case PIPE_FORMAT_I8_UNORM:
       /*i8_put_tile_rgba((ubyte *) packed, w, h, p, src_stride);*/
       break;
-   case PIPE_FORMAT_U_A8_L8:
+   case PIPE_FORMAT_A8L8_UNORM:
       /*a8_l8_put_tile_rgba((ushort *) packed, w, h, p, src_stride);*/
       break;
    case PIPE_FORMAT_R16G16B16A16_SNORM:
@@ -808,6 +819,7 @@ pipe_put_tile_rgba(struct pipe_context *pipe,
       /*z32_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
       break;
    case PIPE_FORMAT_S8Z24_UNORM:
+   case PIPE_FORMAT_X8Z24_UNORM:
       /*s8z24_put_tile_rgba((unsigned *) packed, w, h, p, src_stride);*/
       break;
    case PIPE_FORMAT_Z24S8_UNORM:
@@ -832,18 +844,26 @@ pipe_get_tile_z(struct pipe_context *pipe,
                 uint x, uint y, uint w, uint h,
                 uint *z)
 {
+   struct pipe_screen *screen = pipe->screen;
    const uint dstStride = w;
+   void *map;
    uint *pDest = z;
    uint i, j;
 
    if (pipe_clip_tile(x, y, &w, &h, ps))
       return;
 
+   map = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_READ);
+   if (!map) {
+      assert(0);
+      return;
+   }
+
    switch (ps->format) {
    case PIPE_FORMAT_Z32_UNORM:
       {
          const uint *pSrc
-            = (const uint *) pipe_surface_map(ps) + (y * ps->pitch + x);
+            = (const uint *)map  + (y * ps->pitch + x);
          for (i = 0; i < h; i++) {
             memcpy(pDest, pSrc, 4 * w);
             pDest += dstStride;
@@ -852,9 +872,10 @@ pipe_get_tile_z(struct pipe_context *pipe,
       }
       break;
    case PIPE_FORMAT_S8Z24_UNORM:
+   case PIPE_FORMAT_X8Z24_UNORM:
       {
          const uint *pSrc
-            = (const uint *) pipe_surface_map(ps) + (y * ps->pitch + x);
+            = (const uint *)map + (y * ps->pitch + x);
          for (i = 0; i < h; i++) {
             for (j = 0; j < w; j++) {
                /* convert 24-bit Z to 32-bit Z */
@@ -868,7 +889,7 @@ pipe_get_tile_z(struct pipe_context *pipe,
    case PIPE_FORMAT_Z16_UNORM:
       {
          const ushort *pSrc
-            = (const ushort *) pipe_surface_map(ps) + (y * ps->pitch + x);
+            = (const ushort *)map + (y * ps->pitch + x);
          for (i = 0; i < h; i++) {
             for (j = 0; j < w; j++) {
                /* convert 16-bit Z to 32-bit Z */
@@ -883,7 +904,7 @@ pipe_get_tile_z(struct pipe_context *pipe,
       assert(0);
    }
 
-   pipe_surface_unmap(ps);
+   screen->surface_unmap(screen, ps);
 }
 
 
@@ -893,17 +914,25 @@ pipe_put_tile_z(struct pipe_context *pipe,
                 uint x, uint y, uint w, uint h,
                 const uint *zSrc)
 {
+   struct pipe_screen *screen = pipe->screen;
    const uint srcStride = w;
    const uint *pSrc = zSrc;
+   void *map;
    uint i, j;
 
    if (pipe_clip_tile(x, y, &w, &h, ps))
       return;
 
+   map = screen->surface_map(screen, ps, PIPE_BUFFER_USAGE_CPU_WRITE);
+   if (!map) {
+      assert(0);
+      return;
+   }
+
    switch (ps->format) {
    case PIPE_FORMAT_Z32_UNORM:
       {
-         uint *pDest = (uint *) pipe_surface_map(ps) + (y * ps->pitch + x);
+         uint *pDest = (uint *) map + (y * ps->pitch + x);
          for (i = 0; i < h; i++) {
             memcpy(pDest, pSrc, 4 * w);
             pDest += ps->pitch;
@@ -912,8 +941,9 @@ pipe_put_tile_z(struct pipe_context *pipe,
       }
       break;
    case PIPE_FORMAT_S8Z24_UNORM:
+   case PIPE_FORMAT_X8Z24_UNORM:
       {
-         uint *pDest = (uint *) pipe_surface_map(ps) + (y * ps->pitch + x);
+         uint *pDest = (uint *) map + (y * ps->pitch + x);
          for (i = 0; i < h; i++) {
             for (j = 0; j < w; j++) {
                /* convert 32-bit Z to 24-bit Z (0 stencil) */
@@ -926,7 +956,7 @@ pipe_put_tile_z(struct pipe_context *pipe,
       break;
    case PIPE_FORMAT_Z16_UNORM:
       {
-         ushort *pDest = (ushort *) pipe_surface_map(ps) + (y * ps->pitch + x);
+         ushort *pDest = (ushort *) map + (y * ps->pitch + x);
          for (i = 0; i < h; i++) {
             for (j = 0; j < w; j++) {
                /* convert 32-bit Z to 16-bit Z */
@@ -941,7 +971,7 @@ pipe_put_tile_z(struct pipe_context *pipe,
       assert(0);
    }
 
-   pipe_surface_unmap(ps);
+   screen->surface_unmap(screen, ps);
 }