Chromium Code Reviews| Index: media/video/capture/linux/video_capture_device_chromeos.cc |
| diff --git a/media/video/capture/linux/video_capture_device_chromeos.cc b/media/video/capture/linux/video_capture_device_chromeos.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..dfffa4f32f1a71120c0cae4ba4c34dab5ee31005 |
| --- /dev/null |
| +++ b/media/video/capture/linux/video_capture_device_chromeos.cc |
| @@ -0,0 +1,100 @@ |
| +// 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 "media/video/capture/linux/video_capture_device_chromeos.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/memory/ref_counted.h" |
| +#include "ui/gfx/display.h" |
| +#include "ui/gfx/display_observer.h" |
| +#include "ui/gfx/screen.h" |
| + |
| +namespace media { |
| + |
| +// This is a delegate class used to transfer Display change events from the UI |
| +// thread to the media thread. |
| +class VideoCaptureDeviceChromeOS::ScreenObserverDelegate |
| + : public gfx::DisplayObserver, |
| + public base::RefCountedThreadSafe<ScreenObserverDelegate> { |
| + public: |
| + ScreenObserverDelegate(VideoCaptureDeviceChromeOS* capture_device) |
| + : capture_device_(capture_device), |
| + capture_thread_loop_(base::MessageLoop::current()) { |
| + base::MessageLoopForUI::current()->PostTask( |
| + FROM_HERE, |
|
perkj_chrome
2014/05/13 09:46:40
nit: indentation
Zachary Kuznia
2014/05/13 13:54:29
Done.
|
| + base::Bind(&ScreenObserverDelegate::AddObserverOnUIThread, this)); |
| + } |
| + |
| + void RemoveObserver() { |
| + DCHECK(capture_thread_loop_ == base::MessageLoop::current()); |
| + capture_device_ = NULL; |
| + base::MessageLoopForUI::current()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&ScreenObserverDelegate::RemoveObserverOnUIThread, this)); |
| + } |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<ScreenObserverDelegate>; |
| + |
| + virtual ~ScreenObserverDelegate() { |
| + DCHECK(!capture_device_); |
| + } |
| + |
| + // gfx::DisplayObserver: |
| + virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE { |
| + SendDisplayRotation(display); |
| + } |
| + |
| + virtual void OnDisplayAdded(const gfx::Display& /*new_display*/) OVERRIDE {} |
|
perkj_chrome
2014/05/13 09:46:40
style nit - name all arguments even if they are no
Zachary Kuznia
2014/05/13 13:54:29
See: http://google-styleguide.googlecode.com/svn/t
|
| + virtual void OnDisplayRemoved(const gfx::Display& /*old_display*/) OVERRIDE {} |
| + |
| + void AddObserverOnUIThread() { |
|
tommi (sloooow) - chröme
2014/05/13 11:02:51
nit: add a dcheck that we're indeed on the ui thre
Zachary Kuznia
2014/05/13 13:54:29
Done.
|
| + gfx::Screen* screen = |
| + gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE); |
| + if (screen) { |
| + screen->AddObserver(this); |
| + SendDisplayRotation(screen->GetPrimaryDisplay()); |
| + } |
| + } |
| + |
| + void RemoveObserverOnUIThread() { |
| + gfx::Screen* screen = |
|
tommi (sloooow) - chröme
2014/05/13 11:02:51
dcheck
Zachary Kuznia
2014/05/13 13:54:29
Done.
|
| + gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE); |
| + if (screen) |
| + screen->RemoveObserver(this); |
| + } |
| + |
| + void SendDisplayRotation(const gfx::Display& display) { |
| + capture_thread_loop_->PostTask( |
|
perkj_chrome
2014/05/13 09:46:40
Can you add thread check here as well.
Zachary Kuznia
2014/05/13 13:54:29
Done.
|
| + FROM_HERE, |
|
perkj_chrome
2014/05/13 09:46:40
nit: intendation
Zachary Kuznia
2014/05/13 13:54:29
Done.
|
| + base::Bind(&ScreenObserverDelegate::SendDisplayRotationOnCaptureThread, |
| + this, display)); |
| + } |
| + |
| + void SendDisplayRotationOnCaptureThread(const gfx::Display& display) { |
| + DCHECK(capture_thread_loop_ == base::MessageLoop::current()); |
| + capture_device_->SetDisplayRotation(display); |
| + } |
| + |
|
perkj_chrome
2014/05/13 09:46:40
Can you add a threadchecker and verify that you ar
Zachary Kuznia
2014/05/13 13:54:29
I don't think a threadchecker would be useful, bec
|
| + VideoCaptureDeviceChromeOS* capture_device_; |
| + base::MessageLoop* capture_thread_loop_; |
|
tommi (sloooow) - chröme
2014/05/13 11:02:51
if you use this variable on a thread other than th
Zachary Kuznia
2014/05/13 13:54:29
I actually used a MessageLoopProxy initially, but
tommi (sloooow) - chröme
2014/05/13 14:35:17
Ah, I'm guessing this is the error you ran into:
h
|
| + DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenObserverDelegate); |
| +}; |
| + |
| + |
| +VideoCaptureDeviceChromeOS::VideoCaptureDeviceChromeOS(const Name& device_name) |
| + : VideoCaptureDeviceLinux(device_name), |
| + screen_observer_delegate_(new ScreenObserverDelegate(this)) { |
| +} |
| + |
| +VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() { |
| +} |
| + |
| +void VideoCaptureDeviceChromeOS::SetDisplayRotation( |
| + const gfx::Display& display) { |
| + if (display.IsInternal()) |
| + SetRotation(display.rotation() * 90); |
| +} |
| + |
| +} // namespace media |