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 | |
| 44 | // Hack to let ConnParams calculate the client's preferred encoding |
| 45 | static bool supported(int encoding); |
| 46 | |
| 47 | void writeUpdate(const UpdateInfo& ui, const PixelBuffer* pb, |
| 48 | const RenderedCursor* renderedCursor); |
| 49 | |
| 50 | protected: |
| 51 | void prepareEncoders(); |
| 52 | |
| 53 | int computeNumRects(const Region& changed); |
| 54 | |
| 55 | void writeCopyRects(const UpdateInfo& ui); |
| 56 | void writeSolidRects(Region *changed, const PixelBuffer* pb); |
| 57 | void writeRects(const Region& changed, const PixelBuffer* pb); |
| 58 | |
| 59 | void writeSubRect(const Rect& rect, const PixelBuffer *pb); |
| 60 | |
| 61 | bool checkSolidTile(const Rect& r, const rdr::U8* colourValue, |
| 62 | const PixelBuffer *pb); |
| 63 | void extendSolidAreaByBlock(const Rect& r, const rdr::U8* colourValue, |
| 64 | const PixelBuffer *pb, Rect* er); |
| 65 | void extendSolidAreaByPixel(const Rect& r, const Rect& sr, |
| 66 | const rdr::U8* colourValue, |
| 67 | const PixelBuffer *pb, Rect* er); |
| 68 | |
| 69 | PixelBuffer* preparePixelBuffer(const Rect& rect, |
| 70 | const PixelBuffer *pb, bool convert); |
| 71 | |
| 72 | bool analyseRect(const PixelBuffer *pb, |
| 73 | struct RectInfo *info, int maxColours); |
| 74 | |
| 75 | protected: |
| 76 | // Preprocessor generated, optimised methods |
| 77 | inline bool checkSolidTile(const Rect& r, rdr::U8 colourValue, |
| 78 | const PixelBuffer *pb); |
| 79 | inline bool checkSolidTile(const Rect& r, rdr::U16 colourValue, |
| 80 | const PixelBuffer *pb); |
| 81 | inline bool checkSolidTile(const Rect& r, rdr::U32 colourValue, |
| 82 | const PixelBuffer *pb); |
| 83 | |
| 84 | inline bool analyseRect(int width, int height, |
| 85 | const rdr::U8* buffer, int stride, |
| 86 | struct RectInfo *info, int maxColours); |
| 87 | inline bool analyseRect(int width, int height, |
| 88 | const rdr::U16* buffer, int stride, |
| 89 | struct RectInfo *info, int maxColours); |
| 90 | inline bool analyseRect(int width, int height, |
| 91 | const rdr::U32* buffer, int stride, |
| 92 | struct RectInfo *info, int maxColours); |
| 93 | |
| 94 | protected: |
| 95 | SConnection *conn; |
| 96 | |
| 97 | std::vector<Encoder*> encoders; |
| 98 | std::vector<int> activeEncoders; |
| 99 | |
| 100 | class OffsetPixelBuffer : public FullFramePixelBuffer { |
| 101 | public: |
| 102 | OffsetPixelBuffer() {} |
| 103 | virtual ~OffsetPixelBuffer() {} |
| 104 | |
| 105 | void update(const PixelFormat& pf, int width, int height, |
| 106 | const rdr::U8* data_, int stride); |
| 107 | }; |
| 108 | |
| 109 | OffsetPixelBuffer offsetPixelBuffer; |
| 110 | ManagedPixelBuffer convertedPixelBuffer; |
| 111 | }; |
| 112 | } |
| 113 | |
| 114 | #endif |