blob: ed22508dfcda300b4593d64405d9891d4c737952 [file] [log] [blame]
Constantin Kaplinsky2c019832008-05-30 11:02:04 +00001/* Copyright (C) 2007-2008 Constantin Kaplinsky. All Rights Reserved.
Constantin Kaplinskyb3530d42007-12-26 19:17:02 +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.cxx
21//
22
Constantin Kaplinsky429ea962008-06-02 11:56:57 +000023#include <vector>
24#include <rfb/Region.h>
Constantin Kaplinsky936c3692007-12-27 08:42:53 +000025#include <X11/Xlib.h>
Constantin Kaplinskyb3530d42007-12-26 19:17:02 +000026#include <x0vncserver/XPixelBuffer.h>
27
Constantin Kaplinsky936c3692007-12-27 08:42:53 +000028using namespace rfb;
29
Constantin Kaplinskye0c80c52008-06-04 03:10:05 +000030XPixelBuffer::XPixelBuffer(Display *dpy, ImageFactory &factory,
Constantin Kaplinskyf773a8e2008-06-04 04:30:10 +000031 const Rect &rect, ColourMap* cm)
Constantin Kaplinsky1d2967f2008-06-03 11:21:42 +000032 : FullFramePixelBuffer(),
Constantin Kaplinsky936c3692007-12-27 08:42:53 +000033 m_dpy(dpy),
Constantin Kaplinskyf773a8e2008-06-04 04:30:10 +000034 m_image(factory.newImage(dpy, rect.width(), rect.height())),
35 m_offsetLeft(rect.tl.x),
36 m_offsetTop(rect.tl.y),
Constantin Kaplinskye0c80c52008-06-04 03:10:05 +000037 m_stride(0)
Constantin Kaplinskyb3530d42007-12-26 19:17:02 +000038{
Constantin Kaplinsky1d2967f2008-06-03 11:21:42 +000039 // Fill in the PixelFormat structure of the parent class.
Constantin Kaplinskye0c80c52008-06-04 03:10:05 +000040 format.bpp = m_image->xim->bits_per_pixel;
41 format.depth = m_image->xim->depth;
42 format.bigEndian = (m_image->xim->byte_order == MSBFirst);
43 format.trueColour = m_image->isTrueColor();
44 format.redShift = ffs(m_image->xim->red_mask) - 1;
45 format.greenShift = ffs(m_image->xim->green_mask) - 1;
46 format.blueShift = ffs(m_image->xim->blue_mask) - 1;
47 format.redMax = m_image->xim->red_mask >> format.redShift;
48 format.greenMax = m_image->xim->green_mask >> format.greenShift;
49 format.blueMax = m_image->xim->blue_mask >> format.blueShift;
Constantin Kaplinsky1d2967f2008-06-03 11:21:42 +000050
51 // Set up the remaining data of the parent class.
Constantin Kaplinskyf773a8e2008-06-04 04:30:10 +000052 width_ = rect.width();
53 height_ = rect.height();
Constantin Kaplinskye0c80c52008-06-04 03:10:05 +000054 data = (rdr::U8 *)m_image->xim->data;
Constantin Kaplinsky1d2967f2008-06-03 11:21:42 +000055 colourmap = cm;
56
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.
Constantin Kaplinskye0c80c52008-06-04 03:10:05 +000059 m_stride = m_image->xim->bytes_per_line * 8 / m_image->xim->bits_per_pixel;
60
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 Kaplinskyb3530d42007-12-26 19:17:02 +000063}
64
Constantin Kaplinsky936c3692007-12-27 08:42:53 +000065XPixelBuffer::~XPixelBuffer()
66{
Constantin Kaplinskye0c80c52008-06-04 03:10:05 +000067 delete m_image;
Constantin Kaplinsky936c3692007-12-27 08:42:53 +000068}
69
70void
71XPixelBuffer::grabRegion(const rfb::Region& region)
72{
Constantin Kaplinsky429ea962008-06-02 11:56:57 +000073 std::vector<Rect> rects;
74 std::vector<Rect>::const_iterator i;
75 region.get_rects(&rects);
76 for (i = rects.begin(); i != rects.end(); i++) {
77 grabRect(*i);
78 }
Constantin Kaplinsky936c3692007-12-27 08:42:53 +000079}
80