blob: f4641825e7fb96e1dab7f47fdd7e7efd14790123 [file] [log] [blame]
Constantin Kaplinsky2c019832008-05-30 11:02:04 +00001/* Copyright (C) 2007-2008 Constantin Kaplinsky. All Rights Reserved.
Pierre Ossman4d0bc6e2014-02-12 13:12:31 +01002 * Copyright 2014 Pierre Ossman for Cendio AB
Constantin Kaplinskyb3530d42007-12-26 19:17:02 +00003 *
4 * This is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this software; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
17 * USA.
18 */
19
20//
21// XPixelBuffer.cxx
22//
23
Constantin Kaplinsky429ea962008-06-02 11:56:57 +000024#include <vector>
25#include <rfb/Region.h>
Constantin Kaplinsky936c3692007-12-27 08:42:53 +000026#include <X11/Xlib.h>
Constantin Kaplinskyb3530d42007-12-26 19:17:02 +000027#include <x0vncserver/XPixelBuffer.h>
28
Constantin Kaplinsky936c3692007-12-27 08:42:53 +000029using namespace rfb;
30
Constantin Kaplinskye0c80c52008-06-04 03:10:05 +000031XPixelBuffer::XPixelBuffer(Display *dpy, ImageFactory &factory,
Pierre Ossmanb6b4dc62014-01-20 15:05:21 +010032 const Rect &rect)
Constantin Kaplinsky1d2967f2008-06-03 11:21:42 +000033 : FullFramePixelBuffer(),
Constantin Kaplinsky303433a2008-06-04 05:57:06 +000034 m_poller(0),
Constantin Kaplinsky936c3692007-12-27 08:42:53 +000035 m_dpy(dpy),
Constantin Kaplinskyf773a8e2008-06-04 04:30:10 +000036 m_image(factory.newImage(dpy, rect.width(), rect.height())),
37 m_offsetLeft(rect.tl.x),
Pierre Ossman2e5a1062014-01-30 17:57:27 +010038 m_offsetTop(rect.tl.y)
Constantin Kaplinskyb3530d42007-12-26 19:17:02 +000039{
Constantin Kaplinsky1d2967f2008-06-03 11:21:42 +000040 // Fill in the PixelFormat structure of the parent class.
Pierre Ossman4d0bc6e2014-02-12 13:12:31 +010041 format = PixelFormat(m_image->xim->bits_per_pixel,
42 m_image->xim->depth,
43 (m_image->xim->byte_order == MSBFirst),
44 m_image->isTrueColor(),
45 m_image->xim->red_mask >> (ffs(m_image->xim->red_mask) - 1),
46 m_image->xim->green_mask >> (ffs(m_image->xim->green_mask) - 1),
47 m_image->xim->blue_mask >> (ffs(m_image->xim->blue_mask) - 1),
48 ffs(m_image->xim->red_mask) - 1,
49 ffs(m_image->xim->green_mask) - 1,
50 ffs(m_image->xim->blue_mask) - 1);
Constantin Kaplinsky1d2967f2008-06-03 11:21:42 +000051
52 // Set up the remaining data of the parent class.
Constantin Kaplinskyf773a8e2008-06-04 04:30:10 +000053 width_ = rect.width();
54 height_ = rect.height();
Constantin Kaplinskye0c80c52008-06-04 03:10:05 +000055 data = (rdr::U8 *)m_image->xim->data;
Constantin Kaplinsky1d2967f2008-06-03 11:21:42 +000056
Constantin Kaplinskye0c80c52008-06-04 03:10:05 +000057 // Calculate the distance in pixels between two subsequent scan
Constantin Kaplinskyf773a8e2008-06-04 04:30:10 +000058 // lines of the framebuffer. This may differ from image width.
Pierre Ossman2e5a1062014-01-30 17:57:27 +010059 stride = m_image->xim->bytes_per_line * 8 / m_image->xim->bits_per_pixel;
Constantin Kaplinskye0c80c52008-06-04 03:10:05 +000060
Constantin Kaplinsky1d2967f2008-06-03 11:21:42 +000061 // Get initial screen image from the X display.
Constantin Kaplinsky429ea962008-06-02 11:56:57 +000062 m_image->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop);
Constantin Kaplinsky303433a2008-06-04 05:57:06 +000063
64 // PollingManager will detect changed pixels.
65 m_poller = new PollingManager(dpy, getImage(), factory,
66 m_offsetLeft, m_offsetTop);
Constantin Kaplinskyb3530d42007-12-26 19:17:02 +000067}
68
Constantin Kaplinsky936c3692007-12-27 08:42:53 +000069XPixelBuffer::~XPixelBuffer()
70{
Constantin Kaplinsky303433a2008-06-04 05:57:06 +000071 delete m_poller;
Constantin Kaplinskye0c80c52008-06-04 03:10:05 +000072 delete m_image;
Constantin Kaplinsky936c3692007-12-27 08:42:53 +000073}
74
75void
76XPixelBuffer::grabRegion(const rfb::Region& region)
77{
Constantin Kaplinsky429ea962008-06-02 11:56:57 +000078 std::vector<Rect> rects;
79 std::vector<Rect>::const_iterator i;
80 region.get_rects(&rects);
81 for (i = rects.begin(); i != rects.end(); i++) {
82 grabRect(*i);
83 }
Constantin Kaplinsky936c3692007-12-27 08:42:53 +000084}
85