| 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/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "remoting/base/capture_data.h" | 10 #include "remoting/base/capture_data.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 | 42 |
| 43 EncoderVp8 encoder; | 43 EncoderVp8 encoder; |
| 44 EncoderCallback callback; | 44 EncoderCallback callback; |
| 45 | 45 |
| 46 std::vector<uint8> buffer(width * height * kBytesPerPixel); | 46 std::vector<uint8> buffer(width * height * kBytesPerPixel); |
| 47 DataPlanes planes; | 47 DataPlanes planes; |
| 48 planes.data[0] = &buffer.front(); | 48 planes.data[0] = &buffer.front(); |
| 49 planes.strides[0] = width; | 49 planes.strides[0] = width; |
| 50 | 50 |
| 51 scoped_refptr<CaptureData> capture_data(new CaptureData( | 51 scoped_refptr<CaptureData> capture_data(new CaptureData( |
| 52 planes, gfx::Size(width, height), media::VideoFrame::RGB32)); | 52 planes, SkISize::Make(width, height), media::VideoFrame::RGB32)); |
| 53 encoder.Encode(capture_data, false, | 53 encoder.Encode(capture_data, false, |
| 54 NewCallback(&callback, &EncoderCallback::DataAvailable)); | 54 NewCallback(&callback, &EncoderCallback::DataAvailable)); |
| 55 | 55 |
| 56 height /= 2; | 56 height /= 2; |
| 57 capture_data = new CaptureData(planes, gfx::Size(width, height), | 57 capture_data = new CaptureData(planes, SkISize::Make(width, height), |
| 58 media::VideoFrame::RGB32); | 58 media::VideoFrame::RGB32); |
| 59 encoder.Encode(capture_data, false, | 59 encoder.Encode(capture_data, false, |
| 60 NewCallback(&callback, &EncoderCallback::DataAvailable)); | 60 NewCallback(&callback, &EncoderCallback::DataAvailable)); |
| 61 } | 61 } |
| 62 | 62 |
| 63 TEST(EncoderVp8Test, AlignAndClipRect) { | 63 TEST(EncoderVp8Test, AlignAndClipRect) { |
| 64 // Simple test case (no clipping). | 64 // Simple test case (no clipping). |
| 65 gfx::Rect r1(100, 200, 300, 400); | 65 SkIRect r1(SkIRect::MakeXYWH(100, 200, 300, 400)); |
| 66 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, kIntMax, kIntMax), r1); | 66 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, kIntMax, kIntMax), r1); |
| 67 | 67 |
| 68 // Should expand outward to r1. | 68 // Should expand outward to r1. |
| 69 gfx::Rect r2(101, 201, 298, 398); | 69 SkIRect r2(SkIRect::MakeXYWH(101, 201, 298, 398)); |
| 70 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r2, kIntMax, kIntMax), r1); | 70 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r2, kIntMax, kIntMax), r1); |
| 71 | 71 |
| 72 // Test clipping to screen size. | 72 // Test clipping to screen size. |
| 73 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, 110, 220), | 73 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, 110, 220), |
| 74 gfx::Rect(100, 200, 10, 20)); | 74 SkIRect::MakeXYWH(100, 200, 10, 20)); |
| 75 | 75 |
| 76 // Rectangle completely off-screen. | 76 // Rectangle completely off-screen. |
| 77 EXPECT_TRUE(EncoderVp8::AlignAndClipRect(r1, 50, 50).IsEmpty()); | 77 EXPECT_TRUE(EncoderVp8::AlignAndClipRect(r1, 50, 50).isEmpty()); |
| 78 | 78 |
| 79 // Clipping to odd-sized screen. An unlikely case, and we might not deal | 79 // 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 | 80 // with it cleanly in the encoder (we possibly lose 1px at right & bottom |
| 81 // of screen). | 81 // of screen). |
| 82 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, 199, 299), | 82 EXPECT_EQ(EncoderVp8::AlignAndClipRect(r1, 199, 299), |
| 83 gfx::Rect(100, 200, 98, 98)); | 83 SkIRect::MakeXYWH(100, 200, 98, 98)); |
| 84 } | 84 } |
| 85 | 85 |
| 86 } // namespace remoting | 86 } // namespace remoting |
| OLD | NEW |