diff --git a/webrtc/modules/desktop_capture/screen_capturer_mac.mm b/webrtc/modules/desktop_capture/screen_capturer_mac.mm index b652477273..89d97761b9 100644 --- a/webrtc/modules/desktop_capture/screen_capturer_mac.mm +++ b/webrtc/modules/desktop_capture/screen_capturer_mac.mm @@ -219,6 +219,29 @@ class ScreenCapturerMac : public ScreenCapturer { DISALLOW_COPY_AND_ASSIGN(ScreenCapturerMac); }; +// DesktopFrame wrapper that flips wrapped frame upside down by inverting +// stride. +class InvertedDesktopFrame : public DesktopFrame { + public: + // Takes ownership of |frame|. + InvertedDesktopFrame(DesktopFrame* frame) + : DesktopFrame( + frame->size(), -frame->stride(), + frame->data() - (frame->size().height() - 1) * frame->stride(), + frame->shared_memory()), + original_frame_(frame) { + set_dpi(frame->dpi()); + set_capture_time_ms(frame->capture_time_ms()); + mutable_updated_region()->Swap(frame->mutable_updated_region()); + } + virtual ~InvertedDesktopFrame() {} + + private: + scoped_ptr original_frame_; + + DISALLOW_COPY_AND_ASSIGN(InvertedDesktopFrame); +}; + DesktopFrame* CreateFrame( const MacDesktopConfiguration& desktop_config) { @@ -364,16 +387,12 @@ void ScreenCapturerMac::Capture( CgBlitPreLion(*current_frame, region); } - uint8_t* buffer = current_frame->data(); - int stride = current_frame->stride(); - if (flip) { - stride = -stride; - buffer += (current_frame->size().height() - 1) * current_frame->stride(); - } - DesktopFrame* new_frame = queue_.current_frame()->Share(); *new_frame->mutable_updated_region() = region; + if (flip) + new_frame = new InvertedDesktopFrame(new_frame); + helper_.set_size_most_recent(new_frame->size()); // Signal that we are done capturing data from the display framebuffer,