17949SN/A/* 210839Sandreas.sandberg@arm.com * Copyright (c) 2010, 2015 ARM Limited 37949SN/A * All rights reserved 47949SN/A * 57949SN/A * The license below extends only to copyright in the software and shall 67949SN/A * not be construed as granting a license to any other intellectual 77949SN/A * property including but not limited to intellectual property relating 87949SN/A * to a hardware implementation of the functionality of the software 97949SN/A * licensed hereunder. You may use the software subject to the license 107949SN/A * terms below provided that you ensure that this notice is replicated 117949SN/A * unmodified and in its entirety in all distributions of the software, 127949SN/A * modified or unmodified, in source code or in binary form. 137949SN/A * 147949SN/A * Redistribution and use in source and binary forms, with or without 157949SN/A * modification, are permitted provided that the following conditions are 167949SN/A * met: redistributions of source code must retain the above copyright 177949SN/A * notice, this list of conditions and the following disclaimer; 187949SN/A * redistributions in binary form must reproduce the above copyright 197949SN/A * notice, this list of conditions and the following disclaimer in the 207949SN/A * documentation and/or other materials provided with the distribution; 217949SN/A * neither the name of the copyright holders nor the names of its 227949SN/A * contributors may be used to endorse or promote products derived from 237949SN/A * this software without specific prior written permission. 247949SN/A * 257949SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 267949SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 277949SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 287949SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 297949SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 307949SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 317949SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 327949SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 337949SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 347949SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 357949SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 367949SN/A * 377949SN/A * Authors: Ali Saidi 387949SN/A * William Wang 397949SN/A */ 407949SN/A 417949SN/A/** @file 429330Schander.sudanthi@arm.com * Declaration of a VNC input 437949SN/A */ 447949SN/A 459330Schander.sudanthi@arm.com#ifndef __BASE_VNC_VNC_INPUT_HH__ 469330Schander.sudanthi@arm.com#define __BASE_VNC_VNC_INPUT_HH__ 477949SN/A 487949SN/A#include <iostream> 4910839Sandreas.sandberg@arm.com#include <memory> 507949SN/A 5112230Sgiacomo.travaglini@arm.com#include "base/imgwriter.hh" 529330Schander.sudanthi@arm.com#include "params/VncInput.hh" 537949SN/A#include "sim/sim_object.hh" 547949SN/A 5511359Sandreas@sandberg.pp.seclass OutputDirectory; 5611359Sandreas@sandberg.pp.se 577949SN/A/** 587949SN/A * A device that expects to receive input from the vnc server should derrive 597949SN/A * (through mulitple inheritence if necessary from VncKeyboard or VncMouse 607949SN/A * and call setKeyboard() or setMouse() respectively on the vnc server. 617949SN/A */ 627949SN/Aclass VncKeyboard 637949SN/A{ 647949SN/A public: 657949SN/A /** 667949SN/A * Called when the vnc server receives a key press event from the 677949SN/A * client. 687949SN/A * @param key the key passed is an x11 keysym 697949SN/A * @param down is the key now down or up? 707949SN/A */ 717949SN/A virtual void keyPress(uint32_t key, bool down) = 0; 727949SN/A}; 737949SN/A 747949SN/Aclass VncMouse 757949SN/A{ 767949SN/A public: 777949SN/A /** 787949SN/A * called whenever the mouse moves or it's button state changes 797949SN/A * buttons is a simple mask with each button (0-8) corresponding to 807949SN/A * a bit position in the byte with 1 being down and 0 being up 817949SN/A * @param x the x position of the mouse 827949SN/A * @param y the y position of the mouse 837949SN/A * @param buttos the button state as described above 847949SN/A */ 857949SN/A virtual void mouseAt(uint16_t x, uint16_t y, uint8_t buttons) = 0; 867949SN/A}; 877949SN/A 889330Schander.sudanthi@arm.comclass VncInput : public SimObject 897949SN/A{ 907949SN/A public: 917949SN/A 927949SN/A /** Client -> Server message IDs */ 937949SN/A enum ClientMessages { 947949SN/A ClientSetPixelFormat = 0, 957949SN/A ClientSetEncodings = 2, 967949SN/A ClientFrameBufferUpdate = 3, 977949SN/A ClientKeyEvent = 4, 987949SN/A ClientPointerEvent = 5, 997949SN/A ClientCutText = 6 1007949SN/A }; 1017949SN/A 1027949SN/A struct PixelFormat { 1037949SN/A uint8_t bpp; 1047949SN/A uint8_t depth; 1057949SN/A uint8_t bigendian; 1067949SN/A uint8_t truecolor; 1077949SN/A uint16_t redmax; 1087949SN/A uint16_t greenmax; 1097949SN/A uint16_t bluemax; 1107949SN/A uint8_t redshift; 1117949SN/A uint8_t greenshift; 1127949SN/A uint8_t blueshift; 1137949SN/A uint8_t padding[3]; 1147949SN/A } M5_ATTR_PACKED; 1157949SN/A 1167949SN/A struct PixelFormatMessage { 1177949SN/A uint8_t type; 1187949SN/A uint8_t padding[3]; 1197949SN/A PixelFormat px; 1207949SN/A } M5_ATTR_PACKED; 1217949SN/A 1227949SN/A struct PixelEncodingsMessage { 1237949SN/A uint8_t type; 1247949SN/A uint8_t padding; 1257949SN/A uint16_t num_encodings; 1267949SN/A } M5_ATTR_PACKED; 1277949SN/A 1287949SN/A struct FrameBufferUpdateReq { 1297949SN/A uint8_t type; 1307949SN/A uint8_t incremental; 1317949SN/A uint16_t x; 1327949SN/A uint16_t y; 1337949SN/A uint16_t width; 1347949SN/A uint16_t height; 1357949SN/A } M5_ATTR_PACKED; 1367949SN/A 1377949SN/A struct KeyEventMessage { 1387949SN/A uint8_t type; 1397949SN/A uint8_t down_flag; 1407949SN/A uint8_t padding[2]; 1417949SN/A uint32_t key; 1427949SN/A } M5_ATTR_PACKED; 1437949SN/A 1447949SN/A struct PointerEventMessage { 1457949SN/A uint8_t type; 1467949SN/A uint8_t button_mask; 1477949SN/A uint16_t x; 1487949SN/A uint16_t y; 1497949SN/A } M5_ATTR_PACKED; 1507949SN/A 1517949SN/A struct ClientCutTextMessage { 1527949SN/A uint8_t type; 1537949SN/A uint8_t padding[3]; 1547949SN/A uint32_t length; 1557949SN/A } M5_ATTR_PACKED; 1567949SN/A 1579330Schander.sudanthi@arm.com typedef VncInputParams Params; 1589330Schander.sudanthi@arm.com VncInput(const Params *p); 1597949SN/A 1609330Schander.sudanthi@arm.com /** Set the address of the frame buffer we are going to show. 1619330Schander.sudanthi@arm.com * To avoid copying, just have the display controller 1629330Schander.sudanthi@arm.com * tell us where the data is instead of constanly copying it around 1639330Schander.sudanthi@arm.com * @param rfb frame buffer that we're going to use 1649330Schander.sudanthi@arm.com */ 16510839Sandreas.sandberg@arm.com virtual void setFrameBuffer(const FrameBuffer *rfb); 1667949SN/A 1679330Schander.sudanthi@arm.com /** Set up the device that would like to receive notifications when keys are 1689330Schander.sudanthi@arm.com * pressed in the vnc client keyboard 1699330Schander.sudanthi@arm.com * @param _keyboard an object that derrives from VncKeyboard 1709330Schander.sudanthi@arm.com */ 1719330Schander.sudanthi@arm.com void setKeyboard(VncKeyboard *_keyboard) { keyboard = _keyboard; } 1727949SN/A 1739330Schander.sudanthi@arm.com /** Setup the device that would like to receive notifications when mouse 1749330Schander.sudanthi@arm.com * movements or button presses are received from the vnc client. 1759330Schander.sudanthi@arm.com * @param _mouse an object that derrives from VncMouse 1769330Schander.sudanthi@arm.com */ 1779330Schander.sudanthi@arm.com void setMouse(VncMouse *_mouse) { mouse = _mouse; } 1789330Schander.sudanthi@arm.com 1799330Schander.sudanthi@arm.com /** What is the width of the screen we're displaying. 1809330Schander.sudanthi@arm.com * This is used for pointer/tablet devices that need to know to calculate 1819330Schander.sudanthi@arm.com * the correct value to send to the device driver. 1829330Schander.sudanthi@arm.com * @return the width of the simulated screen 1839330Schander.sudanthi@arm.com */ 1849330Schander.sudanthi@arm.com uint16_t videoWidth() const { return _videoWidth; } 1859330Schander.sudanthi@arm.com 1869330Schander.sudanthi@arm.com /** What is the height of the screen we're displaying. 1879330Schander.sudanthi@arm.com * This is used for pointer/tablet devices that need to know to calculate 1889330Schander.sudanthi@arm.com * the correct value to send to the device driver. 1899330Schander.sudanthi@arm.com * @return the height of the simulated screen 1909330Schander.sudanthi@arm.com */ 1919330Schander.sudanthi@arm.com uint16_t videoHeight() const { return _videoHeight; } 1929330Schander.sudanthi@arm.com 1939330Schander.sudanthi@arm.com /** The frame buffer uses this call to notify the vnc server that 1949330Schander.sudanthi@arm.com * the frame buffer has been updated and a new image needs to be sent to the 1959330Schander.sudanthi@arm.com * client 1969330Schander.sudanthi@arm.com */ 19710839Sandreas.sandberg@arm.com virtual void setDirty(); 1987949SN/A 1997949SN/A protected: 20010839Sandreas.sandberg@arm.com virtual void frameBufferResized() {}; 20110839Sandreas.sandberg@arm.com 2029330Schander.sudanthi@arm.com /** The device to notify when we get key events */ 2039330Schander.sudanthi@arm.com VncKeyboard *keyboard; 2047949SN/A 2059330Schander.sudanthi@arm.com /** The device to notify when we get mouse events */ 2069330Schander.sudanthi@arm.com VncMouse *mouse; 2077949SN/A 2089330Schander.sudanthi@arm.com /** pointer to the actual data that is stored in the frame buffer device */ 20910839Sandreas.sandberg@arm.com const FrameBuffer *fb; 2107949SN/A 2117949SN/A /** the width of the frame buffer we are sending to the client */ 2127949SN/A uint16_t _videoWidth; 2137949SN/A 2147949SN/A /** the height of the frame buffer we are sending to the client */ 2157949SN/A uint16_t _videoHeight; 2167949SN/A 2178635SN/A /** Flag indicating whether to capture snapshots of frame buffer or not */ 2188635SN/A bool captureEnabled; 2198635SN/A 2208635SN/A /** Current frame number being captured to a file */ 2218635SN/A int captureCurrentFrame; 2228635SN/A 2238635SN/A /** Directory to store captured frames to */ 22411359Sandreas@sandberg.pp.se OutputDirectory *captureOutputDirectory; 2258635SN/A 2268635SN/A /** Computed hash of the last captured frame */ 2278635SN/A uint64_t captureLastHash; 2288635SN/A 22912230Sgiacomo.travaglini@arm.com /** Cached ImgWriter object for writing out frame buffers to file */ 23012230Sgiacomo.travaglini@arm.com std::unique_ptr<ImgWriter> captureImage; 23112230Sgiacomo.travaglini@arm.com 23212230Sgiacomo.travaglini@arm.com /** image format */ 23312230Sgiacomo.travaglini@arm.com Enums::ImageFormat imgFormat; 2348635SN/A 2358635SN/A /** Captures the current frame buffer to a file */ 2368635SN/A void captureFrameBuffer(); 2377949SN/A}; 2387949SN/A#endif 239