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

Unified Diff: webrtc/modules/desktop_capture/screen_drawer_linux.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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/desktop_capture/screen_drawer_linux.cc
diff --git a/webrtc/modules/desktop_capture/screen_drawer_linux.cc b/webrtc/modules/desktop_capture/screen_drawer_linux.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7e28c42a64521f3a7fb2f2291a984ac15d45c134
--- /dev/null
+++ b/webrtc/modules/desktop_capture/screen_drawer_linux.cc
@@ -0,0 +1,111 @@
+/*
+ * 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 <memory>
+
+#include "webrtc/base/checks.h"
+#include "webrtc/modules/desktop_capture/screen_drawer.h"
+#include "webrtc/modules/desktop_capture/x11/shared_x_display.h"
+
+namespace webrtc {
+
+namespace {
+
+int XErrorHandler(Display* display, XErrorEvent* event) {
+ RTC_CHECK(false) << "XError";
+}
+
+int XIOErrorHandler(Display* display) {
+ RTC_CHECK(false) << "XIOError";
+}
+
+// A ScreenDrawer implementation for X11.
+class ScreenDrawerLinux : public ScreenDrawer {
+ public:
+ ScreenDrawerLinux();
+ ~ScreenDrawerLinux() override;
+
+ // ScreenDrawer interface.
+ DesktopRect DrawableRegion() override;
+ void DrawRectangle(DesktopRect rect, uint32_t rgba) override;
+
+ private:
+ rtc::scoped_refptr<SharedXDisplay> display_;
+ Screen* screen_;
+ int screen_num_;
+ DesktopRect rect_;
+ Window window_;
+ GC context_;
+ Colormap colormap_;
+};
+
+ScreenDrawerLinux::ScreenDrawerLinux() {
+ XSetErrorHandler(&XErrorHandler);
+ XSetIOErrorHandler(&XIOErrorHandler);
Sergey Ulanov 2016/08/15 21:41:09 I don't think these are useful, since the default
Hzj_jie 2016/08/15 23:47:18 Done.
+ display_ = SharedXDisplay::CreateDefault();
+ RTC_CHECK(display_.get());
+ screen_ = DefaultScreenOfDisplay(display_->display());
+ RTC_CHECK(screen_);
+ screen_num_ = DefaultScreen(display_->display());
+ rect_ = DesktopRect::MakeWH(screen_->width, screen_->height);
+ window_ = XCreateSimpleWindow(display_->display(),
+ RootWindow(display_->display(), screen_num_), 0,
+ 0, rect_.width(), rect_.height(), 0,
+ BlackPixel(display_->display(), screen_num_),
+ BlackPixel(display_->display(), screen_num_));
+ XSelectInput(display_->display(), window_, StructureNotifyMask);
+ XMapWindow(display_->display(), window_);
+ while (true) {
+ XEvent event;
+ XNextEvent(display_->display(), &event);
+ if (event.type == MapNotify) {
+ break;
+ }
+ }
+ XFlush(display_->display());
+ context_ = DefaultGC(display_->display(), screen_num_);
+ colormap_ = DefaultColormap(display_->display(), screen_num_);
+}
+
+ScreenDrawerLinux::~ScreenDrawerLinux() {
+ XUnmapWindow(display_->display(), window_);
+ XDestroyWindow(display_->display(), window_);
+}
+
+DesktopRect ScreenDrawerLinux::DrawableRegion() {
+ return rect_;
+}
+
+void ScreenDrawerLinux::DrawRectangle(DesktopRect rect, uint32_t rgba) {
+ int r = (rgba & 0xff00) >> 8;
+ int g = (rgba & 0xff0000) >> 16;
+ int b = (rgba & 0xff000000) >> 24;
+ // X11 does not support Alpha.
+ XColor color;
+ // X11 uses 16 bits for each primary color.
+ color.red = r * 256;
+ color.green = g * 256;
+ color.blue = b * 256;
+ color.flags = DoRed | DoGreen | DoBlue;
+ XAllocColor(display_->display(), colormap_, &color);
+ XSetForeground(display_->display(), context_, color.pixel);
+ XFillRectangle(display_->display(), window_, context_, rect.left(),
+ rect.top(), rect.width(), rect.height());
+ XFlush(display_->display());
+}
+
+} // namespace
+
+// static
+std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() {
+ return std::unique_ptr<ScreenDrawer>(new ScreenDrawerLinux());
+}
+
+} // namespace webrtc
« no previous file with comments | « webrtc/modules/desktop_capture/screen_drawer.cc ('k') | webrtc/modules/desktop_capture/screen_drawer_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698