Roll src/third_party/WebKit f36d5e0:68b67cd (svn 193299:193303)
[chromium-blink-merge.git] / remoting / host / chromeos / aura_desktop_capturer.cc
blobd996a976585eb5b48058e4ebfa554c01319b9cf3
1 // Copyright 2014 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.
5 #include "remoting/host/chromeos/aura_desktop_capturer.h"
7 #include "base/bind.h"
8 #include "cc/output/copy_output_request.h"
9 #include "cc/output/copy_output_result.h"
10 #include "remoting/host/chromeos/skia_bitmap_desktop_frame.h"
11 #include "ui/aura/window.h"
12 #include "ui/aura/window_tree_host.h"
14 #if defined(USE_ASH)
15 #include "ash/shell.h"
16 #endif
18 namespace remoting {
20 AuraDesktopCapturer::AuraDesktopCapturer()
21 : callback_(nullptr), desktop_window_(nullptr), weak_factory_(this) {
24 AuraDesktopCapturer::~AuraDesktopCapturer() {
27 void AuraDesktopCapturer::Start(webrtc::DesktopCapturer::Callback* callback) {
28 #if defined(USE_ASH)
29 if (ash::Shell::HasInstance()) {
30 // TODO(kelvinp): Use ash::Shell::GetAllRootWindows() when multiple monitor
31 // support is implemented.
32 desktop_window_ = ash::Shell::GetPrimaryRootWindow();
33 DCHECK(desktop_window_) << "Failed to retrieve the Aura Shell root window";
35 #endif
37 DCHECK(!callback_) << "Start() can only be called once";
38 callback_ = callback;
39 DCHECK(callback_);
42 void AuraDesktopCapturer::Capture(const webrtc::DesktopRegion&) {
43 scoped_ptr<cc::CopyOutputRequest> request =
44 cc::CopyOutputRequest::CreateBitmapRequest(
45 base::Bind(
46 &AuraDesktopCapturer::OnFrameCaptured,
47 weak_factory_.GetWeakPtr()));
49 gfx::Rect window_rect(desktop_window_->bounds().size());
51 request->set_area(window_rect);
52 desktop_window_->layer()->RequestCopyOfOutput(request.Pass());
55 void AuraDesktopCapturer::OnFrameCaptured(
56 scoped_ptr<cc::CopyOutputResult> result) {
57 DCHECK(result->HasBitmap());
59 scoped_ptr<SkBitmap> bitmap = result->TakeBitmap();
61 scoped_ptr<webrtc::DesktopFrame> frame(
62 SkiaBitmapDesktopFrame::Create(bitmap.Pass()));
64 // |VideoFramePump| will not encode the frame if |updated_region| is empty.
65 const webrtc::DesktopRect& rect = webrtc::DesktopRect::MakeWH(
66 frame->size().width(), frame->size().height());
68 // TODO(kelvinp): Set Frame DPI according to the screen resolution.
69 // See cc::Layer::contents_scale_(x|y)() and frame->set_depi().
70 frame->mutable_updated_region()->SetRect(rect);
72 callback_->OnCaptureCompleted(frame.release());
75 } // namespace remoting