Constantin Kaplinsky | 2c01983 | 2008-05-30 11:02:04 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2007-2008 Constantin Kaplinsky. All Rights Reserved. |
Constantin Kaplinsky | 614c7b5 | 2007-12-26 18:17:09 +0000 | [diff] [blame] | 2 | * |
| 3 | * This is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License as published by |
| 5 | * the Free Software Foundation; either version 2 of the License, or |
| 6 | * (at your option) any later version. |
| 7 | * |
| 8 | * This software is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License |
| 14 | * along with this software; if not, write to the Free Software |
| 15 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
| 16 | * USA. |
| 17 | */ |
| 18 | |
| 19 | // |
| 20 | // XPixelBuffer.h |
| 21 | // |
| 22 | |
| 23 | #ifndef __XPIXELBUFFER_H__ |
| 24 | #define __XPIXELBUFFER_H__ |
| 25 | |
| 26 | #include <rfb/PixelBuffer.h> |
Constantin Kaplinsky | 303433a | 2008-06-04 05:57:06 +0000 | [diff] [blame] | 27 | #include <rfb/VNCServer.h> |
Constantin Kaplinsky | 936c369 | 2007-12-27 08:42:53 +0000 | [diff] [blame] | 28 | #include <x0vncserver/Image.h> |
Constantin Kaplinsky | 303433a | 2008-06-04 05:57:06 +0000 | [diff] [blame] | 29 | #include <x0vncserver/PollingManager.h> |
Constantin Kaplinsky | 614c7b5 | 2007-12-26 18:17:09 +0000 | [diff] [blame] | 30 | |
| 31 | using namespace rfb; |
| 32 | |
| 33 | // |
Constantin Kaplinsky | 936c369 | 2007-12-27 08:42:53 +0000 | [diff] [blame] | 34 | // XPixelBuffer is an Image-based implementation of FullFramePixelBuffer. |
Constantin Kaplinsky | 614c7b5 | 2007-12-26 18:17:09 +0000 | [diff] [blame] | 35 | // |
| 36 | |
| 37 | class XPixelBuffer : public FullFramePixelBuffer |
| 38 | { |
| 39 | public: |
Constantin Kaplinsky | e0c80c5 | 2008-06-04 03:10:05 +0000 | [diff] [blame] | 40 | XPixelBuffer(Display *dpy, ImageFactory &factory, |
Constantin Kaplinsky | f773a8e | 2008-06-04 04:30:10 +0000 | [diff] [blame] | 41 | const Rect &rect, ColourMap* cm); |
Constantin Kaplinsky | 936c369 | 2007-12-27 08:42:53 +0000 | [diff] [blame] | 42 | virtual ~XPixelBuffer(); |
Constantin Kaplinsky | 614c7b5 | 2007-12-26 18:17:09 +0000 | [diff] [blame] | 43 | |
Constantin Kaplinsky | 8a85c49 | 2008-06-04 05:36:40 +0000 | [diff] [blame] | 44 | // Provide access to the underlying Image object. |
Constantin Kaplinsky | 303433a | 2008-06-04 05:57:06 +0000 | [diff] [blame] | 45 | const Image *getImage() const { return m_image; } |
| 46 | |
| 47 | // Detect changed pixels, notify the server. |
| 48 | inline void poll(VNCServer *server) { m_poller->poll(server); } |
Constantin Kaplinsky | 2c01983 | 2008-05-30 11:02:04 +0000 | [diff] [blame] | 49 | |
Constantin Kaplinsky | e0c80c5 | 2008-06-04 03:10:05 +0000 | [diff] [blame] | 50 | // Override PixelBuffer::getStride(). |
Constantin Kaplinsky | 936c369 | 2007-12-27 08:42:53 +0000 | [diff] [blame] | 51 | virtual int getStride() const { return m_stride; } |
Constantin Kaplinsky | 614c7b5 | 2007-12-26 18:17:09 +0000 | [diff] [blame] | 52 | |
Constantin Kaplinsky | e0c80c5 | 2008-06-04 03:10:05 +0000 | [diff] [blame] | 53 | // Override PixelBuffer::grabRegion(). |
Constantin Kaplinsky | b3530d4 | 2007-12-26 19:17:02 +0000 | [diff] [blame] | 54 | virtual void grabRegion(const rfb::Region& region); |
| 55 | |
Constantin Kaplinsky | 614c7b5 | 2007-12-26 18:17:09 +0000 | [diff] [blame] | 56 | protected: |
Constantin Kaplinsky | 303433a | 2008-06-04 05:57:06 +0000 | [diff] [blame] | 57 | PollingManager *m_poller; |
| 58 | |
Constantin Kaplinsky | 936c369 | 2007-12-27 08:42:53 +0000 | [diff] [blame] | 59 | Display *m_dpy; |
| 60 | Image* m_image; |
| 61 | int m_offsetLeft; |
| 62 | int m_offsetTop; |
| 63 | |
| 64 | // The number of pixels in a row, with padding included. |
| 65 | int m_stride; |
Constantin Kaplinsky | 429ea96 | 2008-06-02 11:56:57 +0000 | [diff] [blame] | 66 | |
| 67 | // Copy pixels from the screen to the pixel buffer, |
| 68 | // for the specified rectangular area of the buffer. |
| 69 | inline void grabRect(const Rect &r) { |
| 70 | m_image->get(DefaultRootWindow(m_dpy), |
| 71 | m_offsetLeft + r.tl.x, m_offsetTop + r.tl.y, |
| 72 | r.width(), r.height(), r.tl.x, r.tl.y); |
| 73 | } |
Constantin Kaplinsky | 614c7b5 | 2007-12-26 18:17:09 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | #endif // __XPIXELBUFFER_H__ |
| 77 | |