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

Side by Side Diff: media/base/android/java/src/org/chromium/media/DialogSurfaceManager.java

Issue 2178973004: DialogSurfaceManager implementation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moved jni out of content/app Created 4 years, 4 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 package org.chromium.media;
6
7 import android.os.Handler;
8 import android.os.HandlerThread;
9 import android.os.IBinder;
10
11 import org.chromium.base.annotations.CalledByNative;
12 import org.chromium.base.annotations.JNINamespace;
13
14 /**
15 * Singleton class to create and manage DialogSurface. Normally, you won't need
16 * to access this directly. Instead, see the native wrappers in
17 * dialog_surface_manager.cc for usage.
18 *
19 * The wrappers do roughly the following on the gpu side:
20 * - Create an IDialogSurfaceCallback. For native, DialogSurfaceCallback hides
21 * the threading issues and provides the java peer.
22 * - Get an IDialogSurfaceManager from the browser via ChildProcessCallback .
23 * - dialogSurface = IDialogSurfaceManager.createSurface(callback)
24 * This calls into the browser, and returns an IDialogSurface IBinder.
25 * - Wrap the DialogSurface in a DialogSurfaceWrapper. This provides the JNI
26 * bindings for native.
27 * - Expect callbacks on the callback to let you know when the underlying
28 * android surface state changes.
29 * - Use the surface.
30 * - Call IDialogSurface::release() to destroy the surface when done.
31 */
32 @JNINamespace("media")
33 public class DialogSurfaceManager extends IDialogSurfaceManager.Stub {
34 private static final String TAG = "cr_media";
35 private static DialogSurfaceManager sInstance;
36
37 // We maintain a thread with a Looper for the DialogSurfaces to use,
38 // since Dialog requires one. We don't want this to be the native thread
39 // that's used to create them, because it probably also has a native message
40 // loop. Including a looper on it is not a good idea.
41 private HandlerThread mThread;
42 private Handler mHandler;
43 private IDialogSurfaceActivityMapper mMapper;
44
45 // Number of DialogSurfaces that have been created but not released.
46 private int mNumSurfaces;
47
48 // Maximum number of concurrent surfaces we allow.
49 private static final int sMaxSurfaces = 1;
50
51 private DialogSurfaceManager(IDialogSurfaceActivityMapper mapper) {
52 mMapper = mapper;
53 mNumSurfaces = 0;
54 }
55
56 public static IBinder instance(IDialogSurfaceActivityMapper mapper) {
57 if (sInstance == null) sInstance = new DialogSurfaceManager(mapper);
58
59 return sInstance.asBinder();
60 }
61
62 @Override
63 @CalledByNative
watk 2016/07/26 21:34:30 not called by native?
liberato (no reviews please) 2016/07/26 22:49:16 it should be, but i removed it for this CL. Dialo
64 public IDialogSurface createSurface(int rendererPid, int renderFrameId,
65 IDialogSurfaceCallback callback, int x, int y, int width, int height ) {
66 // Limit the number of concurrent surfaces.
67 if (mNumSurfaces >= sMaxSurfaces) return null;
68
69 ensureThread();
70
71 mNumSurfaces++;
72
73 // TODO(liberato): would instantiate DialogSurface here.
74 return null;
75 }
76
77 /**
78 * Called by DialogSurfaces when they no longer need the thread.
79 */
80 public void notifyReleased() {
81 if (mNumSurfaces > 0) mNumSurfaces--;
watk 2016/07/26 21:34:30 Is there a valid way for mNumSurfaces to be negati
liberato (no reviews please) 2016/07/26 22:49:16 it should not be negative.
82
83 // We don't stop the looper thread here, else android can get mad when
84 // it tries to send a message from the dialog on this thread.
85 // DialogSurface might have to notify us separately to tell us
86 // when it's done with the thread, if we don't want to wait until then
87 // to start creating a new SV.
88 // Instead, we just avoid shutting down the thread at all for now.
89 /*
90 if (mNumSurfaces == 0) {
91 mThread.quitSafely();
92 mThread = null;
93 mHandler = null;
94 }
95 */
watk 2016/07/26 21:34:30 delete?
liberato (no reviews please) 2016/07/26 22:49:16 yeah, you're right.
96 }
97
98 /**
99 * Make sure that mThread and mHandler are ready for use.
100 */
101 private void ensureThread() {
102 // Called on main thread only.
103 if (mThread != null) return;
104
105 mThread = new HandlerThread("DialogSurfaceThread");
106 mThread.start();
107 mHandler = new Handler(mThread.getLooper());
108 }
109
110 /**
111 * Return the activity mapper.
112 */
113 public IDialogSurfaceActivityMapper getMapper() {
114 return mMapper;
115 }
116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698