diff options
author | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-22 10:20:33 +0000 |
---|---|---|
committer | wez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-12-22 10:20:33 +0000 |
commit | 15e7b6c7f10e09714e47179015acce8ba87164e8 (patch) | |
tree | 5c4951dab6847f5652ad087e0027fbb1df3706ec /remoting/base | |
parent | 6bede3d585e84feb3b21f97d0b09559b40b21af9 (diff) | |
download | chromium_src-15e7b6c7f10e09714e47179015acce8ba87164e8.zip chromium_src-15e7b6c7f10e09714e47179015acce8ba87164e8.tar.gz chromium_src-15e7b6c7f10e09714e47179015acce8ba87164e8.tar.bz2 |
Refactoring of the client-side input pipeline and scaling dimension management.
The main changes are:
* Express key-release, mouse coordinate scaling and clamping as InputStubs.
* KeyEventTracker handles key release.
* MouseInputFilter handles mouse scaling & clamping.
* PepperInputHandler converts Pepper events to InputStub events.
* Replace scaling ratios with host and view dimensions.
This resulted in some related changes
* The DecoderVp8 enforces a <=1:1 output-size before converting the frame.
* The setScaleToFit() API now has no effect.
* ChromotingView has become a pure interface again.
Things this CL is currently missing:
* Unit-tests for the new components.
Future work:
* Move the non-Pepper-specific input pipeline components to ChromotingClient.
* Rework the decode / convert / scale / render pipeline.
BUG=93552
TEST=remoting_unittests, and manual testing.
Review URL: http://codereview.chromium.org/8985007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115511 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/base')
-rw-r--r-- | remoting/base/decoder.h | 14 | ||||
-rw-r--r-- | remoting/base/decoder_vp8.cc | 56 | ||||
-rw-r--r-- | remoting/base/decoder_vp8.h | 8 | ||||
-rw-r--r-- | remoting/base/util.cc | 50 | ||||
-rw-r--r-- | remoting/base/util.h | 10 |
5 files changed, 64 insertions, 74 deletions
diff --git a/remoting/base/decoder.h b/remoting/base/decoder.h index d932ff1..dd37757 100644 --- a/remoting/base/decoder.h +++ b/remoting/base/decoder.h @@ -57,11 +57,10 @@ class Decoder { virtual VideoPacketFormat::Encoding Encoding() = 0; - // Set the scale factors of the decoded output. If the decoder doesn't support - // scaling then this all is ignored. - // If both |horizontal_ratio| and |vertical_ratio| equal 1.0 then scaling is - // turned off. - virtual void SetScaleRatios(double horizontal_ratio, double vertical_ratio) {} + // Set the output dimensions for the decoder. If the dimensions are empty + // then the source is rendered without scaling. + // Output dimensions are ignored if the decoder doesn't support scaling. + virtual void SetOutputSize(const SkISize& size) {} // Set the clipping rectangle to the decoder. Decoder should respect this and // only output changes in this rectangle. The new clipping rectangle will be @@ -71,9 +70,8 @@ class Decoder { virtual void SetClipRect(const SkIRect& clip_rect) {} // Force decoder to output a video frame with content in |rects| using the - // last decoded video frame. - // - // Coordinates of rectangles supplied here are before scaling. + // last decoded video frame. |rects| are expressed in video frame rather + // than output coordinates. virtual void RefreshRects(const RectVector& rects) {} }; diff --git a/remoting/base/decoder_vp8.cc b/remoting/base/decoder_vp8.cc index 8c8a205..af1f718 100644 --- a/remoting/base/decoder_vp8.cc +++ b/remoting/base/decoder_vp8.cc @@ -23,8 +23,7 @@ DecoderVp8::DecoderVp8() codec_(NULL), last_image_(NULL), clip_rect_(SkIRect::MakeEmpty()), - horizontal_scale_ratio_(1.0), - vertical_scale_ratio_(1.0) { + output_size_(SkISize::Make(0, 0)) { } DecoderVp8::~DecoderVp8() { @@ -103,10 +102,17 @@ Decoder::DecodeResult DecoderVp8::DecodePacket(const VideoPacket* packet) { remoting_rect.height())); } - if (!DoScaling()) - ConvertRects(rects, &updated_rects_); - else - ScaleAndConvertRects(rects, &updated_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 + // 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_.height() > static_cast<int>(frame_->height()))) { + output_size_.set(frame_->width(), frame_->height()); + } + + RefreshRects(rects); return DECODE_DONE; } @@ -127,18 +133,8 @@ VideoPacketFormat::Encoding DecoderVp8::Encoding() { return VideoPacketFormat::ENCODING_VP8; } -void DecoderVp8::SetScaleRatios(double horizontal_ratio, - double vertical_ratio) { - // TODO(hclam): Ratio greater than 1.0 is not supported. This is - // because we need to reallocate the backing video frame and this - // is not implemented yet. - if (horizontal_ratio > 1.0 || horizontal_ratio <= 0.0 || - vertical_ratio > 1.0 || vertical_ratio <= 0.0) { - return; - } - - horizontal_scale_ratio_ = horizontal_ratio; - vertical_scale_ratio_ = vertical_ratio; +void DecoderVp8::SetOutputSize(const SkISize& size) { + output_size_ = size; } void DecoderVp8::SetClipRect(const SkIRect& clip_rect) { @@ -153,7 +149,8 @@ void DecoderVp8::RefreshRects(const RectVector& rects) { } bool DecoderVp8::DoScaling() const { - return horizontal_scale_ratio_ != 1.0 || vertical_scale_ratio_ != 1.0; + DCHECK(last_image_); + return !output_size_.equals(last_image_->d_w, last_image_->d_h); } void DecoderVp8::ConvertRects(const RectVector& input_rects, @@ -203,30 +200,25 @@ void DecoderVp8::ScaleAndConvertRects(const RectVector& input_rects, if (!last_image_) return; - int input_width = last_image_->d_w; - int input_height = last_image_->d_h; - - uint8* output_rgb_buf = frame_->data(media::VideoFrame::kRGBPlane); - const int output_stride = frame_->stride(media::VideoFrame::kRGBPlane); - - // TODO(wez): Resize |frame_| to our desired output dimensions when scaling. - int output_width = ceil(input_width * horizontal_scale_ratio_); - int output_height = ceil(input_height * vertical_scale_ratio_); + DCHECK(output_size_.width() <= static_cast<int>(frame_->width())); + DCHECK(output_size_.height() <= static_cast<int>(frame_->height())); output_rects->clear(); // Clip based on both the output dimensions and Pepper clip rect. SkIRect clip_rect = clip_rect_; - if (!clip_rect.intersect(SkIRect::MakeWH(output_width, output_height))) + 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); + 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(input_rects[i], - horizontal_scale_ratio_, - vertical_scale_ratio_); + SkIRect output_rect = ScaleRect(input_rects[i], image_size, output_size_); if (!output_rect.intersect(clip_rect)) continue; diff --git a/remoting/base/decoder_vp8.h b/remoting/base/decoder_vp8.h index 33ec147..a89991c 100644 --- a/remoting/base/decoder_vp8.h +++ b/remoting/base/decoder_vp8.h @@ -24,8 +24,7 @@ class DecoderVp8 : public Decoder { virtual bool IsReadyForData() OVERRIDE; virtual void Reset() OVERRIDE; virtual VideoPacketFormat::Encoding Encoding() OVERRIDE; - virtual void SetScaleRatios(double horizontal_ratio, - double vertical_ratio) OVERRIDE; + virtual void SetOutputSize(const SkISize& size) OVERRIDE; virtual void SetClipRect(const SkIRect& clip_rect) OVERRIDE; virtual void RefreshRects(const RectVector& rects) OVERRIDE; @@ -67,9 +66,8 @@ class DecoderVp8 : public Decoder { // Clipping rect for the output of the decoder. SkIRect clip_rect_; - // Scale factors of the decoded output. - double horizontal_scale_ratio_; - double vertical_scale_ratio_; + // Output dimensions. + SkISize output_size_; DISALLOW_COPY_AND_ASSIGN(DecoderVp8); }; diff --git a/remoting/base/util.cc b/remoting/base/util.cc index 23af0ea..d069ce8 100644 --- a/remoting/base/util.cc +++ b/remoting/base/util.cc @@ -61,9 +61,9 @@ void ConvertYUVToRGB32WithRect(const uint8* y_plane, int y_stride, int uv_stride, int rgb_stride) { - int rgb_offset = CalculateRGBOffset(rect.fLeft, rect.fTop, rgb_stride); - int y_offset = CalculateYOffset(rect.fLeft, rect.fTop, y_stride); - int uv_offset = CalculateUVOffset(rect.fLeft, rect.fTop, uv_stride); + int rgb_offset = CalculateRGBOffset(rect.left(), rect.top(), rgb_stride); + int y_offset = CalculateYOffset(rect.left(), rect.top(), y_stride); + int uv_offset = CalculateUVOffset(rect.left(), rect.top(), uv_stride); media::ConvertYUVToRGB32(y_plane + y_offset, u_plane + uv_offset, @@ -86,14 +86,14 @@ void ScaleYUVToRGB32WithRect(const uint8* y_plane, int y_stride, int uv_stride, int rgb_stride) { - int rgb_offset = CalculateRGBOffset(dest_rect.fLeft, - dest_rect.fTop, + int rgb_offset = CalculateRGBOffset(dest_rect.left(), + dest_rect.top(), rgb_stride); - int y_offset = CalculateYOffset(source_rect.fLeft, - source_rect.fTop, + int y_offset = CalculateYOffset(source_rect.left(), + source_rect.top(), y_stride); - int uv_offset = CalculateUVOffset(source_rect.fLeft, - source_rect.fTop, + int uv_offset = CalculateUVOffset(source_rect.left(), + source_rect.top(), uv_stride); media::ScaleYUVToRGB32(y_plane + y_offset, @@ -143,20 +143,22 @@ int RoundToTwosMultiple(int x) { } SkIRect AlignRect(const SkIRect& rect) { - int x = RoundToTwosMultiple(rect.fLeft); - int y = RoundToTwosMultiple(rect.fTop); - int right = RoundToTwosMultiple(rect.fRight + 1); - int bottom = RoundToTwosMultiple(rect.fBottom + 1); - return SkIRect::MakeXYWH(x, y, right - x, bottom - y); + int x = RoundToTwosMultiple(rect.left()); + int y = RoundToTwosMultiple(rect.top()); + int right = RoundToTwosMultiple(rect.right() + 1); + int bottom = RoundToTwosMultiple(rect.bottom() + 1); + return SkIRect::MakeLTRB(x, y, right, bottom); } SkIRect ScaleRect(const SkIRect& rect, - double horizontal_ratio, - double vertical_ratio) { - int left = floor(rect.left() * horizontal_ratio); - int top = floor(rect.top() * vertical_ratio); - int right = ceil(rect.right() * horizontal_ratio); - int bottom = ceil(rect.bottom() * vertical_ratio); + const SkISize& in_size, + const SkISize& out_size) { + int left = (rect.left() * out_size.width()) / in_size.width(); + int top = (rect.top() * out_size.height()) / in_size.height(); + int right = (rect.right() * out_size.width() + out_size.width() - 1) / + in_size.width(); + int bottom = (rect.bottom() * out_size.height() + out_size.height() - 1) / + in_size.height(); return SkIRect::MakeLTRB(left, top, right, bottom); } @@ -166,10 +168,10 @@ void CopyRect(const uint8* src_plane, int dest_plane_stride, int bytes_per_pixel, const SkIRect& rect) { - // Get the address of the starting point. - 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; + // Get the address of the starting point. + const int src_y_offset = src_plane_stride * rect.top(); + const int dest_y_offset = dest_plane_stride * rect.top(); + const int x_offset = bytes_per_pixel * rect.left(); 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 cf2b2dd..8bed6f4 100644 --- a/remoting/base/util.h +++ b/remoting/base/util.h @@ -54,12 +54,12 @@ int RoundToTwosMultiple(int x); // Align the sides of the rectangle to multiples of 2 (expanding outwards). SkIRect AlignRect(const SkIRect& rect); -// Scale a rectangle by horizontal and vertical factors. If the result has -// non-integer coordinates then the smallest integer-coordinate rectangle that -// wholly encloses it is returned. +// Scales the supplied rectangle from |in_size| coordinates to |out_size|. +// If the result has non-integer coordinates then the smallest integer- +// coordinate rectangle that wholly encloses it is returned. SkIRect ScaleRect(const SkIRect& rect, - double horizontal_ratio, - double vertical_ratio); + const SkISize& in_size, + const SkISize& out_size); // Copy pixels in the rectangle from source to destination. void CopyRect(const uint8* src_plane, |