OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 public: | 26 public: |
27 ScreenDrawerLockWin(); | 27 ScreenDrawerLockWin(); |
28 ~ScreenDrawerLockWin() override; | 28 ~ScreenDrawerLockWin() override; |
29 | 29 |
30 private: | 30 private: |
31 HANDLE mutex_; | 31 HANDLE mutex_; |
32 }; | 32 }; |
33 | 33 |
34 ScreenDrawerLockWin::ScreenDrawerLockWin() { | 34 ScreenDrawerLockWin::ScreenDrawerLockWin() { |
35 while (true) { | 35 while (true) { |
36 mutex_ = CreateMutex(NULL, FALSE, kMutexName); | 36 mutex_ = CreateMutex(nullptr, FALSE, kMutexName); |
37 if (GetLastError() != ERROR_ALREADY_EXISTS && mutex_ != NULL) { | 37 if (GetLastError() != ERROR_ALREADY_EXISTS && mutex_ != nullptr) { |
38 break; | 38 break; |
39 } else { | 39 } else { |
40 if (mutex_) { | 40 if (mutex_) { |
41 CloseHandle(mutex_); | 41 CloseHandle(mutex_); |
42 } | 42 } |
43 SleepMs(1000); | 43 SleepMs(1000); |
44 } | 44 } |
45 } | 45 } |
46 } | 46 } |
47 | 47 |
48 ScreenDrawerLockWin::~ScreenDrawerLockWin() { | 48 ScreenDrawerLockWin::~ScreenDrawerLockWin() { |
49 CloseHandle(mutex_); | 49 CloseHandle(mutex_); |
50 } | 50 } |
51 | 51 |
52 DesktopRect GetScreenRect() { | 52 DesktopRect GetScreenRect() { |
53 HDC hdc = GetDC(NULL); | 53 HDC hdc = GetDC(nullptr); |
54 DesktopRect rect = DesktopRect::MakeWH(GetDeviceCaps(hdc, HORZRES), | 54 DesktopRect rect = DesktopRect::MakeWH(GetDeviceCaps(hdc, HORZRES), |
55 GetDeviceCaps(hdc, VERTRES)); | 55 GetDeviceCaps(hdc, VERTRES)); |
56 ReleaseDC(NULL, hdc); | 56 ReleaseDC(nullptr, hdc); |
57 return rect; | 57 return rect; |
58 } | 58 } |
59 | 59 |
60 HWND CreateDrawerWindow(DesktopRect rect) { | 60 HWND CreateDrawerWindow(DesktopRect rect) { |
61 HWND hwnd = CreateWindowA( | 61 HWND hwnd = |
62 "STATIC", "DrawerWindow", WS_POPUPWINDOW | WS_VISIBLE, rect.left(), | 62 CreateWindowA("STATIC", "DrawerWindow", WS_POPUPWINDOW | WS_VISIBLE, |
63 rect.top(), rect.width(), rect.height(), NULL, NULL, NULL, NULL); | 63 rect.left(), rect.top(), rect.width(), rect.height(), |
| 64 nullptr, nullptr, nullptr, nullptr); |
64 SetForegroundWindow(hwnd); | 65 SetForegroundWindow(hwnd); |
65 return hwnd; | 66 return hwnd; |
66 } | 67 } |
67 | 68 |
68 COLORREF ColorToRef(RgbaColor color) { | 69 COLORREF ColorToRef(RgbaColor color) { |
69 // Windows device context does not support alpha. | 70 // Windows device context does not support alpha. |
70 return RGB(color.red, color.green, color.blue); | 71 return RGB(color.red, color.green, color.blue); |
71 } | 72 } |
72 | 73 |
73 // A ScreenDrawer implementation for Windows. | 74 // A ScreenDrawer implementation for Windows. |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 // from processing windows ghosting feature. | 109 // from processing windows ghosting feature. |
109 DisableProcessWindowsGhosting(); | 110 DisableProcessWindowsGhosting(); |
110 | 111 |
111 // Always use stock pen (DC_PEN) and brush (DC_BRUSH). | 112 // Always use stock pen (DC_PEN) and brush (DC_BRUSH). |
112 SelectObject(hdc_, GetStockObject(DC_PEN)); | 113 SelectObject(hdc_, GetStockObject(DC_PEN)); |
113 SelectObject(hdc_, GetStockObject(DC_BRUSH)); | 114 SelectObject(hdc_, GetStockObject(DC_BRUSH)); |
114 BringToFront(); | 115 BringToFront(); |
115 } | 116 } |
116 | 117 |
117 ScreenDrawerWin::~ScreenDrawerWin() { | 118 ScreenDrawerWin::~ScreenDrawerWin() { |
118 ReleaseDC(NULL, hdc_); | 119 ReleaseDC(nullptr, hdc_); |
119 DestroyWindow(window_); | 120 DestroyWindow(window_); |
120 // Unfortunately there is no EnableProcessWindowsGhosting() API. | 121 // Unfortunately there is no EnableProcessWindowsGhosting() API. |
121 } | 122 } |
122 | 123 |
123 DesktopRect ScreenDrawerWin::DrawableRegion() { | 124 DesktopRect ScreenDrawerWin::DrawableRegion() { |
124 return rect_; | 125 return rect_; |
125 } | 126 } |
126 | 127 |
127 void ScreenDrawerWin::DrawRectangle(DesktopRect rect, RgbaColor color) { | 128 void ScreenDrawerWin::DrawRectangle(DesktopRect rect, RgbaColor color) { |
128 if (rect.width() == 1 && rect.height() == 1) { | 129 if (rect.width() == 1 && rect.height() == 1) { |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 std::unique_ptr<ScreenDrawerLock> ScreenDrawerLock::Create() { | 196 std::unique_ptr<ScreenDrawerLock> ScreenDrawerLock::Create() { |
196 return std::unique_ptr<ScreenDrawerLock>(new ScreenDrawerLockWin()); | 197 return std::unique_ptr<ScreenDrawerLock>(new ScreenDrawerLockWin()); |
197 } | 198 } |
198 | 199 |
199 // static | 200 // static |
200 std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() { | 201 std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() { |
201 return std::unique_ptr<ScreenDrawer>(new ScreenDrawerWin()); | 202 return std::unique_ptr<ScreenDrawer>(new ScreenDrawerWin()); |
202 } | 203 } |
203 | 204 |
204 } // namespace webrtc | 205 } // namespace webrtc |
OLD | NEW |