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.

Win32PixelBuffer.cxx 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2011-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. #ifdef HAVE_CONFIG_H
  20. #include <config.h>
  21. #endif
  22. #include <stdlib.h>
  23. #include <windows.h>
  24. #include <FL/x.H>
  25. #include <rfb/LogWriter.h>
  26. #include <rfb/Exception.h>
  27. #include "i18n.h"
  28. #include "Win32PixelBuffer.h"
  29. using namespace rfb;
  30. static rfb::LogWriter vlog("Win32PixelBuffer");
  31. Win32PixelBuffer::Win32PixelBuffer(int width, int height) :
  32. PlatformPixelBuffer(rfb::PixelFormat(32, 24, false, true,
  33. 255, 255, 255, 16, 8, 0),
  34. width, height, NULL, width),
  35. bitmap(NULL)
  36. {
  37. BITMAPINFOHEADER bih;
  38. memset(&bih, 0, sizeof(bih));
  39. bih.biSize = sizeof(BITMAPINFOHEADER);
  40. bih.biBitCount = getPF().bpp;
  41. bih.biSizeImage = (getPF().bpp / 8) * width * height;
  42. bih.biPlanes = 1;
  43. bih.biWidth = width;
  44. bih.biHeight = -height; // Negative to get top-down
  45. bih.biCompression = BI_RGB;
  46. bitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bih,
  47. DIB_RGB_COLORS, (void**)&data, NULL, 0);
  48. if (!bitmap)
  49. throw rdr::SystemException("CreateDIBSection", GetLastError());
  50. }
  51. Win32PixelBuffer::~Win32PixelBuffer()
  52. {
  53. DeleteObject(bitmap);
  54. }
  55. void Win32PixelBuffer::draw(int src_x, int src_y, int x, int y, int w, int h)
  56. {
  57. HDC dc;
  58. dc = CreateCompatibleDC(fl_gc);
  59. if (!dc)
  60. throw rdr::SystemException("CreateCompatibleDC", GetLastError());
  61. if (!SelectObject(dc, bitmap))
  62. throw rdr::SystemException("SelectObject", GetLastError());
  63. if (!BitBlt(fl_gc, x, y, w, h, dc, src_x, src_y, SRCCOPY)) {
  64. // If the desktop we're rendering to is inactive (like when the screen
  65. // is locked or the UAC is active), then GDI calls will randomly fail.
  66. // This is completely undocumented so we have no idea how best to deal
  67. // with it. For now, we've only seen this error and for this function
  68. // so only ignore this combination.
  69. if (GetLastError() != ERROR_INVALID_HANDLE)
  70. throw rdr::SystemException("BitBlt", GetLastError());
  71. }
  72. DeleteDC(dc);
  73. }