From: Dana Jansens Date: Sat, 18 Jan 2003 00:33:48 +0000 (+0000) Subject: start of new render code X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=0dcbf985c11c850b30b2983e1e20cd8cf033f054;p=chaz%2Fopenbox start of new render code --- diff --git a/otk/Makefile.am b/otk/Makefile.am index d8964758..ae5bcf79 100644 --- a/otk/Makefile.am +++ b/otk/Makefile.am @@ -8,7 +8,7 @@ INCLUDES= -I../src #noinst_LIBRARIES=libotk.a noinst_LTLIBRARIES=libotk.la -libotk_la_SOURCES=rendercontrol.cc \ +libotk_la_SOURCES=rendercontrol.cc truerendercontrol.cc \ color.cc display.cc font.cc gccache.cc image.cc \ property.cc imagecontrol.cc rect.cc screeninfo.cc \ texture.cc timer.cc style.cc \ diff --git a/otk/otk.hh b/otk/otk.hh index 23af8477..397534e5 100644 --- a/otk/otk.hh +++ b/otk/otk.hh @@ -2,6 +2,8 @@ #ifndef __otk_hh #define __otk_hh +#include "../config.h" + #include "eventdispatcher.hh" #include "eventhandler.hh" #include "widget.hh" diff --git a/otk/rendercontrol.cc b/otk/rendercontrol.cc new file mode 100644 index 00000000..1dd5704d --- /dev/null +++ b/otk/rendercontrol.cc @@ -0,0 +1,60 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +#ifdef HAVE_CONFIG_H +# include "../config.h" +#endif // HAVE_CONFIG_H + +#include "rendercontrol.hh" +#include "truerendercontrol.hh" +#include "display.hh" +#include "screeninfo.hh" + +extern "C" { +#ifdef HAVE_STDLIB_H +# include +#endif // HAVE_STDLIB_H + +#include "gettext.h" +#define _(str) gettext(str) +} + +namespace otk { + +RenderControl *RenderControl::getRenderControl(int screen) +{ + const ScreenInfo *info = display->screenInfo(screen); + + // get the visual on the screen and return the correct type of RenderControl + int vclass = info->visual()->c_class; + switch (vclass) { + case TrueColor: + return new TrueRenderControl(info); + case PseudoColor: + case StaticColor: +// return new PseudoRenderControl(info); + case GrayScale: + case StaticGray: +// return new GrayRenderControl(info); + default: + printf(_("RenderControl: Unsupported visual %d specified. Aborting.\n"), + vclass); + ::exit(1); + } +} + +RenderControl::RenderControl(const ScreenInfo *screen) + : _screen(screen) +{ + printf("Initializing RenderControl\n"); + + +} + +RenderControl::~RenderControl() +{ + printf("Destroying RenderControl\n"); + + +} + +} diff --git a/otk/rendercontrol.hh b/otk/rendercontrol.hh new file mode 100644 index 00000000..cc05a319 --- /dev/null +++ b/otk/rendercontrol.hh @@ -0,0 +1,60 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- +#ifndef __rendercontrol_hh +#define __rendercontrol_hh + +extern "C" { +#include +} + +namespace otk { + +class ScreenInfo; + +class RenderControl { +protected: + const ScreenInfo *_screen; +/* + Bool _dither; + + int _cpc; // colors-per-channel: must be a value between [2,6] + int _bpp; // bits-per-pixel + + unsigned int *_grad_xbuffer; + unsigned int *_grad_ybuffer; + unsigned int _grad_buffer_width; + unsigned int _grad_buffer_height; + + unsigned long *_sqrt_table; + + // These values are all determined based on a visual + + int _red_bits; // the number of bits (1-255) that each shade of color + int _green_bits; // spans across. best case is 1, which gives 255 shades. + int _blue_bits; + unsigned char _red_color_table[256]; + unsigned char _green_color_table[256]; + unsigned char _blue_color_table[256]; + + // These are only used for TrueColor visuals + int _red_offset; // the offset of each color in a color mask + int _green_offset; + int _blue_offset; + + // These are only used for !TrueColor visuals + XColor *_colors; + int _ncolors; +*/ + + RenderControl(const ScreenInfo *screen); + +public: + virtual ~RenderControl(); + + static RenderControl *getRenderControl(int screen); + + virtual void render(::Drawable d) = 0; +}; + +} + +#endif // __rendercontrol_hh diff --git a/otk/rendertest.cc b/otk/rendertest.cc new file mode 100644 index 00000000..c9226b1f --- /dev/null +++ b/otk/rendertest.cc @@ -0,0 +1,25 @@ +#include "otk.hh" +#include "rendercontrol.hh" + +#include + +int main(int argc, char **argv) +{ + printf("\n"); + + otk::Application app(argc, argv); + otk::AppWidget foo(&app); + foo.resize(600, 500); + foo.show(); + + otk::RenderControl *rc = otk::RenderControl::getRenderControl(0); + + rc->render(foo.window()); + + app.run(); + + delete rc; + + printf("\n"); + return 0; +} diff --git a/otk/truerendercontrol.cc b/otk/truerendercontrol.cc new file mode 100644 index 00000000..a99b1997 --- /dev/null +++ b/otk/truerendercontrol.cc @@ -0,0 +1,64 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- + +#ifdef HAVE_CONFIG_H +# include "../config.h" +#endif // HAVE_CONFIG_H + +#include "truerendercontrol.hh" +#include "display.hh" +#include "screeninfo.hh" + +extern "C" { +#ifdef HAVE_STDLIB_H +# include +#endif // HAVE_STDLIB_H + +#include "gettext.h" +#define _(str) gettext(str) +} + +namespace otk { + +TrueRenderControl::TrueRenderControl(const ScreenInfo *screen) + : RenderControl(screen) +{ + printf("Initializing TrueColor RenderControl\n"); + + unsigned long red_mask, green_mask, blue_mask; + + // find the offsets for each color in the visual's masks + red_mask = screen->visual()->red_mask; + green_mask = screen->visual()->green_mask; + blue_mask = screen->visual()->blue_mask; + + while (! (red_mask & 1)) { _red_offset++; red_mask >>= 1; } + while (! (green_mask & 1)) { _green_offset++; green_mask >>= 1; } + while (! (blue_mask & 1)) { _blue_offset++; blue_mask >>= 1; } + + // use the mask to determine the number of bits for each shade of color + // so, best case, red_mask == 0xff (255), with each bit as a different + // shade! + _red_bits = 255 / red_mask; + _green_bits = 255 / green_mask; + _blue_bits = 255 / blue_mask; + + // compute color tables, based on the number of bits for each shade + for (int i = 0; i < 256; i++) { + _red_color_table[i] = i / _red_bits; + _green_color_table[i] = i / _green_bits; + _blue_color_table[i] = i / _blue_bits; + } +} + +TrueRenderControl::~TrueRenderControl() +{ + printf("Destroying TrueColor RenderControl\n"); + + +} + +void TrueRenderControl::render(::Drawable d) +{ +} + +} diff --git a/otk/truerendercontrol.hh b/otk/truerendercontrol.hh new file mode 100644 index 00000000..72e3850e --- /dev/null +++ b/otk/truerendercontrol.hh @@ -0,0 +1,38 @@ +// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- +#ifndef __truerendercontrol_hh +#define __truerendercontrol_hh + +#include "rendercontrol.hh" + +namespace otk { + +class TrueRenderControl : public RenderControl { +private: + // the offset of each color in a color mask + int _red_offset; + int _green_offset; + int _blue_offset; + + // the number of bits (1-255) that each shade of color spans across. best + // case is 1, which gives 255 shades + int _red_bits; + int _green_bits; + int _blue_bits; + + // color tables, meaning, 256 (possibly) different shades of each color, + // based on the number of bits there are available for each color in the + // visual + unsigned char _red_color_table[256]; + unsigned char _green_color_table[256]; + unsigned char _blue_color_table[256]; + +public: + TrueRenderControl(const ScreenInfo *screen); + virtual ~TrueRenderControl(); + + virtual void render(::Drawable d); +}; + +} + +#endif // __truerendercontrol_hh