summaryrefslogtreecommitdiffstats
path: root/remoting/host/capturer_helper.h
blob: 36968a1580b2fae57597506e45235c3e403bf43e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef REMOTING_HOST_CAPTURER_HELPER_H_
#define REMOTING_HOST_CAPTURER_HELPER_H_

#include "base/synchronization/lock.h"
#include "third_party/skia/include/core/SkRegion.h"
#include "ui/gfx/size.h"

namespace remoting {

// CapturerHelper is intended to be used by an implementation of the Capturer
// interface. It maintains a thread-safe invalid region, and the size of the
// most recently captured screen, on behalf of the Capturer that owns it.
class CapturerHelper {
 public:
  CapturerHelper();
  ~CapturerHelper();

  // Clear out the invalid region.
  void ClearInvalidRegion();

  // Invalidate the specified region.
  void InvalidateRegion(const SkRegion& invalid_region);

  // Invalidate the entire screen, of a given size.
  void InvalidateScreen(const gfx::Size& size);

  // Invalidate the entire screen, using the size of the most recently
  // captured screen.
  void InvalidateFullScreen();

  // Whether the invalid region is a full screen of a given size.
  bool IsCaptureFullScreen(const gfx::Size& size);

  // Swap the given region with the stored invalid region.
  void SwapInvalidRegion(SkRegion* invalid_region);

  // Access the size of the most recently captured screen.
  const gfx::Size& size_most_recent() const;
  void set_size_most_recent(const gfx::Size& size);

 private:
  // A region that has been manually invalidated (through InvalidateRegion).
  // These will be returned as dirty_region in the capture data during the next
  // capture.
  SkRegion invalid_region_;

  // A lock protecting |invalid_region_| across threads.
  base::Lock invalid_region_lock_;

  // The size of the most recently captured screen.
  gfx::Size size_most_recent_;

  DISALLOW_COPY_AND_ASSIGN(CapturerHelper);
};

}  // namespace remoting

#endif  // REMOTING_HOST_CAPTURER_HELPER_H_