Create common trace_drm code, add to radeon_winsys.
authorCorbin Simpson <MostAwesomeDude@gmail.com>
Sat, 16 May 2009 16:58:54 +0000 (09:58 -0700)
committerCorbin Simpson <MostAwesomeDude@gmail.com>
Sat, 16 May 2009 17:07:58 +0000 (10:07 -0700)
src/gallium/auxiliary/trace/trace_drm.h [new file with mode: 0644]
src/gallium/winsys/drm/radeon/core/radeon_drm.c
src/gallium/winsys/drm/radeon/dri/Makefile
src/gallium/winsys/drm/radeon/egl/Makefile

diff --git a/src/gallium/auxiliary/trace/trace_drm.h b/src/gallium/auxiliary/trace/trace_drm.h
new file mode 100644 (file)
index 0000000..892bd98
--- /dev/null
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2009 Jakob Bornecrantz <jakob@vmware.com>
+ *                Corbin Simpson <MostAwesomeDude@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 TRACE_DRM_H
+#define TRACE_DRM_H
+
+#include "state_tracker/drm_api.h"
+
+#include "trace/tr_buffer.h"
+#include "trace/tr_context.h"
+#include "trace/tr_screen.h"
+#include "trace/tr_texture.h"
+
+struct drm_api hooks;
+
+static struct pipe_screen *
+trace_drm_create_screen(int fd, struct drm_create_screen_arg *arg)
+{
+       struct pipe_screen *screen;
+
+       if (arg && arg->mode != DRM_CREATE_NORMAL)
+               return NULL;
+
+       screen = hooks.create_screen(fd, arg);
+
+       return trace_screen_create(screen);
+};
+
+static struct pipe_context *
+trace_drm_create_context(struct pipe_screen *_screen)
+{
+       struct pipe_screen *screen;
+       struct pipe_context *pipe;
+
+       if (trace_enabled())
+               screen = trace_screen(_screen)->screen;
+       else
+               screen = _screen;
+
+       pipe = hooks.create_context(screen);
+
+       if (trace_enabled())
+               pipe = trace_context_create(_screen, pipe);
+
+       return pipe;
+};
+
+static boolean
+trace_drm_buffer_from_texture(struct pipe_texture *_texture,
+                              struct pipe_buffer **_buffer,
+                              unsigned *stride)
+{
+       struct pipe_texture *texture;
+       struct pipe_buffer *buffer = NULL;
+       boolean result;
+
+       if (trace_enabled())
+               texture = trace_texture(_texture)->texture;
+       else
+               texture = _texture;
+
+       result = hooks.buffer_from_texture(texture, &buffer, stride);
+
+       if (result && _buffer)
+               buffer = trace_buffer_create(trace_screen(texture->screen), buffer);
+
+       if (_buffer)
+               *_buffer = buffer;
+       else
+               pipe_buffer_reference(&buffer, NULL);
+
+       return result;
+}
+
+static struct pipe_buffer *
+trace_drm_buffer_from_handle(struct pipe_screen *_screen,
+                             const char *name,
+                             unsigned handle)
+{
+       struct pipe_screen *screen;
+       struct pipe_buffer *result;
+
+       if (trace_enabled())
+               screen = trace_screen(_screen)->screen;
+       else
+               screen = _screen;
+
+       result = hooks.buffer_from_handle(screen, name, handle);
+
+       if (trace_enabled())
+               result = trace_buffer_create(trace_screen(_screen), result);
+
+       return result;
+}
+
+static boolean
+trace_drm_handle_from_buffer(struct pipe_screen *_screen,
+                             struct pipe_buffer *_buffer,
+                             unsigned *handle)
+{
+       struct pipe_screen *screen;
+       struct pipe_buffer *buffer;
+
+       if (trace_enabled()) {
+               screen = trace_screen(_screen)->screen;
+               buffer = trace_buffer(_buffer)->buffer;
+       } else {
+               screen = _screen;
+               buffer = _buffer;
+       }
+
+       return hooks.handle_from_buffer(screen, buffer, handle);
+}
+
+static boolean
+trace_drm_global_handle_from_buffer(struct pipe_screen *_screen,
+                                    struct pipe_buffer *_buffer,
+                                    unsigned *handle)
+{
+       struct pipe_screen *screen;
+       struct pipe_buffer *buffer;
+
+       if (trace_enabled()) {
+               screen = trace_screen(_screen)->screen;
+               buffer = trace_buffer(_buffer)->buffer;
+       } else {
+               screen = _screen;
+               buffer = _buffer;
+       }
+
+       return hooks.global_handle_from_buffer(screen, buffer, handle);
+}
+
+struct drm_api drm_api_hooks =
+{
+       .create_screen = trace_drm_create_screen,
+       .create_context = trace_drm_create_context,
+
+       .buffer_from_texture = trace_drm_buffer_from_texture,
+       .buffer_from_handle = trace_drm_buffer_from_handle,
+       .handle_from_buffer = trace_drm_handle_from_buffer,
+       .global_handle_from_buffer = trace_drm_global_handle_from_buffer,
+};
+
+#endif /* TRACE_DRM_H */
index 428d3f65a169be009d8e00395b84e162bec203f1..5406d2bbea06b2545be6ffb328196560c553fb25 100644 (file)
 
 #include "radeon_drm.h"
 
+#ifdef DEBUG
+#include "trace/trace_drm.h"
+#endif
+
 /* Create a pipe_screen. */
 struct pipe_screen* radeon_create_screen(int drmFB,
                                         struct drm_create_screen_arg *arg)
@@ -112,7 +116,11 @@ boolean radeon_global_handle_from_buffer(struct pipe_screen* screen,
     return TRUE;
 }
 
+#ifdef DEBUG
+struct drm_api hooks = {
+#else
 struct drm_api drm_api_hooks = {
+#endif
     .create_screen = radeon_create_screen,
     .create_context = radeon_create_context,
     /* XXX fix this */
index c218ee9d0104eb3dcc568c552566c656345fd0d1..a9889444de8b47c1513275b3516f5343da47d8e9 100644 (file)
@@ -10,6 +10,7 @@ PIPE_DRIVERS = \
        $(TOP)/src/gallium/state_trackers/dri/libdridrm.a \
        $(TOP)/src/gallium/winsys/drm/radeon/core/libradeonwinsys.a \
        $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
+       $(TOP)/src/gallium/drivers/trace/libtrace.a \
        $(TOP)/src/gallium/drivers/r300/libr300.a
 
 C_SOURCES = \
index d989b3aa935af48e63a59d7dca43ed4d30057181..6a1448d1b9ba0079f2a2d037401f41f1595cfa0a 100644 (file)
@@ -8,6 +8,7 @@ PIPE_DRIVERS = \
        $(TOP)/src/gallium/state_trackers/egl/libegldrm.a \
        $(GALLIUMDIR)/winsys/drm/radeon/core/libradeonwinsys.a \
        $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \
+       $(TOP)/src/gallium/drivers/trace/libtrace.a \
        $(TOP)/src/gallium/drivers/r300/libr300.a
 
 DRIVER_SOURCES =