OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef REMOTING_HOST_VIDEO_FRAME_CAPTURER_HELPER_H_ |
| 6 #define REMOTING_HOST_VIDEO_FRAME_CAPTURER_HELPER_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/synchronization/lock.h" |
| 11 #include "third_party/skia/include/core/SkRegion.h" |
| 12 |
| 13 namespace remoting { |
| 14 |
| 15 // VideoFrameCapturerHelper is intended to be used by an implementation of the |
| 16 // VideoFrameCapturer interface. It maintains a thread-safe invalid region, and |
| 17 // the size of the most recently captured screen, on behalf of the |
| 18 // VideoFrameCapturer that owns it. |
| 19 class VideoFrameCapturerHelper { |
| 20 public: |
| 21 VideoFrameCapturerHelper(); |
| 22 ~VideoFrameCapturerHelper(); |
| 23 |
| 24 // Clear out the invalid region. |
| 25 void ClearInvalidRegion(); |
| 26 |
| 27 // Invalidate the specified region. |
| 28 void InvalidateRegion(const SkRegion& invalid_region); |
| 29 |
| 30 // Invalidate the entire screen, of a given size. |
| 31 void InvalidateScreen(const SkISize& size); |
| 32 |
| 33 // Invalidate the entire screen, using the size of the most recently |
| 34 // captured screen. |
| 35 void InvalidateFullScreen(); |
| 36 |
| 37 // Swap the given region with the stored invalid region. |
| 38 void SwapInvalidRegion(SkRegion* invalid_region); |
| 39 |
| 40 // Access the size of the most recently captured screen. |
| 41 const SkISize& size_most_recent() const; |
| 42 void set_size_most_recent(const SkISize& size); |
| 43 |
| 44 // 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 |
| 46 // be changed in the compressed output. So we need to re-render an entire |
| 47 // block whenever part of the block changes. |
| 48 // |
| 49 // If |log_grid_size| is >= 1, then this function makes SwapInvalidRegion |
| 50 // 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 |
| 52 // of the most recently captured screen, as previously set by |
| 53 // set_size_most_recent(). |
| 54 // If |log_grid_size| is <= 0, then the invalid region is not expanded. |
| 55 void SetLogGridSize(int log_grid_size); |
| 56 |
| 57 // 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. |
| 59 static scoped_ptr<SkRegion> ExpandToGrid(const SkRegion& region, |
| 60 int log_grid_size); |
| 61 |
| 62 private: |
| 63 // A region that has been manually invalidated (through InvalidateRegion). |
| 64 // These will be returned as dirty_region in the capture data during the next |
| 65 // capture. |
| 66 SkRegion invalid_region_; |
| 67 |
| 68 // A lock protecting |invalid_region_| across threads. |
| 69 base::Lock invalid_region_lock_; |
| 70 |
| 71 // The size of the most recently captured screen. |
| 72 SkISize size_most_recent_; |
| 73 |
| 74 // The log (base 2) of the size of the grid to which the invalid region is |
| 75 // expanded. |
| 76 // If the value is <= 0, then the invalid region is not expanded to a grid. |
| 77 int log_grid_size_; |
| 78 |
| 79 DISALLOW_COPY_AND_ASSIGN(VideoFrameCapturerHelper); |
| 80 }; |
| 81 |
| 82 } // namespace remoting |
| 83 |
| 84 #endif // REMOTING_HOST_VIDEO_FRAME_CAPTURER_HELPER_H_ |
OLD | NEW |