Index: remoting/base/decoder_vp8.cc |
diff --git a/remoting/base/decoder_vp8.cc b/remoting/base/decoder_vp8.cc |
index 4074691353d3d326428405ed5cdd2c6aa033fd61..b27f247112a1d11e53f4a4ddba6e88c1ab9643ee 100644 |
--- a/remoting/base/decoder_vp8.cc |
+++ b/remoting/base/decoder_vp8.cc |
@@ -22,8 +22,7 @@ DecoderVp8::DecoderVp8() |
: state_(kUninitialized), |
codec_(NULL), |
last_image_(NULL), |
- clip_rect_(SkIRect::MakeEmpty()), |
- output_size_(SkISize::Make(0, 0)) { |
+ screen_size_(SkISize::Make(0, 0)) { |
} |
DecoderVp8::~DecoderVp8() { |
@@ -34,16 +33,10 @@ DecoderVp8::~DecoderVp8() { |
delete codec_; |
} |
-void DecoderVp8::Initialize(scoped_refptr<media::VideoFrame> frame) { |
+void DecoderVp8::Initialize(const SkISize& screen_size) { |
DCHECK_EQ(kUninitialized, state_); |
- if (frame->format() != media::VideoFrame::RGB32) { |
- LOG(INFO) << "DecoderVp8 only supports RGB32 as output"; |
- state_ = kError; |
- return; |
- } |
- frame_ = frame; |
- |
+ screen_size_ = screen_size; |
state_ = kReady; |
} |
@@ -102,16 +95,11 @@ Decoder::DecodeResult DecoderVp8::DecodePacket(const VideoPacket* packet) { |
region.op(rect, SkRegion::kUnion_Op); |
} |
- RefreshRegion(region); |
+ UpdateRegion(region); |
return DECODE_DONE; |
} |
-void DecoderVp8::GetUpdatedRegion(SkRegion* region) { |
- region->swap(updated_region_); |
-} |
- |
void DecoderVp8::Reset() { |
- frame_ = NULL; |
state_ = kUninitialized; |
Wez
2012/02/07 01:56:31
Do we need this, since when we use it, we immediat
alexeypa (please no reviews)
2012/02/15 23:06:22
Done.
|
} |
@@ -123,122 +111,48 @@ VideoPacketFormat::Encoding DecoderVp8::Encoding() { |
return VideoPacketFormat::ENCODING_VP8; |
} |
-void DecoderVp8::SetOutputSize(const SkISize& size) { |
- output_size_ = size; |
-} |
- |
-void DecoderVp8::SetClipRect(const SkIRect& clip_rect) { |
- clip_rect_ = clip_rect; |
-} |
- |
-void DecoderVp8::RefreshRegion(const SkRegion& region) { |
- // 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 |
- // frame, so currently we render 1:1 in that case; the app will see the |
- // host size change and resize us if need be. |
- if (output_size_.width() > static_cast<int>(frame_->width())) |
- output_size_.set(frame_->width(), output_size_.height()); |
- 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_); |
- } |
-} |
- |
-bool DecoderVp8::DoScaling() const { |
- DCHECK(last_image_); |
- return !output_size_.equals(last_image_->d_w, last_image_->d_h); |
+void DecoderVp8::UpdateRegion(const SkRegion& region) { |
+ updated_region_.op(region, SkRegion::kUnion_Op); |
} |
-void DecoderVp8::ConvertRegion(const SkRegion& input_region, |
- SkRegion* output_region) { |
- if (!last_image_) |
- return; |
- |
+void DecoderVp8::Draw(const SkISize& view_size, |
+ const SkIRect& clip_area, |
+ uint8* image_buffer, |
+ int image_stride, |
+ SkRegion* output_region) { |
output_region->setEmpty(); |
- // Clip based on both the output dimensions and Pepper clip rect. |
- // ConvertYUVToRGB32WithRect() requires even X and Y coordinates, so we align |
- // |clip_rect| to prevent clipping from breaking alignment. We then clamp it |
- // to the image dimensions, which may lead to odd width & height, which we |
- // can cope with. |
- SkIRect clip_rect = AlignRect(clip_rect_); |
- if (!clip_rect.intersect(SkIRect::MakeWH(last_image_->d_w, last_image_->d_h))) |
- return; |
- |
- 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()) { |
- // Align the rectangle so the top-left coordinates are even, for |
- // ConvertYUVToRGB32WithRect(). |
- SkIRect dest_rect(AlignRect(i.rect())); |
- |
- // Clip the rectangle, preserving alignment since |clip_rect| is aligned. |
- if (!dest_rect.intersect(clip_rect)) |
- continue; |
- |
- ConvertYUVToRGB32WithRect(last_image_->planes[0], |
- last_image_->planes[1], |
- last_image_->planes[2], |
- output_rgb_buf, |
- dest_rect, |
- last_image_->stride[0], |
- last_image_->stride[1], |
- output_stride); |
- |
- output_region->op(dest_rect, SkRegion::kUnion_Op); |
- } |
-} |
- |
-void DecoderVp8::ScaleAndConvertRegion(const SkRegion& input_region, |
- SkRegion* output_region) { |
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(); |
- |
- // Clip based on both the output dimensions and Pepper clip rect. |
- SkIRect clip_rect = clip_rect_; |
- if (!clip_rect.intersect(SkIRect::MakeSize(output_size_))) |
- return; |
- |
- SkISize image_size = SkISize::Make(last_image_->d_w, last_image_->d_h); |
- uint8* output_rgb_buf = frame_->data(media::VideoFrame::kRGBPlane); |
- const int output_stride = frame_->stride(media::VideoFrame::kRGBPlane); |
+ SkIRect source_clip = SkIRect::MakeWH(last_image_->d_w, last_image_->d_h); |
- for (SkRegion::Iterator i(input_region); !i.done(); i.next()) { |
+ for (SkRegion::Iterator i(updated_region_); !i.done(); i.next()) { |
// Determine the scaled area affected by this rectangle changing. |
- SkIRect output_rect = ScaleRect(i.rect(), image_size, output_size_); |
- if (!output_rect.intersect(clip_rect)) |
+ SkIRect rect = i.rect(); |
+ if (!rect.intersect(source_clip)) |
+ continue; |
+ rect = ScaleRect(rect, screen_size_, view_size); |
+ if (!rect.intersect(clip_area)) |
continue; |
- // The scaler will not to read outside the input dimensions. |
- media::ScaleYUVToRGB32WithRect(last_image_->planes[0], |
- last_image_->planes[1], |
- last_image_->planes[2], |
- output_rgb_buf, |
- image_size.width(), |
- image_size.height(), |
- output_size_.width(), |
- output_size_.height(), |
- output_rect.x(), |
- output_rect.y(), |
- output_rect.right(), |
- output_rect.bottom(), |
- last_image_->stride[0], |
- last_image_->stride[1], |
- output_stride); |
- |
- output_region->op(output_rect, SkRegion::kUnion_Op); |
+ ConvertAndScaleYUVToRGB32Rect(last_image_->planes[0], |
+ last_image_->planes[1], |
+ last_image_->planes[2], |
+ last_image_->stride[0], |
+ last_image_->stride[1], |
+ screen_size_, |
+ source_clip, |
+ image_buffer, |
+ image_stride, |
+ view_size, |
+ clip_area, |
+ rect); |
+ |
+ output_region->op(rect, SkRegion::kUnion_Op); |
} |
+ |
+ updated_region_.setEmpty(); |
} |
} // namespace remoting |