OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_BASE_ANDROID_ANDROID_OVERLAY_H_ | 5 #ifndef MEDIA_BASE_ANDROID_ANDROID_OVERLAY_H_ |
6 #define MEDIA_BASE_ANDROID_ANDROID_OVERLAY_H_ | 6 #define MEDIA_BASE_ANDROID_ANDROID_OVERLAY_H_ |
7 | 7 |
| 8 #include <list> |
| 9 |
8 #include "base/android/scoped_java_ref.h" | 10 #include "base/android/scoped_java_ref.h" |
9 #include "base/callback.h" | 11 #include "base/callback.h" |
10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/weak_ptr.h" |
11 #include "media/base/android_overlay_config.h" | 14 #include "media/base/android_overlay_config.h" |
12 #include "media/base/media_export.h" | 15 #include "media/base/media_export.h" |
13 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
14 #include "ui/gl/android/scoped_java_surface.h" | 17 #include "ui/gl/android/scoped_java_surface.h" |
15 | 18 |
16 namespace media { | 19 namespace media { |
17 | 20 |
18 // Client interface to an AndroidOverlay. Once constructed, you can expect to | 21 // Client interface to an AndroidOverlay. Once constructed, you can expect to |
19 // receive either a call to ReadyCB or a call to FailedCB to indicate whether | 22 // receive either a call to ReadyCB or a call to FailedCB to indicate whether |
20 // the overlay is ready, or isn't going to be ready. If one does get ReadyCB, | 23 // the overlay is ready, or isn't going to be ready. If one does get ReadyCB, |
21 // then one may GetJavaSurface() to retrieve the java Surface object. One | 24 // then one may GetJavaSurface() to retrieve the java Surface object. One |
22 // will get DestroyedCB eventually after ReadyCB, assuming that one doesn't | 25 // will get DestroyedCB eventually after ReadyCB, assuming that one doesn't |
23 // delete the overlay before that. | 26 // delete the overlay before that. |
24 // When DestroyedCB arrives, you should stop using the Android Surface and | 27 // When DestroyedCB arrives, you should stop using the Android Surface and |
25 // delete the AndroidOverlay instance. Currently, the exact contract depends | 28 // delete the AndroidOverlay instance. Currently, the exact contract depends |
26 // on the concrete implementation. Once ContentVideoView is deprecated, it will | 29 // on the concrete implementation. Once ContentVideoView is deprecated, it will |
27 // be: it is not guaranteed that any AndroidOverlay instances will operate until | 30 // be: it is not guaranteed that any AndroidOverlay instances will operate until |
28 // the destroyed instance is deleted. This must happen on the thread that was | 31 // the destroyed instance is deleted. This must happen on the thread that was |
29 // used to create it. It does not have to happen immediately, or before the | 32 // used to create it. It does not have to happen immediately, or before the |
30 // callback returns. | 33 // callback returns. |
31 // With CVV, one must still delete the overlay on the main thread, and it | 34 // With CVV, one must still delete the overlay on the main thread, and it |
32 // doesn't have to happen before this returns. However, one must signal the | 35 // doesn't have to happen before this returns. However, one must signal the |
33 // CVV onSurfaceDestroyed handler on some thread before returning from the | 36 // CVV onSurfaceDestroyed handler on some thread before returning from the |
34 // callback. AVDACodecAllocator::ReleaseMediaCodec handles signaling. The | 37 // callback. AVDACodecAllocator::ReleaseMediaCodec handles signaling. The |
35 // fundamental difference is that CVV blocks the UI thread in the browser, which | 38 // fundamental difference is that CVV blocks the UI thread in the browser, which |
36 // makes it unsafe to let the gpu main thread proceed without risk of deadlock | 39 // makes it unsafe to let the gpu main thread proceed without risk of deadlock |
37 // AndroidOverlay isn't technically supposed to do that. | 40 // AndroidOverlay isn't technically supposed to do that. |
38 class MEDIA_EXPORT AndroidOverlay { | 41 class MEDIA_EXPORT AndroidOverlay { |
39 public: | 42 public: |
40 virtual ~AndroidOverlay() {} | 43 virtual ~AndroidOverlay(); |
41 | 44 |
42 // Schedules a relayout of this overlay. If called before the client is | 45 // Schedules a relayout of this overlay. If called before the client is |
43 // notified that the surface is created, then the call will be ignored. | 46 // notified that the surface is created, then the call will be ignored. |
44 virtual void ScheduleLayout(const gfx::Rect& rect) = 0; | 47 virtual void ScheduleLayout(const gfx::Rect& rect) = 0; |
45 | 48 |
46 // May be called during / after ReadyCB and before DestroyedCB. | 49 // May be called during / after ReadyCB and before DestroyedCB. |
47 virtual const base::android::JavaRef<jobject>& GetJavaSurface() const = 0; | 50 virtual const base::android::JavaRef<jobject>& GetJavaSurface() const = 0; |
48 | 51 |
| 52 // Add a destruction callback that will be called if the surface is destroyed. |
| 53 // Note that this refers to the destruction of the Android Surface, caused by |
| 54 // Android. It is not reporting the destruction of |this|. |
| 55 // |
| 56 // Destroying |this| prevents any further destroyed callbacks. This includes |
| 57 // cases in which an earlier callback out of multiple registred ones deletes |
| 58 // |this|. None of the later callbacks will be called. |
| 59 // |
| 60 // These will be called in the same order that they're added. |
| 61 void AddSurfaceDestroyedCallback(AndroidOverlayConfig::DestroyedCB cb); |
| 62 |
49 protected: | 63 protected: |
50 AndroidOverlay() {} | 64 AndroidOverlay(); |
| 65 |
| 66 void RunSurfaceDestroyedCallbacks(); |
| 67 |
| 68 std::list<AndroidOverlayConfig::DestroyedCB> destruction_cbs_; |
| 69 |
| 70 base::WeakPtrFactory<AndroidOverlay> weak_factory_; |
51 | 71 |
52 DISALLOW_COPY_AND_ASSIGN(AndroidOverlay); | 72 DISALLOW_COPY_AND_ASSIGN(AndroidOverlay); |
53 }; | 73 }; |
54 | 74 |
55 } // namespace media | 75 } // namespace media |
56 | 76 |
57 #endif // MEDIA_BASE_ANDROID_ANDROID_OVERLAY_H_ | 77 #endif // MEDIA_BASE_ANDROID_ANDROID_OVERLAY_H_ |
OLD | NEW |