Constantin Kaplinsky | 2c01983 | 2008-05-30 11:02:04 +0000 | [diff] [blame] | 1 | /* Copyright (C) 2007-2008 Constantin Kaplinsky. All Rights Reserved. |
Constantin Kaplinsky | b3530d4 | 2007-12-26 19:17:02 +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.cxx |
| 21 | // |
| 22 | |
Constantin Kaplinsky | 429ea96 | 2008-06-02 11:56:57 +0000 | [diff] [blame] | 23 | #include <vector> |
| 24 | #include <rfb/Region.h> |
Constantin Kaplinsky | 936c369 | 2007-12-27 08:42:53 +0000 | [diff] [blame] | 25 | #include <X11/Xlib.h> |
Constantin Kaplinsky | b3530d4 | 2007-12-26 19:17:02 +0000 | [diff] [blame] | 26 | #include <x0vncserver/XPixelBuffer.h> |
| 27 | |
Constantin Kaplinsky | 936c369 | 2007-12-27 08:42:53 +0000 | [diff] [blame] | 28 | using namespace rfb; |
| 29 | |
Constantin Kaplinsky | e0c80c5 | 2008-06-04 03:10:05 +0000 | [diff] [blame] | 30 | XPixelBuffer::XPixelBuffer(Display *dpy, ImageFactory &factory, |
Constantin Kaplinsky | f773a8e | 2008-06-04 04:30:10 +0000 | [diff] [blame] | 31 | const Rect &rect, ColourMap* cm) |
Constantin Kaplinsky | 1d2967f | 2008-06-03 11:21:42 +0000 | [diff] [blame] | 32 | : FullFramePixelBuffer(), |
Constantin Kaplinsky | 303433a | 2008-06-04 05:57:06 +0000 | [diff] [blame] | 33 | m_poller(0), |
Constantin Kaplinsky | 936c369 | 2007-12-27 08:42:53 +0000 | [diff] [blame] | 34 | m_dpy(dpy), |
Constantin Kaplinsky | f773a8e | 2008-06-04 04:30:10 +0000 | [diff] [blame] | 35 | m_image(factory.newImage(dpy, rect.width(), rect.height())), |
| 36 | m_offsetLeft(rect.tl.x), |
| 37 | m_offsetTop(rect.tl.y), |
Constantin Kaplinsky | e0c80c5 | 2008-06-04 03:10:05 +0000 | [diff] [blame] | 38 | m_stride(0) |
Constantin Kaplinsky | b3530d4 | 2007-12-26 19:17:02 +0000 | [diff] [blame] | 39 | { |
Constantin Kaplinsky | 1d2967f | 2008-06-03 11:21:42 +0000 | [diff] [blame] | 40 | // Fill in the PixelFormat structure of the parent class. |
Constantin Kaplinsky | e0c80c5 | 2008-06-04 03:10:05 +0000 | [diff] [blame] | 41 | format.bpp = m_image->xim->bits_per_pixel; |
| 42 | format.depth = m_image->xim->depth; |
| 43 | format.bigEndian = (m_image->xim->byte_order == MSBFirst); |
| 44 | format.trueColour = m_image->isTrueColor(); |
| 45 | format.redShift = ffs(m_image->xim->red_mask) - 1; |
| 46 | format.greenShift = ffs(m_image->xim->green_mask) - 1; |
| 47 | format.blueShift = ffs(m_image->xim->blue_mask) - 1; |
| 48 | format.redMax = m_image->xim->red_mask >> format.redShift; |
| 49 | format.greenMax = m_image->xim->green_mask >> format.greenShift; |
| 50 | format.blueMax = m_image->xim->blue_mask >> format.blueShift; |
Constantin Kaplinsky | 1d2967f | 2008-06-03 11:21:42 +0000 | [diff] [blame] | 51 | |
| 52 | // Set up the remaining data of the parent class. |
Constantin Kaplinsky | f773a8e | 2008-06-04 04:30:10 +0000 | [diff] [blame] | 53 | width_ = rect.width(); |
| 54 | height_ = rect.height(); |
Constantin Kaplinsky | e0c80c5 | 2008-06-04 03:10:05 +0000 | [diff] [blame] | 55 | data = (rdr::U8 *)m_image->xim->data; |
Constantin Kaplinsky | 1d2967f | 2008-06-03 11:21:42 +0000 | [diff] [blame] | 56 | colourmap = cm; |
| 57 | |
Constantin Kaplinsky | e0c80c5 | 2008-06-04 03:10:05 +0000 | [diff] [blame] | 58 | // Calculate the distance in pixels between two subsequent scan |
Constantin Kaplinsky | f773a8e | 2008-06-04 04:30:10 +0000 | [diff] [blame] | 59 | // lines of the framebuffer. This may differ from image width. |
Constantin Kaplinsky | e0c80c5 | 2008-06-04 03:10:05 +0000 | [diff] [blame] | 60 | m_stride = m_image->xim->bytes_per_line * 8 / m_image->xim->bits_per_pixel; |
| 61 | |
Constantin Kaplinsky | 1d2967f | 2008-06-03 11:21:42 +0000 | [diff] [blame] | 62 | // Get initial screen image from the X display. |
Constantin Kaplinsky | 429ea96 | 2008-06-02 11:56:57 +0000 | [diff] [blame] | 63 | m_image->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop); |
Constantin Kaplinsky | 303433a | 2008-06-04 05:57:06 +0000 | [diff] [blame] | 64 | |
| 65 | // PollingManager will detect changed pixels. |
| 66 | m_poller = new PollingManager(dpy, getImage(), factory, |
| 67 | m_offsetLeft, m_offsetTop); |
Constantin Kaplinsky | b3530d4 | 2007-12-26 19:17:02 +0000 | [diff] [blame] | 68 | } |
| 69 | |
Constantin Kaplinsky | 936c369 | 2007-12-27 08:42:53 +0000 | [diff] [blame] | 70 | XPixelBuffer::~XPixelBuffer() |
| 71 | { |
Constantin Kaplinsky | 303433a | 2008-06-04 05:57:06 +0000 | [diff] [blame] | 72 | delete m_poller; |
Constantin Kaplinsky | e0c80c5 | 2008-06-04 03:10:05 +0000 | [diff] [blame] | 73 | delete m_image; |
Constantin Kaplinsky | 936c369 | 2007-12-27 08:42:53 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void |
| 77 | XPixelBuffer::grabRegion(const rfb::Region& region) |
| 78 | { |
Constantin Kaplinsky | 429ea96 | 2008-06-02 11:56:57 +0000 | [diff] [blame] | 79 | std::vector<Rect> rects; |
| 80 | std::vector<Rect>::const_iterator i; |
| 81 | region.get_rects(&rects); |
| 82 | for (i = rects.begin(); i != rects.end(); i++) { |
| 83 | grabRect(*i); |
| 84 | } |
Constantin Kaplinsky | 936c369 | 2007-12-27 08:42:53 +0000 | [diff] [blame] | 85 | } |
| 86 | |