diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-25 22:16:21 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-09-25 22:16:21 +0000 |
commit | e59d6594e14b9a697098cc517f7218941e2787ff (patch) | |
tree | e04cc296501d095e24acfb5357c5af5bacebca82 /remoting/base | |
parent | 1f291cd57a56e70369dc2e47e3d4be6102254102 (diff) | |
download | chromium_src-e59d6594e14b9a697098cc517f7218941e2787ff.zip chromium_src-e59d6594e14b9a697098cc517f7218941e2787ff.tar.gz chromium_src-e59d6594e14b9a697098cc517f7218941e2787ff.tar.bz2 |
Remove dependency on Skia from chromoting client.
Now DesktopRegion, DesktopRect and DesktopSize are used instead of
corresponding skia types.
R=alexeypa@chromium.org
TBR=reed@google.com (for _moved_ skia dependency)
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=224101
Review URL: https://codereview.chromium.org/23440046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@225265 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/base')
-rw-r--r-- | remoting/base/util.cc | 137 | ||||
-rw-r--r-- | remoting/base/util.h | 44 | ||||
-rw-r--r-- | remoting/base/util_unittest.cc | 61 |
3 files changed, 127 insertions, 115 deletions
diff --git a/remoting/base/util.cc b/remoting/base/util.cc index 0a0a529..d27b651 100644 --- a/remoting/base/util.cc +++ b/remoting/base/util.cc @@ -12,7 +12,7 @@ #include "media/base/video_frame.h" #include "media/base/yuv_convert.h" #include "third_party/libyuv/include/libyuv/convert.h" -#include "third_party/skia/include/core/SkRegion.h" +#include "third_party/webrtc/modules/desktop_capture/desktop_region.h" #if defined(OS_POSIX) #include <pwd.h> @@ -73,54 +73,56 @@ void ConvertRGB32ToYUVWithRect(const uint8* rgb_plane, width, height); } -void ConvertAndScaleYUVToRGB32Rect(const uint8* source_yplane, - const uint8* source_uplane, - const uint8* source_vplane, - int source_ystride, - int source_uvstride, - const SkISize& source_size, - const SkIRect& source_buffer_rect, - uint8* dest_buffer, - int dest_stride, - const SkISize& dest_size, - const SkIRect& dest_buffer_rect, - const SkIRect& dest_rect) { +void ConvertAndScaleYUVToRGB32Rect( + const uint8* source_yplane, + const uint8* source_uplane, + const uint8* source_vplane, + int source_ystride, + int source_uvstride, + const webrtc::DesktopSize& source_size, + const webrtc::DesktopRect& source_buffer_rect, + uint8* dest_buffer, + int dest_stride, + const webrtc::DesktopSize& dest_size, + const webrtc::DesktopRect& dest_buffer_rect, + const webrtc::DesktopRect& dest_rect) { // N.B. It is caller's responsibility to check if strides are large enough. We // cannot do it here anyway. - DCHECK(SkIRect::MakeSize(source_size).contains(source_buffer_rect)); - DCHECK(SkIRect::MakeSize(dest_size).contains(dest_buffer_rect)); - DCHECK(dest_buffer_rect.contains(dest_rect)); - DCHECK(ScaleRect(source_buffer_rect, source_size, dest_size). - contains(dest_rect)); + DCHECK(DoesRectContain(webrtc::DesktopRect::MakeSize(source_size), + source_buffer_rect)); + DCHECK(DoesRectContain(webrtc::DesktopRect::MakeSize(dest_size), + dest_buffer_rect)); + DCHECK(DoesRectContain(dest_buffer_rect, dest_rect)); + DCHECK(DoesRectContain(ScaleRect(source_buffer_rect, source_size, dest_size), + dest_rect)); // If the source and/or destination buffers don't start at (0, 0) // offset the pointers to pretend we have complete buffers. - int y_offset = - CalculateYOffset(source_buffer_rect.x(), - source_buffer_rect.y(), + int y_offset = - CalculateYOffset(source_buffer_rect.left(), + source_buffer_rect.top(), source_ystride); - int uv_offset = - CalculateUVOffset(source_buffer_rect.x(), - source_buffer_rect.y(), + int uv_offset = - CalculateUVOffset(source_buffer_rect.left(), + source_buffer_rect.top(), source_uvstride); - int rgb_offset = - CalculateRGBOffset(dest_buffer_rect.x(), - dest_buffer_rect.y(), + int rgb_offset = - CalculateRGBOffset(dest_buffer_rect.left(), + dest_buffer_rect.top(), dest_stride); // See if scaling is needed. - if (source_size == dest_size) { + if (source_size.equals(dest_size)) { // Calculate the inner rectangle that can be copied by the optimized // libyuv::I420ToARGB(). - SkIRect inner_rect = - SkIRect::MakeLTRB(RoundToTwosMultiple(dest_rect.left() + 1), - RoundToTwosMultiple(dest_rect.top() + 1), - dest_rect.right(), - dest_rect.bottom()); + webrtc::DesktopRect inner_rect = + webrtc::DesktopRect::MakeLTRB(RoundToTwosMultiple(dest_rect.left() + 1), + RoundToTwosMultiple(dest_rect.top() + 1), + dest_rect.right(), dest_rect.bottom()); // Offset pointers to point to the top left corner of the inner rectangle. - y_offset += CalculateYOffset(inner_rect.x(), inner_rect.y(), + y_offset += CalculateYOffset(inner_rect.left(), inner_rect.top(), source_ystride); - uv_offset += CalculateUVOffset(inner_rect.x(), inner_rect.y(), + uv_offset += CalculateUVOffset(inner_rect.left(), inner_rect.top(), source_uvstride); - rgb_offset += CalculateRGBOffset(inner_rect.x(), inner_rect.y(), + rgb_offset += CalculateRGBOffset(inner_rect.left(), inner_rect.top(), dest_stride); libyuv::I420ToARGB(source_yplane + y_offset, source_ystride, @@ -130,15 +132,14 @@ void ConvertAndScaleYUVToRGB32Rect(const uint8* source_yplane, inner_rect.width(), inner_rect.height()); // Now see if some pixels weren't copied due to alignment. - if (dest_rect != inner_rect) { - SkIRect outer_rect = - SkIRect::MakeLTRB(RoundToTwosMultiple(dest_rect.left()), - RoundToTwosMultiple(dest_rect.top()), - dest_rect.right(), - dest_rect.bottom()); + if (!dest_rect.equals(inner_rect)) { + webrtc::DesktopRect outer_rect = + webrtc::DesktopRect::MakeLTRB(RoundToTwosMultiple(dest_rect.left()), + RoundToTwosMultiple(dest_rect.top()), + dest_rect.right(), dest_rect.bottom()); - SkIPoint offset = SkIPoint::Make(outer_rect.x() - inner_rect.x(), - outer_rect.y() - inner_rect.y()); + webrtc::DesktopVector offset(outer_rect.left() - inner_rect.left(), + outer_rect.top() - inner_rect.top()); // Offset the pointers to point to the top left corner of the outer // rectangle. @@ -147,11 +148,12 @@ void ConvertAndScaleYUVToRGB32Rect(const uint8* source_yplane, rgb_offset += CalculateRGBOffset(offset.x(), offset.y(), dest_stride); // Draw unaligned edges. - SkRegion edges(dest_rect); - edges.op(inner_rect, SkRegion::kDifference_Op); - for (SkRegion::Iterator i(edges); !i.done(); i.next()) { - SkIRect rect(i.rect()); - rect.offset(- outer_rect.left(), - outer_rect.top()); + webrtc::DesktopRegion edges(dest_rect); + edges.Subtract(inner_rect); + for (webrtc::DesktopRegion::Iterator i(edges); !i.IsAtEnd(); + i.Advance()) { + webrtc::DesktopRect rect = i.rect(); + rect.Translate(-outer_rect.left(), -outer_rect.top()); media::ScaleYUVToRGB32WithRect(source_yplane + y_offset, source_uplane + uv_offset, source_vplane + uv_offset, @@ -192,43 +194,45 @@ int RoundToTwosMultiple(int x) { return x & (~1); } -SkIRect AlignRect(const SkIRect& rect) { +webrtc::DesktopRect AlignRect(const webrtc::DesktopRect& rect) { 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); + return webrtc::DesktopRect::MakeLTRB(x, y, right, bottom); } -SkIRect ScaleRect(const SkIRect& rect, - const SkISize& in_size, - const SkISize& out_size) { +webrtc::DesktopRect ScaleRect(const webrtc::DesktopRect& rect, + const webrtc::DesktopSize& in_size, + const webrtc::DesktopSize& 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() + in_size.width() - 1) / in_size.width(); int bottom = (rect.bottom() * out_size.height() + in_size.height() - 1) / in_size.height(); - return SkIRect::MakeLTRB(left, top, right, bottom); + return webrtc::DesktopRect::MakeLTRB(left, top, right, bottom); } void CopyRGB32Rect(const uint8* source_buffer, int source_stride, - const SkIRect& source_buffer_rect, + const webrtc::DesktopRect& source_buffer_rect, uint8* dest_buffer, int dest_stride, - const SkIRect& dest_buffer_rect, - const SkIRect& dest_rect) { - DCHECK(dest_buffer_rect.contains(dest_rect)); - DCHECK(source_buffer_rect.contains(dest_rect)); + const webrtc::DesktopRect& dest_buffer_rect, + const webrtc::DesktopRect& dest_rect) { + DCHECK(DoesRectContain(dest_buffer_rect, dest_rect)); + DCHECK(DoesRectContain(source_buffer_rect, dest_rect)); // Get the address of the starting point. - source_buffer += CalculateRGBOffset(dest_rect.x() - source_buffer_rect.x(), - dest_rect.y() - source_buffer_rect.y(), - source_stride); - dest_buffer += CalculateRGBOffset(dest_rect.x() - dest_buffer_rect.x(), - dest_rect.y() - dest_buffer_rect.y(), - source_stride); + source_buffer += CalculateRGBOffset( + dest_rect.left() - source_buffer_rect.left(), + dest_rect.top() - source_buffer_rect.top(), + source_stride); + dest_buffer += CalculateRGBOffset( + dest_rect.left() - dest_buffer_rect.left(), + dest_rect.top() - dest_buffer_rect.top(), + source_stride); // Copy pixels in the rectangle line by line. const int bytes_per_line = kBytesPerPixelRGB32 * dest_rect.width(); @@ -328,4 +332,11 @@ std::string GetUsername() { #endif // defined(OS_POSIX) } +bool DoesRectContain(const webrtc::DesktopRect& a, + const webrtc::DesktopRect& b) { + webrtc::DesktopRect intersection(a); + intersection.IntersectWith(b); + return intersection.equals(b); +} + } // namespace remoting diff --git a/remoting/base/util.h b/remoting/base/util.h index 8f70005..5478c7f 100644 --- a/remoting/base/util.h +++ b/remoting/base/util.h @@ -8,7 +8,7 @@ #include <string> #include "media/base/video_frame.h" -#include "third_party/skia/include/core/SkRect.h" +#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" namespace remoting { @@ -36,18 +36,19 @@ int CalculateUVOffset(int x, int y, int stride); // // N.B. The top left corner coordinates of YUV buffer should have even X and Y // coordinates. -void ConvertAndScaleYUVToRGB32Rect(const uint8* source_yplane, - const uint8* source_uplane, - const uint8* source_vplane, - int source_ystride, - int source_uvstride, - const SkISize& source_size, - const SkIRect& source_buffer_rect, - uint8* dest_buffer, - int dest_stride, - const SkISize& dest_size, - const SkIRect& dest_buffer_rect, - const SkIRect& dest_rect); +void ConvertAndScaleYUVToRGB32Rect( + const uint8* source_yplane, + const uint8* source_uplane, + const uint8* source_vplane, + int source_ystride, + int source_uvstride, + const webrtc::DesktopSize& source_size, + const webrtc::DesktopRect& source_buffer_rect, + uint8* dest_buffer, + int dest_stride, + const webrtc::DesktopSize& dest_size, + const webrtc::DesktopRect& dest_buffer_rect, + const webrtc::DesktopRect& dest_rect); // Convert RGB32 to YUV on a specific rectangle. void ConvertRGB32ToYUVWithRect(const uint8* rgb_plane, @@ -65,23 +66,23 @@ void ConvertRGB32ToYUVWithRect(const uint8* rgb_plane, int RoundToTwosMultiple(int x); // Align the sides of the rectangle to multiples of 2 (expanding outwards). -SkIRect AlignRect(const SkIRect& rect); +webrtc::DesktopRect AlignRect(const webrtc::DesktopRect& rect); // 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, - const SkISize& in_size, - const SkISize& out_size); +webrtc::DesktopRect ScaleRect(const webrtc::DesktopRect& rect, + const webrtc::DesktopSize& in_size, + const webrtc::DesktopSize& out_size); // Copy content of a rectangle in a RGB32 image. void CopyRGB32Rect(const uint8* source_buffer, int source_stride, - const SkIRect& source_buffer_rect, + const webrtc::DesktopRect& source_buffer_rect, uint8* dest_buffer, int dest_stride, - const SkIRect& dest_buffer_rect, - const SkIRect& dest_rect); + const webrtc::DesktopRect& dest_buffer_rect, + const webrtc::DesktopRect& dest_rect); // Replaces every occurrence of "\n" in a string by "\r\n". std::string ReplaceLfByCrLf(const std::string& in); @@ -96,6 +97,9 @@ bool StringIsUtf8(const char* data, size_t length); // error or if not implemented. std::string GetUsername(); +bool DoesRectContain(const webrtc::DesktopRect& a, + const webrtc::DesktopRect& b); + } // namespace remoting #endif // REMOTING_BASE_UTIL_H_ diff --git a/remoting/base/util_unittest.cc b/remoting/base/util_unittest.cc index a269c07..1dad9aa 100644 --- a/remoting/base/util_unittest.cc +++ b/remoting/base/util_unittest.cc @@ -6,8 +6,7 @@ #include "remoting/base/util.h" #include "testing/gtest/include/gtest/gtest.h" -#include "third_party/skia/include/core/SkRect.h" -#include "third_party/skia/include/core/SkSize.h" +#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h" static const int kWidth = 32 ; static const int kHeight = 24 ; @@ -45,7 +44,7 @@ class YuvToRgbTester { memset(rgb_buffer_.get(), 0, rgb_buffer_size_); } - void FillRgbBuffer(const SkIRect& rect) { + void FillRgbBuffer(const webrtc::DesktopRect& rect) { uint32* ptr = reinterpret_cast<uint32*>( rgb_buffer_.get() + (rect.top() * kRgbStride) + (rect.left() * kBytesPerPixel)); @@ -57,7 +56,7 @@ class YuvToRgbTester { } // Check the the desination buffer is filled within expected bounds. - void CheckRgbBuffer(const SkIRect& rect) { + void CheckRgbBuffer(const webrtc::DesktopRect& rect) { uint32* ptr = reinterpret_cast<uint32*>(rgb_buffer_.get()); for (int y = 0; y < kHeight; ++y) { if (y < rect.top() || rect.bottom() <= y) { @@ -81,8 +80,10 @@ class YuvToRgbTester { } } - void RunTest(const SkISize dest_size, const SkIRect& rect) { - ASSERT_TRUE(SkIRect::MakeSize(dest_size).contains(rect)); + void RunTest(const webrtc::DesktopSize dest_size, + const webrtc::DesktopRect& rect) { + ASSERT_TRUE( + DoesRectContain(webrtc::DesktopRect::MakeSize(dest_size), rect)); // Reset buffers. ResetYuvBuffer(); @@ -109,12 +110,12 @@ class YuvToRgbTester { vplane_, kYStride, kUvStride, - SkISize::Make(kWidth, kHeight), - SkIRect::MakeWH(kWidth, kHeight), + webrtc::DesktopSize(kWidth, kHeight), + webrtc::DesktopRect::MakeWH(kWidth, kHeight), rgb_buffer_.get(), kRgbStride, dest_size, - SkIRect::MakeSize(dest_size), + webrtc::DesktopRect::MakeSize(dest_size), rect); // Check if it worked out. @@ -123,7 +124,8 @@ class YuvToRgbTester { void TestBasicConversion() { // Whole buffer. - RunTest(SkISize::Make(kWidth, kHeight), SkIRect::MakeWH(kWidth, kHeight)); + RunTest(webrtc::DesktopSize(kWidth, kHeight), + webrtc::DesktopRect::MakeWH(kWidth, kHeight)); } private: @@ -147,18 +149,15 @@ TEST(YuvToRgbTest, BasicConversion) { TEST(YuvToRgbTest, Clipping) { YuvToRgbTester tester; - SkISize dest_size = SkISize::Make(kWidth, kHeight); - SkIRect rect = SkIRect::MakeLTRB(0, 0, kWidth - 1, kHeight - 1); + webrtc::DesktopSize dest_size = webrtc::DesktopSize(kWidth, kHeight); + webrtc::DesktopRect rect = + webrtc::DesktopRect::MakeLTRB(0, 0, kWidth - 1, kHeight - 1); for (int i = 0; i < 16; ++i) { - SkIRect dest_rect = rect; - if ((i & 1) != 0) - dest_rect.fLeft += 1; - if ((i & 2) != 0) - dest_rect.fTop += 1; - if ((i & 4) != 0) - dest_rect.fRight += 1; - if ((i & 8) != 0) - dest_rect.fBottom += 1; + webrtc::DesktopRect dest_rect = webrtc::DesktopRect::MakeLTRB( + rect.left() + ((i & 1) ? 1 : 0), + rect.top() + ((i & 2) ? 1 : 0), + rect.right() + ((i & 4) ? 1 : 0), + rect.bottom() + ((i & 8) ? 1 : 0)); tester.RunTest(dest_size, dest_rect); } @@ -167,18 +166,16 @@ TEST(YuvToRgbTest, Clipping) { TEST(YuvToRgbTest, ClippingAndScaling) { YuvToRgbTester tester; - SkISize dest_size = SkISize::Make(kWidth - 10, kHeight - 10); - SkIRect rect = SkIRect::MakeLTRB(5, 5, kWidth - 11, kHeight - 11); + webrtc::DesktopSize dest_size = + webrtc::DesktopSize(kWidth - 10, kHeight - 10); + webrtc::DesktopRect rect = + webrtc::DesktopRect::MakeLTRB(5, 5, kWidth - 11, kHeight - 11); for (int i = 0; i < 16; ++i) { - SkIRect dest_rect = rect; - if ((i & 1) != 0) - dest_rect.fLeft += 1; - if ((i & 2) != 0) - dest_rect.fTop += 1; - if ((i & 4) != 0) - dest_rect.fRight += 1; - if ((i & 8) != 0) - dest_rect.fBottom += 1; + webrtc::DesktopRect dest_rect = webrtc::DesktopRect::MakeLTRB( + rect.left() + ((i & 1) ? 1 : 0), + rect.top() + ((i & 2) ? 1 : 0), + rect.right() + ((i & 4) ? 1 : 0), + rect.bottom() + ((i & 8) ? 1 : 0)); tester.RunTest(dest_size, dest_rect); } |