Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(756)

Side by Side Diff: webrtc/modules/desktop_capture/screen_drawer_win.cc

Issue 2210443002: [WebRTC] Implement Windows ScreenDrawer to test ScreenCapturer* (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Implement ScreenDrawer for X11 Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "webrtc/modules/desktop_capture/screen_drawer_win.h"
12
13 #include <memory>
14
15 namespace webrtc {
16
17 namespace {
18
19 DesktopRect GetScreenRect() {
20 HDC hdc = GetDC(NULL);
21 DesktopRect rect = DesktopRect::MakeWH(GetDeviceCaps(hdc, HORZRES),
22 GetDeviceCaps(hdc, VERTRES));
23 ReleaseDC(NULL, hdc);
24 return rect;
25 }
26
27 HWND CreateDrawerWindow(DesktopRect rect) {
28 HWND hwnd = CreateWindowA(
29 "STATIC", "DrawerWindow", WS_POPUPWINDOW | WS_VISIBLE, rect.left(),
30 rect.top(), rect.width(), rect.height(), NULL, NULL, NULL, NULL);
31 SetForegroundWindow(hwnd);
32 return hwnd;
33 }
34
35 } // namespace
36
37 ScreenDrawerWin::ScreenDrawerWin()
38 : ScreenDrawer(),
39 rect_(GetScreenRect()),
40 window_(CreateDrawerWindow(rect_)),
41 hdc_(GetWindowDC(window_)) {
42 // We do not need to handle any messages for the |window_|, so disable Windows
43 // process windows ghosting feature.
44 DisableProcessWindowsGhosting();
45 }
46
47 ScreenDrawerWin::~ScreenDrawerWin() {
48 ReleaseDC(NULL, hdc_);
49 DestroyWindow(window_);
50 // Unfortunately there is no EnableProcessWindowsGhosting() API.
51 }
52
53 DesktopRect ScreenDrawerWin::DrawableRegion() {
54 return rect_;
55 }
56
57 void ScreenDrawerWin::DrawRectangle(DesktopRect rect, uint32_t rgba) {
58 const char* rgba_array = reinterpret_cast<const char*>(&rgba);
59 int r = rgba_array[0];
60 int g = rgba_array[1];
61 int b = rgba_array[2];
62 // Windows device context does not support Alpha.
63 SelectObject(hdc_, GetStockObject(DC_PEN));
64 SelectObject(hdc_, GetStockObject(DC_BRUSH));
65 SetDCBrushColor(hdc_, RGB(r, g, b));
66 SetDCPenColor(hdc_, RGB(r, g, b));
67 Rectangle(hdc_, rect.left(), rect.top(), rect.right(), rect.bottom());
68 }
69
70 // static
71 std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() {
72 return std::unique_ptr<ScreenDrawer>(new ScreenDrawerWin());
73 }
74
75 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698