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