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_SCREEN_CAPTURER_HELPER_H_ 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_HELPER_H_ 13 14 #include "webrtc/modules/desktop_capture/desktop_geometry.h" 15 #include "webrtc/modules/desktop_capture/desktop_region.h" 16 #include "webrtc/system_wrappers/interface/rw_lock_wrapper.h" 17 #include "webrtc/system_wrappers/interface/scoped_ptr.h" 18 19 namespace webrtc { 20 21 // ScreenCapturerHelper is intended to be used by an implementation of the 22 // ScreenCapturer interface. It maintains a thread-safe invalid region, and 23 // the size of the most recently captured screen, on behalf of the 24 // ScreenCapturer that owns it. 25 class ScreenCapturerHelper { 26 public: 27 ScreenCapturerHelper(); 28 ~ScreenCapturerHelper(); 29 30 // Clear out the invalid region. 31 void ClearInvalidRegion(); 32 33 // Invalidate the specified region. 34 void InvalidateRegion(const DesktopRegion& invalid_region); 35 36 // Invalidate the entire screen, of a given size. 37 void InvalidateScreen(const DesktopSize& size); 38 39 // Copies current invalid region to |invalid_region| clears invalid region 40 // storage for the next frame. 41 void TakeInvalidRegion(DesktopRegion* invalid_region); 42 43 // Access the size of the most recently captured screen. 44 const DesktopSize& size_most_recent() const; 45 void set_size_most_recent(const DesktopSize& size); 46 47 // Lossy compression can result in color values leaking between pixels in one 48 // block. If part of a block changes, then unchanged parts of that block can 49 // be changed in the compressed output. So we need to re-render an entire 50 // block whenever part of the block changes. 51 // 52 // If |log_grid_size| is >= 1, then this function makes TakeInvalidRegion() 53 // produce an invalid region expanded so that its vertices lie on a grid of 54 // size 2 ^ |log_grid_size|. The expanded region is then clipped to the size 55 // of the most recently captured screen, as previously set by 56 // set_size_most_recent(). 57 // If |log_grid_size| is <= 0, then the invalid region is not expanded. 58 void SetLogGridSize(int log_grid_size); 59 60 // Expands a region so that its vertices all lie on a grid. 61 // The grid size must be >= 2, so |log_grid_size| must be >= 1. 62 static void ExpandToGrid(const DesktopRegion& region, 63 int log_grid_size, 64 DesktopRegion* result); 65 66 private: 67 // A region that has been manually invalidated (through InvalidateRegion). 68 // These will be returned as dirty_region in the capture data during the next 69 // capture. 70 DesktopRegion invalid_region_; 71 72 // A lock protecting |invalid_region_| across threads. 73 scoped_ptr<RWLockWrapper> invalid_region_lock_; 74 75 // The size of the most recently captured screen. 76 DesktopSize size_most_recent_; 77 78 // The log (base 2) of the size of the grid to which the invalid region is 79 // expanded. 80 // If the value is <= 0, then the invalid region is not expanded to a grid. 81 int log_grid_size_; 82 83 DISALLOW_COPY_AND_ASSIGN(ScreenCapturerHelper); 84 }; 85 86 } // namespace webrtc 87 88 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_SCREEN_CAPTURER_HELPER_H_ 89