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

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: 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, uint32_t bgra) override;
30 void Clear() override; 31 void WaitForPendingPaintings() override;
31 32
32 private: 33 private:
33 rtc::scoped_refptr<SharedXDisplay> display_; 34 rtc::scoped_refptr<SharedXDisplay> display_;
34 Screen* screen_; 35 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 };
(...skipping 26 matching lines...) Expand all
67 68
68 ScreenDrawerLinux::~ScreenDrawerLinux() { 69 ScreenDrawerLinux::~ScreenDrawerLinux() {
69 XUnmapWindow(display_->display(), window_); 70 XUnmapWindow(display_->display(), window_);
70 XDestroyWindow(display_->display(), window_); 71 XDestroyWindow(display_->display(), window_);
71 } 72 }
72 73
73 DesktopRect ScreenDrawerLinux::DrawableRegion() { 74 DesktopRect ScreenDrawerLinux::DrawableRegion() {
74 return rect_; 75 return rect_;
75 } 76 }
76 77
77 void ScreenDrawerLinux::DrawRectangle(DesktopRect rect, uint32_t rgba) { 78 void ScreenDrawerLinux::DrawRectangle(DesktopRect rect, uint32_t bgra) {
78 int r = (rgba & 0xff00) >> 8; 79 int b = (bgra & 0xff000000) >> 24;
79 int g = (rgba & 0xff0000) >> 16; 80 int g = (bgra & 0xff0000) >> 16;
80 int b = (rgba & 0xff000000) >> 24; 81 int r = (bgra & 0xff00) >> 8;
81 // X11 does not support Alpha. 82 // X11 does not support Alpha.
82 XColor color; 83 XColor color;
83 // X11 uses 16 bits for each primary color. 84 // X11 uses 16 bits for each primary color.
84 color.red = r * 256; 85 color.red = r * 256 + r;
85 color.green = g * 256; 86 color.green = g * 256 + g;
86 color.blue = b * 256; 87 color.blue = b * 256 + b;
87 color.flags = DoRed | DoGreen | DoBlue; 88 color.flags = DoRed | DoGreen | DoBlue;
88 XAllocColor(display_->display(), colormap_, &color); 89 XAllocColor(display_->display(), colormap_, &color);
89 XSetForeground(display_->display(), context_, color.pixel); 90 XSetForeground(display_->display(), context_, color.pixel);
90 XFillRectangle(display_->display(), window_, context_, rect.left(), 91 XFillRectangle(display_->display(), window_, context_, rect.left(),
91 rect.top(), rect.width(), rect.height()); 92 rect.top(), rect.width(), rect.height());
92 XFlush(display_->display()); 93 XFlush(display_->display());
93 } 94 }
94 95
95 void ScreenDrawerLinux::Clear() { 96 // TODO(zijiehe): Find the right signal from X11 to indicate the finish of all
96 DrawRectangle(DrawableRegion(), 0); 97 // pending paintings.
98 void ScreenDrawerLinux::WaitForPendingPaintings() {
99 SleepMs(500);
97 } 100 }
98 101
99 } // namespace 102 } // namespace
100 103
101 // static 104 // static
102 std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() { 105 std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() {
103 return std::unique_ptr<ScreenDrawer>(new ScreenDrawerLinux()); 106 if (SharedXDisplay::CreateDefault().get()) {
107 return std::unique_ptr<ScreenDrawer>(new ScreenDrawerLinux());
108 } else {
109 return nullptr;
110 }
104 } 111 }
105 112
106 } // namespace webrtc 113 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698