Deleted Added
sdiff udiff text old ( 10810:683ab55819fd ) new ( 10839:10cac0f0f419 )
full compact
1/*
2 * Copyright (c) 2010, 2015 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated

--- 45 unchanged lines hidden (view full) ---

56
57#include <fcntl.h>
58#include <poll.h>
59#include <sys/types.h>
60#include <unistd.h>
61
62#include <cerrno>
63#include <cstdio>
64#include <cstddef>
65
66#include "base/atomicio.hh"
67#include "base/bitmap.hh"
68#include "base/misc.hh"
69#include "base/output.hh"
70#include "base/socket.hh"
71#include "base/trace.hh"
72#include "debug/VNC.hh"
73#include "sim/byteswap.hh"
74#include "sim/core.hh"
75
76using namespace std;
77
78const PixelConverter VncServer::pixelConverter(
79 4, // 4 bytes / pixel
80 16, 8, 0, // R in [23, 16], G in [15, 8], B in [7, 0]
81 8, 8, 8, // 8 bits / channel
82 LittleEndianByteOrder);
83
84/** @file
85 * Implementiation of a VNC server
86 */
87
88/**
89 * Poll event for the listen socket
90 */
91VncServer::ListenEvent::ListenEvent(VncServer *vs, int fd, int e)

--- 32 unchanged lines hidden (view full) ---

124 dataFd(-1), sendUpdate(false),
125 supportsRawEnc(false), supportsResizeEnc(false)
126{
127 if (p->port)
128 listen(p->port);
129
130 curState = WaitForProtocolVersion;
131
132 // We currently only support one pixel format. Extract the pixel
133 // representation from our PixelConverter instance and keep it
134 // around for telling the client and making sure it cooperates
135 pixelFormat.bpp = 8 * pixelConverter.length;
136 pixelFormat.depth = pixelConverter.depth;
137 pixelFormat.bigendian = pixelConverter.byte_order == BigEndianByteOrder;
138 pixelFormat.truecolor = 1;
139 pixelFormat.redmax = pixelConverter.ch_r.mask;
140 pixelFormat.greenmax = pixelConverter.ch_g.mask;
141 pixelFormat.bluemax = pixelConverter.ch_b.mask;
142 pixelFormat.redshift = pixelConverter.ch_r.offset;
143 pixelFormat.greenshift = pixelConverter.ch_g.offset;
144 pixelFormat.blueshift = pixelConverter.ch_b.offset;
145
146 DPRINTF(VNC, "Vnc server created at port %d\n", p->port);
147}
148
149VncServer::~VncServer()
150{
151 if (dataFd != -1)
152 ::close(dataFd);

--- 463 unchanged lines hidden (view full) ---

616
617}
618
619
620void
621VncServer::sendFrameBufferUpdate()
622{
623
624 if (dataFd <= 0 || curState != NormalPhase || !sendUpdate) {
625 DPRINTF(VNC, "NOT sending framebuffer update\n");
626 return;
627 }
628
629 // The client will request data constantly, unless we throttle it
630 sendUpdate = false;
631
632 DPRINTF(VNC, "Sending framebuffer update\n");
633
634 FrameBufferUpdate fbu;
635 FrameBufferRect fbr;
636

--- 12 unchanged lines hidden (view full) ---

649 fbr.width = htobe(fbr.width);
650 fbr.height = htobe(fbr.height);
651 fbr.encoding = htobe(fbr.encoding);
652
653 // send headers to client
654 write(&fbu);
655 write(&fbr);
656
657 assert(fb);
658
659 std::vector<uint8_t> line_buffer(pixelConverter.length * fb->width());
660 for (int y = 0; y < fb->height(); ++y) {
661 // Convert and send a line at a time
662 uint8_t *raw_pixel(line_buffer.data());
663 for (unsigned x = 0; x < fb->width(); ++x) {
664 pixelConverter.fromPixel(raw_pixel, fb->pixel(x, y));
665 raw_pixel += pixelConverter.length;
666 }
667
668 write(line_buffer.data(), line_buffer.size());
669 }
670}
671
672void
673VncServer::sendFrameBufferResized()
674{
675 assert(fb && dataFd > 0 && curState == NormalPhase);
676 DPRINTF(VNC, "Sending framebuffer resize\n");
677
678 FrameBufferUpdate fbu;
679 FrameBufferRect fbr;
680
681 fbu.type = ServerFrameBufferUpdate;
682 fbu.num_rects = 1;
683 fbr.x = 0;

--- 13 unchanged lines hidden (view full) ---

697 // send headers to client
698 write(&fbu);
699 write(&fbr);
700
701 // No actual data is sent in this message
702}
703
704void
705VncServer::setDirty()
706{
707 VncInput::setDirty();
708
709 sendUpdate = true;
710 sendFrameBufferUpdate();
711}
712
713void
714VncServer::frameBufferResized()
715{
716 if (dataFd > 0 && curState == NormalPhase) {
717 if (supportsResizeEnc)
718 sendFrameBufferResized();
719 else
720 // The frame buffer changed size and we can't update the client
721 detach();
722 }
723}
724
725// create the VNC server object
726VncServer *
727VncServerParams::create()
728{
729 return new VncServer(this);
730}
731