vncserver.cc (10810:683ab55819fd) vncserver.cc (10839:10cac0f0f419)
1/*
1/*
2 * Copyright (c) 2010 ARM Limited
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>
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>
64
65#include "base/atomicio.hh"
66#include "base/bitmap.hh"
67#include "base/misc.hh"
68#include "base/output.hh"
69#include "base/socket.hh"
70#include "base/trace.hh"
71#include "debug/VNC.hh"
72#include "sim/byteswap.hh"
73#include "sim/core.hh"
74
75using namespace std;
76
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
77/** @file
78 * Implementiation of a VNC server
79 */
80
81/**
82 * Poll event for the listen socket
83 */
84VncServer::ListenEvent::ListenEvent(VncServer *vs, int fd, int e)

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

117 dataFd(-1), sendUpdate(false),
118 supportsRawEnc(false), supportsResizeEnc(false)
119{
120 if (p->port)
121 listen(p->port);
122
123 curState = WaitForProtocolVersion;
124
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
125 // currently we only support this one pixel format
126 // unpacked 32bit rgb (rgb888 + 8 bits of nothing/alpha)
127 // keep it around for telling the client and making
128 // sure the client cooperates
129 pixelFormat.bpp = 32;
130 pixelFormat.depth = 24;
131 pixelFormat.bigendian = 0;
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;
132 pixelFormat.truecolor = 1;
138 pixelFormat.truecolor = 1;
133 pixelFormat.redmax = 0xff;
134 pixelFormat.greenmax = 0xff;
135 pixelFormat.bluemax = 0xff;
136 pixelFormat.redshift = 16;
137 pixelFormat.greenshift = 8;
138 pixelFormat.blueshift = 0;
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;
139
140 DPRINTF(VNC, "Vnc server created at port %d\n", p->port);
141}
142
143VncServer::~VncServer()
144{
145 if (dataFd != -1)
146 ::close(dataFd);

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

610
611}
612
613
614void
615VncServer::sendFrameBufferUpdate()
616{
617
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
618 if (!fbPtr || dataFd <= 0 || curState != NormalPhase || !sendUpdate) {
624 if (dataFd <= 0 || curState != NormalPhase || !sendUpdate) {
619 DPRINTF(VNC, "NOT sending framebuffer update\n");
620 return;
621 }
622
625 DPRINTF(VNC, "NOT sending framebuffer update\n");
626 return;
627 }
628
623 assert(vc);
624
625 // The client will request data constantly, unless we throttle it
626 sendUpdate = false;
627
628 DPRINTF(VNC, "Sending framebuffer update\n");
629
630 FrameBufferUpdate fbu;
631 FrameBufferRect fbr;
632

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

645 fbr.width = htobe(fbr.width);
646 fbr.height = htobe(fbr.height);
647 fbr.encoding = htobe(fbr.encoding);
648
649 // send headers to client
650 write(&fbu);
651 write(&fbr);
652
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
653 assert(fbPtr);
657 assert(fb);
654
658
655 uint8_t *tmp = vc->convert(fbPtr);
656 uint64_t num_pixels = videoWidth() * videoHeight();
657 write(tmp, num_pixels * sizeof(uint32_t));
658 delete [] tmp;
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 }
659
667
668 write(line_buffer.data(), line_buffer.size());
669 }
660}
661
662void
663VncServer::sendFrameBufferResized()
664{
670}
671
672void
673VncServer::sendFrameBufferResized()
674{
665 assert(fbPtr && dataFd > 0 && curState == NormalPhase);
675 assert(fb && dataFd > 0 && curState == NormalPhase);
666 DPRINTF(VNC, "Sending framebuffer resize\n");
667
668 FrameBufferUpdate fbu;
669 FrameBufferRect fbr;
670
671 fbu.type = ServerFrameBufferUpdate;
672 fbu.num_rects = 1;
673 fbr.x = 0;

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

687 // send headers to client
688 write(&fbu);
689 write(&fbr);
690
691 // No actual data is sent in this message
692}
693
694void
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
695VncServer::setFrameBufferParams(VideoConvert::Mode mode, uint16_t width,
696 uint16_t height)
705VncServer::setDirty()
697{
706{
698 VncInput::setFrameBufferParams(mode, width, height);
707 VncInput::setDirty();
699
708
700 if (mode != videoMode || width != videoWidth() || height != videoHeight()) {
701 if (dataFd > 0 && fbPtr && curState == NormalPhase) {
702 if (supportsResizeEnc)
703 sendFrameBufferResized();
704 else
705 // The frame buffer changed size and we can't update the client
706 detach();
707 }
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();
708 }
709}
710
711// create the VNC server object
712VncServer *
713VncServerParams::create()
714{
715 return new VncServer(this);
716}
717
722 }
723}
724
725// create the VNC server object
726VncServer *
727VncServerParams::create()
728{
729 return new VncServer(this);
730}
731