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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. int err = GetLastError();
  50. throw rdr::SystemException(_("unable to create DIB section"), err);
  51. }
  52. }
  53. Win32PixelBuffer::~Win32PixelBuffer()
  54. {
  55. DeleteObject(bitmap);
  56. }
  57. void Win32PixelBuffer::draw(int src_x, int src_y, int x, int y, int w, int h)
  58. {
  59. HDC dc;
  60. dc = CreateCompatibleDC(fl_gc);
  61. if (!dc)
  62. throw rdr::SystemException(_("CreateCompatibleDC failed"), GetLastError());
  63. if (!SelectObject(dc, bitmap))
  64. throw rdr::SystemException(_("SelectObject failed"), GetLastError());
  65. if (!BitBlt(fl_gc, x, y, w, h, dc, src_x, src_y, SRCCOPY)) {
  66. // If the desktop we're rendering to is inactive (like when the screen
  67. // is locked or the UAC is active), then GDI calls will randomly fail.
  68. // This is completely undocumented so we have no idea how best to deal
  69. // with it. For now, we've only seen this error and for this function
  70. // so only ignore this combination.
  71. if (GetLastError() != ERROR_INVALID_HANDLE)
  72. throw rdr::SystemException(_("BitBlt failed"), GetLastError());
  73. }
  74. DeleteDC(dc);
  75. }