summaryrefslogtreecommitdiffstats
path: root/remoting/host/capturer.cc
blob: cf1bac75638032f1c8e524c75756285abdd4cacd (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Copyright (c) 2010 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.

#include "remoting/host/capturer.h"

#include <algorithm>

#include "remoting/base/tracer.h"

namespace remoting {

Capturer::Capturer(MessageLoop* message_loop)
    : width_(0),
      height_(0),
      pixel_format_(media::VideoFrame::INVALID),
      bytes_per_row_(0),
      current_buffer_(0),
      message_loop_(message_loop) {
}

Capturer::~Capturer() {
}

// Return the width of the screen.
int Capturer::width() const {
  return width_;
}

// Return the height of the screen.
int Capturer::height() const {
  return height_;
}

// Return the pixel format of the screen.
media::VideoFrame::Format Capturer::pixel_format() const {
  return pixel_format_;
}

void Capturer::ClearInvalidRects() {
  base::AutoLock auto_inval_rects_lock(inval_rects_lock_);
  inval_rects_.clear();
}

void Capturer::InvalidateRects(const InvalidRects& inval_rects) {
  InvalidRects temp_rects;
  std::set_union(inval_rects_.begin(), inval_rects_.end(),
                 inval_rects.begin(), inval_rects.end(),
                 std::inserter(temp_rects, temp_rects.begin()));
  {
    base::AutoLock auto_inval_rects_lock(inval_rects_lock_);
    inval_rects_.swap(temp_rects);
  }
}

void Capturer::InvalidateFullScreen() {
  base::AutoLock auto_inval_rects_lock(inval_rects_lock_);
  inval_rects_.clear();
  inval_rects_.insert(gfx::Rect(0, 0, width_, height_));
}

void Capturer::CaptureInvalidRects(CaptureCompletedCallback* callback) {
  // Calculate which rects need to be captured.
  TraceContext::tracer()->PrintString("Started CalculateInvalidRects");
  CalculateInvalidRects();
  TraceContext::tracer()->PrintString("Done CalculateInvalidRects");

  // Braced to scope the lock.
  InvalidRects local_rects;
  {
    base::AutoLock auto_inval_rects_lock(inval_rects_lock_);
    local_rects.swap(inval_rects_);
  }

  TraceContext::tracer()->PrintString("Start CaptureRects");
  CaptureRects(local_rects, callback);
}

void Capturer::FinishCapture(scoped_refptr<CaptureData> data,
                             CaptureCompletedCallback* callback) {
  // Select the next buffer to be the current buffer.
  current_buffer_ = (current_buffer_ + 1) % kNumBuffers;

  callback->Run(data);
  delete callback;
}

}  // namespace remoting