Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 #include "ui/gfx/screen.h" | |
| 15 | |
| 16 namespace remoting { | |
| 17 | |
| 18 AuraDesktopCapturer::AuraDesktopCapturer() | |
| 19 : callback_(NULL), desktop_window_(NULL), weak_factory_(this) { | |
| 20 } | |
| 21 | |
| 22 AuraDesktopCapturer::~AuraDesktopCapturer() { | |
| 23 } | |
| 24 | |
| 25 void AuraDesktopCapturer::Start(webrtc::DesktopCapturer::Callback* callback) { | |
| 26 desktop_window_ = ash::Shell::GetPrimaryRootWindow(); | |
| 27 DCHECK(desktop_window_) << "Failed to retrieve the Aura Shell root window"; | |
| 28 callback_ = callback; | |
| 29 } | |
| 30 | |
| 31 void AuraDesktopCapturer::Capture(const webrtc::DesktopRegion&) { | |
| 32 scoped_ptr<cc::CopyOutputRequest> request = | |
| 33 cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( | |
| 34 &AuraDesktopCapturer::OnFrameCaptured, weak_factory_.GetWeakPtr())); | |
| 35 | |
| 36 int width = desktop_window_->bounds().width(); | |
| 37 int height = desktop_window_->bounds().height(); | |
| 38 gfx::Rect window_rect = gfx::Rect(width, height); | |
| 39 | |
| 40 request->set_area(window_rect); | |
| 41 DCHECK(desktop_window_); | |
| 42 desktop_window_->layer()->RequestCopyOfOutput(request.Pass()); | |
| 43 } | |
| 44 | |
| 45 void AuraDesktopCapturer::OnFrameCaptured( | |
| 46 scoped_ptr<cc::CopyOutputResult> result) { | |
| 47 DCHECK(result->HasBitmap()); | |
| 48 | |
| 49 scoped_ptr<SkBitmap> bitmap = result->TakeBitmap(); | |
| 50 | |
| 51 int width = bitmap->width(); | |
| 52 int height = bitmap->height(); | |
| 53 | |
| 54 webrtc::DesktopSize size(width, height); | |
| 55 scoped_ptr<webrtc::DesktopFrame> frame(new webrtc::BasicDesktopFrame(size)); | |
| 56 | |
| 57 DCHECK(bitmap->bytesPerPixel() == 4) | |
| 58 << "DesktopFrame objects always hold RGBA data."; | |
| 59 DCHECK(static_cast<int>(bitmap->rowBytes()) == frame->stride()); | |
| 60 | |
| 61 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.
| |
| 62 | |
| 63 bitmap->lockPixels(); | |
| 64 const webrtc::DesktopRect& rect = webrtc::DesktopRect::MakeWH(width, height); | |
| 65 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.
| |
| 66 bitmap->unlockPixels(); | |
| 67 | |
| 68 // |VideoScheduler| always checks |updated_region| is not empty before | |
| 69 // encoding a given frame. | |
| 70 frame->mutable_updated_region()->SetRect(rect); | |
| 71 | |
| 72 callback_->OnCaptureCompleted(frame.release()); | |
| 73 } | |
| 74 | |
| 75 } // namespace remoting | |
| OLD | NEW |