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