Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 1 | /* 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 | |
| 28 | namespace 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 Ossman | 20dd2a9 | 2015-02-11 17:43:15 +0100 | [diff] [blame] | 44 | void logStats(); |
| 45 | |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 46 | // 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 Ossman | 20dd2a9 | 2015-02-11 17:43:15 +0100 | [diff] [blame] | 57 | Encoder *startRect(const Rect& rect, int type); |
| 58 | void endRect(); |
| 59 | |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 60 | void writeCopyRects(const UpdateInfo& ui); |
| 61 | void writeSolidRects(Region *changed, const PixelBuffer* pb); |
Pierre Ossman | eef5516 | 2015-02-12 13:44:22 +0100 | [diff] [blame] | 62 | void findSolidRect(const Rect& rect, Region *changed, const PixelBuffer* pb); |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 63 | 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 Ossman | 20dd2a9 | 2015-02-11 17:43:15 +0100 | [diff] [blame] | 106 | 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; |
Pierre Ossman | e539cb8 | 2015-09-22 11:09:00 +0200 | [diff] [blame] | 115 | EncoderStats copyStats; |
Pierre Ossman | 20dd2a9 | 2015-02-11 17:43:15 +0100 | [diff] [blame] | 116 | StatsVector stats; |
| 117 | int activeType; |
| 118 | int beforeLength; |
| 119 | |
Pierre Ossman | c039726 | 2014-03-14 15:59:46 +0100 | [diff] [blame] | 120 | class OffsetPixelBuffer : public FullFramePixelBuffer { |
| 121 | public: |
| 122 | OffsetPixelBuffer() {} |
| 123 | virtual ~OffsetPixelBuffer() {} |
| 124 | |
| 125 | void update(const PixelFormat& pf, int width, int height, |
| 126 | const rdr::U8* data_, int stride); |
| 127 | }; |
| 128 | |
| 129 | OffsetPixelBuffer offsetPixelBuffer; |
| 130 | ManagedPixelBuffer convertedPixelBuffer; |
| 131 | }; |
| 132 | } |
| 133 | |
| 134 | #endif |