| 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/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "remoting/host/differ.h" | 6 #include "remoting/host/differ.h" |
| 7 #include "remoting/host/differ_block.h" | 7 #include "remoting/host/differ_block.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 | 9 |
| 10 namespace remoting { | 10 namespace remoting { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 memset(prev_.get(), 0, buffer_size_); | 37 memset(prev_.get(), 0, buffer_size_); |
| 38 | 38 |
| 39 curr_.reset(new uint8[buffer_size_]); | 39 curr_.reset(new uint8[buffer_size_]); |
| 40 memset(curr_.get(), 0, buffer_size_); | 40 memset(curr_.get(), 0, buffer_size_); |
| 41 } | 41 } |
| 42 | 42 |
| 43 void ClearBuffer(uint8* buffer) { | 43 void ClearBuffer(uint8* buffer) { |
| 44 memset(buffer, 0, buffer_size_); | 44 memset(buffer, 0, buffer_size_); |
| 45 } | 45 } |
| 46 | 46 |
| 47 // Here in DifferTest so that tests can access private methods of Differ. | |
| 48 void MarkDirtyBlocks(const void* prev_buffer, const void* curr_buffer) { | |
| 49 differ_->MarkDirtyBlocks(prev_buffer, curr_buffer); | |
| 50 } | |
| 51 | |
| 52 void MergeBlocks(SkRegion* dirty) { | |
| 53 differ_->MergeBlocks(dirty); | |
| 54 } | |
| 55 | |
| 56 // Convenience method to count rectangles in a region. | |
| 57 int RegionRectCount(const SkRegion& region) { | |
| 58 int count = 0; | |
| 59 for(SkRegion::Iterator iter(region); !iter.done(); iter.next()) { | |
| 60 ++count; | |
| 61 } | |
| 62 return count; | |
| 63 } | |
| 64 | |
| 65 // Convenience wrapper for Differ's DiffBlock that calculates the appropriate | 47 // Convenience wrapper for Differ's DiffBlock that calculates the appropriate |
| 66 // offset to the start of the desired block. | 48 // offset to the start of the desired block. |
| 67 DiffInfo DiffBlock(int block_x, int block_y) { | 49 DiffInfo DiffBlock(int block_x, int block_y) { |
| 68 // Offset from upper-left of buffer to upper-left of requested block. | 50 // Offset from upper-left of buffer to upper-left of requested block. |
| 69 int block_offset = ((block_y * stride_) + (block_x * bytes_per_pixel_)) | 51 int block_offset = ((block_y * stride_) + (block_x * bytes_per_pixel_)) |
| 70 * kBlockSize; | 52 * kBlockSize; |
| 71 return BlockDifference(prev_.get() + block_offset, | 53 return BlockDifference(prev_.get() + block_offset, |
| 72 curr_.get() + block_offset, | 54 curr_.get() + block_offset, |
| 73 stride_); | 55 stride_); |
| 74 } | 56 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 | 116 |
| 135 // Mark the range of blocks specified. | 117 // Mark the range of blocks specified. |
| 136 void MarkBlocks(int x_origin, int y_origin, int width, int height) { | 118 void MarkBlocks(int x_origin, int y_origin, int width, int height) { |
| 137 for (int y = 0; y < height; y++) { | 119 for (int y = 0; y < height; y++) { |
| 138 for (int x = 0; x < width; x++) { | 120 for (int x = 0; x < width; x++) { |
| 139 SetDiffInfo(x_origin + x, y_origin + y, 1); | 121 SetDiffInfo(x_origin + x, y_origin + y, 1); |
| 140 } | 122 } |
| 141 } | 123 } |
| 142 } | 124 } |
| 143 | 125 |
| 144 // Verify that |region| contains a rectangle defined by |x|, |y|, |width| and | 126 // Verify that the given dirty rect matches the expected |x|, |y|, |width| |
| 145 // |height|. | 127 // and |height|. |
| 146 // |x|, |y|, |width| and |height| are specified in block (not pixel) units. | 128 // |x|, |y|, |width| and |height| are specified in block (not pixel) units. |
| 147 bool CheckDirtyRegionContainsRect(const SkRegion& region, int x, int y, | 129 void CheckDirtyRect(const InvalidRects& rects, int x, int y, |
| 148 int width, int height) { | 130 int width, int height) { |
| 149 SkIRect r = SkIRect::MakeXYWH(x * kBlockSize, y * kBlockSize, | 131 gfx::Rect r(x * kBlockSize, y * kBlockSize, |
| 150 width * kBlockSize, height * kBlockSize); | 132 width * kBlockSize, height * kBlockSize); |
| 151 bool found = false; | 133 EXPECT_TRUE(rects.find(r) != rects.end()); |
| 152 for (SkRegion::Iterator i(region); !found && !i.done(); i.next()) { | |
| 153 found = (i.rect() == r); | |
| 154 } | |
| 155 return found; | |
| 156 } | 134 } |
| 157 | 135 |
| 158 // Mark the range of blocks specified and then verify that they are | 136 // Mark the range of blocks specified and then verify that they are |
| 159 // merged correctly. | 137 // merged correctly. |
| 160 // Only one rectangular region of blocks can be checked with this routine. | 138 // Only one rectangular region of blocks can be checked with this routine. |
| 161 bool MarkBlocksAndCheckMerge(int x_origin, int y_origin, | 139 void MarkBlocksAndCheckMerge(int x_origin, int y_origin, |
| 162 int width, int height) { | 140 int width, int height) { |
| 163 ClearDiffInfo(); | 141 ClearDiffInfo(); |
| 164 MarkBlocks(x_origin, y_origin, width, height); | 142 MarkBlocks(x_origin, y_origin, width, height); |
| 165 | 143 |
| 166 SkRegion dirty; | 144 scoped_ptr<InvalidRects> dirty(new InvalidRects()); |
| 167 MergeBlocks(&dirty); | 145 differ_->MergeBlocks(dirty.get()); |
| 168 | 146 |
| 169 bool is_good = dirty.isRect(); | 147 ASSERT_EQ(1UL, dirty->size()); |
| 170 if (is_good) { | 148 CheckDirtyRect(*dirty.get(), x_origin, y_origin, width, height); |
| 171 is_good = CheckDirtyRegionContainsRect(dirty, x_origin, y_origin, | |
| 172 width, height); | |
| 173 } | |
| 174 return is_good; | |
| 175 } | 149 } |
| 176 | 150 |
| 177 // The differ class we're testing. | 151 // The differ class we're testing. |
| 178 scoped_ptr<Differ> differ_; | 152 scoped_ptr<Differ> differ_; |
| 179 | 153 |
| 180 // Screen/buffer info. | 154 // Screen/buffer info. |
| 181 int width_; | 155 int width_; |
| 182 int height_; | 156 int height_; |
| 183 int bytes_per_pixel_; | 157 int bytes_per_pixel_; |
| 184 int stride_; | 158 int stride_; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 215 InitDiffer(kScreenWidth, kScreenHeight); | 189 InitDiffer(kScreenWidth, kScreenHeight); |
| 216 ClearDiffInfo(); | 190 ClearDiffInfo(); |
| 217 | 191 |
| 218 // Update a pixel in each block. | 192 // Update a pixel in each block. |
| 219 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { | 193 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { |
| 220 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { | 194 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { |
| 221 WriteBlockPixel(curr_.get(), x, y, 10, 10, 0xff00ff); | 195 WriteBlockPixel(curr_.get(), x, y, 10, 10, 0xff00ff); |
| 222 } | 196 } |
| 223 } | 197 } |
| 224 | 198 |
| 225 MarkDirtyBlocks(prev_.get(), curr_.get()); | 199 differ_->MarkDirtyBlocks(prev_.get(), curr_.get()); |
| 226 | 200 |
| 227 // Make sure each block is marked as dirty. | 201 // Make sure each block is marked as dirty. |
| 228 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { | 202 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { |
| 229 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { | 203 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { |
| 230 EXPECT_EQ(1, GetDiffInfo(x, y)) | 204 EXPECT_EQ(1, GetDiffInfo(x, y)) |
| 231 << "when x = " << x << ", and y = " << y; | 205 << "when x = " << x << ", and y = " << y; |
| 232 } | 206 } |
| 233 } | 207 } |
| 234 } | 208 } |
| 235 | 209 |
| 236 TEST_F(DifferTest, MarkDirtyBlocks_Sampling) { | 210 TEST_F(DifferTest, MarkDirtyBlocks_Sampling) { |
| 237 InitDiffer(kScreenWidth, kScreenHeight); | 211 InitDiffer(kScreenWidth, kScreenHeight); |
| 238 ClearDiffInfo(); | 212 ClearDiffInfo(); |
| 239 | 213 |
| 240 // Update some pixels in image. | 214 // Update some pixels in image. |
| 241 WriteBlockPixel(curr_.get(), 1, 0, 10, 10, 0xff00ff); | 215 WriteBlockPixel(curr_.get(), 1, 0, 10, 10, 0xff00ff); |
| 242 WriteBlockPixel(curr_.get(), 2, 1, 10, 10, 0xff00ff); | 216 WriteBlockPixel(curr_.get(), 2, 1, 10, 10, 0xff00ff); |
| 243 WriteBlockPixel(curr_.get(), 0, 2, 10, 10, 0xff00ff); | 217 WriteBlockPixel(curr_.get(), 0, 2, 10, 10, 0xff00ff); |
| 244 | 218 |
| 245 MarkDirtyBlocks(prev_.get(), curr_.get()); | 219 differ_->MarkDirtyBlocks(prev_.get(), curr_.get()); |
| 246 | 220 |
| 247 // Make sure corresponding blocks are updated. | 221 // Make sure corresponding blocks are updated. |
| 248 EXPECT_EQ(0, GetDiffInfo(0, 0)); | 222 EXPECT_EQ(0, GetDiffInfo(0, 0)); |
| 249 EXPECT_EQ(0, GetDiffInfo(0, 1)); | 223 EXPECT_EQ(0, GetDiffInfo(0, 1)); |
| 250 EXPECT_EQ(1, GetDiffInfo(0, 2)); | 224 EXPECT_EQ(1, GetDiffInfo(0, 2)); |
| 251 EXPECT_EQ(1, GetDiffInfo(1, 0)); | 225 EXPECT_EQ(1, GetDiffInfo(1, 0)); |
| 252 EXPECT_EQ(0, GetDiffInfo(1, 1)); | 226 EXPECT_EQ(0, GetDiffInfo(1, 1)); |
| 253 EXPECT_EQ(0, GetDiffInfo(1, 2)); | 227 EXPECT_EQ(0, GetDiffInfo(1, 2)); |
| 254 EXPECT_EQ(0, GetDiffInfo(2, 0)); | 228 EXPECT_EQ(0, GetDiffInfo(2, 0)); |
| 255 EXPECT_EQ(1, GetDiffInfo(2, 1)); | 229 EXPECT_EQ(1, GetDiffInfo(2, 1)); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 InitDiffer(kPartialScreenWidth, kPartialScreenHeight); | 277 InitDiffer(kPartialScreenWidth, kPartialScreenHeight); |
| 304 ClearDiffInfo(); | 278 ClearDiffInfo(); |
| 305 | 279 |
| 306 // Update the first pixel in each block. | 280 // Update the first pixel in each block. |
| 307 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { | 281 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { |
| 308 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { | 282 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { |
| 309 WriteBlockPixel(curr_.get(), x, y, 0, 0, 0xff00ff); | 283 WriteBlockPixel(curr_.get(), x, y, 0, 0, 0xff00ff); |
| 310 } | 284 } |
| 311 } | 285 } |
| 312 | 286 |
| 313 MarkDirtyBlocks(prev_.get(), curr_.get()); | 287 differ_->MarkDirtyBlocks(prev_.get(), curr_.get()); |
| 314 | 288 |
| 315 // Make sure each block is marked as dirty. | 289 // Make sure each block is marked as dirty. |
| 316 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { | 290 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { |
| 317 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { | 291 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { |
| 318 EXPECT_EQ(1, GetDiffInfo(x, y)) | 292 EXPECT_EQ(1, GetDiffInfo(x, y)) |
| 319 << "when x = " << x << ", and y = " << y; | 293 << "when x = " << x << ", and y = " << y; |
| 320 } | 294 } |
| 321 } | 295 } |
| 322 } | 296 } |
| 323 | 297 |
| 324 TEST_F(DifferTest, Partial_BorderPixel) { | 298 TEST_F(DifferTest, Partial_BorderPixel) { |
| 325 InitDiffer(kPartialScreenWidth, kPartialScreenHeight); | 299 InitDiffer(kPartialScreenWidth, kPartialScreenHeight); |
| 326 ClearDiffInfo(); | 300 ClearDiffInfo(); |
| 327 | 301 |
| 328 // Update the right/bottom border pixels. | 302 // Update the right/bottom border pixels. |
| 329 for (int y = 0; y < height_; y++) { | 303 for (int y = 0; y < height_; y++) { |
| 330 WritePixel(curr_.get(), width_ - 1, y, 0xff00ff); | 304 WritePixel(curr_.get(), width_ - 1, y, 0xff00ff); |
| 331 } | 305 } |
| 332 for (int x = 0; x < width_; x++) { | 306 for (int x = 0; x < width_; x++) { |
| 333 WritePixel(curr_.get(), x, height_ - 1, 0xff00ff); | 307 WritePixel(curr_.get(), x, height_ - 1, 0xff00ff); |
| 334 } | 308 } |
| 335 | 309 |
| 336 MarkDirtyBlocks(prev_.get(), curr_.get()); | 310 differ_->MarkDirtyBlocks(prev_.get(), curr_.get()); |
| 337 | 311 |
| 338 // Make sure last (partial) block in each row/column is marked as dirty. | 312 // Make sure last (partial) block in each row/column is marked as dirty. |
| 339 int x_last = GetDiffInfoWidth() - 2; | 313 int x_last = GetDiffInfoWidth() - 2; |
| 340 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { | 314 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { |
| 341 EXPECT_EQ(1, GetDiffInfo(x_last, y)) | 315 EXPECT_EQ(1, GetDiffInfo(x_last, y)) |
| 342 << "when x = " << x_last << ", and y = " << y; | 316 << "when x = " << x_last << ", and y = " << y; |
| 343 } | 317 } |
| 344 int y_last = GetDiffInfoHeight() - 2; | 318 int y_last = GetDiffInfoHeight() - 2; |
| 345 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { | 319 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { |
| 346 EXPECT_EQ(1, GetDiffInfo(x, y_last)) | 320 EXPECT_EQ(1, GetDiffInfo(x, y_last)) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 362 // | | | | _ | | 336 // | | | | _ | |
| 363 // +---+---+---+---+ | 337 // +---+---+---+---+ |
| 364 // | | | | _ | | 338 // | | | | _ | |
| 365 // +---+---+---+---+ | 339 // +---+---+---+---+ |
| 366 // | | | | _ | | 340 // | | | | _ | |
| 367 // +---+---+---+---+ | 341 // +---+---+---+---+ |
| 368 // | _ | _ | _ | _ | | 342 // | _ | _ | _ | _ | |
| 369 // +---+---+---+---+ | 343 // +---+---+---+---+ |
| 370 ClearDiffInfo(); | 344 ClearDiffInfo(); |
| 371 | 345 |
| 372 SkRegion dirty; | 346 scoped_ptr<InvalidRects> dirty(new InvalidRects()); |
| 373 MergeBlocks(&dirty); | 347 differ_->MergeBlocks(dirty.get()); |
| 374 | 348 |
| 375 EXPECT_TRUE(dirty.isEmpty()); | 349 EXPECT_EQ(0UL, dirty->size()); |
| 376 } | 350 } |
| 377 | 351 |
| 378 TEST_F(DifferTest, MergeBlocks_SingleBlock) { | 352 TEST_F(DifferTest, MergeBlocks_SingleBlock) { |
| 379 InitDiffer(kScreenWidth, kScreenHeight); | 353 InitDiffer(kScreenWidth, kScreenHeight); |
| 380 // Mark a single block and make sure that there is a single merged | 354 // Mark a single block and make sure that there is a single merged |
| 381 // rect with the correct bounds. | 355 // rect with the correct bounds. |
| 382 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { | 356 for (int y = 0; y < GetDiffInfoHeight() - 1; y++) { |
| 383 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { | 357 for (int x = 0; x < GetDiffInfoWidth() - 1; x++) { |
| 384 ASSERT_TRUE(MarkBlocksAndCheckMerge(x, y, 1, 1)) << "x: " << x | 358 MarkBlocksAndCheckMerge(x, y, 1, 1); |
| 385 << "y: " << y; | |
| 386 } | 359 } |
| 387 } | 360 } |
| 388 } | 361 } |
| 389 | 362 |
| 390 TEST_F(DifferTest, MergeBlocks_BlockRow) { | 363 TEST_F(DifferTest, MergeBlocks_BlockRow) { |
| 391 InitDiffer(kScreenWidth, kScreenHeight); | 364 InitDiffer(kScreenWidth, kScreenHeight); |
| 392 | 365 |
| 393 // +---+---+---+---+ | 366 // +---+---+---+---+ |
| 394 // | X | X | | _ | | 367 // | X | X | | _ | |
| 395 // +---+---+---+---+ | 368 // +---+---+---+---+ |
| 396 // | | | | _ | | 369 // | | | | _ | |
| 397 // +---+---+---+---+ | 370 // +---+---+---+---+ |
| 398 // | | | | _ | | 371 // | | | | _ | |
| 399 // +---+---+---+---+ | 372 // +---+---+---+---+ |
| 400 // | _ | _ | _ | _ | | 373 // | _ | _ | _ | _ | |
| 401 // +---+---+---+---+ | 374 // +---+---+---+---+ |
| 402 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 0, 2, 1)); | 375 MarkBlocksAndCheckMerge(0, 0, 2, 1); |
| 403 | 376 |
| 404 // +---+---+---+---+ | 377 // +---+---+---+---+ |
| 405 // | | | | _ | | 378 // | | | | _ | |
| 406 // +---+---+---+---+ | 379 // +---+---+---+---+ |
| 407 // | X | X | X | _ | | 380 // | X | X | X | _ | |
| 408 // +---+---+---+---+ | 381 // +---+---+---+---+ |
| 409 // | | | | _ | | 382 // | | | | _ | |
| 410 // +---+---+---+---+ | 383 // +---+---+---+---+ |
| 411 // | _ | _ | _ | _ | | 384 // | _ | _ | _ | _ | |
| 412 // +---+---+---+---+ | 385 // +---+---+---+---+ |
| 413 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 1, 3, 1)); | 386 MarkBlocksAndCheckMerge(0, 1, 3, 1); |
| 414 | 387 |
| 415 // +---+---+---+---+ | 388 // +---+---+---+---+ |
| 416 // | | | | _ | | 389 // | | | | _ | |
| 417 // +---+---+---+---+ | 390 // +---+---+---+---+ |
| 418 // | | | | _ | | 391 // | | | | _ | |
| 419 // +---+---+---+---+ | 392 // +---+---+---+---+ |
| 420 // | | X | X | _ | | 393 // | | X | X | _ | |
| 421 // +---+---+---+---+ | 394 // +---+---+---+---+ |
| 422 // | _ | _ | _ | _ | | 395 // | _ | _ | _ | _ | |
| 423 // +---+---+---+---+ | 396 // +---+---+---+---+ |
| 424 ASSERT_TRUE(MarkBlocksAndCheckMerge(1, 2, 2, 1)); | 397 MarkBlocksAndCheckMerge(1, 2, 2, 1); |
| 425 } | 398 } |
| 426 | 399 |
| 427 TEST_F(DifferTest, MergeBlocks_BlockColumn) { | 400 TEST_F(DifferTest, MergeBlocks_BlockColumn) { |
| 428 InitDiffer(kScreenWidth, kScreenHeight); | 401 InitDiffer(kScreenWidth, kScreenHeight); |
| 429 | 402 |
| 430 // +---+---+---+---+ | 403 // +---+---+---+---+ |
| 431 // | X | | | _ | | 404 // | X | | | _ | |
| 432 // +---+---+---+---+ | 405 // +---+---+---+---+ |
| 433 // | X | | | _ | | 406 // | X | | | _ | |
| 434 // +---+---+---+---+ | 407 // +---+---+---+---+ |
| 435 // | | | | _ | | 408 // | | | | _ | |
| 436 // +---+---+---+---+ | 409 // +---+---+---+---+ |
| 437 // | _ | _ | _ | _ | | 410 // | _ | _ | _ | _ | |
| 438 // +---+---+---+---+ | 411 // +---+---+---+---+ |
| 439 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 0, 1, 2)); | 412 MarkBlocksAndCheckMerge(0, 0, 1, 2); |
| 440 | 413 |
| 441 // +---+---+---+---+ | 414 // +---+---+---+---+ |
| 442 // | | | | _ | | 415 // | | | | _ | |
| 443 // +---+---+---+---+ | 416 // +---+---+---+---+ |
| 444 // | | X | | _ | | 417 // | | X | | _ | |
| 445 // +---+---+---+---+ | 418 // +---+---+---+---+ |
| 446 // | | X | | _ | | 419 // | | X | | _ | |
| 447 // +---+---+---+---+ | 420 // +---+---+---+---+ |
| 448 // | _ | _ | _ | _ | | 421 // | _ | _ | _ | _ | |
| 449 // +---+---+---+---+ | 422 // +---+---+---+---+ |
| 450 ASSERT_TRUE(MarkBlocksAndCheckMerge(1, 1, 1, 2)); | 423 MarkBlocksAndCheckMerge(1, 1, 1, 2); |
| 451 | 424 |
| 452 // +---+---+---+---+ | 425 // +---+---+---+---+ |
| 453 // | | | X | _ | | 426 // | | | X | _ | |
| 454 // +---+---+---+---+ | 427 // +---+---+---+---+ |
| 455 // | | | X | _ | | 428 // | | | X | _ | |
| 456 // +---+---+---+---+ | 429 // +---+---+---+---+ |
| 457 // | | | X | _ | | 430 // | | | X | _ | |
| 458 // +---+---+---+---+ | 431 // +---+---+---+---+ |
| 459 // | _ | _ | _ | _ | | 432 // | _ | _ | _ | _ | |
| 460 // +---+---+---+---+ | 433 // +---+---+---+---+ |
| 461 ASSERT_TRUE(MarkBlocksAndCheckMerge(2, 0, 1, 3)); | 434 MarkBlocksAndCheckMerge(2, 0, 1, 3); |
| 462 } | 435 } |
| 463 | 436 |
| 464 TEST_F(DifferTest, MergeBlocks_BlockRect) { | 437 TEST_F(DifferTest, MergeBlocks_BlockRect) { |
| 465 InitDiffer(kScreenWidth, kScreenHeight); | 438 InitDiffer(kScreenWidth, kScreenHeight); |
| 466 | 439 |
| 467 // +---+---+---+---+ | 440 // +---+---+---+---+ |
| 468 // | X | X | | _ | | 441 // | X | X | | _ | |
| 469 // +---+---+---+---+ | 442 // +---+---+---+---+ |
| 470 // | X | X | | _ | | 443 // | X | X | | _ | |
| 471 // +---+---+---+---+ | 444 // +---+---+---+---+ |
| 472 // | | | | _ | | 445 // | | | | _ | |
| 473 // +---+---+---+---+ | 446 // +---+---+---+---+ |
| 474 // | _ | _ | _ | _ | | 447 // | _ | _ | _ | _ | |
| 475 // +---+---+---+---+ | 448 // +---+---+---+---+ |
| 476 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 0, 2, 2)); | 449 MarkBlocksAndCheckMerge(0, 0, 2, 2); |
| 477 | 450 |
| 478 // +---+---+---+---+ | 451 // +---+---+---+---+ |
| 479 // | | | | _ | | 452 // | | | | _ | |
| 480 // +---+---+---+---+ | 453 // +---+---+---+---+ |
| 481 // | | X | X | _ | | 454 // | | X | X | _ | |
| 482 // +---+---+---+---+ | 455 // +---+---+---+---+ |
| 483 // | | X | X | _ | | 456 // | | X | X | _ | |
| 484 // +---+---+---+---+ | 457 // +---+---+---+---+ |
| 485 // | _ | _ | _ | _ | | 458 // | _ | _ | _ | _ | |
| 486 // +---+---+---+---+ | 459 // +---+---+---+---+ |
| 487 ASSERT_TRUE(MarkBlocksAndCheckMerge(1, 1, 2, 2)); | 460 MarkBlocksAndCheckMerge(1, 1, 2, 2); |
| 488 | 461 |
| 489 // +---+---+---+---+ | 462 // +---+---+---+---+ |
| 490 // | | X | X | _ | | 463 // | | X | X | _ | |
| 491 // +---+---+---+---+ | 464 // +---+---+---+---+ |
| 492 // | | X | X | _ | | 465 // | | X | X | _ | |
| 493 // +---+---+---+---+ | 466 // +---+---+---+---+ |
| 494 // | | X | X | _ | | 467 // | | X | X | _ | |
| 495 // +---+---+---+---+ | 468 // +---+---+---+---+ |
| 496 // | _ | _ | _ | _ | | 469 // | _ | _ | _ | _ | |
| 497 // +---+---+---+---+ | 470 // +---+---+---+---+ |
| 498 ASSERT_TRUE(MarkBlocksAndCheckMerge(1, 0, 2, 3)); | 471 MarkBlocksAndCheckMerge(1, 0, 2, 3); |
| 499 | 472 |
| 500 // +---+---+---+---+ | 473 // +---+---+---+---+ |
| 501 // | | | | _ | | 474 // | | | | _ | |
| 502 // +---+---+---+---+ | 475 // +---+---+---+---+ |
| 503 // | X | X | X | _ | | 476 // | X | X | X | _ | |
| 504 // +---+---+---+---+ | 477 // +---+---+---+---+ |
| 505 // | X | X | X | _ | | 478 // | X | X | X | _ | |
| 506 // +---+---+---+---+ | 479 // +---+---+---+---+ |
| 507 // | _ | _ | _ | _ | | 480 // | _ | _ | _ | _ | |
| 508 // +---+---+---+---+ | 481 // +---+---+---+---+ |
| 509 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 1, 3, 2)); | 482 MarkBlocksAndCheckMerge(0, 1, 3, 2); |
| 510 | 483 |
| 511 // +---+---+---+---+ | 484 // +---+---+---+---+ |
| 512 // | X | X | X | _ | | 485 // | X | X | X | _ | |
| 513 // +---+---+---+---+ | 486 // +---+---+---+---+ |
| 514 // | X | X | X | _ | | 487 // | X | X | X | _ | |
| 515 // +---+---+---+---+ | 488 // +---+---+---+---+ |
| 516 // | X | X | X | _ | | 489 // | X | X | X | _ | |
| 517 // +---+---+---+---+ | 490 // +---+---+---+---+ |
| 518 // | _ | _ | _ | _ | | 491 // | _ | _ | _ | _ | |
| 519 // +---+---+---+---+ | 492 // +---+---+---+---+ |
| 520 ASSERT_TRUE(MarkBlocksAndCheckMerge(0, 0, 3, 3)); | 493 MarkBlocksAndCheckMerge(0, 0, 3, 3); |
| 521 } | 494 } |
| 522 | 495 |
| 523 // This tests marked regions that require more than 1 single dirty rect. | 496 // This tests marked regions that require more than 1 single dirty rect. |
| 524 // The exact rects returned depend on the current implementation, so these | 497 // The exact rects returned depend on the current implementation, so these |
| 525 // may need to be updated if we modify how we merge blocks. | 498 // may need to be updated if we modify how we merge blocks. |
| 526 TEST_F(DifferTest, MergeBlocks_MultiRect) { | 499 TEST_F(DifferTest, MergeBlocks_MultiRect) { |
| 527 InitDiffer(kScreenWidth, kScreenHeight); | 500 InitDiffer(kScreenWidth, kScreenHeight); |
| 528 SkRegion dirty; | 501 scoped_ptr<InvalidRects> dirty; |
| 529 | 502 |
| 530 // +---+---+---+---+ +---+---+---+ | 503 // +---+---+---+---+ +---+---+---+ |
| 531 // | | X | | _ | | | 0 | | | 504 // | | X | | _ | | | 0 | | |
| 532 // +---+---+---+---+ +---+---+---+ | 505 // +---+---+---+---+ +---+---+---+ |
| 533 // | X | | | _ | | 1 | | | | 506 // | X | | | _ | | 1 | | | |
| 534 // +---+---+---+---+ => +---+---+---+ | 507 // +---+---+---+---+ => +---+---+---+ |
| 535 // | | | X | _ | | | | 2 | | 508 // | | | X | _ | | | | 2 | |
| 536 // +---+---+---+---+ +---+---+---+ | 509 // +---+---+---+---+ +---+---+---+ |
| 537 // | _ | _ | _ | _ | | 510 // | _ | _ | _ | _ | |
| 538 // +---+---+---+---+ | 511 // +---+---+---+---+ |
| 539 ClearDiffInfo(); | 512 ClearDiffInfo(); |
| 540 MarkBlocks(1, 0, 1, 1); | 513 MarkBlocks(1, 0, 1, 1); |
| 541 MarkBlocks(0, 1, 1, 1); | 514 MarkBlocks(0, 1, 1, 1); |
| 542 MarkBlocks(2, 2, 1, 1); | 515 MarkBlocks(2, 2, 1, 1); |
| 543 | 516 |
| 544 dirty.setEmpty(); | 517 dirty.reset(new InvalidRects()); |
| 545 MergeBlocks(&dirty); | 518 differ_->MergeBlocks(dirty.get()); |
| 546 | 519 |
| 547 ASSERT_EQ(3, RegionRectCount(dirty)); | 520 ASSERT_EQ(3UL, dirty->size()); |
| 548 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 1, 0, 1, 1)); | 521 CheckDirtyRect(*dirty.get(), 1, 0, 1, 1); |
| 549 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 1, 1, 1)); | 522 CheckDirtyRect(*dirty.get(), 0, 1, 1, 1); |
| 550 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 2, 2, 1, 1)); | 523 CheckDirtyRect(*dirty.get(), 2, 2, 1, 1); |
| 551 | 524 |
| 552 // +---+---+---+---+ +---+---+---+ | 525 // +---+---+---+---+ +---+---+---+ |
| 553 // | | | X | _ | | | | 0 | | 526 // | | | X | _ | | | | 0 | |
| 554 // +---+---+---+---+ +---+---+---+ | 527 // +---+---+---+---+ +---+---+ + |
| 555 // | X | X | X | _ | | 1 1 1 | | 528 // | X | X | X | _ | | 1 1 | 0 | |
| 556 // +---+---+---+---+ => + + | 529 // +---+---+---+---+ => + + + |
| 557 // | X | X | X | _ | | 1 1 1 | | 530 // | X | X | X | _ | | 1 1 | 0 | |
| 558 // +---+---+---+---+ +---+---+---+ | 531 // +---+---+---+---+ +---+---+---+ |
| 559 // | _ | _ | _ | _ | | 532 // | _ | _ | _ | _ | |
| 560 // +---+---+---+---+ | 533 // +---+---+---+---+ |
| 561 ClearDiffInfo(); | 534 ClearDiffInfo(); |
| 562 MarkBlocks(2, 0, 1, 1); | 535 MarkBlocks(2, 0, 1, 3); |
| 563 MarkBlocks(0, 1, 3, 2); | 536 MarkBlocks(0, 1, 2, 2); |
| 564 | 537 |
| 565 dirty.setEmpty(); | 538 dirty.reset(new InvalidRects()); |
| 566 MergeBlocks(&dirty); | 539 differ_->MergeBlocks(dirty.get()); |
| 567 | 540 |
| 568 ASSERT_EQ(2, RegionRectCount(dirty)); | 541 ASSERT_EQ(2UL, dirty->size()); |
| 569 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 2, 0, 1, 1)); | 542 CheckDirtyRect(*dirty.get(), 2, 0, 1, 3); |
| 570 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 1, 3, 2)); | 543 CheckDirtyRect(*dirty.get(), 0, 1, 2, 2); |
| 571 | 544 |
| 572 // +---+---+---+---+ +---+---+---+ | 545 // +---+---+---+---+ +---+---+---+ |
| 573 // | | | | _ | | | | | | 546 // | | | | _ | | | | | |
| 574 // +---+---+---+---+ +---+---+---+ | 547 // +---+---+---+---+ +---+---+---+ |
| 575 // | X | | X | _ | | 0 | | 1 | | 548 // | X | | X | _ | | 0 | | 1 | |
| 576 // +---+---+---+---+ => + +---+ + | 549 // +---+---+---+---+ => + +---+ + |
| 577 // | X | X | X | _ | | 2 | 2 | 2 | | 550 // | X | X | X | _ | | 0 | 2 | 1 | |
| 578 // +---+---+---+---+ +---+---+---+ | 551 // +---+---+---+---+ +---+---+---+ |
| 579 // | _ | _ | _ | _ | | 552 // | _ | _ | _ | _ | |
| 580 // +---+---+---+---+ | 553 // +---+---+---+---+ |
| 581 ClearDiffInfo(); | 554 ClearDiffInfo(); |
| 582 MarkBlocks(0, 1, 1, 1); | 555 MarkBlocks(0, 1, 1, 1); |
| 583 MarkBlocks(2, 1, 1, 1); | 556 MarkBlocks(2, 1, 1, 1); |
| 584 MarkBlocks(0, 2, 3, 1); | 557 MarkBlocks(0, 2, 3, 1); |
| 585 | 558 |
| 586 dirty.setEmpty(); | 559 dirty.reset(new InvalidRects()); |
| 587 MergeBlocks(&dirty); | 560 differ_->MergeBlocks(dirty.get()); |
| 588 | 561 |
| 589 ASSERT_EQ(3, RegionRectCount(dirty)); | 562 ASSERT_EQ(3UL, dirty->size()); |
| 590 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 1, 1, 1)); | 563 CheckDirtyRect(*dirty.get(), 0, 1, 1, 2); |
| 591 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 2, 1, 1, 1)); | 564 CheckDirtyRect(*dirty.get(), 2, 1, 1, 2); |
| 592 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 2, 3, 1)); | 565 CheckDirtyRect(*dirty.get(), 1, 2, 1, 1); |
| 593 | 566 |
| 594 // +---+---+---+---+ +---+---+---+ | 567 // +---+---+---+---+ +---+---+---+ |
| 595 // | X | X | X | _ | | 0 0 0 | | 568 // | X | X | X | _ | | 0 0 0 | |
| 596 // +---+---+---+---+ +---+---+---+ | 569 // +---+---+---+---+ +---+---+---+ |
| 597 // | X | | X | _ | | 1 | | 2 | | 570 // | X | | X | _ | | 1 | | 2 | |
| 598 // +---+---+---+---+ => + +---+ + | 571 // +---+---+---+---+ => + +---+ + |
| 599 // | X | X | X | _ | | 3 | 3 | 3 | | 572 // | X | X | X | _ | | 1 | 3 | 2 | |
| 600 // +---+---+---+---+ +---+---+---+ | 573 // +---+---+---+---+ +---+---+---+ |
| 601 // | _ | _ | _ | _ | | 574 // | _ | _ | _ | _ | |
| 602 // +---+---+---+---+ | 575 // +---+---+---+---+ |
| 603 ClearDiffInfo(); | 576 ClearDiffInfo(); |
| 604 MarkBlocks(0, 0, 3, 1); | 577 MarkBlocks(0, 0, 3, 1); |
| 605 MarkBlocks(0, 1, 1, 1); | 578 MarkBlocks(0, 1, 1, 1); |
| 606 MarkBlocks(2, 1, 1, 1); | 579 MarkBlocks(2, 1, 1, 1); |
| 607 MarkBlocks(0, 2, 3, 1); | 580 MarkBlocks(0, 2, 3, 1); |
| 608 | 581 |
| 609 dirty.setEmpty(); | 582 dirty.reset(new InvalidRects()); |
| 610 MergeBlocks(&dirty); | 583 differ_->MergeBlocks(dirty.get()); |
| 611 | 584 |
| 612 ASSERT_EQ(4, RegionRectCount(dirty)); | 585 ASSERT_EQ(4UL, dirty->size()); |
| 613 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 0, 3, 1)); | 586 CheckDirtyRect(*dirty.get(), 0, 0, 3, 1); |
| 614 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 1, 1, 1)); | 587 CheckDirtyRect(*dirty.get(), 0, 1, 1, 2); |
| 615 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 2, 1, 1, 1)); | 588 CheckDirtyRect(*dirty.get(), 2, 1, 1, 2); |
| 616 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 2, 3, 1)); | 589 CheckDirtyRect(*dirty.get(), 1, 2, 1, 1); |
| 617 | 590 |
| 618 // +---+---+---+---+ +---+---+---+ | 591 // +---+---+---+---+ +---+---+---+ |
| 619 // | X | X | | _ | | 0 0 | | | 592 // | X | X | | _ | | 0 0 | | |
| 620 // +---+---+---+---+ + +---+ | 593 // +---+---+---+---+ + +---+ |
| 621 // | X | X | | _ | | 0 0 | | | 594 // | X | X | | _ | | 0 0 | | |
| 622 // +---+---+---+---+ => +---+---+---+ | 595 // +---+---+---+---+ => +---+---+---+ |
| 623 // | | X | | _ | | | 1 | | | 596 // | | X | | _ | | | 1 | | |
| 624 // +---+---+---+---+ +---+---+---+ | 597 // +---+---+---+---+ +---+---+---+ |
| 625 // | _ | _ | _ | _ | | 598 // | _ | _ | _ | _ | |
| 626 // +---+---+---+---+ | 599 // +---+---+---+---+ |
| 627 ClearDiffInfo(); | 600 ClearDiffInfo(); |
| 628 MarkBlocks(0, 0, 2, 2); | 601 MarkBlocks(0, 0, 2, 2); |
| 629 MarkBlocks(1, 2, 1, 1); | 602 MarkBlocks(1, 2, 1, 1); |
| 630 | 603 |
| 631 dirty.setEmpty(); | 604 dirty.reset(new InvalidRects()); |
| 632 MergeBlocks(&dirty); | 605 differ_->MergeBlocks(dirty.get()); |
| 633 | 606 |
| 634 ASSERT_EQ(2, RegionRectCount(dirty)); | 607 ASSERT_EQ(2UL, dirty->size()); |
| 635 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 0, 0, 2, 2)); | 608 CheckDirtyRect(*dirty.get(), 0, 0, 2, 2); |
| 636 ASSERT_TRUE(CheckDirtyRegionContainsRect(dirty, 1, 2, 1, 1)); | 609 CheckDirtyRect(*dirty.get(), 1, 2, 1, 1); |
| 637 } | 610 } |
| 638 | 611 |
| 639 } // namespace remoting | 612 } // namespace remoting |
| OLD | NEW |