r300g: move r300_transfer to separate files
authorMarek Olšák <maraeo@gmail.com>
Sat, 6 Feb 2010 02:11:50 +0000 (03:11 +0100)
committerMarek Olšák <maraeo@gmail.com>
Sun, 7 Mar 2010 14:39:37 +0000 (15:39 +0100)
src/gallium/drivers/r300/Makefile
src/gallium/drivers/r300/SConscript
src/gallium/drivers/r300/r300_screen.c
src/gallium/drivers/r300/r300_screen.h
src/gallium/drivers/r300/r300_transfer.c [new file with mode: 0644]
src/gallium/drivers/r300/r300_transfer.h [new file with mode: 0644]

index 1f69daec8194f2064a272c5f614d190399fa012b..61b54af4ddf1fb8895679f2964ca3a6b21ed25c9 100644 (file)
@@ -19,7 +19,8 @@ C_SOURCES = \
        r300_state_invariant.c \
        r300_vs.c \
        r300_texture.c \
-       r300_tgsi_to_rc.c
+       r300_tgsi_to_rc.c \
+       r300_transfer.c
 
 LIBRARY_INCLUDES = \
        -I$(TOP)/src/mesa/drivers/dri/r300/compiler \
index 183aa17f9b3361fe52e6dc9fa47aca187270f629..27b2e30993280cc8b648fb4f9a629f588402af15 100644 (file)
@@ -30,6 +30,7 @@ r300 = env.ConvenienceLibrary(
         'r300_vs.c',
         'r300_texture.c',
         'r300_tgsi_to_rc.c',
+        'r300_transfer.c',
     ] + r300compiler) + r300compiler
 
 Export('r300')
index d397a8eb2b454d53874190a6dd591d06577f7912..a35be05940d45fe092f2b170604d1d4689c32472 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
+ * Copyright 2010 Marek Olšák <maraeo@gmail.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  * USE OR OTHER DEALINGS IN THE SOFTWARE. */
 
-#include "util/u_inlines.h"
 #include "util/u_format.h"
 #include "util/u_memory.h"
 #include "util/u_simple_screen.h"
 
 #include "r300_context.h"
-#include "r300_screen.h"
 #include "r300_texture.h"
+#include "r300_transfer.h"
 
 #include "radeon_winsys.h"
 #include "r300_winsys.h"
@@ -250,70 +250,6 @@ static boolean r300_is_format_supported(struct pipe_screen* screen,
     return retval == usage;
 }
 
-static struct pipe_transfer*
-r300_get_tex_transfer(struct pipe_screen *screen,
-                      struct pipe_texture *texture,
-                      unsigned face, unsigned level, unsigned zslice,
-                      enum pipe_transfer_usage usage, unsigned x, unsigned y,
-                      unsigned w, unsigned h)
-{
-    struct r300_texture *tex = (struct r300_texture *)texture;
-    struct r300_transfer *trans;
-    struct r300_screen *rscreen = r300_screen(screen);
-    unsigned offset;
-
-    offset = r300_texture_get_offset(tex, level, zslice, face);  /* in bytes */
-
-    trans = CALLOC_STRUCT(r300_transfer);
-    if (trans) {
-        pipe_texture_reference(&trans->transfer.texture, texture);
-        trans->transfer.x = x;
-        trans->transfer.y = y;
-        trans->transfer.width = w;
-        trans->transfer.height = h;
-        trans->transfer.stride = r300_texture_get_stride(rscreen, tex, level);
-        trans->transfer.usage = usage;
-        trans->transfer.zslice = zslice;
-        trans->transfer.face = face;
-
-        trans->offset = offset;
-    }
-    return &trans->transfer;
-}
-
-static void
-r300_tex_transfer_destroy(struct pipe_transfer *trans)
-{
-   pipe_texture_reference(&trans->texture, NULL);
-   FREE(trans);
-}
-
-static void* r300_transfer_map(struct pipe_screen* screen,
-                              struct pipe_transfer* transfer)
-{
-    struct r300_texture* tex = (struct r300_texture*)transfer->texture;
-    char* map;
-    enum pipe_format format = tex->tex.format;
-
-    map = pipe_buffer_map(screen, tex->buffer,
-                          pipe_transfer_buffer_flags(transfer));
-
-    if (!map) {
-        return NULL;
-    }
-
-    return map + r300_transfer(transfer)->offset +
-        transfer->y / util_format_get_blockheight(format) * transfer->stride +
-        transfer->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
-}
-
-static void r300_transfer_unmap(struct pipe_screen* screen,
-                                struct pipe_transfer* transfer)
-{
-    struct r300_texture* tex = (struct r300_texture*)transfer->texture;
-    pipe_buffer_unmap(screen, tex->buffer);
-}
-
 static void r300_destroy_screen(struct pipe_screen* pscreen)
 {
     struct r300_screen* r300screen = r300_screen(pscreen);
@@ -350,13 +286,11 @@ struct pipe_screen* r300_create_screen(struct radeon_winsys* radeon_winsys)
     r300screen->screen.get_paramf = r300_get_paramf;
     r300screen->screen.is_format_supported = r300_is_format_supported;
     r300screen->screen.context_create = r300_create_context;
-    r300screen->screen.get_tex_transfer = r300_get_tex_transfer;
-    r300screen->screen.tex_transfer_destroy = r300_tex_transfer_destroy;
-    r300screen->screen.transfer_map = r300_transfer_map;
-    r300screen->screen.transfer_unmap = r300_transfer_unmap;
 
     r300_init_screen_texture_functions(&r300screen->screen);
+    r300_init_screen_transfer_functions(&r300screen->screen);
     u_simple_screen_init(&r300screen->screen);
 
     return &r300screen->screen;
 }
