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