OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.compositor; | 5 package org.chromium.chrome.browser.compositor; |
6 | 6 |
7 import android.app.Activity; | 7 import android.app.Activity; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.graphics.Color; | 9 import android.graphics.Color; |
10 import android.graphics.PixelFormat; | 10 import android.graphics.PixelFormat; |
11 import android.graphics.Rect; | 11 import android.graphics.Rect; |
| 12 import android.graphics.drawable.Drawable; |
12 import android.os.Build; | 13 import android.os.Build; |
13 import android.view.Display; | 14 import android.view.Display; |
14 import android.view.MotionEvent; | 15 import android.view.MotionEvent; |
15 import android.view.Surface; | 16 import android.view.Surface; |
16 import android.view.SurfaceHolder; | 17 import android.view.SurfaceHolder; |
17 import android.view.SurfaceView; | 18 import android.view.SurfaceView; |
18 import android.view.View; | 19 import android.view.View; |
19 import android.view.WindowManager; | 20 import android.view.WindowManager; |
| 21 import android.widget.FrameLayout; |
20 | 22 |
21 import org.chromium.base.CommandLine; | 23 import org.chromium.base.CommandLine; |
22 import org.chromium.base.Log; | |
23 import org.chromium.base.TraceEvent; | 24 import org.chromium.base.TraceEvent; |
24 import org.chromium.base.annotations.CalledByNative; | 25 import org.chromium.base.annotations.CalledByNative; |
25 import org.chromium.base.annotations.JNINamespace; | 26 import org.chromium.base.annotations.JNINamespace; |
26 import org.chromium.base.annotations.UsedByReflection; | 27 import org.chromium.base.annotations.UsedByReflection; |
27 import org.chromium.chrome.browser.ChromeSwitches; | 28 import org.chromium.chrome.browser.ChromeSwitches; |
28 import org.chromium.chrome.browser.compositor.layouts.Layout; | 29 import org.chromium.chrome.browser.compositor.layouts.Layout; |
29 import org.chromium.chrome.browser.compositor.layouts.LayoutProvider; | 30 import org.chromium.chrome.browser.compositor.layouts.LayoutProvider; |
30 import org.chromium.chrome.browser.compositor.layouts.LayoutRenderHost; | 31 import org.chromium.chrome.browser.compositor.layouts.LayoutRenderHost; |
31 import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager; | 32 import org.chromium.chrome.browser.compositor.layouts.content.TabContentManager; |
32 import org.chromium.chrome.browser.compositor.resources.StaticResourcePreloads; | 33 import org.chromium.chrome.browser.compositor.resources.StaticResourcePreloads; |
33 import org.chromium.chrome.browser.compositor.scene_layer.SceneLayer; | 34 import org.chromium.chrome.browser.compositor.scene_layer.SceneLayer; |
34 import org.chromium.chrome.browser.externalnav.IntentWithGesturesHandler; | 35 import org.chromium.chrome.browser.externalnav.IntentWithGesturesHandler; |
35 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; | 36 import org.chromium.chrome.browser.multiwindow.MultiWindowUtils; |
36 import org.chromium.chrome.browser.tabmodel.TabModelImpl; | 37 import org.chromium.chrome.browser.tabmodel.TabModelImpl; |
37 import org.chromium.chrome.browser.widget.ClipDrawableProgressBar.DrawingInfo; | 38 import org.chromium.chrome.browser.widget.ClipDrawableProgressBar.DrawingInfo; |
38 import org.chromium.ui.base.DeviceFormFactor; | 39 import org.chromium.ui.base.DeviceFormFactor; |
39 import org.chromium.ui.base.WindowAndroid; | 40 import org.chromium.ui.base.WindowAndroid; |
40 import org.chromium.ui.resources.AndroidResourceType; | 41 import org.chromium.ui.resources.AndroidResourceType; |
41 import org.chromium.ui.resources.ResourceManager; | 42 import org.chromium.ui.resources.ResourceManager; |
42 | 43 |
43 import java.util.ArrayList; | 44 import java.util.ArrayList; |
44 import java.util.List; | 45 import java.util.List; |
45 | 46 |
46 /** | 47 /** |
47 * The is the {@link View} displaying the ui compositor results; including webpa
ges and tabswitcher. | 48 * The is the {@link View} displaying the ui compositor results; including webpa
ges and tabswitcher. |
48 */ | 49 */ |
49 @JNINamespace("android") | 50 @JNINamespace("android") |
50 public class CompositorView extends SurfaceView implements SurfaceHolder.Callbac
k2 { | 51 public class CompositorView extends FrameLayout implements SurfaceHolder.Callbac
k2 { |
51 private static final String TAG = "CompositorView"; | 52 private static final String TAG = "CompositorView"; |
52 private static final long NANOSECONDS_PER_MILLISECOND = 1000000; | 53 private static final long NANOSECONDS_PER_MILLISECOND = 1000000; |
53 | 54 |
54 // Cache objects that should not be created every frame | 55 // Cache objects that should not be created every frame |
55 private final Rect mCacheAppRect = new Rect(); | 56 private final Rect mCacheAppRect = new Rect(); |
56 private final int[] mCacheViewPosition = new int[2]; | 57 private final int[] mCacheViewPosition = new int[2]; |
57 | 58 |
| 59 private CompositorSurfaceManager mCompositorSurfaceManager; |
| 60 private boolean mOverlayVideoEnabled; |
| 61 private boolean mAlwaysTranslucent; |
| 62 |
| 63 // Are we waiting to hide the outgoing surface until the foreground has some
thing to display? |
| 64 // If == 0, then no. If > 0, then yes. We'll hide when it transitions from
one to zero. |
| 65 private int mFramesUntilHideBackground; |
| 66 |
58 private long mNativeCompositorView; | 67 private long mNativeCompositorView; |
59 private final LayoutRenderHost mRenderHost; | 68 private final LayoutRenderHost mRenderHost; |
60 private boolean mEnableTabletTabStack; | 69 private boolean mEnableTabletTabStack; |
61 private int mPreviousWindowTop = -1; | 70 private int mPreviousWindowTop = -1; |
62 | 71 |
63 // A conservative estimate of when a frame is guaranteed to be presented aft
er being submitted. | 72 // A conservative estimate of when a frame is guaranteed to be presented aft
er being submitted. |
64 private long mFramePresentationDelay; | 73 private long mFramePresentationDelay; |
65 | 74 |
66 // Resource Management | 75 // Resource Management |
67 private ResourceManager mResourceManager; | 76 private ResourceManager mResourceManager; |
68 | 77 |
69 // Lazily populated as it is needed. | 78 // Lazily populated as it is needed. |
70 private View mRootActivityView; | 79 private View mRootActivityView; |
71 private WindowAndroid mWindowAndroid; | 80 private WindowAndroid mWindowAndroid; |
72 private LayerTitleCache mLayerTitleCache; | 81 private LayerTitleCache mLayerTitleCache; |
73 private TabContentManager mTabContentManager; | 82 private TabContentManager mTabContentManager; |
74 | 83 |
75 private View mRootView; | 84 private View mRootView; |
76 private int mSurfaceWidth; | |
77 private int mSurfaceHeight; | |
78 private boolean mPreloadedResources; | 85 private boolean mPreloadedResources; |
79 private List<Runnable> mDrawingFinishedCallbacks; | 86 private List<Runnable> mDrawingFinishedCallbacks; |
80 | 87 |
81 // The current SurfaceView pixel format. Defaults to OPAQUE. | |
82 private int mCurrentPixelFormat = PixelFormat.OPAQUE; | |
83 | |
84 /** | 88 /** |
85 * Creates a {@link CompositorView}. This can be called only after the nativ
e library is | 89 * Creates a {@link CompositorView}. This can be called only after the nativ
e library is |
86 * properly loaded. | 90 * properly loaded. |
87 * @param c The Context to create this {@link CompositorView} in. | 91 * @param c The Context to create this {@link CompositorView} in. |
88 * @param host The renderer host owning this view. | 92 * @param host The renderer host owning this view. |
89 */ | 93 */ |
90 public CompositorView(Context c, LayoutRenderHost host) { | 94 public CompositorView(Context c, LayoutRenderHost host) { |
91 super(c); | 95 super(c); |
92 mRenderHost = host; | 96 mRenderHost = host; |
93 resetFlags(); | 97 resetFlags(); |
| 98 |
94 setVisibility(View.INVISIBLE); | 99 setVisibility(View.INVISIBLE); |
95 setZOrderMediaOverlay(true); | |
96 } | 100 } |
97 | 101 |
98 /** | 102 /** |
99 * @param view The root view of the hierarchy. | 103 * @param view The root view of the hierarchy. |
100 */ | 104 */ |
101 public void setRootView(View view) { | 105 public void setRootView(View view) { |
102 mRootView = view; | 106 mRootView = view; |
103 } | 107 } |
104 | 108 |
105 /** | 109 /** |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 * @return The ResourceManager. | 158 * @return The ResourceManager. |
155 */ | 159 */ |
156 public ResourceManager getResourceManager() { | 160 public ResourceManager getResourceManager() { |
157 return mResourceManager; | 161 return mResourceManager; |
158 } | 162 } |
159 | 163 |
160 /** | 164 /** |
161 * Should be called for cleanup when the CompositorView instance is no longe
r used. | 165 * Should be called for cleanup when the CompositorView instance is no longe
r used. |
162 */ | 166 */ |
163 public void shutDown() { | 167 public void shutDown() { |
164 getHolder().removeCallback(this); | 168 mCompositorSurfaceManager.shutDown(); |
165 if (mNativeCompositorView != 0) nativeDestroy(mNativeCompositorView); | 169 if (mNativeCompositorView != 0) nativeDestroy(mNativeCompositorView); |
166 mNativeCompositorView = 0; | 170 mNativeCompositorView = 0; |
167 } | 171 } |
168 | 172 |
169 /** | 173 /** |
170 * Initializes the {@link CompositorView}'s native parts (e.g. the rendering
parts). | 174 * Initializes the {@link CompositorView}'s native parts (e.g. the rendering
parts). |
171 * @param lowMemDevice If this is a low memory device. | 175 * @param lowMemDevice If this is a low memory device. |
172 * @param windowAndroid A {@link WindowAndroid} instance. | 176 * @param windowAndroid A {@link WindowAndroid} instance. |
173 * @param layerTitleCache A {@link LayerTitleCache} instance. | 177 * @param layerTitleCache A {@link LayerTitleCache} instance. |
174 * @param tabContentManager A {@link TabContentManager} instance. | 178 * @param tabContentManager A {@link TabContentManager} instance. |
175 */ | 179 */ |
176 public void initNativeCompositor(boolean lowMemDevice, WindowAndroid windowA
ndroid, | 180 public void initNativeCompositor(boolean lowMemDevice, WindowAndroid windowA
ndroid, |
177 LayerTitleCache layerTitleCache, TabContentManager tabContentManager
) { | 181 LayerTitleCache layerTitleCache, TabContentManager tabContentManager
) { |
178 mWindowAndroid = windowAndroid; | 182 mWindowAndroid = windowAndroid; |
179 mLayerTitleCache = layerTitleCache; | 183 mLayerTitleCache = layerTitleCache; |
180 mTabContentManager = tabContentManager; | 184 mTabContentManager = tabContentManager; |
181 | 185 |
182 mNativeCompositorView = nativeInit(lowMemDevice, | 186 mNativeCompositorView = nativeInit(lowMemDevice, |
183 windowAndroid.getNativePointer(), layerTitleCache, tabContentMan
ager); | 187 windowAndroid.getNativePointer(), layerTitleCache, tabContentMan
ager); |
184 | 188 |
185 assert !getHolder().getSurface().isValid() | 189 // compositor_impl_android.cc will use 565 EGL surfaces if and only if w
e're using a low |
186 : "Surface created before native library loaded."; | 190 // memory device, and no alpha channel is desired. Otherwise, it will u
se 8888. Since |
187 getHolder().addCallback(this); | 191 // SurfaceFlinger doesn't need the eOpaque flag to optimize out alpha bl
ending during |
| 192 // composition if the buffer has no alpha channel, we can avoid using th
e extra background |
| 193 // surface (and the memory it requires) in the low memory case. The out
put buffer will |
| 194 // either have an alpha channel or not, depending on whether the composi
tor needs it. We |
| 195 // can keep the surface translucent all the times without worrying about
the impact on power |
| 196 // usage during SurfaceFlinger composition. We might also want to set |m
AlwaysTranslucent| |
| 197 // on non-low memory devices, if we are running on hardware that impleme
nts efficient alpha |
| 198 // blending. |
| 199 mAlwaysTranslucent = lowMemDevice; |
| 200 |
| 201 mCompositorSurfaceManager = new CompositorSurfaceManager(this, this); |
| 202 // In case the background drawable was set before now, update it. |
| 203 mCompositorSurfaceManager.setBackgroundDrawable(getBackground()); |
| 204 mCompositorSurfaceManager.setWillNotDraw(willNotDraw()); |
| 205 mCompositorSurfaceManager.requestSurface(getSurfacePixelFormat()); |
| 206 mCompositorSurfaceManager.setVisibility(getVisibility()); |
188 | 207 |
189 // Cover the black surface before it has valid content. | 208 // Cover the black surface before it has valid content. |
190 setBackgroundColor(Color.WHITE); | 209 setBackgroundColor(Color.WHITE); |
191 setVisibility(View.VISIBLE); | 210 setVisibility(View.VISIBLE); |
192 | 211 |
193 mFramePresentationDelay = 0; | 212 mFramePresentationDelay = 0; |
194 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { | 213 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { |
195 Display display = | 214 Display display = |
196 ((WindowManager) getContext().getSystemService(Context.WINDO
W_SERVICE)) | 215 ((WindowManager) getContext().getSystemService(Context.WINDO
W_SERVICE)) |
197 .getDefaultDisplay(); | 216 .getDefaultDisplay(); |
(...skipping 10 matching lines...) Expand all Loading... |
208 // Redraw in case there are callbacks pending |mDrawingFinishedCallbacks
|. | 227 // Redraw in case there are callbacks pending |mDrawingFinishedCallbacks
|. |
209 nativeSetNeedsComposite(mNativeCompositorView); | 228 nativeSetNeedsComposite(mNativeCompositorView); |
210 } | 229 } |
211 | 230 |
212 @Override | 231 @Override |
213 public boolean onTouchEvent(MotionEvent e) { | 232 public boolean onTouchEvent(MotionEvent e) { |
214 return super.onTouchEvent(e); | 233 return super.onTouchEvent(e); |
215 } | 234 } |
216 | 235 |
217 /** | 236 /** |
| 237 * @see SurfaceView#getHolder |
| 238 */ |
| 239 SurfaceHolder getHolder() { |
| 240 return mCompositorSurfaceManager.getHolder(); |
| 241 } |
| 242 |
| 243 /** |
218 * Enables/disables overlay video mode. Affects alpha blending on this view. | 244 * Enables/disables overlay video mode. Affects alpha blending on this view. |
219 * @param enabled Whether to enter or leave overlay video mode. | 245 * @param enabled Whether to enter or leave overlay video mode. |
220 */ | 246 */ |
221 public void setOverlayVideoMode(boolean enabled) { | 247 public void setOverlayVideoMode(boolean enabled) { |
222 mCurrentPixelFormat = enabled ? PixelFormat.TRANSLUCENT : PixelFormat.OP
AQUE; | |
223 getHolder().setFormat(mCurrentPixelFormat); | |
224 nativeSetOverlayVideoMode(mNativeCompositorView, enabled); | 248 nativeSetOverlayVideoMode(mNativeCompositorView, enabled); |
| 249 |
| 250 mOverlayVideoEnabled = enabled; |
| 251 // Request the new surface, even if it's the same as the old one. We'll
get a synthetic |
| 252 // destroy / create / changed callback in that case, possibly before thi
s returns. |
| 253 mCompositorSurfaceManager.requestSurface(getSurfacePixelFormat()); |
| 254 // Note that we don't know if we'll get a surfaceCreated / surfaceDestoy
ed for this surface. |
| 255 // We do know that if we do get one, then it will be for the surface tha
t we just requested. |
| 256 } |
| 257 |
| 258 private int getSurfacePixelFormat() { |
| 259 return (mOverlayVideoEnabled || mAlwaysTranslucent) ? PixelFormat.TRANSL
UCENT |
| 260 : PixelFormat.OPAQUE
; |
225 } | 261 } |
226 | 262 |
227 @Override | 263 @Override |
228 public void surfaceRedrawNeeded(SurfaceHolder holder) { | 264 public void surfaceRedrawNeeded(SurfaceHolder holder) { |
229 // Intentionally not implemented. | 265 // Intentionally not implemented. |
230 } | 266 } |
231 | 267 |
232 // TODO(boliu): Mark this override instead. | 268 // TODO(boliu): Mark this override instead. |
233 @UsedByReflection("Android") | 269 @UsedByReflection("Android") |
234 public void surfaceRedrawNeededAsync(SurfaceHolder holder, Runnable drawingF
inished) { | 270 public void surfaceRedrawNeededAsync(SurfaceHolder holder, Runnable drawingF
inished) { |
235 if (mDrawingFinishedCallbacks == null) mDrawingFinishedCallbacks = new A
rrayList<>(); | 271 if (mDrawingFinishedCallbacks == null) mDrawingFinishedCallbacks = new A
rrayList<>(); |
236 mDrawingFinishedCallbacks.add(drawingFinished); | 272 mDrawingFinishedCallbacks.add(drawingFinished); |
237 if (mNativeCompositorView != 0) nativeSetNeedsComposite(mNativeComposito
rView); | 273 if (mNativeCompositorView != 0) nativeSetNeedsComposite(mNativeComposito
rView); |
238 } | 274 } |
239 | 275 |
240 @Override | 276 @Override |
241 public void surfaceChanged(SurfaceHolder holder, int format, int width, int
height) { | 277 public void surfaceChanged(SurfaceHolder holder, int format, int width, int
height) { |
242 if (mNativeCompositorView == 0) return; | 278 if (mNativeCompositorView == 0) return; |
| 279 |
243 nativeSurfaceChanged(mNativeCompositorView, format, width, height, holde
r.getSurface()); | 280 nativeSurfaceChanged(mNativeCompositorView, format, width, height, holde
r.getSurface()); |
244 mRenderHost.onPhysicalBackingSizeChanged(width, height); | 281 mRenderHost.onPhysicalBackingSizeChanged(width, height); |
245 mSurfaceWidth = width; | |
246 mSurfaceHeight = height; | |
247 } | 282 } |
248 | 283 |
249 @Override | 284 @Override |
250 public void surfaceCreated(SurfaceHolder holder) { | 285 public void surfaceCreated(SurfaceHolder holder) { |
251 if (mNativeCompositorView == 0) return; | 286 if (mNativeCompositorView == 0) return; |
| 287 |
252 nativeSurfaceCreated(mNativeCompositorView); | 288 nativeSurfaceCreated(mNativeCompositorView); |
| 289 mFramesUntilHideBackground = 2; |
253 mRenderHost.onSurfaceCreated(); | 290 mRenderHost.onSurfaceCreated(); |
254 } | 291 } |
255 | 292 |
256 @Override | 293 @Override |
257 public void surfaceDestroyed(SurfaceHolder holder) { | 294 public void surfaceDestroyed(SurfaceHolder holder) { |
258 if (mNativeCompositorView == 0) return; | 295 if (mNativeCompositorView == 0) return; |
| 296 |
259 nativeSurfaceDestroyed(mNativeCompositorView); | 297 nativeSurfaceDestroyed(mNativeCompositorView); |
260 } | 298 } |
261 | 299 |
262 @Override | 300 @Override |
263 public void onWindowVisibilityChanged(int visibility) { | 301 public void onWindowVisibilityChanged(int visibility) { |
264 super.onWindowVisibilityChanged(visibility); | 302 super.onWindowVisibilityChanged(visibility); |
265 if (mWindowAndroid == null) return; | 303 if (mWindowAndroid == null) return; |
266 if (visibility == View.GONE) { | 304 if (visibility == View.GONE) { |
267 mWindowAndroid.onVisibilityChanged(false); | 305 mWindowAndroid.onVisibilityChanged(false); |
268 } else if (visibility == View.VISIBLE) { | 306 } else if (visibility == View.VISIBLE) { |
269 mWindowAndroid.onVisibilityChanged(true); | 307 mWindowAndroid.onVisibilityChanged(true); |
270 } | 308 } |
271 IntentWithGesturesHandler.getInstance().clear(); | 309 IntentWithGesturesHandler.getInstance().clear(); |
272 } | 310 } |
273 | 311 |
274 @CalledByNative | 312 @CalledByNative |
275 private void onCompositorLayout() { | 313 private void onCompositorLayout() { |
276 mRenderHost.onCompositorLayout(); | 314 mRenderHost.onCompositorLayout(); |
277 } | 315 } |
278 | 316 |
279 /* | 317 /* |
280 * On JellyBean there is a known bug where a crashed producer process | 318 * On JellyBean there is a known bug where a crashed producer process |
281 * (i.e. GPU process) does not properly disconnect from the BufferQueue, | 319 * (i.e. GPU process) does not properly disconnect from the BufferQueue, |
282 * which means we won't be able to reconnect to it ever again. | 320 * which means we won't be able to reconnect to it ever again. |
283 * This workaround forces the creation of a new Surface. | 321 * This workaround forces the creation of a new Surface. |
284 */ | 322 */ |
285 @CalledByNative | 323 @CalledByNative |
286 private void onJellyBeanSurfaceDisconnectWorkaround(boolean inOverlayMode) { | 324 private void onJellyBeanSurfaceDisconnectWorkaround(boolean inOverlayMode) { |
287 // There is a bug in JellyBean because of which we will not be able to | 325 mCompositorSurfaceManager.recreateSurfaceForJellyBean(); |
288 // reconnect to the existing Surface after we launch a new GPU process. | |
289 // We simply trick the JB Android code to allocate a new Surface. | |
290 // It does a strict comparison between the current format and the reques
ted | |
291 // one, even if they are the same in practice. Furthermore, the format | |
292 // does not matter here since the producer-side EGL config overwrites it | |
293 // (but transparency might matter). | |
294 switch (mCurrentPixelFormat) { | |
295 case PixelFormat.OPAQUE: | |
296 mCurrentPixelFormat = PixelFormat.RGBA_8888; | |
297 break; | |
298 case PixelFormat.RGBA_8888: | |
299 mCurrentPixelFormat = inOverlayMode | |
300 ? PixelFormat.TRANSLUCENT : PixelFormat.OPAQUE; | |
301 break; | |
302 case PixelFormat.TRANSLUCENT: | |
303 mCurrentPixelFormat = PixelFormat.RGBA_8888; | |
304 break; | |
305 default: | |
306 assert false; | |
307 Log.e(TAG, "Unknown current pixel format."); | |
308 } | |
309 getHolder().setFormat(mCurrentPixelFormat); | |
310 } | 326 } |
311 | 327 |
312 /** | 328 /** |
313 * Request compositor view to render a frame. | 329 * Request compositor view to render a frame. |
314 */ | 330 */ |
315 public void requestRender() { | 331 public void requestRender() { |
316 if (mNativeCompositorView != 0) nativeSetNeedsComposite(mNativeComposito
rView); | 332 if (mNativeCompositorView != 0) nativeSetNeedsComposite(mNativeComposito
rView); |
317 } | 333 } |
318 | 334 |
319 @CalledByNative | 335 @CalledByNative |
320 private void didSwapFrame(int pendingFrameCount) { | 336 private void didSwapFrame(int pendingFrameCount) { |
321 // Clear the color used to cover the uninitialized surface. | 337 // Clear the color used to cover the uninitialized surface. |
322 if (getBackground() != null) { | 338 if (getBackground() != null) { |
323 postDelayed(new Runnable() { | 339 postDelayed(new Runnable() { |
324 @Override | 340 @Override |
325 public void run() { | 341 public void run() { |
326 setBackgroundResource(0); | 342 setBackgroundResource(0); |
327 } | 343 } |
328 }, mFramePresentationDelay); | 344 }, mFramePresentationDelay); |
329 } | 345 } |
330 | 346 |
331 mRenderHost.didSwapFrame(pendingFrameCount); | 347 mRenderHost.didSwapFrame(pendingFrameCount); |
332 } | 348 } |
333 | 349 |
334 @CalledByNative | 350 @CalledByNative |
335 private void didSwapBuffers() { | 351 private void didSwapBuffers() { |
| 352 // If we're in the middle of a surface swap, then see if we've received
a new frame yet for |
| 353 // the new surface before hiding the outgoing surface. |
| 354 if (mFramesUntilHideBackground > 1) { |
| 355 // We need at least one more frame before we hide the outgoing surfa
ce. Make sure that |
| 356 // there will be a frame. |
| 357 mFramesUntilHideBackground--; |
| 358 requestRender(); |
| 359 } else if (mFramesUntilHideBackground == 1) { |
| 360 // We can hide the outgoing surface, since the incoming one has a fr
ame. It's okay if |
| 361 // we've don't have an unowned surface. |
| 362 mFramesUntilHideBackground = 0; |
| 363 mCompositorSurfaceManager.doneWithUnownedSurface(); |
| 364 } |
| 365 |
336 List<Runnable> runnables = mDrawingFinishedCallbacks; | 366 List<Runnable> runnables = mDrawingFinishedCallbacks; |
337 mDrawingFinishedCallbacks = null; | 367 mDrawingFinishedCallbacks = null; |
338 if (runnables == null) return; | 368 if (runnables == null) return; |
339 for (Runnable r : runnables) { | 369 for (Runnable r : runnables) { |
340 r.run(); | 370 r.run(); |
341 } | 371 } |
342 } | 372 } |
343 | 373 |
344 /** | 374 /** |
345 * Converts the layout into compositor layers. This is to be called on every
frame the layout | 375 * Converts the layout into compositor layers. This is to be called on every
frame the layout |
(...skipping 28 matching lines...) Expand all Loading... |
374 provider.getUpdatedActiveSceneLayer(mLayerTitleCache, mTabConten
tManager, | 404 provider.getUpdatedActiveSceneLayer(mLayerTitleCache, mTabConten
tManager, |
375 mResourceManager, provider.getFullscreenManager()); | 405 mResourceManager, provider.getFullscreenManager()); |
376 | 406 |
377 nativeSetSceneLayer(mNativeCompositorView, sceneLayer); | 407 nativeSetSceneLayer(mNativeCompositorView, sceneLayer); |
378 | 408 |
379 TabModelImpl.flushActualTabSwitchLatencyMetric(); | 409 TabModelImpl.flushActualTabSwitchLatencyMetric(); |
380 nativeFinalizeLayers(mNativeCompositorView); | 410 nativeFinalizeLayers(mNativeCompositorView); |
381 TraceEvent.end("CompositorView:finalizeLayers"); | 411 TraceEvent.end("CompositorView:finalizeLayers"); |
382 } | 412 } |
383 | 413 |
| 414 @Override |
| 415 public void setWillNotDraw(boolean willNotDraw) { |
| 416 if (mCompositorSurfaceManager != null) { |
| 417 mCompositorSurfaceManager.setWillNotDraw(willNotDraw); |
| 418 } |
| 419 } |
| 420 |
| 421 @Override |
| 422 public void setBackgroundDrawable(Drawable background) { |
| 423 // We override setBackgroundDrawable since that's the common entry point
from all the |
| 424 // setBackground* calls in View. We still call to setBackground on the
SurfaceView because |
| 425 // SetBackgroundDrawable is deprecated, and the semantics are the same I
think. |
| 426 super.setBackgroundDrawable(background); |
| 427 if (mCompositorSurfaceManager != null) { |
| 428 mCompositorSurfaceManager.setBackgroundDrawable(background); |
| 429 } |
| 430 } |
| 431 |
| 432 @Override |
| 433 public void setVisibility(int visibility) { |
| 434 super.setVisibility(visibility); |
| 435 // Also set the visibility on any child SurfaceViews, since that hides |
| 436 // the surface as well. Otherwise, the surface is kept, which can |
| 437 // interfere with VR. |
| 438 if (mCompositorSurfaceManager != null) { |
| 439 mCompositorSurfaceManager.setVisibility(visibility); |
| 440 } |
| 441 } |
| 442 |
384 // Implemented in native | 443 // Implemented in native |
385 private native long nativeInit(boolean lowMemDevice, long nativeWindowAndroi
d, | 444 private native long nativeInit(boolean lowMemDevice, long nativeWindowAndroi
d, |
386 LayerTitleCache layerTitleCache, TabContentManager tabContentManager
); | 445 LayerTitleCache layerTitleCache, TabContentManager tabContentManager
); |
387 private native void nativeDestroy(long nativeCompositorView); | 446 private native void nativeDestroy(long nativeCompositorView); |
388 private native ResourceManager nativeGetResourceManager(long nativeComposito
rView); | 447 private native ResourceManager nativeGetResourceManager(long nativeComposito
rView); |
389 private native void nativeSurfaceCreated(long nativeCompositorView); | 448 private native void nativeSurfaceCreated(long nativeCompositorView); |
390 private native void nativeSurfaceDestroyed(long nativeCompositorView); | 449 private native void nativeSurfaceDestroyed(long nativeCompositorView); |
391 private native void nativeSurfaceChanged( | 450 private native void nativeSurfaceChanged( |
392 long nativeCompositorView, int format, int width, int height, Surfac
e surface); | 451 long nativeCompositorView, int format, int width, int height, Surfac
e surface); |
393 private native void nativeFinalizeLayers(long nativeCompositorView); | 452 private native void nativeFinalizeLayers(long nativeCompositorView); |
394 private native void nativeSetNeedsComposite(long nativeCompositorView); | 453 private native void nativeSetNeedsComposite(long nativeCompositorView); |
395 private native void nativeSetLayoutBounds(long nativeCompositorView); | 454 private native void nativeSetLayoutBounds(long nativeCompositorView); |
396 private native void nativeSetOverlayVideoMode(long nativeCompositorView, boo
lean enabled); | 455 private native void nativeSetOverlayVideoMode(long nativeCompositorView, boo
lean enabled); |
397 private native void nativeSetSceneLayer(long nativeCompositorView, SceneLaye
r sceneLayer); | 456 private native void nativeSetSceneLayer(long nativeCompositorView, SceneLaye
r sceneLayer); |
398 } | 457 } |
OLD | NEW |