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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
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..441644337373f281db22b093e04a1918ef13db01
--- /dev/null
+++ b/remoting/host/chromeos/aura_desktop_capturer.cc
@@ -0,0 +1,116 @@
+// 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"
+
+namespace remoting {
+
+namespace {
+
+// DesktopFrame implementation used by screen capture on ChromeOS.
+// Frame data is stored in a SkBitmap.
+class SkiaBitmapDesktopFrame : public webrtc::DesktopFrame {
+ public:
+ static SkiaBitmapDesktopFrame* Create(scoped_ptr<SkBitmap> bitmap);
+ virtual ~SkiaBitmapDesktopFrame();
+
+ private:
+ SkiaBitmapDesktopFrame(webrtc::DesktopSize size,
+ int stride,
+ uint8_t* data,
+ scoped_ptr<SkBitmap> bitmap);
+
+ scoped_ptr<SkBitmap> bitmap_;
+
+ DISALLOW_COPY_AND_ASSIGN(SkiaBitmapDesktopFrame);
+};
+
+// static
+SkiaBitmapDesktopFrame* SkiaBitmapDesktopFrame::Create(
+ scoped_ptr<SkBitmap> bitmap) {
+
+ webrtc::DesktopSize size(bitmap->width(), bitmap->height());
+
+ DCHECK_EQ(4, bitmap->bytesPerPixel())
+ << "DesktopFrame objects always hold RGBA data.";
+
+ uint8_t* bitmap_data = reinterpret_cast<uint8_t*>(bitmap->getPixels());
+
+ SkiaBitmapDesktopFrame* result = new SkiaBitmapDesktopFrame(
+ size, bitmap->rowBytes(), bitmap_data, bitmap.Pass());
+
+ return result;
+}
+
+SkiaBitmapDesktopFrame::SkiaBitmapDesktopFrame(webrtc::DesktopSize size,
+ int stride,
+ uint8_t* data,
+ scoped_ptr<SkBitmap> bitmap)
+ : DesktopFrame(size, stride, data, NULL), bitmap_(bitmap.Pass()) {
+}
+
+SkiaBitmapDesktopFrame::~SkiaBitmapDesktopFrame() {
+}
+
+} // namespace
+
+AuraDesktopCapturer::AuraDesktopCapturer()
+ : callback_(NULL), desktop_window_(NULL), weak_factory_(this) {
+}
+
+AuraDesktopCapturer::~AuraDesktopCapturer() {
+}
+
+void AuraDesktopCapturer::Start(webrtc::DesktopCapturer::Callback* callback) {
+ if (ash::Shell::HasInstance()) {
+ desktop_window_ = ash::Shell::GetPrimaryRootWindow();
sky 2014/09/11 19:34:24 Why are you using GetprimaryRootWindow and not the
kelvinp 2014/09/11 20:54:17 For remote assistance, I am trying to capture the
sky 2014/09/11 21:22:47 Add a TODO then.
+ 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);
+ desktop_window_->layer()->RequestCopyOfOutput(request.Pass());
+}
+
+void AuraDesktopCapturer::OnFrameCaptured(
+ scoped_ptr<cc::CopyOutputResult> result) {
+ DCHECK(result->HasBitmap());
+
+ scoped_ptr<SkBitmap> bitmap = result->TakeBitmap();
+
+ scoped_ptr<webrtc::DesktopFrame> frame(
+ SkiaBitmapDesktopFrame::Create(bitmap.Pass()));
+
+ // |VideoScheduler| will not encode the frame if |updated_region| is empty.
+ const webrtc::DesktopRect& rect = webrtc::DesktopRect::MakeWH(
+ frame->size().width(), frame->size().height());
+
+ // TODO(kelvinp): Set Frame DPI according to the screen resolution.
+ // See cc::Layer::contents_scale_(x|y)() and frame->set_depi().
+ frame->mutable_updated_region()->SetRect(rect);
+
+ callback_->OnCaptureCompleted(frame.release());
+}
+
+} // namespace remoting

Powered by Google App Engine
This is Rietveld 408576698