summaryrefslogtreecommitdiffstats
path: root/remoting/base
diff options
context:
space:
mode:
Diffstat (limited to 'remoting/base')
-rw-r--r--remoting/base/capture_data.cc3
-rw-r--r--remoting/base/capture_data.h14
-rw-r--r--remoting/base/codec_test.cc58
-rw-r--r--remoting/base/decoder.h2
-rw-r--r--remoting/base/encoder_row_based.cc21
-rw-r--r--remoting/base/encoder_row_based.h10
-rw-r--r--remoting/base/encoder_vp8.cc9
-rw-r--r--remoting/base/types.h21
-rw-r--r--remoting/base/util.cc8
-rw-r--r--remoting/base/util.h3
10 files changed, 69 insertions, 80 deletions
diff --git a/remoting/base/capture_data.cc b/remoting/base/capture_data.cc
index 1740447..b66b239 100644
--- a/remoting/base/capture_data.cc
+++ b/remoting/base/capture_data.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -17,7 +17,6 @@ CaptureData::CaptureData(const DataPlanes &data_planes,
const gfx::Size& size,
media::VideoFrame::Format format)
: data_planes_(data_planes),
- dirty_rects_(),
size_(size),
pixel_format_(format),
capture_time_ms_(0),
diff --git a/remoting/base/capture_data.h b/remoting/base/capture_data.h
index b8592fa..ae5b89e 100644
--- a/remoting/base/capture_data.h
+++ b/remoting/base/capture_data.h
@@ -10,7 +10,8 @@
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "media/base/video_frame.h"
-#include "remoting/base/types.h"
+#include "third_party/skia/include/core/SkRegion.h"
+#include "ui/gfx/size.h"
namespace remoting {
@@ -30,12 +31,11 @@ class CaptureData : public base::RefCountedThreadSafe<CaptureData> {
const gfx::Size& size,
media::VideoFrame::Format format);
- // Get the data_planes data of the last capture.
+ // Get the data_planes data of the previous capture.
const DataPlanes& data_planes() const { return data_planes_; }
- // Get the list of updated rectangles in the last capture. The result is
- // written into |rects|.
- const InvalidRects& dirty_rects() const { return dirty_rects_; }
+ // Get the dirty region from the previous capture.
+ const SkRegion& dirty_region() const { return dirty_region_; }
// Return the size of the image captured.
gfx::Size size() const { return size_; }
@@ -44,7 +44,7 @@ class CaptureData : public base::RefCountedThreadSafe<CaptureData> {
media::VideoFrame::Format pixel_format() const { return pixel_format_; }
// Mutating methods.
- InvalidRects& mutable_dirty_rects() { return dirty_rects_; }
+ SkRegion& mutable_dirty_region() { return dirty_region_; }
// Return the time spent on capturing.
int capture_time_ms() const { return capture_time_ms_; }
@@ -62,7 +62,7 @@ class CaptureData : public base::RefCountedThreadSafe<CaptureData> {
private:
const DataPlanes data_planes_;
- InvalidRects dirty_rects_;
+ SkRegion dirty_region_;
gfx::Size size_;
media::VideoFrame::Format pixel_format_;
diff --git a/remoting/base/codec_test.cc b/remoting/base/codec_test.cc
index d1b4978..0b62a63 100644
--- a/remoting/base/codec_test.cc
+++ b/remoting/base/codec_test.cc
@@ -1,10 +1,11 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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 <deque>
#include <stdlib.h>
+#include "base/memory/scoped_ptr.h"
#include "media/base/video_frame.h"
#include "remoting/base/base_mock_objects.h"
#include "remoting/base/codec_test.h"
@@ -12,19 +13,18 @@
#include "remoting/base/encoder.h"
#include "remoting/base/util.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gfx/rect.h"
static const int kWidth = 320;
static const int kHeight = 240;
static const int kBytesPerPixel = 4;
// Some sample rects for testing.
-static const gfx::Rect kTestRects[] = {
- gfx::Rect(0, 0, kWidth, kHeight),
- gfx::Rect(0, 0, kWidth / 2, kHeight / 2),
- gfx::Rect(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2),
- gfx::Rect(16, 16, 16, 16),
- gfx::Rect(128, 64, 32, 32),
+static const SkIRect kTestRects[] = {
+ SkIRect::MakeXYWH(0, 0, kWidth, kHeight),
+ SkIRect::MakeXYWH(0, 0, kWidth / 2, kHeight / 2),
+ SkIRect::MakeXYWH(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2),
+ SkIRect::MakeXYWH(16, 16, 16, 16),
+ SkIRect::MakeXYWH(128, 64, 32, 32),
};
namespace remoting {
@@ -58,10 +58,10 @@ class EncoderMessageTester {
++begin_rect_;
if (strict_) {
- gfx::Rect rect = rects_.front();
+ SkIRect rect = rects_.front();
rects_.pop_front();
- EXPECT_EQ(rect.x(), packet->format().x());
- EXPECT_EQ(rect.y(), packet->format().y());
+ EXPECT_EQ(rect.fLeft, packet->format().x());
+ EXPECT_EQ(rect.fTop, packet->format().y());
EXPECT_EQ(rect.width(), packet->format().width());
EXPECT_EQ(rect.height(), packet->format().height());
}
@@ -93,7 +93,7 @@ class EncoderMessageTester {
strict_ = strict;
}
- void AddRects(const gfx::Rect* rects, int count) {
+ void AddRects(const SkIRect* rects, int count) {
rects_.insert(rects_.begin() + rects_.size(), rects, rects + count);
added_rects_ += count;
}
@@ -111,7 +111,7 @@ class EncoderMessageTester {
State state_;
bool strict_;
- std::deque<gfx::Rect> rects_;
+ std::deque<SkIRect> rects_;
DISALLOW_COPY_AND_ASSIGN(EncoderMessageTester);
};
@@ -152,7 +152,7 @@ class DecoderTester {
capture_data_ = data;
}
- void AddRects(const gfx::Rect* rects, int count) {
+ void AddRects(const SkIRect* rects, int count) {
rects_.insert(rects_.begin() + rects_.size(), rects, rects + count);
}
@@ -165,7 +165,8 @@ class DecoderTester {
// Test the content of the update rect.
ASSERT_EQ(rects_.size(), update_rects_.size());
for (size_t i = 0; i < update_rects_.size(); ++i) {
- gfx::Rect rect = rects_[i];
+ SkIRect &r = rects_[i];
+ gfx::Rect rect(r.fLeft, r.fTop, r.width(), r.height());
EXPECT_EQ(rect, update_rects_[i]);
EXPECT_EQ(frame_->stride(0), capture_data_->data_planes().strides[0]);
@@ -186,7 +187,7 @@ class DecoderTester {
private:
bool strict_;
- std::deque<gfx::Rect> rects_;
+ std::deque<SkIRect> rects_;
UpdatedRects update_rects_;
Decoder* decoder_;
scoped_refptr<media::VideoFrame> frame_;
@@ -221,7 +222,7 @@ class EncoderTester {
delete packet;
}
- void AddRects(const gfx::Rect* rects, int count) {
+ void AddRects(const SkIRect* rects, int count) {
message_tester_->AddRects(rects, count);
}
@@ -263,10 +264,10 @@ scoped_refptr<CaptureData> PrepareEncodeData(media::VideoFrame::Format format,
static void TestEncodingRects(Encoder* encoder,
EncoderTester* tester,
scoped_refptr<CaptureData> data,
- const gfx::Rect* rects, int count) {
- data->mutable_dirty_rects().clear();
+ const SkIRect* rects, int count) {
+ data->mutable_dirty_region().setEmpty();
for (int i = 0; i < count; ++i) {
- data->mutable_dirty_rects().insert(rects[i]);
+ data->mutable_dirty_region().op(rects[i], SkRegion::kUnion_Op);
}
tester->AddRects(rects, count);
@@ -283,22 +284,22 @@ void TestEncoder(Encoder* encoder, bool strict) {
uint8* memory;
scoped_refptr<CaptureData> data =
PrepareEncodeData(media::VideoFrame::RGB32, &memory);
+ scoped_array<uint8> memory_wrapper(memory);
TestEncodingRects(encoder, &tester, data, kTestRects, 1);
TestEncodingRects(encoder, &tester, data, kTestRects + 1, 1);
TestEncodingRects(encoder, &tester, data, kTestRects + 2, 1);
TestEncodingRects(encoder, &tester, data, kTestRects + 3, 2);
- delete [] memory;
}
static void TestEncodingRects(Encoder* encoder,
EncoderTester* encoder_tester,
DecoderTester* decoder_tester,
scoped_refptr<CaptureData> data,
- const gfx::Rect* rects, int count) {
- data->mutable_dirty_rects().clear();
+ const SkIRect* rects, int count) {
+ data->mutable_dirty_region().setEmpty();
for (int i = 0; i < count; ++i) {
- data->mutable_dirty_rects().insert(rects[i]);
+ data->mutable_dirty_region().op(rects[i], SkRegion::kUnion_Op);
}
encoder_tester->AddRects(rects, count);
decoder_tester->AddRects(rects, count);
@@ -306,12 +307,12 @@ static void TestEncodingRects(Encoder* encoder,
// Generate random data for the updated rects.
srand(0);
for (int i = 0; i < count; ++i) {
- const gfx::Rect rect = rects[i];
+ const SkIRect& rect = rects[i];
const int bytes_per_pixel = GetBytesPerPixel(data->pixel_format());
const int row_size = bytes_per_pixel * rect.width();
uint8* memory = data->data_planes().data[0] +
- data->data_planes().strides[0] * rect.y() +
- bytes_per_pixel * rect.x();
+ data->data_planes().strides[0] * rect.fTop +
+ bytes_per_pixel * rect.fLeft;
for (int y = 0; y < rect.height(); ++y) {
for (int x = 0; x < row_size; ++x)
memory[x] = rand() % 256;
@@ -334,6 +335,8 @@ void TestEncoderDecoder(Encoder* encoder, Decoder* decoder, bool strict) {
uint8* memory;
scoped_refptr<CaptureData> data =
PrepareEncodeData(media::VideoFrame::RGB32, &memory);
+ scoped_array<uint8> memory_wrapper(memory);
+
DecoderTester decoder_tester(decoder);
decoder_tester.set_strict(strict);
decoder_tester.set_capture_data(data);
@@ -347,7 +350,6 @@ void TestEncoderDecoder(Encoder* encoder, Decoder* decoder, bool strict) {
kTestRects + 2, 1);
TestEncodingRects(encoder, &encoder_tester, &decoder_tester, data,
kTestRects + 3, 2);
- delete [] memory;
}
} // namespace remoting
diff --git a/remoting/base/decoder.h b/remoting/base/decoder.h
index a0a9244..b13483f 100644
--- a/remoting/base/decoder.h
+++ b/remoting/base/decoder.h
@@ -46,6 +46,8 @@ class Decoder {
// Returns rects that were updated in the last frame. Can be called only
// after DecodePacket returned DECODE_DONE. Caller keeps ownership of
// |rects|. |rects| is kept empty if whole screen needs to be updated.
+ // TODO(dmaclach): Move this over to using SkRegion.
+ // http://crbug.com/92085
virtual void GetUpdatedRects(UpdatedRects* rects) = 0;
// Reset the decoder to an uninitialized state. Release all references to
diff --git a/remoting/base/encoder_row_based.cc b/remoting/base/encoder_row_based.cc
index 8039869..75af34a 100644
--- a/remoting/base/encoder_row_based.cc
+++ b/remoting/base/encoder_row_based.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -66,16 +66,19 @@ void EncoderRowBased::Encode(scoped_refptr<CaptureData> capture_data,
capture_data_ = capture_data;
callback_.reset(data_available_callback);
- const InvalidRects& rects = capture_data->dirty_rects();
- for (InvalidRects::const_iterator r = rects.begin(); r != rects.end(); ++r) {
- EncodeRect(*r, r == --rects.end());
+ const SkRegion& region = capture_data->dirty_region();
+ SkRegion::Iterator iter(region);
+ while (!iter.done()) {
+ SkIRect rect = iter.rect();
+ iter.next();
+ EncodeRect(rect, iter.done());
}
capture_data_ = NULL;
callback_.reset();
}
-void EncoderRowBased::EncodeRect(const gfx::Rect& rect, bool last) {
+void EncoderRowBased::EncodeRect(const SkIRect& rect, bool last) {
CHECK(capture_data_->data_planes().data[0]);
const int strides = capture_data_->data_planes().strides[0];
const int bytes_per_pixel = GetBytesPerPixel(capture_data_->pixel_format());
@@ -86,7 +89,7 @@ void EncoderRowBased::EncodeRect(const gfx::Rect& rect, bool last) {
VideoPacket* packet = new VideoPacket();
PrepareUpdateStart(rect, packet);
const uint8* in = capture_data_->data_planes().data[0] +
- rect.y() * strides + rect.x() * bytes_per_pixel;
+ rect.fTop * strides + rect.fLeft * bytes_per_pixel;
// TODO(hclam): Fill in the sequence number.
uint8* out = GetOutputBuffer(packet, packet_size_);
int filled = 0;
@@ -142,13 +145,13 @@ void EncoderRowBased::EncodeRect(const gfx::Rect& rect, bool last) {
}
}
-void EncoderRowBased::PrepareUpdateStart(const gfx::Rect& rect,
+void EncoderRowBased::PrepareUpdateStart(const SkIRect& rect,
VideoPacket* packet) {
packet->set_flags(packet->flags() | VideoPacket::FIRST_PACKET);
VideoPacketFormat* format = packet->mutable_format();
- format->set_x(rect.x());
- format->set_y(rect.y());
+ format->set_x(rect.fLeft);
+ format->set_y(rect.fTop);
format->set_width(rect.width());
format->set_height(rect.height());
format->set_encoding(encoding_);
diff --git a/remoting/base/encoder_row_based.h b/remoting/base/encoder_row_based.h
index d453ffb..6da2cd5 100644
--- a/remoting/base/encoder_row_based.h
+++ b/remoting/base/encoder_row_based.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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.
@@ -7,8 +7,8 @@
#include "remoting/base/encoder.h"
#include "remoting/proto/video.pb.h"
-
-#include "ui/gfx/rect.h"
+#include "third_party/skia/include/core/SkRect.h"
+#include "ui/gfx/size.h"
namespace remoting {
@@ -41,10 +41,10 @@ class EncoderRowBased : public Encoder {
int packet_size);
// Encode a single dirty rect using compressor.
- void EncodeRect(const gfx::Rect& rect, bool last);
+ void EncodeRect(const SkIRect& rect, bool last);
// Marks a packet as the first in a series of rectangle updates.
- void PrepareUpdateStart(const gfx::Rect& rect, VideoPacket* packet);
+ void PrepareUpdateStart(const SkIRect& rect, VideoPacket* packet);
// Retrieves a pointer to the output buffer in |update| used for storing the
// encoded rectangle data. Will resize the buffer to |size|.
diff --git a/remoting/base/encoder_vp8.cc b/remoting/base/encoder_vp8.cc
index 447e5d5..5616bba 100644
--- a/remoting/base/encoder_vp8.cc
+++ b/remoting/base/encoder_vp8.cc
@@ -10,6 +10,7 @@
#include "remoting/base/capture_data.h"
#include "remoting/base/util.h"
#include "remoting/proto/video.pb.h"
+#include "third_party/skia/include/core/SkRegion.h"
extern "C" {
#define VPX_CODEC_DISABLE_COMPAT 1
@@ -148,7 +149,7 @@ bool EncoderVp8::PrepareImage(scoped_refptr<CaptureData> capture_data,
return false;
}
- const InvalidRects& rects = capture_data->dirty_rects();
+ const SkRegion& region = capture_data->dirty_region();
const uint8* in = capture_data->data_planes().data[0];
const int in_stride = capture_data->data_planes().strides[0];
const int plane_size =
@@ -160,9 +161,11 @@ bool EncoderVp8::PrepareImage(scoped_refptr<CaptureData> capture_data,
const int uv_stride = image_->stride[1];
DCHECK(updated_rects->empty());
- for (InvalidRects::const_iterator r = rects.begin(); r != rects.end(); ++r) {
+ for (SkRegion::Iterator r(region); !r.done(); r.next()) {
// Align the rectangle, report it as updated.
- gfx::Rect rect = AlignAndClipRect(*r, image_->w, image_->h);
+ SkIRect skRect = r.rect();
+ gfx::Rect rect(skRect.fLeft, skRect.fTop, skRect.width(), skRect.height());
+ rect = AlignAndClipRect(rect, image_->w, image_->h);
if (!rect.IsEmpty())
updated_rects->push_back(rect);
diff --git a/remoting/base/types.h b/remoting/base/types.h
deleted file mode 100644
index 1c93f6f..0000000
--- a/remoting/base/types.h
+++ /dev/null
@@ -1,21 +0,0 @@
-// Copyright (c) 2010 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_TYPES_H_
-#define REMOTING_BASE_TYPES_H_
-
-#include <set>
-
-#include "ui/gfx/rect.h"
-
-namespace remoting {
-
-// The collection of 'invalid' screen rectangles.
-// This is used to keep track of regions of the screen that require
-// updating.
-typedef std::set<gfx::Rect> InvalidRects;
-
-} // namespace remoting
-
-#endif // REMOTING_BASE_TYPES_H_
diff --git a/remoting/base/util.cc b/remoting/base/util.cc
index 8671eeb..483d97f 100644
--- a/remoting/base/util.cc
+++ b/remoting/base/util.cc
@@ -161,11 +161,11 @@ void CopyRect(const uint8* src_plane,
uint8* dest_plane,
int dest_plane_stride,
int bytes_per_pixel,
- const gfx::Rect& rect) {
+ const SkIRect& rect) {
// Get the address of the starting point.
- const int src_y_offset = src_plane_stride * rect.y();
- const int dest_y_offset = dest_plane_stride * rect.y();
- const int x_offset = bytes_per_pixel * rect.x();
+ const int src_y_offset = src_plane_stride * rect.fTop;
+ const int dest_y_offset = dest_plane_stride * rect.fTop;
+ const int x_offset = bytes_per_pixel * rect.fLeft;
src_plane += src_y_offset + x_offset;
dest_plane += dest_y_offset + x_offset;
diff --git a/remoting/base/util.h b/remoting/base/util.h
index d0e0b0d..262b551 100644
--- a/remoting/base/util.h
+++ b/remoting/base/util.h
@@ -6,6 +6,7 @@
#define REMOTING_BASE_UTIL_H_
#include "media/base/video_frame.h"
+#include "third_party/skia/include/core/SkRect.h"
#include "ui/gfx/rect.h"
namespace remoting {
@@ -64,7 +65,7 @@ void CopyRect(const uint8* src_plane,
uint8* dest_plane,
int dest_plane_stride,
int bytes_per_pixel,
- const gfx::Rect& rect);
+ const SkIRect& rect);
} // namespace remoting