]> Dogcows Code - chaz/openbox/commitdiff
start of new render code
authorDana Jansens <danakj@orodu.net>
Sat, 18 Jan 2003 00:33:48 +0000 (00:33 +0000)
committerDana Jansens <danakj@orodu.net>
Sat, 18 Jan 2003 00:33:48 +0000 (00:33 +0000)
otk/Makefile.am
otk/otk.hh
otk/rendercontrol.cc [new file with mode: 0644]
otk/rendercontrol.hh [new file with mode: 0644]
otk/rendertest.cc [new file with mode: 0644]
otk/truerendercontrol.cc [new file with mode: 0644]
otk/truerendercontrol.hh [new file with mode: 0644]

index d89647589145856eaa58b8bcf1ab6ed320256010..ae5bcf7930ea508c033224e7032a4afaf090c608 100644 (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 \
index 23af8477e14c9de4f9064a36c54f4fdf404d5552..397534e5dcf59c4796264b90b7a989ca12a7d362 100644 (file)
@@ -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 (file)
index 0000000..1dd5704
--- /dev/null
@@ -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");
+
+
+}
+
+}
diff --git a/otk/rendercontrol.hh b/otk/rendercontrol.hh
new file mode 100644 (file)
index 0000000..cc05a31
--- /dev/null
@@ -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
diff --git a/otk/rendertest.cc b/otk/rendertest.cc
new file mode 100644 (file)
index 0000000..c9226b1
--- /dev/null
@@ -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;
+}
diff --git a/otk/truerendercontrol.cc b/otk/truerendercontrol.cc
new file mode 100644 (file)
index 0000000..a99b199
--- /dev/null
@@ -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)
+{
+}
+
+}
diff --git a/otk/truerendercontrol.hh b/otk/truerendercontrol.hh
new file mode 100644 (file)
index 0000000..72e3850
--- /dev/null
@@ -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
This page took 0.030473 seconds and 4 git commands to generate.