blob: 18c85fe292f6ee282278e18423e03f0f93e91313 [file] [log] [blame]
Constantin Kaplinsky2c019832008-05-30 11:02:04 +00001/* Copyright (C) 2007-2008 Constantin Kaplinsky. All Rights Reserved.
Constantin Kaplinsky614c7b52007-12-26 18:17:09 +00002 *
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 Kaplinsky303433a2008-06-04 05:57:06 +000027#include <rfb/VNCServer.h>
Constantin Kaplinsky936c3692007-12-27 08:42:53 +000028#include <x0vncserver/Image.h>
Constantin Kaplinsky303433a2008-06-04 05:57:06 +000029#include <x0vncserver/PollingManager.h>
Constantin Kaplinsky614c7b52007-12-26 18:17:09 +000030
Constantin Kaplinsky614c7b52007-12-26 18:17:09 +000031//
Constantin Kaplinsky936c3692007-12-27 08:42:53 +000032// XPixelBuffer is an Image-based implementation of FullFramePixelBuffer.
Constantin Kaplinsky614c7b52007-12-26 18:17:09 +000033//
34
Peter Åstrand (astrand)f523ee12017-10-09 14:59:24 +020035class XPixelBuffer : public rfb::FullFramePixelBuffer
Constantin Kaplinsky614c7b52007-12-26 18:17:09 +000036{
37public:
Peter Åstrand (astrand)f523ee12017-10-09 14:59:24 +020038 XPixelBuffer(Display *dpy, ImageFactory &factory, const rfb::Rect &rect);
Constantin Kaplinsky936c3692007-12-27 08:42:53 +000039 virtual ~XPixelBuffer();
Constantin Kaplinsky614c7b52007-12-26 18:17:09 +000040
Constantin Kaplinsky8a85c492008-06-04 05:36:40 +000041 // Provide access to the underlying Image object.
Constantin Kaplinsky303433a2008-06-04 05:57:06 +000042 const Image *getImage() const { return m_image; }
43
44 // Detect changed pixels, notify the server.
Peter Åstrand (astrand)f523ee12017-10-09 14:59:24 +020045 inline void poll(rfb::VNCServer *server) { m_poller->poll(server); }
Constantin Kaplinsky2c019832008-05-30 11:02:04 +000046
Constantin Kaplinskye0c80c52008-06-04 03:10:05 +000047 // Override PixelBuffer::grabRegion().
Constantin Kaplinskyb3530d42007-12-26 19:17:02 +000048 virtual void grabRegion(const rfb::Region& region);
49
Constantin Kaplinsky614c7b52007-12-26 18:17:09 +000050protected:
Constantin Kaplinsky303433a2008-06-04 05:57:06 +000051 PollingManager *m_poller;
52
Constantin Kaplinsky936c3692007-12-27 08:42:53 +000053 Display *m_dpy;
54 Image* m_image;
55 int m_offsetLeft;
56 int m_offsetTop;
57
Constantin Kaplinsky429ea962008-06-02 11:56:57 +000058 // Copy pixels from the screen to the pixel buffer,
59 // for the specified rectangular area of the buffer.
Peter Åstrand (astrand)f523ee12017-10-09 14:59:24 +020060 inline void grabRect(const rfb::Rect &r) {
Constantin Kaplinsky429ea962008-06-02 11:56:57 +000061 m_image->get(DefaultRootWindow(m_dpy),
62 m_offsetLeft + r.tl.x, m_offsetTop + r.tl.y,
63 r.width(), r.height(), r.tl.x, r.tl.y);
64 }
Constantin Kaplinsky614c7b52007-12-26 18:17:09 +000065};
66
67#endif // __XPIXELBUFFER_H__
68