Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(85)

Side by Side Diff: remoting/host/differ.cc

Issue 7491070: Switch over to using SkRegions to calculate dirty areas. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed up shared lib compile Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/differ.h ('k') | remoting/host/differ_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "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 #include "remoting/host/differ_block.h"
9 9
10 namespace remoting { 10 namespace remoting {
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::CalcDirtyRects(const void* prev_buffer, const void* curr_buffer, 29 void Differ::CalcDirtyRegion(const void* prev_buffer, const void* curr_buffer,
30 InvalidRects* rects) { 30 SkRegion* region) {
31 if (!rects) { 31 if (!region) {
32 return; 32 return;
33 } 33 }
34 rects->clear(); 34 region->setEmpty();
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.
45 MergeBlocks(rects); 45 MergeBlocks(region);
46 } 46 }
47 47
48 void Differ::MarkDirtyBlocks(const void* prev_buffer, const void* curr_buffer) { 48 void Differ::MarkDirtyBlocks(const void* prev_buffer, const void* curr_buffer) {
49 memset(diff_info_.get(), 0, diff_info_size_); 49 memset(diff_info_.get(), 0, diff_info_size_);
50 50
51 // Calc number of full blocks. 51 // Calc number of full blocks.
52 int x_full_blocks = width_ / kBlockSize; 52 int x_full_blocks = width_ / kBlockSize;
53 int y_full_blocks = height_ / kBlockSize; 53 int y_full_blocks = height_ / kBlockSize;
54 54
55 // Calc size of partial blocks which may be present on right and bottom edge. 55 // Calc size of partial blocks which may be present on right and bottom edge.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(InvalidRects* rects) { 134 void Differ::MergeBlocks(SkRegion* region) {
135 DCHECK(rects); 135 DCHECK(region);
136 rects->clear(); 136 region->setEmpty();
137 137
138 uint8* diff_info_row_start = static_cast<uint8*>(diff_info_.get()); 138 uint8* diff_info_row_start = static_cast<uint8*>(diff_info_.get());
139 int diff_info_stride = diff_info_width_ * sizeof(DiffInfo); 139 int diff_info_stride = diff_info_width_ * sizeof(DiffInfo);
140 140
141 for (int y = 0; y < diff_info_height_; y++) { 141 for (int y = 0; y < diff_info_height_; y++) {
142 uint8* diff_info = diff_info_row_start; 142 uint8* diff_info = diff_info_row_start;
143 for (int x = 0; x < diff_info_width_; x++) { 143 for (int x = 0; x < diff_info_width_; x++) {
144 if (*diff_info != 0) { 144 if (*diff_info != 0) {
145 // We've found a modified block. Look at blocks to the right and below 145 // 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. 146 // to group this block with as many others as we can.
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 188
189 // Add rect to list of dirty rects. 189 // Add rect to list of dirty rects.
190 width *= kBlockSize; 190 width *= kBlockSize;
191 if (left + width > width_) { 191 if (left + width > width_) {
192 width = width_ - left; 192 width = width_ - left;
193 } 193 }
194 height *= kBlockSize; 194 height *= kBlockSize;
195 if (top + height > height_) { 195 if (top + height > height_) {
196 height = height_ - top; 196 height = height_ - top;
197 } 197 }
198 rects->insert(gfx::Rect(left, top, width, height)); 198 region->op(SkIRect::MakeXYWH(left, top, width, height),
199 SkRegion::kUnion_Op);
199 } 200 }
200 201
201 // Increment to next block in this row. 202 // Increment to next block in this row.
202 diff_info++; 203 diff_info++;
203 } 204 }
204 205
205 // Go to start of next row. 206 // Go to start of next row.
206 diff_info_row_start += diff_info_stride; 207 diff_info_row_start += diff_info_stride;
207 } 208 }
208 } 209 }
209 210
210 } // namespace remoting 211 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/differ.h ('k') | remoting/host/differ_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698