Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(751)

Side by Side Diff: webrtc/modules/desktop_capture/screen_capturer_mac.mm

Issue 2490063002: Remove ScreenCapturer and WindowCapturer (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/modules/desktop_capture/screen_capturer.h"
12
13 #include <stddef.h> 11 #include <stddef.h>
14 12
15 #include <memory> 13 #include <memory>
16 #include <set> 14 #include <set>
17 #include <utility> 15 #include <utility>
18 16
19 #include <ApplicationServices/ApplicationServices.h> 17 #include <ApplicationServices/ApplicationServices.h>
20 #include <Cocoa/Cocoa.h> 18 #include <Cocoa/Cocoa.h>
21 #include <CoreGraphics/CoreGraphics.h> 19 #include <CoreGraphics/CoreGraphics.h>
22 #include <dlfcn.h> 20 #include <dlfcn.h>
23 #include <OpenGL/CGLMacro.h> 21 #include <OpenGL/CGLMacro.h>
24 #include <OpenGL/OpenGL.h> 22 #include <OpenGL/OpenGL.h>
25 23
26 #include "webrtc/base/checks.h" 24 #include "webrtc/base/checks.h"
27 #include "webrtc/base/constructormagic.h" 25 #include "webrtc/base/constructormagic.h"
28 #include "webrtc/base/macutils.h" 26 #include "webrtc/base/macutils.h"
29 #include "webrtc/base/timeutils.h" 27 #include "webrtc/base/timeutils.h"
28 #include "webrtc/modules/desktop_capture/desktop_capturer.h"
30 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" 29 #include "webrtc/modules/desktop_capture/desktop_capture_options.h"
31 #include "webrtc/modules/desktop_capture/desktop_frame.h" 30 #include "webrtc/modules/desktop_capture/desktop_frame.h"
32 #include "webrtc/modules/desktop_capture/desktop_geometry.h" 31 #include "webrtc/modules/desktop_capture/desktop_geometry.h"
33 #include "webrtc/modules/desktop_capture/desktop_region.h" 32 #include "webrtc/modules/desktop_capture/desktop_region.h"
34 #include "webrtc/modules/desktop_capture/mac/desktop_configuration.h" 33 #include "webrtc/modules/desktop_capture/mac/desktop_configuration.h"
35 #include "webrtc/modules/desktop_capture/mac/desktop_configuration_monitor.h" 34 #include "webrtc/modules/desktop_capture/mac/desktop_configuration_monitor.h"
36 #include "webrtc/modules/desktop_capture/mac/scoped_pixel_buffer_object.h" 35 #include "webrtc/modules/desktop_capture/mac/scoped_pixel_buffer_object.h"
37 #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" 36 #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h"
38 #include "webrtc/modules/desktop_capture/screen_capturer_differ_wrapper.h"
39 #include "webrtc/modules/desktop_capture/screen_capturer_helper.h" 37 #include "webrtc/modules/desktop_capture/screen_capturer_helper.h"
40 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" 38 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h"
41 #include "webrtc/system_wrappers/include/logging.h" 39 #include "webrtc/system_wrappers/include/logging.h"
42 40
43 // Once Chrome no longer supports OSX 10.8, everything within this 41 // Once Chrome no longer supports OSX 10.8, everything within this
44 // preprocessor block can be removed. https://crbug.com/579255 42 // preprocessor block can be removed. https://crbug.com/579255
45 #if !defined(MAC_OS_X_VERSION_10_9) || \ 43 #if !defined(MAC_OS_X_VERSION_10_9) || \
46 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9 44 MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_9
47 CG_EXTERN const CGRect* CGDisplayStreamUpdateGetRects( 45 CG_EXTERN const CGRect* CGDisplayStreamUpdateGetRects(
48 CGDisplayStreamUpdateRef updateRef, 46 CGDisplayStreamUpdateRef updateRef,
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 window_bounds.origin.x = pixel_bounds.left() / dip_to_pixel_scale; 266 window_bounds.origin.x = pixel_bounds.left() / dip_to_pixel_scale;
269 window_bounds.origin.y = pixel_bounds.top() / dip_to_pixel_scale; 267 window_bounds.origin.y = pixel_bounds.top() / dip_to_pixel_scale;
270 window_bounds.size.width = pixel_bounds.width(); 268 window_bounds.size.width = pixel_bounds.width();
271 window_bounds.size.height = pixel_bounds.height(); 269 window_bounds.size.height = pixel_bounds.height();
272 270
273 return CGWindowListCreateImageFromArray( 271 return CGWindowListCreateImageFromArray(
274 window_bounds, window_list, kCGWindowImageDefault); 272 window_bounds, window_list, kCGWindowImageDefault);
275 } 273 }
276 274
277 // A class to perform video frame capturing for mac. 275 // A class to perform video frame capturing for mac.
278 class ScreenCapturerMac : public ScreenCapturer { 276 class ScreenCapturerMac : public DesktopCapturer {
279 public: 277 public:
280 explicit ScreenCapturerMac( 278 explicit ScreenCapturerMac(
281 rtc::scoped_refptr<DesktopConfigurationMonitor> desktop_config_monitor); 279 rtc::scoped_refptr<DesktopConfigurationMonitor> desktop_config_monitor);
282 ~ScreenCapturerMac() override; 280 ~ScreenCapturerMac() override;
283 281
284 bool Init(); 282 bool Init();
285 283
286 // Overridden from ScreenCapturer: 284 // DesktopCapturer interface.
287 void Start(Callback* callback) override; 285 void Start(Callback* callback) override;
288 void CaptureFrame() override; 286 void CaptureFrame() override;
289 void SetExcludedWindow(WindowId window) override; 287 void SetExcludedWindow(WindowId window) override;
290 bool GetScreenList(ScreenList* screens) override; 288 bool GetSourceList(SourceList* screens) override;
291 bool SelectScreen(ScreenId id) override; 289 bool SelectSource(SourceId id) override;
292 290
293 private: 291 private:
294 void GlBlitFast(const DesktopFrame& frame, 292 void GlBlitFast(const DesktopFrame& frame,
295 const DesktopRegion& region); 293 const DesktopRegion& region);
296 void GlBlitSlow(const DesktopFrame& frame); 294 void GlBlitSlow(const DesktopFrame& frame);
297 void CgBlitPreLion(const DesktopFrame& frame, 295 void CgBlitPreLion(const DesktopFrame& frame,
298 const DesktopRegion& region); 296 const DesktopRegion& region);
299 // Returns false if the selected screen is no longer valid. 297 // Returns false if the selected screen is no longer valid.
300 bool CgBlitPostLion(const DesktopFrame& frame, 298 bool CgBlitPostLion(const DesktopFrame& frame,
301 const DesktopRegion& region); 299 const DesktopRegion& region);
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 490
493 new_frame->set_capture_time_ms((rtc::TimeNanos() - capture_start_time_nanos) / 491 new_frame->set_capture_time_ms((rtc::TimeNanos() - capture_start_time_nanos) /
494 rtc::kNumNanosecsPerMillisec); 492 rtc::kNumNanosecsPerMillisec);
495 callback_->OnCaptureResult(Result::SUCCESS, std::move(new_frame)); 493 callback_->OnCaptureResult(Result::SUCCESS, std::move(new_frame));
496 } 494 }
497 495
498 void ScreenCapturerMac::SetExcludedWindow(WindowId window) { 496 void ScreenCapturerMac::SetExcludedWindow(WindowId window) {
499 excluded_window_ = window; 497 excluded_window_ = window;
500 } 498 }
501 499
502 bool ScreenCapturerMac::GetScreenList(ScreenList* screens) { 500 bool ScreenCapturerMac::GetSourceList(SourceList* screens) {
503 assert(screens->size() == 0); 501 assert(screens->size() == 0);
504 if (rtc::GetOSVersionName() < rtc::kMacOSLion) { 502 if (rtc::GetOSVersionName() < rtc::kMacOSLion) {
505 // Single monitor cast is not supported on pre OS X 10.7. 503 // Single monitor cast is not supported on pre OS X 10.7.
506 Screen screen; 504 screens->push_back({kFullDesktopScreenId});
507 screen.id = kFullDesktopScreenId;
508 screens->push_back(screen);
509 return true; 505 return true;
510 } 506 }
511 507
512 for (MacDisplayConfigurations::iterator it = desktop_config_.displays.begin(); 508 for (MacDisplayConfigurations::iterator it = desktop_config_.displays.begin();
513 it != desktop_config_.displays.end(); ++it) { 509 it != desktop_config_.displays.end(); ++it) {
514 Screen screen; 510 screens->push_back({it->id});
515 screen.id = static_cast<ScreenId>(it->id);
516 screens->push_back(screen);
517 } 511 }
518 return true; 512 return true;
519 } 513 }
520 514
521 bool ScreenCapturerMac::SelectScreen(ScreenId id) { 515 bool ScreenCapturerMac::SelectSource(SourceId id) {
522 if (rtc::GetOSVersionName() < rtc::kMacOSLion) { 516 if (rtc::GetOSVersionName() < rtc::kMacOSLion) {
523 // Ignore the screen selection on unsupported OS. 517 // Ignore the screen selection on unsupported OS.
524 assert(!current_display_); 518 assert(!current_display_);
525 return id == kFullDesktopScreenId; 519 return id == kFullDesktopScreenId;
526 } 520 }
527 521
528 if (id == kFullDesktopScreenId) { 522 if (id == kFullDesktopScreenId) {
529 current_display_ = 0; 523 current_display_ = 0;
530 } else { 524 } else {
531 const MacDisplayConfiguration* config = 525 const MacDisplayConfiguration* config =
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 std::unique_ptr<DesktopFrame> frame( 1007 std::unique_ptr<DesktopFrame> frame(
1014 new BasicDesktopFrame(screen_pixel_bounds_.size())); 1008 new BasicDesktopFrame(screen_pixel_bounds_.size()));
1015 frame->set_dpi(DesktopVector(kStandardDPI * dip_to_pixel_scale_, 1009 frame->set_dpi(DesktopVector(kStandardDPI * dip_to_pixel_scale_,
1016 kStandardDPI * dip_to_pixel_scale_)); 1010 kStandardDPI * dip_to_pixel_scale_));
1017 return frame; 1011 return frame;
1018 } 1012 }
1019 1013
1020 } // namespace 1014 } // namespace
1021 1015
1022 // static 1016 // static
1023 ScreenCapturer* ScreenCapturer::Create(const DesktopCaptureOptions& options) {
1024 if (!options.configuration_monitor())
1025 return nullptr;
1026
1027 std::unique_ptr<ScreenCapturer> capturer(
1028 new ScreenCapturerMac(options.configuration_monitor()));
1029 if (!static_cast<ScreenCapturerMac*>(capturer.get())->Init()) {
1030 return nullptr;
1031 }
1032
1033 if (options.detect_updated_region()) {
1034 capturer.reset(new ScreenCapturerDifferWrapper(std::move(capturer)));
1035 }
1036
1037 return capturer.release();
1038 }
1039
1040 // static
1041 std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawScreenCapturer( 1017 std::unique_ptr<DesktopCapturer> DesktopCapturer::CreateRawScreenCapturer(
1042 const DesktopCaptureOptions& options) { 1018 const DesktopCaptureOptions& options) {
1043 if (!options.configuration_monitor()) 1019 if (!options.configuration_monitor())
1044 return nullptr; 1020 return nullptr;
1045 1021
1046 std::unique_ptr<ScreenCapturer> capturer( 1022 std::unique_ptr<ScreenCapturerMac> capturer(
1047 new ScreenCapturerMac(options.configuration_monitor())); 1023 new ScreenCapturerMac(options.configuration_monitor()));
1048 if (!static_cast<ScreenCapturerMac*>(capturer.get())->Init()) { 1024 if (!capturer.get()->Init()) {
1049 return nullptr; 1025 return nullptr;
1050 } 1026 }
1051 1027
1052 return capturer; 1028 return capturer;
1053 } 1029 }
1054 1030
1055 } // namespace webrtc 1031 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698