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

Unified 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: Lint error, inconsistent local / online lint results 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/modules/desktop_capture/screen_drawer_unittest.cc ('k') | webrtc/modules/modules.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/modules/desktop_capture/screen_drawer_win.cc
diff --git a/webrtc/modules/desktop_capture/screen_drawer_win.cc b/webrtc/modules/desktop_capture/screen_drawer_win.cc
new file mode 100644
index 0000000000000000000000000000000000000000..061a40539e1cb72091347bf1b743b2315982e99c
--- /dev/null
+++ b/webrtc/modules/desktop_capture/screen_drawer_win.cc
@@ -0,0 +1,97 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include <windows.h>
+
+#include <memory>
+
+#include "webrtc/modules/desktop_capture/screen_drawer.h"
+
+namespace webrtc {
+
+namespace {
+
+DesktopRect GetScreenRect() {
+ HDC hdc = GetDC(NULL);
+ DesktopRect rect = DesktopRect::MakeWH(GetDeviceCaps(hdc, HORZRES),
+ GetDeviceCaps(hdc, VERTRES));
+ ReleaseDC(NULL, hdc);
+ return rect;
+}
+
+HWND CreateDrawerWindow(DesktopRect rect) {
+ HWND hwnd = CreateWindowA(
+ "STATIC", "DrawerWindow", WS_POPUPWINDOW | WS_VISIBLE, rect.left(),
+ rect.top(), rect.width(), rect.height(), NULL, NULL, NULL, NULL);
+ SetForegroundWindow(hwnd);
+ return hwnd;
+}
+
+// A ScreenDrawer implementation for Windows.
+class ScreenDrawerWin : public ScreenDrawer {
+ public:
+ ScreenDrawerWin();
+ ~ScreenDrawerWin() override;
+
+ // ScreenDrawer interface.
+ DesktopRect DrawableRegion() override;
+ void DrawRectangle(DesktopRect rect, uint32_t rgba) override;
+ void Clear() override;
+
+ private:
+ const DesktopRect rect_;
+ HWND window_;
+ HDC hdc_;
+};
+
+ScreenDrawerWin::ScreenDrawerWin()
+ : ScreenDrawer(),
+ rect_(GetScreenRect()),
+ window_(CreateDrawerWindow(rect_)),
+ hdc_(GetWindowDC(window_)) {
+ // We do not need to handle any messages for the |window_|, so disable Windows
+ // process windows ghosting feature.
+ DisableProcessWindowsGhosting();
+}
+
+ScreenDrawerWin::~ScreenDrawerWin() {
+ ReleaseDC(NULL, hdc_);
+ DestroyWindow(window_);
+ // Unfortunately there is no EnableProcessWindowsGhosting() API.
+}
+
+DesktopRect ScreenDrawerWin::DrawableRegion() {
+ return rect_;
+}
+
+void ScreenDrawerWin::DrawRectangle(DesktopRect rect, uint32_t rgba) {
+ int r = (rgba & 0xff00) >> 8;
+ int g = (rgba & 0xff0000) >> 16;
+ int b = (rgba & 0xff000000) >> 24;
+ // Windows device context does not support Alpha.
+ SelectObject(hdc_, GetStockObject(DC_PEN));
+ SelectObject(hdc_, GetStockObject(DC_BRUSH));
+ SetDCBrushColor(hdc_, RGB(r, g, b));
+ SetDCPenColor(hdc_, RGB(r, g, b));
+ Rectangle(hdc_, rect.left(), rect.top(), rect.right(), rect.bottom());
+}
+
+void ScreenDrawerWin::Clear() {
+ DrawRectangle(DrawableRegion(), 0);
+}
+
+} // namespace
+
+// static
+std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() {
+ return std::unique_ptr<ScreenDrawer>(new ScreenDrawerWin());
+}
+
+} // namespace webrtc
« no previous file with comments | « webrtc/modules/desktop_capture/screen_drawer_unittest.cc ('k') | webrtc/modules/modules.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698