summaryrefslogtreecommitdiffstats
path: root/remoting/codec
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-19 21:24:28 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-19 21:24:28 +0000
commitb4e50594c117da39d9d65beed489acc3ce4cd35e (patch)
treeeb321c268adbabfc85ad3dae6931be64c2f92150 /remoting/codec
parentc45d12c0186dbf6a1ffdbb7cb45a15c2366d9dcf (diff)
downloadchromium_src-b4e50594c117da39d9d65beed489acc3ce4cd35e.zip
chromium_src-b4e50594c117da39d9d65beed489acc3ce4cd35e.tar.gz
chromium_src-b4e50594c117da39d9d65beed489acc3ce4cd35e.tar.bz2
Revert 224101 "Remove dependency on Skia from chromoting client."
> Remove dependency on Skia from chromoting client. > > Now DesktopRegion, DesktopRect and DesktopSize are used instead of > corresponding skia types. > > TBR=reed@google.com (for _moved_ skia dependency) > > Review URL: https://chromiumcodereview.appspot.com/23440046 TBR=sergeyu@chromium.org Review URL: https://codereview.chromium.org/24217003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@224205 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.cc63
-rw-r--r--remoting/codec/video_decoder_verbatim.h20
-rw-r--r--remoting/codec/video_decoder_vp8.cc163
-rw-r--r--remoting/codec/video_decoder_vp8.h32
-rw-r--r--remoting/codec/video_encoder_vp8.cc46
-rw-r--r--remoting/codec/video_encoder_vp8.h6
8 files changed, 184 insertions, 200 deletions
diff --git a/remoting/codec/codec_test.cc b/remoting/codec/codec_test.cc
index 26bd84c..83d1035 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(
- webrtc::DesktopSize(screen_size_.width(), screen_size_.height()));
+ SkISize::Make(screen_size_.width(), screen_size_.height()));
}
void Reset() {
expected_region_.Clear();
- update_region_.Clear();
+ update_region_.setEmpty();
}
void ResetRenderedData() {
@@ -89,9 +89,10 @@ class VideoDecoderTester {
void RenderFrame() {
decoder_->RenderFrame(
- webrtc::DesktopSize(view_size_.width(), view_size_.height()),
- webrtc::DesktopRect::MakeWH(view_size_.width(), view_size_.height()),
- image_data_.get(), view_size_.width() * kBytesPerPixel,
+ SkISize::Make(view_size_.width(), view_size_.height()),
+ SkIRect::MakeWH(view_size_.width(), view_size_.height()),
+ image_data_.get(),
+ view_size_.width() * kBytesPerPixel,
&update_region_);
}
@@ -124,10 +125,14 @@ class VideoDecoderTester {
ASSERT_TRUE(frame_);
// Test the content of the update region.
- EXPECT_TRUE(expected_region_.Equals(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));
- for (webrtc::DesktopRegion::Iterator i(update_region_); !i.IsAtEnd();
- i.Advance()) {
+ for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) {
const int stride = view_size_.width() * kBytesPerPixel;
EXPECT_EQ(stride, frame_->stride());
const int offset = stride * i.rect().top() +
@@ -152,8 +157,7 @@ class VideoDecoderTester {
double max_error = 0.0;
double sum_error = 0.0;
int error_num = 0;
- for (webrtc::DesktopRegion::Iterator i(update_region_); !i.IsAtEnd();
- i.Advance()) {
+ for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) {
const int stride = view_size_.width() * kBytesPerPixel;
const int offset = stride * i.rect().top() +
kBytesPerPixel * i.rect().left();
@@ -195,7 +199,7 @@ class VideoDecoderTester {
DesktopSize view_size_;
bool strict_;
webrtc::DesktopRegion expected_region_;
- webrtc::DesktopRegion update_region_;
+ SkRegion update_region_;
VideoDecoder* decoder_;
scoped_ptr<uint8[]> image_data_;
webrtc::DesktopFrame* frame_;
@@ -377,9 +381,8 @@ void TestVideoEncoderDecoderGradient(VideoEncoder* encoder,
// invalidates the frame.
decoder_tester.ResetRenderedData();
decoder->Invalidate(
- webrtc::DesktopSize(view_size.width(), view_size.height()),
- webrtc::DesktopRegion(
- webrtc::DesktopRect::MakeWH(view_size.width(), view_size.height())));
+ SkISize::Make(view_size.width(), view_size.height()),
+ SkRegion(SkIRect::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 83197b8..4730d3a 100644
--- a/remoting/codec/video_decoder.h
+++ b/remoting/codec/video_decoder.h
@@ -7,12 +7,9 @@
#include "base/basictypes.h"
#include "remoting/proto/video.pb.h"
-
-namespace webrtc {
-class DesktopRect;
-class DesktopRegion;
-class DesktopSize;
-} // namespace webrtc
+#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 remoting {
@@ -34,7 +31,7 @@ class VideoDecoder {
// Initializes the decoder and sets the output dimensions.
// |screen size| must not be empty.
- virtual void Initialize(const webrtc::DesktopSize& screen_size) = 0;
+ virtual void Initialize(const SkISize& screen_size) = 0;
// Feeds more data into the decoder.
virtual DecodeResult DecodePacket(const VideoPacket* packet) = 0;
@@ -47,8 +44,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 webrtc::DesktopSize& view_size,
- const webrtc::DesktopRegion& region) = 0;
+ virtual void Invalidate(const SkISize& view_size,
+ const SkRegion& region) = 0;
// Copies invalidated pixels within |clip_area| to |image_buffer|. Pixels are
// invalidated either by new data received in DecodePacket(), or by explicit
@@ -62,15 +59,15 @@ class VideoDecoder {
//
// On return, |output_region| contains the updated area, in |view_size|
// coordinates.
- virtual void RenderFrame(const webrtc::DesktopSize& view_size,
- const webrtc::DesktopRect& clip_area,
+ virtual void RenderFrame(const SkISize& view_size,
+ const SkIRect& clip_area,
uint8* image_buffer,
int image_stride,
- webrtc::DesktopRegion* output_region) = 0;
+ SkRegion* output_region) = 0;
// Returns the "shape", if any, of the most recently rendered frame.
// The shape is returned in source dimensions.
- virtual const webrtc::DesktopRegion* GetImageShape() = 0;
+ virtual const SkRegion* GetImageShape() = 0;
};
} // namespace remoting
diff --git a/remoting/codec/video_decoder_verbatim.cc b/remoting/codec/video_decoder_verbatim.cc
index 81c3b48..b6b2179 100644
--- a/remoting/codec/video_decoder_verbatim.cc
+++ b/remoting/codec/video_decoder_verbatim.cc
@@ -14,7 +14,8 @@ namespace {
const int kBytesPerPixel = 4;
} // namespace
-VideoDecoderVerbatim::VideoDecoderVerbatim() {}
+VideoDecoderVerbatim::VideoDecoderVerbatim()
+ : screen_size_(SkISize::Make(0, 0)) {}
VideoDecoderVerbatim::~VideoDecoderVerbatim() {}
@@ -22,13 +23,13 @@ bool VideoDecoderVerbatim::IsReadyForData() {
return true;
}
-void VideoDecoderVerbatim::Initialize(const webrtc::DesktopSize& screen_size) {
- updated_region_.Clear();
+void VideoDecoderVerbatim::Initialize(const SkISize& screen_size) {
+ updated_region_.setEmpty();
screen_buffer_.reset();
screen_size_ = screen_size;
// Allocate the screen buffer, if necessary.
- if (!screen_size_.is_empty()) {
+ if (!screen_size_.isEmpty()) {
screen_buffer_.reset(
new uint8
[screen_size_.width() * screen_size_.height() * kBytesPerPixel]);
@@ -37,26 +38,27 @@ void VideoDecoderVerbatim::Initialize(const webrtc::DesktopSize& screen_size) {
VideoDecoder::DecodeResult VideoDecoderVerbatim::DecodePacket(
const VideoPacket* packet) {
- webrtc::DesktopRegion region;
+ SkRegion 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);
- webrtc::DesktopRect rect =
- webrtc::DesktopRect::MakeXYWH(proto_rect.x(), proto_rect.y(),
- proto_rect.width(), proto_rect.height());
- region.AddRect(rect);
+ SkIRect rect = SkIRect::MakeXYWH(proto_rect.x(),
+ proto_rect.y(),
+ proto_rect.width(),
+ proto_rect.height());
+ region.op(rect, SkRegion::kUnion_Op);
- if (!DoesRectContain(webrtc::DesktopRect::MakeSize(screen_size_), rect)) {
+ if (!SkIRect::MakeSize(screen_size_).contains(rect)) {
LOG(ERROR) << "Invalid packet received";
return DECODE_ERROR;
}
int rect_row_size = kBytesPerPixel * rect.width();
- uint8_t* out = screen_buffer_.get() + rect.top() * stride +
- rect.left() * kBytesPerPixel;
- for (int y = rect.top(); y < rect.top() + rect.height(); ++y) {
+ uint8_t* out = screen_buffer_.get() + rect.y() * stride +
+ rect.x() * kBytesPerPixel;
+ for (int y = rect.y(); y < rect.y() + rect.height(); ++y) {
if (in + rect_row_size > packet->data().data() + packet->data().size()) {
LOG(ERROR) << "Invalid packet received";
return DECODE_ERROR;
@@ -72,7 +74,7 @@ VideoDecoder::DecodeResult VideoDecoderVerbatim::DecodePacket(
return DECODE_ERROR;
}
- updated_region_.AddRegion(region);
+ updated_region_.op(region, SkRegion::kUnion_Op);
return DECODE_DONE;
}
@@ -81,31 +83,28 @@ VideoPacketFormat::Encoding VideoDecoderVerbatim::Encoding() {
return VideoPacketFormat::ENCODING_VERBATIM;
}
-void VideoDecoderVerbatim::Invalidate(const webrtc::DesktopSize& view_size,
- const webrtc::DesktopRegion& region) {
- updated_region_.AddRegion(region);
+void VideoDecoderVerbatim::Invalidate(const SkISize& view_size,
+ const SkRegion& region) {
+ updated_region_.op(region, SkRegion::kUnion_Op);
}
-void VideoDecoderVerbatim::RenderFrame(const webrtc::DesktopSize& view_size,
- const webrtc::DesktopRect& clip_area,
+void VideoDecoderVerbatim::RenderFrame(const SkISize& view_size,
+ const SkIRect& clip_area,
uint8* image_buffer,
int image_stride,
- webrtc::DesktopRegion* output_region) {
- output_region->Clear();
+ SkRegion* output_region) {
+ output_region->setEmpty();
// TODO(alexeypa): scaling is not implemented.
- webrtc::DesktopRect clip_rect = webrtc::DesktopRect::MakeSize(screen_size_);
- clip_rect.IntersectWith(clip_area);
- if (clip_rect.is_empty())
+ SkIRect clip_rect = SkIRect::MakeSize(screen_size_);
+ if (!clip_rect.intersect(clip_area))
return;
int screen_stride = screen_size_.width() * kBytesPerPixel;
- for (webrtc::DesktopRegion::Iterator i(updated_region_);
- !i.IsAtEnd(); i.Advance()) {
- webrtc::DesktopRect rect(i.rect());
- rect.IntersectWith(clip_rect);
- if (rect.is_empty())
+ for (SkRegion::Iterator i(updated_region_); !i.done(); i.next()) {
+ SkIRect rect(i.rect());
+ if (!rect.intersect(clip_rect))
continue;
CopyRGB32Rect(screen_buffer_.get(), screen_stride,
@@ -113,13 +112,13 @@ void VideoDecoderVerbatim::RenderFrame(const webrtc::DesktopSize& view_size,
image_buffer, image_stride,
clip_area,
rect);
- output_region->AddRect(rect);
+ output_region->op(rect, SkRegion::kUnion_Op);
}
- updated_region_.Clear();
+ updated_region_.setEmpty();
}
-const webrtc::DesktopRegion* VideoDecoderVerbatim::GetImageShape() {
+const SkRegion* VideoDecoderVerbatim::GetImageShape() {
return NULL;
}
diff --git a/remoting/codec/video_decoder_verbatim.h b/remoting/codec/video_decoder_verbatim.h
index ae72379..96b75e21 100644
--- a/remoting/codec/video_decoder_verbatim.h
+++ b/remoting/codec/video_decoder_verbatim.h
@@ -8,8 +8,6 @@
#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 {
@@ -24,24 +22,24 @@ class VideoDecoderVerbatim : public VideoDecoder {
// VideoDecoder implementation.
virtual bool IsReadyForData() OVERRIDE;
- virtual void Initialize(const webrtc::DesktopSize& screen_size) OVERRIDE;
+ virtual void Initialize(const SkISize& screen_size) OVERRIDE;
virtual DecodeResult DecodePacket(const VideoPacket* packet) OVERRIDE;
virtual VideoPacketFormat::Encoding Encoding() OVERRIDE;
- 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,
+ virtual void Invalidate(const SkISize& view_size,
+ const SkRegion& region) OVERRIDE;
+ virtual void RenderFrame(const SkISize& view_size,
+ const SkIRect& clip_area,
uint8* image_buffer,
int image_stride,
- webrtc::DesktopRegion* output_region) OVERRIDE;
- virtual const webrtc::DesktopRegion* GetImageShape() OVERRIDE;
+ SkRegion* output_region) OVERRIDE;
+ virtual const SkRegion* GetImageShape() OVERRIDE;
private:
// The region updated that hasn't been copied to the screen yet.
- webrtc::DesktopRegion updated_region_;
+ SkRegion updated_region_;
// Size of the remote screen.
- webrtc::DesktopSize screen_size_;
+ SkISize 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 617df93..33896fb 100644
--- a/remoting/codec/video_decoder_vp8.cc
+++ b/remoting/codec/video_decoder_vp8.cc
@@ -28,7 +28,8 @@ const uint32 kTransparent = 0;
VideoDecoderVp8::VideoDecoderVp8()
: state_(kUninitialized),
codec_(NULL),
- last_image_(NULL) {
+ last_image_(NULL),
+ screen_size_(SkISize::Make(0, 0)) {
}
VideoDecoderVp8::~VideoDecoderVp8() {
@@ -39,17 +40,13 @@ VideoDecoderVp8::~VideoDecoderVp8() {
delete codec_;
}
-bool VideoDecoderVp8::IsReadyForData() {
- return state_ == kReady;
-}
-
-void VideoDecoderVp8::Initialize(const webrtc::DesktopSize& screen_size) {
- DCHECK(!screen_size.is_empty());
+void VideoDecoderVp8::Initialize(const SkISize& screen_size) {
+ DCHECK(!screen_size.isEmpty());
screen_size_ = screen_size;
state_ = kReady;
- transparent_region_.SetRect(webrtc::DesktopRect::MakeSize(screen_size_));
+ transparent_region_.setRect(SkIRect::MakeSize(screen_size_));
}
VideoDecoder::DecodeResult VideoDecoderVp8::DecodePacket(
@@ -67,7 +64,8 @@ VideoDecoder::DecodeResult VideoDecoderVp8::DecodePacket(
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_;
@@ -97,30 +95,33 @@ VideoDecoder::DecodeResult VideoDecoderVp8::DecodePacket(
}
last_image_ = image;
- webrtc::DesktopRegion region;
+ SkRegion region;
for (int i = 0; i < packet->dirty_rects_size(); ++i) {
Rect remoting_rect = packet->dirty_rects(i);
- region.AddRect(webrtc::DesktopRect::MakeXYWH(
- remoting_rect.x(), remoting_rect.y(),
- remoting_rect.width(), remoting_rect.height()));
+ SkIRect rect = SkIRect::MakeXYWH(remoting_rect.x(),
+ remoting_rect.y(),
+ remoting_rect.width(),
+ remoting_rect.height());
+ region.op(rect, SkRegion::kUnion_Op);
}
- updated_region_.AddRegion(region);
+ updated_region_.op(region, SkRegion::kUnion_Op);
// Update the desktop shape region.
- webrtc::DesktopRegion desktop_shape_region;
+ SkRegion 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);
- desktop_shape_region.AddRect(webrtc::DesktopRect::MakeXYWH(
- remoting_rect.x(), remoting_rect.y(),
- remoting_rect.width(), remoting_rect.height()));
+ SkIRect rect = SkIRect::MakeXYWH(remoting_rect.x(),
+ remoting_rect.y(),
+ remoting_rect.width(),
+ remoting_rect.height());
+ desktop_shape_region.op(rect, SkRegion::kUnion_Op);
}
} else {
// Fallback for the case when the host didn't include the desktop shape
// region.
- desktop_shape_region =
- webrtc::DesktopRegion(webrtc::DesktopRect::MakeSize(screen_size_));
+ desktop_shape_region = SkRegion(SkIRect::MakeSize(screen_size_));
}
UpdateImageShapeRegion(&desktop_shape_region);
@@ -128,69 +129,72 @@ VideoDecoder::DecodeResult VideoDecoderVp8::DecodePacket(
return DECODE_DONE;
}
+bool VideoDecoderVp8::IsReadyForData() {
+ return state_ == kReady;
+}
+
VideoPacketFormat::Encoding VideoDecoderVp8::Encoding() {
return VideoPacketFormat::ENCODING_VP8;
}
-void VideoDecoderVp8::Invalidate(const webrtc::DesktopSize& view_size,
- const webrtc::DesktopRegion& region) {
+void VideoDecoderVp8::Invalidate(const SkISize& view_size,
+ const SkRegion& region) {
DCHECK_EQ(kReady, state_);
- DCHECK(!view_size.is_empty());
+ DCHECK(!view_size.isEmpty());
- for (webrtc::DesktopRegion::Iterator i(region); !i.IsAtEnd(); i.Advance()) {
- updated_region_.AddRect(ScaleRect(i.rect(), view_size, screen_size_));
+ 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);
}
// Updated areas outside of the new desktop shape region should be made
// transparent, not repainted.
- webrtc::DesktopRegion difference = updated_region_;
- difference.Subtract(desktop_shape_);
- updated_region_.Subtract(difference);
- transparent_region_.AddRegion(difference);
+ 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);
}
-void VideoDecoderVp8::RenderFrame(const webrtc::DesktopSize& view_size,
- const webrtc::DesktopRect& clip_area,
+void VideoDecoderVp8::RenderFrame(const SkISize& view_size,
+ const SkIRect& clip_area,
uint8* image_buffer,
int image_stride,
- webrtc::DesktopRegion* output_region) {
+ SkRegion* output_region) {
DCHECK_EQ(kReady, state_);
- DCHECK(!view_size.is_empty());
+ DCHECK(!view_size.isEmpty());
// Early-return and do nothing if we haven't yet decoded any frames.
if (!last_image_)
return;
- webrtc::DesktopRect source_clip =
- webrtc::DesktopRect::MakeWH(last_image_->d_w, last_image_->d_h);
+ SkIRect source_clip = SkIRect::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_.is_empty() &&
+ if (!updated_region_.isEmpty() &&
(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.
- 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());
+ 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());
// If there were no changes within the clip source area then don't render.
- webrtc::DesktopRegion intersection(source_rect);
- intersection.IntersectWith(updated_region_);
- if (intersection.is_empty())
+ if (!updated_region_.intersects(source_rect))
return;
// Scale & convert the entire clip area.
- int y_offset = CalculateYOffset(source_rect.left(), source_rect.top(),
+ int y_offset = CalculateYOffset(source_rect.x(),
+ source_rect.y(),
last_image_->stride[0]);
- int uv_offset = CalculateUVOffset(source_rect.left(), source_rect.top(),
+ int uv_offset = CalculateUVOffset(source_rect.x(),
+ source_rect.y(),
last_image_->stride[1]);
ScaleYUVToRGB32(last_image_->planes[0] + y_offset,
last_image_->planes[1] + uv_offset,
@@ -207,21 +211,18 @@ void VideoDecoderVp8::RenderFrame(const webrtc::DesktopSize& view_size,
media::ROTATE_0,
media::FILTER_BILINEAR);
- output_region->AddRect(clip_area);
- updated_region_.Subtract(source_rect);
+ output_region->op(clip_area, SkRegion::kUnion_Op);
+ updated_region_.op(source_rect, SkRegion::kDifference_Op);
return;
}
- for (webrtc::DesktopRegion::Iterator i(updated_region_);
- !i.IsAtEnd(); i.Advance()) {
+ for (SkRegion::Iterator i(updated_region_); !i.done(); i.next()) {
// Determine the scaled area affected by this rectangle changing.
- webrtc::DesktopRect rect = i.rect();
- rect.IntersectWith(source_clip);
- if (rect.is_empty())
+ SkIRect rect = i.rect();
+ if (!rect.intersect(source_clip))
continue;
rect = ScaleRect(rect, screen_size_, view_size);
- rect.IntersectWith(clip_area);
- if (rect.is_empty())
+ if (!rect.intersect(clip_area))
continue;
ConvertAndScaleYUVToRGB32Rect(last_image_->planes[0],
@@ -237,41 +238,38 @@ void VideoDecoderVp8::RenderFrame(const webrtc::DesktopSize& view_size,
clip_area,
rect);
- output_region->AddRect(rect);
+ output_region->op(rect, SkRegion::kUnion_Op);
}
- updated_region_.Subtract(ScaleRect(clip_area, view_size, screen_size_));
+ updated_region_.op(ScaleRect(clip_area, view_size, screen_size_),
+ SkRegion::kDifference_Op);
- for (webrtc::DesktopRegion::Iterator i(transparent_region_);
- !i.IsAtEnd(); i.Advance()) {
+ for (SkRegion::Iterator i(transparent_region_); !i.done(); i.next()) {
// Determine the scaled area affected by this rectangle changing.
- webrtc::DesktopRect rect = i.rect();
- rect.IntersectWith(source_clip);
- if (rect.is_empty())
+ SkIRect rect = i.rect();
+ if (!rect.intersect(source_clip))
continue;
rect = ScaleRect(rect, screen_size_, view_size);
- rect.IntersectWith(clip_area);
- if (rect.is_empty())
+ if (!rect.intersect(clip_area))
continue;
// Fill the rectange with transparent pixels.
FillRect(image_buffer, image_stride, rect, kTransparent);
- output_region->AddRect(rect);
+ output_region->op(rect, SkRegion::kUnion_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);
+ 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);
}
-const webrtc::DesktopRegion* VideoDecoderVp8::GetImageShape() {
+const SkRegion* VideoDecoderVp8::GetImageShape() {
return &desktop_shape_;
}
void VideoDecoderVp8::FillRect(uint8* buffer,
int stride,
- const webrtc::DesktopRect& rect,
+ const SkIRect& rect,
uint32 color) {
uint32* ptr = reinterpret_cast<uint32*>(buffer + (rect.top() * stride) +
(rect.left() * kBytesPerPixelRGB32));
@@ -282,23 +280,22 @@ void VideoDecoderVp8::FillRect(uint8* buffer,
}
}
-void VideoDecoderVp8::UpdateImageShapeRegion(
- webrtc::DesktopRegion* new_desktop_shape) {
+void VideoDecoderVp8::UpdateImageShapeRegion(SkRegion* 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_.AddRegion(desktop_shape_);
- transparent_region_.AddRegion(updated_region_);
- transparent_region_.Subtract(*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);
// Add newly exposed areas to the update region and limit updates to the new
// desktop shape.
- webrtc::DesktopRegion difference = *new_desktop_shape;
- difference.Subtract(desktop_shape_);
- updated_region_.AddRegion(difference);
- updated_region_.IntersectWith(*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);
// 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 719ae77..2efbd22 100644
--- a/remoting/codec/video_decoder_vp8.h
+++ b/remoting/codec/video_decoder_vp8.h
@@ -7,8 +7,6 @@
#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;
@@ -21,18 +19,18 @@ class VideoDecoderVp8 : public VideoDecoder {
virtual ~VideoDecoderVp8();
// VideoDecoder implementations.
- virtual bool IsReadyForData() OVERRIDE;
- virtual void Initialize(const webrtc::DesktopSize& screen_size) OVERRIDE;
+ virtual void Initialize(const SkISize& screen_size) OVERRIDE;
virtual DecodeResult DecodePacket(const VideoPacket* packet) OVERRIDE;
+ virtual bool IsReadyForData() OVERRIDE;
virtual VideoPacketFormat::Encoding Encoding() OVERRIDE;
- 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,
+ virtual void Invalidate(const SkISize& view_size,
+ const SkRegion& region) OVERRIDE;
+ virtual void RenderFrame(const SkISize& view_size,
+ const SkIRect& clip_area,
uint8* image_buffer,
int image_stride,
- webrtc::DesktopRegion* output_region) OVERRIDE;
- virtual const webrtc::DesktopRegion* GetImageShape() OVERRIDE;
+ SkRegion* output_region) OVERRIDE;
+ virtual const SkRegion* GetImageShape() OVERRIDE;
private:
enum State {
@@ -42,14 +40,12 @@ class VideoDecoderVp8 : public VideoDecoder {
};
// Fills the rectangle |rect| with the given ARGB color |color| in |buffer|.
- void FillRect(uint8* buffer, int stride,
- const webrtc::DesktopRect& rect,
- uint32 color);
+ void FillRect(uint8* buffer, int stride, const SkIRect& 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(webrtc::DesktopRegion* new_desktop_shape);
+ void UpdateImageShapeRegion(SkRegion* new_desktop_shape);
// The internal state of the decoder.
State state_;
@@ -60,16 +56,16 @@ class VideoDecoderVp8 : public VideoDecoder {
vpx_image_t* last_image_;
// The region updated that hasn't been copied to the screen yet.
- webrtc::DesktopRegion updated_region_;
+ SkRegion updated_region_;
// Output dimensions.
- webrtc::DesktopSize screen_size_;
+ SkISize screen_size_;
// The region occupied by the top level windows.
- webrtc::DesktopRegion desktop_shape_;
+ SkRegion desktop_shape_;
// The region that should be make transparent.
- webrtc::DesktopRegion transparent_region_;
+ SkRegion transparent_region_;
DISALLOW_COPY_AND_ASSIGN(VideoDecoderVp8);
};
diff --git a/remoting/codec/video_encoder_vp8.cc b/remoting/codec/video_encoder_vp8.cc
index 077bdd1..179483d 100644
--- a/remoting/codec/video_encoder_vp8.cc
+++ b/remoting/codec/video_encoder_vp8.cc
@@ -12,7 +12,6 @@
#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
@@ -146,31 +145,30 @@ bool VideoEncoderVp8::Init(const webrtc::DesktopSize& size) {
}
void VideoEncoderVp8::PrepareImage(const webrtc::DesktopFrame& frame,
- webrtc::DesktopRegion* updated_region) {
+ SkRegion* updated_region) {
if (frame.updated_region().is_empty()) {
- updated_region->Clear();
+ updated_region->setEmpty();
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<webrtc::DesktopRect> aligned_rects;
+ std::vector<SkIRect> 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(webrtc::DesktopRect::MakeLTRB(
- rect.left(), rect.top(), rect.right(), rect.bottom())));
+ aligned_rects.push_back(AlignRect(
+ SkIRect::MakeLTRB(rect.left(), rect.top(), rect.right(), rect.bottom())));
}
DCHECK(!aligned_rects.empty());
- updated_region->Clear();
- updated_region->AddRects(&aligned_rects[0], aligned_rects.size());
+ updated_region->setRects(&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->IntersectWith(
- webrtc::DesktopRect::MakeWH(image_->w, image_->h));
+ updated_region->op(SkIRect::MakeWH(image_->w, image_->h),
+ SkRegion::kIntersect_Op);
// Convert the updated region to YUV ready for encoding.
const uint8* rgb_data = frame.data();
@@ -181,25 +179,22 @@ 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 (webrtc::DesktopRegion::Iterator r(*updated_region); !r.IsAtEnd();
- r.Advance()) {
- const webrtc::DesktopRect& rect = r.rect();
+ for (SkRegion::Iterator r(*updated_region); !r.done(); r.next()) {
+ const SkIRect& rect = r.rect();
ConvertRGB32ToYUVWithRect(
rgb_data, y_data, u_data, v_data,
- rect.left(), rect.top(), rect.width(), rect.height(),
+ rect.x(), rect.y(), rect.width(), rect.height(),
rgb_stride, y_stride, uv_stride);
}
}
-void VideoEncoderVp8::PrepareActiveMap(
- const webrtc::DesktopRegion& updated_region) {
+void VideoEncoderVp8::PrepareActiveMap(const SkRegion& updated_region) {
// Clear active map first.
memset(active_map_.get(), 0, active_map_width_ * active_map_height_);
// Mark updated areas active.
- for (webrtc::DesktopRegion::Iterator r(updated_region); !r.IsAtEnd();
- r.Advance()) {
- const webrtc::DesktopRect& rect = r.rect();
+ for (SkRegion::Iterator r(updated_region); !r.done(); r.next()) {
+ const SkIRect& rect = r.rect();
int left = rect.left() / kMacroBlockSize;
int right = (rect.right() - 1) / kMacroBlockSize;
int top = rect.top() / kMacroBlockSize;
@@ -232,7 +227,7 @@ scoped_ptr<VideoPacket> VideoEncoderVp8::Encode(
}
// Convert the updated capture data ready for encode.
- webrtc::DesktopRegion updated_region;
+ SkRegion updated_region;
PrepareImage(frame, &updated_region);
// Update active map based on updated region.
@@ -268,8 +263,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;
@@ -295,11 +290,10 @@ scoped_ptr<VideoPacket> VideoEncoderVp8::Encode(
packet->mutable_format()->set_x_dpi(frame.dpi().x());
packet->mutable_format()->set_y_dpi(frame.dpi().y());
}
- for (webrtc::DesktopRegion::Iterator r(updated_region); !r.IsAtEnd();
- r.Advance()) {
+ for (SkRegion::Iterator r(updated_region); !r.done(); r.next()) {
Rect* rect = packet->add_dirty_rects();
- rect->set_x(r.rect().left());
- rect->set_y(r.rect().top());
+ rect->set_x(r.rect().x());
+ rect->set_y(r.rect().y());
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 25b00b3..2e1ade1 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,
- webrtc::DesktopRegion* updated_region);
+ SkRegion* 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 webrtc::DesktopRegion& updated_region);
+ void PrepareActiveMap(const SkRegion& updated_region);
// True if the encoder is initialized.
bool initialized_;