summaryrefslogtreecommitdiffstats
path: root/remoting/codec
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-25 22:16:21 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-25 22:16:21 +0000
commite59d6594e14b9a697098cc517f7218941e2787ff (patch)
treee04cc296501d095e24acfb5357c5af5bacebca82 /remoting/codec
parent1f291cd57a56e70369dc2e47e3d4be6102254102 (diff)
downloadchromium_src-e59d6594e14b9a697098cc517f7218941e2787ff.zip
chromium_src-e59d6594e14b9a697098cc517f7218941e2787ff.tar.gz
chromium_src-e59d6594e14b9a697098cc517f7218941e2787ff.tar.bz2
Remove dependency on Skia from chromoting client.
Now DesktopRegion, DesktopRect and DesktopSize are used instead of corresponding skia types. R=alexeypa@chromium.org TBR=reed@google.com (for _moved_ skia dependency) Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=224101 Review URL: https://codereview.chromium.org/23440046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@225265 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/codec')
-rw-r--r--remoting/codec/codec_test.cc31
-rw-r--r--remoting/codec/video_decoder.h23
-rw-r--r--remoting/codec/video_decoder_verbatim.cc67
-rw-r--r--remoting/codec/video_decoder_verbatim.h20
-rw-r--r--remoting/codec/video_decoder_vp8.cc155
-rw-r--r--remoting/codec/video_decoder_vp8.h30
-rw-r--r--remoting/codec/video_encoder_vp8.cc46
-rw-r--r--remoting/codec/video_encoder_vp8.h6
8 files changed, 198 insertions, 180 deletions
diff --git a/remoting/codec/codec_test.cc b/remoting/codec/codec_test.cc
index eebe263..e63ec3e 100644
--- a/remoting/codec/codec_test.cc
+++ b/remoting/codec/codec_test.cc
@@ -64,12 +64,12 @@ class VideoDecoderTester {
view_size_.width() * view_size_.height() * kBytesPerPixel]);
EXPECT_TRUE(image_data_.get());
decoder_->Initialize(
- SkISize::Make(screen_size_.width(), screen_size_.height()));
+ webrtc::DesktopSize(screen_size_.width(), screen_size_.height()));
}
void Reset() {
expected_region_.Clear();
- update_region_.setEmpty();
+ update_region_.Clear();
}
void ResetRenderedData() {
@@ -85,10 +85,9 @@ class VideoDecoderTester {
void RenderFrame() {
decoder_->RenderFrame(
- SkISize::Make(view_size_.width(), view_size_.height()),
- SkIRect::MakeWH(view_size_.width(), view_size_.height()),
- image_data_.get(),
- view_size_.width() * kBytesPerPixel,
+ webrtc::DesktopSize(view_size_.width(), view_size_.height()),
+ webrtc::DesktopRect::MakeWH(view_size_.width(), view_size_.height()),
+ image_data_.get(), view_size_.width() * kBytesPerPixel,
&update_region_);
}
@@ -121,14 +120,10 @@ class VideoDecoderTester {
ASSERT_TRUE(frame_);
// Test the content of the update region.
- webrtc::DesktopRegion update_region;
- for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) {
- update_region.AddRect(webrtc::DesktopRect::MakeXYWH(
- i.rect().x(), i.rect().y(), i.rect().width(), i.rect().height()));
- }
- EXPECT_TRUE(expected_region_.Equals(update_region));
+ EXPECT_TRUE(expected_region_.Equals(update_region_));
- for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) {
+ for (webrtc::DesktopRegion::Iterator i(update_region_); !i.IsAtEnd();
+ i.Advance()) {
const int stride = view_size_.width() * kBytesPerPixel;
EXPECT_EQ(stride, frame_->stride());
const int offset = stride * i.rect().top() +
@@ -153,7 +148,8 @@ class VideoDecoderTester {
double max_error = 0.0;
double sum_error = 0.0;
int error_num = 0;
- for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) {
+ for (webrtc::DesktopRegion::Iterator i(update_region_); !i.IsAtEnd();
+ i.Advance()) {
const int stride = view_size_.width() * kBytesPerPixel;
const int offset = stride * i.rect().top() +
kBytesPerPixel * i.rect().left();
@@ -195,7 +191,7 @@ class VideoDecoderTester {
DesktopSize view_size_;
bool strict_;
webrtc::DesktopRegion expected_region_;
- SkRegion update_region_;
+ webrtc::DesktopRegion update_region_;
VideoDecoder* decoder_;
scoped_ptr<uint8[]> image_data_;
webrtc::DesktopFrame* frame_;
@@ -377,8 +373,9 @@ void TestVideoEncoderDecoderGradient(VideoEncoder* encoder,
// invalidates the frame.
decoder_tester.ResetRenderedData();
decoder->Invalidate(
- SkISize::Make(view_size.width(), view_size.height()),
- SkRegion(SkIRect::MakeWH(view_size.width(), view_size.height())));
+ webrtc::DesktopSize(view_size.width(), view_size.height()),
+ webrtc::DesktopRegion(
+ webrtc::DesktopRect::MakeWH(view_size.width(), view_size.height())));
decoder_tester.RenderFrame();
decoder_tester.VerifyResultsApprox(expected_result->data(),
max_error_limit, mean_error_limit);
diff --git a/remoting/codec/video_decoder.h b/remoting/codec/video_decoder.h
index 61f0233..b3048a9 100644
--- a/remoting/codec/video_decoder.h
+++ b/remoting/codec/video_decoder.h
@@ -7,9 +7,12 @@
#include "base/basictypes.h"
#include "remoting/proto/video.pb.h"
-#include "third_party/skia/include/core/SkRect.h"
-#include "third_party/skia/include/core/SkRegion.h"
-#include "third_party/skia/include/core/SkSize.h"
+
+namespace webrtc {
+class DesktopRect;
+class DesktopRegion;
+class DesktopSize;
+} // namespace webrtc
namespace remoting {
@@ -24,7 +27,7 @@ class VideoDecoder {
// Initializes the decoder and sets the output dimensions.
// |screen size| must not be empty.
- virtual void Initialize(const SkISize& screen_size) = 0;
+ virtual void Initialize(const webrtc::DesktopSize& screen_size) = 0;
// Feeds more data into the decoder. Returns true if |packet| was processed
// and the frame can be displayed now.
@@ -33,8 +36,8 @@ class VideoDecoder {
// Marks the specified |region| of the view for update the next time
// RenderFrame() is called. |region| is expressed in |view_size| coordinates.
// |view_size| must not be empty.
- virtual void Invalidate(const SkISize& view_size,
- const SkRegion& region) = 0;
+ virtual void Invalidate(const webrtc::DesktopSize& view_size,
+ const webrtc::DesktopRegion& region) = 0;
// Copies invalidated pixels within |clip_area| to |image_buffer|. Pixels are
// invalidated either by new data received in DecodePacket(), or by explicit
@@ -48,15 +51,15 @@ class VideoDecoder {
//
// On return, |output_region| contains the updated area, in |view_size|
// coordinates.
- virtual void RenderFrame(const SkISize& view_size,
- const SkIRect& clip_area,
+ virtual void RenderFrame(const webrtc::DesktopSize& view_size,
+ const webrtc::DesktopRect& clip_area,
uint8* image_buffer,
int image_stride,
- SkRegion* output_region) = 0;
+ webrtc::DesktopRegion* output_region) = 0;
// Returns the "shape", if any, of the most recently rendered frame.
// The shape is returned in source dimensions.
- virtual const SkRegion* GetImageShape() = 0;
+ virtual const webrtc::DesktopRegion* GetImageShape() = 0;
};
} // namespace remoting
diff --git a/remoting/codec/video_decoder_verbatim.cc b/remoting/codec/video_decoder_verbatim.cc
index 0431dc2..05af0ce 100644
--- a/remoting/codec/video_decoder_verbatim.cc
+++ b/remoting/codec/video_decoder_verbatim.cc
@@ -9,18 +9,17 @@
namespace remoting {
-VideoDecoderVerbatim::VideoDecoderVerbatim()
- : screen_size_(SkISize::Make(0, 0)) {}
+VideoDecoderVerbatim::VideoDecoderVerbatim() {}
VideoDecoderVerbatim::~VideoDecoderVerbatim() {}
-void VideoDecoderVerbatim::Initialize(const SkISize& screen_size) {
- updated_region_.setEmpty();
+void VideoDecoderVerbatim::Initialize(const webrtc::DesktopSize& screen_size) {
+ updated_region_.Clear();
screen_buffer_.reset();
screen_size_ = screen_size;
// Allocate the screen buffer, if necessary.
- if (!screen_size_.isEmpty()) {
+ if (!screen_size_.is_empty()) {
screen_buffer_.reset(
new uint8[screen_size_.width() * screen_size_.height() *
kBytesPerPixel]);
@@ -28,27 +27,28 @@ void VideoDecoderVerbatim::Initialize(const SkISize& screen_size) {
}
bool VideoDecoderVerbatim::DecodePacket(const VideoPacket& packet) {
- SkRegion region;
+ webrtc::DesktopRegion region;
const char* in = packet.data().data();
int stride = kBytesPerPixel * screen_size_.width();
for (int i = 0; i < packet.dirty_rects_size(); ++i) {
Rect proto_rect = packet.dirty_rects(i);
- SkIRect rect = SkIRect::MakeXYWH(proto_rect.x(),
- proto_rect.y(),
- proto_rect.width(),
- proto_rect.height());
- region.op(rect, SkRegion::kUnion_Op);
-
- if (!SkIRect::MakeSize(screen_size_).contains(rect)) {
+ webrtc::DesktopRect rect =
+ webrtc::DesktopRect::MakeXYWH(proto_rect.x(),
+ proto_rect.y(),
+ proto_rect.width(),
+ proto_rect.height());
+ region.AddRect(rect);
+
+ if (!DoesRectContain(webrtc::DesktopRect::MakeSize(screen_size_), rect)) {
LOG(ERROR) << "Invalid packet received";
return false;
}
int rect_row_size = kBytesPerPixel * rect.width();
- uint8_t* out = screen_buffer_.get() + rect.y() * stride +
- rect.x() * kBytesPerPixel;
- for (int y = rect.y(); y < rect.y() + rect.height(); ++y) {
+ uint8_t* out = screen_buffer_.get() + rect.top() * stride +
+ rect.left() * kBytesPerPixel;
+ for (int y = rect.top(); y < rect.top() + rect.height(); ++y) {
if (in + rect_row_size > packet.data().data() + packet.data().size()) {
LOG(ERROR) << "Invalid packet received";
return false;
@@ -64,33 +64,36 @@ bool VideoDecoderVerbatim::DecodePacket(const VideoPacket& packet) {
return false;
}
- updated_region_.op(region, SkRegion::kUnion_Op);
+ updated_region_.AddRegion(region);
return true;
}
-void VideoDecoderVerbatim::Invalidate(const SkISize& view_size,
- const SkRegion& region) {
- updated_region_.op(region, SkRegion::kUnion_Op);
+void VideoDecoderVerbatim::Invalidate(const webrtc::DesktopSize& view_size,
+ const webrtc::DesktopRegion& region) {
+ updated_region_.AddRegion(region);
}
-void VideoDecoderVerbatim::RenderFrame(const SkISize& view_size,
- const SkIRect& clip_area,
+void VideoDecoderVerbatim::RenderFrame(const webrtc::DesktopSize& view_size,
+ const webrtc::DesktopRect& clip_area,
uint8* image_buffer,
int image_stride,
- SkRegion* output_region) {
- output_region->setEmpty();
+ webrtc::DesktopRegion* output_region) {
+ output_region->Clear();
// TODO(alexeypa): scaling is not implemented.
- SkIRect clip_rect = SkIRect::MakeSize(screen_size_);
- if (!clip_rect.intersect(clip_area))
+ webrtc::DesktopRect clip_rect = webrtc::DesktopRect::MakeSize(screen_size_);
+ clip_rect.IntersectWith(clip_area);
+ if (clip_rect.is_empty())
return;
int screen_stride = screen_size_.width() * kBytesPerPixel;
- for (SkRegion::Iterator i(updated_region_); !i.done(); i.next()) {
- SkIRect rect(i.rect());
- if (!rect.intersect(clip_rect))
+ for (webrtc::DesktopRegion::Iterator i(updated_region_);
+ !i.IsAtEnd(); i.Advance()) {
+ webrtc::DesktopRect rect(i.rect());
+ rect.IntersectWith(clip_rect);
+ if (rect.is_empty())
continue;
CopyRGB32Rect(screen_buffer_.get(), screen_stride,
@@ -98,13 +101,13 @@ void VideoDecoderVerbatim::RenderFrame(const SkISize& view_size,
image_buffer, image_stride,
clip_area,
rect);
- output_region->op(rect, SkRegion::kUnion_Op);
+ output_region->AddRect(rect);
}
- updated_region_.setEmpty();
+ updated_region_.Clear();
}
-const SkRegion* VideoDecoderVerbatim::GetImageShape() {
+const webrtc::DesktopRegion* VideoDecoderVerbatim::GetImageShape() {
return NULL;
}
diff --git a/remoting/codec/video_decoder_verbatim.h b/remoting/codec/video_decoder_verbatim.h
index fa783dd..24203d9 100644
--- a/remoting/codec/video_decoder_verbatim.h
+++ b/remoting/codec/video_decoder_verbatim.h
@@ -8,6 +8,8 @@
#include "base/compiler_specific.h"
#include "base/memory/scoped_ptr.h"
#include "remoting/codec/video_decoder.h"
+#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
+#include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
namespace remoting {
@@ -21,23 +23,23 @@ class VideoDecoderVerbatim : public VideoDecoder {
VideoDecoderVerbatim();
// VideoDecoder implementation.
- virtual void Initialize(const SkISize& screen_size) OVERRIDE;
+ virtual void Initialize(const webrtc::DesktopSize& screen_size) OVERRIDE;
virtual bool DecodePacket(const VideoPacket& packet) OVERRIDE;
- virtual void Invalidate(const SkISize& view_size,
- const SkRegion& region) OVERRIDE;
- virtual void RenderFrame(const SkISize& view_size,
- const SkIRect& clip_area,
+ virtual void Invalidate(const webrtc::DesktopSize& view_size,
+ const webrtc::DesktopRegion& region) OVERRIDE;
+ virtual void RenderFrame(const webrtc::DesktopSize& view_size,
+ const webrtc::DesktopRect& clip_area,
uint8* image_buffer,
int image_stride,
- SkRegion* output_region) OVERRIDE;
- virtual const SkRegion* GetImageShape() OVERRIDE;
+ webrtc::DesktopRegion* output_region) OVERRIDE;
+ virtual const webrtc::DesktopRegion* GetImageShape() OVERRIDE;
private:
// The region updated that hasn't been copied to the screen yet.
- SkRegion updated_region_;
+ webrtc::DesktopRegion updated_region_;
// Size of the remote screen.
- SkISize screen_size_;
+ webrtc::DesktopSize screen_size_;
// The bitmap holding the remote screen bits.
scoped_ptr<uint8[]> screen_buffer_;
diff --git a/remoting/codec/video_decoder_vp8.cc b/remoting/codec/video_decoder_vp8.cc
index 48bf534..0d43f15 100644
--- a/remoting/codec/video_decoder_vp8.cc
+++ b/remoting/codec/video_decoder_vp8.cc
@@ -26,8 +26,7 @@ const uint32 kTransparent = 0;
VideoDecoderVp8::VideoDecoderVp8()
: state_(kUninitialized),
codec_(NULL),
- last_image_(NULL),
- screen_size_(SkISize::Make(0, 0)) {
+ last_image_(NULL) {
}
VideoDecoderVp8::~VideoDecoderVp8() {
@@ -38,13 +37,13 @@ VideoDecoderVp8::~VideoDecoderVp8() {
delete codec_;
}
-void VideoDecoderVp8::Initialize(const SkISize& screen_size) {
- DCHECK(!screen_size.isEmpty());
+void VideoDecoderVp8::Initialize(const webrtc::DesktopSize& screen_size) {
+ DCHECK(!screen_size.is_empty());
screen_size_ = screen_size;
state_ = kReady;
- transparent_region_.setRect(SkIRect::MakeSize(screen_size_));
+ transparent_region_.SetRect(webrtc::DesktopRect::MakeSize(screen_size_));
}
bool VideoDecoderVp8::DecodePacket(const VideoPacket& packet) {
@@ -61,8 +60,7 @@ bool VideoDecoderVp8::DecodePacket(const VideoPacket& packet) {
config.h = 0;
config.threads = 2;
vpx_codec_err_t ret =
- vpx_codec_dec_init(
- codec_, vpx_codec_vp8_dx(), &config, 0);
+ vpx_codec_dec_init(codec_, vpx_codec_vp8_dx(), &config, 0);
if (ret != VPX_CODEC_OK) {
LOG(INFO) << "Cannot initialize codec.";
delete codec_;
@@ -92,33 +90,30 @@ bool VideoDecoderVp8::DecodePacket(const VideoPacket& packet) {
}
last_image_ = image;
- SkRegion region;
+ webrtc::DesktopRegion region;
for (int i = 0; i < packet.dirty_rects_size(); ++i) {
Rect remoting_rect = packet.dirty_rects(i);
- SkIRect rect = SkIRect::MakeXYWH(remoting_rect.x(),
- remoting_rect.y(),
- remoting_rect.width(),
- remoting_rect.height());
- region.op(rect, SkRegion::kUnion_Op);
+ region.AddRect(webrtc::DesktopRect::MakeXYWH(
+ remoting_rect.x(), remoting_rect.y(),
+ remoting_rect.width(), remoting_rect.height()));
}
- updated_region_.op(region, SkRegion::kUnion_Op);
+ updated_region_.AddRegion(region);
// Update the desktop shape region.
- SkRegion desktop_shape_region;
+ webrtc::DesktopRegion desktop_shape_region;
if (packet.has_use_desktop_shape()) {
for (int i = 0; i < packet.desktop_shape_rects_size(); ++i) {
Rect remoting_rect = packet.desktop_shape_rects(i);
- SkIRect rect = SkIRect::MakeXYWH(remoting_rect.x(),
- remoting_rect.y(),
- remoting_rect.width(),
- remoting_rect.height());
- desktop_shape_region.op(rect, SkRegion::kUnion_Op);
+ desktop_shape_region.AddRect(webrtc::DesktopRect::MakeXYWH(
+ remoting_rect.x(), remoting_rect.y(),
+ remoting_rect.width(), remoting_rect.height()));
}
} else {
// Fallback for the case when the host didn't include the desktop shape
// region.
- desktop_shape_region = SkRegion(SkIRect::MakeSize(screen_size_));
+ desktop_shape_region =
+ webrtc::DesktopRegion(webrtc::DesktopRect::MakeSize(screen_size_));
}
UpdateImageShapeRegion(&desktop_shape_region);
@@ -126,64 +121,65 @@ bool VideoDecoderVp8::DecodePacket(const VideoPacket& packet) {
return true;
}
-void VideoDecoderVp8::Invalidate(const SkISize& view_size,
- const SkRegion& region) {
+void VideoDecoderVp8::Invalidate(const webrtc::DesktopSize& view_size,
+ const webrtc::DesktopRegion& region) {
DCHECK_EQ(kReady, state_);
- DCHECK(!view_size.isEmpty());
+ DCHECK(!view_size.is_empty());
- for (SkRegion::Iterator i(region); !i.done(); i.next()) {
- SkIRect rect = i.rect();
- rect = ScaleRect(rect, view_size, screen_size_);
- updated_region_.op(rect, SkRegion::kUnion_Op);
+ for (webrtc::DesktopRegion::Iterator i(region); !i.IsAtEnd(); i.Advance()) {
+ updated_region_.AddRect(ScaleRect(i.rect(), view_size, screen_size_));
}
// Updated areas outside of the new desktop shape region should be made
// transparent, not repainted.
- SkRegion difference = updated_region_;
- difference.op(desktop_shape_, SkRegion::kDifference_Op);
- updated_region_.op(difference, SkRegion::kDifference_Op);
- transparent_region_.op(difference, SkRegion::kUnion_Op);
+ webrtc::DesktopRegion difference = updated_region_;
+ difference.Subtract(desktop_shape_);
+ updated_region_.Subtract(difference);
+ transparent_region_.AddRegion(difference);
}
-void VideoDecoderVp8::RenderFrame(const SkISize& view_size,
- const SkIRect& clip_area,
+void VideoDecoderVp8::RenderFrame(const webrtc::DesktopSize& view_size,
+ const webrtc::DesktopRect& clip_area,
uint8* image_buffer,
int image_stride,
- SkRegion* output_region) {
+ webrtc::DesktopRegion* output_region) {
DCHECK_EQ(kReady, state_);
- DCHECK(!view_size.isEmpty());
+ DCHECK(!view_size.is_empty());
// Early-return and do nothing if we haven't yet decoded any frames.
if (!last_image_)
return;
- SkIRect source_clip = SkIRect::MakeWH(last_image_->d_w, last_image_->d_h);
+ webrtc::DesktopRect source_clip =
+ webrtc::DesktopRect::MakeWH(last_image_->d_w, last_image_->d_h);
// ScaleYUVToRGB32WithRect does not currently support up-scaling. We won't
// be asked to up-scale except during resizes or if page zoom is >100%, so
// we work-around the limitation by using the slower ScaleYUVToRGB32.
// TODO(wez): Remove this hack if/when ScaleYUVToRGB32WithRect can up-scale.
- if (!updated_region_.isEmpty() &&
+ if (!updated_region_.is_empty() &&
(source_clip.width() < view_size.width() ||
source_clip.height() < view_size.height())) {
// We're scaling only |clip_area| into the |image_buffer|, so we need to
// work out which source rectangle that corresponds to.
- SkIRect source_rect = ScaleRect(clip_area, view_size, screen_size_);
- source_rect = SkIRect::MakeLTRB(RoundToTwosMultiple(source_rect.left()),
- RoundToTwosMultiple(source_rect.top()),
- source_rect.right(),
- source_rect.bottom());
+ webrtc::DesktopRect source_rect =
+ ScaleRect(clip_area, view_size, screen_size_);
+ source_rect = webrtc::DesktopRect::MakeLTRB(
+ RoundToTwosMultiple(source_rect.left()),
+ RoundToTwosMultiple(source_rect.top()),
+ source_rect.right(),
+ source_rect.bottom());
// If there were no changes within the clip source area then don't render.
- if (!updated_region_.intersects(source_rect))
+ webrtc::DesktopRegion intersection(source_rect);
+ intersection.IntersectWith(updated_region_);
+ if (intersection.is_empty())
return;
// Scale & convert the entire clip area.
- int y_offset = CalculateYOffset(source_rect.x(),
- source_rect.y(),
+ int y_offset = CalculateYOffset(source_rect.left(), source_rect.top(),
last_image_->stride[0]);
- int uv_offset = CalculateUVOffset(source_rect.x(),
- source_rect.y(),
+ int uv_offset = CalculateUVOffset(source_rect.left(), source_rect.top(),
last_image_->stride[1]);
ScaleYUVToRGB32(last_image_->planes[0] + y_offset,
last_image_->planes[1] + uv_offset,
@@ -200,18 +196,21 @@ void VideoDecoderVp8::RenderFrame(const SkISize& view_size,
media::ROTATE_0,
media::FILTER_BILINEAR);
- output_region->op(clip_area, SkRegion::kUnion_Op);
- updated_region_.op(source_rect, SkRegion::kDifference_Op);
+ output_region->AddRect(clip_area);
+ updated_region_.Subtract(source_rect);
return;
}
- for (SkRegion::Iterator i(updated_region_); !i.done(); i.next()) {
+ for (webrtc::DesktopRegion::Iterator i(updated_region_);
+ !i.IsAtEnd(); i.Advance()) {
// Determine the scaled area affected by this rectangle changing.
- SkIRect rect = i.rect();
- if (!rect.intersect(source_clip))
+ webrtc::DesktopRect rect = i.rect();
+ rect.IntersectWith(source_clip);
+ if (rect.is_empty())
continue;
rect = ScaleRect(rect, screen_size_, view_size);
- if (!rect.intersect(clip_area))
+ rect.IntersectWith(clip_area);
+ if (rect.is_empty())
continue;
ConvertAndScaleYUVToRGB32Rect(last_image_->planes[0],
@@ -227,38 +226,41 @@ void VideoDecoderVp8::RenderFrame(const SkISize& view_size,
clip_area,
rect);
- output_region->op(rect, SkRegion::kUnion_Op);
+ output_region->AddRect(rect);
}
- updated_region_.op(ScaleRect(clip_area, view_size, screen_size_),
- SkRegion::kDifference_Op);
+ updated_region_.Subtract(ScaleRect(clip_area, view_size, screen_size_));
- for (SkRegion::Iterator i(transparent_region_); !i.done(); i.next()) {
+ for (webrtc::DesktopRegion::Iterator i(transparent_region_);
+ !i.IsAtEnd(); i.Advance()) {
// Determine the scaled area affected by this rectangle changing.
- SkIRect rect = i.rect();
- if (!rect.intersect(source_clip))
+ webrtc::DesktopRect rect = i.rect();
+ rect.IntersectWith(source_clip);
+ if (rect.is_empty())
continue;
rect = ScaleRect(rect, screen_size_, view_size);
- if (!rect.intersect(clip_area))
+ rect.IntersectWith(clip_area);
+ if (rect.is_empty())
continue;
// Fill the rectange with transparent pixels.
FillRect(image_buffer, image_stride, rect, kTransparent);
- output_region->op(rect, SkRegion::kUnion_Op);
+ output_region->AddRect(rect);
}
- SkIRect scaled_clip_area = ScaleRect(clip_area, view_size, screen_size_);
- updated_region_.op(scaled_clip_area, SkRegion::kDifference_Op);
- transparent_region_.op(scaled_clip_area, SkRegion::kDifference_Op);
+ webrtc::DesktopRect scaled_clip_area =
+ ScaleRect(clip_area, view_size, screen_size_);
+ updated_region_.Subtract(scaled_clip_area);
+ transparent_region_.Subtract(scaled_clip_area);
}
-const SkRegion* VideoDecoderVp8::GetImageShape() {
+const webrtc::DesktopRegion* VideoDecoderVp8::GetImageShape() {
return &desktop_shape_;
}
void VideoDecoderVp8::FillRect(uint8* buffer,
int stride,
- const SkIRect& rect,
+ const webrtc::DesktopRect& rect,
uint32 color) {
uint32* ptr = reinterpret_cast<uint32*>(buffer + (rect.top() * stride) +
(rect.left() * kBytesPerPixel));
@@ -269,22 +271,23 @@ void VideoDecoderVp8::FillRect(uint8* buffer,
}
}
-void VideoDecoderVp8::UpdateImageShapeRegion(SkRegion* new_desktop_shape) {
+void VideoDecoderVp8::UpdateImageShapeRegion(
+ webrtc::DesktopRegion* new_desktop_shape) {
// Add all areas that have been updated or become transparent to the
// transparent region. Exclude anything within the new desktop shape.
- transparent_region_.op(desktop_shape_, SkRegion::kUnion_Op);
- transparent_region_.op(updated_region_, SkRegion::kUnion_Op);
- transparent_region_.op(*new_desktop_shape, SkRegion::kDifference_Op);
+ transparent_region_.AddRegion(desktop_shape_);
+ transparent_region_.AddRegion(updated_region_);
+ transparent_region_.Subtract(*new_desktop_shape);
// Add newly exposed areas to the update region and limit updates to the new
// desktop shape.
- SkRegion difference = *new_desktop_shape;
- difference.op(desktop_shape_, SkRegion::kDifference_Op);
- updated_region_.op(difference, SkRegion::kUnion_Op);
- updated_region_.op(*new_desktop_shape, SkRegion::kIntersect_Op);
+ webrtc::DesktopRegion difference = *new_desktop_shape;
+ difference.Subtract(desktop_shape_);
+ updated_region_.AddRegion(difference);
+ updated_region_.IntersectWith(*new_desktop_shape);
// Set the new desktop shape region.
- desktop_shape_.swap(*new_desktop_shape);
+ desktop_shape_.Swap(new_desktop_shape);
}
} // namespace remoting
diff --git a/remoting/codec/video_decoder_vp8.h b/remoting/codec/video_decoder_vp8.h
index 6912ab0..42a3176 100644
--- a/remoting/codec/video_decoder_vp8.h
+++ b/remoting/codec/video_decoder_vp8.h
@@ -7,6 +7,8 @@
#include "base/compiler_specific.h"
#include "remoting/codec/video_decoder.h"
+#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
+#include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
typedef struct vpx_codec_ctx vpx_codec_ctx_t;
typedef struct vpx_image vpx_image_t;
@@ -19,16 +21,16 @@ class VideoDecoderVp8 : public VideoDecoder {
virtual ~VideoDecoderVp8();
// VideoDecoder implementations.
- virtual void Initialize(const SkISize& screen_size) OVERRIDE;
+ virtual void Initialize(const webrtc::DesktopSize& screen_size) OVERRIDE;
virtual bool DecodePacket(const VideoPacket& packet) OVERRIDE;
- virtual void Invalidate(const SkISize& view_size,
- const SkRegion& region) OVERRIDE;
- virtual void RenderFrame(const SkISize& view_size,
- const SkIRect& clip_area,
+ virtual void Invalidate(const webrtc::DesktopSize& view_size,
+ const webrtc::DesktopRegion& region) OVERRIDE;
+ virtual void RenderFrame(const webrtc::DesktopSize& view_size,
+ const webrtc::DesktopRect& clip_area,
uint8* image_buffer,
int image_stride,
- SkRegion* output_region) OVERRIDE;
- virtual const SkRegion* GetImageShape() OVERRIDE;
+ webrtc::DesktopRegion* output_region) OVERRIDE;
+ virtual const webrtc::DesktopRegion* GetImageShape() OVERRIDE;
private:
enum State {
@@ -38,12 +40,14 @@ class VideoDecoderVp8 : public VideoDecoder {
};
// Fills the rectangle |rect| with the given ARGB color |color| in |buffer|.
- void FillRect(uint8* buffer, int stride, const SkIRect& rect, uint32 color);
+ void FillRect(uint8* buffer, int stride,
+ const webrtc::DesktopRect& rect,
+ uint32 color);
// Calculates the difference between the desktop shape regions in two
// consecutive frames and updates |updated_region_| and |transparent_region_|
// accordingly.
- void UpdateImageShapeRegion(SkRegion* new_desktop_shape);
+ void UpdateImageShapeRegion(webrtc::DesktopRegion* new_desktop_shape);
// The internal state of the decoder.
State state_;
@@ -54,16 +58,16 @@ class VideoDecoderVp8 : public VideoDecoder {
vpx_image_t* last_image_;
// The region updated that hasn't been copied to the screen yet.
- SkRegion updated_region_;
+ webrtc::DesktopRegion updated_region_;
// Output dimensions.
- SkISize screen_size_;
+ webrtc::DesktopSize screen_size_;
// The region occupied by the top level windows.
- SkRegion desktop_shape_;
+ webrtc::DesktopRegion desktop_shape_;
// The region that should be make transparent.
- SkRegion transparent_region_;
+ webrtc::DesktopRegion transparent_region_;
DISALLOW_COPY_AND_ASSIGN(VideoDecoderVp8);
};
diff --git a/remoting/codec/video_encoder_vp8.cc b/remoting/codec/video_encoder_vp8.cc
index 179483d..077bdd1 100644
--- a/remoting/codec/video_encoder_vp8.cc
+++ b/remoting/codec/video_encoder_vp8.cc
@@ -12,6 +12,7 @@
#include "remoting/proto/video.pb.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
+#include "third_party/webrtc/modules/desktop_capture/desktop_region.h"
extern "C" {
#define VPX_CODEC_DISABLE_COMPAT 1
@@ -145,30 +146,31 @@ bool VideoEncoderVp8::Init(const webrtc::DesktopSize& size) {
}
void VideoEncoderVp8::PrepareImage(const webrtc::DesktopFrame& frame,
- SkRegion* updated_region) {
+ webrtc::DesktopRegion* updated_region) {
if (frame.updated_region().is_empty()) {
- updated_region->setEmpty();
+ updated_region->Clear();
return;
}
// Align the region to macroblocks, to avoid encoding artefacts.
// This also ensures that all rectangles have even-aligned top-left, which
// is required for ConvertRGBToYUVWithRect() to work.
- std::vector<SkIRect> aligned_rects;
+ std::vector<webrtc::DesktopRect> aligned_rects;
for (webrtc::DesktopRegion::Iterator r(frame.updated_region());
!r.IsAtEnd(); r.Advance()) {
const webrtc::DesktopRect& rect = r.rect();
- aligned_rects.push_back(AlignRect(
- SkIRect::MakeLTRB(rect.left(), rect.top(), rect.right(), rect.bottom())));
+ aligned_rects.push_back(AlignRect(webrtc::DesktopRect::MakeLTRB(
+ rect.left(), rect.top(), rect.right(), rect.bottom())));
}
DCHECK(!aligned_rects.empty());
- updated_region->setRects(&aligned_rects[0], aligned_rects.size());
+ updated_region->Clear();
+ updated_region->AddRects(&aligned_rects[0], aligned_rects.size());
// Clip back to the screen dimensions, in case they're not macroblock aligned.
// The conversion routines don't require even width & height, so this is safe
// even if the source dimensions are not even.
- updated_region->op(SkIRect::MakeWH(image_->w, image_->h),
- SkRegion::kIntersect_Op);
+ updated_region->IntersectWith(
+ webrtc::DesktopRect::MakeWH(image_->w, image_->h));
// Convert the updated region to YUV ready for encoding.
const uint8* rgb_data = frame.data();
@@ -179,22 +181,25 @@ void VideoEncoderVp8::PrepareImage(const webrtc::DesktopFrame& frame,
uint8* y_data = image_->planes[0];
uint8* u_data = image_->planes[1];
uint8* v_data = image_->planes[2];
- for (SkRegion::Iterator r(*updated_region); !r.done(); r.next()) {
- const SkIRect& rect = r.rect();
+ for (webrtc::DesktopRegion::Iterator r(*updated_region); !r.IsAtEnd();
+ r.Advance()) {
+ const webrtc::DesktopRect& rect = r.rect();
ConvertRGB32ToYUVWithRect(
rgb_data, y_data, u_data, v_data,
- rect.x(), rect.y(), rect.width(), rect.height(),
+ rect.left(), rect.top(), rect.width(), rect.height(),
rgb_stride, y_stride, uv_stride);
}
}
-void VideoEncoderVp8::PrepareActiveMap(const SkRegion& updated_region) {
+void VideoEncoderVp8::PrepareActiveMap(
+ const webrtc::DesktopRegion& updated_region) {
// Clear active map first.
memset(active_map_.get(), 0, active_map_width_ * active_map_height_);
// Mark updated areas active.
- for (SkRegion::Iterator r(updated_region); !r.done(); r.next()) {
- const SkIRect& rect = r.rect();
+ for (webrtc::DesktopRegion::Iterator r(updated_region); !r.IsAtEnd();
+ r.Advance()) {
+ const webrtc::DesktopRect& rect = r.rect();
int left = rect.left() / kMacroBlockSize;
int right = (rect.right() - 1) / kMacroBlockSize;
int top = rect.top() / kMacroBlockSize;
@@ -227,7 +232,7 @@ scoped_ptr<VideoPacket> VideoEncoderVp8::Encode(
}
// Convert the updated capture data ready for encode.
- SkRegion updated_region;
+ webrtc::DesktopRegion updated_region;
PrepareImage(frame, &updated_region);
// Update active map based on updated region.
@@ -263,8 +268,8 @@ scoped_ptr<VideoPacket> VideoEncoderVp8::Encode(
scoped_ptr<VideoPacket> packet(new VideoPacket());
while (!got_data) {
- const vpx_codec_cx_pkt_t* vpx_packet = vpx_codec_get_cx_data(codec_.get(),
- &iter);
+ const vpx_codec_cx_pkt_t* vpx_packet =
+ vpx_codec_get_cx_data(codec_.get(), &iter);
if (!vpx_packet)
continue;
@@ -290,10 +295,11 @@ scoped_ptr<VideoPacket> VideoEncoderVp8::Encode(
packet->mutable_format()->set_x_dpi(frame.dpi().x());
packet->mutable_format()->set_y_dpi(frame.dpi().y());
}
- for (SkRegion::Iterator r(updated_region); !r.done(); r.next()) {
+ for (webrtc::DesktopRegion::Iterator r(updated_region); !r.IsAtEnd();
+ r.Advance()) {
Rect* rect = packet->add_dirty_rects();
- rect->set_x(r.rect().x());
- rect->set_y(r.rect().y());
+ rect->set_x(r.rect().left());
+ rect->set_y(r.rect().top());
rect->set_width(r.rect().width());
rect->set_height(r.rect().height());
}
diff --git a/remoting/codec/video_encoder_vp8.h b/remoting/codec/video_encoder_vp8.h
index 2e1ade1..25b00b3 100644
--- a/remoting/codec/video_encoder_vp8.h
+++ b/remoting/codec/video_encoder_vp8.h
@@ -7,12 +7,12 @@
#include "base/gtest_prod_util.h"
#include "remoting/codec/video_encoder.h"
-#include "third_party/skia/include/core/SkRegion.h"
typedef struct vpx_codec_ctx vpx_codec_ctx_t;
typedef struct vpx_image vpx_image_t;
namespace webrtc {
+class DesktopRegion;
class DesktopSize;
} // namespace webrtc
@@ -42,11 +42,11 @@ class VideoEncoderVp8 : public VideoEncoder {
//
// TODO(sergeyu): Update this code to use webrtc::DesktopRegion.
void PrepareImage(const webrtc::DesktopFrame& frame,
- SkRegion* updated_region);
+ webrtc::DesktopRegion* updated_region);
// Update the active map according to |updated_region|. Active map is then
// given to the encoder to speed up encoding.
- void PrepareActiveMap(const SkRegion& updated_region);
+ void PrepareActiveMap(const webrtc::DesktopRegion& updated_region);
// True if the encoder is initialized.
bool initialized_;