1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
* Copyright 2014 Pierre Ossman for Cendio AB
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
// -=- PixelBuffer.h
//
// The PixelBuffer class encapsulates the PixelFormat and dimensions
// of a block of pixel data.
#ifndef __RFB_PIXEL_BUFFER_H__
#define __RFB_PIXEL_BUFFER_H__
#include <rfb/PixelFormat.h>
#include <rfb/Rect.h>
#include <rfb/Pixel.h>
#include <rfb/util.h>
namespace rfb {
class Region;
class PixelBuffer {
public:
PixelBuffer(const PixelFormat& pf, int width, int height);
virtual ~PixelBuffer();
///////////////////////////////////////////////
// Format / Layout
//
public:
// Get pixel format
const PixelFormat &getPF() const { return format; }
// Get width, height and number of pixels
int width() const { return width_; }
int height() const { return height_; }
int area() const { return width_ * height_; }
// Get rectangle encompassing this buffer
// Top-left of rectangle is either at (0,0), or the specified point.
Rect getRect() const { return Rect(0, 0, width_, height_); }
Rect getRect(const Point& pos) const {
return Rect(pos, pos.translate(Point(width_, height_)));
}
///////////////////////////////////////////////
// Access to pixel data
//
// Get a pointer into the buffer
// The pointer is to the top-left pixel of the specified Rect.
// The buffer stride (in pixels) is returned.
virtual const rdr::U8* getBuffer(const Rect& r, int* stride) const = 0;
// Get pixel data for a given part of the buffer
// Data is copied into the supplied buffer, with the specified
// stride. Try to avoid using this though as getBuffer() will in
// most cases avoid the extra memory copy.
void getImage(void* imageBuf, const Rect& r, int stride=0) const;
// Get pixel data in a given format
// Works just the same as getImage(), but guaranteed to be in a
// specific format.
void getImage(const PixelFormat& pf, void* imageBuf,
const Rect& r, int stride=0) const;
///////////////////////////////////////////////
// Framebuffer update methods
//
// Ensure that the specified rectangle of buffer is up to date.
// Overridden by derived classes implementing framebuffer access
// to copy the required display data into place.
virtual void grabRegion(const Region& __unused_attr region) {}
protected:
PixelBuffer();
virtual void setSize(int width, int height);
protected:
PixelFormat format;
private:
int width_, height_;
};
// ModifiablePixelBuffer
class ModifiablePixelBuffer : public PixelBuffer {
public:
ModifiablePixelBuffer(const PixelFormat& pf, int width, int height);
virtual ~ModifiablePixelBuffer();
///////////////////////////////////////////////
// Access to pixel data
//
// Get a writeable pointer into the buffer
// Like getBuffer(), the pointer is to the top-left pixel of the
// specified Rect and the stride in pixels is returned.
virtual rdr::U8* getBufferRW(const Rect& r, int* stride) = 0;
// Commit the modified contents
// Ensures that the changes to the specified Rect is properly
// stored away and any temporary buffers are freed. The Rect given
// here needs to match the Rect given to the earlier call to
// getBufferRW().
virtual void commitBufferRW(const Rect& r) = 0;
///////////////////////////////////////////////
// Basic rendering operations
// These operations DO NOT clip to the pixelbuffer area, or trap overruns.
// Fill a rectangle
void fillRect(const Rect &dest, const void* pix);
// Copy pixel data to the buffer
void imageRect(const Rect &dest, const void* pixels, int stride=0);
// Copy pixel data from one PixelBuffer location to another
void copyRect(const Rect &dest, const Point& move_by_delta);
// Render in a specific format
// Does the exact same thing as the above methods, but the given
// pixel values are defined by the given PixelFormat.
void fillRect(const PixelFormat& pf, const Rect &dest, const void* pix);
void imageRect(const PixelFormat& pf, const Rect &dest,
const void* pixels, int stride=0);
protected:
ModifiablePixelBuffer();
};
// FullFramePixelBuffer
class FullFramePixelBuffer : public ModifiablePixelBuffer {
public:
FullFramePixelBuffer(const PixelFormat& pf, int width, int height,
rdr::U8* data_, int stride);
virtual ~FullFramePixelBuffer();
public:
virtual const rdr::U8* getBuffer(const Rect& r, int* stride) const;
virtual rdr::U8* getBufferRW(const Rect& r, int* stride);
virtual void commitBufferRW(const Rect& r);
protected:
FullFramePixelBuffer();
virtual void setBuffer(int width, int height, rdr::U8* data, int stride);
private:
virtual void setSize(int w, int h);
private:
rdr::U8* data;
int stride;
};
// -=- Managed pixel buffer class
// Automatically allocates enough space for the specified format & area
class ManagedPixelBuffer : public FullFramePixelBuffer {
public:
ManagedPixelBuffer();
ManagedPixelBuffer(const PixelFormat& pf, int width, int height);
virtual ~ManagedPixelBuffer();
// Manage the pixel buffer layout
virtual void setPF(const PixelFormat &pf);
virtual void setSize(int w, int h);
private:
rdr::U8* data_; // Mirrors FullFramePixelBuffer::data
unsigned long datasize;
};
};
#endif // __RFB_PIXEL_BUFFER_H__
|