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

Side by Side 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: 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 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 <memory>
12
13 #include "webrtc/base/checks.h"
14 #include "webrtc/modules/desktop_capture/screen_drawer.h"
15 #include "webrtc/modules/desktop_capture/x11/shared_x_display.h"
16
17 namespace webrtc {
18
19 namespace {
20
21 // A ScreenDrawer implementation for X11.
22 class ScreenDrawerLinux : public ScreenDrawer {
23 public:
24 ScreenDrawerLinux();
25 ~ScreenDrawerLinux() override;
26
27 // ScreenDrawer interface.
28 DesktopRect DrawableRegion() override;
29 void DrawRectangle(DesktopRect rect, uint32_t rgba) override;
30 void Clear() override;
31
32 private:
33 rtc::scoped_refptr<SharedXDisplay> display_;
34 Screen* screen_;
35 int screen_num_;
36 DesktopRect rect_;
37 Window window_;
38 GC context_;
39 Colormap colormap_;
40 };
41
42 ScreenDrawerLinux::ScreenDrawerLinux() {
43 display_ = SharedXDisplay::CreateDefault();
44 RTC_CHECK(display_.get());
45 screen_ = DefaultScreenOfDisplay(display_->display());
46 RTC_CHECK(screen_);
47 screen_num_ = DefaultScreen(display_->display());
48 rect_ = DesktopRect::MakeWH(screen_->width, screen_->height);
49 window_ = XCreateSimpleWindow(display_->display(),
50 RootWindow(display_->display(), screen_num_), 0,
51 0, rect_.width(), rect_.height(), 0,
52 BlackPixel(display_->display(), screen_num_),
53 BlackPixel(display_->display(), screen_num_));
54 XSelectInput(display_->display(), window_, StructureNotifyMask);
55 XMapWindow(display_->display(), window_);
56 while (true) {
57 XEvent event;
58 XNextEvent(display_->display(), &event);
59 if (event.type == MapNotify) {
60 break;
61 }
62 }
63 XFlush(display_->display());
64 context_ = DefaultGC(display_->display(), screen_num_);
65 colormap_ = DefaultColormap(display_->display(), screen_num_);
66 }
67
68 ScreenDrawerLinux::~ScreenDrawerLinux() {
69 XUnmapWindow(display_->display(), window_);
70 XDestroyWindow(display_->display(), window_);
71 }
72
73 DesktopRect ScreenDrawerLinux::DrawableRegion() {
74 return rect_;
75 }
76
77 void ScreenDrawerLinux::DrawRectangle(DesktopRect rect, uint32_t rgba) {
78 int r = (rgba & 0xff00) >> 8;
79 int g = (rgba & 0xff0000) >> 16;
80 int b = (rgba & 0xff000000) >> 24;
81 // X11 does not support Alpha.
82 XColor color;
83 // X11 uses 16 bits for each primary color.
84 color.red = r * 256;
85 color.green = g * 256;
86 color.blue = b * 256;
87 color.flags = DoRed | DoGreen | DoBlue;
88 XAllocColor(display_->display(), colormap_, &color);
89 XSetForeground(display_->display(), context_, color.pixel);
90 XFillRectangle(display_->display(), window_, context_, rect.left(),
91 rect.top(), rect.width(), rect.height());
92 XFlush(display_->display());
93 }
94
95 void ScreenDrawerLinux::Clear() {
96 DrawRectangle(DrawableRegion(), 0);
97 }
98
99 } // namespace
100
101 // static
102 std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() {
103 return std::unique_ptr<ScreenDrawer>(new ScreenDrawerLinux());
104 }
105
106 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/desktop_capture/screen_drawer.h ('k') | webrtc/modules/desktop_capture/screen_drawer_mac.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698