| Index: media/base/android/android_overlay_proxy.h
|
| diff --git a/media/base/android/android_overlay_proxy.h b/media/base/android/android_overlay_proxy.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..a80e8720527c1f83e62e28b1ea7f313576d5575d
|
| --- /dev/null
|
| +++ b/media/base/android/android_overlay_proxy.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_ANDROID_OVERLAY_PROXY_H_
|
| +#define MEDIA_BASE_ANDROID_ANDROID_OVERLAY_PROXY_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 AndroidOverlayCallback;
|
| +
|
| +// This class implements the C++ wrapper around a java AndroidOverlay.
|
| +// 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 AndroidOverlay during a
|
| +// callback, and expect that no further callbacks will happen.
|
| +// When a AndroidOverlay is deleted, the associated Android surface, if any,
|
| +// will
|
| +// be destroyed. This will be asynchronous.
|
| +class MEDIA_EXPORT AndroidOverlayProxy {
|
| + public:
|
| + // These must match AndroidOverlay.java
|
| + //
|
| + // 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 AndroidOverlay 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 AndroidOverlay 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 AndroidOverlayCallback 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 IAndroidOverlay java instance, which
|
| + // we will take ownership of. |callback| is the wrapped callback that it will
|
| + // use to communicate with us (AndroidOverlayCallback).
|
| + // Note: one generally doesn't want to call this directly. Use
|
| + // AndroidOverlayProviderProxy instead.
|
| + AndroidOverlayProxy(const base::android::JavaRef<jobject>& unwrapped_surface,
|
| + std::unique_ptr<AndroidOverlayCallback> callback);
|
| + ~AndroidOverlayProxy();
|
| +
|
| + // 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. AndroidOverlayCallback
|
| + // 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 AndroidOverlayWrapper 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 AndroidOverlayCallback once the object is deleted.
|
| + std::unique_ptr<AndroidOverlayCallback> wrapped_callback_;
|
| +
|
| + gl::ScopedJavaSurface android_surface_;
|
| +
|
| + base::ThreadChecker thread_checker_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(AndroidOverlayProxy);
|
| +};
|
| +
|
| +} // namespace media
|
| +
|
| +#endif // MEDIA_BASE_ANDROID_ANDROID_OVERLAY_PROXY_H_
|
|
|