選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

XPixelBuffer.cxx 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #include <vector>
  23. #include <rfb/Region.h>
  24. #include <X11/Xlib.h>
  25. #include <x0vncserver/XPixelBuffer.h>
  26. using namespace rfb;
  27. XPixelBuffer::XPixelBuffer(Display *dpy, ImageFactory &factory,
  28. const Rect &rect)
  29. : FullFramePixelBuffer(),
  30. m_poller(0),
  31. m_dpy(dpy),
  32. m_image(factory.newImage(dpy, rect.width(), rect.height())),
  33. m_offsetLeft(rect.tl.x),
  34. m_offsetTop(rect.tl.y)
  35. {
  36. // Fill in the PixelFormat structure of the parent class.
  37. format = PixelFormat(m_image->xim->bits_per_pixel,
  38. m_image->xim->depth,
  39. (m_image->xim->byte_order == MSBFirst),
  40. true,
  41. m_image->xim->red_mask >> (ffs(m_image->xim->red_mask) - 1),
  42. m_image->xim->green_mask >> (ffs(m_image->xim->green_mask) - 1),
  43. m_image->xim->blue_mask >> (ffs(m_image->xim->blue_mask) - 1),
  44. ffs(m_image->xim->red_mask) - 1,
  45. ffs(m_image->xim->green_mask) - 1,
  46. ffs(m_image->xim->blue_mask) - 1);
  47. // Set up the remaining data of the parent class.
  48. width_ = rect.width();
  49. height_ = rect.height();
  50. data = (rdr::U8 *)m_image->xim->data;
  51. // Calculate the distance in pixels between two subsequent scan
  52. // lines of the framebuffer. This may differ from image width.
  53. stride = m_image->xim->bytes_per_line * 8 / m_image->xim->bits_per_pixel;
  54. // Get initial screen image from the X display.
  55. m_image->get(DefaultRootWindow(m_dpy), m_offsetLeft, m_offsetTop);
  56. // PollingManager will detect changed pixels.
  57. m_poller = new PollingManager(dpy, getImage(), factory,
  58. m_offsetLeft, m_offsetTop);
  59. }
  60. XPixelBuffer::~XPixelBuffer()
  61. {
  62. delete m_poller;
  63. delete m_image;
  64. }
  65. void
  66. XPixelBuffer::grabRegion(const rfb::Region& region)
  67. {
  68. std::vector<Rect> rects;
  69. std::vector<Rect>::const_iterator i;
  70. region.get_rects(&rects);
  71. for (i = rects.begin(); i != rects.end(); i++) {
  72. grabRect(*i);
  73. }
  74. }