summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-21 05:49:45 +0000
committerwez@chromium.org <wez@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-01-21 05:49:45 +0000
commit76a1fdeeed9cc4d90f462a794a822c87cd6309a2 (patch)
tree28e174b0c4ea4e10c0ccd507f0466f6dc0496f02
parent5af0c6bce269f1f6905fd6c0ec4e5256bf160970 (diff)
downloadchromium_src-76a1fdeeed9cc4d90f462a794a822c87cd6309a2.zip
chromium_src-76a1fdeeed9cc4d90f462a794a822c87cd6309a2.tar.gz
chromium_src-76a1fdeeed9cc4d90f462a794a822c87cd6309a2.tar.bz2
Revert 118600 - Merge 115088 - Remoting client rectangle decoder and VP8 decoder fixes.
These are required to avoid artefacts when linear scaling is implemented. BUG=93451 Review URL: http://codereview.chromium.org/8745008 TBR=wez@chromium.org Review URL: https://chromiumcodereview.appspot.com/9131033 TBR=wez@chromium.org Review URL: https://chromiumcodereview.appspot.com/9131034 git-svn-id: svn://svn.chromium.org/chrome/branches/963/src@118609 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--remoting/base/decoder_vp8.cc89
-rw-r--r--remoting/base/util.cc16
-rw-r--r--remoting/base/util.h7
-rw-r--r--remoting/client/rectangle_update_decoder.cc47
-rw-r--r--remoting/client/rectangle_update_decoder.h1
5 files changed, 80 insertions, 80 deletions
diff --git a/remoting/base/decoder_vp8.cc b/remoting/base/decoder_vp8.cc
index 8c8a205..6ce7f03 100644
--- a/remoting/base/decoder_vp8.cc
+++ b/remoting/base/decoder_vp8.cc
@@ -4,8 +4,6 @@
#include "remoting/base/decoder_vp8.h"
-#include <math.h>
-
#include "base/logging.h"
#include "media/base/media.h"
#include "media/base/yuv_convert.h"
@@ -156,91 +154,82 @@ bool DecoderVp8::DoScaling() const {
return horizontal_scale_ratio_ != 1.0 || vertical_scale_ratio_ != 1.0;
}
-void DecoderVp8::ConvertRects(const RectVector& input_rects,
+void DecoderVp8::ConvertRects(const RectVector& rects,
RectVector* output_rects) {
if (!last_image_)
return;
- // The conversion routine we use is optimized for even widths & heights.
- int image_width = RoundToTwosMultiple(last_image_->d_w);
- int image_height = RoundToTwosMultiple(last_image_->d_h);
-
- uint8* output_rgb_buf = frame_->data(media::VideoFrame::kRGBPlane);
- const int output_stride = frame_->stride(media::VideoFrame::kRGBPlane);
+ uint8* data_start = frame_->data(media::VideoFrame::kRGBPlane);
+ const int stride = frame_->stride(media::VideoFrame::kRGBPlane);
output_rects->clear();
+ output_rects->reserve(rects.size());
+ for (size_t i = 0; i < rects.size(); ++i) {
+ // Clip by the clipping rectangle first.
+ SkIRect dest_rect = rects[i];
+ if (!dest_rect.intersect(clip_rect_))
+ continue;
- // Clip based on both the output dimensions and Pepper clip rect.
- SkIRect clip_rect = clip_rect_;
- if (!clip_rect.intersect(SkIRect::MakeWH(image_width, image_height)))
- return;
+ // Round down the image width and height.
+ int image_width = RoundToTwosMultiple(last_image_->d_w);
+ int image_height = RoundToTwosMultiple(last_image_->d_h);
- output_rects->reserve(input_rects.size());
+ // Then clip by the rounded down dimension of the image for safety.
+ if (!dest_rect.intersect(SkIRect::MakeWH(image_width, image_height)))
+ continue;
- for (size_t i = 0; i < input_rects.size(); ++i) {
// Align the rectangle to avoid artifacts in color space conversion.
- SkIRect dest_rect = AlignRect(input_rects[i]);
-
- // Clip to the image and Pepper clip region.
- if (!dest_rect.intersect(clip_rect))
- continue;
+ dest_rect = AlignRect(dest_rect);
ConvertYUVToRGB32WithRect(last_image_->planes[0],
last_image_->planes[1],
last_image_->planes[2],
- output_rgb_buf,
+ data_start,
dest_rect,
last_image_->stride[0],
last_image_->stride[1],
- output_stride);
-
+ stride);
output_rects->push_back(dest_rect);
}
}
-void DecoderVp8::ScaleAndConvertRects(const RectVector& input_rects,
+void DecoderVp8::ScaleAndConvertRects(const RectVector& rects,
RectVector* output_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_);
+ uint8* data_start = frame_->data(media::VideoFrame::kRGBPlane);
+ const int stride = frame_->stride(media::VideoFrame::kRGBPlane);
output_rects->clear();
+ output_rects->reserve(rects.size());
+ for (size_t i = 0; i < rects.size(); ++i) {
+ // Round down the image width and height.
+ int image_width = RoundToTwosMultiple(last_image_->d_w);
+ int image_height = RoundToTwosMultiple(last_image_->d_h);
+
+ // Clip by the rounded down dimension of the image for safety.
+ SkIRect dest_rect = rects[i];
+ if (!dest_rect.intersect(SkIRect::MakeWH(image_width, image_height)))
+ continue;
- // 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)))
- return;
-
- output_rects->reserve(input_rects.size());
+ // Align the rectangle to avoid artifacts in color space conversion.
+ dest_rect = AlignRect(dest_rect);
- 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],
+ SkIRect scaled_rect = ScaleRect(dest_rect,
horizontal_scale_ratio_,
vertical_scale_ratio_);
- if (!output_rect.intersect(clip_rect))
- continue;
- // The scaler will not read outside the input dimensions.
ScaleYUVToRGB32WithRect(last_image_->planes[0],
last_image_->planes[1],
last_image_->planes[2],
- output_rgb_buf,
- input_rects[i],
- output_rect,
+ data_start,
+ dest_rect,
+ scaled_rect,
last_image_->stride[0],
last_image_->stride[1],
- output_stride);
- output_rects->push_back(output_rect);
+ stride);
+ output_rects->push_back(scaled_rect);
}
}
diff --git a/remoting/base/util.cc b/remoting/base/util.cc
index 23af0ea..e960f09 100644
--- a/remoting/base/util.cc
+++ b/remoting/base/util.cc
@@ -2,15 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "remoting/base/util.h"
-
-#include <math.h>
-
#include "base/logging.h"
#include "base/stringprintf.h"
#include "base/time.h"
#include "media/base/video_frame.h"
#include "media/base/yuv_convert.h"
+#include "remoting/base/util.h"
using media::VideoFrame;
@@ -153,11 +150,12 @@ SkIRect AlignRect(const SkIRect& rect) {
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);
- return SkIRect::MakeLTRB(left, top, right, bottom);
+ int x = rect.fLeft * horizontal_ratio;
+ int y = rect.fTop * vertical_ratio;
+ int w = rect.fRight * horizontal_ratio - x;
+ int h = rect.fBottom * vertical_ratio - y;
+
+ return SkIRect::MakeXYWH(x, y, w, h);
}
void CopyRect(const uint8* src_plane,
diff --git a/remoting/base/util.h b/remoting/base/util.h
index cf2b2dd..b60e072 100644
--- a/remoting/base/util.h
+++ b/remoting/base/util.h
@@ -5,8 +5,6 @@
#ifndef REMOTING_BASE_UTIL_H_
#define REMOTING_BASE_UTIL_H_
-#include <string>
-
#include "media/base/video_frame.h"
#include "third_party/skia/include/core/SkRect.h"
@@ -54,9 +52,8 @@ 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.
+// Return a scaled rectangle using the horizontal and vertical scale
+// factors.
SkIRect ScaleRect(const SkIRect& rect,
double horizontal_ratio,
double vertical_ratio);
diff --git a/remoting/client/rectangle_update_decoder.cc b/remoting/client/rectangle_update_decoder.cc
index 09e67a2..9e09d7f 100644
--- a/remoting/client/rectangle_update_decoder.cc
+++ b/remoting/client/rectangle_update_decoder.cc
@@ -138,20 +138,10 @@ void RectangleUpdateDecoder::SetScaleRatios(double horizontal_ratio,
return;
}
- // TODO(wez): Refresh the frame only if the ratio has changed.
- if (frame_) {
- SkIRect frame_rect = SkIRect::MakeWH(frame_->width(), frame_->height());
- refresh_rects_.push_back(frame_rect);
- }
-
// TODO(hclam): If the scale ratio has changed we should reallocate a
// VideoFrame of different size. However if the scale ratio is always
// smaller than 1.0 we can use the same video frame.
decoder_->SetScaleRatios(horizontal_ratio, vertical_ratio);
-
- // TODO(wez): Defer refresh, so that resize, which will affect both scale
- // factor and clip rect, doesn't lead to unnecessary refreshes.
- DoRefresh();
}
void RectangleUpdateDecoder::UpdateClipRect(const SkIRect& new_clip_rect) {
@@ -165,16 +155,41 @@ void RectangleUpdateDecoder::UpdateClipRect(const SkIRect& new_clip_rect) {
if (new_clip_rect == clip_rect_ || !decoder_.get())
return;
- // TODO(wez): Only refresh newly-exposed portions of the frame.
- if (frame_) {
- SkIRect frame_rect = SkIRect::MakeWH(frame_->width(), frame_->height());
- refresh_rects_.push_back(frame_rect);
+ // Find out the rectangles to show because of clip rect is updated.
+ if (new_clip_rect.fTop < clip_rect_.fTop) {
+ refresh_rects_.push_back(
+ SkIRect::MakeXYWH(new_clip_rect.fLeft,
+ new_clip_rect.fTop,
+ new_clip_rect.width(),
+ clip_rect_.fTop - new_clip_rect.fTop));
+ }
+
+ if (new_clip_rect.fLeft < clip_rect_.fLeft) {
+ refresh_rects_.push_back(
+ SkIRect::MakeXYWH(new_clip_rect.fLeft,
+ clip_rect_.fTop,
+ clip_rect_.fLeft - new_clip_rect.fLeft,
+ clip_rect_.height()));
+ }
+
+ if (new_clip_rect.fRight > clip_rect_.fRight) {
+ refresh_rects_.push_back(
+ SkIRect::MakeXYWH(clip_rect_.fRight,
+ clip_rect_.fTop,
+ new_clip_rect.fRight - clip_rect_.fRight,
+ new_clip_rect.height()));
+ }
+
+ if (new_clip_rect.fBottom > clip_rect_.fBottom) {
+ refresh_rects_.push_back(
+ SkIRect::MakeXYWH(new_clip_rect.fLeft,
+ clip_rect_.fBottom,
+ new_clip_rect.width(),
+ new_clip_rect.fBottom - clip_rect_.fBottom));
}
clip_rect_ = new_clip_rect;
decoder_->SetClipRect(new_clip_rect);
-
- // TODO(wez): Defer refresh so that multiple events can be batched.
DoRefresh();
}
diff --git a/remoting/client/rectangle_update_decoder.h b/remoting/client/rectangle_update_decoder.h
index 53f0cdd..fd5b2c2 100644
--- a/remoting/client/rectangle_update_decoder.h
+++ b/remoting/client/rectangle_update_decoder.h
@@ -62,6 +62,7 @@ class RectangleUpdateDecoder :
void AllocateFrame(const VideoPacket* packet, const base::Closure& done);
void ProcessPacketData(const VideoPacket* packet, const base::Closure& done);
+ void RefreshRects(const RectVector& rects);
// Obtain updated rectangles from decoder and submit it to the consumer.
void SubmitToConsumer();