blob: a3df8f746160af77c90b863370426175bbbf2612 [file] [log] [blame]
Pierre Ossmanc0397262014-03-14 15:59:46 +01001/* Copyright (C) 2000-2003 Constantin Kaplinsky. All Rights Reserved.
2 * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
3 * Copyright 2014 Pierre Ossman for Cendio AB
4 *
5 * This is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This software is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this software; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
18 * USA.
19 */
20#ifndef __RFB_ENCODEMANAGER_H__
21#define __RFB_ENCODEMANAGER_H__
22
23#include <vector>
24
25#include <rdr/types.h>
26#include <rfb/PixelBuffer.h>
27
28namespace rfb {
29 class SConnection;
30 class Encoder;
31 class UpdateInfo;
32 class PixelBuffer;
33 class RenderedCursor;
34 class Region;
35 class Rect;
36
37 struct RectInfo;
38
39 class EncodeManager {
40 public:
41 EncodeManager(SConnection* conn);
42 ~EncodeManager();
43
Pierre Ossman20dd2a92015-02-11 17:43:15 +010044 void logStats();
45
Pierre Ossmanc0397262014-03-14 15:59:46 +010046 // Hack to let ConnParams calculate the client's preferred encoding
47 static bool supported(int encoding);
48
49 void writeUpdate(const UpdateInfo& ui, const PixelBuffer* pb,
50 const RenderedCursor* renderedCursor);
51
52 protected:
53 void prepareEncoders();
54
55 int computeNumRects(const Region& changed);
56
Pierre Ossman20dd2a92015-02-11 17:43:15 +010057 Encoder *startRect(const Rect& rect, int type);
58 void endRect();
59
Pierre Ossmanc0397262014-03-14 15:59:46 +010060 void writeCopyRects(const UpdateInfo& ui);
61 void writeSolidRects(Region *changed, const PixelBuffer* pb);
Pierre Ossmaneef55162015-02-12 13:44:22 +010062 void findSolidRect(const Rect& rect, Region *changed, const PixelBuffer* pb);
Pierre Ossmanc0397262014-03-14 15:59:46 +010063 void writeRects(const Region& changed, const PixelBuffer* pb);
64
65 void writeSubRect(const Rect& rect, const PixelBuffer *pb);
66
67 bool checkSolidTile(const Rect& r, const rdr::U8* colourValue,
68 const PixelBuffer *pb);
69 void extendSolidAreaByBlock(const Rect& r, const rdr::U8* colourValue,
70 const PixelBuffer *pb, Rect* er);
71 void extendSolidAreaByPixel(const Rect& r, const Rect& sr,
72 const rdr::U8* colourValue,
73 const PixelBuffer *pb, Rect* er);
74
75 PixelBuffer* preparePixelBuffer(const Rect& rect,
76 const PixelBuffer *pb, bool convert);
77
78 bool analyseRect(const PixelBuffer *pb,
79 struct RectInfo *info, int maxColours);
80
81 protected:
82 // Preprocessor generated, optimised methods
83 inline bool checkSolidTile(const Rect& r, rdr::U8 colourValue,
84 const PixelBuffer *pb);
85 inline bool checkSolidTile(const Rect& r, rdr::U16 colourValue,
86 const PixelBuffer *pb);
87 inline bool checkSolidTile(const Rect& r, rdr::U32 colourValue,
88 const PixelBuffer *pb);
89
90 inline bool analyseRect(int width, int height,
91 const rdr::U8* buffer, int stride,
92 struct RectInfo *info, int maxColours);
93 inline bool analyseRect(int width, int height,
94 const rdr::U16* buffer, int stride,
95 struct RectInfo *info, int maxColours);
96 inline bool analyseRect(int width, int height,
97 const rdr::U32* buffer, int stride,
98 struct RectInfo *info, int maxColours);
99
100 protected:
101 SConnection *conn;
102
103 std::vector<Encoder*> encoders;
104 std::vector<int> activeEncoders;
105
Pierre Ossman20dd2a92015-02-11 17:43:15 +0100106 struct EncoderStats {
107 unsigned rects;
108 unsigned long long bytes;
109 unsigned long long pixels;
110 unsigned long long equivalent;
111 };
112 typedef std::vector< std::vector<struct EncoderStats> > StatsVector;
113
114 unsigned updates;
115 StatsVector stats;
116 int activeType;
117 int beforeLength;
118
Pierre Ossmanc0397262014-03-14 15:59:46 +0100119 class OffsetPixelBuffer : public FullFramePixelBuffer {
120 public:
121 OffsetPixelBuffer() {}
122 virtual ~OffsetPixelBuffer() {}
123
124 void update(const PixelFormat& pf, int width, int height,
125 const rdr::U8* data_, int stride);
126 };
127
128 OffsetPixelBuffer offsetPixelBuffer;
129 ManagedPixelBuffer convertedPixelBuffer;
130 };
131}
132
133#endif