Chromium Code Reviews| Index: media/base/android/dialog_surface.h |
| diff --git a/media/base/android/dialog_surface.h b/media/base/android/dialog_surface.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..35c11e4252a11f9c110e4fc6c6bd5ba3c0582946 |
| --- /dev/null |
| +++ b/media/base/android/dialog_surface.h |
| @@ -0,0 +1,111 @@ |
| +// 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_H_ |
| +#define MEDIA_BASE_ANDROID_DIALOG_SURFACE_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/rect.h" |
| +#include "ui/gl/android/scoped_java_surface.h" |
| + |
| +namespace media { |
| + |
| +class DialogSurfaceCallback; |
| +class DialogSurfaceManager; |
| + |
| +// This class implements the C++ wrapper around a java DialogSurface. |
| +// All callbacks happen on the thread that it's constructed on. |
| +// Once the object is destroyed on that same thread, no further callbacks will |
| +// arrive. In particular, it's safe to delete a DialogSurface during a |
| +// callback, and expect that no further callbacks will happen. |
| +// When a DialogSurface is deleted, the associated Android surface, if any, will |
| +// be destroyed. This will be asynchronous. |
| +class MEDIA_EXPORT DialogSurface { |
| + public: |
| + // 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.
|
| + // |
| + // SURFACE_CREATED will be sent at most once an android surface is available |
| + // via GetAndroidSurface. Prior to SURFACE_CREATED, layout requests will be |
| + // ignored, and GetAndroidSurface will return an empty surface. |
| + // |
| + // SURFACE_DESTROYED will be sent to indicate that the DialogSurface instance |
| + // is no longer needd. The application must quit using the Android Surface |
| + // before this callback returns. It is okay for SURFACE_DESTROYED to arrive |
| + // without a pending SURFACE_CREATED, to indicate that no surface will arrive. |
| + // In either case, the application must create a new DialogSurface instance |
| + // if it wants another surface. |
| + 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::Rect rect; |
| + // This may also include pixel format, is_secure, etc. |
| + }; |
| + |
| + // |unwrapped_surface| is the IDialogSurface 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. |
| + DialogSurface(const base::android::JavaRef<jobject>& unwrapped_surface, |
| + std::unique_ptr<DialogSurfaceCallback> callback); |
| + ~DialogSurface(); |
| + |
| + // Schedule a relayout and/or reposition of the surface. Calls before a |
| + // SURFACE_CREATED callback, or after SURFACE_DESTROYED, are ignored. |
| + void ScheduleLayout(const Config& config); |
| + |
| + // Note that java does not have a reference to this object -- it knows only |
| + // about the callback. This is helpful, since we don't need to synchronize |
| + // our destruction with anything going on in java. DialogSurfaceCallback |
| + // handles synchronization of itself. |
| + |
| + // Return the Androird surface, or null. This will return null until the |
| + // callback is called with SURFACE_CREATED. You may take ownership of this |
| + // surface, or not. |
| + gl::ScopedJavaSurface& GetAndroidSurface(); |
| + |
| + protected: |
| + bool CalledOnValidThread() const; |
| + |
| + // Set the java surface from the callback. |
| + void OnAndroidSurface(const base::android::JavaRef<jobject>& jsurface); |
| + |
| + private: |
| + // Java DialogSurfaceWrapper instance. |
| + base::android::ScopedJavaGlobalRef<jobject> j_wrapped_surface_; |
| + |
| + // Callback that's associated with this surface. We maintain ownership of it |
| + // so that the native object stays around while we do. Future callbacks will |
| + // be cancelled by DialogSurfaceCallback once the object is deleted. |
| + std::unique_ptr<DialogSurfaceCallback> wrapped_callback_; |
| + |
| + gl::ScopedJavaSurface android_surface_; |
| + |
| + base::ThreadChecker thread_checker_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(DialogSurface); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_BASE_ANDROID_DIALOG_SURFACE_H_ |