Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/capturer.h" | 5 #include "remoting/host/capturer.h" |
| 6 | 6 |
| 7 #include <ApplicationServices/ApplicationServices.h> | 7 #include <ApplicationServices/ApplicationServices.h> |
| 8 #include <Cocoa/Cocoa.h> | 8 #include <Cocoa/Cocoa.h> |
| 9 #include <dlfcn.h> | 9 #include <dlfcn.h> |
| 10 #include <IOKit/pwr_mgt/IOPMLib.h> | 10 #include <IOKit/pwr_mgt/IOPMLib.h> |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 class CapturerMac : public Capturer { | 170 class CapturerMac : public Capturer { |
| 171 public: | 171 public: |
| 172 CapturerMac(); | 172 CapturerMac(); |
| 173 virtual ~CapturerMac(); | 173 virtual ~CapturerMac(); |
| 174 | 174 |
| 175 bool Init(); | 175 bool Init(); |
| 176 | 176 |
| 177 // Capturer interface. | 177 // Capturer interface. |
| 178 virtual void Start(const CursorShapeChangedCallback& callback) OVERRIDE; | 178 virtual void Start(const CursorShapeChangedCallback& callback) OVERRIDE; |
| 179 virtual void Stop() OVERRIDE; | 179 virtual void Stop() OVERRIDE; |
| 180 virtual void ScreenConfigurationChanged() OVERRIDE; | |
| 181 virtual media::VideoFrame::Format pixel_format() const OVERRIDE; | 180 virtual media::VideoFrame::Format pixel_format() const OVERRIDE; |
| 182 virtual void ClearInvalidRegion() OVERRIDE; | |
| 183 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; | 181 virtual void InvalidateRegion(const SkRegion& invalid_region) OVERRIDE; |
| 184 virtual void InvalidateScreen(const SkISize& size) OVERRIDE; | |
| 185 virtual void InvalidateFullScreen() OVERRIDE; | |
| 186 virtual void CaptureInvalidRegion( | 182 virtual void CaptureInvalidRegion( |
| 187 const CaptureCompletedCallback& callback) OVERRIDE; | 183 const CaptureCompletedCallback& callback) OVERRIDE; |
| 188 virtual const SkISize& size_most_recent() const OVERRIDE; | 184 virtual const SkISize& size_most_recent() const OVERRIDE; |
| 189 | 185 |
| 190 private: | 186 private: |
| 191 void CaptureCursor(); | 187 void CaptureCursor(); |
| 192 | 188 |
| 193 void GlBlitFast(const VideoFrameBuffer& buffer, const SkRegion& region); | 189 void GlBlitFast(const VideoFrameBuffer& buffer, const SkRegion& region); |
| 194 void GlBlitSlow(const VideoFrameBuffer& buffer); | 190 void GlBlitSlow(const VideoFrameBuffer& buffer); |
| 195 void CgBlitPreLion(const VideoFrameBuffer& buffer, const SkRegion& region); | 191 void CgBlitPreLion(const VideoFrameBuffer& buffer, const SkRegion& region); |
| 196 void CgBlitPostLion(const VideoFrameBuffer& buffer, const SkRegion& region); | 192 void CgBlitPostLion(const VideoFrameBuffer& buffer, const SkRegion& region); |
| 197 void CaptureRegion(const SkRegion& region, | 193 void CaptureRegion(const SkRegion& region, |
| 198 const CaptureCompletedCallback& callback); | 194 const CaptureCompletedCallback& callback); |
| 199 | 195 |
| 196 // Called when the screen configuration is changed. | |
| 197 void ScreenConfigurationChanged(); | |
|
Wez
2012/07/18 20:31:19
Add a blank line after this so it's clear that the
alexeypa (please no reviews)
2012/07/18 20:51:26
Done.
| |
| 200 void ScreenRefresh(CGRectCount count, const CGRect *rect_array); | 198 void ScreenRefresh(CGRectCount count, const CGRect *rect_array); |
| 201 void ScreenUpdateMove(CGScreenUpdateMoveDelta delta, | 199 void ScreenUpdateMove(CGScreenUpdateMoveDelta delta, |
| 202 size_t count, | 200 size_t count, |
| 203 const CGRect *rect_array); | 201 const CGRect *rect_array); |
| 204 void DisplaysReconfigured(CGDirectDisplayID display, | 202 void DisplaysReconfigured(CGDirectDisplayID display, |
| 205 CGDisplayChangeSummaryFlags flags); | 203 CGDisplayChangeSummaryFlags flags); |
| 206 static void ScreenRefreshCallback(CGRectCount count, | 204 static void ScreenRefreshCallback(CGRectCount count, |
| 207 const CGRect *rect_array, | 205 const CGRect *rect_array, |
| 208 void *user_parameter); | 206 void *user_parameter); |
| 209 static void ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, | 207 static void ScreenUpdateMoveCallback(CGScreenUpdateMoveDelta delta, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 349 if (power_assertion_id_display_ != kIOPMNullAssertionID) { | 347 if (power_assertion_id_display_ != kIOPMNullAssertionID) { |
| 350 IOPMAssertionRelease(power_assertion_id_display_); | 348 IOPMAssertionRelease(power_assertion_id_display_); |
| 351 power_assertion_id_display_ = kIOPMNullAssertionID; | 349 power_assertion_id_display_ = kIOPMNullAssertionID; |
| 352 } | 350 } |
| 353 if (power_assertion_id_user_ != kIOPMNullAssertionID) { | 351 if (power_assertion_id_user_ != kIOPMNullAssertionID) { |
| 354 IOPMAssertionRelease(power_assertion_id_user_); | 352 IOPMAssertionRelease(power_assertion_id_user_); |
| 355 power_assertion_id_user_ = kIOPMNullAssertionID; | 353 power_assertion_id_user_ = kIOPMNullAssertionID; |
| 356 } | 354 } |
| 357 } | 355 } |
| 358 | 356 |
| 359 void CapturerMac::ScreenConfigurationChanged() { | |
| 360 ReleaseBuffers(); | |
| 361 helper_.ClearInvalidRegion(); | |
| 362 last_buffer_ = NULL; | |
| 363 | |
| 364 CGDirectDisplayID mainDevice = CGMainDisplayID(); | |
| 365 int width = CGDisplayPixelsWide(mainDevice); | |
| 366 int height = CGDisplayPixelsHigh(mainDevice); | |
| 367 InvalidateScreen(SkISize::Make(width, height)); | |
| 368 | |
| 369 if (!CGDisplayUsesOpenGLAcceleration(mainDevice)) { | |
| 370 VLOG(3) << "OpenGL support not available."; | |
| 371 return; | |
| 372 } | |
| 373 | |
| 374 if (display_create_image_func_ != NULL) { | |
| 375 // No need for any OpenGL support on Lion | |
| 376 return; | |
| 377 } | |
| 378 | |
| 379 CGLPixelFormatAttribute attributes[] = { | |
| 380 kCGLPFAFullScreen, | |
| 381 kCGLPFADisplayMask, | |
| 382 (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(mainDevice), | |
| 383 (CGLPixelFormatAttribute)0 | |
| 384 }; | |
| 385 CGLPixelFormatObj pixel_format = NULL; | |
| 386 GLint matching_pixel_format_count = 0; | |
| 387 CGLError err = CGLChoosePixelFormat(attributes, | |
| 388 &pixel_format, | |
| 389 &matching_pixel_format_count); | |
| 390 DCHECK_EQ(err, kCGLNoError); | |
| 391 err = CGLCreateContext(pixel_format, NULL, &cgl_context_); | |
| 392 DCHECK_EQ(err, kCGLNoError); | |
| 393 CGLDestroyPixelFormat(pixel_format); | |
| 394 CGLSetFullScreen(cgl_context_); | |
| 395 CGLSetCurrentContext(cgl_context_); | |
| 396 | |
| 397 size_t buffer_size = width * height * sizeof(uint32_t); | |
| 398 pixel_buffer_object_.Init(cgl_context_, buffer_size); | |
| 399 } | |
| 400 | |
| 401 media::VideoFrame::Format CapturerMac::pixel_format() const { | 357 media::VideoFrame::Format CapturerMac::pixel_format() const { |
| 402 return pixel_format_; | 358 return pixel_format_; |
| 403 } | 359 } |
| 404 | 360 |
| 405 void CapturerMac::ClearInvalidRegion() { | |
| 406 helper_.ClearInvalidRegion(); | |
| 407 } | |
| 408 | |
| 409 void CapturerMac::InvalidateRegion(const SkRegion& invalid_region) { | 361 void CapturerMac::InvalidateRegion(const SkRegion& invalid_region) { |
| 410 helper_.InvalidateRegion(invalid_region); | 362 helper_.InvalidateRegion(invalid_region); |
| 411 } | 363 } |
| 412 | 364 |
| 413 void CapturerMac::InvalidateScreen(const SkISize& size) { | |
| 414 helper_.InvalidateScreen(size); | |
| 415 } | |
| 416 | |
| 417 void CapturerMac::InvalidateFullScreen() { | |
| 418 helper_.InvalidateFullScreen(); | |
| 419 } | |
| 420 | |
| 421 void CapturerMac::CaptureInvalidRegion( | 365 void CapturerMac::CaptureInvalidRegion( |
| 422 const CaptureCompletedCallback& callback) { | 366 const CaptureCompletedCallback& callback) { |
| 423 // Only allow captures when the display configuration is not occurring. | 367 // Only allow captures when the display configuration is not occurring. |
| 424 scoped_refptr<CaptureData> data; | 368 scoped_refptr<CaptureData> data; |
| 425 | 369 |
| 426 // Critical section shared with DisplaysReconfigured(...). | 370 // Critical section shared with DisplaysReconfigured(...). |
| 427 CHECK(display_configuration_capture_event_.TimedWait( | 371 CHECK(display_configuration_capture_event_.TimedWait( |
| 428 base::TimeDelta::FromSeconds(kDisplayReconfigurationTimeoutInSeconds))); | 372 base::TimeDelta::FromSeconds(kDisplayReconfigurationTimeoutInSeconds))); |
| 429 SkRegion region; | 373 SkRegion region; |
| 430 helper_.SwapInvalidRegion(®ion); | 374 helper_.SwapInvalidRegion(®ion); |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 705 src_bytes_per_pixel, | 649 src_bytes_per_pixel, |
| 706 copy_rect); | 650 copy_rect); |
| 707 } | 651 } |
| 708 } | 652 } |
| 709 } | 653 } |
| 710 | 654 |
| 711 const SkISize& CapturerMac::size_most_recent() const { | 655 const SkISize& CapturerMac::size_most_recent() const { |
| 712 return helper_.size_most_recent(); | 656 return helper_.size_most_recent(); |
| 713 } | 657 } |
| 714 | 658 |
| 659 void CapturerMac::ScreenConfigurationChanged() { | |
| 660 ReleaseBuffers(); | |
| 661 helper_.ClearInvalidRegion(); | |
| 662 last_buffer_ = NULL; | |
| 663 | |
| 664 CGDirectDisplayID mainDevice = CGMainDisplayID(); | |
| 665 int width = CGDisplayPixelsWide(mainDevice); | |
| 666 int height = CGDisplayPixelsHigh(mainDevice); | |
| 667 helper_.InvalidateScreen(SkISize::Make(width, height)); | |
| 668 | |
| 669 if (!CGDisplayUsesOpenGLAcceleration(mainDevice)) { | |
| 670 VLOG(3) << "OpenGL support not available."; | |
| 671 return; | |
| 672 } | |
| 673 | |
| 674 if (display_create_image_func_ != NULL) { | |
| 675 // No need for any OpenGL support on Lion | |
| 676 return; | |
| 677 } | |
| 678 | |
| 679 CGLPixelFormatAttribute attributes[] = { | |
| 680 kCGLPFAFullScreen, | |
| 681 kCGLPFADisplayMask, | |
| 682 (CGLPixelFormatAttribute)CGDisplayIDToOpenGLDisplayMask(mainDevice), | |
| 683 (CGLPixelFormatAttribute)0 | |
| 684 }; | |
| 685 CGLPixelFormatObj pixel_format = NULL; | |
| 686 GLint matching_pixel_format_count = 0; | |
| 687 CGLError err = CGLChoosePixelFormat(attributes, | |
| 688 &pixel_format, | |
| 689 &matching_pixel_format_count); | |
| 690 DCHECK_EQ(err, kCGLNoError); | |
| 691 err = CGLCreateContext(pixel_format, NULL, &cgl_context_); | |
| 692 DCHECK_EQ(err, kCGLNoError); | |
| 693 CGLDestroyPixelFormat(pixel_format); | |
| 694 CGLSetFullScreen(cgl_context_); | |
| 695 CGLSetCurrentContext(cgl_context_); | |
| 696 | |
| 697 size_t buffer_size = width * height * sizeof(uint32_t); | |
| 698 pixel_buffer_object_.Init(cgl_context_, buffer_size); | |
| 699 } | |
| 700 | |
| 715 void CapturerMac::ScreenRefresh(CGRectCount count, const CGRect *rect_array) { | 701 void CapturerMac::ScreenRefresh(CGRectCount count, const CGRect *rect_array) { |
| 716 SkIRect skirect_array[count]; | 702 SkIRect skirect_array[count]; |
| 717 for (CGRectCount i = 0; i < count; ++i) { | 703 for (CGRectCount i = 0; i < count; ++i) { |
| 718 skirect_array[i] = CGRectToSkIRect(rect_array[i]); | 704 skirect_array[i] = CGRectToSkIRect(rect_array[i]); |
| 719 } | 705 } |
| 720 SkRegion region; | 706 SkRegion region; |
| 721 region.setRects(skirect_array, count); | 707 region.setRects(skirect_array, count); |
| 722 InvalidateRegion(region); | 708 InvalidateRegion(region); |
| 723 } | 709 } |
| 724 | 710 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 783 Capturer* Capturer::Create() { | 769 Capturer* Capturer::Create() { |
| 784 CapturerMac* capturer = new CapturerMac(); | 770 CapturerMac* capturer = new CapturerMac(); |
| 785 if (!capturer->Init()) { | 771 if (!capturer->Init()) { |
| 786 delete capturer; | 772 delete capturer; |
| 787 capturer = NULL; | 773 capturer = NULL; |
| 788 } | 774 } |
| 789 return capturer; | 775 return capturer; |
| 790 } | 776 } |
| 791 | 777 |
| 792 } // namespace remoting | 778 } // namespace remoting |
| OLD | NEW |