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

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: 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 side-by-side diff with in-line comments
Download patch
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..d81e4125bcae5ebe86e3b3cad38910e604608011
--- /dev/null
+++ b/webrtc/modules/desktop_capture/screen_drawer_win.cc
@@ -0,0 +1,75 @@
+/*
+ * 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 "webrtc/modules/desktop_capture/screen_drawer_win.h"
+
+#include <memory>
+
+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;
+}
+
+} // namespace
+
+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) {
+ const char* rgba_array = reinterpret_cast<const char*>(&rgba);
+ int r = rgba_array[0];
+ int g = rgba_array[1];
+ int b = rgba_array[2];
+ // 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());
+}
+
+// static
+std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() {
+ return std::unique_ptr<ScreenDrawer>(new ScreenDrawerWin());
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698