summaryrefslogtreecommitdiffstats
path: root/media/video/capture/screen
diff options
context:
space:
mode:
Diffstat (limited to 'media/video/capture/screen')
-rw-r--r--media/video/capture/screen/screen_capturer.h18
-rw-r--r--media/video/capture/screen/screen_capturer_linux.cc16
-rw-r--r--media/video/capture/screen/screen_capturer_mac.mm16
-rw-r--r--media/video/capture/screen/screen_capturer_mac_unittest.cc5
-rw-r--r--media/video/capture/screen/screen_capturer_mock_objects.h2
-rw-r--r--media/video/capture/screen/screen_capturer_unittest.cc31
-rw-r--r--media/video/capture/screen/screen_capturer_win.cc55
-rw-r--r--media/video/capture/screen/shared_buffer_factory.h29
8 files changed, 69 insertions, 103 deletions
diff --git a/media/video/capture/screen/screen_capturer.h b/media/video/capture/screen/screen_capturer.h
index 8183812..1dc2330 100644
--- a/media/video/capture/screen/screen_capturer.h
+++ b/media/video/capture/screen/screen_capturer.h
@@ -7,15 +7,17 @@
#include "base/basictypes.h"
#include "base/callback.h"
+#include "base/memory/ref_counted.h"
#include "base/shared_memory.h"
#include "media/base/media_export.h"
+#include "media/video/capture/screen/shared_buffer.h"
#include "third_party/skia/include/core/SkRegion.h"
namespace media {
class ScreenCaptureData;
struct MouseCursorShape;
-class SharedBufferFactory;
+class SharedBuffer;
// Class used to capture video frames asynchronously.
//
@@ -51,8 +53,16 @@ class MEDIA_EXPORT ScreenCapturer {
public:
// Provides callbacks used by the capturer to pass captured video frames and
// mouse cursor shapes to the processing pipeline.
- class Delegate {
+ class MEDIA_EXPORT Delegate {
public:
+ // Creates a shared memory buffer of the given size. Returns NULL if shared
+ // buffers are not supported.
+ virtual scoped_refptr<SharedBuffer> CreateSharedBuffer(uint32 size);
+
+ // Notifies the delegate that the buffer is no longer used and can be
+ // released.
+ virtual void ReleaseSharedBuffer(scoped_refptr<SharedBuffer> buffer);
+
// Called when a video frame has been captured. |capture_data| describes
// a captured frame.
virtual void OnCaptureCompleted(
@@ -72,10 +82,6 @@ class MEDIA_EXPORT ScreenCapturer {
// Creates platform-specific capturer.
static scoped_ptr<ScreenCapturer> Create();
- // Creates platform-specific capturer that uses shared memory buffers.
- static scoped_ptr<ScreenCapturer> CreateWithFactory(
- SharedBufferFactory* shared_buffer_factory);
-
#if defined(OS_LINUX)
// Creates platform-specific capturer and instructs it whether it should use
// X DAMAGE support.
diff --git a/media/video/capture/screen/screen_capturer_linux.cc b/media/video/capture/screen/screen_capturer_linux.cc
index 1c34f42..ed45d05 100644
--- a/media/video/capture/screen/screen_capturer_linux.cc
+++ b/media/video/capture/screen/screen_capturer_linux.cc
@@ -587,6 +587,15 @@ void ScreenCapturerLinux::SlowBlit(uint8* image, const SkIRect& rect,
} // namespace
+scoped_refptr<SharedBuffer> ScreenCapturer::Delegate::CreateSharedBuffer(
+ uint32 size) {
+ return scoped_refptr<SharedBuffer>();
+}
+
+void ScreenCapturer::Delegate::ReleaseSharedBuffer(
+ scoped_refptr<SharedBuffer> buffer) {
+}
+
// static
scoped_ptr<ScreenCapturer> ScreenCapturer::Create() {
scoped_ptr<ScreenCapturerLinux> capturer(new ScreenCapturerLinux());
@@ -596,13 +605,6 @@ scoped_ptr<ScreenCapturer> ScreenCapturer::Create() {
}
// static
-scoped_ptr<ScreenCapturer> ScreenCapturer::CreateWithFactory(
- SharedBufferFactory* shared_buffer_factory) {
- NOTIMPLEMENTED();
- return scoped_ptr<ScreenCapturer>();
-}
-
-// static
scoped_ptr<ScreenCapturer> ScreenCapturer::CreateWithXDamage(
bool use_x_damage) {
scoped_ptr<ScreenCapturerLinux> capturer(new ScreenCapturerLinux());
diff --git a/media/video/capture/screen/screen_capturer_mac.mm b/media/video/capture/screen/screen_capturer_mac.mm
index 6a109db..52e36f1 100644
--- a/media/video/capture/screen/screen_capturer_mac.mm
+++ b/media/video/capture/screen/screen_capturer_mac.mm
@@ -854,6 +854,15 @@ void ScreenCapturerMac::DisplaysReconfiguredCallback(
} // namespace
+scoped_refptr<SharedBuffer> ScreenCapturer::Delegate::CreateSharedBuffer(
+ uint32 size) {
+ return scoped_refptr<SharedBuffer>();
+}
+
+void ScreenCapturer::Delegate::ReleaseSharedBuffer(
+ scoped_refptr<SharedBuffer> buffer) {
+}
+
// static
scoped_ptr<ScreenCapturer> ScreenCapturer::Create() {
scoped_ptr<ScreenCapturerMac> capturer(new ScreenCapturerMac());
@@ -862,11 +871,4 @@ scoped_ptr<ScreenCapturer> ScreenCapturer::Create() {
return capturer.PassAs<ScreenCapturer>();
}
-// static
-scoped_ptr<ScreenCapturer> ScreenCapturer::CreateWithFactory(
- SharedBufferFactory* shared_buffer_factory) {
- NOTIMPLEMENTED();
- return scoped_ptr<ScreenCapturer>();
-}
-
} // namespace media
diff --git a/media/video/capture/screen/screen_capturer_mac_unittest.cc b/media/video/capture/screen/screen_capturer_mac_unittest.cc
index a62d40b..f683894 100644
--- a/media/video/capture/screen/screen_capturer_mac_unittest.cc
+++ b/media/video/capture/screen/screen_capturer_mac_unittest.cc
@@ -17,6 +17,7 @@
using ::testing::_;
using ::testing::AnyNumber;
+using ::testing::Return;
namespace media {
@@ -90,6 +91,10 @@ TEST_F(ScreenCapturerMacTest, Capture) {
EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_))
.Times(AnyNumber());
+ EXPECT_CALL(delegate_, CreateSharedBuffer(_))
+ .Times(AnyNumber())
+ .WillRepeatedly(Return(scoped_refptr<SharedBuffer>()));
+
SCOPED_TRACE("");
capturer_->Start(&delegate_);
diff --git a/media/video/capture/screen/screen_capturer_mock_objects.h b/media/video/capture/screen/screen_capturer_mock_objects.h
index 36bf3fb..4bf9890 100644
--- a/media/video/capture/screen/screen_capturer_mock_objects.h
+++ b/media/video/capture/screen/screen_capturer_mock_objects.h
@@ -33,6 +33,8 @@ class MockScreenCapturerDelegate : public ScreenCapturer::Delegate {
void OnCursorShapeChanged(scoped_ptr<MouseCursorShape> cursor_shape) OVERRIDE;
+ MOCK_METHOD1(CreateSharedBuffer, scoped_refptr<SharedBuffer>(uint32));
+ MOCK_METHOD1(ReleaseSharedBuffer, void(scoped_refptr<SharedBuffer>));
MOCK_METHOD1(OnCaptureCompleted, void(scoped_refptr<ScreenCaptureData>));
MOCK_METHOD1(OnCursorShapeChangedPtr,
void(MouseCursorShape* cursor_shape));
diff --git a/media/video/capture/screen/screen_capturer_unittest.cc b/media/video/capture/screen/screen_capturer_unittest.cc
index be08749..b135ed0 100644
--- a/media/video/capture/screen/screen_capturer_unittest.cc
+++ b/media/video/capture/screen/screen_capturer_unittest.cc
@@ -10,27 +10,15 @@
#endif // defined(OS_MACOSX)
#include "media/video/capture/screen/screen_capture_data.h"
#include "media/video/capture/screen/screen_capturer_mock_objects.h"
-#include "media/video/capture/screen/shared_buffer_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::_;
using ::testing::AnyNumber;
+using ::testing::Return;
namespace media {
-class MockSharedBufferFactory : public SharedBufferFactory {
- public:
- MockSharedBufferFactory() {}
- virtual ~MockSharedBufferFactory() {}
-
- MOCK_METHOD1(CreateSharedBuffer, scoped_refptr<SharedBuffer>(uint32));
- MOCK_METHOD1(ReleaseSharedBuffer, void(scoped_refptr<SharedBuffer>));
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MockSharedBufferFactory);
-};
-
MATCHER(DirtyRegionIsNonEmptyRect, "") {
const SkRegion& dirty_region = arg->dirty_region();
const SkIRect& dirty_region_bounds = dirty_region.getBounds();
@@ -46,7 +34,6 @@ class ScreenCapturerTest : public testing::Test {
protected:
scoped_ptr<ScreenCapturer> capturer_;
- MockSharedBufferFactory shared_buffer_factory_;
MockScreenCapturerDelegate delegate_;
};
@@ -74,6 +61,10 @@ TEST_F(ScreenCapturerTest, MAYBE_Capture) {
EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_))
.Times(AnyNumber());
+ EXPECT_CALL(delegate_, CreateSharedBuffer(_))
+ .Times(AnyNumber())
+ .WillRepeatedly(Return(scoped_refptr<SharedBuffer>()));
+
capturer_ = ScreenCapturer::Create();
capturer_->Start(&delegate_);
capturer_->CaptureFrame();
@@ -88,13 +79,13 @@ TEST_F(ScreenCapturerTest, UseSharedBuffers) {
EXPECT_CALL(delegate_, OnCursorShapeChangedPtr(_))
.Times(AnyNumber());
- EXPECT_CALL(shared_buffer_factory_, CreateSharedBuffer(_))
- .Times(1)
- .WillOnce(Invoke(this, &ScreenCapturerTest::CreateSharedBuffer));
- EXPECT_CALL(shared_buffer_factory_, ReleaseSharedBuffer(_))
- .Times(1);
+ EXPECT_CALL(delegate_, CreateSharedBuffer(_))
+ .Times(AnyNumber())
+ .WillRepeatedly(Invoke(this, &ScreenCapturerTest::CreateSharedBuffer));
+ EXPECT_CALL(delegate_, ReleaseSharedBuffer(_))
+ .Times(AnyNumber());
- capturer_ = ScreenCapturer::CreateWithFactory(&shared_buffer_factory_);
+ capturer_ = ScreenCapturer::Create();
capturer_->Start(&delegate_);
capturer_->CaptureFrame();
capturer_->Stop();
diff --git a/media/video/capture/screen/screen_capturer_win.cc b/media/video/capture/screen/screen_capturer_win.cc
index bf6bfae..796af5f 100644
--- a/media/video/capture/screen/screen_capturer_win.cc
+++ b/media/video/capture/screen/screen_capturer_win.cc
@@ -23,7 +23,6 @@
#include "media/video/capture/screen/screen_capture_frame.h"
#include "media/video/capture/screen/screen_capture_frame_queue.h"
#include "media/video/capture/screen/screen_capturer_helper.h"
-#include "media/video/capture/screen/shared_buffer_factory.h"
#include "media/video/capture/screen/win/desktop.h"
#include "media/video/capture/screen/win/scoped_thread_desktop.h"
#include "third_party/skia/include/core/SkColorPriv.h"
@@ -49,7 +48,7 @@ const uint32 kPixelBgraTransparent = 0x00000000;
class ScreenCaptureFrameWin : public ScreenCaptureFrame {
public:
ScreenCaptureFrameWin(HDC desktop_dc, const SkISize& size,
- SharedBufferFactory* shared_buffer_factory);
+ ScreenCapturer::Delegate* delegate);
virtual ~ScreenCaptureFrameWin();
// Returns handle of the device independent bitmap representing this frame
@@ -65,8 +64,8 @@ class ScreenCaptureFrameWin : public ScreenCaptureFrame {
// GDI.
base::win::ScopedBitmap bitmap_;
- // Used to allocate shared memory buffers if set.
- SharedBufferFactory* shared_buffer_factory_;
+ // Used to work with shared memory buffers.
+ ScreenCapturer::Delegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(ScreenCaptureFrameWin);
};
@@ -77,7 +76,6 @@ class ScreenCaptureFrameWin : public ScreenCaptureFrame {
class ScreenCapturerWin : public ScreenCapturer {
public:
ScreenCapturerWin();
- explicit ScreenCapturerWin(SharedBufferFactory* shared_buffer_factory);
virtual ~ScreenCapturerWin();
// Overridden from ScreenCapturer:
@@ -105,9 +103,6 @@ class ScreenCapturerWin : public ScreenCapturer {
// Capture the current cursor shape.
void CaptureCursor();
- // Used to allocate shared memory buffers if set.
- SharedBufferFactory* shared_buffer_factory_;
-
Delegate* delegate_;
// A thread-safe list of invalid rectangles, and the size of the most
@@ -146,14 +141,14 @@ static const int kPixelsPerMeter = 3780;
ScreenCaptureFrameWin::ScreenCaptureFrameWin(
HDC desktop_dc,
const SkISize& size,
- SharedBufferFactory* shared_buffer_factory)
- : shared_buffer_factory_(shared_buffer_factory) {
- // Allocate a shared memory buffer.
+ ScreenCapturer::Delegate* delegate)
+ : delegate_(delegate) {
+ // Try to allocate a shared memory buffer.
uint32 buffer_size =
size.width() * size.height() * ScreenCaptureData::kBytesPerPixel;
- if (shared_buffer_factory_) {
- scoped_refptr<SharedBuffer> shared_buffer =
- shared_buffer_factory_->CreateSharedBuffer(buffer_size);
+ scoped_refptr<SharedBuffer> shared_buffer =
+ delegate_->CreateSharedBuffer(buffer_size);
+ if (shared_buffer) {
CHECK(shared_buffer->ptr() != NULL);
set_shared_buffer(shared_buffer);
}
@@ -163,7 +158,7 @@ ScreenCaptureFrameWin::ScreenCaptureFrameWin(
ScreenCaptureFrameWin::~ScreenCaptureFrameWin() {
if (shared_buffer())
- shared_buffer_factory_->ReleaseSharedBuffer(shared_buffer());
+ delegate_->ReleaseSharedBuffer(shared_buffer());
}
HBITMAP ScreenCaptureFrameWin::GetBitmap() {
@@ -206,16 +201,7 @@ void ScreenCaptureFrameWin::AllocateBitmap(HDC desktop_dc,
}
ScreenCapturerWin::ScreenCapturerWin()
- : shared_buffer_factory_(NULL),
- delegate_(NULL),
- desktop_dc_rect_(SkIRect::MakeEmpty()),
- composition_func_(NULL) {
-}
-
-ScreenCapturerWin::ScreenCapturerWin(
- SharedBufferFactory* shared_buffer_factory)
- : shared_buffer_factory_(shared_buffer_factory),
- delegate_(NULL),
+ : delegate_(NULL),
desktop_dc_rect_(SkIRect::MakeEmpty()),
composition_func_(NULL) {
}
@@ -380,7 +366,7 @@ void ScreenCapturerWin::CaptureImage() {
SkISize size = SkISize::Make(desktop_dc_rect_.width(),
desktop_dc_rect_.height());
scoped_ptr<ScreenCaptureFrameWin> buffer(
- new ScreenCaptureFrameWin(*desktop_dc_, size, shared_buffer_factory_));
+ new ScreenCaptureFrameWin(*desktop_dc_, size, delegate_));
queue_.ReplaceCurrentFrame(buffer.PassAs<ScreenCaptureFrame>());
}
@@ -583,17 +569,18 @@ void ScreenCapturerWin::CaptureCursor() {
} // namespace
-// static
-scoped_ptr<ScreenCapturer> ScreenCapturer::Create() {
- return scoped_ptr<ScreenCapturer>(new ScreenCapturerWin());
+scoped_refptr<SharedBuffer> ScreenCapturer::Delegate::CreateSharedBuffer(
+ uint32 size) {
+ return scoped_refptr<SharedBuffer>();
+}
+
+void ScreenCapturer::Delegate::ReleaseSharedBuffer(
+ scoped_refptr<SharedBuffer> buffer) {
}
// static
-scoped_ptr<ScreenCapturer> ScreenCapturer::CreateWithFactory(
- SharedBufferFactory* shared_buffer_factory) {
- scoped_ptr<ScreenCapturerWin> capturer(
- new ScreenCapturerWin(shared_buffer_factory));
- return capturer.PassAs<ScreenCapturer>();
+scoped_ptr<ScreenCapturer> ScreenCapturer::Create() {
+ return scoped_ptr<ScreenCapturer>(new ScreenCapturerWin());
}
} // namespace media
diff --git a/media/video/capture/screen/shared_buffer_factory.h b/media/video/capture/screen/shared_buffer_factory.h
deleted file mode 100644
index f5bafc6..0000000
--- a/media/video/capture/screen/shared_buffer_factory.h
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef MEDIA_VIDEO_CAPTURE_SCREEN_SHARED_BUFFER_FACTORY_H_
-#define MEDIA_VIDEO_CAPTURE_SCREEN_SHARED_BUFFER_FACTORY_H_
-
-namespace media {
-
-class SharedBuffer;
-
-// Provides a way to create shared buffers accessible by two or more processes.
-class SharedBufferFactory {
- public:
- // Creates a shared memory buffer of the given size.
- virtual scoped_refptr<SharedBuffer> CreateSharedBuffer(uint32 size) = 0;
-
- // Notifies the factory that the buffer is no longer used by the caller and
- // can be released. The caller still has to drop all references to free
- // the memory.
- virtual void ReleaseSharedBuffer(scoped_refptr<SharedBuffer> buffer) = 0;
-
- protected:
- virtual ~SharedBufferFactory() {}
-};
-
-} // namespace media
-
-#endif // MEDIA_VIDEO_CAPTURE_SCREEN_SHARED_BUFFER_FACTORY_H_