Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(373)

Side by Side Diff: media/base/android/android_overlay_proxy.h

Issue 2178973004: DialogSurfaceManager implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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_ANDROID_OVERLAY_PROXY_H_
6 #define MEDIA_BASE_ANDROID_ANDROID_OVERLAY_PROXY_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 AndroidOverlayCallback;
28
29 // This class implements the C++ wrapper around a java AndroidOverlay.
30 // All callbacks happen on the thread that it's constructed on.
31 // Once the object is destroyed on that same thread, no further callbacks will
32 // arrive. In particular, it's safe to delete a AndroidOverlay during a
33 // callback, and expect that no further callbacks will happen.
34 // When a AndroidOverlay is deleted, the associated Android surface, if any,
35 // will
36 // be destroyed. This will be asynchronous.
37 class MEDIA_EXPORT AndroidOverlayProxy {
38 public:
39 // These must match AndroidOverlay.java
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 AndroidOverlay 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 AndroidOverlay 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 AndroidOverlayCallback 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 IAndroidOverlay java instance, which
65 // we will take ownership of. |callback| is the wrapped callback that it will
66 // use to communicate with us (AndroidOverlayCallback).
67 // Note: one generally doesn't want to call this directly. Use
68 // AndroidOverlayProviderProxy instead.
69 AndroidOverlayProxy(const base::android::JavaRef<jobject>& unwrapped_surface,
70 std::unique_ptr<AndroidOverlayCallback> callback);
71 ~AndroidOverlayProxy();
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. AndroidOverlayCallback
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 AndroidOverlayWrapper 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 AndroidOverlayCallback once the object is deleted.
100 std::unique_ptr<AndroidOverlayCallback> wrapped_callback_;
101
102 gl::ScopedJavaSurface android_surface_;
103
104 base::ThreadChecker thread_checker_;
105
106 DISALLOW_COPY_AND_ASSIGN(AndroidOverlayProxy);
107 };
108
109 } // namespace media
110
111 #endif // MEDIA_BASE_ANDROID_ANDROID_OVERLAY_PROXY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698