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 #ifndef REMOTING_HOST_DIFFER_H_ | 5 #ifndef REMOTING_HOST_DIFFER_H_ |
6 #define REMOTING_HOST_DIFFER_H_ | 6 #define REMOTING_HOST_DIFFER_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "remoting/base/types.h" | 12 #include "third_party/skia/include/core/SkRegion.h" |
13 #include "ui/gfx/rect.h" | |
14 | 13 |
15 namespace remoting { | 14 namespace remoting { |
16 | 15 |
17 typedef uint8 DiffInfo; | 16 typedef uint8 DiffInfo; |
18 | 17 |
19 // Size (in pixels) of each square block used for diffing. | 18 // Size (in pixels) of each square block used for diffing. |
20 // This must be a multiple of sizeof(uint64). | 19 // This must be a multiple of sizeof(uint64). |
21 static const int kBlockSize = 32; | 20 static const int kBlockSize = 32; |
22 | 21 |
22 // TODO(dmaclach): Simplify differ now that we are working with SkRegions. | |
23 // diff_info_ should no longer be needed, as we can put our data directly into | |
24 // the region that we are calculating. | |
23 class Differ { | 25 class Differ { |
24 public: | 26 public: |
25 // Create a differ that operates on bitmaps with the specified width, height | 27 // Create a differ that operates on bitmaps with the specified width, height |
26 // and bytes_per_pixel. | 28 // and bytes_per_pixel. |
27 Differ(int width, int height, int bytes_per_pixel, int stride); | 29 Differ(int width, int height, int bytes_per_pixel, int stride); |
28 ~Differ(); | 30 ~Differ(); |
29 | 31 |
30 int width() { return width_; } | 32 int width() { return width_; } |
31 int height() { return height_; } | 33 int height() { return height_; } |
32 int bytes_per_pixel() { return bytes_per_pixel_; } | 34 int bytes_per_pixel() { return bytes_per_pixel_; } |
33 int bytes_per_row() { return bytes_per_row_; } | 35 int bytes_per_row() { return bytes_per_row_; } |
34 | 36 |
35 // Given the previous and current screen buffer, calculate the set of | 37 // Given the previous and current screen buffer, calculate the dirty region |
36 // rectangles that enclose all the changed pixels in the new screen. | 38 // that encloses all of the changed pixels in the new screen. |
37 void CalcDirtyRects(const void* prev_buffer, const void* curr_buffer, | 39 void CalcDirtyRegion(const void* prev_buffer, const void* curr_buffer, |
38 InvalidRects* rects); | 40 SkRegion* region); |
41 | |
42 private: | |
43 // Allow tests to access our private parts. | |
44 friend class DifferTest; | |
39 | 45 |
40 // Identify all of the blocks that contain changed pixels. | 46 // Identify all of the blocks that contain changed pixels. |
41 void MarkDirtyBlocks(const void* prev_buffer, const void* curr_buffer); | 47 void MarkDirtyBlocks(const void* prev_buffer, const void* curr_buffer); |
42 | 48 |
43 // After the dirty blocks have been identified, this routine merges adjacent | 49 // After the dirty blocks have been identified, this routine merges adjacent |
44 // blocks into larger rectangular units. | 50 // blocks into a region. |
45 // The goal is to minimize the number of rects that cover the dirty blocks, | 51 // The goal is to minimize the region that covers the dirty blocks. |
46 // although it is not required to calc the absolute minimum of rects. | 52 void MergeBlocks(SkRegion* region); |
Wez
2011/08/08 20:49:34
You decided not to optimize out these steps in thi
dmac
2011/08/10 20:30:36
Added todo at the top of this file, and have now l
| |
47 void MergeBlocks(InvalidRects* rects); | |
48 | |
49 // Allow tests to access our private parts. | |
50 friend class DifferTest; | |
51 | |
52 private: | |
53 | 53 |
54 // Check for diffs in upper-left portion of the block. The size of the portion | 54 // Check for diffs in upper-left portion of the block. The size of the portion |
55 // to check is specified by the |width| and |height| values. | 55 // to check is specified by the |width| and |height| values. |
56 // Note that if we force the capturer to always return images whose width and | 56 // Note that if we force the capturer to always return images whose width and |
57 // height are multiples of kBlockSize, then this will never be called. | 57 // height are multiples of kBlockSize, then this will never be called. |
58 DiffInfo DiffPartialBlock(const uint8* prev_buffer, const uint8* curr_buffer, | 58 DiffInfo DiffPartialBlock(const uint8* prev_buffer, const uint8* curr_buffer, |
59 int stride, int width, int height); | 59 int stride, int width, int height); |
60 | 60 |
61 // Dimensions of screen. | 61 // Dimensions of screen. |
62 int width_; | 62 int width_; |
(...skipping 13 matching lines...) Expand all Loading... | |
76 int diff_info_width_; | 76 int diff_info_width_; |
77 int diff_info_height_; | 77 int diff_info_height_; |
78 int diff_info_size_; | 78 int diff_info_size_; |
79 | 79 |
80 DISALLOW_COPY_AND_ASSIGN(Differ); | 80 DISALLOW_COPY_AND_ASSIGN(Differ); |
81 }; | 81 }; |
82 | 82 |
83 } // namespace remoting | 83 } // namespace remoting |
84 | 84 |
85 #endif // REMOTING_HOST_DIFFER_H_ | 85 #endif // REMOTING_HOST_DIFFER_H_ |
OLD | NEW |