add surfaces
authorDana Jansens <danakj@orodu.net>
Mon, 26 May 2003 16:26:51 +0000 (16:26 +0000)
committerDana Jansens <danakj@orodu.net>
Mon, 26 May 2003 16:26:51 +0000 (16:26 +0000)
render2/.cvsignore
render2/Makefile.am
render2/render.h
render2/surface.c [new file with mode: 0644]
render2/surface.h [new file with mode: 0644]

index ba11ed4675aa285d98a5aac8228894d28eb0a7de..5a3f2d5a0c13872928cb5add2ee29fd485319623 100644 (file)
@@ -10,3 +10,4 @@ init.lo
 debug.lo
 color.lo
 font.lo
+surface.lo
index 8e3e5fd88e896fe7b15338e1111cd96fc3d71297..88f862447c7273c47cc7cc46b6bd62998471f96f 100644 (file)
@@ -15,10 +15,9 @@ rendertest_LDFLAGS=-lobrender2 -L.
 rendertest_SOURCES=test.c
 
 lib_LTLIBRARIES=libobrender2.la
-libobrender2_la_SOURCES=init.c instance.c color.c debug.c font.c
+libobrender2_la_SOURCES=init.c instance.c color.c debug.c font.c surface.c
 
-
-noinst_HEADERS=render.h instance.h debug.h
+noinst_HEADERS=render.h instance.h debug.h surface.h
 
 MAINTAINERCLEANFILES=Makefile.in
 
index 947a014b76821e31f3feccd094b2e0c3e83c7e1a..b034409381a8a1b2785b24a0d7a7193af886204e 100644 (file)
@@ -73,4 +73,61 @@ int RrFontMeasureString(struct RrFont *font, const char *string);
 int RrFontHeight(struct RrFont *font);
 int RrFontMaxCharWidth(struct RrFont *font);
 
+/* surfaces */
+
+struct RrSurface;
+struct RrTexture;
+
+enum RrSurfaceType {
+    RR_SURFACE_PLANAR,
+    RR_SURFACE_NONPLANAR
+};
+
+enum RrTextureType {
+    RR_TEXTURE_FOO
+};
+
+/*! The options available for the background of an RrSurface */
+enum RrSurfaceColorType {
+    /*! No rendering on the surface background, its contents will be
+      undefined. */
+    RR_SURFACE_NONE,
+    /*! Solid color fill. */
+    RR_SURFACE_SOLID,
+    /*! Horizontal gradient. */
+    RR_SURFACE_HORIZONTAL,
+    /*! Vertical gradient. */
+    RR_SURFACE_VERTICAL,
+    /*! Diagonal (TL->BR) gradient. */
+    RR_SURFACE_DIAGONAL,
+    /*! Cross-Diagonal (TR->BL) gradient. */
+    RR_SURFACE_CROSSDIAGONAL,
+    /*! Pipecross gradient. */
+    RR_SURFACE_PIPECROSS,
+    /*! Rectangle gradient. */
+    RR_SURFACE_RECTANGLE,
+    /*! Pyramid gradient. */
+    RR_SURFACE_PYRAMID
+};
+
+/*! Create a new top-level RrSurface for a Window. */
+struct RrSurface *RrSurfaceNew(struct RrInstance *inst,
+                               enum RrSurfaceType type,
+                               Window win,
+                               int numtex);
+/*! Create a new RrSurface which is a child of another. */
+struct RrSurface *RrSurfaceNewChild(enum RrSurfaceType type,
+                                    struct RrSurface *parent,
+                                    int numtex);
+/*! Copy an RrSurface, creating a new top-level RrSurface for a Window. */
+struct RrSurface *RrSurfaceCopy(struct RrInstance *inst,
+                                struct RrSurface *sur,
+                                Window win);
+/*! Copy an RrSurface, creating a nwe RrSurface which is a child of another. */
+struct RrSurface *RrSurfaceCopyChild(struct RrSurface *sur,
+                                     struct RrSurface *parent);
+void RrSurfaceFree(struct RrSurface *sur);
+
+struct RrTexture *RrSurfaceTexture(struct RrSurface *sur, int texnum);
+
 #endif
