| OLD | NEW |
| (Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include <windows.h> |
| 12 |
| 13 #include <memory> |
| 14 |
| 15 #include "webrtc/modules/desktop_capture/screen_drawer.h" |
| 16 |
| 17 namespace webrtc { |
| 18 |
| 19 namespace { |
| 20 |
| 21 DesktopRect GetScreenRect() { |
| 22 HDC hdc = GetDC(NULL); |
| 23 DesktopRect rect = DesktopRect::MakeWH(GetDeviceCaps(hdc, HORZRES), |
| 24 GetDeviceCaps(hdc, VERTRES)); |
| 25 ReleaseDC(NULL, hdc); |
| 26 return rect; |
| 27 } |
| 28 |
| 29 HWND CreateDrawerWindow(DesktopRect rect) { |
| 30 HWND hwnd = CreateWindowA( |
| 31 "STATIC", "DrawerWindow", WS_POPUPWINDOW | WS_VISIBLE, rect.left(), |
| 32 rect.top(), rect.width(), rect.height(), NULL, NULL, NULL, NULL); |
| 33 SetForegroundWindow(hwnd); |
| 34 return hwnd; |
| 35 } |
| 36 |
| 37 // A ScreenDrawer implementation for Windows. |
| 38 class ScreenDrawerWin : public ScreenDrawer { |
| 39 public: |
| 40 ScreenDrawerWin(); |
| 41 ~ScreenDrawerWin() override; |
| 42 |
| 43 // ScreenDrawer interface. |
| 44 DesktopRect DrawableRegion() override; |
| 45 void DrawRectangle(DesktopRect rect, uint32_t rgba) override; |
| 46 void Clear() override; |
| 47 |
| 48 private: |
| 49 const DesktopRect rect_; |
| 50 HWND window_; |
| 51 HDC hdc_; |
| 52 }; |
| 53 |
| 54 ScreenDrawerWin::ScreenDrawerWin() |
| 55 : ScreenDrawer(), |
| 56 rect_(GetScreenRect()), |
| 57 window_(CreateDrawerWindow(rect_)), |
| 58 hdc_(GetWindowDC(window_)) { |
| 59 // We do not need to handle any messages for the |window_|, so disable Windows |
| 60 // process windows ghosting feature. |
| 61 DisableProcessWindowsGhosting(); |
| 62 } |
| 63 |
| 64 ScreenDrawerWin::~ScreenDrawerWin() { |
| 65 ReleaseDC(NULL, hdc_); |
| 66 DestroyWindow(window_); |
| 67 // Unfortunately there is no EnableProcessWindowsGhosting() API. |
| 68 } |
| 69 |
| 70 DesktopRect ScreenDrawerWin::DrawableRegion() { |
| 71 return rect_; |
| 72 } |
| 73 |
| 74 void ScreenDrawerWin::DrawRectangle(DesktopRect rect, uint32_t rgba) { |
| 75 int r = (rgba & 0xff00) >> 8; |
| 76 int g = (rgba & 0xff0000) >> 16; |
| 77 int b = (rgba & 0xff000000) >> 24; |
| 78 // Windows device context does not support Alpha. |
| 79 SelectObject(hdc_, GetStockObject(DC_PEN)); |
| 80 SelectObject(hdc_, GetStockObject(DC_BRUSH)); |
| 81 SetDCBrushColor(hdc_, RGB(r, g, b)); |
| 82 SetDCPenColor(hdc_, RGB(r, g, b)); |
| 83 Rectangle(hdc_, rect.left(), rect.top(), rect.right(), rect.bottom()); |
| 84 } |
| 85 |
| 86 void ScreenDrawerWin::Clear() { |
| 87 DrawRectangle(DrawableRegion(), 0); |
| 88 } |
| 89 |
| 90 } // namespace |
| 91 |
| 92 // static |
| 93 std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() { |
| 94 return std::unique_ptr<ScreenDrawer>(new ScreenDrawerWin()); |
| 95 } |
| 96 |
| 97 } // namespace webrtc |
| OLD | NEW |