vncinput.hh revision 9330
17949SN/A/* 27949SN/A * Copyright (c) 2010 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> 497949SN/A 508229SN/A#include "base/vnc/convert.hh" 518635SN/A#include "base/bitmap.hh" 529330Schander.sudanthi@arm.com#include "params/VncInput.hh" 537949SN/A#include "sim/sim_object.hh" 547949SN/A 557949SN/A/** 567949SN/A * A device that expects to receive input from the vnc server should derrive 577949SN/A * (through mulitple inheritence if necessary from VncKeyboard or VncMouse 587949SN/A * and call setKeyboard() or setMouse() respectively on the vnc server. 597949SN/A */ 607949SN/Aclass VncKeyboard 617949SN/A{ 627949SN/A public: 637949SN/A /** 647949SN/A * Called when the vnc server receives a key press event from the 657949SN/A * client. 667949SN/A * @param key the key passed is an x11 keysym 677949SN/A * @param down is the key now down or up? 687949SN/A */ 697949SN/A virtual void keyPress(uint32_t key, bool down) = 0; 707949SN/A}; 717949SN/A 727949SN/Aclass VncMouse 737949SN/A{ 747949SN/A public: 757949SN/A /** 767949SN/A * called whenever the mouse moves or it's button state changes 777949SN/A * buttons is a simple mask with each button (0-8) corresponding to 787949SN/A * a bit position in the byte with 1 being down and 0 being up 797949SN/A * @param x the x position of the mouse 807949SN/A * @param y the y position of the mouse 817949SN/A * @param buttos the button state as described above 827949SN/A */ 837949SN/A virtual void mouseAt(uint16_t x, uint16_t y, uint8_t buttons) = 0; 847949SN/A}; 857949SN/A 869330Schander.sudanthi@arm.comclass VncInput : public SimObject 877949SN/A{ 887949SN/A public: 897949SN/A 907949SN/A /** Client -> Server message IDs */ 917949SN/A enum ClientMessages { 927949SN/A ClientSetPixelFormat = 0, 937949SN/A ClientSetEncodings = 2, 947949SN/A ClientFrameBufferUpdate = 3, 957949SN/A ClientKeyEvent = 4, 967949SN/A ClientPointerEvent = 5, 977949SN/A ClientCutText = 6 987949SN/A }; 997949SN/A 1007949SN/A struct PixelFormat { 1017949SN/A uint8_t bpp; 1027949SN/A uint8_t depth; 1037949SN/A uint8_t bigendian; 1047949SN/A uint8_t truecolor; 1057949SN/A uint16_t redmax; 1067949SN/A uint16_t greenmax; 1077949SN/A uint16_t bluemax; 1087949SN/A uint8_t redshift; 1097949SN/A uint8_t greenshift; 1107949SN/A uint8_t blueshift; 1117949SN/A uint8_t padding[3]; 1127949SN/A } M5_ATTR_PACKED; 1137949SN/A 1147949SN/A struct PixelFormatMessage { 1157949SN/A uint8_t type; 1167949SN/A uint8_t padding[3]; 1177949SN/A PixelFormat px; 1187949SN/A } M5_ATTR_PACKED; 1197949SN/A 1207949SN/A struct PixelEncodingsMessage { 1217949SN/A uint8_t type; 1227949SN/A uint8_t padding; 1237949SN/A uint16_t num_encodings; 1247949SN/A } M5_ATTR_PACKED; 1257949SN/A 1267949SN/A struct FrameBufferUpdateReq { 1277949SN/A uint8_t type; 1287949SN/A uint8_t incremental; 1297949SN/A uint16_t x; 1307949SN/A uint16_t y; 1317949SN/A uint16_t width; 1327949SN/A uint16_t height; 1337949SN/A } M5_ATTR_PACKED; 1347949SN/A 1357949SN/A struct KeyEventMessage { 1367949SN/A uint8_t type; 1377949SN/A uint8_t down_flag; 1387949SN/A uint8_t padding[2]; 1397949SN/A uint32_t key; 1407949SN/A } M5_ATTR_PACKED; 1417949SN/A 1427949SN/A struct PointerEventMessage { 1437949SN/A uint8_t type; 1447949SN/A uint8_t button_mask; 1457949SN/A uint16_t x; 1467949SN/A uint16_t y; 1477949SN/A } M5_ATTR_PACKED; 1487949SN/A 1497949SN/A struct ClientCutTextMessage { 1507949SN/A uint8_t type; 1517949SN/A uint8_t padding[3]; 1527949SN/A uint32_t length; 1537949SN/A } M5_ATTR_PACKED; 1547949SN/A 1559330Schander.sudanthi@arm.com typedef VncInputParams Params; 1569330Schander.sudanthi@arm.com VncInput(const Params *p); 1577949SN/A 1589330Schander.sudanthi@arm.com /** Set the address of the frame buffer we are going to show. 1599330Schander.sudanthi@arm.com * To avoid copying, just have the display controller 1609330Schander.sudanthi@arm.com * tell us where the data is instead of constanly copying it around 1619330Schander.sudanthi@arm.com * @param rfb frame buffer that we're going to use 1629330Schander.sudanthi@arm.com */ 1639330Schander.sudanthi@arm.com void 1649330Schander.sudanthi@arm.com setFramebufferAddr(uint8_t* rfb) 1659330Schander.sudanthi@arm.com { 1669330Schander.sudanthi@arm.com fbPtr = rfb; 1679330Schander.sudanthi@arm.com } 1687949SN/A 1699330Schander.sudanthi@arm.com /** Set up the device that would like to receive notifications when keys are 1709330Schander.sudanthi@arm.com * pressed in the vnc client keyboard 1719330Schander.sudanthi@arm.com * @param _keyboard an object that derrives from VncKeyboard 1729330Schander.sudanthi@arm.com */ 1739330Schander.sudanthi@arm.com void setKeyboard(VncKeyboard *_keyboard) { keyboard = _keyboard; } 1747949SN/A 1759330Schander.sudanthi@arm.com /** Setup the device that would like to receive notifications when mouse 1769330Schander.sudanthi@arm.com * movements or button presses are received from the vnc client. 1779330Schander.sudanthi@arm.com * @param _mouse an object that derrives from VncMouse 1789330Schander.sudanthi@arm.com */ 1799330Schander.sudanthi@arm.com void setMouse(VncMouse *_mouse) { mouse = _mouse; } 1809330Schander.sudanthi@arm.com 1819330Schander.sudanthi@arm.com /** What is the width of the screen we're displaying. 1829330Schander.sudanthi@arm.com * This is used for pointer/tablet devices that need to know to calculate 1839330Schander.sudanthi@arm.com * the correct value to send to the device driver. 1849330Schander.sudanthi@arm.com * @return the width of the simulated screen 1859330Schander.sudanthi@arm.com */ 1869330Schander.sudanthi@arm.com uint16_t videoWidth() const { return _videoWidth; } 1879330Schander.sudanthi@arm.com 1889330Schander.sudanthi@arm.com /** What is the height of the screen we're displaying. 1899330Schander.sudanthi@arm.com * This is used for pointer/tablet devices that need to know to calculate 1909330Schander.sudanthi@arm.com * the correct value to send to the device driver. 1919330Schander.sudanthi@arm.com * @return the height of the simulated screen 1929330Schander.sudanthi@arm.com */ 1939330Schander.sudanthi@arm.com uint16_t videoHeight() const { return _videoHeight; } 1949330Schander.sudanthi@arm.com 1959330Schander.sudanthi@arm.com /** The frame buffer uses this call to notify the vnc server that 1969330Schander.sudanthi@arm.com * the frame buffer has been updated and a new image needs to be sent to the 1979330Schander.sudanthi@arm.com * client 1989330Schander.sudanthi@arm.com */ 1999330Schander.sudanthi@arm.com virtual void setDirty() 2009330Schander.sudanthi@arm.com { 2019330Schander.sudanthi@arm.com if (captureEnabled) 2029330Schander.sudanthi@arm.com captureFrameBuffer(); 2039330Schander.sudanthi@arm.com } 2049330Schander.sudanthi@arm.com 2059330Schander.sudanthi@arm.com /** Set the mode of the data the frame buffer will be sending us 2069330Schander.sudanthi@arm.com * @param mode the mode 2079330Schander.sudanthi@arm.com */ 2089330Schander.sudanthi@arm.com virtual void setFrameBufferParams(VideoConvert::Mode mode, uint16_t width, uint16_t height); 2097949SN/A 2107949SN/A protected: 2119330Schander.sudanthi@arm.com /** The device to notify when we get key events */ 2129330Schander.sudanthi@arm.com VncKeyboard *keyboard; 2137949SN/A 2149330Schander.sudanthi@arm.com /** The device to notify when we get mouse events */ 2159330Schander.sudanthi@arm.com VncMouse *mouse; 2167949SN/A 2179330Schander.sudanthi@arm.com /** The video converter that transforms data for us */ 2189330Schander.sudanthi@arm.com VideoConvert *vc; 2197949SN/A 2209330Schander.sudanthi@arm.com /** pointer to the actual data that is stored in the frame buffer device */ 2219330Schander.sudanthi@arm.com uint8_t* fbPtr; 2227949SN/A 2239330Schander.sudanthi@arm.com /** The mode of data we're getting frame buffer in */ 2249330Schander.sudanthi@arm.com VideoConvert::Mode videoMode; 2257949SN/A 2267949SN/A /** the width of the frame buffer we are sending to the client */ 2277949SN/A uint16_t _videoWidth; 2287949SN/A 2297949SN/A /** the height of the frame buffer we are sending to the client */ 2307949SN/A uint16_t _videoHeight; 2317949SN/A 2328635SN/A /** Flag indicating whether to capture snapshots of frame buffer or not */ 2338635SN/A bool captureEnabled; 2348635SN/A 2358635SN/A /** Current frame number being captured to a file */ 2368635SN/A int captureCurrentFrame; 2378635SN/A 2388635SN/A /** Directory to store captured frames to */ 2398635SN/A std::string captureOutputDirectory; 2408635SN/A 2418635SN/A /** Computed hash of the last captured frame */ 2428635SN/A uint64_t captureLastHash; 2438635SN/A 2448635SN/A /** Cached bitmap object for writing out frame buffers to file */ 2458635SN/A Bitmap *captureBitmap; 2468635SN/A 2478635SN/A /** Captures the current frame buffer to a file */ 2488635SN/A void captureFrameBuffer(); 2497949SN/A}; 2507949SN/A#endif 251