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 | |
| 15 namespace remoting { | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 // DesktopFrame implementation used by screen capture on ChromeOS. | |
| 20 // Frame data is stored in a SkBitmap. | |
| 21 class SkiaBitmapDesktopFrame : public webrtc::DesktopFrame { | |
| 22 public: | |
| 23 static SkiaBitmapDesktopFrame* Create(scoped_ptr<SkBitmap> bitmap); | |
| 24 virtual ~SkiaBitmapDesktopFrame(); | |
| 25 | |
| 26 private: | |
| 27 SkiaBitmapDesktopFrame(webrtc::DesktopSize size, | |
| 28 int stride, | |
| 29 uint8_t* data, | |
| 30 scoped_ptr<SkBitmap> bitmap); | |
| 31 | |
| 32 scoped_ptr<SkBitmap> bitmap_; | |
| 33 | |
| 34 DISALLOW_COPY_AND_ASSIGN(SkiaBitmapDesktopFrame); | |
| 35 }; | |
| 36 | |
| 37 // static | |
| 38 SkiaBitmapDesktopFrame* SkiaBitmapDesktopFrame::Create( | |
| 39 scoped_ptr<SkBitmap> bitmap) { | |
| 40 | |
| 41 webrtc::DesktopSize size(bitmap->width(), bitmap->height()); | |
| 42 | |
| 43 DCHECK_EQ(4, bitmap->bytesPerPixel()) | |
| 44 << "DesktopFrame objects always hold RGBA data."; | |
| 45 | |
| 46 uint8_t* bitmap_data = reinterpret_cast<uint8_t*>(bitmap->getPixels()); | |
| 47 | |
| 48 SkiaBitmapDesktopFrame* result = new SkiaBitmapDesktopFrame( | |
| 49 size, bitmap->rowBytes(), bitmap_data, bitmap.Pass()); | |
| 50 | |
| 51 return result; | |
| 52 } | |
| 53 | |
| 54 SkiaBitmapDesktopFrame::SkiaBitmapDesktopFrame(webrtc::DesktopSize size, | |
| 55 int stride, | |
| 56 uint8_t* data, | |
| 57 scoped_ptr<SkBitmap> bitmap) | |
| 58 : DesktopFrame(size, stride, data, NULL), bitmap_(bitmap.Pass()) { | |
| 59 } | |
| 60 | |
| 61 SkiaBitmapDesktopFrame::~SkiaBitmapDesktopFrame() { | |
| 62 } | |
| 63 | |
| 64 } // namespace | |
| 65 | |
| 66 AuraDesktopCapturer::AuraDesktopCapturer() | |
| 67 : callback_(NULL), desktop_window_(NULL), weak_factory_(this) { | |
| 68 } | |
| 69 | |
| 70 AuraDesktopCapturer::~AuraDesktopCapturer() { | |
| 71 } | |
| 72 | |
| 73 void AuraDesktopCapturer::Start(webrtc::DesktopCapturer::Callback* callback) { | |
| 74 if (ash::Shell::HasInstance()) { | |
| 75 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.
| |
| 76 DCHECK(desktop_window_) << "Failed to retrieve the Aura Shell root window"; | |
| 77 } | |
| 78 callback_ = callback; | |
| 79 } | |
| 80 | |
| 81 void AuraDesktopCapturer::Capture(const webrtc::DesktopRegion&) { | |
| 82 scoped_ptr<cc::CopyOutputRequest> request = | |
| 83 cc::CopyOutputRequest::CreateBitmapRequest( | |
| 84 base::Bind( | |
| 85 &AuraDesktopCapturer::OnFrameCaptured, | |
| 86 weak_factory_.GetWeakPtr())); | |
| 87 | |
| 88 int width = desktop_window_->bounds().width(); | |
| 89 int height = desktop_window_->bounds().height(); | |
| 90 gfx::Rect window_rect = gfx::Rect(width, height); | |
| 91 | |
| 92 request->set_area(window_rect); | |
| 93 desktop_window_->layer()->RequestCopyOfOutput(request.Pass()); | |
| 94 } | |
| 95 | |
| 96 void AuraDesktopCapturer::OnFrameCaptured( | |
| 97 scoped_ptr<cc::CopyOutputResult> result) { | |
| 98 DCHECK(result->HasBitmap()); | |
| 99 | |
| 100 scoped_ptr<SkBitmap> bitmap = result->TakeBitmap(); | |
| 101 | |
| 102 scoped_ptr<webrtc::DesktopFrame> frame( | |
| 103 SkiaBitmapDesktopFrame::Create(bitmap.Pass())); | |
| 104 | |
| 105 // |VideoScheduler| will not encode the frame if |updated_region| is empty. | |
| 106 const webrtc::DesktopRect& rect = webrtc::DesktopRect::MakeWH( | |
| 107 frame->size().width(), frame->size().height()); | |
| 108 | |
| 109 // TODO(kelvinp): Set Frame DPI according to the screen resolution. | |
| 110 // See cc::Layer::contents_scale_(x|y)() and frame->set_depi(). | |
| 111 frame->mutable_updated_region()->SetRect(rect); | |
| 112 | |
| 113 callback_->OnCaptureCompleted(frame.release()); | |
| 114 } | |
| 115 | |
| 116 } // namespace remoting | |
| OLD | NEW |