| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 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 #ifndef MEDIA_CAPTURE_VIDEO_CHROMEOS_DISPLAY_ROTATION_OBSERVER_H_ | |
| 6 #define MEDIA_CAPTURE_VIDEO_CHROMEOS_DISPLAY_ROTATION_OBSERVER_H_ | |
| 7 | |
| 8 #include "base/memory/ref_counted.h" | |
| 9 #include "base/single_thread_task_runner.h" | |
| 10 #include "ui/display/display.h" | |
| 11 #include "ui/display/display_observer.h" | |
| 12 #include "ui/display/screen.h" | |
| 13 | |
| 14 namespace media { | |
| 15 | |
| 16 class DisplayRotationObserver { | |
| 17 public: | |
| 18 virtual void SetDisplayRotation(const display::Display& display) = 0; | |
| 19 }; | |
| 20 | |
| 21 // Registers itself as an observer at |display::Screen::GetScreen()| and | |
| 22 // forwards rotation change events to the given DisplayRotationObserver on the | |
| 23 // thread where ScreenObserverDelegate was created. | |
| 24 class ScreenObserverDelegate | |
| 25 : public display::DisplayObserver, | |
| 26 public base::RefCountedThreadSafe<ScreenObserverDelegate> { | |
| 27 public: | |
| 28 ScreenObserverDelegate( | |
| 29 DisplayRotationObserver* observer, | |
| 30 scoped_refptr<base::SingleThreadTaskRunner> display_task_runner); | |
| 31 | |
| 32 // The user must call RemoveObserver() to drop the reference to |observer_| in | |
| 33 // ScreenObserverDelegate before deleting |observer_|. | |
| 34 void RemoveObserver(); | |
| 35 | |
| 36 private: | |
| 37 friend class base::RefCountedThreadSafe<ScreenObserverDelegate>; | |
| 38 | |
| 39 ~ScreenObserverDelegate() override; | |
| 40 | |
| 41 // DisplayObserver implementations. | |
| 42 void OnDisplayAdded(const display::Display& /*new_display*/) override; | |
| 43 void OnDisplayRemoved(const display::Display& /*old_display*/) override; | |
| 44 void OnDisplayMetricsChanged(const display::Display& display, | |
| 45 uint32_t metrics) override; | |
| 46 | |
| 47 void AddObserverOnDisplayThread(); | |
| 48 void RemoveObserverOnDisplayThread(); | |
| 49 | |
| 50 // Post the screen rotation change from the display thread to capture thread | |
| 51 void SendDisplayRotation(const display::Display& display); | |
| 52 void SendDisplayRotationOnCaptureThread(const display::Display& display); | |
| 53 | |
| 54 DisplayRotationObserver* observer_; | |
| 55 // The task runner where the calls to display::Display must be serialized on. | |
| 56 const scoped_refptr<base::SingleThreadTaskRunner> display_task_runner_; | |
| 57 // The task runner on which the ScreenObserverDelegate is created. | |
| 58 const scoped_refptr<base::SingleThreadTaskRunner> delegate_task_runner_; | |
| 59 DISALLOW_IMPLICIT_CONSTRUCTORS(ScreenObserverDelegate); | |
| 60 }; | |
| 61 | |
| 62 } // namespace media | |
| 63 | |
| 64 #endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_DISPLAY_ROTATION_OBSERVER_H_ | |
| OLD | NEW |