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

Side by Side Diff: webrtc/modules/desktop_capture/screen_drawer_linux.cc

Issue 2268093002: [WebRTC] A real ScreenCapturer test (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Resolve review comments Created 4 years, 3 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
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <memory> 11 #include <memory>
12 12
13 #include "webrtc/base/checks.h" 13 #include "webrtc/base/checks.h"
14 #include "webrtc/modules/desktop_capture/screen_drawer.h" 14 #include "webrtc/modules/desktop_capture/screen_drawer.h"
15 #include "webrtc/modules/desktop_capture/x11/shared_x_display.h" 15 #include "webrtc/modules/desktop_capture/x11/shared_x_display.h"
16 #include "webrtc/system_wrappers/include/sleep.h"
16 17
17 namespace webrtc { 18 namespace webrtc {
18 19
19 namespace { 20 namespace {
20 21
21 // A ScreenDrawer implementation for X11. 22 // A ScreenDrawer implementation for X11.
22 class ScreenDrawerLinux : public ScreenDrawer { 23 class ScreenDrawerLinux : public ScreenDrawer {
23 public: 24 public:
24 ScreenDrawerLinux(); 25 ScreenDrawerLinux();
25 ~ScreenDrawerLinux() override; 26 ~ScreenDrawerLinux() override;
26 27
27 // ScreenDrawer interface. 28 // ScreenDrawer interface.
28 DesktopRect DrawableRegion() override; 29 DesktopRect DrawableRegion() override;
29 void DrawRectangle(DesktopRect rect, uint32_t rgba) override; 30 void DrawRectangle(DesktopRect rect, Color color) override;
30 void Clear() override; 31 void Clear() override;
32 void WaitForPendingPaintings() override;
31 33
32 private: 34 private:
33 rtc::scoped_refptr<SharedXDisplay> display_; 35 rtc::scoped_refptr<SharedXDisplay> display_;
34 Screen* screen_;
35 int screen_num_; 36 int screen_num_;
36 DesktopRect rect_; 37 DesktopRect rect_;
37 Window window_; 38 Window window_;
38 GC context_; 39 GC context_;
39 Colormap colormap_; 40 Colormap colormap_;
40 }; 41 };
41 42
42 ScreenDrawerLinux::ScreenDrawerLinux() { 43 ScreenDrawerLinux::ScreenDrawerLinux() {
43 display_ = SharedXDisplay::CreateDefault(); 44 display_ = SharedXDisplay::CreateDefault();
44 RTC_CHECK(display_.get()); 45 RTC_CHECK(display_.get());
45 screen_ = DefaultScreenOfDisplay(display_->display());
46 RTC_CHECK(screen_);
47 screen_num_ = DefaultScreen(display_->display()); 46 screen_num_ = DefaultScreen(display_->display());
48 rect_ = DesktopRect::MakeWH(screen_->width, screen_->height); 47 XWindowAttributes root_attributes;
49 window_ = XCreateSimpleWindow(display_->display(), 48 if (!XGetWindowAttributes(display_->display(),
50 RootWindow(display_->display(), screen_num_), 0, 49 RootWindow(display_->display(), screen_num_),
51 0, rect_.width(), rect_.height(), 0, 50 &root_attributes)) {
52 BlackPixel(display_->display(), screen_num_), 51 RTC_DCHECK(false) << "Failed to get root window size.";
53 BlackPixel(display_->display(), screen_num_)); 52 }
53 window_ = XCreateSimpleWindow(
54 display_->display(), RootWindow(display_->display(), screen_num_), 0, 0,
55 root_attributes.width, root_attributes.height, 0,
56 BlackPixel(display_->display(), screen_num_),
57 BlackPixel(display_->display(), screen_num_));
54 XSelectInput(display_->display(), window_, StructureNotifyMask); 58 XSelectInput(display_->display(), window_, StructureNotifyMask);
55 XMapWindow(display_->display(), window_); 59 XMapWindow(display_->display(), window_);
56 while (true) { 60 while (true) {
57 XEvent event; 61 XEvent event;
58 XNextEvent(display_->display(), &event); 62 XNextEvent(display_->display(), &event);
59 if (event.type == MapNotify) { 63 if (event.type == MapNotify) {
60 break; 64 break;
61 } 65 }
62 } 66 }
63 XFlush(display_->display()); 67 XFlush(display_->display());
68 Window child;
69 int x, y;
70 if (!XTranslateCoordinates(display_->display(), window_,
71 RootWindow(display_->display(), screen_num_), 0, 0,
72 &x, &y, &child)) {
73 RTC_DCHECK(false) << "Failed to get window position.";
74 }
75 // In two monitor system, if this window is on the first monitor, part of the
76 // DrawableRegion() may be covered by another window.
Jamie 2016/08/26 22:29:10 I don't understand this comment. If you're explain
Hzj_jie 2016/08/29 21:57:28 Not really, AFAICT, this comment is for unity only
Jamie 2016/08/31 17:39:39 If I'm understanding the code correctly, I think t
Hzj_jie 2016/08/31 21:22:39 No, the size of window does not need to be adjuste
77 rect_ = DesktopRect::MakeLTRB(x, y, root_attributes.width,
78 root_attributes.height);
Jamie 2016/08/26 22:29:10 I think you need to add x and y to width and heigh
Hzj_jie 2016/08/29 21:57:28 The explanation is same as the one above. i.e. roo
64 context_ = DefaultGC(display_->display(), screen_num_); 79 context_ = DefaultGC(display_->display(), screen_num_);
65 colormap_ = DefaultColormap(display_->display(), screen_num_); 80 colormap_ = DefaultColormap(display_->display(), screen_num_);
66 } 81 }
67 82
68 ScreenDrawerLinux::~ScreenDrawerLinux() { 83 ScreenDrawerLinux::~ScreenDrawerLinux() {
69 XUnmapWindow(display_->display(), window_); 84 XUnmapWindow(display_->display(), window_);
70 XDestroyWindow(display_->display(), window_); 85 XDestroyWindow(display_->display(), window_);
71 } 86 }
72 87
73 DesktopRect ScreenDrawerLinux::DrawableRegion() { 88 DesktopRect ScreenDrawerLinux::DrawableRegion() {
74 return rect_; 89 return rect_;
75 } 90 }
76 91
77 void ScreenDrawerLinux::DrawRectangle(DesktopRect rect, uint32_t rgba) { 92 void ScreenDrawerLinux::DrawRectangle(DesktopRect rect, Color color) {
78 int r = (rgba & 0xff00) >> 8; 93 XColor xcolor;
79 int g = (rgba & 0xff0000) >> 16;
80 int b = (rgba & 0xff000000) >> 24;
81 // X11 does not support Alpha. 94 // X11 does not support Alpha.
82 XColor color;
83 // X11 uses 16 bits for each primary color. 95 // X11 uses 16 bits for each primary color.
84 color.red = r * 256; 96 xcolor.red = color.red() * 256 + color.red();
85 color.green = g * 256; 97 xcolor.green = color.green() * 256 + color.green();
86 color.blue = b * 256; 98 xcolor.blue = color.blue() * 256 + color.blue();
87 color.flags = DoRed | DoGreen | DoBlue; 99 xcolor.flags = DoRed | DoGreen | DoBlue;
88 XAllocColor(display_->display(), colormap_, &color); 100 XAllocColor(display_->display(), colormap_, &xcolor);
89 XSetForeground(display_->display(), context_, color.pixel); 101 XSetForeground(display_->display(), context_, xcolor.pixel);
90 XFillRectangle(display_->display(), window_, context_, rect.left(), 102 XFillRectangle(display_->display(), window_, context_, rect.left(),
91 rect.top(), rect.width(), rect.height()); 103 rect.top(), rect.width(), rect.height());
92 XFlush(display_->display()); 104 XFlush(display_->display());
93 } 105 }
94 106
95 void ScreenDrawerLinux::Clear() { 107 void ScreenDrawerLinux::Clear() {
96 DrawRectangle(DrawableRegion(), 0); 108 DesktopRect rect =
109 DesktopRect::MakeWH(DrawableRegion().width(), DrawableRegion().height());
110 DrawRectangle(rect, Color::FromBGR(0));
Jamie 2016/08/26 22:29:10 I think this method is simpler (doesn't need to be
Hzj_jie 2016/08/29 21:57:28 Done.
111 }
112
113 // TODO(zijiehe): Find the right signal from X11 to indicate the finish of all
114 // pending paintings.
115 void ScreenDrawerLinux::WaitForPendingPaintings() {
116 SleepMs(50);
97 } 117 }
98 118
99 } // namespace 119 } // namespace
100 120
101 // static 121 // static
102 std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() { 122 std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() {
103 return std::unique_ptr<ScreenDrawer>(new ScreenDrawerLinux()); 123 if (SharedXDisplay::CreateDefault().get()) {
Jamie 2016/08/26 22:29:10 What is this needed for? Does it belong in this CL
Hzj_jie 2016/08/29 21:57:28 Before this change, this function does not use in
124 return std::unique_ptr<ScreenDrawer>(new ScreenDrawerLinux());
125 } else {
126 return nullptr;
127 }
104 } 128 }
105 129
106 } // namespace webrtc 130 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698