Home | History | Annotate | Download | only in base
      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 
     11 #ifndef WEBRTC_BASE_WINDOW_H_
     12 #define WEBRTC_BASE_WINDOW_H_
     13 
     14 #include "webrtc/base/stringencode.h"
     15 
     16 // Define platform specific window types.
     17 #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID)
     18 typedef unsigned long Window;  // Avoid include <X11/Xlib.h>.
     19 #elif defined(WEBRTC_WIN)
     20 // We commonly include win32.h in webrtc/base so just include it here.
     21 #include "webrtc/base/win32.h"  // Include HWND, HMONITOR.
     22 #elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
     23 typedef unsigned int CGWindowID;
     24 typedef unsigned int CGDirectDisplayID;
     25 #endif
     26 
     27 namespace rtc {
     28 
     29 class WindowId {
     30  public:
     31   // Define WindowT for each platform.
     32 #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID)
     33   typedef Window WindowT;
     34 #elif defined(WEBRTC_WIN)
     35   typedef HWND WindowT;
     36 #elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
     37   typedef CGWindowID WindowT;
     38 #else
     39   typedef unsigned int WindowT;
     40 #endif
     41 
     42   static WindowId Cast(uint64 id) {
     43 #if defined(WEBRTC_WIN)
     44     return WindowId(reinterpret_cast<WindowId::WindowT>(id));
     45 #else
     46     return WindowId(static_cast<WindowId::WindowT>(id));
     47 #endif
     48   }
     49 
     50   static uint64 Format(const WindowT& id) {
     51 #if defined(WEBRTC_WIN)
     52     return static_cast<uint64>(reinterpret_cast<uintptr_t>(id));
     53 #else
     54     return static_cast<uint64>(id);
     55 #endif
     56   }
     57 
     58   WindowId() : id_(0) {}
     59   WindowId(const WindowT& id) : id_(id) {}  // NOLINT
     60   const WindowT& id() const { return id_; }
     61   bool IsValid() const { return id_ != 0; }
     62   bool Equals(const WindowId& other) const {
     63     return id_ == other.id();
     64   }
     65 
     66  private:
     67   WindowT id_;
     68 };
     69 
     70 class DesktopId {
     71  public:
     72   // Define DesktopT for each platform.
     73 #if defined(WEBRTC_LINUX) && !defined(WEBRTC_ANDROID)
     74   typedef Window DesktopT;
     75 #elif defined(WEBRTC_WIN)
     76   typedef HMONITOR DesktopT;
     77 #elif defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
     78   typedef CGDirectDisplayID DesktopT;
     79 #else
     80   typedef unsigned int DesktopT;
     81 #endif
     82 
     83   static DesktopId Cast(int id, int index) {
     84 #if defined(WEBRTC_WIN)
     85     return DesktopId(reinterpret_cast<DesktopId::DesktopT>(id), index);
     86 #else
     87     return DesktopId(static_cast<DesktopId::DesktopT>(id), index);
     88 #endif
     89   }
     90 
     91   DesktopId() : id_(0), index_(-1) {}
     92   DesktopId(const DesktopT& id, int index)  // NOLINT
     93       : id_(id), index_(index) {
     94   }
     95   const DesktopT& id() const { return id_; }
     96   int index() const { return index_; }
     97   bool IsValid() const { return index_ != -1; }
     98   bool Equals(const DesktopId& other) const {
     99     return id_ == other.id() && index_ == other.index();
    100   }
    101 
    102  private:
    103   // Id is the platform specific desktop identifier.
    104   DesktopT id_;
    105   // Index is the desktop index as enumerated by each platform.
    106   // Desktop capturer typically takes the index instead of id.
    107   int index_;
    108 };
    109 
    110 // Window event types.
    111 enum WindowEvent {
    112   WE_RESIZE = 0,
    113   WE_CLOSE = 1,
    114   WE_MINIMIZE = 2,
    115   WE_RESTORE = 3,
    116 };
    117 
    118 inline std::string ToString(const WindowId& window) {
    119   return ToString(window.id());
    120 }
    121 
    122 }  // namespace rtc
    123 
    124 #endif  // WEBRTC_BASE_WINDOW_H_
    125