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..b5f764d1a218db0b0fb08189702f5b19fa9aacb3 |
--- /dev/null |
+++ b/media/video/capture/linux/video_capture_device_chromeos.cc |
@@ -0,0 +1,98 @@ |
+// 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/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), |
+ media_message_loop_(base::MessageLoop::current()) { |
+ base::MessageLoopForUI::current()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&ScreenObserverDelegate::AddObserverOnUIThread, this)); |
+ } |
+ |
+ ~ScreenObserverDelegate() { |
+ DCHECK(!capture_device_); |
+ } |
+ |
+ void RemoveObserver() { |
+ capture_device_ = NULL; |
+ base::MessageLoopForUI::current()->PostTask( |
+ FROM_HERE, |
+ base::Bind(&ScreenObserverDelegate::RemoveObserverOnUIThread, this)); |
+ } |
+ |
+ private: |
+ friend class base::RefCountedThreadSafe<ScreenObserverDelegate>; |
mcasas
2014/05/11 18:41:25
According to base/memory/ref_counted.h, if you use
Zachary Kuznia
2014/05/12 02:54:18
Done.
|
+ |
+ // gfx::DisplayObserver: |
+ virtual void OnDisplayBoundsChanged(const gfx::Display& display) OVERRIDE { |
+ SendDisplayRotation(display); |
+ } |
+ |
+ virtual void OnDisplayAdded(const gfx::Display& /*new_display*/) OVERRIDE {} |
+ virtual void OnDisplayRemoved(const gfx::Display& /*old_display*/) OVERRIDE {} |
mcasas
2014/05/11 18:41:25
Shouldn't these 3 methods from gfx::DisplayObserve
Zachary Kuznia
2014/05/12 02:54:18
This is a controversial topic. See: https://group
|
+ |
+ void AddObserverOnUIThread() { |
+ gfx::Screen* screen = |
+ gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE); |
mcasas
2014/05/11 18:41:25
Why not gfx::SCREEN_TYPE_NATIVE?
Zachary Kuznia
2014/05/12 02:54:18
Because this is the pattern established in ash/she
|
+ if (screen) { |
+ screen->AddObserver(this); |
+ SendDisplayRotation(screen->GetPrimaryDisplay()); |
+ } |
+ } |
+ |
+ void RemoveObserverOnUIThread() { |
+ gfx::Screen* screen = |
+ gfx::Screen::GetScreenByType(gfx::SCREEN_TYPE_ALTERNATE); |
+ if (screen) |
+ screen->RemoveObserver(this); |
+ } |
+ |
+ void SendDisplayRotation(const gfx::Display& display) { |
+ media_message_loop_->PostTask( |
+ FROM_HERE, |
+ base::Bind(&ScreenObserverDelegate::SendDisplayRotationOnMediaThread, |
+ this, display)); |
+ } |
+ |
+ void SendDisplayRotationOnMediaThread(const gfx::Display& display) { |
+ capture_device_->SetDisplayRotation(display); |
+ } |
+ |
+ VideoCaptureDeviceChromeOS* capture_device_; |
mcasas
2014/05/11 18:41:25
Ugh naked pointer. Maybe const?
Zachary Kuznia
2014/05/12 02:54:18
Unfortunately, that would require marking rotation
|
+ base::MessageLoop* media_message_loop_; |
mcasas
2014/05/11 18:41:25
const?
ultra-nit: would you mind terribly calling
Zachary Kuznia
2014/05/12 02:54:18
Nits Done. The MessageLoop pointer can't be const
|
+ DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenObserverDelegate); |
+}; |
+ |
+ |
+VideoCaptureDeviceChromeOS::VideoCaptureDeviceChromeOS(const Name& device_name) |
+ : VideoCaptureDeviceLinux(device_name), |
+ screen_observer_delegate_(new ScreenObserverDelegate(this)) { |
+} |
+ |
+VideoCaptureDeviceChromeOS::~VideoCaptureDeviceChromeOS() { |
+ |
mcasas
2014/05/11 18:41:25
nit: no empty line.
Zachary Kuznia
2014/05/12 02:54:18
Done.
|
+} |
+ |
+void VideoCaptureDeviceChromeOS::SetDisplayRotation( |
+ const gfx::Display& display) { |
+ if (display.IsInternal()) |
+ SetRotation(display.rotation() * 90); |
+} |
+ |
+} // namespace media |