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

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 wez'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 int width = bitmap->width();
42 int height = bitmap->height();
43
44 webrtc::DesktopSize size(width, height);
Sergey Ulanov 2014/09/10 23:08:52 nit: size(bitmap->width(), bitmap->height()) and r
45
46 DCHECK_EQ(4, bitmap->bytesPerPixel())
47 << "DesktopFrame objects always hold RGBA data.";
48
49 uint8_t* bitmap_data = reinterpret_cast<uint8_t*>(bitmap->getPixels());
50
51 SkiaBitmapDesktopFrame* result = new SkiaBitmapDesktopFrame(
52 size, bitmap->rowBytes(), bitmap_data, bitmap.Pass());
53
54 return result;
55 }
56
57 SkiaBitmapDesktopFrame::SkiaBitmapDesktopFrame(webrtc::DesktopSize size,
58 int stride,
59 uint8_t* data,
60 scoped_ptr<SkBitmap> bitmap)
61 : DesktopFrame(size, stride, data, NULL), bitmap_(bitmap.Pass()) {
62 }
63
64 SkiaBitmapDesktopFrame::~SkiaBitmapDesktopFrame() {
65 }
66
67 } // namespace
68
69 AuraDesktopCapturer::AuraDesktopCapturer()
70 : callback_(NULL), desktop_window_(NULL), weak_factory_(this) {
71 }
72
73 AuraDesktopCapturer::~AuraDesktopCapturer() {
74 }
75
76 void AuraDesktopCapturer::Start(webrtc::DesktopCapturer::Callback* callback) {
77 if (ash::Shell::HasInstance()) {
78 desktop_window_ = ash::Shell::GetPrimaryRootWindow();
79 DCHECK(desktop_window_) << "Failed to retrieve the Aura Shell root window";
80 }
81 callback_ = callback;
82 }
83
84 void AuraDesktopCapturer::Capture(const webrtc::DesktopRegion&) {
85 scoped_ptr<cc::CopyOutputRequest> request =
86 cc::CopyOutputRequest::CreateBitmapRequest(
87 base::Bind(
88 &AuraDesktopCapturer::OnFrameCaptured,
89 weak_factory_.GetWeakPtr()));
90
91 int width = desktop_window_->bounds().width();
92 int height = desktop_window_->bounds().height();
93 gfx::Rect window_rect = gfx::Rect(width, height);
94
95 request->set_area(window_rect);
96 desktop_window_->layer()->RequestCopyOfOutput(request.Pass());
97 }
98
99 void AuraDesktopCapturer::SetExcludedWindow(webrtc::WindowId window) {
100 NOTIMPLEMENTED();
101 }
102
103 void AuraDesktopCapturer::OnFrameCaptured(
104 scoped_ptr<cc::CopyOutputResult> result) {
105 DCHECK(result->HasBitmap());
106
107 scoped_ptr<SkBitmap> bitmap = result->TakeBitmap();
108
109 scoped_ptr<webrtc::DesktopFrame> frame(
110 SkiaBitmapDesktopFrame::Create(bitmap.Pass()));
111
112 // |VideoScheduler| will not encode the frame if |updated_region| is empty.
113 const webrtc::DesktopRect& rect = webrtc::DesktopRect::MakeWH(
114 frame->size().width(), frame->size().height());
115 frame->mutable_updated_region()->SetRect(rect);
Sergey Ulanov 2014/09/10 23:08:52 I think we also need to set frame DPI according to
116
117 callback_->OnCaptureCompleted(frame.release());
118 }
119
120 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698