You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XPixelBuffer.cxx 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Copyright (C) 2007-2008 Constantin Kaplinsky. All Rights Reserved.
  2. * Copyright 2014 Pierre Ossman for Cendio AB
  3. *
  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. // XPixelBuffer.cxx
  21. //
  22. #ifdef HAVE_CONFIG_H
  23. #include <config.h>
  24. #endif
  25. #include <vector>
  26. #include <rfb/Region.h>
  27. #include <X11/Xlib.h>
  28. #include <x0vncserver/XPixelBuffer.h>
  29. using namespace rfb;
  30. XPixelBuffer::XPixelBuffer(Display *dpy, ImageFactory &factory,
  31. const Rect &rect)
  32. : FullFramePixelBuffer(),
  33. m_poller(0),
  34. m_dpy(dpy),
  35. m_image(factory.newImage(dpy, rect.width(), rect.height())),
  36. m_offsetLeft(rect.tl.x),
  37. m_offsetTop(rect.tl.y)
  38. {
  39. // Fill in the PixelFormat structure of the parent class.
  40. format = PixelFormat(m_image->xim->bits_per_pixel,
  41. m_image->xim->depth,
  42. (m_image->xim->byte_order == MSBFirst),
  43. true,
  44. m_image->xim->red_mask >> (ffs(m_image->xim->red_mask) - 1),
  45. m_image->xim->green_mask >> (ffs(m_image->xim->green_mask) - 1),
  46. m_image->xim->blue_mask >> (ffs(m_image->xim->blue_mask) - 1),
  47. ffs(m_image->xim->red_mask) - 1,
  48. ffs(m_image->xim->green_mask) - 1,
  49. ffs(m_image->xim->blue_mask) - 1);
  50. // Set up the remaining data of the parent class.
  51. setBuffer(rect.width(), rect.height(), (rdr::U8 *)m_image->xim->data,
  52. m_image->xim->bytes_per_line * 8 / m_image->xim->bits_per_pixel);
  53. // Get initial screen image from the X display.
  54. m_image->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop);
  55. // PollingManager will detect changed pixels.
  56. m_poller = new PollingManager(dpy, getImage(), factory,
  57. m_offsetLeft, m_offsetTop);
  58. }
  59. XPixelBuffer::~XPixelBuffer()
  60. {
  61. delete m_poller;
  62. delete m_image;
  63. }
  64. void
  65. XPixelBuffer::grabRegion(const rfb::Region& region)
  66. {
  67. std::vector<Rect> rects;
  68. std::vector<Rect>::const_iterator i;
  69. region.get_rects(&rects);
  70. for (i = rects.begin(); i != rects.end(); i++) {
  71. grabRect(*i);
  72. }
  73. }