Chromium Code Reviews| 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..2b93ac84ef3f041fbbcf82c91b8f7a843a1e99ed |
| --- /dev/null |
| +++ b/webrtc/modules/desktop_capture/screen_drawer_linux.cc |
| @@ -0,0 +1,79 @@ |
| +/* |
| + * 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 "webrtc/modules/desktop_capture/screen_drawer_linux.h" |
| + |
| +#include <memory> |
| + |
| +namespace webrtc { |
| + |
| +ScreenDrawerX11::ScreenDrawerX11() |
| + : ScreenDrawer(), |
| + display_(SharedXDisplay::CreateDefault()), |
| + screen_(DefaultScreenOfDisplay(display_->display())), |
| + screen_num_(DefaultScreen(display_->display())), |
| + rect_(DesktopRect::MakeWH(screen_->width, screen_->height)), |
| + window_( |
| + 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.
|
| + 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_); |
|
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
|
| + 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_); |
| +} |
| + |
| +ScreenDrawerX11::~ScreenDrawerX11() { |
| + XUnmapWindow(display_->display(), window_); |
| + XDestroyWindow(display_->display(), window_); |
| +} |
| + |
| +DesktopRect ScreenDrawerX11::DrawableRegion() { |
| + return rect_; |
| +} |
| + |
| +void ScreenDrawerX11::DrawRectangle(DesktopRect rect, uint32_t rgba) { |
| + const char* rgba_array = reinterpret_cast<const char*>(&rgba); |
| + int r = rgba_array[0]; |
| + int g = rgba_array[1]; |
| + 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.
|
| + // X11 does not support Alpha. |
| + XColor color; |
| + 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.
|
| + color.green = g << 8; |
| + color.blue = b << 8; |
| + 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()); |
| +} |
| + |
| +// static |
| +std::unique_ptr<ScreenDrawer> ScreenDrawer::Create() { |
| + return std::unique_ptr<ScreenDrawer>(new ScreenDrawerX11()); |
| +} |
| + |
| +} // namespace webrtc |