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

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: 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 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 "webrtc/modules/desktop_capture/screen_drawer_linux.h"
12
13 #include <memory>
14
15 namespace webrtc {
16
17 ScreenDrawerX11::ScreenDrawerX11()
18 : ScreenDrawer(),
19 display_(SharedXDisplay::CreateDefault()),
20 screen_(DefaultScreenOfDisplay(display_->display())),
21 screen_num_(DefaultScreen(display_->display())),
22 rect_(DesktopRect::MakeWH(screen_->width, screen_->height)),
23 window_(
24 XCreateSimpleWindow(display_->display(),
Sergey Ulanov 2016/08/09 17:43:01 I'd prefer moving all this initialization logic ou
Hzj_jie 2016/08/11 18:42:03 Done.
25 RootWindow(display_->display(), screen_num_),
26 0,
27 0,
28 rect_.width(),
29 rect_.height(),
30 0,
31 BlackPixel(display_->display(), screen_num_),
32 BlackPixel(display_->display(), screen_num_))) {
33 XSelectInput(display_->display(), window_, StructureNotifyMask);
34 XMapWindow(display_->display(), window_);
Sergey Ulanov 2016/08/09 17:43:01 Verify that these succeed. Since this is test-only
Hzj_jie 2016/08/11 18:42:04 I believe the return value of these functions are
35 while (true) {
36 XEvent event;
37 XNextEvent(display_->display(), &event);
38 if (event.type == MapNotify) {
39 break;
40 }
41 }
42 XFlush(display_->display());
43 context_ = DefaultGC(display_->display(), screen_num_);
44 colormap_ = DefaultColormap(display_->display(), screen_num_);
45 }
46
47 ScreenDrawerX11::~ScreenDrawerX11() {
48 XUnmapWindow(display_->display(), window_);
49 XDestroyWindow(display_->display(), window_);
50 }
51
52 DesktopRect ScreenDrawerX11::DrawableRegion() {
53 return rect_;
54 }
55
56 void ScreenDrawerX11::DrawRectangle(DesktopRect rect, uint32_t rgba) {
57 const char* rgba_array = reinterpret_cast<const char*>(&rgba);
58 int r = rgba_array[0];
59 int g = rgba_array[1];
60 int b = rgba_array[2];
Sergey Ulanov 2016/08/09 17:43:01 r = rgba & 0xff; g = (rgba & 0xff00) >> 8; b = (rg
Hzj_jie 2016/08/11 18:42:04 Good point. Done.
61 // X11 does not support Alpha.
62 XColor color;
63 color.red = r << 8;
Sergey Ulanov 2016/08/09 17:43:01 r * 256 would be more readable as it makes it clea
Hzj_jie 2016/08/11 18:42:04 Done.
64 color.green = g << 8;
65 color.blue = b << 8;
66 color.flags = DoRed | DoGreen | DoBlue;
67 XAllocColor(display_->display(), colormap_, &color);
68 XSetForeground(display_->display(), context_, color.pixel);
69 XFillRectangle(display_->display(), window_, context_, rect.left(),
70 rect.top(), rect.width(), rect.height());
71 XFlush(display_->display());
72 }
73
74 // static
75 std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() {
76 return std::unique_ptr<ScreenDrawer>(new ScreenDrawerX11());
77 }
78
79 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698