ThreadedRenderer.java revision 33eb07f5759b85a5617f8057d8a335019c7d24dd
1cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck/* 2cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * Copyright (C) 2013 The Android Open Source Project 3cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * 4cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * Licensed under the Apache License, Version 2.0 (the "License"); 5cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * you may not use this file except in compliance with the License. 6cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * You may obtain a copy of the License at 7cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * 8cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * http://www.apache.org/licenses/LICENSE-2.0 9cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * 10cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * Unless required by applicable law or agreed to in writing, software 11cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * distributed under the License is distributed on an "AS IS" BASIS, 12cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * See the License for the specific language governing permissions and 14cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * limitations under the License. 15cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck */ 16cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 17cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckpackage android.view; 18cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 1933eb07f5759b85a5617f8057d8a335019c7d24ddTim Murrayimport android.app.ActivityManagerNative; 20ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckimport android.annotation.IntDef; 212507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craikimport android.annotation.NonNull; 22b8802b1293c05a14399005aeaeb93b82ec2e2f27John Reckimport android.content.Context; 2358c42c3596a2b79184c9a6b7beffc6e94cce112cAlan Viveretteimport android.content.res.TypedArray; 2404fc583c3dd3144bc6b718fcac4b3e1afdfdb067John Reckimport android.graphics.Bitmap; 2550210d912925aef14e4ce69be82e4949122a3cd9Alan Viveretteimport android.graphics.Point; 26ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viveretteimport android.graphics.Rect; 27718cd3eb70703c43f29ca37907bbf0e153d8cca0Doris Liuimport android.graphics.drawable.AnimatedVectorDrawable; 28edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reckimport android.os.Binder; 2906f5bc70a667a02b14e31d3f53f91d3661e30666Andres Moralesimport android.os.Handler; 3066f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reckimport android.os.IBinder; 3106f5bc70a667a02b14e31d3f53f91d3661e30666Andres Moralesimport android.os.Message; 32edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reckimport android.os.ParcelFileDescriptor; 3366f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reckimport android.os.RemoteException; 3466f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reckimport android.os.ServiceManager; 35cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.os.Trace; 3666f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reckimport android.util.Log; 37cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.view.Surface.OutOfResourcesException; 38cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport android.view.View.AttachInfo; 39cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 40ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckimport com.android.internal.R; 4106f5bc70a667a02b14e31d3f53f91d3661e30666Andres Moralesimport com.android.internal.util.VirtualRefBasePtr; 42ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck 4351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reckimport java.io.File; 44fe5e7b7346a54537b980796ceeca66bfdbd05561John Reckimport java.io.FileDescriptor; 45cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reckimport java.io.PrintWriter; 46ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckimport java.lang.annotation.Retention; 47ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reckimport java.lang.annotation.RetentionPolicy; 4806f5bc70a667a02b14e31d3f53f91d3661e30666Andres Moralesimport java.util.HashSet; 49cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 50cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck/** 51cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * Hardware renderer that proxies the rendering to a render thread. Most calls 524f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * are currently synchronous. 53cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * 54cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * The UI thread can block on the RenderThread, but RenderThread must never 55cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * block on the UI thread. 56cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * 574f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * ThreadedRenderer creates an instance of RenderProxy. RenderProxy in turn creates 584f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * and manages a CanvasContext on the RenderThread. The CanvasContext is fully managed 594f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * by the lifecycle of the RenderProxy. 604f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck * 61cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * Note that although currently the EGL context & surfaces are created & managed 62cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * by the render thread, the goal is to move that into a shared structure that can 63cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * be managed by both threads. EGLSurface creation & deletion should ideally be 64cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * done on the UI thread and not the RenderThread to avoid stalling the 65cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * RenderThread with surface buffer allocation. 66cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * 67cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck * @hide 68cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck */ 6951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reckpublic final class ThreadedRenderer { 7051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck private static final String LOG_TAG = "ThreadedRenderer"; 7151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 7251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 7351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Name of the file that holds the shaders cache. 7451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 7551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck private static final String CACHE_PATH_SHADERS = "com.android.opengl.shaders_cache"; 7651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 7751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 7851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * System property used to enable or disable dirty regions invalidation. 7951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * This property is only queried if {@link #RENDER_DIRTY_REGIONS} is true. 8051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * The default value of this property is assumed to be true. 8151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 8251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Possible values: 8351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "true", to enable partial invalidates 8451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "false", to disable partial invalidates 8551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 8651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck static final String RENDER_DIRTY_REGIONS_PROPERTY = "debug.hwui.render_dirty_regions"; 8751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 8851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 8951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * System property used to enable or disable hardware rendering profiling. 9051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * The default value of this property is assumed to be false. 9151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 9251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * When profiling is enabled, the adb shell dumpsys gfxinfo command will 9351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * output extra information about the time taken to execute by the last 9451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * frames. 9551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 9651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Possible values: 9751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "true", to enable profiling 9851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "visual_bars", to enable profiling and visualize the results on screen 9951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "false", to disable profiling 10051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 10151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @see #PROFILE_PROPERTY_VISUALIZE_BARS 10251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 10351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @hide 10451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 10551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static final String PROFILE_PROPERTY = "debug.hwui.profile"; 10651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 10751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 10851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Value for {@link #PROFILE_PROPERTY}. When the property is set to this 10951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * value, profiling data will be visualized on screen as a bar chart. 11051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 11151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @hide 11251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 11351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static final String PROFILE_PROPERTY_VISUALIZE_BARS = "visual_bars"; 11451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 11551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 11651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * System property used to specify the number of frames to be used 11751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * when doing hardware rendering profiling. 11851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * The default value of this property is #PROFILE_MAX_FRAMES. 11951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 12051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * When profiling is enabled, the adb shell dumpsys gfxinfo command will 12151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * output extra information about the time taken to execute by the last 12251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * frames. 12351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 12451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Possible values: 12551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "60", to set the limit of frames to 60 12651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 12751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck static final String PROFILE_MAXFRAMES_PROPERTY = "debug.hwui.profile.maxframes"; 12851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 12951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 13051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * System property used to debug EGL configuration choice. 13151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 13251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Possible values: 13351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "choice", print the chosen configuration only 13451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "all", print all possible configurations 13551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 13651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck static final String PRINT_CONFIG_PROPERTY = "debug.hwui.print_config"; 13751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 13851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 13951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Turn on to draw dirty regions every other frame. 14051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 14151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Possible values: 14251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "true", to enable dirty regions debugging 14351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "false", to disable dirty regions debugging 14451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 14551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @hide 14651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 14751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static final String DEBUG_DIRTY_REGIONS_PROPERTY = "debug.hwui.show_dirty_regions"; 14851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 14951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 15051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Turn on to flash hardware layers when they update. 15151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 15251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Possible values: 15351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "true", to enable hardware layers updates debugging 15451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "false", to disable hardware layers updates debugging 15551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 15651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @hide 15751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 15851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static final String DEBUG_SHOW_LAYERS_UPDATES_PROPERTY = 15951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck "debug.hwui.show_layers_updates"; 16051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 16151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 16251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Controls overdraw debugging. 16351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 16451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Possible values: 16551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "false", to disable overdraw debugging 16651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "show", to show overdraw areas on screen 16751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "count", to display an overdraw counter 16851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 16951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @hide 17051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 17151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static final String DEBUG_OVERDRAW_PROPERTY = "debug.hwui.overdraw"; 17251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 17351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 17451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Value for {@link #DEBUG_OVERDRAW_PROPERTY}. When the property is set to this 17551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * value, overdraw will be shown on screen by coloring pixels. 17651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 17751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @hide 17851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 17951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static final String OVERDRAW_PROPERTY_SHOW = "show"; 18051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 18151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 18251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Turn on to debug non-rectangular clip operations. 18351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 18451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Possible values: 18551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "hide", to disable this debug mode 18651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "highlight", highlight drawing commands tested against a non-rectangular clip 18751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * "stencil", renders the clip region on screen when set 18851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 18951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @hide 19051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 19151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static final String DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY = 19251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck "debug.hwui.show_non_rect_clip"; 19351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 19451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 19551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * A process can set this flag to false to prevent the use of hardware 19651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * rendering. 19751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 19851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @hide 19951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 20051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static boolean sRendererDisabled = false; 20151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 20251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 20351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Further hardware renderer disabling for the system process. 20451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 20551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @hide 20651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 20751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static boolean sSystemRendererDisabled = false; 20851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 20951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 21051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Invoke this method to disable hardware rendering in the current process. 21151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 21251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @hide 21351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 21451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static void disable(boolean system) { 21551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck sRendererDisabled = true; 21651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck if (system) { 21751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck sSystemRendererDisabled = true; 21851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 21951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 22051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 22151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static boolean sTrimForeground = false; 22251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 22351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 22451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Controls whether or not the hardware renderer should aggressively 22551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * trim memory. Note that this must not be set for any process that 22651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * uses WebView! This should be only used by system_process or similar 22751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * that do not go into the background. 22851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 22951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static void enableForegroundTrimming() { 23051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck sTrimForeground = true; 23151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 23251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 23351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 23451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Indicates whether hardware acceleration is available under any form for 23551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * the view hierarchy. 23651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 23751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @return True if the view hierarchy can potentially be hardware accelerated, 23851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * false otherwise 23951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 24051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static boolean isAvailable() { 24151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck return DisplayListCanvas.isAvailable(); 24251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 24351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 24451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 24551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Sets the directory to use as a persistent storage for hardware rendering 24651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * resources. 24751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 24851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param cacheDir A directory the current process can write to 24951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 25051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @hide 25151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 25251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static void setupDiskCache(File cacheDir) { 25351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck ThreadedRenderer.setupShadersDiskCache(new File(cacheDir, CACHE_PATH_SHADERS).getAbsolutePath()); 25451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 25551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 25651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 25751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Creates a hardware renderer using OpenGL. 25851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 25951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param translucent True if the surface is translucent, false otherwise 26051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 26151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @return A hardware renderer backed by OpenGL. 26251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 26351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static ThreadedRenderer create(Context context, boolean translucent) { 26451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck ThreadedRenderer renderer = null; 26551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck if (DisplayListCanvas.isAvailable()) { 26651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck renderer = new ThreadedRenderer(context, translucent); 26751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 26851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck return renderer; 26951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 27051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 27151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 27251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Invoke this method when the system is running out of memory. This 27351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * method will attempt to recover as much memory as possible, based on 27451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * the specified hint. 27551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 27651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param level Hint about the amount of memory that should be trimmed, 27751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * see {@link android.content.ComponentCallbacks} 27851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 27951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static void trimMemory(int level) { 28051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck nTrimMemory(level); 28151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 28251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 28351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static void overrideProperty(@NonNull String name, @NonNull String value) { 28451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck if (name == null || value == null) { 28551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck throw new IllegalArgumentException("name and value must be non-null"); 28651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 28751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck nOverrideProperty(name, value); 28851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 28951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 29051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck public static void dumpProfileData(byte[] data, FileDescriptor fd) { 29151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck nDumpProfileData(data, fd); 29251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 293cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 294f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck // Keep in sync with DrawFrameTask.h SYNC_* flags 295f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck // Nothing interesting to report 296cd028f336e36b22dbe8cf623eb5bd2361314495cJohn Reck private static final int SYNC_OK = 0; 297f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck // Needs a ViewRoot invalidate 298cd028f336e36b22dbe8cf623eb5bd2361314495cJohn Reck private static final int SYNC_INVALIDATE_REQUIRED = 1 << 0; 299aa95a88327d9a3ac8a4a00b065b78ac0f28b3a19John Reck // Spoiler: the reward is GPU-accelerated drawing, better find that Surface! 300aa95a88327d9a3ac8a4a00b065b78ac0f28b3a19John Reck private static final int SYNC_LOST_SURFACE_REWARD_IF_FOUND = 1 << 1; 3019a17da8125c36c82ba73e7f4b3ed80b9c633767fJohn Reck // setStopped is true, drawing is false 3029a17da8125c36c82ba73e7f4b3ed80b9c633767fJohn Reck // TODO: Remove this and SYNC_LOST_SURFACE_REWARD_IF_FOUND? 3039a17da8125c36c82ba73e7f4b3ed80b9c633767fJohn Reck // This flag isn't really used as there's nothing that we care to do 3049a17da8125c36c82ba73e7f4b3ed80b9c633767fJohn Reck // in response, so it really just exists to differentiate from LOST_SURFACE 3059a17da8125c36c82ba73e7f4b3ed80b9c633767fJohn Reck // but possibly both can just be deleted. 3069a17da8125c36c82ba73e7f4b3ed80b9c633767fJohn Reck private static final int SYNC_CONTEXT_IS_STOPPED = 1 << 2; 307f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck 308fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck private static final String[] VISUALIZERS = { 309fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck PROFILE_PROPERTY_VISUALIZE_BARS, 310fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck }; 311fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck 312ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck private static final int FLAG_DUMP_FRAMESTATS = 1 << 0; 313ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck private static final int FLAG_DUMP_RESET = 1 << 1; 314ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck 315ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck @IntDef(flag = true, value = { 316ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck FLAG_DUMP_FRAMESTATS, FLAG_DUMP_RESET }) 317ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck @Retention(RetentionPolicy.SOURCE) 318ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck public @interface DumpFlags {} 319ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck 320ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette // Size of the rendered content. 321cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck private int mWidth, mHeight; 322ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette 323ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette // Actual size of the drawing surface. 324ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette private int mSurfaceWidth, mSurfaceHeight; 325ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette 326ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette // Insets between the drawing surface and rendered content. These are 327ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette // applied as translation when updating the root render node. 328ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette private int mInsetTop, mInsetLeft; 329ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette 33057774a82f02c225941f81cf89c7a03bf899df2c1Alan Viverette // Whether the surface has insets. Used to protect opacity. 33157774a82f02c225941f81cf89c7a03bf899df2c1Alan Viverette private boolean mHasInsets; 33257774a82f02c225941f81cf89c7a03bf899df2c1Alan Viverette 33358c42c3596a2b79184c9a6b7beffc6e94cce112cAlan Viverette // Light and shadow properties specified by the theme. 33458c42c3596a2b79184c9a6b7beffc6e94cce112cAlan Viverette private final float mLightY; 33558c42c3596a2b79184c9a6b7beffc6e94cce112cAlan Viverette private final float mLightZ; 33658c42c3596a2b79184c9a6b7beffc6e94cce112cAlan Viverette private final float mLightRadius; 337058fc640017c90120c599d378a4cbc55668b05b7Chris Craik private final int mAmbientShadowAlpha; 338058fc640017c90120c599d378a4cbc55668b05b7Chris Craik private final int mSpotShadowAlpha; 33958c42c3596a2b79184c9a6b7beffc6e94cce112cAlan Viverette 3404f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck private long mNativeProxy; 341f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck private boolean mInitialized = false; 342bc0cc0220b830df54c8ed41d0b53daffd7f6c991John Reck private RenderNode mRootNode; 34318f16e6fba74eda173e1e7c869e6e2e2acc073ffJohn Reck private Choreographer mChoreographer; 3440a97330b98dd633b58dcfff405d94476c89e867dJohn Reck private boolean mRootNodeNeedsUpdate; 345cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 34651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck private boolean mEnabled; 34751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck private boolean mRequested = true; 34851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 349b8802b1293c05a14399005aeaeb93b82ec2e2f27John Reck ThreadedRenderer(Context context, boolean translucent) { 350ed6f14a20c69da3d221cc1acbaa31e74e837917cAlan Viverette final TypedArray a = context.obtainStyledAttributes(null, R.styleable.Lighting, 0, 0); 35158c42c3596a2b79184c9a6b7beffc6e94cce112cAlan Viverette mLightY = a.getDimension(R.styleable.Lighting_lightY, 0); 35258c42c3596a2b79184c9a6b7beffc6e94cce112cAlan Viverette mLightZ = a.getDimension(R.styleable.Lighting_lightZ, 0); 35358c42c3596a2b79184c9a6b7beffc6e94cce112cAlan Viverette mLightRadius = a.getDimension(R.styleable.Lighting_lightRadius, 0); 354ed6f14a20c69da3d221cc1acbaa31e74e837917cAlan Viverette mAmbientShadowAlpha = 355ed6f14a20c69da3d221cc1acbaa31e74e837917cAlan Viverette (int) (255 * a.getFloat(R.styleable.Lighting_ambientShadowAlpha, 0) + 0.5f); 356ed6f14a20c69da3d221cc1acbaa31e74e837917cAlan Viverette mSpotShadowAlpha = (int) (255 * a.getFloat(R.styleable.Lighting_spotShadowAlpha, 0) + 0.5f); 35758c42c3596a2b79184c9a6b7beffc6e94cce112cAlan Viverette a.recycle(); 35858c42c3596a2b79184c9a6b7beffc6e94cce112cAlan Viverette 359e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck long rootNodePtr = nCreateRootRenderNode(); 360e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck mRootNode = RenderNode.adopt(rootNodePtr); 361bc0cc0220b830df54c8ed41d0b53daffd7f6c991John Reck mRootNode.setClipToBounds(false); 362e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck mNativeProxy = nCreateProxy(translucent, rootNodePtr); 36318f16e6fba74eda173e1e7c869e6e2e2acc073ffJohn Reck 364edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck ProcessInitializer.sInstance.init(context, mNativeProxy); 3653b20251a355c88193c439f928a84ae69483fb488John Reck 366fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck loadSystemProperties(); 367cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 368cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 36951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 37051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Destroys the hardware rendering context. 37151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 372f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck void destroy() { 373f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck mInitialized = false; 374f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck updateEnabledState(null); 375350e65206cfbd86484fcfda77bb988e270606ddaDoris Liu nDestroy(mNativeProxy, mRootNode.mNativeRenderNode); 376cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 377cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 37851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 37951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Indicates whether hardware acceleration is currently enabled. 38051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 38151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @return True if hardware acceleration is in use, false otherwise. 38251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 38351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck boolean isEnabled() { 38451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck return mEnabled; 38551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 38651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 38751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 38851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Indicates whether hardware acceleration is currently enabled. 38951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 39051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param enabled True if the hardware renderer is in use, false otherwise. 39151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 39251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck void setEnabled(boolean enabled) { 39351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck mEnabled = enabled; 39451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 39551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 39651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 39751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Indicates whether hardware acceleration is currently request but not 39851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * necessarily enabled yet. 39951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 40051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @return True if requested, false otherwise. 40151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 40251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck boolean isRequested() { 40351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck return mRequested; 40451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 40551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 40651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 40751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Indicates whether hardware acceleration is currently requested but not 40851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * necessarily enabled yet. 40951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 41051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @return True to request hardware acceleration, false otherwise. 41151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 41251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck void setRequested(boolean requested) { 41351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck mRequested = requested; 41451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 41551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 416f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck private void updateEnabledState(Surface surface) { 417f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck if (surface == null || !surface.isValid()) { 418f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck setEnabled(false); 419f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck } else { 420f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck setEnabled(mInitialized); 421f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck } 422f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck } 423f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck 42451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 42551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Initializes the hardware renderer for the specified surface. 42651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 42751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param surface The surface to hardware accelerate 42851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 42951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @return True if the initialization was successful, false otherwise. 43051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 431cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck boolean initialize(Surface surface) throws OutOfResourcesException { 4320bcd0cb6b1193168fa2840855195347488daab9eThomas Buhot boolean status = !mInitialized; 433f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck mInitialized = true; 434f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck updateEnabledState(surface); 4350bcd0cb6b1193168fa2840855195347488daab9eThomas Buhot nInitialize(mNativeProxy, surface); 4365795d6408d8bf44ffe2f49a25f9f333069b59a49Dan Stoza return status; 437cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 438cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 43951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 44051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Initializes the hardware renderer for the specified surface and setup the 44151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * renderer for drawing, if needed. This is invoked when the ViewAncestor has 44251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * potentially lost the hardware renderer. The hardware renderer should be 44351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * reinitialized and setup when the render {@link #isRequested()} and 44451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * {@link #isEnabled()}. 44551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 44651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param width The width of the drawing surface. 44751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param height The height of the drawing surface. 44851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param attachInfo Information about the window. 44951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param surface The surface to hardware accelerate 45051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param surfaceInsets The drawing surface insets to apply 45151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 45251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @return true if the surface was initialized, false otherwise. Returning 45351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * false might mean that the surface was already initialized. 45451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 45551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck boolean initializeIfNeeded(int width, int height, View.AttachInfo attachInfo, 45651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck Surface surface, Rect surfaceInsets) throws OutOfResourcesException { 45751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck if (isRequested()) { 45851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck // We lost the gl context, so recreate it. 45951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck if (!isEnabled()) { 46051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck if (initialize(surface)) { 46151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck setup(width, height, attachInfo, surfaceInsets); 46251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck return true; 46351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 46451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 46551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 46651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck return false; 46751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 46851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 46951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 47051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Updates the hardware renderer for the specified surface. 47151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 47251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param surface The surface to hardware accelerate 47351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 474cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck void updateSurface(Surface surface) throws OutOfResourcesException { 475f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck updateEnabledState(surface); 4764f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck nUpdateSurface(mNativeProxy, surface); 477cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 478cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 47951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 4808afcc76920499d0a384dba1470c5a377f80ed768John Reck * Halts any current rendering into the surface. Use this if it is unclear whether 48151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * or not the surface used by the HardwareRenderer will be changing. It 4828afcc76920499d0a384dba1470c5a377f80ed768John Reck * Suspends any rendering into the surface, but will not do any destruction. 4838afcc76920499d0a384dba1470c5a377f80ed768John Reck * 4848afcc76920499d0a384dba1470c5a377f80ed768John Reck * Any subsequent draws will override the pause, resuming normal operation. 48551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 48601a5ea35fbba4c5bb1d7790ae1677a2fa752e042John Reck boolean pauseSurface(Surface surface) { 48701a5ea35fbba4c5bb1d7790ae1677a2fa752e042John Reck return nPauseSurface(mNativeProxy, surface); 488f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck } 489f7d9c1dc84671d4e99657ef071d275700d85bb11John Reck 49051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 4918afcc76920499d0a384dba1470c5a377f80ed768John Reck * Hard stops or resumes rendering into the surface. This flag is used to 4928afcc76920499d0a384dba1470c5a377f80ed768John Reck * determine whether or not it is safe to use the given surface *at all* 4938afcc76920499d0a384dba1470c5a377f80ed768John Reck */ 4948afcc76920499d0a384dba1470c5a377f80ed768John Reck void setStopped(boolean stopped) { 4958afcc76920499d0a384dba1470c5a377f80ed768John Reck nSetStopped(mNativeProxy, stopped); 4968afcc76920499d0a384dba1470c5a377f80ed768John Reck } 4978afcc76920499d0a384dba1470c5a377f80ed768John Reck 4988afcc76920499d0a384dba1470c5a377f80ed768John Reck /** 49951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Destroys all hardware rendering resources associated with the specified 50051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * view hierarchy. 50151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 50251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param view The root of the view hierarchy 50351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 504cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck void destroyHardwareResources(View view) { 5054f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck destroyResources(view); 506f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck nDestroyHardwareResources(mNativeProxy); 5074f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck } 5084f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 5094f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck private static void destroyResources(View view) { 5104f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck view.destroyHardwareResources(); 5114f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 5124f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck if (view instanceof ViewGroup) { 5134f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck ViewGroup group = (ViewGroup) view; 5144f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck 5154f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck int count = group.getChildCount(); 5164f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck for (int i = 0; i < count; i++) { 5174f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck destroyResources(group.getChildAt(i)); 5184f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck } 5194f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck } 520cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 521cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 52251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 52351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * This method should be invoked whenever the current hardware renderer 52451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * context should be reset. 52551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 52651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param surface The surface to hardware accelerate 52751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 528cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck void invalidate(Surface surface) { 5294f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck updateSurface(surface); 530cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 531cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 53251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 53351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Detaches the layer's surface texture from the GL context and releases 53451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * the texture id 53551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 536918ad523b2780e0c893f3d2a32d4ec13f2a7e921John Reck void detachSurfaceTexture(long hardwareLayer) { 537918ad523b2780e0c893f3d2a32d4ec13f2a7e921John Reck nDetachSurfaceTexture(mNativeProxy, hardwareLayer); 538cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 539cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 54051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 54151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Sets up the renderer for drawing. 54251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 54351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param width The width of the drawing surface. 54451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param height The height of the drawing surface. 54551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param attachInfo Information about the window. 54651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param surfaceInsets The drawing surface insets to apply 54751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 54850210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette void setup(int width, int height, AttachInfo attachInfo, Rect surfaceInsets) { 549cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck mWidth = width; 550cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck mHeight = height; 55150210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette 5523aa1ffbc75e39b8e53b64256775ea917ca0c6beeAlan Viverette if (surfaceInsets != null && (surfaceInsets.left != 0 || surfaceInsets.right != 0 5533aa1ffbc75e39b8e53b64256775ea917ca0c6beeAlan Viverette || surfaceInsets.top != 0 || surfaceInsets.bottom != 0)) { 55457774a82f02c225941f81cf89c7a03bf899df2c1Alan Viverette mHasInsets = true; 555ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette mInsetLeft = surfaceInsets.left; 556ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette mInsetTop = surfaceInsets.top; 557ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette mSurfaceWidth = width + mInsetLeft + surfaceInsets.right; 558ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette mSurfaceHeight = height + mInsetTop + surfaceInsets.bottom; 55957774a82f02c225941f81cf89c7a03bf899df2c1Alan Viverette 56057774a82f02c225941f81cf89c7a03bf899df2c1Alan Viverette // If the surface has insets, it can't be opaque. 56157774a82f02c225941f81cf89c7a03bf899df2c1Alan Viverette setOpaque(false); 562ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette } else { 56357774a82f02c225941f81cf89c7a03bf899df2c1Alan Viverette mHasInsets = false; 564ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette mInsetLeft = 0; 565ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette mInsetTop = 0; 566ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette mSurfaceWidth = width; 567ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette mSurfaceHeight = height; 568ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette } 56950210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette 570ccb11e183763db5cbaca96abe461adf480ed8e44Alan Viverette mRootNode.setLeftTopRightBottom(-mInsetLeft, -mInsetTop, mSurfaceWidth, mSurfaceHeight); 57150210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette nSetup(mNativeProxy, mSurfaceWidth, mSurfaceHeight, mLightRadius, 572b36016c65f1d1b5846dba0349aab491dbd3a746aJohn Reck mAmbientShadowAlpha, mSpotShadowAlpha); 57350210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette 57450210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette setLightCenter(attachInfo); 57550210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette } 57650210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette 57751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 57851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Updates the light position based on the position of the window. 57951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 58051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param attachInfo Information about the window. 58151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 58250210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette void setLightCenter(AttachInfo attachInfo) { 58350210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette // Adjust light position for window offsets. 58450210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette final Point displaySize = attachInfo.mPoint; 58550210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette attachInfo.mDisplay.getRealSize(displaySize); 58650210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette final float lightX = displaySize.x / 2f - attachInfo.mWindowLeft; 58750210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette final float lightY = mLightY - attachInfo.mWindowTop; 58850210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette 58950210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette nSetLightCenter(mNativeProxy, lightX, lightY, mLightZ); 590cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 591cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 59251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 59351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Change the HardwareRenderer's opacity 59451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 59563a06673253914510bbeebd500655008682dade1John Reck void setOpaque(boolean opaque) { 59657774a82f02c225941f81cf89c7a03bf899df2c1Alan Viverette nSetOpaque(mNativeProxy, opaque && !mHasInsets); 59763a06673253914510bbeebd500655008682dade1John Reck } 59863a06673253914510bbeebd500655008682dade1John Reck 59951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 60051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Gets the current width of the surface. This is the width that the surface 60151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * was last set to in a call to {@link #setup(int, int, View.AttachInfo, Rect)}. 60251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 60351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @return the current width of the surface 60451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 605cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck int getWidth() { 606cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck return mWidth; 607cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 608cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 60951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 61051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Gets the current height of the surface. This is the height that the surface 61151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * was last set to in a call to {@link #setup(int, int, View.AttachInfo, Rect)}. 61251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 61351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @return the current width of the surface 61451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 615cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck int getHeight() { 616cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck return mHeight; 617cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 618cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 61951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 62051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Outputs extra debugging information in the specified file descriptor. 62151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 622ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck void dumpGfxInfo(PrintWriter pw, FileDescriptor fd, String[] args) { 623fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck pw.flush(); 624ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck int flags = 0; 625ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck for (int i = 0; i < args.length; i++) { 626ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck switch (args[i]) { 627ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck case "framestats": 628ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck flags |= FLAG_DUMP_FRAMESTATS; 629ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck break; 630ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck case "reset": 631ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck flags |= FLAG_DUMP_RESET; 632ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck break; 633ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck } 634fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck } 635ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck nDumpProfileInfo(mNativeProxy, fd, flags); 636cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 637cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 63851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 63951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Loads system properties used by the renderer. This method is invoked 64051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * whenever system properties are modified. Implementations can use this 64151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * to trigger live updates of the renderer based on properties. 64251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 64351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @return True if a property has changed. 64451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 645cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck boolean loadSystemProperties() { 646fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck boolean changed = nLoadSystemProperties(mNativeProxy); 64723d307c8d88f4a3849163b9e5b7cd11d0d4f372cJohn Reck if (changed) { 64823d307c8d88f4a3849163b9e5b7cd11d0d4f372cJohn Reck invalidateRoot(); 64923d307c8d88f4a3849163b9e5b7cd11d0d4f372cJohn Reck } 650fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck return changed; 651cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 652cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 6530a97330b98dd633b58dcfff405d94476c89e867dJohn Reck private void updateViewTreeDisplayList(View view) { 654cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck view.mPrivateFlags |= View.PFLAG_DRAWN; 655cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck view.mRecreateDisplayList = (view.mPrivateFlags & View.PFLAG_INVALIDATED) 656cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck == View.PFLAG_INVALIDATED; 657cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck view.mPrivateFlags &= ~View.PFLAG_INVALIDATED; 65831a2d063df5111e730abe7d07be064690deedc34Chris Craik view.updateDisplayListIfDirty(); 6590a97330b98dd633b58dcfff405d94476c89e867dJohn Reck view.mRecreateDisplayList = false; 6600a97330b98dd633b58dcfff405d94476c89e867dJohn Reck } 661cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 66261375a8bb5e112d4e79ee4240699ffe7e3f4c8e5John Reck private void updateRootDisplayList(View view, HardwareDrawCallbacks callbacks) { 66370850ea258cbf91477efa57a1f1a23cc0044cc93Chris Craik Trace.traceBegin(Trace.TRACE_TAG_VIEW, "Record View#draw()"); 6640a97330b98dd633b58dcfff405d94476c89e867dJohn Reck updateViewTreeDisplayList(view); 6650a97330b98dd633b58dcfff405d94476c89e867dJohn Reck 6660a97330b98dd633b58dcfff405d94476c89e867dJohn Reck if (mRootNodeNeedsUpdate || !mRootNode.isValid()) { 667f6829a0a618b4523619ec53c996b04d67e3186b9Chris Craik DisplayListCanvas canvas = mRootNode.start(mSurfaceWidth, mSurfaceHeight); 6680a97330b98dd633b58dcfff405d94476c89e867dJohn Reck try { 669dbed893ba88b76f88ea51d8666653458955cdc67Alan Viverette final int saveCount = canvas.save(); 6700a97330b98dd633b58dcfff405d94476c89e867dJohn Reck canvas.translate(mInsetLeft, mInsetTop); 6710a97330b98dd633b58dcfff405d94476c89e867dJohn Reck callbacks.onHardwarePreDraw(canvas); 672abedca398334236f9f03b5af04c58d4bb00a1247Chris Craik 673abedca398334236f9f03b5af04c58d4bb00a1247Chris Craik canvas.insertReorderBarrier(); 67431a2d063df5111e730abe7d07be064690deedc34Chris Craik canvas.drawRenderNode(view.updateDisplayListIfDirty()); 675abedca398334236f9f03b5af04c58d4bb00a1247Chris Craik canvas.insertInorderBarrier(); 676abedca398334236f9f03b5af04c58d4bb00a1247Chris Craik 6770a97330b98dd633b58dcfff405d94476c89e867dJohn Reck callbacks.onHardwarePostDraw(canvas); 678dbed893ba88b76f88ea51d8666653458955cdc67Alan Viverette canvas.restoreToCount(saveCount); 6790a97330b98dd633b58dcfff405d94476c89e867dJohn Reck mRootNodeNeedsUpdate = false; 6800a97330b98dd633b58dcfff405d94476c89e867dJohn Reck } finally { 6810a97330b98dd633b58dcfff405d94476c89e867dJohn Reck mRootNode.end(canvas); 6820a97330b98dd633b58dcfff405d94476c89e867dJohn Reck } 68305e858400adee0f579b1e27e321b48bd55843fbdJohn Reck } 6840a97330b98dd633b58dcfff405d94476c89e867dJohn Reck Trace.traceEnd(Trace.TRACE_TAG_VIEW); 6850a97330b98dd633b58dcfff405d94476c89e867dJohn Reck } 686cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 687ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne /** 688ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne * Adds a rendernode to the renderer which can be drawn and changed asynchronously to the 689ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne * rendernode of the UI thread. 690ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne * @param node The node to add. 691ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne * @param placeFront If true, the render node will be placed in front of the content node, 692ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne * otherwise behind the content node. 693ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne */ 694ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne public void addRenderNode(RenderNode node, boolean placeFront) { 695ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne nAddRenderNode(mNativeProxy, node.mNativeRenderNode, placeFront); 696ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne } 697ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne 698ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne /** 699ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne * Only especially added render nodes can be removed. 700ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne * @param node The node which was added via addRenderNode which should get removed again. 701ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne */ 702ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne public void removeRenderNode(RenderNode node) { 703ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne nRemoveRenderNode(mNativeProxy, node.mNativeRenderNode); 704ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne } 705ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne 706ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne /** 707ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne * Draws a particular render node. If the node is not the content node, only the additional 708ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne * nodes will get drawn and the content remains untouched. 709ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne * @param node The node to be drawn. 710ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne */ 711ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne public void drawRenderNode(RenderNode node) { 712ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne nDrawRenderNode(mNativeProxy, node.mNativeRenderNode); 713ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne } 714ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne 715ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne /** 716ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne * To avoid unnecessary overdrawing of the main content all additionally passed render nodes 717ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne * will be prevented to overdraw this area. It will be synchronized with the draw call. 718ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne * This should be updated in the content view's draw call. 719ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne * @param left The left side of the protected bounds. 720ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne * @param top The top side of the protected bounds. 721ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne * @param right The right side of the protected bounds. 722ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne * @param bottom The bottom side of the protected bounds. 723ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne */ 724b816087962aba0019b022303330f03b897b580edSkuhne public void setContentDrawBounds(int left, int top, int right, int bottom) { 725e85ce990fe7bfa33d6b7d8bfd23b7336096466b9Jorim Jaggi nSetContentDrawBounds(mNativeProxy, left, top, right, bottom); 726ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne } 727ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne 72851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 72951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Interface used to receive callbacks whenever a view is drawn by 73051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * a hardware renderer instance. 73151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 73251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck interface HardwareDrawCallbacks { 73351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 73451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Invoked before a view is drawn by a hardware renderer. 73551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * This method can be used to apply transformations to the 73651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * canvas but no drawing command should be issued. 73751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 73851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param canvas The Canvas used to render the view. 73951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 74051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck void onHardwarePreDraw(DisplayListCanvas canvas); 74151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 74251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 74351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Invoked after a view is drawn by a hardware renderer. 74451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * It is safe to invoke drawing commands from this method. 74551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 74651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param canvas The Canvas used to render the view. 74751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 74851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck void onHardwarePostDraw(DisplayListCanvas canvas); 74951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck } 75051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 75151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 75251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Indicates that the content drawn by HardwareDrawCallbacks needs to 75351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * be updated, which will be done by the next call to draw() 75451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 7550a97330b98dd633b58dcfff405d94476c89e867dJohn Reck void invalidateRoot() { 7560a97330b98dd633b58dcfff405d94476c89e867dJohn Reck mRootNodeNeedsUpdate = true; 757bc0cc0220b830df54c8ed41d0b53daffd7f6c991John Reck } 758bc0cc0220b830df54c8ed41d0b53daffd7f6c991John Reck 75951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 76051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Draws the specified view. 76151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 76251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param view The view to draw. 76351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param attachInfo AttachInfo tied to the specified view. 76451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param callbacks Callbacks invoked when drawing happens. 76551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 76661375a8bb5e112d4e79ee4240699ffe7e3f4c8e5John Reck void draw(View view, AttachInfo attachInfo, HardwareDrawCallbacks callbacks) { 767bc0cc0220b830df54c8ed41d0b53daffd7f6c991John Reck attachInfo.mIgnoreDirtyState = true; 768bc0cc0220b830df54c8ed41d0b53daffd7f6c991John Reck 769ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck final Choreographer choreographer = attachInfo.mViewRootImpl.mChoreographer; 770ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck choreographer.mFrameInfo.markDrawStart(); 771fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck 77261375a8bb5e112d4e79ee4240699ffe7e3f4c8e5John Reck updateRootDisplayList(view, callbacks); 773cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 7746313b9259d37b59f3402058e197637aa3014516cJohn Reck attachInfo.mIgnoreDirtyState = false; 7756313b9259d37b59f3402058e197637aa3014516cJohn Reck 776119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck // register animating rendernodes which started animating prior to renderer 777119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck // creation, which is typical for animators started prior to first draw 778119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck if (attachInfo.mPendingAnimatingRenderNodes != null) { 779119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck final int count = attachInfo.mPendingAnimatingRenderNodes.size(); 780119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck for (int i = 0; i < count; i++) { 781119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck registerAnimatingRenderNode( 782119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck attachInfo.mPendingAnimatingRenderNodes.get(i)); 783119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck } 784119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck attachInfo.mPendingAnimatingRenderNodes.clear(); 785119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck // We don't need this anymore as subsequent calls to 786119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck // ViewRootImpl#attachRenderNodeAnimator will go directly to us. 787119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck attachInfo.mPendingAnimatingRenderNodes = null; 788119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck } 789119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck 790ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck final long[] frameInfo = choreographer.mFrameInfo.mFrameInfo; 79151f2d606dcbfba3cc5b03dfea37c1304b91c232fJohn Reck int syncResult = nSyncAndDrawFrame(mNativeProxy, frameInfo, frameInfo.length); 792aa95a88327d9a3ac8a4a00b065b78ac0f28b3a19John Reck if ((syncResult & SYNC_LOST_SURFACE_REWARD_IF_FOUND) != 0) { 793aa95a88327d9a3ac8a4a00b065b78ac0f28b3a19John Reck setEnabled(false); 794b13de07f0b26953115f4315bc7417ca87c70594bJohn Reck attachInfo.mViewRootImpl.mSurface.release(); 795aa95a88327d9a3ac8a4a00b065b78ac0f28b3a19John Reck // Invalidate since we failed to draw. This should fetch a Surface 796aa95a88327d9a3ac8a4a00b065b78ac0f28b3a19John Reck // if it is still needed or do nothing if we are no longer drawing 797aa95a88327d9a3ac8a4a00b065b78ac0f28b3a19John Reck attachInfo.mViewRootImpl.invalidate(); 798aa95a88327d9a3ac8a4a00b065b78ac0f28b3a19John Reck } 799f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck if ((syncResult & SYNC_INVALIDATE_REQUIRED) != 0) { 800f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck attachInfo.mViewRootImpl.invalidate(); 801f9be77940e365036fecd8cc0e491e8545c34e79bJohn Reck } 802cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 803cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 8043b20251a355c88193c439f928a84ae69483fb488John Reck static void invokeFunctor(long functor, boolean waitForCompletion) { 8053b20251a355c88193c439f928a84ae69483fb488John Reck nInvokeFunctor(functor, waitForCompletion); 8060d1f634f4b5e1bb37aa51777efb6a68619488d01John Reck } 8070d1f634f4b5e1bb37aa51777efb6a68619488d01John Reck 80851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 80951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Creates a new hardware layer. A hardware layer built by calling this 81051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * method will be treated as a texture layer, instead of as a render target. 81151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 81251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @return A hardware layer 81351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 81419b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck HardwareLayer createTextureLayer() { 81519b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck long layer = nCreateTextureLayer(mNativeProxy); 81619b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck return HardwareLayer.adoptTextureLayer(this, layer); 817cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 818cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 81951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 8203e8249568cc428296ac76c7ddce3f0382d40fe5bJohn Reck void buildLayer(RenderNode node) { 8213e8249568cc428296ac76c7ddce3f0382d40fe5bJohn Reck nBuildLayer(mNativeProxy, node.getNativeDisplayList()); 8223e8249568cc428296ac76c7ddce3f0382d40fe5bJohn Reck } 8233e8249568cc428296ac76c7ddce3f0382d40fe5bJohn Reck 82451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 82519b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck boolean copyLayerInto(final HardwareLayer layer, final Bitmap bitmap) { 82619b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck return nCopyLayerInto(mNativeProxy, 8273731dc220ed457e0f1e99d7ec2589e0a43872b59John Reck layer.getDeferredLayerUpdater(), bitmap); 828cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 829cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 83051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 83151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Indicates that the specified hardware layer needs to be updated 83251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * as soon as possible. 83351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 83451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param layer The hardware layer that needs an update 83551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 83619b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck void pushLayerUpdate(HardwareLayer layer) { 837d72e0a339b54af0c4e731513bbad120dff694723John Reck nPushLayerUpdate(mNativeProxy, layer.getDeferredLayerUpdater()); 83819b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck } 83919b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck 84051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 84151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Tells the HardwareRenderer that the layer is destroyed. The renderer 84251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * should remove the layer from any update queues. 84351aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 84419b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck void onLayerDestroyed(HardwareLayer layer) { 845d72e0a339b54af0c4e731513bbad120dff694723John Reck nCancelLayerUpdate(mNativeProxy, layer.getDeferredLayerUpdater()); 846cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 847cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 84851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 84951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Optional, sets the name of the renderer. Useful for debugging purposes. 85051aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * 85151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * @param name The name of this renderer, can be null 85251aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 853cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck void setName(String name) { 854b36016c65f1d1b5846dba0349aab491dbd3a746aJohn Reck nSetName(mNativeProxy, name); 855cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 856cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 85751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 85851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Blocks until all previously queued work has completed. 85951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 86028ad7b52e038ef0cdd89f753d9839444a434b299John Reck void fence() { 86128ad7b52e038ef0cdd89f753d9839444a434b299John Reck nFence(mNativeProxy); 86228ad7b52e038ef0cdd89f753d9839444a434b299John Reck } 86328ad7b52e038ef0cdd89f753d9839444a434b299John Reck 86451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 86551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Prevents any further drawing until draw() is called. This is a signal 86651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * that the contents of the RenderNode tree are no longer safe to play back. 86751aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * In practice this usually means that there are Functor pointers in the 86851aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * display list that are no longer valid. 86951aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 870f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck void stopDrawing() { 871f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck nStopDrawing(mNativeProxy); 872f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck } 873f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck 87451aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck /** 87551aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck * Called by {@link ViewRootImpl} when a new performTraverals is scheduled. 87651aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck */ 877a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck public void notifyFramePending() { 878a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck nNotifyFramePending(mNativeProxy); 879a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck } 880a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck 88151aaf906f9f5fb2f117f5ccfae8be6974f7cb903John Reck 882119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck void registerAnimatingRenderNode(RenderNode animator) { 883119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck nRegisterAnimatingRenderNode(mRootNode.mNativeRenderNode, animator.mNativeRenderNode); 884119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck } 885119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck 886718cd3eb70703c43f29ca37907bbf0e153d8cca0Doris Liu void registerVectorDrawableAnimator( 887718cd3eb70703c43f29ca37907bbf0e153d8cca0Doris Liu AnimatedVectorDrawable.VectorDrawableAnimatorRT animator) { 888718cd3eb70703c43f29ca37907bbf0e153d8cca0Doris Liu nRegisterVectorDrawableAnimator(mRootNode.mNativeRenderNode, 889718cd3eb70703c43f29ca37907bbf0e153d8cca0Doris Liu animator.getAnimatorNativePtr()); 890718cd3eb70703c43f29ca37907bbf0e153d8cca0Doris Liu } 891718cd3eb70703c43f29ca37907bbf0e153d8cca0Doris Liu 892e248bd1b2c3fcf8088429507e73b31f45ee2544bJohn Reck public void serializeDisplayListTree() { 893e248bd1b2c3fcf8088429507e73b31f45ee2544bJohn Reck nSerializeDisplayListTree(mNativeProxy); 894e248bd1b2c3fcf8088429507e73b31f45ee2544bJohn Reck } 895e248bd1b2c3fcf8088429507e73b31f45ee2544bJohn Reck 896e94cbc76d560a157c0a0d47181b4ed2a0aadbeb1John Reck public static int copySurfaceInto(Surface surface, Bitmap bitmap) { 89710dd0585c11dcedb5a271d54e645594f1d215d5cJohn Reck return nCopySurfaceInto(surface, bitmap); 89810dd0585c11dcedb5a271d54e645594f1d215d5cJohn Reck } 89910dd0585c11dcedb5a271d54e645594f1d215d5cJohn Reck 900119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck @Override 9014f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck protected void finalize() throws Throwable { 9024f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck try { 9034f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck nDeleteProxy(mNativeProxy); 9040ed751dd22a98f0c1f637570c5775b4f5e97d895John Reck mNativeProxy = 0; 9054f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck } finally { 9064f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck super.finalize(); 907cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 908cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck } 909cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 910edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck private static class ProcessInitializer { 911edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck static ProcessInitializer sInstance = new ProcessInitializer(); 912edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck private static IBinder sProcToken; 91366f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck 91466f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck private boolean mInitialized = false; 91566f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck 916edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck private ProcessInitializer() {} 91766f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck 9183b20251a355c88193c439f928a84ae69483fb488John Reck synchronized void init(Context context, long renderProxy) { 91966f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck if (mInitialized) return; 920edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck mInitialized = true; 92133eb07f5759b85a5617f8057d8a335019c7d24ddTim Murray initSched(context, renderProxy); 922edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck initGraphicsStats(context, renderProxy); 923edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck initAssetAtlas(context, renderProxy); 924edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck } 925edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck 92633eb07f5759b85a5617f8057d8a335019c7d24ddTim Murray private static void initSched(Context context, long renderProxy) { 92733eb07f5759b85a5617f8057d8a335019c7d24ddTim Murray try { 92833eb07f5759b85a5617f8057d8a335019c7d24ddTim Murray int tid = nGetRenderThreadTid(renderProxy); 92933eb07f5759b85a5617f8057d8a335019c7d24ddTim Murray ActivityManagerNative.getDefault().setRenderThread(tid); 93033eb07f5759b85a5617f8057d8a335019c7d24ddTim Murray } catch (Throwable t) { 93133eb07f5759b85a5617f8057d8a335019c7d24ddTim Murray Log.w(LOG_TAG, "Failed to set scheduler for RenderThread", t); 93233eb07f5759b85a5617f8057d8a335019c7d24ddTim Murray } 93333eb07f5759b85a5617f8057d8a335019c7d24ddTim Murray } 93433eb07f5759b85a5617f8057d8a335019c7d24ddTim Murray 935edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck private static void initGraphicsStats(Context context, long renderProxy) { 936edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck try { 937828698b012e3c317073c0dbbe323d06fe9954af4John Reck IBinder binder = ServiceManager.getService("graphicsstats"); 938828698b012e3c317073c0dbbe323d06fe9954af4John Reck if (binder == null) return; 939828698b012e3c317073c0dbbe323d06fe9954af4John Reck IGraphicsStats graphicsStatsService = IGraphicsStats.Stub 940828698b012e3c317073c0dbbe323d06fe9954af4John Reck .asInterface(binder); 941828698b012e3c317073c0dbbe323d06fe9954af4John Reck sProcToken = new Binder(); 942edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck final String pkg = context.getApplicationInfo().packageName; 943828698b012e3c317073c0dbbe323d06fe9954af4John Reck ParcelFileDescriptor pfd = graphicsStatsService. 944edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck requestBufferForProcess(pkg, sProcToken); 945edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck nSetProcessStatsBuffer(renderProxy, pfd.getFd()); 946edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck pfd.close(); 947828698b012e3c317073c0dbbe323d06fe9954af4John Reck } catch (Throwable t) { 948828698b012e3c317073c0dbbe323d06fe9954af4John Reck Log.w(LOG_TAG, "Could not acquire gfx stats buffer", t); 949edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck } 950edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck } 951edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck 952edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck private static void initAssetAtlas(Context context, long renderProxy) { 95366f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck IBinder binder = ServiceManager.getService("assetatlas"); 95466f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck if (binder == null) return; 95566f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck 95666f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck IAssetAtlas atlas = IAssetAtlas.Stub.asInterface(binder); 95766f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck try { 95866f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck if (atlas.isCompatible(android.os.Process.myPpid())) { 95966f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck GraphicBuffer buffer = atlas.getBuffer(); 96066f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck if (buffer != null) { 96166f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck long[] map = atlas.getMap(); 96266f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck if (map != null) { 9633b20251a355c88193c439f928a84ae69483fb488John Reck nSetAtlas(renderProxy, buffer, map); 96466f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck } 96566f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck // If IAssetAtlas is not the same class as the IBinder 96666f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck // we are using a remote service and we can safely 96766f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck // destroy the graphic buffer 96866f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck if (atlas.getClass() != binder.getClass()) { 96966f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck buffer.destroy(); 97066f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck } 97166f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck } 97266f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck } 97366f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck } catch (RemoteException e) { 97466f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck Log.w(LOG_TAG, "Could not acquire atlas", e); 97566f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck } 97666f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck } 97766f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck } 97866f0be65a1046f54ddce0498b242c1fa0776b1eaJohn Reck 979910beb8f5d9042163e2ad0dbb744d9f147db9604Andres Morales void addFrameMetricsObserver(FrameMetricsObserver observer) { 980910beb8f5d9042163e2ad0dbb744d9f147db9604Andres Morales long nativeObserver = nAddFrameMetricsObserver(mNativeProxy, observer); 981910beb8f5d9042163e2ad0dbb744d9f147db9604Andres Morales observer.mNative = new VirtualRefBasePtr(nativeObserver); 98206f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales } 98306f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales 984910beb8f5d9042163e2ad0dbb744d9f147db9604Andres Morales void removeFrameMetricsObserver(FrameMetricsObserver observer) { 985910beb8f5d9042163e2ad0dbb744d9f147db9604Andres Morales nRemoveFrameMetricsObserver(mNativeProxy, observer.mNative.get()); 986910beb8f5d9042163e2ad0dbb744d9f147db9604Andres Morales observer.mNative = null; 98706f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales } 98806f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales 98984a4c887a07c1c2939443f4e0587d7f1ac109e4bJohn Reck static native void setupShadersDiskCache(String cacheFile); 99084a4c887a07c1c2939443f4e0587d7f1ac109e4bJohn Reck 9913b20251a355c88193c439f928a84ae69483fb488John Reck private static native void nSetAtlas(long nativeProxy, GraphicBuffer buffer, long[] map); 992edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck private static native void nSetProcessStatsBuffer(long nativeProxy, int fd); 99333eb07f5759b85a5617f8057d8a335019c7d24ddTim Murray private static native int nGetRenderThreadTid(long nativeProxy); 994cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 995e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck private static native long nCreateRootRenderNode(); 996e45b1fd03b524d2b57cc6c222d89076a31a08beaJohn Reck private static native long nCreateProxy(boolean translucent, long rootRenderNode); 9974f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck private static native void nDeleteProxy(long nativeProxy); 998cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 999e4280baaa709c74d86cf6a389a4674ca665f5af6John Reck private static native boolean nLoadSystemProperties(long nativeProxy); 1000b36016c65f1d1b5846dba0349aab491dbd3a746aJohn Reck private static native void nSetName(long nativeProxy, String name); 100118f16e6fba74eda173e1e7c869e6e2e2acc073ffJohn Reck 10020bcd0cb6b1193168fa2840855195347488daab9eThomas Buhot private static native void nInitialize(long nativeProxy, Surface window); 10034f02bf4eef6af47f35c70c4dda5b7b9523d89ca0John Reck private static native void nUpdateSurface(long nativeProxy, Surface window); 100401a5ea35fbba4c5bb1d7790ae1677a2fa752e042John Reck private static native boolean nPauseSurface(long nativeProxy, Surface window); 10058afcc76920499d0a384dba1470c5a377f80ed768John Reck private static native void nSetStopped(long nativeProxy, boolean stopped); 1006797b95b26bbb7557678af78b9a2a61830158920fChris Craik private static native void nSetup(long nativeProxy, int width, int height, 100750210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette float lightRadius, int ambientShadowAlpha, int spotShadowAlpha); 100850210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette private static native void nSetLightCenter(long nativeProxy, 100950210d912925aef14e4ce69be82e4949122a3cd9Alan Viverette float lightX, float lightY, float lightZ); 101063a06673253914510bbeebd500655008682dade1John Reck private static native void nSetOpaque(long nativeProxy, boolean opaque); 101151f2d606dcbfba3cc5b03dfea37c1304b91c232fJohn Reck private static native int nSyncAndDrawFrame(long nativeProxy, long[] frameInfo, int size); 1012350e65206cfbd86484fcfda77bb988e270606ddaDoris Liu private static native void nDestroy(long nativeProxy, long rootRenderNode); 1013119907cd2575c56b1ebf66348b52e67aaf6a88d8John Reck private static native void nRegisterAnimatingRenderNode(long rootRenderNode, long animatingNode); 1014718cd3eb70703c43f29ca37907bbf0e153d8cca0Doris Liu private static native void nRegisterVectorDrawableAnimator(long rootRenderNode, long animator); 1015cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck 10163b20251a355c88193c439f928a84ae69483fb488John Reck private static native void nInvokeFunctor(long functor, boolean waitForCompletion); 101719b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck 101819b6bcfd83eb7fb92ebd06d2fec89e308311f1d0John Reck private static native long nCreateTextureLayer(long nativeProxy); 10193e8249568cc428296ac76c7ddce3f0382d40fe5bJohn Reck private static native void nBuildLayer(long nativeProxy, long node); 10203731dc220ed457e0f1e99d7ec2589e0a43872b59John Reck private static native boolean nCopyLayerInto(long nativeProxy, long layer, Bitmap bitmap); 1021d72e0a339b54af0c4e731513bbad120dff694723John Reck private static native void nPushLayerUpdate(long nativeProxy, long layer); 1022d72e0a339b54af0c4e731513bbad120dff694723John Reck private static native void nCancelLayerUpdate(long nativeProxy, long layer); 1023918ad523b2780e0c893f3d2a32d4ec13f2a7e921John Reck private static native void nDetachSurfaceTexture(long nativeProxy, long layer); 102428ad7b52e038ef0cdd89f753d9839444a434b299John Reck 1025f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck private static native void nDestroyHardwareResources(long nativeProxy); 1026f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck private static native void nTrimMemory(int level); 10272507c34d91bb0d722b6012e85cb47387b2aa6873Chris Craik private static native void nOverrideProperty(String name, String value); 1028e1628b7c6fc3822fa83cf02028ce8ad67abb0afeJohn Reck 102928ad7b52e038ef0cdd89f753d9839444a434b299John Reck private static native void nFence(long nativeProxy); 1030f47a594f5250b1914c36423ee6b371f0b8db09d0John Reck private static native void nStopDrawing(long nativeProxy); 1031a5dda645da738da7b4ae15e28fa7d93d3b04b94fJohn Reck private static native void nNotifyFramePending(long nativeProxy); 1032fe5e7b7346a54537b980796ceeca66bfdbd05561John Reck 1033e248bd1b2c3fcf8088429507e73b31f45ee2544bJohn Reck private static native void nSerializeDisplayListTree(long nativeProxy); 1034e248bd1b2c3fcf8088429507e73b31f45ee2544bJohn Reck 1035ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck private static native void nDumpProfileInfo(long nativeProxy, FileDescriptor fd, 1036ba6adf66d3c44c0aa2fd8a224862ff1901d64300John Reck @DumpFlags int dumpFlags); 1037edc524c90506d80e0fc5fb67e8de7b8f3ef53439John Reck private static native void nDumpProfileData(byte[] data, FileDescriptor fd); 1038ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne 1039ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne private static native void nAddRenderNode(long nativeProxy, long rootRenderNode, 1040ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne boolean placeFront); 1041ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne private static native void nRemoveRenderNode(long nativeProxy, long rootRenderNode); 1042ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne private static native void nDrawRenderNode(long nativeProxy, long rootRenderNode); 1043b816087962aba0019b022303330f03b897b580edSkuhne private static native void nSetContentDrawBounds(long nativeProxy, int left, 1044ea7a7fb75acb7305eb774ca7bc7e96103bd49323Skuhne int top, int right, int bottom); 104506f5bc70a667a02b14e31d3f53f91d3661e30666Andres Morales 1046910beb8f5d9042163e2ad0dbb744d9f147db9604Andres Morales private static native long nAddFrameMetricsObserver(long nativeProxy, FrameMetricsObserver observer); 1047910beb8f5d9042163e2ad0dbb744d9f147db9604Andres Morales private static native void nRemoveFrameMetricsObserver(long nativeProxy, long nativeObserver); 104810dd0585c11dcedb5a271d54e645594f1d215d5cJohn Reck 1049e94cbc76d560a157c0a0d47181b4ed2a0aadbeb1John Reck private static native int nCopySurfaceInto(Surface surface, Bitmap bitmap); 1050cec24ae16e9a0a7c3075f1a8d9149bb7fb3813fcJohn Reck} 1051