Index: remoting/host/chromeos/aura_desktop_capturer.cc |
diff --git a/remoting/host/chromeos/aura_desktop_capturer.cc b/remoting/host/chromeos/aura_desktop_capturer.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..e81625197ee108c7de623ab11db5ff44d57ccd8a |
--- /dev/null |
+++ b/remoting/host/chromeos/aura_desktop_capturer.cc |
@@ -0,0 +1,75 @@ |
+// Copyright 2014 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/chromeos/aura_desktop_capturer.h" |
+ |
+#include "ash/shell.h" |
+#include "base/bind.h" |
+#include "cc/output/copy_output_request.h" |
+#include "cc/output/copy_output_result.h" |
+#include "third_party/skia/include/core/SkBitmap.h" |
+#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
+#include "ui/aura/window_tree_host.h" |
+#include "ui/gfx/screen.h" |
+ |
+namespace remoting { |
+ |
+AuraDesktopCapturer::AuraDesktopCapturer() |
+ : callback_(NULL), desktop_window_(NULL), weak_factory_(this) { |
+} |
+ |
+AuraDesktopCapturer::~AuraDesktopCapturer() { |
+} |
+ |
+void AuraDesktopCapturer::Start(webrtc::DesktopCapturer::Callback* callback) { |
+ desktop_window_ = ash::Shell::GetPrimaryRootWindow(); |
+ DCHECK(desktop_window_) << "Failed to retrieve the Aura Shell root window"; |
+ callback_ = callback; |
+} |
+ |
+void AuraDesktopCapturer::Capture(const webrtc::DesktopRegion&) { |
+ scoped_ptr<cc::CopyOutputRequest> request = |
+ cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( |
+ &AuraDesktopCapturer::OnFrameCaptured, weak_factory_.GetWeakPtr())); |
+ |
+ int width = desktop_window_->bounds().width(); |
+ int height = desktop_window_->bounds().height(); |
+ gfx::Rect window_rect = gfx::Rect(width, height); |
+ |
+ request->set_area(window_rect); |
+ DCHECK(desktop_window_); |
+ desktop_window_->layer()->RequestCopyOfOutput(request.Pass()); |
+} |
+ |
+void AuraDesktopCapturer::OnFrameCaptured( |
+ scoped_ptr<cc::CopyOutputResult> result) { |
+ DCHECK(result->HasBitmap()); |
+ |
+ scoped_ptr<SkBitmap> bitmap = result->TakeBitmap(); |
+ |
+ int width = bitmap->width(); |
+ int height = bitmap->height(); |
+ |
+ webrtc::DesktopSize size(width, height); |
+ scoped_ptr<webrtc::DesktopFrame> frame(new webrtc::BasicDesktopFrame(size)); |
+ |
+ DCHECK(bitmap->bytesPerPixel() == 4) |
+ << "DesktopFrame objects always hold RGBA data."; |
+ DCHECK(static_cast<int>(bitmap->rowBytes()) == frame->stride()); |
+ |
+ uint8_t* bitmapData = reinterpret_cast<uint8_t*>(bitmap->getPixels()); |
Sergey Ulanov
2014/09/06 02:03:25
bitmap_data
kelvinp
2014/09/09 21:19:46
Done.
|
+ |
+ bitmap->lockPixels(); |
+ const webrtc::DesktopRect& rect = webrtc::DesktopRect::MakeWH(width, height); |
+ frame->CopyPixelsFrom(bitmapData, bitmap->rowBytes(), rect); |
Sergey Ulanov
2014/09/06 02:03:25
Ideally we want to avoid copying pixels. You can a
kelvinp
2014/09/09 21:19:46
Done.
|
+ bitmap->unlockPixels(); |
+ |
+ // |VideoScheduler| always checks |updated_region| is not empty before |
+ // encoding a given frame. |
+ frame->mutable_updated_region()->SetRect(rect); |
+ |
+ callback_->OnCaptureCompleted(frame.release()); |
+} |
+ |
+} // namespace remoting |