blob: f6ffa4b6e98e812ababad7bc4413c41a8c765f03 [file] [log] [blame]
Pierre Ossman9f273e92015-11-09 16:34:54 +01001/* Copyright 2015 Pierre Ossman for Cendio AB
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19#include <assert.h>
20#include <string.h>
21
22#include <rfb/DecodeManager.h>
23#include <rfb/Decoder.h>
24
25#include <rfb/LogWriter.h>
26
27#include <rdr/Exception.h>
28
29using namespace rfb;
30
31static LogWriter vlog("DecodeManager");
32
33DecodeManager::DecodeManager(CConnection *conn) :
34 conn(conn)
35{
36 memset(decoders, 0, sizeof(decoders));
37}
38
39DecodeManager::~DecodeManager()
40{
41 for (size_t i = 0; i < sizeof(decoders)/sizeof(decoders[0]); i++)
42 delete decoders[i];
43}
44
45void DecodeManager::decodeRect(const Rect& r, int encoding,
46 ModifiablePixelBuffer* pb)
47{
48 assert(pb != NULL);
49
50 if (!Decoder::supported(encoding)) {
51 vlog.error("Unknown encoding %d", encoding);
52 throw rdr::Exception("Unknown encoding");
53 }
54
55 if (!decoders[encoding]) {
56 decoders[encoding] = Decoder::createDecoder(encoding, conn);
57 if (!decoders[encoding]) {
58 vlog.error("Unknown encoding %d", encoding);
59 throw rdr::Exception("Unknown encoding");
60 }
61 }
62 decoders[encoding]->readRect(r, pb);
63}