diff --git a/webrtc/modules/desktop_capture/desktop_and_cursor_composer.cc b/webrtc/modules/desktop_capture/desktop_and_cursor_composer.cc index 6ed3ae881f..59d564e751 100644 --- a/webrtc/modules/desktop_capture/desktop_and_cursor_composer.cc +++ b/webrtc/modules/desktop_capture/desktop_and_cursor_composer.cc @@ -81,7 +81,7 @@ DesktopFrameWithCursor::DesktopFrameWithCursor(DesktopFrame* frame, mutable_updated_region()->Swap(frame->mutable_updated_region()); DesktopVector image_pos = position.subtract(cursor.hotspot()); - DesktopRect target_rect = DesktopRect::MakeSize(cursor.image().size()); + DesktopRect target_rect = DesktopRect::MakeSize(cursor.image()->size()); target_rect.Translate(image_pos); DesktopVector target_origin = target_rect.top_left(); target_rect.IntersectWith(DesktopRect::MakeSize(size())); @@ -101,10 +101,10 @@ DesktopFrameWithCursor::DesktopFrameWithCursor(DesktopFrame* frame, target_rect.left() * DesktopFrame::kBytesPerPixel; DesktopVector origin_shift = target_rect.top_left().subtract(target_origin); AlphaBlend(target_rect_data, stride(), - cursor.image().data() + - origin_shift.y() * cursor.image().stride() + + cursor.image()->data() + + origin_shift.y() * cursor.image()->stride() + origin_shift.x() * DesktopFrame::kBytesPerPixel, - cursor.image().stride(), + cursor.image()->stride(), target_rect.size()); } diff --git a/webrtc/modules/desktop_capture/mouse_cursor.cc b/webrtc/modules/desktop_capture/mouse_cursor.cc index 3f1ab3ddf5..c6c58d87cb 100644 --- a/webrtc/modules/desktop_capture/mouse_cursor.cc +++ b/webrtc/modules/desktop_capture/mouse_cursor.cc @@ -14,6 +14,8 @@ namespace webrtc { +MouseCursor::MouseCursor() {} + MouseCursor::MouseCursor(DesktopFrame* image, const DesktopVector& hotspot) : image_(image), hotspot_(hotspot) { @@ -25,8 +27,9 @@ MouseCursor::~MouseCursor() {} // static MouseCursor* MouseCursor::CopyOf(const MouseCursor& cursor) { - return new MouseCursor(BasicDesktopFrame::CopyOf(cursor.image()), - cursor.hotspot()); + return new MouseCursor( + cursor.image() ? NULL : BasicDesktopFrame::CopyOf(*cursor.image()), + cursor.hotspot()); } } // namespace webrtc diff --git a/webrtc/modules/desktop_capture/mouse_cursor.h b/webrtc/modules/desktop_capture/mouse_cursor.h index 4cf770830c..3acfa45a33 100644 --- a/webrtc/modules/desktop_capture/mouse_cursor.h +++ b/webrtc/modules/desktop_capture/mouse_cursor.h @@ -21,13 +21,19 @@ class DesktopFrame; class MouseCursor { public: + MouseCursor(); + // Takes ownership of |image|. |hotspot| must be within |image| boundaries. MouseCursor(DesktopFrame* image, const DesktopVector& hotspot); + ~MouseCursor(); static MouseCursor* CopyOf(const MouseCursor& cursor); - const DesktopFrame& image() const { return *image_; } + void set_image(DesktopFrame* image) { image_.reset(image); } + const DesktopFrame* image() const { return image_.get(); } + + void set_hotspot(const DesktopVector& hotspot ) { hotspot_ = hotspot; } const DesktopVector& hotspot() const { return hotspot_; } private: diff --git a/webrtc/modules/desktop_capture/mouse_cursor_monitor_mac.mm b/webrtc/modules/desktop_capture/mouse_cursor_monitor_mac.mm index 6f9380af3e..0da9869242 100644 --- a/webrtc/modules/desktop_capture/mouse_cursor_monitor_mac.mm +++ b/webrtc/modules/desktop_capture/mouse_cursor_monitor_mac.mm @@ -182,10 +182,10 @@ void MouseCursorMonitorMac::CaptureImage() { // Compare the cursor with the previous one. if (last_cursor_.get() && - last_cursor_->image().size().equals(size) && + last_cursor_->image()->size().equals(size) && last_cursor_->hotspot().equals(hotspot) && - memcmp(last_cursor_->image().data(), src_data, - last_cursor_->image().stride() * size.height()) == 0) { + memcmp(last_cursor_->image()->data(), src_data, + last_cursor_->image()->stride() * size.height()) == 0) { return; } diff --git a/webrtc/modules/desktop_capture/mouse_cursor_monitor_unittest.cc b/webrtc/modules/desktop_capture/mouse_cursor_monitor_unittest.cc index 18bf1ca40e..f91a9aff14 100644 --- a/webrtc/modules/desktop_capture/mouse_cursor_monitor_unittest.cc +++ b/webrtc/modules/desktop_capture/mouse_cursor_monitor_unittest.cc @@ -66,10 +66,10 @@ TEST_F(MouseCursorMonitorTest, MAYBE(FromScreen)) { EXPECT_TRUE(cursor_image_.get()); EXPECT_GE(cursor_image_->hotspot().x(), 0); EXPECT_LE(cursor_image_->hotspot().x(), - cursor_image_->image().size().width()); + cursor_image_->image()->size().width()); EXPECT_GE(cursor_image_->hotspot().y(), 0); EXPECT_LE(cursor_image_->hotspot().y(), - cursor_image_->image().size().height()); + cursor_image_->image()->size().height()); EXPECT_TRUE(position_received_); EXPECT_EQ(MouseCursorMonitor::INSIDE, state_); diff --git a/webrtc/modules/desktop_capture/screen_capturer_win.cc b/webrtc/modules/desktop_capture/screen_capturer_win.cc index a9bcd48f9c..fecbb4d79e 100644 --- a/webrtc/modules/desktop_capture/screen_capturer_win.cc +++ b/webrtc/modules/desktop_capture/screen_capturer_win.cc @@ -336,13 +336,13 @@ void ScreenCapturerWin::CaptureCursor() { scoped_ptr cursor(new MouseCursorShape); cursor->hotspot = cursor_image->hotspot(); - cursor->size = cursor_image->image().size(); - uint8_t* current_row = cursor_image->image().data(); - for (int y = 0; y < cursor_image->image().size().height(); ++y) { + cursor->size = cursor_image->image()->size(); + uint8_t* current_row = cursor_image->image()->data(); + for (int y = 0; y < cursor_image->image()->size().height(); ++y) { cursor->data.append(current_row, - current_row + cursor_image->image().size().width() * + current_row + cursor_image->image()->size().width() * DesktopFrame::kBytesPerPixel); - current_row += cursor_image->image().stride(); + current_row += cursor_image->image()->stride(); } // Compare the current cursor with the last one we sent to the client. If diff --git a/webrtc/modules/desktop_capture/win/cursor_unittest.cc b/webrtc/modules/desktop_capture/win/cursor_unittest.cc index f590bd255c..9d2387483d 100644 --- a/webrtc/modules/desktop_capture/win/cursor_unittest.cc +++ b/webrtc/modules/desktop_capture/win/cursor_unittest.cc @@ -58,7 +58,7 @@ bool ConvertToMouseShapeAndCompare(unsigned left, unsigned right) { int width = bitmap_info.bmWidth; int height = bitmap_info.bmHeight; - EXPECT_TRUE(DesktopSize(width, height).equals(mouse_shape->image().size())); + EXPECT_TRUE(DesktopSize(width, height).equals(mouse_shape->image()->size())); // Get the pixels from |scoped_color|. int size = width * height; @@ -66,7 +66,7 @@ bool ConvertToMouseShapeAndCompare(unsigned left, unsigned right) { EXPECT_TRUE(GetBitmapBits(scoped_color, size * sizeof(uint32_t), data.get())); // Compare the 32bpp image in |mouse_shape| with the one loaded from |right|. - return memcmp(data.get(), mouse_shape->image().data(), + return memcmp(data.get(), mouse_shape->image()->data(), size * sizeof(uint32_t)) == 0; }