diff --git a/render2/surface.c b/render2/surface.c
new file mode 100644 (file)
index 0000000..1620606
--- /dev/null
@@ -0,0 +1,114 @@
+#include "surface.h"
+#include "instance.h"
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* doesn't set win or parent */
+static struct RrSurface *surface_new(enum RrSurfaceType type,
+                                     int numtex)
+{
+    struct RrSurface *sur;
+
+    sur = malloc(sizeof(struct RrSurface));
+    sur->type = type;
+    sur->ntextures = numtex;
+    if (numtex) {
+        sur->texture = malloc(sizeof(struct RrTexture) * numtex);
+        memset(sur->texture, 0, sizeof(struct RrTexture) * numtex);
+    } else
+        sur->texture = NULL;
+    return sur;
+}
+
+struct RrSurface *RrSurfaceNew(struct RrInstance *inst,
+                               enum RrSurfaceType type,
+                               Window win,
+                               int numtex)
+{
+    struct RrSurface *sur;
+
+    sur = surface_new(type, numtex);
+    sur->inst = inst;
+    sur->win = win;
+    sur->parent = NULL;
+    return sur;
+}
+
+struct RrSurface *RrSurfaceNewChild(enum RrSurfaceType type,
+                                    struct RrSurface *parent,
+                                    int numtex)
+{
+    struct RrSurface *sur;
+
+    sur = surface_new(type, numtex);
+    sur->inst = parent->inst;
+    sur->win = None; /* XXX XCreateWindow? */
+    sur->parent = parent;
+    sur->parentx = 0;
+    sur->parenty = 0;
+    return sur;
+}
+
+/* doesn't set win or parent */
+static struct RrSurface *surface_copy(struct RrSurface *orig)
+{
+    struct RrSurface *sur;
+
+    sur = malloc(sizeof(struct RrSurface));
+    sur->type = orig->type;
+    switch (sur->type) {
+    case RR_SURFACE_PLANAR:
+        sur->data = orig->data;
+        break;
+    case RR_SURFACE_NONPLANAR:
+        assert(0);
+    }
+    sur->ntextures = orig->ntextures;
+    sur->texture = malloc(sizeof(struct RrTexture) * sur->ntextures);
+    memcpy(sur->texture, orig->texture,
+           sizeof(struct RrTexture) * sur->ntextures);
+    return sur;
+}
+
+struct RrSurface *RrSurfaceCopy(struct RrInstance *inst,
+                                struct RrSurface *orig,
+                                Window win)
+{
+    struct RrSurface *sur;
+
+    sur = surface_copy(orig);
+    sur->inst = inst;
+    sur->win = win;
+    sur->parent = NULL;
+    return sur;
+}
+
+struct RrSurface *RrSurfaceCopyChild(struct RrSurface *orig,
+                                     struct RrSurface *parent)
+{
+    struct RrSurface *sur;
+
+    sur = surface_copy(orig);
+    sur->inst = parent->inst;
+    sur->win = None; /* XXX XCreateWindow? */
+    sur->parent = parent;
+    return sur;
+}
+
+void RrSurfaceFree(struct RrSurface *sur)
+{
+    if (sur) {
+        if (sur->ntextures)
+            free(sur->texture);
+        if (sur->parent && sur->win)
+            XDestroyWindow(RrDisplay(sur->inst), sur->win);
+        free(sur);
+    }
+}
+
+struct RrTexture *RrSurfaceTexture(struct RrSurface *sur, int texnum)
+{
+    assert(texnum < sur->ntextures);
+    return &(sur->texture[texnum]);
+}
diff --git a/render2/surface.h b/render2/surface.h
new file mode 100644 (file)
index 0000000..e6ea418
--- /dev/null
@@ -0,0 +1,47 @@
+#ifndef __render_surface_h
+#define __render_surface_h
+
+#include "render.h"
+
+union RrTextureData {
+    int foo;
+};
+
+struct RrTexture {
+    enum RrTextureType type;
+    union RrTextureData data;
+};
+
+struct RrPlanarSurface {
+    enum RrSurfaceColorType colortype;
+
+    struct RrColor primary;
+    struct RrColor secondary;
+};
+
+struct RrNonPlanarSurface {
+    int foo;
+};
+
+union RrSurfaceData {
+    struct RrPlanarSurface planar;
+    struct RrNonPlanarSurface nonplanar;
+};
+
+struct RrSurface {
+    struct RrInstance *inst;
+
+    enum RrSurfaceType type;
+    union RrSurfaceData data;
+
+    Window win; /* this can optionally be None if parent != NULL ... */
+
+    int ntextures;
+    struct RrTexture *texture;
+
+    struct RrSurface *parent;
+    int parentx;
+    int parenty;
+};
+
+#endif