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_CONTROLLER_H_ |
| 6 #define MEDIA_BASE_ANDROID_DIALOG_SURFACE_CONTROLLER_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/point.h" |
| 23 #include "ui/gfx/geometry/size.h" |
| 24 #include "ui/gl/android/scoped_java_surface.h" |
| 25 |
| 26 namespace base { |
| 27 class WaitableEvent; |
| 28 } |
| 29 |
| 30 namespace media { |
| 31 |
| 32 class DialogSurfaceCallback; |
| 33 class DialogSurfaceManager; |
| 34 |
| 35 // This class implements the C++ wrapper around a java DialogSurfaceController. |
| 36 // All callbacks happen on the thread that it's constructed on. |
| 37 class MEDIA_EXPORT DialogSurfaceController { |
| 38 public: |
| 39 // These must match DialogSurfaceController.java |
| 40 enum CallbackOp { SURFACE_CREATED = 0, SURFACE_DESTROYED = 1 }; |
| 41 |
| 42 // Callback type for finding out about the status of the surface. While we |
| 43 // don't use this directly, it lets us keep DialogSurfaceCallback as an |
| 44 // implementation detail. |
| 45 using Callback = base::Callback<void(CallbackOp)>; |
| 46 |
| 47 // Configuration for the surface. |
| 48 struct Config { |
| 49 gfx::Point position; |
| 50 gfx::Size size; |
| 51 // This may also include pixel format, is_secure, etc. |
| 52 }; |
| 53 |
| 54 // |unwrapped_controller| is the IDialogSurfaceController java instance, which |
| 55 // we will take ownership of. |callback| is the wrapped callback that it will |
| 56 // use to communicate with us (DialogSurfaceCallback). |
| 57 // Note: one generally doesn't want to call this directly. Use |
| 58 // DialogSurfaceManager instead. |
| 59 DialogSurfaceController( |
| 60 const base::android::JavaRef<jobject>& unwrapped_controller, |
| 61 std::unique_ptr<DialogSurfaceCallback>&& callback); |
| 62 ~DialogSurfaceController(); |
| 63 |
| 64 // Schedule a relayout and/or reposition of the surface. |
| 65 void ScheduleLayout(const Config& config); |
| 66 |
| 67 // Return the java surface, if any. One should not assume that this is |
| 68 // available immediately. The callback will be called with SURFACE_CREATED |
| 69 // when it is available. Of course, it may become unavailable again |
| 70 // asynchronously, so one must always check. |
| 71 gl::ScopedJavaSurface GetSurface(); |
| 72 |
| 73 static bool RegisterDialogSurfaceController(JNIEnv* env); |
| 74 |
| 75 protected: |
| 76 bool CalledOnValidThread() const; |
| 77 |
| 78 private: |
| 79 // Java DialogSurfaceControllerWrapper instance. |
| 80 base::android::ScopedJavaGlobalRef<jobject> j_wrapped_controller_; |
| 81 |
| 82 // Callback that's associated with this surface. We maintain ownership of it |
| 83 // so that the native object stays around while we do. |
| 84 std::unique_ptr<DialogSurfaceCallback> wrapped_callback_; |
| 85 |
| 86 base::ThreadChecker thread_checker_; |
| 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(DialogSurfaceController); |
| 89 }; |
| 90 |
| 91 } // namespace media |
| 92 |
| 93 #endif // MEDIA_BASE_ANDROID_DIALOG_SURFACE_CONTROLLER_H_ |
OLD | NEW |