1 /*
2 * Copyright (c) 2019 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 "modules/desktop_capture/linux/x_window_property.h"
12
13 namespace webrtc {
14
XWindowPropertyBase(Display * display,Window window,Atom property,int expected_size)15 XWindowPropertyBase::XWindowPropertyBase(Display* display,
16 Window window,
17 Atom property,
18 int expected_size) {
19 const int kBitsPerByte = 8;
20 Atom actual_type;
21 int actual_format;
22 unsigned long bytes_after; // NOLINT: type required by XGetWindowProperty
23 int status = XGetWindowProperty(display, window, property, 0L, ~0L, False,
24 AnyPropertyType, &actual_type, &actual_format,
25 &size_, &bytes_after, &data_);
26 if (status != Success) {
27 data_ = nullptr;
28 return;
29 }
30 if ((expected_size * kBitsPerByte) != actual_format) {
31 size_ = 0;
32 return;
33 }
34
35 is_valid_ = true;
36 }
37
~XWindowPropertyBase()38 XWindowPropertyBase::~XWindowPropertyBase() {
39 if (data_)
40 XFree(data_);
41 }
42
43 } // namespace webrtc
44