#include <Cocoa/Cocoa.h>
#include <CoreFoundation/CoreFoundation.h>
+#include "webrtc/base/macutils.h"
+#include "webrtc/modules/desktop_capture/desktop_capture_options.h"
#include "webrtc/modules/desktop_capture/desktop_frame.h"
+#include "webrtc/modules/desktop_capture/mac/desktop_configuration.h"
+#include "webrtc/modules/desktop_capture/mac/full_screen_chrome_window_detector.h"
+#include "webrtc/modules/desktop_capture/mac/window_list_utils.h"
#include "webrtc/system_wrappers/interface/logging.h"
+#include "webrtc/system_wrappers/interface/scoped_refptr.h"
+#include "webrtc/system_wrappers/interface/tick_util.h"
namespace webrtc {
namespace {
-bool CFStringRefToUtf8(const CFStringRef string, std::string* str_utf8) {
- assert(string);
- assert(str_utf8);
- CFIndex length = CFStringGetLength(string);
- size_t max_length_utf8 =
- CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
- str_utf8->resize(max_length_utf8);
- CFIndex used_bytes;
- int result = CFStringGetBytes(
- string, CFRangeMake(0, length), kCFStringEncodingUTF8, 0, false,
- reinterpret_cast<UInt8*>(&*str_utf8->begin()), max_length_utf8,
- &used_bytes);
- if (result != length) {
- str_utf8->clear();
- return false;
- }
- str_utf8->resize(used_bytes);
- return true;
-}
-
+// Returns true if the window exists.
bool IsWindowValid(CGWindowID id) {
CFArrayRef window_id_array =
CFArrayCreate(NULL, reinterpret_cast<const void **>(&id), 1, NULL);
class WindowCapturerMac : public WindowCapturer {
public:
- WindowCapturerMac();
+ explicit WindowCapturerMac(
+ scoped_refptr<FullScreenChromeWindowDetector>
+ full_screen_chrome_window_detector);
virtual ~WindowCapturerMac();
// WindowCapturer interface.
private:
Callback* callback_;
+
+ // The window being captured.
CGWindowID window_id_;
+ scoped_refptr<FullScreenChromeWindowDetector>
+ full_screen_chrome_window_detector_;
+
DISALLOW_COPY_AND_ASSIGN(WindowCapturerMac);
};
-WindowCapturerMac::WindowCapturerMac()
+WindowCapturerMac::WindowCapturerMac(
+ scoped_refptr<FullScreenChromeWindowDetector>
+ full_screen_chrome_window_detector)
: callback_(NULL),
- window_id_(0) {
+ window_id_(0),
+ full_screen_chrome_window_detector_(full_screen_chrome_window_detector) {
}
WindowCapturerMac::~WindowCapturerMac() {
CFNumberGetValue(window_id, kCFNumberIntType, &id);
WindowCapturer::Window window;
window.id = id;
- if (!CFStringRefToUtf8(window_title, &(window.title)) ||
+ if (!rtc::ToUtf8(window_title, &(window.title)) ||
window.title.empty()) {
continue;
}
return;
}
+ CGWindowID on_screen_window = window_id_;
+ if (full_screen_chrome_window_detector_) {
+ CGWindowID full_screen_window =
+ full_screen_chrome_window_detector_->FindFullScreenWindow(window_id_);
+
+ if (full_screen_window != kCGNullWindowID)
+ on_screen_window = full_screen_window;
+ }
+
CGImageRef window_image = CGWindowListCreateImage(
CGRectNull, kCGWindowListOptionIncludingWindow,
- window_id_, kCGWindowImageBoundsIgnoreFraming);
+ on_screen_window, kCGWindowImageBoundsIgnoreFraming);
if (!window_image) {
callback_->OnCaptureCompleted(NULL);
CFRelease(window_image);
callback_->OnCaptureCompleted(frame);
+
+ if (full_screen_chrome_window_detector_)
+ full_screen_chrome_window_detector_->UpdateWindowListIfNeeded(window_id_);
}
} // namespace
// static
WindowCapturer* WindowCapturer::Create(const DesktopCaptureOptions& options) {
- return new WindowCapturerMac();
+ return new WindowCapturerMac(options.full_screen_chrome_window_detector());
}
} // namespace webrtc