vncinput.hh revision 12230
17404SAli.Saidi@ARM.com/* 27404SAli.Saidi@ARM.com * Copyright (c) 2010, 2015 ARM Limited 37404SAli.Saidi@ARM.com * All rights reserved 47404SAli.Saidi@ARM.com * 57404SAli.Saidi@ARM.com * The license below extends only to copyright in the software and shall 67404SAli.Saidi@ARM.com * not be construed as granting a license to any other intellectual 77404SAli.Saidi@ARM.com * property including but not limited to intellectual property relating 87404SAli.Saidi@ARM.com * to a hardware implementation of the functionality of the software 97404SAli.Saidi@ARM.com * licensed hereunder. You may use the software subject to the license 107404SAli.Saidi@ARM.com * terms below provided that you ensure that this notice is replicated 117404SAli.Saidi@ARM.com * unmodified and in its entirety in all distributions of the software, 127404SAli.Saidi@ARM.com * modified or unmodified, in source code or in binary form. 137404SAli.Saidi@ARM.com * 147404SAli.Saidi@ARM.com * Redistribution and use in source and binary forms, with or without 157404SAli.Saidi@ARM.com * modification, are permitted provided that the following conditions are 167404SAli.Saidi@ARM.com * met: redistributions of source code must retain the above copyright 177404SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer; 187404SAli.Saidi@ARM.com * redistributions in binary form must reproduce the above copyright 197404SAli.Saidi@ARM.com * notice, this list of conditions and the following disclaimer in the 207404SAli.Saidi@ARM.com * documentation and/or other materials provided with the distribution; 217404SAli.Saidi@ARM.com * neither the name of the copyright holders nor the names of its 227404SAli.Saidi@ARM.com * contributors may be used to endorse or promote products derived from 237404SAli.Saidi@ARM.com * this software without specific prior written permission. 247404SAli.Saidi@ARM.com * 257404SAli.Saidi@ARM.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 267404SAli.Saidi@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 277404SAli.Saidi@ARM.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 287404SAli.Saidi@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 297404SAli.Saidi@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 307404SAli.Saidi@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 317404SAli.Saidi@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 327404SAli.Saidi@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 337404SAli.Saidi@ARM.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 347404SAli.Saidi@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 357404SAli.Saidi@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 367404SAli.Saidi@ARM.com * 377404SAli.Saidi@ARM.com * Authors: Ali Saidi 387404SAli.Saidi@ARM.com * William Wang 397404SAli.Saidi@ARM.com */ 407404SAli.Saidi@ARM.com 417404SAli.Saidi@ARM.com/** @file 427404SAli.Saidi@ARM.com * Declaration of a VNC input 437404SAli.Saidi@ARM.com */ 447728SAli.Saidi@ARM.com 457404SAli.Saidi@ARM.com#ifndef __BASE_VNC_VNC_INPUT_HH__ 467748SAli.Saidi@ARM.com#define __BASE_VNC_VNC_INPUT_HH__ 477404SAli.Saidi@ARM.com 487404SAli.Saidi@ARM.com#include <iostream> 497404SAli.Saidi@ARM.com#include <memory> 507404SAli.Saidi@ARM.com 517728SAli.Saidi@ARM.com#include "base/imgwriter.hh" 527728SAli.Saidi@ARM.com#include "params/VncInput.hh" 537439Sdam.sunwoo@arm.com#include "sim/sim_object.hh" 547576SAli.Saidi@ARM.com 557439Sdam.sunwoo@arm.comclass OutputDirectory; 567404SAli.Saidi@ARM.com 577404SAli.Saidi@ARM.com/** 587404SAli.Saidi@ARM.com * A device that expects to receive input from the vnc server should derrive 597404SAli.Saidi@ARM.com * (through mulitple inheritence if necessary from VncKeyboard or VncMouse 607404SAli.Saidi@ARM.com * and call setKeyboard() or setMouse() respectively on the vnc server. 617404SAli.Saidi@ARM.com */ 627404SAli.Saidi@ARM.comclass VncKeyboard 637748SAli.Saidi@ARM.com{ 647748SAli.Saidi@ARM.com public: 657404SAli.Saidi@ARM.com /** 667748SAli.Saidi@ARM.com * Called when the vnc server receives a key press event from the 677733SAli.Saidi@ARM.com * client. 687733SAli.Saidi@ARM.com * @param key the key passed is an x11 keysym 697733SAli.Saidi@ARM.com * @param down is the key now down or up? 707733SAli.Saidi@ARM.com */ 717733SAli.Saidi@ARM.com virtual void keyPress(uint32_t key, bool down) = 0; 727733SAli.Saidi@ARM.com}; 737733SAli.Saidi@ARM.com 747733SAli.Saidi@ARM.comclass VncMouse 757733SAli.Saidi@ARM.com{ 767733SAli.Saidi@ARM.com public: 777733SAli.Saidi@ARM.com /** 787404SAli.Saidi@ARM.com * called whenever the mouse moves or it's button state changes 797404SAli.Saidi@ARM.com * buttons is a simple mask with each button (0-8) corresponding to 807748SAli.Saidi@ARM.com * a bit position in the byte with 1 being down and 0 being up 817748SAli.Saidi@ARM.com * @param x the x position of the mouse 827748SAli.Saidi@ARM.com * @param y the y position of the mouse 837748SAli.Saidi@ARM.com * @param buttos the button state as described above 847748SAli.Saidi@ARM.com */ 857748SAli.Saidi@ARM.com virtual void mouseAt(uint16_t x, uint16_t y, uint8_t buttons) = 0; 867748SAli.Saidi@ARM.com}; 877748SAli.Saidi@ARM.com 887748SAli.Saidi@ARM.comclass VncInput : public SimObject 897748SAli.Saidi@ARM.com{ 907404SAli.Saidi@ARM.com public: 917404SAli.Saidi@ARM.com 927404SAli.Saidi@ARM.com /** Client -> Server message IDs */ 937404SAli.Saidi@ARM.com enum ClientMessages { 947404SAli.Saidi@ARM.com ClientSetPixelFormat = 0, 957404SAli.Saidi@ARM.com ClientSetEncodings = 2, 967404SAli.Saidi@ARM.com ClientFrameBufferUpdate = 3, 977404SAli.Saidi@ARM.com ClientKeyEvent = 4, 987404SAli.Saidi@ARM.com ClientPointerEvent = 5, 997404SAli.Saidi@ARM.com ClientCutText = 6 1007404SAli.Saidi@ARM.com }; 1017404SAli.Saidi@ARM.com 1027404SAli.Saidi@ARM.com struct PixelFormat { 1037404SAli.Saidi@ARM.com uint8_t bpp; 1047404SAli.Saidi@ARM.com uint8_t depth; 1057404SAli.Saidi@ARM.com uint8_t bigendian; 1067404SAli.Saidi@ARM.com uint8_t truecolor; 1077437Sdam.sunwoo@arm.com uint16_t redmax; 1087404SAli.Saidi@ARM.com uint16_t greenmax; 1097404SAli.Saidi@ARM.com uint16_t bluemax; 1107439Sdam.sunwoo@arm.com uint8_t redshift; 1117439Sdam.sunwoo@arm.com uint8_t greenshift; 1127439Sdam.sunwoo@arm.com uint8_t blueshift; 1137439Sdam.sunwoo@arm.com uint8_t padding[3]; 1147439Sdam.sunwoo@arm.com } M5_ATTR_PACKED; 1157404SAli.Saidi@ARM.com 1167439Sdam.sunwoo@arm.com struct PixelFormatMessage { 1177439Sdam.sunwoo@arm.com uint8_t type; 1187439Sdam.sunwoo@arm.com uint8_t padding[3]; 1197439Sdam.sunwoo@arm.com PixelFormat px; 1207439Sdam.sunwoo@arm.com } M5_ATTR_PACKED; 1217439Sdam.sunwoo@arm.com 1227439Sdam.sunwoo@arm.com struct PixelEncodingsMessage { 1237439Sdam.sunwoo@arm.com uint8_t type; 1247439Sdam.sunwoo@arm.com uint8_t padding; 1257439Sdam.sunwoo@arm.com uint16_t num_encodings; 1267439Sdam.sunwoo@arm.com } M5_ATTR_PACKED; 1277439Sdam.sunwoo@arm.com 1287439Sdam.sunwoo@arm.com struct FrameBufferUpdateReq { 1297439Sdam.sunwoo@arm.com uint8_t type; 1307404SAli.Saidi@ARM.com uint8_t incremental; 1317436Sdam.sunwoo@arm.com uint16_t x; 1327436Sdam.sunwoo@arm.com uint16_t y; 1337720Sgblack@eecs.umich.edu uint16_t width; 1347439Sdam.sunwoo@arm.com uint16_t height; 1357439Sdam.sunwoo@arm.com } M5_ATTR_PACKED; 1367439Sdam.sunwoo@arm.com 1377439Sdam.sunwoo@arm.com struct KeyEventMessage { 1387439Sdam.sunwoo@arm.com uint8_t type; 1397439Sdam.sunwoo@arm.com uint8_t down_flag; 1407439Sdam.sunwoo@arm.com uint8_t padding[2]; 1417728SAli.Saidi@ARM.com uint32_t key; 1427728SAli.Saidi@ARM.com } M5_ATTR_PACKED; 1437728SAli.Saidi@ARM.com 1447728SAli.Saidi@ARM.com struct PointerEventMessage { 1457728SAli.Saidi@ARM.com uint8_t type; 1467728SAli.Saidi@ARM.com uint8_t button_mask; 1477728SAli.Saidi@ARM.com uint16_t x; 1487728SAli.Saidi@ARM.com uint16_t y; 1497728SAli.Saidi@ARM.com } M5_ATTR_PACKED; 1507728SAli.Saidi@ARM.com 1517728SAli.Saidi@ARM.com struct ClientCutTextMessage { 1527728SAli.Saidi@ARM.com uint8_t type; 1537728SAli.Saidi@ARM.com uint8_t padding[3]; 1547728SAli.Saidi@ARM.com uint32_t length; 1557728SAli.Saidi@ARM.com } M5_ATTR_PACKED; 1567728SAli.Saidi@ARM.com 1577728SAli.Saidi@ARM.com typedef VncInputParams Params; 1587728SAli.Saidi@ARM.com VncInput(const Params *p); 1597728SAli.Saidi@ARM.com 1607728SAli.Saidi@ARM.com /** Set the address of the frame buffer we are going to show. 1617728SAli.Saidi@ARM.com * To avoid copying, just have the display controller 1627728SAli.Saidi@ARM.com * tell us where the data is instead of constanly copying it around 1637728SAli.Saidi@ARM.com * @param rfb frame buffer that we're going to use 1647728SAli.Saidi@ARM.com */ 1657728SAli.Saidi@ARM.com virtual void setFrameBuffer(const FrameBuffer *rfb); 1667728SAli.Saidi@ARM.com 1677728SAli.Saidi@ARM.com /** Set up the device that would like to receive notifications when keys are 1687728SAli.Saidi@ARM.com * pressed in the vnc client keyboard 1697728SAli.Saidi@ARM.com * @param _keyboard an object that derrives from VncKeyboard 1707404SAli.Saidi@ARM.com */ 1717404SAli.Saidi@ARM.com void setKeyboard(VncKeyboard *_keyboard) { keyboard = _keyboard; } 1727404SAli.Saidi@ARM.com 1737439Sdam.sunwoo@arm.com /** Setup the device that would like to receive notifications when mouse 1747404SAli.Saidi@ARM.com * movements or button presses are received from the vnc client. 1757406SAli.Saidi@ARM.com * @param _mouse an object that derrives from VncMouse 1767439Sdam.sunwoo@arm.com */ 1777439Sdam.sunwoo@arm.com void setMouse(VncMouse *_mouse) { mouse = _mouse; } 1787406SAli.Saidi@ARM.com 1797439Sdam.sunwoo@arm.com /** What is the width of the screen we're displaying. 1807406SAli.Saidi@ARM.com * This is used for pointer/tablet devices that need to know to calculate 1817439Sdam.sunwoo@arm.com * the correct value to send to the device driver. 1827404SAli.Saidi@ARM.com * @return the width of the simulated screen 1837406SAli.Saidi@ARM.com */ 1847439Sdam.sunwoo@arm.com uint16_t videoWidth() const { return _videoWidth; } 1857439Sdam.sunwoo@arm.com 1867404SAli.Saidi@ARM.com /** What is the height of the screen we're displaying. 1877404SAli.Saidi@ARM.com * This is used for pointer/tablet devices that need to know to calculate 1887439Sdam.sunwoo@arm.com * the correct value to send to the device driver. 1897439Sdam.sunwoo@arm.com * @return the height of the simulated screen 1907406SAli.Saidi@ARM.com */ 1917404SAli.Saidi@ARM.com uint16_t videoHeight() const { return _videoHeight; } 1927404SAli.Saidi@ARM.com 1937404SAli.Saidi@ARM.com /** The frame buffer uses this call to notify the vnc server that 1947439Sdam.sunwoo@arm.com * the frame buffer has been updated and a new image needs to be sent to the 1957439Sdam.sunwoo@arm.com * client 1967439Sdam.sunwoo@arm.com */ 1977439Sdam.sunwoo@arm.com virtual void setDirty(); 1987579Sminkyu.jeong@arm.com 1997579Sminkyu.jeong@arm.com protected: 2007579Sminkyu.jeong@arm.com virtual void frameBufferResized() {}; 2017728SAli.Saidi@ARM.com 2027728SAli.Saidi@ARM.com /** The device to notify when we get key events */ 2037728SAli.Saidi@ARM.com VncKeyboard *keyboard; 2047579Sminkyu.jeong@arm.com 2057579Sminkyu.jeong@arm.com /** The device to notify when we get mouse events */ 2067579Sminkyu.jeong@arm.com VncMouse *mouse; 2077579Sminkyu.jeong@arm.com 2087579Sminkyu.jeong@arm.com /** pointer to the actual data that is stored in the frame buffer device */ 2097579Sminkyu.jeong@arm.com const FrameBuffer *fb; 2107404SAli.Saidi@ARM.com 2117404SAli.Saidi@ARM.com /** the width of the frame buffer we are sending to the client */ 2127439Sdam.sunwoo@arm.com uint16_t _videoWidth; 2137404SAli.Saidi@ARM.com 2147728SAli.Saidi@ARM.com /** the height of the frame buffer we are sending to the client */ 2157728SAli.Saidi@ARM.com uint16_t _videoHeight; 2167578Sdam.sunwoo@arm.com 2177653Sgene.wu@arm.com /** Flag indicating whether to capture snapshots of frame buffer or not */ 2187653Sgene.wu@arm.com bool captureEnabled; 2197439Sdam.sunwoo@arm.com 2207404SAli.Saidi@ARM.com /** Current frame number being captured to a file */ 2217608SGene.Wu@arm.com int captureCurrentFrame; 2227608SGene.Wu@arm.com 2237608SGene.Wu@arm.com /** Directory to store captured frames to */ 2247608SGene.Wu@arm.com OutputDirectory *captureOutputDirectory; 2257404SAli.Saidi@ARM.com 2267728SAli.Saidi@ARM.com /** Computed hash of the last captured frame */ 2277728SAli.Saidi@ARM.com uint64_t captureLastHash; 2287404SAli.Saidi@ARM.com 2297439Sdam.sunwoo@arm.com /** Cached ImgWriter object for writing out frame buffers to file */ 2307404SAli.Saidi@ARM.com std::unique_ptr<ImgWriter> captureImage; 2317404SAli.Saidi@ARM.com 2327439Sdam.sunwoo@arm.com /** image format */ 2337404SAli.Saidi@ARM.com Enums::ImageFormat imgFormat; 2347404SAli.Saidi@ARM.com 2357404SAli.Saidi@ARM.com /** Captures the current frame buffer to a file */ 2367439Sdam.sunwoo@arm.com void captureFrameBuffer(); 2377439Sdam.sunwoo@arm.com}; 2387404SAli.Saidi@ARM.com#endif 2397439Sdam.sunwoo@arm.com