| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <limits> | 5 #include <limits> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/bind.h" |
| 8 #include "base/callback.h" | 9 #include "base/callback.h" |
| 9 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 10 #include "remoting/base/capture_data.h" | 11 #include "remoting/base/capture_data.h" |
| 11 #include "remoting/base/codec_test.h" | 12 #include "remoting/base/codec_test.h" |
| 12 #include "remoting/base/encoder_vp8.h" | 13 #include "remoting/base/encoder_vp8.h" |
| 13 #include "remoting/proto/video.pb.h" | 14 #include "remoting/proto/video.pb.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 | 18 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 44 EncoderCallback callback; | 45 EncoderCallback callback; |
| 45 | 46 |
| 46 std::vector<uint8> buffer(width * height * kBytesPerPixel); | 47 std::vector<uint8> buffer(width * height * kBytesPerPixel); |
| 47 DataPlanes planes; | 48 DataPlanes planes; |
| 48 planes.data[0] = &buffer.front(); | 49 planes.data[0] = &buffer.front(); |
| 49 planes.strides[0] = width; | 50 planes.strides[0] = width; |
| 50 | 51 |
| 51 scoped_refptr<CaptureData> capture_data(new CaptureData( | 52 scoped_refptr<CaptureData> capture_data(new CaptureData( |
| 52 planes, SkISize::Make(width, height), media::VideoFrame::RGB32)); | 53 planes, SkISize::Make(width, height), media::VideoFrame::RGB32)); |
| 53 encoder.Encode(capture_data, false, | 54 encoder.Encode(capture_data, false, |
| 54 NewCallback(&callback, &EncoderCallback::DataAvailable)); | 55 base::Bind(&EncoderCallback::DataAvailable, |
| 56 base::Unretained(&callback))); |
| 55 | 57 |
| 56 height /= 2; | 58 height /= 2; |
| 57 capture_data = new CaptureData(planes, SkISize::Make(width, height), | 59 capture_data = new CaptureData(planes, SkISize::Make(width, height), |
| 58 media::VideoFrame::RGB32); | 60 media::VideoFrame::RGB32); |
| 59 encoder.Encode(capture_data, false, | 61 encoder.Encode(capture_data, false, |
| 60 NewCallback(&callback, &EncoderCallback::DataAvailable)); | 62 base::Bind(&EncoderCallback::DataAvailable, |
| 63 base::Unretained(&callback))); |
| 61 } | 64 } |
| 62 | 65 |
| 63 TEST(EncoderVp8Test, AlignAndClipRect) { | 66 TEST(EncoderVp8Test, AlignAndClipRect) { |
| 64 // Simple test case (no clipping). | 67 // Simple test case (no clipping). |
| 65 SkIRect r1(SkIRect::MakeXYWH(100, 200, 300, 400)); | 68 SkIRect r1(SkIRect::MakeXYWH(100, 200, 300, 400)); |
| 66 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, kIntMax, kIntMax), r1); | 69 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, kIntMax, kIntMax), r1); |
| 67 | 70 |
| 68 // Should expand outward to r1. | 71 // Should expand outward to r1. |
| 69 SkIRect r2(SkIRect::MakeXYWH(101, 201, 298, 398)); | 72 SkIRect r2(SkIRect::MakeXYWH(101, 201, 298, 398)); |
| 70 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r2, kIntMax, kIntMax), r1); | 73 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r2, kIntMax, kIntMax), r1); |
| 71 | 74 |
| 72 // Test clipping to screen size. | 75 // Test clipping to screen size. |
| 73 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, 110, 220), | 76 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, 110, 220), |
| 74 SkIRect::MakeXYWH(100, 200, 10, 20)); | 77 SkIRect::MakeXYWH(100, 200, 10, 20)); |
| 75 | 78 |
| 76 // Rectangle completely off-screen. | 79 // Rectangle completely off-screen. |
| 77 EXPECT_TRUE(EncoderVp8::AlignAndClipRect(r1, 50, 50).isEmpty()); | 80 EXPECT_TRUE(EncoderVp8::AlignAndClipRect(r1, 50, 50).isEmpty()); |
| 78 | 81 |
| 79 // Clipping to odd-sized screen. An unlikely case, and we might not deal | 82 // Clipping to odd-sized screen. An unlikely case, and we might not deal |
| 80 // with it cleanly in the encoder (we possibly lose 1px at right & bottom | 83 // with it cleanly in the encoder (we possibly lose 1px at right & bottom |
| 81 // of screen). | 84 // of screen). |
| 82 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, 199, 299), | 85 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, 199, 299), |
| 83 SkIRect::MakeXYWH(100, 200, 98, 98)); | 86 SkIRect::MakeXYWH(100, 200, 98, 98)); |
| 84 } | 87 } |
| 85 | 88 |
| 86 } // namespace remoting | 89 } // namespace remoting |
| OLD | NEW |