diff options
author | rsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-24 03:23:23 +0000 |
---|---|---|
committer | rsleevi@chromium.org <rsleevi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-24 03:23:23 +0000 |
commit | 22f58a413b507463f97804a947c732d9a1c7eec6 (patch) | |
tree | eb5e11bb4ab6b25b220648cb346d2a6d712de133 /remoting/base | |
parent | 4466cbde3ee2d518081872862e3cfe741731540e (diff) | |
download | chromium_src-22f58a413b507463f97804a947c732d9a1c7eec6.zip chromium_src-22f58a413b507463f97804a947c732d9a1c7eec6.tar.gz chromium_src-22f58a413b507463f97804a947c732d9a1c7eec6.tar.bz2 |
Revert 118790 - Compile error due to missing operator== on SkRegion
Replace RectVectors with SkRegions in Decoder.
BUG=105401
Review URL: http://codereview.chromium.org/9277001
TBR=wez@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9146030
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118793 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/base')
-rw-r--r-- | remoting/base/codec_test.cc | 74 | ||||
-rw-r--r-- | remoting/base/decoder.h | 24 | ||||
-rw-r--r-- | remoting/base/decoder_row_based.cc | 12 | ||||
-rw-r--r-- | remoting/base/decoder_row_based.h | 6 | ||||
-rw-r--r-- | remoting/base/decoder_vp8.cc | 57 | ||||
-rw-r--r-- | remoting/base/decoder_vp8.h | 25 |
6 files changed, 105 insertions, 93 deletions
diff --git a/remoting/base/codec_test.cc b/remoting/base/codec_test.cc index 81f0db8..efe7055 100644 --- a/remoting/base/codec_test.cc +++ b/remoting/base/codec_test.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 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. @@ -132,8 +132,8 @@ class DecoderTester { } void Reset() { - expected_region_.setEmpty(); - update_region_.setEmpty(); + rects_.clear(); + update_rects_.clear(); } void ReceivedPacket(VideoPacket* packet) { @@ -142,7 +142,7 @@ class DecoderTester { ASSERT_NE(Decoder::DECODE_ERROR, result); if (result == Decoder::DECODE_DONE) { - decoder_->GetUpdatedRegion(&update_region_); + decoder_->GetUpdatedRects(&update_rects_); } } @@ -155,9 +155,7 @@ class DecoderTester { } void AddRects(const SkIRect* rects, int count) { - SkRegion new_rects; - new_rects.setRects(rects, count); - expected_region_.op(new_rects, SkRegion::kUnion_Op); + rects_.insert(rects_.begin() + rects_.size(), rects, rects + count); } void VerifyResults() { @@ -166,17 +164,19 @@ class DecoderTester { ASSERT_TRUE(capture_data_.get()); - // Test the content of the update region. - EXPECT_EQ(expected_region_, update_region_); - for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) { + // Test the content of the update rect. + ASSERT_EQ(rects_.size(), update_rects_.size()); + for (size_t i = 0; i < update_rects_.size(); ++i) { + EXPECT_EQ(rects_[i], update_rects_[i]); + EXPECT_EQ(frame_->stride(0), capture_data_->data_planes().strides[0]); const int stride = frame_->stride(0); - const int offset = stride * i.rect().top() + - kBytesPerPixel * i.rect().left(); + const int offset = stride * update_rects_[i].fTop + + kBytesPerPixel * update_rects_[i].fLeft; const uint8* original = capture_data_->data_planes().data[0] + offset; const uint8* decoded = frame_->data(0) + offset; - const int row_size = kBytesPerPixel * i.rect().width(); - for (int y = 0; y < i.rect().height(); ++y) { + const int row_size = kBytesPerPixel * update_rects_[i].width(); + for (int y = 0; y < update_rects_[i].height(); ++y) { EXPECT_EQ(0, memcmp(original, decoded, row_size)) << "Row " << y << " is different"; original += stride; @@ -187,8 +187,8 @@ class DecoderTester { private: bool strict_; - SkRegion expected_region_; - SkRegion update_region_; + std::deque<SkIRect> rects_; + RectVector update_rects_; Decoder* decoder_; scoped_refptr<media::VideoFrame> frame_; scoped_refptr<CaptureData> capture_data_; @@ -292,24 +292,28 @@ void TestEncoder(Encoder* encoder, bool strict) { TestEncodingRects(encoder, &tester, data, kTestRects + 3, 2); } -static void TestEncodeDecodeRects(Encoder* encoder, - EncoderTester* encoder_tester, - DecoderTester* decoder_tester, - scoped_refptr<CaptureData> data, - const SkIRect* rects, int count) { - data->mutable_dirty_region().setRects(rects, count); +static void TestEncodingRects(Encoder* encoder, + EncoderTester* encoder_tester, + DecoderTester* decoder_tester, + scoped_refptr<CaptureData> data, + const SkIRect* rects, int count) { + data->mutable_dirty_region().setEmpty(); + for (int i = 0; i < count; ++i) { + data->mutable_dirty_region().op(rects[i], SkRegion::kUnion_Op); + } encoder_tester->AddRects(rects, count); decoder_tester->AddRects(rects, count); - // Generate random data for the updated region. + // Generate random data for the updated rects. srand(0); for (int i = 0; i < count; ++i) { + const SkIRect& rect = rects[i]; const int bytes_per_pixel = GetBytesPerPixel(data->pixel_format()); - const int row_size = bytes_per_pixel * rects[i].width(); + const int row_size = bytes_per_pixel * rect.width(); uint8* memory = data->data_planes().data[0] + - data->data_planes().strides[0] * rects[i].top() + - bytes_per_pixel * rects[i].left(); - for (int y = 0; y < rects[i].height(); ++y) { + 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; memory += data->data_planes().strides[0]; @@ -338,14 +342,14 @@ void TestEncoderDecoder(Encoder* encoder, Decoder* decoder, bool strict) { decoder_tester.set_capture_data(data); encoder_tester.set_decoder_tester(&decoder_tester); - TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, - kTestRects, 1); - TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, - kTestRects + 1, 1); - TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, - kTestRects + 2, 1); - TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, - kTestRects + 3, 2); + TestEncodingRects(encoder, &encoder_tester, &decoder_tester, data, + kTestRects, 1); + TestEncodingRects(encoder, &encoder_tester, &decoder_tester, data, + kTestRects + 1, 1); + TestEncodingRects(encoder, &encoder_tester, &decoder_tester, data, + kTestRects + 2, 1); + TestEncodingRects(encoder, &encoder_tester, &decoder_tester, data, + kTestRects + 3, 2); } } // namespace remoting diff --git a/remoting/base/decoder.h b/remoting/base/decoder.h index 9efc17e..dd37757 100644 --- a/remoting/base/decoder.h +++ b/remoting/base/decoder.h @@ -1,17 +1,21 @@ -// Copyright (c) 2012 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. #ifndef REMOTING_BASE_DECODER_H_ #define REMOTING_BASE_DECODER_H_ +#include <vector> + #include "base/memory/scoped_ptr.h" #include "media/base/video_frame.h" #include "remoting/proto/video.pb.h" -#include "third_party/skia/include/core/SkRegion.h" +#include "third_party/skia/include/core/SkRect.h" namespace remoting { +typedef std::vector<SkIRect> RectVector; + // Interface for a decoder that takes a stream of bytes from the network and // outputs frames of data. // @@ -38,10 +42,10 @@ class Decoder { // Feeds more data into the decoder. virtual DecodeResult DecodePacket(const VideoPacket* packet) = 0; - // Returns the region affected by the most recent frame. Can be called only + // Returns rects that were updated in the last frame. Can be called only // after DecodePacket returned DECODE_DONE. Caller keeps ownership of - // |region|. - virtual void GetUpdatedRegion(SkRegion* region) = 0; + // |rects|. |rects| is kept empty if whole screen needs to be updated. + virtual void GetUpdatedRects(RectVector* rects) = 0; // Reset the decoder to an uninitialized state. Release all references to // the initialized |frame|. Initialize() must be called before the decoder @@ -61,12 +65,14 @@ class Decoder { // Set the clipping rectangle to the decoder. Decoder should respect this and // only output changes in this rectangle. The new clipping rectangle will be // effective on the next decoded video frame. + // + // When scaling is enabled clipping rectangles are ignored. virtual void SetClipRect(const SkIRect& clip_rect) {} - // Force decoder to output a frame based on the specified |region| of the - // most recently decoded video frame. |region| is expressed in video frame - // rather than output coordinates. - virtual void RefreshRegion(const SkRegion& region) {} + // Force decoder to output a video frame with content in |rects| using the + // last decoded video frame. |rects| are expressed in video frame rather + // than output coordinates. + virtual void RefreshRects(const RectVector& rects) {} }; } // namespace remoting diff --git a/remoting/base/decoder_row_based.cc b/remoting/base/decoder_row_based.cc index 5c95991..da65079 100644 --- a/remoting/base/decoder_row_based.cc +++ b/remoting/base/decoder_row_based.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2012 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. @@ -44,7 +44,7 @@ void DecoderRowBased::Reset() { frame_ = NULL; decompressor_->Reset(); state_ = kUninitialized; - updated_region_.setEmpty(); + updated_rects_.clear(); } bool DecoderRowBased::IsReadyForData() { @@ -128,7 +128,7 @@ Decoder::DecodeResult DecoderRowBased::DecodePacket(const VideoPacket* packet) { return DECODE_ERROR; } - updated_region_.op(clip_, SkRegion::kUnion_Op); + updated_rects_.push_back(clip_); decompressor_->Reset(); } @@ -186,9 +186,9 @@ void DecoderRowBased::UpdateStateForPacket(const VideoPacket* packet) { return; } -void DecoderRowBased::GetUpdatedRegion(SkRegion* region) { - region->swap(updated_region_); - updated_region_.setEmpty(); +void DecoderRowBased::GetUpdatedRects(RectVector* rects) { + rects->swap(updated_rects_); + updated_rects_.clear(); } VideoPacketFormat::Encoding DecoderRowBased::Encoding() { diff --git a/remoting/base/decoder_row_based.h b/remoting/base/decoder_row_based.h index 183086c..7086c7b 100644 --- a/remoting/base/decoder_row_based.h +++ b/remoting/base/decoder_row_based.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 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. @@ -22,7 +22,7 @@ class DecoderRowBased : public Decoder { virtual bool IsReadyForData() OVERRIDE; virtual void Initialize(scoped_refptr<media::VideoFrame> frame) OVERRIDE; virtual DecodeResult DecodePacket(const VideoPacket* packet) OVERRIDE; - virtual void GetUpdatedRegion(SkRegion* region) OVERRIDE; + virtual void GetUpdatedRects(RectVector* rects) OVERRIDE; virtual void Reset() OVERRIDE; virtual VideoPacketFormat::Encoding Encoding() OVERRIDE; @@ -63,7 +63,7 @@ class DecoderRowBased : public Decoder { // The current row in the rect that we are updaing. int row_y_; - SkRegion updated_region_; + RectVector updated_rects_; DISALLOW_COPY_AND_ASSIGN(DecoderRowBased); }; diff --git a/remoting/base/decoder_vp8.cc b/remoting/base/decoder_vp8.cc index 40746913..d0e3785 100644 --- a/remoting/base/decoder_vp8.cc +++ b/remoting/base/decoder_vp8.cc @@ -92,22 +92,22 @@ Decoder::DecodeResult DecoderVp8::DecodePacket(const VideoPacket* packet) { } last_image_ = image; - SkRegion region; + RectVector rects; + rects.reserve(packet->dirty_rects_size()); 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); + rects.push_back(SkIRect::MakeXYWH(remoting_rect.x(), + remoting_rect.y(), + remoting_rect.width(), + remoting_rect.height())); } - RefreshRegion(region); + RefreshRects(rects); return DECODE_DONE; } -void DecoderVp8::GetUpdatedRegion(SkRegion* region) { - region->swap(updated_region_); +void DecoderVp8::GetUpdatedRects(RectVector* rects) { + rects->swap(updated_rects_); } void DecoderVp8::Reset() { @@ -131,7 +131,7 @@ void DecoderVp8::SetClipRect(const SkIRect& clip_rect) { clip_rect_ = clip_rect; } -void DecoderVp8::RefreshRegion(const SkRegion& region) { +void DecoderVp8::RefreshRects(const RectVector& rects) { // TODO(wez): Fix the rest of the decode pipeline not to assume the frame // size is the host dimensions, since it's not when scaling. If the host // gets smaller, then the output size will be too big and we'll overrun the @@ -142,11 +142,10 @@ void DecoderVp8::RefreshRegion(const SkRegion& region) { if (output_size_.height() > static_cast<int>(frame_->height())) output_size_.set(output_size_.width(), frame_->height()); - if (!DoScaling()) { - ConvertRegion(region, &updated_region_); - } else { - ScaleAndConvertRegion(region, &updated_region_); - } + if (!DoScaling()) + ConvertRects(rects, &updated_rects_); + else + ScaleAndConvertRects(rects, &updated_rects_); } bool DecoderVp8::DoScaling() const { @@ -154,12 +153,12 @@ bool DecoderVp8::DoScaling() const { return !output_size_.equals(last_image_->d_w, last_image_->d_h); } -void DecoderVp8::ConvertRegion(const SkRegion& input_region, - SkRegion* output_region) { +void DecoderVp8::ConvertRects(const RectVector& input_rects, + RectVector* output_rects) { if (!last_image_) return; - output_region->setEmpty(); + output_rects->clear(); // Clip based on both the output dimensions and Pepper clip rect. // ConvertYUVToRGB32WithRect() requires even X and Y coordinates, so we align @@ -172,11 +171,12 @@ void DecoderVp8::ConvertRegion(const SkRegion& input_region, uint8* output_rgb_buf = frame_->data(media::VideoFrame::kRGBPlane); const int output_stride = frame_->stride(media::VideoFrame::kRGBPlane); + output_rects->reserve(input_rects.size()); - for (SkRegion::Iterator i(input_region); !i.done(); i.next()) { + for (size_t i = 0; i < input_rects.size(); ++i) { // Align the rectangle so the top-left coordinates are even, for // ConvertYUVToRGB32WithRect(). - SkIRect dest_rect(AlignRect(i.rect())); + SkIRect dest_rect(AlignRect(input_rects[i])); // Clip the rectangle, preserving alignment since |clip_rect| is aligned. if (!dest_rect.intersect(clip_rect)) @@ -191,19 +191,19 @@ void DecoderVp8::ConvertRegion(const SkRegion& input_region, last_image_->stride[1], output_stride); - output_region->op(dest_rect, SkRegion::kUnion_Op); + output_rects->push_back(dest_rect); } } -void DecoderVp8::ScaleAndConvertRegion(const SkRegion& input_region, - SkRegion* output_region) { +void DecoderVp8::ScaleAndConvertRects(const RectVector& input_rects, + RectVector* output_rects) { if (!last_image_) return; DCHECK(output_size_.width() <= static_cast<int>(frame_->width())); DCHECK(output_size_.height() <= static_cast<int>(frame_->height())); - output_region->setEmpty(); + output_rects->clear(); // Clip based on both the output dimensions and Pepper clip rect. SkIRect clip_rect = clip_rect_; @@ -214,9 +214,11 @@ void DecoderVp8::ScaleAndConvertRegion(const SkRegion& input_region, uint8* output_rgb_buf = frame_->data(media::VideoFrame::kRGBPlane); const int output_stride = frame_->stride(media::VideoFrame::kRGBPlane); - for (SkRegion::Iterator i(input_region); !i.done(); i.next()) { + output_rects->reserve(input_rects.size()); + + for (size_t i = 0; i < input_rects.size(); ++i) { // Determine the scaled area affected by this rectangle changing. - SkIRect output_rect = ScaleRect(i.rect(), image_size, output_size_); + SkIRect output_rect = ScaleRect(input_rects[i], image_size, output_size_); if (!output_rect.intersect(clip_rect)) continue; @@ -236,8 +238,7 @@ void DecoderVp8::ScaleAndConvertRegion(const SkRegion& input_region, last_image_->stride[0], last_image_->stride[1], output_stride); - - output_region->op(output_rect, SkRegion::kUnion_Op); + output_rects->push_back(output_rect); } } diff --git a/remoting/base/decoder_vp8.h b/remoting/base/decoder_vp8.h index 76fd547..a89991c 100644 --- a/remoting/base/decoder_vp8.h +++ b/remoting/base/decoder_vp8.h @@ -1,4 +1,4 @@ -// Copyright (c) 2012 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. @@ -20,13 +20,13 @@ class DecoderVp8 : public Decoder { // Decoder implementations. virtual void Initialize(scoped_refptr<media::VideoFrame> frame) OVERRIDE; virtual DecodeResult DecodePacket(const VideoPacket* packet) OVERRIDE; - virtual void GetUpdatedRegion(SkRegion* region) OVERRIDE; + virtual void GetUpdatedRects(RectVector* rects) OVERRIDE; virtual bool IsReadyForData() OVERRIDE; virtual void Reset() OVERRIDE; virtual VideoPacketFormat::Encoding Encoding() OVERRIDE; virtual void SetOutputSize(const SkISize& size) OVERRIDE; virtual void SetClipRect(const SkIRect& clip_rect) OVERRIDE; - virtual void RefreshRegion(const SkRegion& region) OVERRIDE; + virtual void RefreshRects(const RectVector& rects) OVERRIDE; private: enum State { @@ -38,15 +38,16 @@ class DecoderVp8 : public Decoder { // Return true if scaling is enabled bool DoScaling() const; - // Perform color space conversion on the specified region. - // Writes the updated region to |output_region|. - void ConvertRegion(const SkRegion& region, - SkRegion* output_region); + // Perform color space conversion on the specified rectangles. + // Write the updated rectangles to |output_rects|. + void ConvertRects(const RectVector& rects, + RectVector* output_rects); // Perform scaling and color space conversion on the specified - // region. Writes the updated rectangles to |output_region|. - void ScaleAndConvertRegion(const SkRegion& region, - SkRegion* output_region); + // rectangles. + // Write the updated rectangles to |output_rects|. + void ScaleAndConvertRects(const RectVector& rects, + RectVector* output_rects); // The internal state of the decoder. State state_; @@ -59,8 +60,8 @@ class DecoderVp8 : public Decoder { // Pointer to the last decoded image. vpx_image_t* last_image_; - // The region updated by the most recent decode. - SkRegion updated_region_; + // Record the updated rects in the last decode. + RectVector updated_rects_; // Clipping rect for the output of the decoder. SkIRect clip_rect_; |