Chromium Code Reviews| 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) { |
|
alexeypa (please no reviews)
2013/05/08 22:24:59
The whole purpose of this method is to return |reg
Sergey Ulanov
2013/05/09 18:49:02
Done
| |
| 32 return; | 32 return; |
| 33 } | 33 } |
| 34 region->setEmpty(); | |
| 35 | 34 |
| 36 if (!prev_buffer || !curr_buffer) { | 35 if (!prev_buffer || !curr_buffer) { |
|
alexeypa (please no reviews)
2013/05/08 22:24:59
It looks like the callers make sure that |prev_buf
Sergey Ulanov
2013/05/09 18:49:02
Done.
| |
| 37 return; | 36 return; |
| 38 } | 37 } |
| 39 | 38 |
| 40 // Identify all the blocks that contain changed pixels. | 39 // Identify all the blocks that contain changed pixels. |
| 41 MarkDirtyBlocks(prev_buffer, curr_buffer); | 40 MarkDirtyBlocks(prev_buffer, curr_buffer); |
| 42 | 41 |
| 43 // Now that we've identified the blocks that have changed, merge adjacent | 42 // Now that we've identified the blocks that have changed, merge adjacent |
| 44 // blocks to minimize the number of rects that we return. | 43 // blocks to minimize the number of rects that we return. |
| 45 MergeBlocks(region); | 44 MergeBlocks(region); |
| 46 } | 45 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 int width_bytes = width * bytes_per_pixel_; | 123 int width_bytes = width * bytes_per_pixel_; |
| 125 for (int y = 0; y < height; y++) { | 124 for (int y = 0; y < height; y++) { |
| 126 if (memcmp(prev_buffer, curr_buffer, width_bytes) != 0) | 125 if (memcmp(prev_buffer, curr_buffer, width_bytes) != 0) |
| 127 return 1; | 126 return 1; |
| 128 prev_buffer += bytes_per_row_; | 127 prev_buffer += bytes_per_row_; |
| 129 curr_buffer += bytes_per_row_; | 128 curr_buffer += bytes_per_row_; |
| 130 } | 129 } |
| 131 return 0; | 130 return 0; |
| 132 } | 131 } |
| 133 | 132 |
| 134 void Differ::MergeBlocks(SkRegion* region) { | 133 void Differ::MergeBlocks(webrtc::DesktopRegion* region) { |
| 135 DCHECK(region); | 134 DCHECK(region); |
|
alexeypa (please no reviews)
2013/05/08 22:24:59
nit: remove DCHECK. |region->Clear()| will crash i
Sergey Ulanov
2013/05/09 18:49:02
Done.
| |
| 136 region->setEmpty(); | 135 region->Clear(); |
| 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 |