Chromium Code Reviews| 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..a3b5647e8b5ff2a4d7d6cd694166254febfc0313 |
| --- /dev/null |
| +++ b/remoting/host/chromeos/aura_desktop_capturer.cc |
| @@ -0,0 +1,120 @@ |
| +// 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) { |
| + |
| + int width = bitmap->width(); |
| + int height = bitmap->height(); |
| + |
| + webrtc::DesktopSize size(width, height); |
|
Sergey Ulanov
2014/09/10 23:08:52
nit: size(bitmap->width(), bitmap->height()) and r
|
| + |
| + 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(); |
| + 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::SetExcludedWindow(webrtc::WindowId window) { |
| + NOTIMPLEMENTED(); |
| +} |
| + |
| +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()); |
| + 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
|
| + |
| + callback_->OnCaptureCompleted(frame.release()); |
| +} |
| + |
| +} // namespace remoting |