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