blob: a694e063e4eacbcadaf3b14367873890cd2071ae [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);
62 void writeRects(const Region& changed, const PixelBuffer* pb);
63
64 void writeSubRect(const Rect& rect, const PixelBuffer *pb);
65
66 bool checkSolidTile(const Rect& r, const rdr::U8* colourValue,
67 const PixelBuffer *pb);
68 void extendSolidAreaByBlock(const Rect& r, const rdr::U8* colourValue,
69 const PixelBuffer *pb, Rect* er);
70 void extendSolidAreaByPixel(const Rect& r, const Rect& sr,
71 const rdr::U8* colourValue,
72 const PixelBuffer *pb, Rect* er);
73
74 PixelBuffer* preparePixelBuffer(const Rect& rect,
75 const PixelBuffer *pb, bool convert);
76
77 bool analyseRect(const PixelBuffer *pb,
78 struct RectInfo *info, int maxColours);
79
80 protected:
81 // Preprocessor generated, optimised methods
82 inline bool checkSolidTile(const Rect& r, rdr::U8 colourValue,
83 const PixelBuffer *pb);
84 inline bool checkSolidTile(const Rect& r, rdr::U16 colourValue,
85 const PixelBuffer *pb);
86 inline bool checkSolidTile(const Rect& r, rdr::U32 colourValue,
87 const PixelBuffer *pb);
88
89 inline bool analyseRect(int width, int height,
90 const rdr::U8* buffer, int stride,
91 struct RectInfo *info, int maxColours);
92 inline bool analyseRect(int width, int height,
93 const rdr::U16* buffer, int stride,
94 struct RectInfo *info, int maxColours);
95 inline bool analyseRect(int width, int height,
96 const rdr::U32* buffer, int stride,
97 struct RectInfo *info, int maxColours);
98
99 protected:
100 SConnection *conn;
101
102 std::vector<Encoder*> encoders;
103 std::vector<int> activeEncoders;
104
Pierre Ossman20dd2a92015-02-11 17:43:15 +0100105 struct EncoderStats {
106 unsigned rects;
107 unsigned long long bytes;
108 unsigned long long pixels;
109 unsigned long long equivalent;
110 };
111 typedef std::vector< std::vector<struct EncoderStats> > StatsVector;
112
113 unsigned updates;
114 StatsVector stats;
115 int activeType;
116 int beforeLength;
117
Pierre Ossmanc0397262014-03-14 15:59:46 +0100118 class OffsetPixelBuffer : public FullFramePixelBuffer {
119 public:
120 OffsetPixelBuffer() {}
121 virtual ~OffsetPixelBuffer() {}
122
123 void update(const PixelFormat& pf, int width, int height,
124 const rdr::U8* data_, int stride);
125 };
126
127 OffsetPixelBuffer offsetPixelBuffer;
128 ManagedPixelBuffer convertedPixelBuffer;
129 };
130}
131
132#endif