blob: 4cc09f226794bd7aff7a9697d1f281c38ebe7410 [file] [log] [blame]
Pierre Ossman5156d5e2011-03-09 09:42:34 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
2 * Copyright 2009-2011 Pierre Ossman <ossman@cendio.se> for Cendio AB
DRC33c15e32011-11-03 18:49:21 +00003 * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
Pierre Ossman5156d5e2011-03-09 09:42:34 +00004 *
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
Peter Åstrandc359f362011-08-23 12:04:46 +000021#ifdef HAVE_CONFIG_H
22#include <config.h>
23#endif
24
Pierre Ossman5156d5e2011-03-09 09:42:34 +000025#include <assert.h>
DRCb65bb932011-06-24 03:17:00 +000026#ifndef _WIN32
Pierre Ossman5156d5e2011-03-09 09:42:34 +000027#include <unistd.h>
DRCb65bb932011-06-24 03:17:00 +000028#endif
Pierre Ossman5156d5e2011-03-09 09:42:34 +000029
30#include <rfb/CMsgWriter.h>
31#include <rfb/encodings.h>
32#include <rfb/Hostname.h>
33#include <rfb/LogWriter.h>
34#include <rfb/util.h>
35#include <rfb/screenTypes.h>
Pierre Ossmane28bdb22011-11-14 16:02:06 +000036#include <rfb/fenceTypes.h>
Pierre Ossman5156d5e2011-03-09 09:42:34 +000037#include <rfb/Timer.h>
Pierre Ossmane28bdb22011-11-14 16:02:06 +000038#include <rdr/MemInStream.h>
39#include <rdr/MemOutStream.h>
Pierre Ossman5156d5e2011-03-09 09:42:34 +000040#include <network/TcpSocket.h>
41
42#include <FL/Fl.H>
43#include <FL/fl_ask.H>
44
45#include "CConn.h"
Pierre Ossmanf4f30942011-05-17 09:39:07 +000046#include "OptionsDialog.h"
Pierre Ossman5156d5e2011-03-09 09:42:34 +000047#include "i18n.h"
48#include "parameters.h"
Pierre Ossman39ceb502011-07-12 15:54:25 +000049#include "vncviewer.h"
Pierre Ossman5156d5e2011-03-09 09:42:34 +000050
DRCb65bb932011-06-24 03:17:00 +000051#ifdef WIN32
52#include "win32.h"
53#endif
54
Pierre Ossman5156d5e2011-03-09 09:42:34 +000055using namespace rdr;
56using namespace rfb;
57using namespace std;
58
Pierre Ossman5156d5e2011-03-09 09:42:34 +000059static rfb::LogWriter vlog("CConn");
60
Pierre Ossmancf836f22011-07-14 14:34:09 +000061// 8 colours (1 bit per component)
62static const PixelFormat verylowColourPF(8, 3,false, true,
63 1, 1, 1, 2, 1, 0);
64// 64 colours (2 bits per component)
65static const PixelFormat lowColourPF(8, 6, false, true,
66 3, 3, 3, 4, 2, 0);
67// 256 colours (palette)
68static const PixelFormat mediumColourPF(8, 8, false, false);
Pierre Ossmanf4f30942011-05-17 09:39:07 +000069
Pierre Ossman5156d5e2011-03-09 09:42:34 +000070CConn::CConn(const char* vncServerName)
71 : serverHost(0), serverPort(0), sock(NULL), desktop(NULL),
Pierre Ossman5d512c32011-11-04 11:42:16 +000072 pendingPFChange(false),
Pierre Ossman5156d5e2011-03-09 09:42:34 +000073 currentEncoding(encodingTight), lastServerEncoding((unsigned int)-1),
74 formatChange(false), encodingChange(false),
Pierre Ossmand4c61ce2011-04-29 11:18:12 +000075 firstUpdate(true), pendingUpdate(false),
Pierre Ossmane28bdb22011-11-14 16:02:06 +000076 forceNonincremental(true), supportsSyncFence(false)
Pierre Ossman5156d5e2011-03-09 09:42:34 +000077{
78 setShared(::shared);
79
80 int encNum = encodingNum(preferredEncoding);
81 if (encNum != -1)
82 currentEncoding = encNum;
83
Pierre Ossmanda389562011-06-09 08:24:37 +000084 cp.supportsLocalCursor = true;
85
Pierre Ossman5156d5e2011-03-09 09:42:34 +000086 cp.supportsDesktopResize = true;
87 cp.supportsExtendedDesktopSize = true;
88 cp.supportsDesktopRename = true;
Pierre Ossman5156d5e2011-03-09 09:42:34 +000089
90 cp.customCompressLevel = customCompressLevel;
91 cp.compressLevel = compressLevel;
92
93 cp.noJpeg = noJpeg;
94 cp.qualityLevel = qualityLevel;
95
96 try {
97 getHostAndPort(vncServerName, &serverHost, &serverPort);
98
99 sock = new network::TcpSocket(serverHost, serverPort);
100 vlog.info(_("connected to host %s port %d"), serverHost, serverPort);
101 } catch (rdr::Exception& e) {
102 vlog.error(e.str());
103 fl_alert(e.str());
104 exit_vncviewer();
105 return;
106 }
107
108 Fl::add_fd(sock->getFd(), FL_READ | FL_EXCEPT, socketEvent, this);
109
110 // See callback below
111 sock->inStream().setBlockCallback(this);
112
113 setServerName(serverHost);
114 setStreams(&sock->inStream(), &sock->outStream());
115
116 initialiseProtocol();
Pierre Ossmanf4f30942011-05-17 09:39:07 +0000117
118 OptionsDialog::addCallback(handleOptions, this);
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000119}
120
121CConn::~CConn()
122{
Pierre Ossmanf4f30942011-05-17 09:39:07 +0000123 OptionsDialog::removeCallback(handleOptions);
124
Pierre Ossman6a9e2e62011-05-19 14:47:43 +0000125 if (desktop)
126 delete desktop;
127
Pierre Ossman5e04c262011-11-09 11:31:12 +0000128 delete [] serverHost;
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000129 if (sock)
130 Fl::remove_fd(sock->getFd());
131 delete sock;
132}
133
Pierre Ossmand4c61ce2011-04-29 11:18:12 +0000134void CConn::refreshFramebuffer()
135{
Pierre Ossmane28bdb22011-11-14 16:02:06 +0000136 forceNonincremental = true;
137
138 // Without fences, we cannot safely trigger an update request directly
139 // but must wait for the next update to arrive.
140 if (supportsSyncFence)
141 requestNewUpdate();
Pierre Ossmand4c61ce2011-04-29 11:18:12 +0000142}
143
Pierre Ossman2eb1d112011-05-16 12:18:08 +0000144const char *CConn::connectionInfo()
145{
146 static char infoText[1024] = "";
147
148 char pfStr[100];
149 char spfStr[100];
150
151 cp.pf().print(pfStr, 100);
152 serverPF.print(spfStr, 100);
153
154 int secType = csecurity->getType();
155
156 snprintf(infoText, sizeof(infoText),
157 _("Desktop name: %.80s\n"
158 "Host: %.80s port: %d\n"
159 "Size: %d x %d\n"
160 "Pixel format: %s\n"
161 "(server default %s)\n"
162 "Requested encoding: %s\n"
163 "Last used encoding: %s\n"
164 "Line speed estimate: %d kbit/s\n"
165 "Protocol version: %d.%d\n"
166 "Security method: %s\n"),
167 cp.name(), serverHost, serverPort, cp.width, cp.height,
168 pfStr, spfStr, encodingName(currentEncoding),
169 encodingName(lastServerEncoding),
170 sock->inStream().kbitsPerSecond(),
171 cp.majorVersion, cp.minorVersion,
172 secTypeName(secType));
173
174 return infoText;
175}
176
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000177// The RFB core is not properly asynchronous, so it calls this callback
178// whenever it needs to block to wait for more data. Since FLTK is
179// monitoring the socket, we just make sure FLTK gets to run.
180
181void CConn::blockCallback()
182{
183 int next_timer;
184
185 next_timer = Timer::checkTimeouts();
186 if (next_timer == 0)
187 next_timer = INT_MAX;
188
189 Fl::wait((double)next_timer / 1000.0);
190}
191
192void CConn::socketEvent(int fd, void *data)
193{
194 CConn *cc;
195 static bool recursing = false;
196
197 assert(data);
198 cc = (CConn*)data;
199
200 // I don't think processMsg() is recursion safe, so add this check
201 if (recursing)
202 return;
203
204 recursing = true;
205
206 try {
207 // processMsg() only processes one message, so we need to loop
208 // until the buffers are empty or things will stall.
209 do {
210 cc->processMsg();
211 } while (cc->sock->inStream().checkNoWait(1));
212 } catch (rdr::EndOfStream& e) {
213 vlog.info(e.str());
214 exit_vncviewer();
215 } catch (rdr::Exception& e) {
216 vlog.error(e.str());
Pierre Ossmane2ef5c12011-07-12 16:56:34 +0000217 exit_vncviewer(e.str());
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000218 }
219
220 recursing = false;
221}
222
223////////////////////// CConnection callback methods //////////////////////
224
225// serverInit() is called when the serverInit message has been received. At
226// this point we create the desktop window and display it. We also tell the
227// server the pixel format and encodings to use and request the first update.
228void CConn::serverInit()
229{
230 CConnection::serverInit();
231
232 // If using AutoSelect with old servers, start in FullColor
233 // mode. See comment in autoSelectFormatAndEncoding.
234 if (cp.beforeVersion(3, 8) && autoSelect)
235 fullColour.setParam(true);
236
237 serverPF = cp.pf();
238
239 desktop = new DesktopWindow(cp.width, cp.height, cp.name(), serverPF, this);
240 fullColourPF = desktop->getPreferredPF();
241
Pierre Ossman5d512c32011-11-04 11:42:16 +0000242 // Force a switch to the format and encoding we'd like
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000243 formatChange = encodingChange = true;
Pierre Ossman5d512c32011-11-04 11:42:16 +0000244
245 // And kick off the update cycle
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000246 requestNewUpdate();
Pierre Ossman5d512c32011-11-04 11:42:16 +0000247
248 // This initial update request is a bit of a corner case, so we need
249 // to help out setting the correct format here.
250 assert(pendingPFChange);
251 desktop->setServerPF(pendingPF);
252 cp.setPF(pendingPF);
253 pendingPFChange = false;
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000254}
255
256// setDesktopSize() is called when the desktop size changes (including when
257// it is set initially).
258void CConn::setDesktopSize(int w, int h)
259{
260 CConnection::setDesktopSize(w,h);
261 resizeFramebuffer();
262}
263
264// setExtendedDesktopSize() is a more advanced version of setDesktopSize()
265void CConn::setExtendedDesktopSize(int reason, int result, int w, int h,
266 const rfb::ScreenSet& layout)
267{
268 CConnection::setExtendedDesktopSize(reason, result, w, h, layout);
269
270 if ((reason == reasonClient) && (result != resultSuccess)) {
271 vlog.error(_("SetDesktopSize failed: %d"), result);
272 return;
273 }
274
275 resizeFramebuffer();
276}
277
278// setName() is called when the desktop name changes
279void CConn::setName(const char* name)
280{
281 CConnection::setName(name);
282 if (desktop)
283 desktop->setName(name);
284}
285
286// framebufferUpdateStart() is called at the beginning of an update.
287// Here we try to send out a new framebuffer update request so that the
288// next update can be sent out in parallel with us decoding the current
Pierre Ossman5d512c32011-11-04 11:42:16 +0000289// one.
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000290void CConn::framebufferUpdateStart()
291{
Pierre Ossmane28bdb22011-11-14 16:02:06 +0000292 // Note: This might not be true if sync fences are supported
Pierre Ossman5d512c32011-11-04 11:42:16 +0000293 pendingUpdate = false;
294
295 requestNewUpdate();
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000296}
297
298// framebufferUpdateEnd() is called at the end of an update.
299// For each rectangle, the FdInStream will have timed the speed
300// of the connection, allowing us to select format and encoding
301// appropriately, and then request another incremental update.
302void CConn::framebufferUpdateEnd()
303{
304 desktop->updateWindow();
305
306 if (firstUpdate) {
307 int width, height;
308
Pierre Ossmane28bdb22011-11-14 16:02:06 +0000309 // We need fences to make extra update requests "safe".
310 // See fence() for the next step.
311 if (cp.supportsFence)
312 writer()->writeFence(fenceFlagRequest | fenceFlagSyncNext, 0, NULL);
313
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000314 if (cp.supportsSetDesktopSize &&
315 sscanf(desktopSize.getValueStr(), "%dx%d", &width, &height) == 2) {
316 ScreenSet layout;
317
318 layout = cp.screenLayout;
319
320 if (layout.num_screens() == 0)
321 layout.add_screen(rfb::Screen());
322 else if (layout.num_screens() != 1) {
323 ScreenSet::iterator iter;
324
325 while (true) {
326 iter = layout.begin();
327 ++iter;
328
329 if (iter == layout.end())
330 break;
331
332 layout.remove_screen(iter->id);
333 }
334 }
335
336 layout.begin()->dimensions.tl.x = 0;
337 layout.begin()->dimensions.tl.y = 0;
338 layout.begin()->dimensions.br.x = width;
339 layout.begin()->dimensions.br.y = height;
340
341 writer()->writeSetDesktopSize(width, height, layout);
342 }
343
344 firstUpdate = false;
345 }
346
Pierre Ossman5d512c32011-11-04 11:42:16 +0000347 // A format change has been scheduled and we are now past the update
348 // with the old format. Time to active the new one.
349 if (pendingPFChange) {
350 desktop->setServerPF(pendingPF);
351 cp.setPF(pendingPF);
352 pendingPFChange = false;
353 }
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000354
355 // Compute new settings based on updated bandwidth values
356 if (autoSelect)
357 autoSelectFormatAndEncoding();
358
359 // Make sure that the FLTK handling and the timers gets some CPU time
360 // in case of back to back framebuffer updates.
361 Fl::check();
362 Timer::checkTimeouts();
363}
364
365// The rest of the callbacks are fairly self-explanatory...
366
367void CConn::setColourMapEntries(int firstColour, int nColours, rdr::U16* rgbs)
368{
369 desktop->setColourMapEntries(firstColour, nColours, rgbs);
370}
371
372void CConn::bell()
373{
374 fl_beep();
375}
376
377void CConn::serverCutText(const char* str, rdr::U32 len)
378{
Pierre Ossman689c4582011-05-26 15:39:41 +0000379 char *buffer;
380 int size, ret;
Pierre Ossmand81e8f42011-05-19 14:47:15 +0000381
Pierre Ossman689c4582011-05-26 15:39:41 +0000382 size = fl_utf8froma(NULL, 0, str, len);
383 if (size <= 0)
Pierre Ossmand81e8f42011-05-19 14:47:15 +0000384 return;
Pierre Ossman689c4582011-05-26 15:39:41 +0000385
386 size++;
387
388 buffer = new char[size];
389
390 ret = fl_utf8froma(buffer, size, str, len);
391 assert(ret < size);
Pierre Ossmand81e8f42011-05-19 14:47:15 +0000392
393 vlog.debug("Got clipboard data: '%s'", buffer);
394
Pierre Ossmancf2443c2011-09-07 09:01:20 +0000395 // RFB doesn't have separate selection and clipboard concepts, so we
396 // dump the data into both variants.
397 Fl::copy(buffer, ret, 0);
Pierre Ossmand81e8f42011-05-19 14:47:15 +0000398 Fl::copy(buffer, ret, 1);
Pierre Ossman689c4582011-05-26 15:39:41 +0000399
400 delete [] buffer;
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000401}
402
403// We start timing on beginRect and stop timing on endRect, to
404// avoid skewing the bandwidth estimation as a result of the server
405// being slow or the network having high latency
406void CConn::beginRect(const Rect& r, int encoding)
407{
408 sock->inStream().startTiming();
409 if (encoding != encodingCopyRect) {
410 lastServerEncoding = encoding;
411 }
412}
413
414void CConn::endRect(const Rect& r, int encoding)
415{
416 sock->inStream().stopTiming();
417}
418
419void CConn::fillRect(const rfb::Rect& r, rfb::Pixel p)
420{
421 desktop->fillRect(r,p);
422}
423void CConn::imageRect(const rfb::Rect& r, void* p)
424{
425 desktop->imageRect(r,p);
426}
427void CConn::copyRect(const rfb::Rect& r, int sx, int sy)
428{
429 desktop->copyRect(r,sx,sy);
430}
431void CConn::setCursor(int width, int height, const Point& hotspot,
432 void* data, void* mask)
433{
Pierre Ossman835b4ef2011-06-08 17:02:36 +0000434 desktop->setCursor(width, height, hotspot, data, mask);
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000435}
436
Pierre Ossmane28bdb22011-11-14 16:02:06 +0000437void CConn::fence(rdr::U32 flags, unsigned len, const char data[])
438{
439 CMsgHandler::fence(flags, len, data);
440
441 if (flags & fenceFlagRequest) {
442 // We handle everything synchronously so we trivially honor these modes
443 flags = flags & (fenceFlagBlockBefore | fenceFlagBlockAfter);
444
445 writer()->writeFence(flags, len, data);
446 return;
447 }
448
449 if (len == 0) {
450 // Initial probe
451 if (flags & fenceFlagSyncNext)
452 supportsSyncFence = true;
453 } else {
454 // Pixel format change
455 rdr::MemInStream memStream(data, len);
456 PixelFormat pf;
457
458 pf.read(&memStream);
459
460 desktop->setServerPF(pf);
461 cp.setPF(pf);
462 }
463}
464
DRC33c15e32011-11-03 18:49:21 +0000465rdr::U8* CConn::getRawPixelsRW(const rfb::Rect& r, int* stride) {
466 return desktop->getPixelsRW(r, stride);
467}
468void CConn::releaseRawPixels(const rfb::Rect& r) {
469 desktop->damageRect(r);
470}
471
472
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000473////////////////////// Internal methods //////////////////////
474
475void CConn::resizeFramebuffer()
476{
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000477 if (!desktop)
478 return;
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000479
Pierre Ossman6455d852011-06-01 09:33:00 +0000480 desktop->resizeFramebuffer(cp.width, cp.height);
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000481}
482
483// autoSelectFormatAndEncoding() chooses the format and encoding appropriate
484// to the connection speed:
485//
486// First we wait for at least one second of bandwidth measurement.
487//
488// Above 16Mbps (i.e. LAN), we choose the second highest JPEG quality,
489// which should be perceptually lossless.
490//
491// If the bandwidth is below that, we choose a more lossy JPEG quality.
492//
493// If the bandwidth drops below 256 Kbps, we switch to palette mode.
494//
495// Note: The system here is fairly arbitrary and should be replaced
496// with something more intelligent at the server end.
497//
498void CConn::autoSelectFormatAndEncoding()
499{
500 int kbitsPerSecond = sock->inStream().kbitsPerSecond();
501 unsigned int timeWaited = sock->inStream().timeWaited();
502 bool newFullColour = fullColour;
503 int newQualityLevel = qualityLevel;
504
505 // Always use Tight
506 if (currentEncoding != encodingTight) {
507 currentEncoding = encodingTight;
508 encodingChange = true;
509 }
510
511 // Check that we have a decent bandwidth measurement
512 if ((kbitsPerSecond == 0) || (timeWaited < 10000))
513 return;
514
515 // Select appropriate quality level
516 if (!noJpeg) {
517 if (kbitsPerSecond > 16000)
518 newQualityLevel = 8;
519 else
520 newQualityLevel = 6;
521
522 if (newQualityLevel != qualityLevel) {
523 vlog.info(_("Throughput %d kbit/s - changing to quality %d"),
524 kbitsPerSecond, newQualityLevel);
525 cp.qualityLevel = newQualityLevel;
526 qualityLevel.setParam(newQualityLevel);
527 encodingChange = true;
528 }
529 }
530
531 if (cp.beforeVersion(3, 8)) {
532 // Xvnc from TightVNC 1.2.9 sends out FramebufferUpdates with
533 // cursors "asynchronously". If this happens in the middle of a
534 // pixel format change, the server will encode the cursor with
535 // the old format, but the client will try to decode it
536 // according to the new format. This will lead to a
537 // crash. Therefore, we do not allow automatic format change for
538 // old servers.
539 return;
540 }
541
542 // Select best color level
543 newFullColour = (kbitsPerSecond > 256);
544 if (newFullColour != fullColour) {
545 vlog.info(_("Throughput %d kbit/s - full color is now %s"),
546 kbitsPerSecond,
547 newFullColour ? _("enabled") : _("disabled"));
548 fullColour.setParam(newFullColour);
549 formatChange = true;
550 }
551}
552
553// checkEncodings() sends a setEncodings message if one is needed.
554void CConn::checkEncodings()
555{
556 if (encodingChange && writer()) {
557 vlog.info(_("Using %s encoding"),encodingName(currentEncoding));
558 writer()->writeSetEncodings(currentEncoding, true);
559 encodingChange = false;
560 }
561}
562
563// requestNewUpdate() requests an update from the server, having set the
564// format and encoding appropriately.
565void CConn::requestNewUpdate()
566{
567 if (formatChange) {
568 PixelFormat pf;
569
570 /* Catch incorrect requestNewUpdate calls */
Pierre Ossmane28bdb22011-11-14 16:02:06 +0000571 assert(!pendingUpdate || supportsSyncFence);
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000572
573 if (fullColour) {
574 pf = fullColourPF;
575 } else {
576 if (lowColourLevel == 0)
Pierre Ossmancf836f22011-07-14 14:34:09 +0000577 pf = verylowColourPF;
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000578 else if (lowColourLevel == 1)
Pierre Ossmanf4f30942011-05-17 09:39:07 +0000579 pf = lowColourPF;
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000580 else
Pierre Ossmancf836f22011-07-14 14:34:09 +0000581 pf = mediumColourPF;
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000582 }
Pierre Ossman5d512c32011-11-04 11:42:16 +0000583
Pierre Ossmane28bdb22011-11-14 16:02:06 +0000584 if (supportsSyncFence) {
585 // We let the fence carry the pixel format and switch once we
586 // get the response back. That way we will be synchronised with
587 // when the server switches.
588 rdr::MemOutStream memStream;
589
590 pf.write(&memStream);
591
592 writer()->writeFence(fenceFlagRequest | fenceFlagSyncNext,
593 memStream.length(), (const char*)memStream.data());
594 } else {
595 // New requests are sent out at the start of processing the last
596 // one, so we cannot switch our internal format right now (doing so
597 // would mean misdecoding the current update).
598 pendingPFChange = true;
599 pendingPF = pf;
600 }
Pierre Ossman5d512c32011-11-04 11:42:16 +0000601
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000602 char str[256];
603 pf.print(str, 256);
604 vlog.info(_("Using pixel format %s"),str);
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000605 writer()->writeSetPixelFormat(pf);
Pierre Ossmand4c61ce2011-04-29 11:18:12 +0000606
Pierre Ossmand4c61ce2011-04-29 11:18:12 +0000607 formatChange = false;
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000608 }
Pierre Ossmand4c61ce2011-04-29 11:18:12 +0000609
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000610 checkEncodings();
Pierre Ossmand4c61ce2011-04-29 11:18:12 +0000611
Pierre Ossman5d512c32011-11-04 11:42:16 +0000612 pendingUpdate = true;
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000613 writer()->writeFramebufferUpdateRequest(Rect(0, 0, cp.width, cp.height),
Pierre Ossmand4c61ce2011-04-29 11:18:12 +0000614 !forceNonincremental);
615
616 forceNonincremental = false;
Pierre Ossman5156d5e2011-03-09 09:42:34 +0000617}
Pierre Ossmanf4f30942011-05-17 09:39:07 +0000618
619void CConn::handleOptions(void *data)
620{
621 CConn *self = (CConn*)data;
622
623 // Checking all the details of the current set of encodings is just
624 // a pain. Assume something has changed, as resending the encoding
625 // list is cheap. Avoid overriding what the auto logic has selected
626 // though.
627 if (!autoSelect) {
628 int encNum = encodingNum(preferredEncoding);
629
630 if (encNum != -1)
631 self->currentEncoding = encNum;
632
633 self->cp.qualityLevel = qualityLevel;
634 }
635
Pierre Ossmanda389562011-06-09 08:24:37 +0000636 self->cp.supportsLocalCursor = true;
637
Pierre Ossmanf4f30942011-05-17 09:39:07 +0000638 self->cp.customCompressLevel = customCompressLevel;
639 self->cp.compressLevel = compressLevel;
640
641 self->cp.noJpeg = noJpeg;
642
643 self->encodingChange = true;
644
645 // Format changes refreshes the entire screen though and are therefore
646 // very costly. It's probably worth the effort to see if it is necessary
647 // here.
648 PixelFormat pf;
649
650 if (fullColour) {
651 pf = self->fullColourPF;
652 } else {
653 if (lowColourLevel == 0)
Pierre Ossmancf836f22011-07-14 14:34:09 +0000654 pf = verylowColourPF;
Pierre Ossmanf4f30942011-05-17 09:39:07 +0000655 else if (lowColourLevel == 1)
656 pf = lowColourPF;
657 else
Pierre Ossmancf836f22011-07-14 14:34:09 +0000658 pf = mediumColourPF;
Pierre Ossmanf4f30942011-05-17 09:39:07 +0000659 }
660
Pierre Ossmane28bdb22011-11-14 16:02:06 +0000661 if (!pf.equal(self->cp.pf())) {
Pierre Ossmanf4f30942011-05-17 09:39:07 +0000662 self->formatChange = true;
Pierre Ossmane28bdb22011-11-14 16:02:06 +0000663
664 // Without fences, we cannot safely trigger an update request directly
665 // but must wait for the next update to arrive.
666 if (self->supportsSyncFence)
667 self->requestNewUpdate();
668 }
Pierre Ossmanf4f30942011-05-17 09:39:07 +0000669}