Index: media/base/android/dialog_surface_controller.h |
diff --git a/media/base/android/dialog_surface_controller.h b/media/base/android/dialog_surface_controller.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..203c3c2c5d293d3cf102645c8fa26805387c6b0c |
--- /dev/null |
+++ b/media/base/android/dialog_surface_controller.h |
@@ -0,0 +1,93 @@ |
+// Copyright 2016 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. |
+ |
+#ifndef MEDIA_BASE_ANDROID_DIALOG_SURFACE_CONTROLLER_H_ |
+#define MEDIA_BASE_ANDROID_DIALOG_SURFACE_CONTROLLER_H_ |
+ |
+#include <jni.h> |
+#include <stddef.h> |
+#include <stdint.h> |
+ |
+#include <set> |
+#include <string> |
+ |
+#include "base/android/scoped_java_ref.h" |
+#include "base/callback.h" |
+#include "base/macros.h" |
+#include "base/task_runner.h" |
+#include "base/threading/thread_checker.h" |
+#include "base/time/time.h" |
+#include "media/base/media_export.h" |
+#include "ui/gfx/geometry/point.h" |
+#include "ui/gfx/geometry/size.h" |
+#include "ui/gl/android/scoped_java_surface.h" |
+ |
+namespace base { |
+class WaitableEvent; |
+} |
+ |
+namespace media { |
+ |
+class DialogSurfaceCallback; |
+class DialogSurfaceManager; |
+ |
+// This class implements the C++ wrapper around a java DialogSurfaceController. |
+// All callbacks happen on the thread that it's constructed on. |
+class MEDIA_EXPORT DialogSurfaceController { |
+ public: |
+ // These must match DialogSurfaceController.java |
+ enum CallbackOp { SURFACE_CREATED = 0, SURFACE_DESTROYED = 1 }; |
+ |
+ // Callback type for finding out about the status of the surface. While we |
+ // don't use this directly, it lets us keep DialogSurfaceCallback as an |
+ // implementation detail. |
+ using Callback = base::Callback<void(CallbackOp)>; |
+ |
+ // Configuration for the surface. |
+ struct Config { |
+ gfx::Point position; |
+ gfx::Size size; |
+ // This may also include pixel format, is_secure, etc. |
+ }; |
+ |
+ // |unwrapped_controller| is the IDialogSurfaceController java instance, which |
+ // we will take ownership of. |callback| is the wrapped callback that it will |
+ // use to communicate with us (DialogSurfaceCallback). |
+ // Note: one generally doesn't want to call this directly. Use |
+ // DialogSurfaceManager instead. |
+ DialogSurfaceController( |
+ const base::android::JavaRef<jobject>& unwrapped_controller, |
+ std::unique_ptr<DialogSurfaceCallback>&& callback); |
+ ~DialogSurfaceController(); |
+ |
+ // Schedule a relayout and/or reposition of the surface. |
+ void ScheduleLayout(const Config& config); |
+ |
+ // Return the java surface, if any. One should not assume that this is |
+ // available immediately. The callback will be called with SURFACE_CREATED |
+ // when it is available. Of course, it may become unavailable again |
+ // asynchronously, so one must always check. |
+ gl::ScopedJavaSurface GetSurface(); |
+ |
+ static bool RegisterDialogSurfaceController(JNIEnv* env); |
+ |
+ protected: |
+ bool CalledOnValidThread() const; |
+ |
+ private: |
+ // Java DialogSurfaceControllerWrapper instance. |
+ base::android::ScopedJavaGlobalRef<jobject> j_wrapped_controller_; |
+ |
+ // Callback that's associated with this surface. We maintain ownership of it |
+ // so that the native object stays around while we do. |
+ std::unique_ptr<DialogSurfaceCallback> wrapped_callback_; |
+ |
+ base::ThreadChecker thread_checker_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(DialogSurfaceController); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_BASE_ANDROID_DIALOG_SURFACE_CONTROLLER_H_ |