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 "base/memory/ref_counted.h" | 5 #include "base/memory/ref_counted.h" |
6 #include "remoting/host/differ_block.h" | 6 #include "remoting/host/differ_block.h" |
7 #include "testing/gmock/include/gmock/gmock.h" | 7 #include "testing/gmock/include/gmock/gmock.h" |
8 | 8 |
9 namespace remoting { | 9 namespace remoting { |
10 | 10 |
11 // Run 900 times to mimic 1280x720. | 11 // Run 900 times to mimic 1280x720. |
12 // TODO(fbarchard): Remove benchmark once performance is non-issue. | 12 // TODO(fbarchard): Remove benchmark once performance is non-issue. |
13 static const int kTimesToRun = 900; | 13 static const int kTimesToRun = 900; |
14 | 14 |
15 static void GenerateData(uint8* data, int size) { | 15 static void GenerateData(uint8* data, int size) { |
16 for (int i = 0; i < size; ++i) { | 16 for (int i = 0; i < size; ++i) { |
17 data[i] = i; | 17 data[i] = i; |
18 } | 18 } |
19 } | 19 } |
20 | 20 |
21 class EncodeDoneHandler | 21 class EncodeDoneHandler |
22 : public base::RefCountedThreadSafe<EncodeDoneHandler> { | 22 : public base::RefCountedThreadSafe<EncodeDoneHandler> { |
23 public: | 23 public: |
24 MOCK_METHOD0(EncodeDone, void()); | 24 MOCK_METHOD0(EncodeDone, void()); |
25 }; | 25 }; |
26 | 26 |
27 // Memory buffer large enough for 2 blocks aligned to 16 bytes. | 27 // Memory buffer large enough for 2 blocks aligned to 16 bytes. |
28 static const int kSizeOfBlock = kBlockHeight * kBlockWidth * kBytesPerPixel; | 28 static const int kSizeOfBlock = kBlockSize * kBlockSize * kBytesPerPixel; |
29 uint8 block_buffer[kSizeOfBlock * 2 + 16]; | 29 uint8 block_buffer[kSizeOfBlock * 2 + 16]; |
30 | 30 |
31 void PrepareBuffers(uint8* &block1, uint8* &block2) { | 31 void PrepareBuffers(uint8* &block1, uint8* &block2) { |
32 block1 = reinterpret_cast<uint8*> | 32 block1 = reinterpret_cast<uint8*> |
33 ((reinterpret_cast<uintptr_t>(&block_buffer[0]) + 15) & ~15); | 33 ((reinterpret_cast<uintptr_t>(&block_buffer[0]) + 15) & ~15); |
34 GenerateData(block1, kSizeOfBlock); | 34 GenerateData(block1, kSizeOfBlock); |
35 block2 = block1 + kSizeOfBlock; | 35 block2 = block1 + kSizeOfBlock; |
36 memcpy(block2, block1, kSizeOfBlock); | 36 memcpy(block2, block1, kSizeOfBlock); |
37 } | 37 } |
38 | 38 |
39 TEST(BlockDifferenceTestSame, BlockDifference) { | 39 TEST(BlockDifferenceTestSame, BlockDifference) { |
40 uint8* block1; | 40 uint8* block1; |
41 uint8* block2; | 41 uint8* block2; |
42 PrepareBuffers(block1, block2); | 42 PrepareBuffers(block1, block2); |
43 | 43 |
44 // These blocks should match. | 44 // These blocks should match. |
45 for (int i = 0; i < kTimesToRun; ++i) { | 45 for (int i = 0; i < kTimesToRun; ++i) { |
46 int result = BlockDifference(block1, block2, kBlockWidth * kBytesPerPixel); | 46 int result = BlockDifference(block1, block2, kBlockSize * kBytesPerPixel); |
47 EXPECT_EQ(0, result); | 47 EXPECT_EQ(0, result); |
48 } | 48 } |
49 } | 49 } |
50 | 50 |
51 TEST(BlockDifferenceTestLast, BlockDifference) { | 51 TEST(BlockDifferenceTestLast, BlockDifference) { |
52 uint8* block1; | 52 uint8* block1; |
53 uint8* block2; | 53 uint8* block2; |
54 PrepareBuffers(block1, block2); | 54 PrepareBuffers(block1, block2); |
55 block2[kSizeOfBlock-2] += 1; | 55 block2[kSizeOfBlock-2] += 1; |
56 | 56 |
57 for (int i = 0; i < kTimesToRun; ++i) { | 57 for (int i = 0; i < kTimesToRun; ++i) { |
58 int result = BlockDifference(block1, block2, kBlockWidth * kBytesPerPixel); | 58 int result = BlockDifference(block1, block2, kBlockSize * kBytesPerPixel); |
59 EXPECT_EQ(1, result); | 59 EXPECT_EQ(1, result); |
60 } | 60 } |
61 } | 61 } |
62 | 62 |
63 TEST(BlockDifferenceTestMid, BlockDifference) { | 63 TEST(BlockDifferenceTestMid, BlockDifference) { |
64 uint8* block1; | 64 uint8* block1; |
65 uint8* block2; | 65 uint8* block2; |
66 PrepareBuffers(block1, block2); | 66 PrepareBuffers(block1, block2); |
67 block2[kSizeOfBlock/2+1] += 1; | 67 block2[kSizeOfBlock/2+1] += 1; |
68 | 68 |
69 for (int i = 0; i < kTimesToRun; ++i) { | 69 for (int i = 0; i < kTimesToRun; ++i) { |
70 int result = BlockDifference(block1, block2, kBlockWidth * kBytesPerPixel); | 70 int result = BlockDifference(block1, block2, kBlockSize * kBytesPerPixel); |
71 EXPECT_EQ(1, result); | 71 EXPECT_EQ(1, result); |
72 } | 72 } |
73 } | 73 } |
74 | 74 |
75 TEST(BlockDifferenceTestFirst, BlockDifference) { | 75 TEST(BlockDifferenceTestFirst, BlockDifference) { |
76 uint8* block1; | 76 uint8* block1; |
77 uint8* block2; | 77 uint8* block2; |
78 PrepareBuffers(block1, block2); | 78 PrepareBuffers(block1, block2); |
79 block2[0] += 1; | 79 block2[0] += 1; |
80 | 80 |
81 for (int i = 0; i < kTimesToRun; ++i) { | 81 for (int i = 0; i < kTimesToRun; ++i) { |
82 int result = BlockDifference(block1, block2, kBlockWidth * kBytesPerPixel); | 82 int result = BlockDifference(block1, block2, kBlockSize * kBytesPerPixel); |
83 EXPECT_EQ(1, result); | 83 EXPECT_EQ(1, result); |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 } // namespace remoting | 87 } // namespace remoting |
OLD | NEW |