Pierre Ossman | b4cb876 | 2011-06-13 13:24:29 +0000 | [diff] [blame^] | 1 | /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved. |
| 2 | * Copyright 2011 Pierre Ossman <ossman@cendio.se> 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 | #include <assert.h> |
| 21 | #include <stdlib.h> |
| 22 | |
| 23 | #include <windows.h> |
| 24 | |
| 25 | #include <FL/x.H> |
| 26 | |
| 27 | #include <rfb/LogWriter.h> |
| 28 | #include <rfb/Exception.h> |
| 29 | |
| 30 | #include "Win32PixelBuffer.h" |
| 31 | |
| 32 | using namespace rfb; |
| 33 | |
| 34 | static rfb::LogWriter vlog("PlatformPixelBuffer"); |
| 35 | |
| 36 | struct BitmapInfo { |
| 37 | BITMAPINFOHEADER bmiHeader; |
| 38 | union { |
| 39 | struct { |
| 40 | DWORD red; |
| 41 | DWORD green; |
| 42 | DWORD blue; |
| 43 | } mask; |
| 44 | RGBQUAD color[256]; |
| 45 | }; |
| 46 | }; |
| 47 | |
| 48 | PlatformPixelBuffer::PlatformPixelBuffer(int width, int height) : |
| 49 | FullFramePixelBuffer(rfb::PixelFormat(32, 24, false, true, |
| 50 | 255, 255, 255, 16, 8, 0), |
| 51 | width, height, NULL, NULL), |
| 52 | bitmap(NULL) |
| 53 | { |
| 54 | BITMAPINFOHEADER bih; |
| 55 | |
| 56 | memset(&bih, 0, sizeof(bih)); |
| 57 | |
| 58 | bih.biSize = sizeof(BITMAPINFOHEADER); |
| 59 | bih.biBitCount = getPF().bpp; |
| 60 | bih.biSizeImage = (getPF().bpp / 8) * width * height; |
| 61 | bih.biPlanes = 1; |
| 62 | bih.biWidth = width; |
| 63 | bih.biHeight = -height; // Negative to get top-down |
| 64 | bih.biCompression = BI_RGB; |
| 65 | |
| 66 | bitmap = CreateDIBSection(NULL, (BITMAPINFO*)&bih, |
| 67 | DIB_RGB_COLORS, (void**)&data, NULL, 0); |
| 68 | if (!bitmap) { |
| 69 | int err = GetLastError(); |
| 70 | throw rdr::SystemException("unable to create DIB section", err); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | |
| 75 | PlatformPixelBuffer::~PlatformPixelBuffer() |
| 76 | { |
| 77 | DeleteObject(bitmap); |
| 78 | } |
| 79 | |
| 80 | |
| 81 | void PlatformPixelBuffer::draw(int src_x, int src_y, int x, int y, int w, int h) |
| 82 | { |
| 83 | HDC dc; |
| 84 | |
| 85 | dc = CreateCompatibleDC(fl_gc); |
| 86 | if (!dc) |
| 87 | throw rdr::SystemException("CreateCompatibleDC failed", GetLastError()); |
| 88 | |
| 89 | if (!SelectObject(dc, bitmap)) |
| 90 | throw rdr::SystemException("SelectObject failed", GetLastError()); |
| 91 | |
| 92 | if (!BitBlt(fl_gc, x, y, w, h, dc, src_x, src_y, SRCCOPY)) |
| 93 | throw rdr::SystemException("BitBlt failed", GetLastError()); |
| 94 | |
| 95 | DeleteDC(dc); |
| 96 | } |