+
index 502fbfa5a24a1ce4ed6ba74cbb2954cfac5007b6..6d72fec778811b4d62beabcfbb280f14b2943603 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
+ * Copyright 2010 Marek Olšák <maraeo@gmail.com>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
@@ -42,25 +43,14 @@ struct r300_screen {
     unsigned debug;
 };
 
-struct r300_transfer {
-    /* Parent class */
-    struct pipe_transfer transfer;
-
-    /* Offset from start of buffer. */
-    unsigned offset;
-};
 
 /* Convenience cast wrapper. */
 static INLINE struct r300_screen* r300_screen(struct pipe_screen* screen) {
     return (struct r300_screen*)screen;
 }
 
-/* Convenience cast wrapper. */
-static INLINE struct r300_transfer*
-r300_transfer(struct pipe_transfer* transfer)
-{
-    return (struct r300_transfer*)transfer;
-}
+/* Creates a new r300 screen. */
+struct pipe_screen* r300_create_screen(struct radeon_winsys* radeon_winsys);
 
 /* Debug functionality. */
 
diff --git a/src/gallium/drivers/r300/r300_transfer.c b/src/gallium/drivers/r300/r300_transfer.c
new file mode 100644 (file)
index 0000000..fa48688
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
+ * Copyright 2010 Marek Olšák <maraeo@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * 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
+ * THE AUTHOR(S) AND/OR THEIR 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 "r300_context.h"
+#include "r300_transfer.h"
+#include "r300_texture.h"
+#include "r300_screen.h"
+
+#include "util/u_memory.h"
+#include "util/u_format.h"
+
+static struct pipe_transfer*
+r300_get_tex_transfer(struct pipe_screen *screen,
+                      struct pipe_texture *texture,
+                      unsigned face, unsigned level, unsigned zslice,
+                      enum pipe_transfer_usage usage, unsigned x, unsigned y,
+                      unsigned w, unsigned h)
+{
+    struct r300_texture *tex = (struct r300_texture *)texture;
+    struct r300_transfer *trans;
+    struct r300_screen *rscreen = r300_screen(screen);
+    unsigned offset;
+
+    offset = r300_texture_get_offset(tex, level, zslice, face);  /* in bytes */
+
+    trans = CALLOC_STRUCT(r300_transfer);
+    if (trans) {
+        pipe_texture_reference(&trans->transfer.texture, texture);
+        trans->transfer.x = x;
+        trans->transfer.y = y;
+        trans->transfer.width = w;
+        trans->transfer.height = h;
+        trans->transfer.stride = r300_texture_get_stride(rscreen, tex, level);
+        trans->transfer.usage = usage;
+        trans->transfer.zslice = zslice;
+        trans->transfer.face = face;
+
+        trans->offset = offset;
+    }
+    return &trans->transfer;
+}
+
+static void r300_tex_transfer_destroy(struct pipe_transfer *trans)
+{
+   pipe_texture_reference(&trans->texture, NULL);
+   FREE(trans);
+}
+
+static void* r300_transfer_map(struct pipe_screen *screen,
+                              struct pipe_transfer *transfer)
+{
+    struct r300_texture *tex = (struct r300_texture*)transfer->texture;
+    char *map;
+    enum pipe_format format = tex->tex.format;
+
+    map = pipe_buffer_map(screen, tex->buffer,
+                          pipe_transfer_buffer_flags(transfer));
+
+    if (!map) {
+        return NULL;
+    }
+
+    return map + r300_transfer(transfer)->offset +
+        transfer->y / util_format_get_blockheight(format) * transfer->stride +
+        transfer->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
+}
+
+static void r300_transfer_unmap(struct pipe_screen *screen,
+                                struct pipe_transfer *transfer)
+{
+    struct r300_texture *tex = (struct r300_texture*)transfer->texture;
+    pipe_buffer_unmap(screen, tex->buffer);
+}
+
+void r300_init_screen_transfer_functions(struct pipe_screen *screen)
+{
+    screen->get_tex_transfer = r300_get_tex_transfer;
+    screen->tex_transfer_destroy = r300_tex_transfer_destroy;
+    screen->transfer_map = r300_transfer_map;
+    screen->transfer_unmap = r300_transfer_unmap;
+}
diff --git a/src/gallium/drivers/r300/r300_transfer.h b/src/gallium/drivers/r300/r300_transfer.h
new file mode 100644 (file)
index 0000000..faf6233
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
+ * Copyright 2010 Marek Olšák <maraeo@gmail.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * 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
+ * THE AUTHOR(S) AND/OR THEIR 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. */
+
+#ifndef R300_TRANSFER
+#define R300_TRANSFER
+
+#include "pipe/p_screen.h"
+#include "pipe/p_state.h"
+
+struct r300_texture;
+struct r300_screen;
+
+struct r300_transfer {
+    /* Parent class */
+    struct pipe_transfer transfer;
+
+    /* Parameters of get_tex_transfer. */
+    unsigned x, y, level, zslice, face;
+
+    /* Offset from start of buffer. */
+    unsigned offset;
+
+    /* Untiled texture. */
+    struct r300_texture *untiled_texture;
+
+    /* Transfer and format flags. */
+    unsigned buffer_usage, render_target_usage;
+};
+
+/* Convenience cast wrapper. */
+static INLINE struct r300_transfer*
+r300_transfer(struct pipe_transfer* transfer)
+{
+    return (struct r300_transfer*)transfer;
+}
+
+void r300_init_screen_transfer_functions(struct pipe_screen *screen);
+
+#endif
+