Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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_BASE_ANDROID_DIALOG_SURFACE_H_ | |
| 6 #define MEDIA_BASE_ANDROID_DIALOG_SURFACE_H_ | |
| 7 | |
| 8 #include <jni.h> | |
| 9 #include <stddef.h> | |
| 10 #include <stdint.h> | |
| 11 | |
| 12 #include <set> | |
| 13 #include <string> | |
| 14 | |
| 15 #include "base/android/scoped_java_ref.h" | |
| 16 #include "base/callback.h" | |
| 17 #include "base/macros.h" | |
| 18 #include "base/task_runner.h" | |
| 19 #include "base/threading/thread_checker.h" | |
| 20 #include "base/time/time.h" | |
| 21 #include "media/base/media_export.h" | |
| 22 #include "ui/gfx/geometry/rect.h" | |
| 23 #include "ui/gl/android/scoped_java_surface.h" | |
| 24 | |
| 25 namespace media { | |
| 26 | |
| 27 class DialogSurfaceCallback; | |
| 28 class DialogSurfaceManager; | |
| 29 | |
| 30 // This class implements the C++ wrapper around a java DialogSurface. | |
| 31 // All callbacks happen on the thread that it's constructed on. | |
| 32 // Once the object is destroyed on that same thread, no further callbacks will | |
| 33 // arrive. In particular, it's safe to delete a DialogSurface during a | |
| 34 // callback, and expect that no further callbacks will happen. | |
| 35 // When a DialogSurface is deleted, the associated Android surface, if any, will | |
| 36 // be destroyed. This will be asynchronous. | |
| 37 class MEDIA_EXPORT DialogSurface { | |
| 38 public: | |
| 39 // These must match DialogSurface.java | |
|
boliu
2017/01/04 01:48:44
fwiw there is an automated way to generate enums t
liberato (no reviews please)
2017/01/11 22:17:56
Acknowledged.
| |
| 40 // | |
| 41 // SURFACE_CREATED will be sent at most once an android surface is available | |
| 42 // via GetAndroidSurface. Prior to SURFACE_CREATED, layout requests will be | |
| 43 // ignored, and GetAndroidSurface will return an empty surface. | |
| 44 // | |
| 45 // SURFACE_DESTROYED will be sent to indicate that the DialogSurface instance | |
| 46 // is no longer needd. The application must quit using the Android Surface | |
| 47 // before this callback returns. It is okay for SURFACE_DESTROYED to arrive | |
| 48 // without a pending SURFACE_CREATED, to indicate that no surface will arrive. | |
| 49 // In either case, the application must create a new DialogSurface instance | |
| 50 // if it wants another surface. | |
| 51 enum CallbackOp { SURFACE_CREATED = 0, SURFACE_DESTROYED = 1 }; | |
| 52 | |
| 53 // Callback type for finding out about the status of the surface. While we | |
| 54 // don't use this directly, it lets us keep DialogSurfaceCallback as an | |
| 55 // implementation detail. | |
| 56 using Callback = base::Callback<void(CallbackOp)>; | |
| 57 | |
| 58 // Configuration for the surface. | |
| 59 struct Config { | |
| 60 gfx::Rect rect; | |
| 61 // This may also include pixel format, is_secure, etc. | |
| 62 }; | |
| 63 | |
| 64 // |unwrapped_surface| is the IDialogSurface java instance, which | |
| 65 // we will take ownership of. |callback| is the wrapped callback that it will | |
| 66 // use to communicate with us (DialogSurfaceCallback). | |
| 67 // Note: one generally doesn't want to call this directly. Use | |
| 68 // DialogSurfaceManager instead. | |
| 69 DialogSurface(const base::android::JavaRef<jobject>& unwrapped_surface, | |
| 70 std::unique_ptr<DialogSurfaceCallback> callback); | |
| 71 ~DialogSurface(); | |
| 72 | |
| 73 // Schedule a relayout and/or reposition of the surface. Calls before a | |
| 74 // SURFACE_CREATED callback, or after SURFACE_DESTROYED, are ignored. | |
| 75 void ScheduleLayout(const Config& config); | |
| 76 | |
| 77 // Note that java does not have a reference to this object -- it knows only | |
| 78 // about the callback. This is helpful, since we don't need to synchronize | |
| 79 // our destruction with anything going on in java. DialogSurfaceCallback | |
| 80 // handles synchronization of itself. | |
| 81 | |
| 82 // Return the Androird surface, or null. This will return null until the | |
| 83 // callback is called with SURFACE_CREATED. You may take ownership of this | |
| 84 // surface, or not. | |
| 85 gl::ScopedJavaSurface& GetAndroidSurface(); | |
| 86 | |
| 87 protected: | |
| 88 bool CalledOnValidThread() const; | |
| 89 | |
| 90 // Set the java surface from the callback. | |
| 91 void OnAndroidSurface(const base::android::JavaRef<jobject>& jsurface); | |
| 92 | |
| 93 private: | |
| 94 // Java DialogSurfaceWrapper instance. | |
| 95 base::android::ScopedJavaGlobalRef<jobject> j_wrapped_surface_; | |
| 96 | |
| 97 // Callback that's associated with this surface. We maintain ownership of it | |
| 98 // so that the native object stays around while we do. Future callbacks will | |
| 99 // be cancelled by DialogSurfaceCallback once the object is deleted. | |
| 100 std::unique_ptr<DialogSurfaceCallback> wrapped_callback_; | |
| 101 | |
| 102 gl::ScopedJavaSurface android_surface_; | |
| 103 | |
| 104 base::ThreadChecker thread_checker_; | |
| 105 | |
| 106 DISALLOW_COPY_AND_ASSIGN(DialogSurface); | |
| 107 }; | |
| 108 | |
| 109 } // namespace media | |
| 110 | |
| 111 #endif // MEDIA_BASE_ANDROID_DIALOG_SURFACE_H_ | |
| OLD | NEW |