aboutsummaryrefslogtreecommitdiff
path: root/util/fbcompose/OpenGLTexPartitioner.hh
diff options
context:
space:
mode:
Diffstat (limited to 'util/fbcompose/OpenGLTexPartitioner.hh')
-rw-r--r--util/fbcompose/OpenGLTexPartitioner.hh189
1 files changed, 189 insertions, 0 deletions
diff --git a/util/fbcompose/OpenGLTexPartitioner.hh b/util/fbcompose/OpenGLTexPartitioner.hh
new file mode 100644
index 0000000..d37f744
--- /dev/null
+++ b/util/fbcompose/OpenGLTexPartitioner.hh
@@ -0,0 +1,189 @@
1/** OpenGLTexPartitioner.hh file for the fluxbox compositor. */
2
3// Copyright (c) 2011 Gediminas Liktaras (gliktaras at gmail dot com)
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in
13// all copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21// THE SOFTWARE.
22
23
24#ifndef FBCOMPOSITOR_OPENGLTEXPARTITIONER_HH
25#define FBCOMPOSITOR_OPENGLTEXPARTITIONER_HH
26
27
28#include "Exceptions.hh"
29#include "OpenGLResources.hh"
30
31#include "FbTk/RefCount.hh"
32
33#include <GL/glxew.h>
34#include <GL/glx.h>
35
36#include <X11/Xlib.h>
37
38#include <algorithm>
39#include <vector>
40
41
42namespace FbCompositor {
43
44 class OpenGLScreen;
45
46
47 //--- CONSTANTS ------------------------------------------------------------
48
49 /** North border flag. */
50 const int BORDER_NORTH = 1 << 0;
51
52 /** East border flag. */
53 const int BORDER_EAST = 1 << 1;
54
55 /** South border flag. */
56 const int BORDER_SOUTH = 1 << 2;
57
58 /** West border flag. */
59 const int BORDER_WEST = 1 << 3;
60
61 /** A bitfield with all border flags set. */
62 const int BORDER_ALL = BORDER_NORTH | BORDER_EAST | BORDER_SOUTH | BORDER_WEST;
63
64
65 //--- SUPPORTING STRUCTURES ------------------------------------------------
66
67 /**
68 * A single 2D texture partition.
69 */
70 struct TexturePart {
71 OpenGL2DTexturePtr texture; ///< Partition's contents.
72 unsigned int borders; ///< A bitfield showing borders, adjacent to this partition.
73 };
74
75
76 //--- TEXTURE PARTITIONER --------------------------------------------------
77
78 /**
79 * A wrapper that automatically splits large textures into manageable (i.e.
80 * with supported size) parts.
81 */
82 class OpenGL2DTexturePartition {
83 public:
84 //--- CONSTRUCTORS AND DESTRUCTORS -------------------------------------
85
86 /** Constructor. */
87 OpenGL2DTexturePartition(const OpenGLScreen &screen, bool swizzle_alpha_to_one);
88
89 /** Destructor. */
90 ~OpenGL2DTexturePartition();
91
92
93 //--- ACCESSORS --------------------------------------------------------
94
95 /** \returns the partitions of the current texture. */
96 const std::vector<TexturePart> &partitions() const;
97
98
99 /** \returns the full height of the current texture. */
100 int fullHeight() const;
101
102 /** \returns the full width of the current texture. */
103 int fullWidth() const;
104
105
106 //--- MUTATORS ---------------------------------------------------------
107
108 /** Sets the texture's contents to the given pixmap. */
109 void setPixmap(Pixmap pixmap, bool manage_pixmap, int width, int height, int depth);
110
111
112 private:
113 //--- CONSTRUCTORS -----------------------------------------------------
114
115 /** Constructor. */
116 OpenGL2DTexturePartition(const OpenGL2DTexturePartition &other);
117
118 /** Assignment operator. */
119 OpenGL2DTexturePartition &operator=(const OpenGL2DTexturePartition &other);
120
121
122 //--- INTERNALS --------------------------------------------------------
123
124 /** Maximum supported texture size. */
125 int m_max_texture_size;
126
127 /** Whether alpha channel should be swizzled to one. */
128 bool m_swizzle_alpha_to_one;
129
130
131 /** Partitions of the texture. */
132 std::vector<TexturePart> m_partitions;
133
134 /** Pixmap of the texture's contents. */
135 Pixmap m_pixmap;
136
137
138 /** Full texture height. */
139 int m_full_height;
140
141 /** Full texture width. */
142 int m_full_width;
143
144
145 /** Current connection to the X server. */
146 Display *m_display;
147
148 /** Screen that manages this texture. */
149 const OpenGLScreen &m_screen;
150 };
151
152 // Returns the full height of the current texture.
153 inline int OpenGL2DTexturePartition::fullHeight() const {
154 return m_full_height;
155 }
156
157 // Returns the full width of the current texture.
158 inline int OpenGL2DTexturePartition::fullWidth() const {
159 return m_full_width;
160 }
161
162 // Returns the partitions of the current texture.
163 inline const std::vector<TexturePart> &OpenGL2DTexturePartition::partitions() const {
164 return m_partitions;
165 }
166
167
168 //--- SUPPORTING FUNCTIONS -------------------------------------------------
169
170 /** Returns the border bitfield of the given partition. */
171 unsigned int getBorderBitfield(int unit_width, int unit_height, int x, int y);
172
173 /** Space partitioning function. */
174 std::vector<XRectangle> partitionSpace(int x, int y, int width, int height, int max_partition_size,
175 int *unit_width_return = 0, int *unit_height_return = 0);
176
177 /** Partitions space directly to buffers. */
178 std::vector<OpenGLBufferPtr> partitionSpaceToBuffers(const OpenGLScreen &screen, int x, int y,
179 int width, int height);
180
181
182 //--- TYPEDEFS -------------------------------------------------------------
183
184 /** OpenGL texture partition smart pointer. */
185 typedef FbTk::RefCount<OpenGL2DTexturePartition> OpenGL2DTexturePartitionPtr;
186}
187
188#endif // FBCOMPOSITOR_OPENGLTEXPARTITIONER_HH
189