Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(134)

Side by Side Diff: remoting/host/chromeos/aura_desktop_capturer.cc

Issue 543243003: Remote Assistance on Chrome OS Part I - Aura Desktop Capturer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Reed's feedback Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #include "remoting/host/chromeos/aura_desktop_capturer.h"
6
7 #include "ash/shell.h"
8 #include "base/bind.h"
9 #include "cc/output/copy_output_request.h"
10 #include "cc/output/copy_output_result.h"
11 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"
13 #include "ui/aura/window_tree_host.h"
14
15 namespace remoting {
16
17 namespace {
18
19 // DesktopFrame implementation used by screen capture on ChromeOS.
20 // Frame data is stored in a SkBitmap.
21 class SkiaBitmapDesktopFrame : public webrtc::DesktopFrame {
22 public:
23 static SkiaBitmapDesktopFrame* Create(scoped_ptr<SkBitmap> bitmap);
24 virtual ~SkiaBitmapDesktopFrame();
25
26 private:
27 SkiaBitmapDesktopFrame(webrtc::DesktopSize size,
28 int stride,
29 uint8_t* data,
30 scoped_ptr<SkBitmap> bitmap);
31
32 scoped_ptr<SkBitmap> bitmap_;
33
34 DISALLOW_COPY_AND_ASSIGN(SkiaBitmapDesktopFrame);
35 };
36
37 // static
38 SkiaBitmapDesktopFrame* SkiaBitmapDesktopFrame::Create(
39 scoped_ptr<SkBitmap> bitmap) {
40
41 webrtc::DesktopSize size(bitmap->width(), bitmap->height());
42 DCHECK_EQ(kRGBA_8888_SkColorType, bitmap->info().colorType())
43 << "DesktopFrame objects always hold RGBA data.";
44
45 uint8_t* bitmap_data = reinterpret_cast<uint8_t*>(bitmap->getPixels());
46
47 SkiaBitmapDesktopFrame* result = new SkiaBitmapDesktopFrame(
48 size, bitmap->rowBytes(), bitmap_data, bitmap.Pass());
49
50 return result;
51 }
52
53 SkiaBitmapDesktopFrame::SkiaBitmapDesktopFrame(webrtc::DesktopSize size,
54 int stride,
55 uint8_t* data,
56 scoped_ptr<SkBitmap> bitmap)
57 : DesktopFrame(size, stride, data, NULL), bitmap_(bitmap.Pass()) {
58 }
59
60 SkiaBitmapDesktopFrame::~SkiaBitmapDesktopFrame() {
61 }
62
63 } // namespace
64
65 AuraDesktopCapturer::AuraDesktopCapturer()
66 : callback_(NULL), desktop_window_(NULL), weak_factory_(this) {
67 }
68
69 AuraDesktopCapturer::~AuraDesktopCapturer() {
70 }
71
72 void AuraDesktopCapturer::Start(webrtc::DesktopCapturer::Callback* callback) {
73 if (ash::Shell::HasInstance()) {
74 desktop_window_ = ash::Shell::GetPrimaryRootWindow();
75 DCHECK(desktop_window_) << "Failed to retrieve the Aura Shell root window";
76 }
77 callback_ = callback;
78 }
79
80 void AuraDesktopCapturer::Capture(const webrtc::DesktopRegion&) {
81 scoped_ptr<cc::CopyOutputRequest> request =
82 cc::CopyOutputRequest::CreateBitmapRequest(
83 base::Bind(
84 &AuraDesktopCapturer::OnFrameCaptured,
85 weak_factory_.GetWeakPtr()));
86
87 int width = desktop_window_->bounds().width();
88 int height = desktop_window_->bounds().height();
89 gfx::Rect window_rect = gfx::Rect(width, height);
90
91 request->set_area(window_rect);
sky 2014/09/11 21:22:47 It seems like set_area only needs a size, should i
kelvinp 2014/09/11 22:27:51 Done.
92 desktop_window_->layer()->RequestCopyOfOutput(request.Pass());
93 }
94
95 void AuraDesktopCapturer::OnFrameCaptured(
96 scoped_ptr<cc::CopyOutputResult> result) {
97 DCHECK(result->HasBitmap());
98
99 scoped_ptr<SkBitmap> bitmap = result->TakeBitmap();
100
101 scoped_ptr<webrtc::DesktopFrame> frame(
102 SkiaBitmapDesktopFrame::Create(bitmap.Pass()));
103
104 // |VideoScheduler| will not encode the frame if |updated_region| is empty.
105 const webrtc::DesktopRect& rect = webrtc::DesktopRect::MakeWH(
106 frame->size().width(), frame->size().height());
107
108 // TODO(kelvinp): Set Frame DPI according to the screen resolution.
109 // See cc::Layer::contents_scale_(x|y)() and frame->set_depi().
110 frame->mutable_updated_region()->SetRect(rect);
111
112 callback_->OnCaptureCompleted(frame.release());
sky 2014/09/11 21:22:47 Might callback_ be NULL here? Also, what happens i
kelvinp 2014/09/11 22:27:51 Callback may not be NULL here. As Start() must be
113 }
114
115 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698