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 #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/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
12 #include "gfx/rect.h" | 12 #include "gfx/rect.h" |
| 13 #include "remoting/base/types.h" |
13 | 14 |
14 namespace remoting { | 15 namespace remoting { |
15 | 16 |
16 typedef std::vector<gfx::Rect> DirtyRects; | |
17 typedef uint8 DiffInfo; | 17 typedef uint8 DiffInfo; |
18 | 18 |
19 // Size (in pixels) of each square block used for diffing. | 19 // Size (in pixels) of each square block used for diffing. |
20 // This must be a multiple of sizeof(uint64). | 20 // This must be a multiple of sizeof(uint64). |
21 static const int kBlockSize = 32; | 21 static const int kBlockSize = 32; |
22 | 22 |
23 class Differ { | 23 class Differ { |
24 public: | 24 public: |
25 // Create a differ that operates on bitmaps with the specified width, height | 25 // Create a differ that operates on bitmaps with the specified width, height |
26 // and bytes_per_pixel. | 26 // and bytes_per_pixel. |
27 Differ(int width, int height, int bytes_per_pixel); | 27 Differ(int width, int height, int bytes_per_pixel, int stride); |
28 | 28 |
29 // Given the previous and current screen buffer, calculate the set of | 29 // Given the previous and current screen buffer, calculate the set of |
30 // rectangles that enclose all the changed pixels in the new screen. | 30 // rectangles that enclose all the changed pixels in the new screen. |
31 void CalcDirtyRects(const void* prev_buffer, const void* curr_buffer, | 31 void CalcDirtyRects(const void* prev_buffer, const void* curr_buffer, |
32 DirtyRects* rects); | 32 InvalidRects* rects); |
33 | 33 |
34 // Identify all of the blocks that contain changed pixels. | 34 // Identify all of the blocks that contain changed pixels. |
35 void MarkDirtyBlocks(const void* prev_buffer, const void* curr_buffer); | 35 void MarkDirtyBlocks(const void* prev_buffer, const void* curr_buffer); |
36 | 36 |
37 // Diff a small block of image and return non-zero if there is a diff. | 37 // Diff a small block of image and return non-zero if there is a diff. |
38 // Currently, this just returns 0 or 1, but this may change in the future | 38 // Currently, this just returns 0 or 1, but this may change in the future |
39 // to return the number of pixels changed. | 39 // to return the number of pixels changed. |
40 DiffInfo DiffBlock(const uint8* prev_buffer, const uint8* curr_buffer, | 40 DiffInfo DiffBlock(const uint8* prev_buffer, const uint8* curr_buffer, |
41 int stride); | 41 int stride); |
42 | 42 |
43 // Diff a small block of image and return non-zero if there is a diff. | 43 // Diff a small block of image and return non-zero if there is a diff. |
44 // This checks only the part of the block specified by the width and | 44 // This checks only the part of the block specified by the width and |
45 // height parameters. | 45 // height parameters. |
46 // This is much slower than DiffBlock() since it cannot assume that the | 46 // This is much slower than DiffBlock() since it cannot assume that the |
47 // full block is being checked. | 47 // full block is being checked. |
48 // If we force the capturer to always return images whose width/height are | 48 // If we force the capturer to always return images whose width/height are |
49 // multiples of kBlockSize, then this will never be called. | 49 // multiples of kBlockSize, then this will never be called. |
50 DiffInfo DiffPartialBlock(const uint8* prev_buffer, const uint8* curr_buffer, | 50 DiffInfo DiffPartialBlock(const uint8* prev_buffer, const uint8* curr_buffer, |
51 int stride, int width, int height); | 51 int stride, int width, int height); |
52 | 52 |
53 // After the dirty blocks have been identified, this routine merges adjacent | 53 // After the dirty blocks have been identified, this routine merges adjacent |
54 // blocks into larger rectangular units. | 54 // blocks into larger rectangular units. |
55 // The goal is to minimize the number of rects that cover the dirty blocks, | 55 // The goal is to minimize the number of rects that cover the dirty blocks, |
56 // although it is not required to calc the absolute minimum of rects. | 56 // although it is not required to calc the absolute minimum of rects. |
57 void MergeBlocks(DirtyRects* rects); | 57 void MergeBlocks(InvalidRects* rects); |
58 | 58 |
59 // Allow tests to access our private parts. | 59 // Allow tests to access our private parts. |
60 friend class DifferTest; | 60 friend class DifferTest; |
61 | 61 |
62 private: | 62 private: |
63 // Dimensions of screen. | 63 // Dimensions of screen. |
64 int width_; | 64 int width_; |
65 int height_; | 65 int height_; |
66 | 66 |
67 // Number of bytes for each pixel in source and dest bitmap. | 67 // Number of bytes for each pixel in source and dest bitmap. |
| 68 // (Yes, they must match.) |
68 int bytes_per_pixel_; | 69 int bytes_per_pixel_; |
69 | 70 |
70 // Number of bytes in each row of the image. | 71 // Number of bytes in each row of the image (AKA: stride). |
71 int bytes_per_row_; | 72 int bytes_per_row_; |
72 | 73 |
73 // Diff information for each block in the image. | 74 // Diff information for each block in the image. |
74 scoped_array<DiffInfo> diff_info_; | 75 scoped_array<DiffInfo> diff_info_; |
75 | 76 |
76 // Dimensions and total size of diff info array. | 77 // Dimensions and total size of diff info array. |
77 int diff_info_width_; | 78 int diff_info_width_; |
78 int diff_info_height_; | 79 int diff_info_height_; |
79 int diff_info_size_; | 80 int diff_info_size_; |
80 | 81 |
81 DISALLOW_COPY_AND_ASSIGN(Differ); | 82 DISALLOW_COPY_AND_ASSIGN(Differ); |
82 }; | 83 }; |
83 | 84 |
84 } // namespace remoting | 85 } // namespace remoting |
85 | 86 |
86 #endif // REMOTING_HOST_DIFFER_H_ | 87 #endif // REMOTING_HOST_DIFFER_H_ |
OLD | NEW |