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