- Timestamp:
- 03/21/12 18:36:20 (14 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgPlugins/vnc/ReaderWriterVNC.cpp
r12854 r13041 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1999-2008 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1999-2008 Robert Osfield 2 2 * 3 * This software is open source and may be redistributed and/or modified under 3 * This software is open source and may be redistributed and/or modified under 4 4 * the terms of the GNU General Public License (GPL) version 2.0. 5 5 * The full license is in LICENSE.txt file included with this distribution,. 6 * 6 * 7 7 * This software is distributed in the hope that it will be useful, 8 8 * but WITHOUT ANY WARRANTY; without even the implied warranty of 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 10 * include LICENSE.txt for more details. 11 11 */ … … 26 26 { 27 27 public: 28 28 29 29 LibVncImage(); 30 30 … … 32 32 33 33 void close(); 34 34 35 35 virtual bool sendPointerEvent(int x, int y, int buttonMask); 36 36 … … 47 47 48 48 static rfbBool resizeImage(rfbClient* client); 49 49 50 50 static void updateImage(rfbClient* client,int x,int y,int w,int h); 51 51 52 52 static void passwordCheck(rfbClient* client,const char* encryptedPassWord,int len); 53 53 static char* getPassword(rfbClient* client); … … 56 56 std::string _username; 57 57 std::string _password; 58 58 59 59 double _timeOfLastUpdate; 60 60 double _timeOfLastRender; … … 64 64 65 65 protected: 66 66 67 67 virtual ~LibVncImage(); 68 68 … … 79 79 { 80 80 _done = true; 81 while(isRunning()) 81 while(isRunning()) 82 82 { 83 83 OpenThreads::Thread::YieldCurrentThread(); … … 90 90 { 91 91 if (_image->_active) 92 { 92 { 93 93 int i=WaitForMessage(_client,5000); 94 94 if(i<0) … … 98 98 { 99 99 OSG_INFO<<"VNC Handling "<<i<<" messages"<<std::endl; 100 100 101 101 if(!HandleRFBServerMessage(_client)) 102 102 return; … … 109 109 _image->_inactiveBlock->block(); 110 110 } 111 112 111 112 113 113 double deltaTime = _image->getTimeOfLastRender() - _image->getTimeOfLastUpdate(); 114 114 if (deltaTime<-0.01) … … 136 136 137 137 osg::ref_ptr<RfbThread> _rfbThread; 138 138 139 139 }; 140 140 … … 234 234 235 235 rfbClientSetClientData(_client, 0, this); 236 236 237 237 _client->serverHost = strdup(hostname.c_str()); 238 238 … … 247 247 _rfbThread = new RfbThread(_client, this); 248 248 _rfbThread->startThread(); 249 249 250 250 return true; 251 251 } … … 253 253 { 254 254 close(); 255 255 256 256 return false; 257 257 } … … 278 278 279 279 280 rfbBool LibVncImage::resizeImage(rfbClient* client) 280 rfbBool LibVncImage::resizeImage(rfbClient* client) 281 281 { 282 282 LibVncImage* image = (LibVncImage*)(rfbClientGetClientData(client, 0)); 283 283 284 284 int width = client->width; 285 285 int height = client->height; … … 295 295 if (image->_optionString.find("swap")!=std::string::npos || image->_optionString.find("swop")!=std::string::npos) swap = true; 296 296 } 297 297 298 298 GLenum gl_pixelFormat = swap ? GL_BGRA : GL_RGBA; 299 299 … … 310 310 311 311 312 312 313 313 client->frameBuffer= (uint8_t*)(image->data()); 314 314 315 315 return TRUE; 316 316 } … … 359 359 { 360 360 public: 361 361 362 362 ReaderWriterVNC() 363 363 { 364 364 supportsExtension("vnc","VNC plugin"); 365 365 366 366 supportsOption("swap","Swaps the pixel format order, exchanging the red and blue channels."); 367 367 supportsOption("swop","American spelling, same effect as swap."); … … 371 371 supportsOption("BGRA","Use BGRA pixel format for the vnc image"); 372 372 } 373 373 374 374 virtual const char* className() const { return "VNC plugin"; } 375 375 … … 387 387 388 388 std::string hostname = osgDB::getNameLessExtension(fileName); 389 389 390 390 OSG_NOTICE<<"Hostname = "<<hostname<<std::endl; 391 391 392 392 osg::ref_ptr<LibVncImage> image = new LibVncImage; 393 image->setDataVariance(osg::Object::DYNAMIC); 393 image->setDataVariance(osg::Object::DYNAMIC); 394 394 image->setOrigin(osg::Image::TOP_LEFT); 395 395 … … 420 420 return "Could not connect to "+hostname; 421 421 } 422 422 423 423 return image.get(); 424 424 } 425 425 426 426 virtual osgDB::ReaderWriter::ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const 427 427 { 428 428 osgDB::ReaderWriter::ReadResult result = readImage(fileName, options); 429 429 if (!result.validImage()) return result; 430 430 431 431 osg::ref_ptr<osgWidget::VncClient> vncClient = new osgWidget::VncClient(); 432 432 if (vncClient->assign(dynamic_cast<osgWidget::VncImage*>(result.getImage())))
