OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license | |
5 * that can be found in the LICENSE file in the root of the source | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_DIFFER_H_ | |
12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_DIFFER_H_ | |
13 | |
14 #include <memory> | |
15 #include <vector> | |
16 | |
17 #include "webrtc/base/constructormagic.h" | |
18 #include "webrtc/modules/desktop_capture/desktop_region.h" | |
19 | |
20 namespace webrtc { | |
21 | |
22 // TODO(sergeyu): Simplify differ now that we are working with DesktopRegion. | |
23 // diff_info_ should no longer be needed, as we can put our data directly into | |
24 // the region that we are calculating. | |
25 // http://crbug.com/92379 | |
26 // TODO(sergeyu): Rename this class to something more sensible, e.g. | |
27 // ScreenCaptureFrameDifferencer. | |
28 class Differ { | |
29 public: | |
30 // Create a differ that operates on bitmaps with the specified width, height | |
31 // and bytes_per_pixel. | |
32 Differ(int width, int height, int bytes_per_pixel, int stride); | |
33 ~Differ(); | |
34 | |
35 int width() { return width_; } | |
36 int height() { return height_; } | |
37 int bytes_per_pixel() { return bytes_per_pixel_; } | |
38 int bytes_per_row() { return bytes_per_row_; } | |
39 | |
40 // Given the previous and current screen buffer, calculate the dirty region | |
41 // that encloses all of the changed pixels in the new screen. | |
42 void CalcDirtyRegion(const uint8_t* prev_buffer, const uint8_t* curr_buffer, | |
43 DesktopRegion* region); | |
44 | |
45 private: | |
46 // Allow tests to access our private parts. | |
47 friend class DifferTest; | |
48 | |
49 // Identify all of the blocks that contain changed pixels. | |
50 void MarkDirtyBlocks(const uint8_t* prev_buffer, const uint8_t* curr_buffer); | |
51 | |
52 // After the dirty blocks have been identified, this routine merges adjacent | |
53 // blocks into a region. | |
54 // The goal is to minimize the region that covers the dirty blocks. | |
55 void MergeBlocks(DesktopRegion* region); | |
56 | |
57 // Checks whether the upper-left portions of the buffers are equal. The size | |
58 // of the portion to check is specified by the |width| and |height| values. | |
59 // Note that if we force the capturer to always return images whose width and | |
60 // height are multiples of kBlockSize, then this will never be called. | |
61 bool PartialBlocksEqual(const uint8_t* prev_buffer, | |
62 const uint8_t* curr_buffer, | |
63 int stride, | |
64 int width, int height); | |
65 | |
66 // Dimensions of screen. | |
67 int width_; | |
68 int height_; | |
69 | |
70 // Number of bytes for each pixel in source and dest bitmap. | |
71 // (Yes, they must match.) | |
72 int bytes_per_pixel_; | |
73 | |
74 // Number of bytes in each row of the image (AKA: stride). | |
75 int bytes_per_row_; | |
76 | |
77 // Diff information for each block in the image. | |
78 std::unique_ptr<bool[]> diff_info_; | |
79 | |
80 // Dimensions and total size of diff info array. | |
81 int diff_info_width_; | |
82 int diff_info_height_; | |
83 int diff_info_size_; | |
84 | |
85 RTC_DISALLOW_COPY_AND_ASSIGN(Differ); | |
86 }; | |
87 | |
88 } // namespace webrtc | |
89 | |
90 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_DIFFER_H_ | |
OLD | NEW |