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 // DesktopFrame implementation used by screen capture on ChromeOS. | |
| 18 // Frame data is stored in a SkBitmap. | |
| 19 class SkiaBitmapDestkopFrame : public webrtc::DesktopFrame { | |
|
Wez
2014/09/10 01:41:10
typo: Destkop->Desktop
Wez
2014/09/10 01:41:10
This class, and the implementations of its methods
kelvinp
2014/09/10 22:33:58
Done.
kelvinp
2014/09/10 22:33:58
Done.
| |
| 20 public: | |
| 21 virtual ~SkiaBitmapDestkopFrame(); | |
| 22 static SkiaBitmapDestkopFrame* Create(SkBitmap* bitmap); | |
|
Wez
2014/09/10 01:41:10
nit: static methods should appear before ctor/dtor
Wez
2014/09/10 01:41:10
scoped_ptr<SkBitmap>, not SkBitmap*
kelvinp
2014/09/10 22:33:58
Done.
kelvinp
2014/09/10 22:33:58
Done.
| |
| 23 | |
| 24 private: | |
| 25 SkiaBitmapDestkopFrame(webrtc::DesktopSize size, | |
| 26 int stride, | |
| 27 uint8_t* data, | |
| 28 SkBitmap* bitmap); | |
| 29 | |
| 30 scoped_ptr<SkBitmap> bitmap_; | |
| 31 | |
| 32 DISALLOW_COPY_AND_ASSIGN(SkiaBitmapDestkopFrame); | |
| 33 }; | |
| 34 | |
| 35 AuraDesktopCapturer::AuraDesktopCapturer() | |
| 36 : callback_(NULL), desktop_window_(NULL), weak_factory_(this) { | |
| 37 } | |
| 38 | |
| 39 AuraDesktopCapturer::~AuraDesktopCapturer() { | |
| 40 } | |
| 41 | |
| 42 void AuraDesktopCapturer::Start(webrtc::DesktopCapturer::Callback* callback) { | |
| 43 callback_ = callback; | |
| 44 } | |
| 45 | |
| 46 void AuraDesktopCapturer::Capture(const webrtc::DesktopRegion&) { | |
| 47 scoped_ptr<cc::CopyOutputRequest> request = | |
| 48 cc::CopyOutputRequest::CreateBitmapRequest(base::Bind( | |
| 49 &AuraDesktopCapturer::OnFrameCaptured, weak_factory_.GetWeakPtr())); | |
|
Wez
2014/09/10 01:41:10
nit: I think this'll read better if you wrap befor
kelvinp
2014/09/10 22:33:58
Done.
| |
| 50 | |
| 51 int width = desktop_window_->bounds().width(); | |
| 52 int height = desktop_window_->bounds().height(); | |
| 53 gfx::Rect window_rect = gfx::Rect(width, height); | |
| 54 | |
| 55 request->set_area(window_rect); | |
| 56 DCHECK(desktop_window_); | |
|
Wez
2014/09/10 01:41:10
No need to DCHECK this here - you're about to dere
kelvinp
2014/09/10 22:33:58
Done.
| |
| 57 desktop_window_->layer()->RequestCopyOfOutput(request.Pass()); | |
| 58 } | |
| 59 | |
| 60 void AuraDesktopCapturer::OnFrameCaptured( | |
| 61 scoped_ptr<cc::CopyOutputResult> result) { | |
| 62 DCHECK(result->HasBitmap()); | |
|
Wez
2014/09/10 01:41:10
Is there a situation in which it might not have a
kelvinp
2014/09/10 22:33:58
No, that should never happen.
| |
| 63 | |
| 64 scoped_ptr<SkBitmap> bitmap = result->TakeBitmap(); | |
| 65 | |
| 66 scoped_ptr<webrtc::DesktopFrame> frame( | |
| 67 SkiaBitmapDestkopFrame::Create(bitmap.release())); | |
| 68 | |
| 69 callback_->OnCaptureCompleted(frame.release()); | |
| 70 } | |
| 71 | |
| 72 SkiaBitmapDestkopFrame::SkiaBitmapDestkopFrame(webrtc::DesktopSize size, | |
| 73 int stride, | |
| 74 uint8_t* data, | |
| 75 SkBitmap* bitmap) | |
| 76 : DesktopFrame(size, stride, data, NULL), bitmap_(bitmap) { | |
| 77 } | |
| 78 | |
| 79 SkiaBitmapDestkopFrame::~SkiaBitmapDestkopFrame() { | |
| 80 } | |
| 81 | |
| 82 // static | |
| 83 SkiaBitmapDestkopFrame* SkiaBitmapDestkopFrame::Create(SkBitmap* bitmap) { | |
| 84 DCHECK(bitmap); | |
| 85 | |
| 86 int width = bitmap->width(); | |
| 87 int height = bitmap->height(); | |
| 88 | |
| 89 webrtc::DesktopSize size(width, height); | |
| 90 | |
| 91 DCHECK(bitmap->bytesPerPixel() == 4) | |
|
Wez
2014/09/10 01:41:10
DCHECK_EQ(4, bitmap->bytesPerPixel())
Is there a
kelvinp
2014/09/10 22:33:58
No, the current implementation of both the gl rend
| |
| 92 << "DesktopFrame objects always hold RGBA data."; | |
| 93 | |
| 94 uint8_t* bitmap_data = reinterpret_cast<uint8_t*>(bitmap->getPixels()); | |
| 95 | |
| 96 SkiaBitmapDestkopFrame* result = | |
| 97 new SkiaBitmapDestkopFrame(size, bitmap->rowBytes(), bitmap_data, bitmap); | |
| 98 | |
| 99 const webrtc::DesktopRect& rect = webrtc::DesktopRect::MakeWH(width, height); | |
| 100 result->mutable_updated_region()->SetRect(rect); | |
|
Wez
2014/09/10 01:41:10
nit: This makes more logical sense to do in OnFram
kelvinp
2014/09/10 22:33:58
Done.
| |
| 101 | |
| 102 return result; | |
| 103 } | |
| 104 | |
| 105 } // namespace remoting | |
| OLD | NEW |