From ab0a040304bcd900f37afb80cd786eb314004d68 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Mon, 26 May 2003 16:26:51 +0000 Subject: [PATCH] add surfaces --- render2/.cvsignore | 1 + render2/Makefile.am | 5 +- render2/render.h | 57 ++++++++++++++++++++++ render2/surface.c | 114 ++++++++++++++++++++++++++++++++++++++++++++ render2/surface.h | 47 ++++++++++++++++++ 5 files changed, 221 insertions(+), 3 deletions(-) create mode 100644 render2/surface.c create mode 100644 render2/surface.h diff --git a/render2/.cvsignore b/render2/.cvsignore index ba11ed46..5a3f2d5a 100644 --- a/render2/.cvsignore +++ b/render2/.cvsignore @@ -10,3 +10,4 @@ init.lo debug.lo color.lo font.lo +surface.lo diff --git a/render2/Makefile.am b/render2/Makefile.am index 8e3e5fd8..88f86244 100644 --- a/render2/Makefile.am +++ b/render2/Makefile.am @@ -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 diff --git a/render2/render.h b/render2/render.h index 947a014b..b0344093 100644 --- a/render2/render.h +++ b/render2/render.h @@ -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 index 00000000..1620606e --- /dev/null +++ b/render2/surface.c @@ -0,0 +1,114 @@ +#include "surface.h" +#include "instance.h" +#include +#include +#include + +/* 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 index 00000000..e6ea418b --- /dev/null +++ b/render2/surface.h @@ -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 -- 2.34.1