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

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: Move ScreenDrawer::Clear to cc file 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 <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
47 private:
48 const DesktopRect rect_;
49 HWND window_;
50 HDC hdc_;
51 };
52
53 ScreenDrawerWin::ScreenDrawerWin()
54 : ScreenDrawer(),
55 rect_(GetScreenRect()),
56 window_(CreateDrawerWindow(rect_)),
57 hdc_(GetWindowDC(window_)) {
58 // We do not need to handle any messages for the |window_|, so disable Windows
59 // process windows ghosting feature.
60 DisableProcessWindowsGhosting();
61 }
62
63 ScreenDrawerWin::~ScreenDrawerWin() {
64 ReleaseDC(NULL, hdc_);
65 DestroyWindow(window_);
66 // Unfortunately there is no EnableProcessWindowsGhosting() API.
67 }
68
69 DesktopRect ScreenDrawerWin::DrawableRegion() {
70 return rect_;
71 }
72
73 void ScreenDrawerWin::DrawRectangle(DesktopRect rect, uint32_t rgba) {
74 int r = (rgba & 0xff00) >> 8;
75 int g = (rgba & 0xff0000) >> 16;
76 int b = (rgba & 0xff000000) >> 24;
77 // Windows device context does not support Alpha.
78 SelectObject(hdc_, GetStockObject(DC_PEN));
79 SelectObject(hdc_, GetStockObject(DC_BRUSH));
80 SetDCBrushColor(hdc_, RGB(r, g, b));
81 SetDCPenColor(hdc_, RGB(r, g, b));
82 Rectangle(hdc_, rect.left(), rect.top(), rect.right(), rect.bottom());
83 }
84
85 } // namespace
86
87 // static
88 std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() {
89 return std::unique_ptr<ScreenDrawer>(new ScreenDrawerWin());
90 }
91
92 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698