henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef RTC_BASE_WINDOW_H_ |
| 12 | #define RTC_BASE_WINDOW_H_ |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 13 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 14 | #include <stdint.h> |
pbos | c7c26a0 | 2017-01-02 08:42:32 -0800 | [diff] [blame] | 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "rtc_base/stringencode.h" |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 17 | |
| 18 | // Define platform specific window types. |
| 19 | #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID) |
| 20 | typedef unsigned long Window; // Avoid include <X11/Xlib.h>. |
| 21 | #elif defined(WEBRTC_WIN) |
kjellander | e96c45b | 2017-06-30 10:45:21 -0700 | [diff] [blame] | 22 | // We commonly include win32.h in webrtc/rtc_base so just include it here. |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "rtc_base/win32.h" // Include HWND, HMONITOR. |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 24 | #elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
| 25 | typedef unsigned int CGWindowID; |
| 26 | typedef unsigned int CGDirectDisplayID; |
| 27 | #endif |
| 28 | |
| 29 | namespace rtc { |
| 30 | |
| 31 | class WindowId { |
| 32 | public: |
| 33 | // Define WindowT for each platform. |
| 34 | #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID) |
| 35 | typedef Window WindowT; |
| 36 | #elif defined(WEBRTC_WIN) |
| 37 | typedef HWND WindowT; |
| 38 | #elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) |
| 39 | typedef CGWindowID WindowT; |
| 40 | #else |
| 41 | typedef unsigned int WindowT; |
| 42 | #endif |
| 43 | |
| 44 | static WindowId Cast(uint64_t id) { |
| 45 | #if defined(WEBRTC_WIN) |
| 46 | return WindowId(reinterpret_cast<WindowId::WindowT>(id)); |
| 47 | #else |
| 48 | return WindowId(static_cast<WindowId::WindowT>(id)); |
| 49 | #endif |
| 50 | } |
| 51 | |
| 52 | static uint64_t Format(const WindowT& id) { |
| 53 | #if defined(WEBRTC_WIN) |
| 54 | return static_cast<uint64_t>(reinterpret_cast<uintptr_t>(id)); |
| 55 | #else |
| 56 | return static_cast<uint64_t>(id); |
| 57 | #endif |
| 58 | } |
| 59 | |
| 60 | WindowId() : id_(0) {} |
| 61 | WindowId(const WindowT& id) : id_(id) {} // NOLINT |
| 62 | const WindowT& id() const { return id_; } |
| 63 | bool IsValid() const { return id_ != 0; } |
| 64 | bool Equals(const WindowId& other) const { |
| 65 | return id_ == other.id(); |
| 66 | } |
| 67 | |
| 68 | private: |
| 69 | WindowT id_; |
| 70 | }; |
| 71 | |
| 72 | inline std::string ToString(const WindowId& window) { |
| 73 | return ToString(window.id()); |
| 74 | } |
| 75 | |
| 76 | } // namespace rtc |
henrike@webrtc.org | f048872 | 2014-05-13 18:00:26 +0000 | [diff] [blame] | 77 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 78 | #endif // RTC_BASE_WINDOW_H_ |