OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libjava/] [gnu/] [gcj/] [xlib/] [natColormap.cc] - Blame information for rev 756

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 756 jeremybenn
/* Copyright (C) 2000  Free Software Foundation
2
 
3
   This file is part of libgcj.
4
 
5
This software is copyrighted work licensed under the terms of the
6
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
7
details.  */
8
 
9
// Needed to avoid linking in libstdc++
10
#ifndef __STL_USE_EXCEPTIONS
11
#   include <java/lang/OutOfMemoryError.h>
12
#   define __THROW_BAD_ALLOC throw new java::lang::OutOfMemoryError()
13
#endif
14
 
15
#include <vector>
16
 
17
#include <X11/Xlib.h>
18
 
19
#include <gcj/cni.h>
20
#include <java/lang/RuntimeException.h>
21
#include <gnu/gcj/xlib/Display.h>
22
#include <gnu/gcj/xlib/Screen.h>
23
#include <gnu/gcj/xlib/Colormap.h>
24
#include <gnu/gcj/xlib/XColor.h>
25
#include <gnu/gcj/RawData.h>
26
 
27
jlong gnu::gcj::xlib::Colormap::allocateColorPixel(XColor* color)
28
{
29
  ::Display* dpy = (::Display*) (screen->getDisplay()->display);
30
  ::XColor* col = (::XColor*) (color->structure);
31
  Status result = XAllocColor(dpy, xid, col);
32
  if (result == 0)
33
    throw new ::java::lang::RuntimeException(
34
      JvNewStringLatin1("Unable to allocate color pixel."));
35
 
36
  return col->pixel;
37
}
38
 
39
typedef JArray<gnu::gcj::xlib::XColor*>* xcolorarray;
40
 
41
xcolorarray gnu::gcj::xlib::Colormap::getSharedColors()
42
{
43
  ::Display* dpy = (::Display*) (screen->getDisplay()->display);
44
  unsigned int nCells = CellsOfScreen(ScreenOfDisplay(dpy, screen->screenNumber));
45
 
46
  typedef ::XColor xcolor;
47
  std::vector<xcolor> colors(nCells);
48
  for (unsigned int i=0; i<nCells; i++)
49
    colors[i].pixel = i;
50
  ::XColor* cols = colors.get_allocator().address(colors.front());
51
  XQueryColors(dpy, xid, cols,
52
               nCells);
53
 
54
  int nShared = 0;
55
  for (unsigned int i=0; i<nCells; i++)
56
    {
57
      ::XColor color = colors[i];
58
 
59
      if (!XAllocColor(dpy, xid, &color))
60
        continue;
61
 
62
      /* FIXME: In some cases this algorithm may identify a free
63
         color cell as a shared one. */
64
      if (color.pixel != i)
65
        {
66
          // Oops, the color wasn't shared. Free it.
67
          XFreeColors(dpy, xid, &(color.pixel), 1, 0);
68
          colors[i].flags = FLAG_NOT_SHARED;
69
          continue;
70
        }
71
 
72
      // FIXME: Shared or free?
73
 
74
      nShared++;
75
      colors[i].flags = FLAG_SHARED;
76
    }
77
 
78
  JArray<XColor*>* shared = newXColorArray(nShared);
79
  int si=0;
80
  for (unsigned int i=0; i<nCells; i++)
81
    {
82
      if (colors[i].flags != FLAG_SHARED)
83
        continue;
84
 
85
      XColor* col = elements(shared)[si++];
86
      gnu::gcj::RawData* colorData = col->structure;
87
      ::XColor* colStruct = reinterpret_cast<xcolor*>(colorData);
88
      *colStruct = colors[i];
89
    }
90
 
91
  return shared;
92
}
93
 
94
xcolorarray gnu::gcj::xlib::Colormap::getXColors()
95
{
96
  ::Display* dpy = (::Display*) (screen->getDisplay()->display);
97
  unsigned int nCells =
98
    CellsOfScreen(ScreenOfDisplay(dpy, screen->screenNumber));
99
 
100
  typedef ::XColor xcolor;
101
  std::vector<xcolor> colors(nCells);
102
 
103
  JArray<XColor*>* colArray = newXColorArray(nCells);
104
 
105
  for (unsigned int i=0; i<nCells; i++)
106
    colors[i].pixel = i;
107
 
108
  XQueryColors(dpy, xid, &(colors.front()), nCells);
109
 
110
  /* TODO: The current problem with this code is that it relies on
111
     (color.pixel == i) as an indicator that the color is
112
     shared. However, (color.pixel == i), may also occur simply
113
     because color cell i simply was the next free in the list of
114
     unallocated color cells.  IDEA: run through the list both
115
     backwards and forwards, and only pick out the colorcells that
116
     have been identified as shared during both passes.  Reversing the
117
     traversal direction might prevent i from corresponding to the
118
     next free colorcell, atleast in one of the passes. */
119
  for (unsigned int i=0; i<nCells; i++)
120
    {
121
      ::XColor color = colors[i];
122
 
123
      char flag = FLAG_NOT_SHARED;
124
      if (XAllocColor(dpy, xid, &color))
125
        {
126
          if (color.pixel == i)
127
            {
128
              flag = FLAG_SHARED;
129
            }
130
          else
131
            {
132
              // Oops, the color wasn't shared. Free it.
133
              XFreeColors(dpy, xid, &(color.pixel), 1, 0);
134
            }
135
        }
136
 
137
      // Copy color data into object in array
138
      XColor* col = elements(colArray)[i];
139
      gnu::gcj::RawData* colorData = col->structure;
140
      ::XColor* colStruct = reinterpret_cast<xcolor*>(colorData);
141
      *colStruct = colors[i];
142
      colStruct->flags = flag;
143
    }
144
 
145
  return colArray;
146
}
147
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.