| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "remoting/host/differ.h" | 5 #include "remoting/host/differ.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "remoting/host/differ_block.h" |
| 8 | 9 |
| 9 namespace remoting { | 10 namespace remoting { |
| 10 | 11 |
| 11 Differ::Differ(int width, int height, int bpp, int stride) { | 12 Differ::Differ(int width, int height, int bpp, int stride) { |
| 12 // Dimensions of screen. | 13 // Dimensions of screen. |
| 13 width_ = width; | 14 width_ = width; |
| 14 height_ = height; | 15 height_ = height; |
| 15 bytes_per_pixel_ = bpp; | 16 bytes_per_pixel_ = bpp; |
| 16 bytes_per_row_ = stride; | 17 bytes_per_row_ = stride; |
| 17 | 18 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 const uint8* prev_block_row_start = static_cast<const uint8*>(prev_buffer); | 66 const uint8* prev_block_row_start = static_cast<const uint8*>(prev_buffer); |
| 66 const uint8* curr_block_row_start = static_cast<const uint8*>(curr_buffer); | 67 const uint8* curr_block_row_start = static_cast<const uint8*>(curr_buffer); |
| 67 uint8* diff_info_row_start = static_cast<uint8*>(diff_info_.get()); | 68 uint8* diff_info_row_start = static_cast<uint8*>(diff_info_.get()); |
| 68 | 69 |
| 69 for (int y = 0; y < y_full_blocks; y++) { | 70 for (int y = 0; y < y_full_blocks; y++) { |
| 70 const uint8* prev_block = prev_block_row_start; | 71 const uint8* prev_block = prev_block_row_start; |
| 71 const uint8* curr_block = curr_block_row_start; | 72 const uint8* curr_block = curr_block_row_start; |
| 72 uint8* diff_info = diff_info_row_start; | 73 uint8* diff_info = diff_info_row_start; |
| 73 | 74 |
| 74 for (int x = 0; x < x_full_blocks; x++) { | 75 for (int x = 0; x < x_full_blocks; x++) { |
| 75 DiffInfo diff = DiffBlock(prev_block, curr_block, bytes_per_row_); | 76 DiffInfo diff = BlockDifference(prev_block, curr_block, bytes_per_row_); |
| 76 if (diff != 0) { | 77 if (diff != 0) { |
| 77 // Mark this block as being modified so that it gets incorporated into | 78 // Mark this block as being modified so that it gets incorporated into |
| 78 // a dirty rect. | 79 // a dirty rect. |
| 79 *diff_info = diff; | 80 *diff_info = diff; |
| 80 } | 81 } |
| 81 prev_block += block_x_offset; | 82 prev_block += block_x_offset; |
| 82 curr_block += block_x_offset; | 83 curr_block += block_x_offset; |
| 83 diff_info += sizeof(DiffInfo); | 84 diff_info += sizeof(DiffInfo); |
| 84 } | 85 } |
| 85 | 86 |
| 86 // If there is a partial column at the end, handle it. | 87 // If there is a partial column at the end, handle it. |
| 87 if (partial_column_width != 0) { | 88 if (partial_column_width != 0) { |
| 88 // TODO(garykac): Handle last partial column. | 89 // TODO(garykac): Handle last partial column. |
| 89 } | 90 } |
| 90 | 91 |
| 91 // Update pointers for next row. | 92 // Update pointers for next row. |
| 92 prev_block_row_start += block_y_stride; | 93 prev_block_row_start += block_y_stride; |
| 93 curr_block_row_start += block_y_stride; | 94 curr_block_row_start += block_y_stride; |
| 94 diff_info_row_start += diff_info_stride; | 95 diff_info_row_start += diff_info_stride; |
| 95 } | 96 } |
| 96 if (partial_row_height != 0) { | 97 if (partial_row_height != 0) { |
| 97 // TODO(garykac): Handle last partial row. | 98 // TODO(garykac): Handle last partial row. |
| 98 } | 99 } |
| 99 } | 100 } |
| 100 | 101 |
| 101 DiffInfo Differ::DiffBlock(const uint8* prev_buffer, const uint8* curr_buffer, | |
| 102 int stride) { | |
| 103 const uint8* prev_row_start = prev_buffer; | |
| 104 const uint8* curr_row_start = curr_buffer; | |
| 105 | |
| 106 // Number of uint64s in each row of the block. | |
| 107 // This must be an integral number. | |
| 108 int int64s_per_row = (kBlockSize * bytes_per_pixel_) / sizeof(uint64); | |
| 109 DCHECK(((kBlockSize * bytes_per_pixel_) % sizeof(uint64)) == 0); | |
| 110 | |
| 111 for (int y = 0; y < kBlockSize; y++) { | |
| 112 const uint64* prev = reinterpret_cast<const uint64*>(prev_row_start); | |
| 113 const uint64* curr = reinterpret_cast<const uint64*>(curr_row_start); | |
| 114 | |
| 115 // Check each row in uint64-sized chunks. | |
| 116 // Note that this check may straddle multiple pixels. This is OK because | |
| 117 // we're interested in identifying whether or not there was change - we | |
| 118 // don't care what the actual change is. | |
| 119 for (int x = 0; x < int64s_per_row; x++) { | |
| 120 if (*prev++ != *curr++) { | |
| 121 return 1; | |
| 122 } | |
| 123 } | |
| 124 prev_row_start += stride; | |
| 125 curr_row_start += stride; | |
| 126 } | |
| 127 return 0; | |
| 128 } | |
| 129 | |
| 130 DiffInfo Differ::DiffPartialBlock(const uint8* prev_buffer, | 102 DiffInfo Differ::DiffPartialBlock(const uint8* prev_buffer, |
| 131 const uint8* curr_buffer, | 103 const uint8* curr_buffer, |
| 132 int stride, int width, int height) { | 104 int stride, int width, int height) { |
| 133 const uint8* prev_row_start = prev_buffer; | 105 const uint8* prev_row_start = prev_buffer; |
| 134 const uint8* curr_row_start = curr_buffer; | 106 const uint8* curr_row_start = curr_buffer; |
| 135 | 107 |
| 136 for (int y = 0; y < height; y++) { | 108 for (int y = 0; y < height; y++) { |
| 137 const uint8* prev = prev_row_start; | 109 const uint8* prev = prev_row_start; |
| 138 const uint8* curr = curr_row_start; | 110 const uint8* curr = curr_row_start; |
| 139 for (int x = 0; x < width; x++) { | 111 for (int x = 0; x < width; x++) { |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 // Increment to next block in this row. | 191 // Increment to next block in this row. |
| 220 diff_info++; | 192 diff_info++; |
| 221 } | 193 } |
| 222 | 194 |
| 223 // Go to start of next row. | 195 // Go to start of next row. |
| 224 diff_info_row_start += diff_info_stride; | 196 diff_info_row_start += diff_info_stride; |
| 225 } | 197 } |
| 226 } | 198 } |
| 227 | 199 |
| 228 } // namespace remoting | 200 } // namespace remoting |
| OLD | NEW |