start of new render code

This commit is contained in:
Dana Jansens 2003-01-18 00:33:48 +00:00
parent 29f331b63f
commit 0dcbf985c1
7 changed files with 250 additions and 1 deletions

View file

@ -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 \

View file

@ -2,6 +2,8 @@
#ifndef __otk_hh
#define __otk_hh
#include "../config.h"
#include "eventdispatcher.hh"
#include "eventhandler.hh"
#include "widget.hh"

60
otk/rendercontrol.cc Normal file
View file

@ -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 <stdlib.h>
#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");
}
}

60
otk/rendercontrol.hh Normal file
View file

@ -0,0 +1,60 @@
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
#ifndef __rendercontrol_hh
#define __rendercontrol_hh
extern "C" {
#include <X11/Xlib.h>
}
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

25
otk/rendertest.cc Normal file
View file

@ -0,0 +1,25 @@
#include "otk.hh"
#include "rendercontrol.hh"
#include <stdio.h>
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;
}

64
otk/truerendercontrol.cc Normal file
View file

@ -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 <stdlib.h>
#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)
{
}
}

38
otk/truerendercontrol.hh Normal file
View file

@ -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