summaryrefslogtreecommitdiffstats
path: root/remoting/base
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-18 21:42:12 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-18 21:42:12 +0000
commit420a5e4ab23188ab8458c659b331da1d580f6dd7 (patch)
treeccdd9a8f74998b335ea8a96da6e26a633633e9c6 /remoting/base
parent4051754026b9163d6fbbfb329bba3a03a333617c (diff)
downloadchromium_src-420a5e4ab23188ab8458c659b331da1d580f6dd7.zip
chromium_src-420a5e4ab23188ab8458c659b331da1d580f6dd7.tar.gz
chromium_src-420a5e4ab23188ab8458c659b331da1d580f6dd7.tar.bz2
Move screen capturers to remoting/capturer.
Separating screen capturer code from the rest of remoting code so that it can be reused for screen capturing in WebRTC. Also added struct MouseCursorShape to avoid protobuf dependency. BUG=134249 Review URL: https://codereview.chromium.org/11470028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@173789 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/base')
-rw-r--r--remoting/base/capture_data.cc29
-rw-r--r--remoting/base/capture_data.h99
-rw-r--r--remoting/base/shared_buffer.cc37
-rw-r--r--remoting/base/shared_buffer.h69
-rw-r--r--remoting/base/shared_buffer_factory.h28
-rw-r--r--remoting/base/shared_buffer_unittest.cc50
-rw-r--r--remoting/base/util.cc51
-rw-r--r--remoting/base/util.h9
8 files changed, 15 insertions, 357 deletions
diff --git a/remoting/base/capture_data.cc b/remoting/base/capture_data.cc
deleted file mode 100644
index fb0d582..0000000
--- a/remoting/base/capture_data.cc
+++ /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.
-
-#include "remoting/base/capture_data.h"
-
-namespace remoting {
-
-DataPlanes::DataPlanes() {
- for (int i = 0; i < kPlaneCount; ++i) {
- data[i] = NULL;
- strides[i] = 0;
- }
-}
-
-CaptureData::CaptureData(const DataPlanes &data_planes,
- const SkISize& size,
- media::VideoFrame::Format format)
- : data_planes_(data_planes),
- size_(size),
- pixel_format_(format),
- capture_time_ms_(0),
- client_sequence_number_(0),
- dpi_(SkIPoint::Make(0, 0)) {
-}
-
-CaptureData::~CaptureData() {}
-
-} // namespace remoting
diff --git a/remoting/base/capture_data.h b/remoting/base/capture_data.h
deleted file mode 100644
index adab19e..0000000
--- a/remoting/base/capture_data.h
+++ /dev/null
@@ -1,99 +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 REMOTING_BASE_CAPTURE_DATA_H_
-#define REMOTING_BASE_CAPTURE_DATA_H_
-
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/memory/ref_counted.h"
-#include "media/base/video_frame.h"
-#include "remoting/base/shared_buffer.h"
-#include "third_party/skia/include/core/SkRegion.h"
-
-namespace remoting {
-
-class SharedBuffer;
-
-struct DataPlanes {
- DataPlanes();
-
- static const int kPlaneCount = 3;
- uint8* data[kPlaneCount];
- int strides[kPlaneCount];
-};
-
-// Stores the data and information of a capture to pass off to the
-// encoding thread.
-class CaptureData : public base::RefCountedThreadSafe<CaptureData> {
- public:
- CaptureData(const DataPlanes &data_planes,
- const SkISize& size,
- media::VideoFrame::Format format);
-
- // Gets the data_planes data of the previous capture.
- const DataPlanes& data_planes() const { return data_planes_; }
-
- // Gets the dirty region from the previous capture.
- const SkRegion& dirty_region() const { return dirty_region_; }
-
- // Returns the size of the image captured.
- SkISize size() const { return size_; }
-
- // Gets the pixel format of the image captured.
- media::VideoFrame::Format pixel_format() const { return pixel_format_; }
-
- SkRegion& mutable_dirty_region() { return dirty_region_; }
-
- // Returns the time spent on capturing.
- int capture_time_ms() const { return capture_time_ms_; }
-
- // Sets the time spent on capturing.
- void set_capture_time_ms(int capture_time_ms) {
- capture_time_ms_ = capture_time_ms;
- }
-
- int64 client_sequence_number() const { return client_sequence_number_; }
-
- void set_client_sequence_number(int64 client_sequence_number) {
- client_sequence_number_ = client_sequence_number;
- }
-
- SkIPoint dpi() const { return dpi_; }
-
- void set_dpi(const SkIPoint& dpi) { dpi_ = dpi; }
-
- // Returns the shared memory buffer pointed to by |data_planes_.data[0]|.
- scoped_refptr<SharedBuffer> shared_buffer() const { return shared_buffer_; }
-
- // Sets the shared memory buffer pointed to by |data_planes_.data[0]|.
- void set_shared_buffer(scoped_refptr<SharedBuffer> shared_buffer) {
- shared_buffer_ = shared_buffer;
- }
-
- private:
- friend class base::RefCountedThreadSafe<CaptureData>;
- virtual ~CaptureData();
-
- const DataPlanes data_planes_;
- SkRegion dirty_region_;
- SkISize size_;
- media::VideoFrame::Format pixel_format_;
-
- // Time spent in capture. Unit is in milliseconds.
- int capture_time_ms_;
-
- // Sequence number supplied by client for performance tracking.
- int64 client_sequence_number_;
-
- // DPI for this frame.
- SkIPoint dpi_;
-
- scoped_refptr<SharedBuffer> shared_buffer_;
-};
-
-} // namespace remoting
-
-#endif // REMOTING_BASE_CAPTURE_DATA_H_
diff --git a/remoting/base/shared_buffer.cc b/remoting/base/shared_buffer.cc
deleted file mode 100644
index ff0bc93..0000000
--- a/remoting/base/shared_buffer.cc
+++ /dev/null
@@ -1,37 +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.
-
-#include "remoting/base/shared_buffer.h"
-
-const bool kReadOnly = true;
-
-namespace remoting {
-
-SharedBuffer::SharedBuffer(uint32 size)
- : id_(0),
- size_(size) {
- shared_memory_.CreateAndMapAnonymous(size);
-}
-
-SharedBuffer::SharedBuffer(
- int id, base::SharedMemoryHandle handle, uint32 size)
- : id_(id),
- shared_memory_(handle, kReadOnly),
- size_(size) {
- shared_memory_.Map(size);
-}
-
-SharedBuffer::SharedBuffer(
- int id, base::SharedMemoryHandle handle, base::ProcessHandle process,
- uint32 size)
- : id_(id),
- shared_memory_(handle, kReadOnly, process),
- size_(size) {
- shared_memory_.Map(size);
-}
-
-SharedBuffer::~SharedBuffer() {
-}
-
-} // namespace remoting
diff --git a/remoting/base/shared_buffer.h b/remoting/base/shared_buffer.h
deleted file mode 100644
index 7b144d16..0000000
--- a/remoting/base/shared_buffer.h
+++ /dev/null
@@ -1,69 +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 REMOTING_BASE_SHARED_BUFFER_H_
-#define REMOTING_BASE_SHARED_BUFFER_H_
-
-#include "base/basictypes.h"
-#include "base/memory/ref_counted.h"
-#include "base/process.h"
-#include "base/shared_memory.h"
-
-namespace remoting {
-
-// Represents a memory buffer that can be shared between multiple processes.
-// It is more or less a convenience wrapper around base::SharedMemory providing
-// ref-counted lifetime management and unique buffer identifiers.
-class SharedBuffer
- : public base::RefCountedThreadSafe<SharedBuffer> {
- public:
- // Creates a new shared memory buffer of the given size and maps it to
- // the memory of the calling process. If the operation fails for any reason,
- // ptr() method will return NULL. This constructor set the identifier of this
- // buffer to 0.
- explicit SharedBuffer(uint32 size);
-
- // Opens an existing shared memory buffer and maps it to the memory of
- // the calling process (in read only mode). If the operation fails for any
- // reason, ptr() method will return NULL.
- SharedBuffer(int id, base::SharedMemoryHandle handle, uint32 size);
-
- // Opens an existing shared memory buffer created by a different process and
- // maps it to the memory of the calling process (in read only mode). If
- // the operation fails for any reason, ptr() method will return NULL.
- SharedBuffer(int id, base::SharedMemoryHandle handle,
- base::ProcessHandle process, uint32 size);
-
- // Returns pointer to the beginning of the allocated data buffer. Returns NULL
- // if the object initialization failed for any reason.
- void* ptr() const { return shared_memory_.memory(); }
-
- // Returns handle of the shared memory section containing the allocated
- // data buffer.
- base::SharedMemoryHandle handle() const { return shared_memory_.handle(); }
-
- int id() const { return id_; }
- uint32 size() const { return size_; }
-
- void set_id(int id) { id_ = id; }
-
- private:
- friend class base::RefCountedThreadSafe<SharedBuffer>;
- virtual ~SharedBuffer();
-
- // Unique identifier of the buffer or 0 if ID hasn't been set.
- int id_;
-
- // Shared memory section backing up the buffer.
- base::SharedMemory shared_memory_;
-
- // Size of the buffer in bytes.
- uint32 size_;
-
- DISALLOW_COPY_AND_ASSIGN(SharedBuffer);
-};
-
-} // namespace remoting
-
-#endif // REMOTING_BASE_SHARED_BUFFER_H_
diff --git a/remoting/base/shared_buffer_factory.h b/remoting/base/shared_buffer_factory.h
deleted file mode 100644
index bd10a4b..0000000
--- a/remoting/base/shared_buffer_factory.h
+++ /dev/null
@@ -1,28 +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 REMOTING_BASE_SHARED_BUFFER_FACTORY_H_
-#define REMOTING_BASE_SHARED_BUFFER_FACTORY_H_
-
-namespace remoting {
-
-class SharedBuffer;
-
-// Provides a way to create shared buffers accessible by two or more processes.
-class SharedBufferFactory {
- public:
- virtual ~SharedBufferFactory() {}
-
- // 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;
-};
-
-} // namespace remoting
-
-#endif // REMOTING_BASE_SHARED_BUFFER_FACTORY_H_
diff --git a/remoting/base/shared_buffer_unittest.cc b/remoting/base/shared_buffer_unittest.cc
deleted file mode 100644
index bb7e57b..0000000
--- a/remoting/base/shared_buffer_unittest.cc
+++ /dev/null
@@ -1,50 +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.
-
-#include "remoting/base/shared_buffer.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-const uint32 kBufferSize = 4096;
-const int kPattern = 0x12345678;
-
-const int kIdZero = 0;
-const int kIdOne = 1;
-
-namespace remoting {
-
-TEST(SharedBufferTest, Basic) {
- scoped_refptr<SharedBuffer> source(new SharedBuffer(kBufferSize));
-
- // Make sure that the buffer is allocated, the size is recorded correctly and
- // its ID is reset.
- EXPECT_TRUE(source->ptr() != NULL);
- EXPECT_EQ(source->id(), kIdZero);
- EXPECT_EQ(source->size(), kBufferSize);
-
- // See if setting of the ID works.
- source->set_id(kIdOne);
- EXPECT_EQ(source->id(), kIdOne);
-
- scoped_refptr<SharedBuffer> dest(
- new SharedBuffer(kIdZero, source->handle(), kBufferSize));
-
- // Make sure that the buffer is allocated, the size is recorded correctly and
- // its ID is reset.
- EXPECT_TRUE(dest->ptr() != NULL);
- EXPECT_EQ(dest->id(), kIdZero);
- EXPECT_EQ(dest->size(), kBufferSize);
-
- // Verify that the memory contents are the same for the two buffers.
- int* source_ptr = reinterpret_cast<int*>(source->ptr());
- *source_ptr = kPattern;
- int* dest_ptr = reinterpret_cast<int*>(dest->ptr());
- EXPECT_EQ(*source_ptr, *dest_ptr);
-
- // Check that the destination buffer is still mapped even when the source
- // buffer is destroyed.
- source = NULL;
- EXPECT_EQ(0x12345678, *dest_ptr);
-}
-
-} // namespace remoting
diff --git a/remoting/base/util.cc b/remoting/base/util.cc
index 6e656bf..31dda25 100644
--- a/remoting/base/util.cc
+++ b/remoting/base/util.cc
@@ -214,29 +214,6 @@ SkIRect ScaleRect(const SkIRect& rect,
return SkIRect::MakeLTRB(left, top, right, bottom);
}
-void CopyRect(const uint8* src_plane,
- int src_plane_stride,
- uint8* dest_plane,
- int dest_plane_stride,
- int bytes_per_pixel,
- const SkIRect& rect) {
- // Get the address of the starting point.
- const int src_y_offset = src_plane_stride * rect.top();
- const int dest_y_offset = dest_plane_stride * rect.top();
- const int x_offset = bytes_per_pixel * rect.left();
- src_plane += src_y_offset + x_offset;
- dest_plane += dest_y_offset + x_offset;
-
- // Copy pixels in the rectangle line by line.
- const int bytes_per_line = bytes_per_pixel * rect.width();
- const int height = rect.height();
- for (int i = 0 ; i < height; ++i) {
- memcpy(dest_plane, src_plane, bytes_per_line);
- src_plane += src_plane_stride;
- dest_plane += dest_plane_stride;
- }
-}
-
void CopyRGB32Rect(const uint8* source_buffer,
int source_stride,
const SkIRect& source_buffer_rect,
@@ -248,20 +225,20 @@ void CopyRGB32Rect(const uint8* source_buffer,
DCHECK(source_buffer_rect.contains(dest_rect));
// Get the address of the starting point.
- int source_offset = CalculateRGBOffset(dest_rect.x() - source_buffer_rect.x(),
- dest_rect.y() - source_buffer_rect.y(),
- source_stride);
- int dest_offset = CalculateRGBOffset(dest_rect.x() - dest_buffer_rect.x(),
- dest_rect.y() - dest_buffer_rect.y(),
- source_stride);
-
- // Copy bits.
- CopyRect(source_buffer + source_offset,
- source_stride,
- dest_buffer + dest_offset,
- dest_stride,
- kBytesPerPixelRGB32,
- SkIRect::MakeWH(dest_rect.width(), dest_rect.height()));
+ source_buffer += CalculateRGBOffset(dest_rect.x() - source_buffer_rect.x(),
+ dest_rect.y() - source_buffer_rect.y(),
+ source_stride);
+ dest_buffer += CalculateRGBOffset(dest_rect.x() - dest_buffer_rect.x(),
+ dest_rect.y() - dest_buffer_rect.y(),
+ source_stride);
+
+ // Copy pixels in the rectangle line by line.
+ const int bytes_per_line = kBytesPerPixelRGB32 * dest_rect.width();
+ for (int i = 0 ; i < dest_rect.height(); ++i) {
+ memcpy(dest_buffer, source_buffer, bytes_per_line);
+ source_buffer += source_stride;
+ dest_buffer += dest_stride;
+ }
}
std::string ReplaceLfByCrLf(const std::string& in) {
diff --git a/remoting/base/util.h b/remoting/base/util.h
index a627c92..e6abe0f 100644
--- a/remoting/base/util.h
+++ b/remoting/base/util.h
@@ -74,14 +74,7 @@ SkIRect ScaleRect(const SkIRect& rect,
const SkISize& in_size,
const SkISize& out_size);
-// Copy pixels in the rectangle from source to destination.
-void CopyRect(const uint8* src_plane,
- int src_plane_stride,
- uint8* dest_plane,
- int dest_plane_stride,
- int bytes_per_pixel,
- const SkIRect& rect);
-
+// Copy content of a rectangle in a RGB32 image.
void CopyRGB32Rect(const uint8* source_buffer,
int source_stride,
const SkIRect& source_buffer_rect,