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 "media/video/capture/screen/differ.h" | 5 #include "media/video/capture/screen/differ.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "media/video/capture/screen/differ_block.h" | 8 #include "media/video/capture/screen/differ_block.h" |
9 | 9 |
10 namespace media { | 10 namespace media { |
11 | 11 |
12 Differ::Differ(int width, int height, int bpp, int stride) { | 12 Differ::Differ(int width, int height, int bpp, int stride) { |
13 // Dimensions of screen. | 13 // Dimensions of screen. |
14 width_ = width; | 14 width_ = width; |
15 height_ = height; | 15 height_ = height; |
16 bytes_per_pixel_ = bpp; | 16 bytes_per_pixel_ = bpp; |
17 bytes_per_row_ = stride; | 17 bytes_per_row_ = stride; |
18 | 18 |
19 // Calc number of blocks (full and partial) required to cover entire image. | 19 // Calc number of blocks (full and partial) required to cover entire image. |
20 // One additional row/column is added as a boundary on the right & bottom. | 20 // One additional row/column is added as a boundary on the right & bottom. |
21 diff_info_width_ = ((width_ + kBlockSize - 1) / kBlockSize) + 1; | 21 diff_info_width_ = ((width_ + kBlockSize - 1) / kBlockSize) + 1; |
22 diff_info_height_ = ((height_ + kBlockSize - 1) / kBlockSize) + 1; | 22 diff_info_height_ = ((height_ + kBlockSize - 1) / kBlockSize) + 1; |
23 diff_info_size_ = diff_info_width_ * diff_info_height_ * sizeof(DiffInfo); | 23 diff_info_size_ = diff_info_width_ * diff_info_height_ * sizeof(DiffInfo); |
24 diff_info_.reset(new DiffInfo[diff_info_size_]); | 24 diff_info_.reset(new DiffInfo[diff_info_size_]); |
25 } | 25 } |
26 | 26 |
27 Differ::~Differ() {} | 27 Differ::~Differ() {} |
28 | 28 |
29 void Differ::CalcDirtyRegion(const void* prev_buffer, const void* curr_buffer, | 29 void Differ::CalcDirtyRegion(const void* prev_buffer, const void* curr_buffer, |
30 SkRegion* region) { | 30 webrtc::DesktopRegion* region) { |
31 if (!region) { | 31 if (!region) { |
32 return; | 32 return; |
33 } | 33 } |
34 region->setEmpty(); | 34 region->Clear(); |
35 | 35 |
36 if (!prev_buffer || !curr_buffer) { | 36 if (!prev_buffer || !curr_buffer) { |
37 return; | 37 return; |
38 } | 38 } |
39 | 39 |
40 // Identify all the blocks that contain changed pixels. | 40 // Identify all the blocks that contain changed pixels. |
41 MarkDirtyBlocks(prev_buffer, curr_buffer); | 41 MarkDirtyBlocks(prev_buffer, curr_buffer); |
42 | 42 |
43 // Now that we've identified the blocks that have changed, merge adjacent | 43 // Now that we've identified the blocks that have changed, merge adjacent |
44 // blocks to minimize the number of rects that we return. | 44 // blocks to minimize the number of rects that we return. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 int width_bytes = width * bytes_per_pixel_; | 124 int width_bytes = width * bytes_per_pixel_; |
125 for (int y = 0; y < height; y++) { | 125 for (int y = 0; y < height; y++) { |
126 if (memcmp(prev_buffer, curr_buffer, width_bytes) != 0) | 126 if (memcmp(prev_buffer, curr_buffer, width_bytes) != 0) |
127 return 1; | 127 return 1; |
128 prev_buffer += bytes_per_row_; | 128 prev_buffer += bytes_per_row_; |
129 curr_buffer += bytes_per_row_; | 129 curr_buffer += bytes_per_row_; |
130 } | 130 } |
131 return 0; | 131 return 0; |
132 } | 132 } |
133 | 133 |
134 void Differ::MergeBlocks(SkRegion* region) { | 134 void Differ::MergeBlocks(webrtc::DesktopRegion* region) { |
135 DCHECK(region); | 135 DCHECK(region); |
136 region->setEmpty(); | |
alexeypa (please no reviews)
2013/04/26 21:33:58
nit: DCHECK(region->is_empty())
Sergey Ulanov
2013/05/07 22:25:50
Just moved Clear() call here.
| |
137 | 136 |
138 uint8* diff_info_row_start = static_cast<uint8*>(diff_info_.get()); | 137 uint8* diff_info_row_start = static_cast<uint8*>(diff_info_.get()); |
139 int diff_info_stride = diff_info_width_ * sizeof(DiffInfo); | 138 int diff_info_stride = diff_info_width_ * sizeof(DiffInfo); |
140 | 139 |
141 for (int y = 0; y < diff_info_height_; y++) { | 140 for (int y = 0; y < diff_info_height_; y++) { |
142 uint8* diff_info = diff_info_row_start; | 141 uint8* diff_info = diff_info_row_start; |
143 for (int x = 0; x < diff_info_width_; x++) { | 142 for (int x = 0; x < diff_info_width_; x++) { |
144 if (*diff_info != 0) { | 143 if (*diff_info != 0) { |
145 // We've found a modified block. Look at blocks to the right and below | 144 // We've found a modified block. Look at blocks to the right and below |
146 // to group this block with as many others as we can. | 145 // to group this block with as many others as we can. |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 | 187 |
189 // Add rect to list of dirty rects. | 188 // Add rect to list of dirty rects. |
190 width *= kBlockSize; | 189 width *= kBlockSize; |
191 if (left + width > width_) { | 190 if (left + width > width_) { |
192 width = width_ - left; | 191 width = width_ - left; |
193 } | 192 } |
194 height *= kBlockSize; | 193 height *= kBlockSize; |
195 if (top + height > height_) { | 194 if (top + height > height_) { |
196 height = height_ - top; | 195 height = height_ - top; |
197 } | 196 } |
198 region->op(SkIRect::MakeXYWH(left, top, width, height), | 197 region->AddRect( |
199 SkRegion::kUnion_Op); | 198 webrtc::DesktopRect::MakeXYWH(left, top, width, height)); |
200 } | 199 } |
201 | 200 |
202 // Increment to next block in this row. | 201 // Increment to next block in this row. |
203 diff_info++; | 202 diff_info++; |
204 } | 203 } |
205 | 204 |
206 // Go to start of next row. | 205 // Go to start of next row. |
207 diff_info_row_start += diff_info_stride; | 206 diff_info_row_start += diff_info_stride; |
208 } | 207 } |
209 } | 208 } |
210 | 209 |
211 } // namespace media | 210 } // namespace media |
OLD | NEW |