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 | 8 |
9 namespace remoting { | 9 namespace remoting { |
10 | 10 |
11 Differ::Differ(int width, int height, int bpp) { | 11 Differ::Differ(int width, int height, int bpp, int stride) { |
12 // Dimensions of screen. | 12 // Dimensions of screen. |
13 width_ = width; | 13 width_ = width; |
14 height_ = height; | 14 height_ = height; |
15 bytes_per_pixel_ = bpp; | 15 bytes_per_pixel_ = bpp; |
16 bytes_per_row_ = width_ * bytes_per_pixel_; | 16 bytes_per_row_ = stride; |
17 | 17 |
18 // Calc number of blocks (full and partial) required to cover entire image. | 18 // Calc number of blocks (full and partial) required to cover entire image. |
19 // One additional row/column is added as a boundary on the right & bottom. | 19 // One additional row/column is added as a boundary on the right & bottom. |
20 diff_info_width_ = (width_ + kBlockSize - 1) / kBlockSize + 1; | 20 diff_info_width_ = (width_ + kBlockSize - 1) / kBlockSize + 1; |
21 diff_info_height_ = (height_ + kBlockSize - 1) / kBlockSize + 1; | 21 diff_info_height_ = (height_ + kBlockSize - 1) / kBlockSize + 1; |
22 diff_info_size_ = diff_info_width_ * diff_info_height_ * sizeof(DiffInfo); | 22 diff_info_size_ = diff_info_width_ * diff_info_height_ * sizeof(DiffInfo); |
23 diff_info_.reset(new uint8[diff_info_size_]); | 23 diff_info_.reset(new uint8[diff_info_size_]); |
24 } | 24 } |
25 | 25 |
26 void Differ::CalcDirtyRects(const void* prev_buffer, const void* curr_buffer, | 26 void Differ::CalcDirtyRects(const void* prev_buffer, const void* curr_buffer, |
27 DirtyRects* rects) { | 27 InvalidRects* rects) { |
28 if (!rects) { | 28 if (!rects) { |
29 return; | 29 return; |
30 } | 30 } |
31 rects->clear(); | 31 rects->clear(); |
32 | 32 |
33 if (!prev_buffer || !curr_buffer) { | 33 if (!prev_buffer || !curr_buffer) { |
34 return; | 34 return; |
35 } | 35 } |
36 | 36 |
37 // Identify all the blocks that contain changed pixels. | 37 // Identify all the blocks that contain changed pixels. |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 return 1; | 140 return 1; |
141 } | 141 } |
142 } | 142 } |
143 } | 143 } |
144 prev_row_start += bytes_per_row_; | 144 prev_row_start += bytes_per_row_; |
145 curr_row_start += bytes_per_row_; | 145 curr_row_start += bytes_per_row_; |
146 } | 146 } |
147 return 0; | 147 return 0; |
148 } | 148 } |
149 | 149 |
150 void Differ::MergeBlocks(DirtyRects* rects) { | 150 void Differ::MergeBlocks(InvalidRects* rects) { |
151 DCHECK(rects); | 151 DCHECK(rects); |
152 rects->clear(); | 152 rects->clear(); |
153 | 153 |
154 uint8* diff_info_row_start = static_cast<uint8*>(diff_info_.get()); | 154 uint8* diff_info_row_start = static_cast<uint8*>(diff_info_.get()); |
155 int diff_info_stride = diff_info_width_ * sizeof(DiffInfo); | 155 int diff_info_stride = diff_info_width_ * sizeof(DiffInfo); |
156 | 156 |
157 for (int y = 0; y < diff_info_height_; y++) { | 157 for (int y = 0; y < diff_info_height_; y++) { |
158 uint8* diff_info = diff_info_row_start; | 158 uint8* diff_info = diff_info_row_start; |
159 for (int x = 0; x < diff_info_width_; x++) { | 159 for (int x = 0; x < diff_info_width_; x++) { |
160 if (*diff_info != 0) { | 160 if (*diff_info != 0) { |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 | 204 |
205 // Add rect to list of dirty rects. | 205 // Add rect to list of dirty rects. |
206 width *= kBlockSize; | 206 width *= kBlockSize; |
207 if (left + width > width_) { | 207 if (left + width > width_) { |
208 width = width_ - left; | 208 width = width_ - left; |
209 } | 209 } |
210 height *= kBlockSize; | 210 height *= kBlockSize; |
211 if (top + height > height_) { | 211 if (top + height > height_) { |
212 height = height_ - top; | 212 height = height_ - top; |
213 } | 213 } |
214 rects->push_back(gfx::Rect(left, top, width, height)); | 214 rects->insert(gfx::Rect(left, top, width, height)); |
215 } | 215 } |
216 | 216 |
217 // Increment to next block in this row. | 217 // Increment to next block in this row. |
218 diff_info++; | 218 diff_info++; |
219 } | 219 } |
220 | 220 |
221 // Go to start of next row. | 221 // Go to start of next row. |
222 diff_info_row_start += diff_info_stride; | 222 diff_info_row_start += diff_info_stride; |
223 } | 223 } |
224 } | 224 } |
225 | 225 |
226 } // namespace remoting | 226 } // namespace remoting |
OLD | NEW |