OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/host/chromeos/aura_desktop_capturer.h" | 5 #include "remoting/host/chromeos/aura_screen_capturer.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "cc/output/copy_output_request.h" | 9 #include "cc/output/copy_output_request.h" |
10 #include "cc/output/copy_output_result.h" | 10 #include "cc/output/copy_output_result.h" |
11 #include "third_party/skia/include/core/SkBitmap.h" | 11 #include "third_party/skia/include/core/SkBitmap.h" |
12 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 12 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
13 #include "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
14 #include "ui/aura/window_tree_host.h" | 14 #include "ui/aura/window_tree_host.h" |
15 | 15 |
(...skipping 17 matching lines...) Expand all Loading... | |
33 scoped_ptr<SkBitmap> bitmap_; | 33 scoped_ptr<SkBitmap> bitmap_; |
34 | 34 |
35 DISALLOW_COPY_AND_ASSIGN(SkiaBitmapDesktopFrame); | 35 DISALLOW_COPY_AND_ASSIGN(SkiaBitmapDesktopFrame); |
36 }; | 36 }; |
37 | 37 |
38 // static | 38 // static |
39 SkiaBitmapDesktopFrame* SkiaBitmapDesktopFrame::Create( | 39 SkiaBitmapDesktopFrame* SkiaBitmapDesktopFrame::Create( |
40 scoped_ptr<SkBitmap> bitmap) { | 40 scoped_ptr<SkBitmap> bitmap) { |
41 | 41 |
42 webrtc::DesktopSize size(bitmap->width(), bitmap->height()); | 42 webrtc::DesktopSize size(bitmap->width(), bitmap->height()); |
43 DCHECK_EQ(kRGBA_8888_SkColorType, bitmap->info().colorType()) | 43 DCHECK_EQ(kBGRA_8888_SkColorType, bitmap->info().colorType()) |
44 << "DesktopFrame objects always hold RGBA data."; | 44 << "DesktopFrame objects always hold BGRA data."; |
45 | 45 |
46 uint8_t* bitmap_data = reinterpret_cast<uint8_t*>(bitmap->getPixels()); | 46 uint8_t* bitmap_data = reinterpret_cast<uint8_t*>(bitmap->getPixels()); |
47 | 47 |
48 SkiaBitmapDesktopFrame* result = new SkiaBitmapDesktopFrame( | 48 SkiaBitmapDesktopFrame* result = new SkiaBitmapDesktopFrame( |
49 size, bitmap->rowBytes(), bitmap_data, bitmap.Pass()); | 49 size, bitmap->rowBytes(), bitmap_data, bitmap.Pass()); |
50 | 50 |
51 return result; | 51 return result; |
52 } | 52 } |
53 | 53 |
54 SkiaBitmapDesktopFrame::SkiaBitmapDesktopFrame(webrtc::DesktopSize size, | 54 SkiaBitmapDesktopFrame::SkiaBitmapDesktopFrame(webrtc::DesktopSize size, |
55 int stride, | 55 int stride, |
56 uint8_t* data, | 56 uint8_t* data, |
57 scoped_ptr<SkBitmap> bitmap) | 57 scoped_ptr<SkBitmap> bitmap) |
58 : DesktopFrame(size, stride, data, NULL), bitmap_(bitmap.Pass()) { | 58 : DesktopFrame(size, stride, data, NULL), bitmap_(bitmap.Pass()) { |
59 } | 59 } |
60 | 60 |
61 SkiaBitmapDesktopFrame::~SkiaBitmapDesktopFrame() { | 61 SkiaBitmapDesktopFrame::~SkiaBitmapDesktopFrame() { |
62 } | 62 } |
63 | 63 |
64 } // namespace | 64 } // namespace |
65 | 65 |
66 AuraDesktopCapturer::AuraDesktopCapturer() | 66 AuraScreenCapturer::AuraScreenCapturer() |
67 : callback_(NULL), desktop_window_(NULL), weak_factory_(this) { | 67 : callback_(NULL), desktop_window_(NULL), weak_factory_(this) { |
68 } | 68 } |
69 | 69 |
70 AuraDesktopCapturer::~AuraDesktopCapturer() { | 70 AuraScreenCapturer::~AuraScreenCapturer() { |
71 } | 71 } |
72 | 72 |
73 void AuraDesktopCapturer::Start(webrtc::DesktopCapturer::Callback* callback) { | 73 void AuraScreenCapturer::Start(webrtc::DesktopCapturer::Callback* callback) { |
74 if (ash::Shell::HasInstance()) { | 74 if (ash::Shell::HasInstance()) { |
75 // TODO(kelvinp): Use ash::Shell::GetAllRootWindows() when multiple monitor | 75 // TODO(kelvinp): Use ash::Shell::GetAllRootWindows() when multiple monitor |
76 // support is implemented. | 76 // support is implemented. |
77 desktop_window_ = ash::Shell::GetPrimaryRootWindow(); | 77 desktop_window_ = ash::Shell::GetPrimaryRootWindow(); |
78 DCHECK(desktop_window_) << "Failed to retrieve the Aura Shell root window"; | 78 DCHECK(desktop_window_) << "Failed to retrieve the Aura Shell root window"; |
79 } | 79 } |
80 | 80 |
81 DCHECK(!callback_) << "Start() can only be called once"; | 81 DCHECK(!callback_) << "Start() can only be called once"; |
82 callback_ = callback; | 82 callback_ = callback; |
83 DCHECK(callback_); | 83 DCHECK(callback_); |
84 } | 84 } |
85 | 85 |
86 void AuraDesktopCapturer::Capture(const webrtc::DesktopRegion&) { | 86 void AuraScreenCapturer::Capture(const webrtc::DesktopRegion&) { |
87 scoped_ptr<cc::CopyOutputRequest> request = | 87 scoped_ptr<cc::CopyOutputRequest> request = |
88 cc::CopyOutputRequest::CreateBitmapRequest( | 88 cc::CopyOutputRequest::CreateBitmapRequest( |
89 base::Bind( | 89 base::Bind( |
90 &AuraDesktopCapturer::OnFrameCaptured, | 90 &AuraScreenCapturer::OnFrameCaptured, |
91 weak_factory_.GetWeakPtr())); | 91 weak_factory_.GetWeakPtr())); |
92 | 92 |
93 gfx::Rect window_rect(desktop_window_->bounds().size()); | 93 gfx::Rect window_rect(desktop_window_->bounds().size()); |
94 | 94 |
95 request->set_area(window_rect); | 95 request->set_area(window_rect); |
96 desktop_window_->layer()->RequestCopyOfOutput(request.Pass()); | 96 desktop_window_->layer()->RequestCopyOfOutput(request.Pass()); |
97 } | 97 } |
98 | 98 |
99 void AuraDesktopCapturer::OnFrameCaptured( | 99 void AuraScreenCapturer::OnFrameCaptured( |
100 scoped_ptr<cc::CopyOutputResult> result) { | 100 scoped_ptr<cc::CopyOutputResult> result) { |
101 DCHECK(result->HasBitmap()); | 101 DCHECK(result->HasBitmap()); |
102 | 102 |
103 scoped_ptr<SkBitmap> bitmap = result->TakeBitmap(); | 103 scoped_ptr<SkBitmap> bitmap = result->TakeBitmap(); |
104 | 104 |
105 scoped_ptr<webrtc::DesktopFrame> frame( | 105 scoped_ptr<webrtc::DesktopFrame> frame( |
106 SkiaBitmapDesktopFrame::Create(bitmap.Pass())); | 106 SkiaBitmapDesktopFrame::Create(bitmap.Pass())); |
107 | 107 |
108 // |VideoScheduler| will not encode the frame if |updated_region| is empty. | 108 // |VideoScheduler| will not encode the frame if |updated_region| is empty. |
109 const webrtc::DesktopRect& rect = webrtc::DesktopRect::MakeWH( | 109 const webrtc::DesktopRect& rect = webrtc::DesktopRect::MakeWH( |
110 frame->size().width(), frame->size().height()); | 110 frame->size().width(), frame->size().height()); |
111 | 111 |
112 // TODO(kelvinp): Set Frame DPI according to the screen resolution. | 112 // TODO(kelvinp): Set Frame DPI according to the screen resolution. |
113 // See cc::Layer::contents_scale_(x|y)() and frame->set_depi(). | 113 // See cc::Layer::contents_scale_(x|y)() and frame->set_depi(). |
114 frame->mutable_updated_region()->SetRect(rect); | 114 frame->mutable_updated_region()->SetRect(rect); |
115 | 115 |
116 callback_->OnCaptureCompleted(frame.release()); | 116 callback_->OnCaptureCompleted(frame.release()); |
117 } | 117 } |
118 | 118 |
119 bool AuraScreenCapturer::GetScreenList(ScreenList* screens) { | |
120 // Multiple monitors capturing are not supported on ChromeOS. | |
Wez
2014/10/24 00:28:47
nit: Multi-monitor capturing is not supported yet.
kelvinp
2014/10/24 21:39:41
Revert to AuraDesktopCapturer
| |
121 NOTIMPLEMENTED(); | |
122 return false; | |
123 } | |
124 | |
125 bool AuraScreenCapturer::SelectScreen(webrtc::ScreenId id) { | |
126 // Multiple monitors capturing are not supported on ChromeOS. | |
127 NOTIMPLEMENTED(); | |
128 return false; | |
129 }; | |
130 | |
119 } // namespace remoting | 131 } // namespace remoting |
132 | |
133 namespace webrtc { | |
134 | |
135 // static | |
136 ScreenCapturer* ScreenCapturer::Create(const DesktopCaptureOptions& options) { | |
137 return new remoting::AuraScreenCapturer(); | |
138 } | |
139 | |
140 } // namespace webrtc | |
OLD | NEW |