blob: 8b06ecf3bc8bb75a8506d8bfcf3ada48e6b26b9a [file] [log] [blame]
John Reckcec24ae2013-11-05 13:27:50 -08001/*
2 * Copyright (C) 2013 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.view;
18
John Reckba6adf62015-02-19 14:36:50 -080019import android.annotation.IntDef;
Chris Craik2507c342015-05-04 14:36:49 -070020import android.annotation.NonNull;
John Reckb8802b12014-06-16 15:28:50 -070021import android.content.Context;
Alan Viverette58c42c32014-07-12 20:33:45 -070022import android.content.res.TypedArray;
John Reck04fc5832014-02-05 16:38:25 -080023import android.graphics.Bitmap;
Alan Viverette50210d92015-05-14 18:05:36 -070024import android.graphics.Point;
Alan Viveretteccb11e12014-07-08 16:04:02 -070025import android.graphics.Rect;
John Reckedc524c2015-03-18 15:24:33 -070026import android.os.Binder;
Andres Morales06f5bc72015-12-15 15:21:31 -080027import android.os.Handler;
John Reck66f0be62014-05-13 13:39:31 -070028import android.os.IBinder;
Andres Morales06f5bc72015-12-15 15:21:31 -080029import android.os.Message;
John Reckedc524c2015-03-18 15:24:33 -070030import android.os.ParcelFileDescriptor;
John Reck66f0be62014-05-13 13:39:31 -070031import android.os.RemoteException;
32import android.os.ServiceManager;
John Reckcec24ae2013-11-05 13:27:50 -080033import android.os.Trace;
John Reck66f0be62014-05-13 13:39:31 -070034import android.util.Log;
John Reckcec24ae2013-11-05 13:27:50 -080035import android.view.Surface.OutOfResourcesException;
36import android.view.View.AttachInfo;
37
John Reckba6adf62015-02-19 14:36:50 -080038import com.android.internal.R;
Andres Morales06f5bc72015-12-15 15:21:31 -080039import com.android.internal.util.VirtualRefBasePtr;
John Reckba6adf62015-02-19 14:36:50 -080040
John Reck51aaf902015-12-02 15:08:07 -080041import java.io.File;
John Reckfe5e7b72014-05-23 17:42:28 -070042import java.io.FileDescriptor;
John Reckcec24ae2013-11-05 13:27:50 -080043import java.io.PrintWriter;
John Reckba6adf62015-02-19 14:36:50 -080044import java.lang.annotation.Retention;
45import java.lang.annotation.RetentionPolicy;
Andres Morales06f5bc72015-12-15 15:21:31 -080046import java.util.HashSet;
John Reckcec24ae2013-11-05 13:27:50 -080047
48/**
49 * Hardware renderer that proxies the rendering to a render thread. Most calls
John Reck4f02bf42014-01-03 18:09:17 -080050 * are currently synchronous.
John Reckcec24ae2013-11-05 13:27:50 -080051 *
52 * The UI thread can block on the RenderThread, but RenderThread must never
53 * block on the UI thread.
54 *
John Reck4f02bf42014-01-03 18:09:17 -080055 * ThreadedRenderer creates an instance of RenderProxy. RenderProxy in turn creates
56 * and manages a CanvasContext on the RenderThread. The CanvasContext is fully managed
57 * by the lifecycle of the RenderProxy.
58 *
John Reckcec24ae2013-11-05 13:27:50 -080059 * Note that although currently the EGL context & surfaces are created & managed
60 * by the render thread, the goal is to move that into a shared structure that can
61 * be managed by both threads. EGLSurface creation & deletion should ideally be
62 * done on the UI thread and not the RenderThread to avoid stalling the
63 * RenderThread with surface buffer allocation.
64 *
65 * @hide
66 */
John Reck51aaf902015-12-02 15:08:07 -080067public final class ThreadedRenderer {
68 private static final String LOG_TAG = "ThreadedRenderer";
69
70 /**
71 * Name of the file that holds the shaders cache.
72 */
73 private static final String CACHE_PATH_SHADERS = "com.android.opengl.shaders_cache";
74
75 /**
76 * System property used to enable or disable dirty regions invalidation.
77 * This property is only queried if {@link #RENDER_DIRTY_REGIONS} is true.
78 * The default value of this property is assumed to be true.
79 *
80 * Possible values:
81 * "true", to enable partial invalidates
82 * "false", to disable partial invalidates
83 */
84 static final String RENDER_DIRTY_REGIONS_PROPERTY = "debug.hwui.render_dirty_regions";
85
86 /**
87 * System property used to enable or disable hardware rendering profiling.
88 * The default value of this property is assumed to be false.
89 *
90 * When profiling is enabled, the adb shell dumpsys gfxinfo command will
91 * output extra information about the time taken to execute by the last
92 * frames.
93 *
94 * Possible values:
95 * "true", to enable profiling
96 * "visual_bars", to enable profiling and visualize the results on screen
97 * "false", to disable profiling
98 *
99 * @see #PROFILE_PROPERTY_VISUALIZE_BARS
100 *
101 * @hide
102 */
103 public static final String PROFILE_PROPERTY = "debug.hwui.profile";
104
105 /**
106 * Value for {@link #PROFILE_PROPERTY}. When the property is set to this
107 * value, profiling data will be visualized on screen as a bar chart.
108 *
109 * @hide
110 */
111 public static final String PROFILE_PROPERTY_VISUALIZE_BARS = "visual_bars";
112
113 /**
114 * System property used to specify the number of frames to be used
115 * when doing hardware rendering profiling.
116 * The default value of this property is #PROFILE_MAX_FRAMES.
117 *
118 * When profiling is enabled, the adb shell dumpsys gfxinfo command will
119 * output extra information about the time taken to execute by the last
120 * frames.
121 *
122 * Possible values:
123 * "60", to set the limit of frames to 60
124 */
125 static final String PROFILE_MAXFRAMES_PROPERTY = "debug.hwui.profile.maxframes";
126
127 /**
128 * System property used to debug EGL configuration choice.
129 *
130 * Possible values:
131 * "choice", print the chosen configuration only
132 * "all", print all possible configurations
133 */
134 static final String PRINT_CONFIG_PROPERTY = "debug.hwui.print_config";
135
136 /**
137 * Turn on to draw dirty regions every other frame.
138 *
139 * Possible values:
140 * "true", to enable dirty regions debugging
141 * "false", to disable dirty regions debugging
142 *
143 * @hide
144 */
145 public static final String DEBUG_DIRTY_REGIONS_PROPERTY = "debug.hwui.show_dirty_regions";
146
147 /**
148 * Turn on to flash hardware layers when they update.
149 *
150 * Possible values:
151 * "true", to enable hardware layers updates debugging
152 * "false", to disable hardware layers updates debugging
153 *
154 * @hide
155 */
156 public static final String DEBUG_SHOW_LAYERS_UPDATES_PROPERTY =
157 "debug.hwui.show_layers_updates";
158
159 /**
160 * Controls overdraw debugging.
161 *
162 * Possible values:
163 * "false", to disable overdraw debugging
164 * "show", to show overdraw areas on screen
165 * "count", to display an overdraw counter
166 *
167 * @hide
168 */
169 public static final String DEBUG_OVERDRAW_PROPERTY = "debug.hwui.overdraw";
170
171 /**
172 * Value for {@link #DEBUG_OVERDRAW_PROPERTY}. When the property is set to this
173 * value, overdraw will be shown on screen by coloring pixels.
174 *
175 * @hide
176 */
177 public static final String OVERDRAW_PROPERTY_SHOW = "show";
178
179 /**
180 * Turn on to debug non-rectangular clip operations.
181 *
182 * Possible values:
183 * "hide", to disable this debug mode
184 * "highlight", highlight drawing commands tested against a non-rectangular clip
185 * "stencil", renders the clip region on screen when set
186 *
187 * @hide
188 */
189 public static final String DEBUG_SHOW_NON_RECTANGULAR_CLIP_PROPERTY =
190 "debug.hwui.show_non_rect_clip";
191
192 /**
193 * A process can set this flag to false to prevent the use of hardware
194 * rendering.
195 *
196 * @hide
197 */
198 public static boolean sRendererDisabled = false;
199
200 /**
201 * Further hardware renderer disabling for the system process.
202 *
203 * @hide
204 */
205 public static boolean sSystemRendererDisabled = false;
206
207 /**
208 * Invoke this method to disable hardware rendering in the current process.
209 *
210 * @hide
211 */
212 public static void disable(boolean system) {
213 sRendererDisabled = true;
214 if (system) {
215 sSystemRendererDisabled = true;
216 }
217 }
218
219 public static boolean sTrimForeground = false;
220
221 /**
222 * Controls whether or not the hardware renderer should aggressively
223 * trim memory. Note that this must not be set for any process that
224 * uses WebView! This should be only used by system_process or similar
225 * that do not go into the background.
226 */
227 public static void enableForegroundTrimming() {
228 sTrimForeground = true;
229 }
230
231 /**
232 * Indicates whether hardware acceleration is available under any form for
233 * the view hierarchy.
234 *
235 * @return True if the view hierarchy can potentially be hardware accelerated,
236 * false otherwise
237 */
238 public static boolean isAvailable() {
239 return DisplayListCanvas.isAvailable();
240 }
241
242 /**
243 * Sets the directory to use as a persistent storage for hardware rendering
244 * resources.
245 *
246 * @param cacheDir A directory the current process can write to
247 *
248 * @hide
249 */
250 public static void setupDiskCache(File cacheDir) {
251 ThreadedRenderer.setupShadersDiskCache(new File(cacheDir, CACHE_PATH_SHADERS).getAbsolutePath());
252 }
253
254 /**
Michael Lentine03d8f7682016-01-31 15:37:11 -0600255 * Sets the library directory to use as a search path for vulkan layers.
256 *
257 * @param libDir A directory that contains vulkan layers
258 *
259 * @hide
260 */
261 public static void setLibDir(String libDir) {
262 ThreadedRenderer.setupVulkanLayerPath(libDir);
263 }
264
265 /**
John Reck51aaf902015-12-02 15:08:07 -0800266 * Creates a hardware renderer using OpenGL.
267 *
268 * @param translucent True if the surface is translucent, false otherwise
269 *
270 * @return A hardware renderer backed by OpenGL.
271 */
272 public static ThreadedRenderer create(Context context, boolean translucent) {
273 ThreadedRenderer renderer = null;
274 if (DisplayListCanvas.isAvailable()) {
275 renderer = new ThreadedRenderer(context, translucent);
276 }
277 return renderer;
278 }
279
280 /**
281 * Invoke this method when the system is running out of memory. This
282 * method will attempt to recover as much memory as possible, based on
283 * the specified hint.
284 *
285 * @param level Hint about the amount of memory that should be trimmed,
286 * see {@link android.content.ComponentCallbacks}
287 */
288 public static void trimMemory(int level) {
289 nTrimMemory(level);
290 }
291
292 public static void overrideProperty(@NonNull String name, @NonNull String value) {
293 if (name == null || value == null) {
294 throw new IllegalArgumentException("name and value must be non-null");
295 }
296 nOverrideProperty(name, value);
297 }
298
299 public static void dumpProfileData(byte[] data, FileDescriptor fd) {
300 nDumpProfileData(data, fd);
301 }
John Reckcec24ae2013-11-05 13:27:50 -0800302
John Reckf9be7792014-05-02 18:21:16 -0700303 // Keep in sync with DrawFrameTask.h SYNC_* flags
304 // Nothing interesting to report
John Reckcd028f32014-06-24 08:44:29 -0700305 private static final int SYNC_OK = 0;
John Reckf9be7792014-05-02 18:21:16 -0700306 // Needs a ViewRoot invalidate
John Reckcd028f32014-06-24 08:44:29 -0700307 private static final int SYNC_INVALIDATE_REQUIRED = 1 << 0;
John Reckaa95a882014-11-07 11:02:07 -0800308 // Spoiler: the reward is GPU-accelerated drawing, better find that Surface!
309 private static final int SYNC_LOST_SURFACE_REWARD_IF_FOUND = 1 << 1;
John Reckf9be7792014-05-02 18:21:16 -0700310
John Reckfe5e7b72014-05-23 17:42:28 -0700311 private static final String[] VISUALIZERS = {
312 PROFILE_PROPERTY_VISUALIZE_BARS,
313 };
314
John Reckba6adf62015-02-19 14:36:50 -0800315 private static final int FLAG_DUMP_FRAMESTATS = 1 << 0;
316 private static final int FLAG_DUMP_RESET = 1 << 1;
317
318 @IntDef(flag = true, value = {
319 FLAG_DUMP_FRAMESTATS, FLAG_DUMP_RESET })
320 @Retention(RetentionPolicy.SOURCE)
321 public @interface DumpFlags {}
322
Alan Viveretteccb11e12014-07-08 16:04:02 -0700323 // Size of the rendered content.
John Reckcec24ae2013-11-05 13:27:50 -0800324 private int mWidth, mHeight;
Alan Viveretteccb11e12014-07-08 16:04:02 -0700325
326 // Actual size of the drawing surface.
327 private int mSurfaceWidth, mSurfaceHeight;
328
329 // Insets between the drawing surface and rendered content. These are
330 // applied as translation when updating the root render node.
331 private int mInsetTop, mInsetLeft;
332
Alan Viverette57774a82014-07-15 15:49:55 -0700333 // Whether the surface has insets. Used to protect opacity.
334 private boolean mHasInsets;
335
Alan Viverette58c42c32014-07-12 20:33:45 -0700336 // Light and shadow properties specified by the theme.
337 private final float mLightY;
338 private final float mLightZ;
339 private final float mLightRadius;
Chris Craik058fc642014-07-23 18:19:28 -0700340 private final int mAmbientShadowAlpha;
341 private final int mSpotShadowAlpha;
Alan Viverette58c42c32014-07-12 20:33:45 -0700342
John Reck4f02bf42014-01-03 18:09:17 -0800343 private long mNativeProxy;
John Reckf7d9c1d2014-04-09 10:01:03 -0700344 private boolean mInitialized = false;
John Reckbc0cc022014-04-11 16:08:14 -0700345 private RenderNode mRootNode;
John Reck18f16e62014-05-02 16:46:41 -0700346 private Choreographer mChoreographer;
John Reck0a973302014-07-16 13:29:45 -0700347 private boolean mRootNodeNeedsUpdate;
John Reckcec24ae2013-11-05 13:27:50 -0800348
Skuhneea7a7fb2015-08-28 07:10:31 -0700349 // In case of multi threaded render nodes, these bounds indicate the content bounds against
350 // which the backdrop needs to be cropped against.
351 private final Rect mCurrentContentBounds = new Rect();
352 private final Rect mStagedContentBounds = new Rect();
353
John Reck51aaf902015-12-02 15:08:07 -0800354 private boolean mEnabled;
355 private boolean mRequested = true;
356
Andres Morales06f5bc72015-12-15 15:21:31 -0800357 private HashSet<FrameStatsObserver> mFrameStatsObservers;
358
John Reckb8802b12014-06-16 15:28:50 -0700359 ThreadedRenderer(Context context, boolean translucent) {
Alan Viveretteed6f14a2014-08-26 14:53:28 -0700360 final TypedArray a = context.obtainStyledAttributes(null, R.styleable.Lighting, 0, 0);
Alan Viverette58c42c32014-07-12 20:33:45 -0700361 mLightY = a.getDimension(R.styleable.Lighting_lightY, 0);
362 mLightZ = a.getDimension(R.styleable.Lighting_lightZ, 0);
363 mLightRadius = a.getDimension(R.styleable.Lighting_lightRadius, 0);
Alan Viveretteed6f14a2014-08-26 14:53:28 -0700364 mAmbientShadowAlpha =
365 (int) (255 * a.getFloat(R.styleable.Lighting_ambientShadowAlpha, 0) + 0.5f);
366 mSpotShadowAlpha = (int) (255 * a.getFloat(R.styleable.Lighting_spotShadowAlpha, 0) + 0.5f);
Alan Viverette58c42c32014-07-12 20:33:45 -0700367 a.recycle();
368
John Recke45b1fd2014-04-15 09:50:16 -0700369 long rootNodePtr = nCreateRootRenderNode();
370 mRootNode = RenderNode.adopt(rootNodePtr);
John Reckbc0cc022014-04-11 16:08:14 -0700371 mRootNode.setClipToBounds(false);
John Recke45b1fd2014-04-15 09:50:16 -0700372 mNativeProxy = nCreateProxy(translucent, rootNodePtr);
John Reck18f16e62014-05-02 16:46:41 -0700373
John Reckedc524c2015-03-18 15:24:33 -0700374 ProcessInitializer.sInstance.init(context, mNativeProxy);
John Reck3b202512014-06-23 13:13:08 -0700375
John Reckfe5e7b72014-05-23 17:42:28 -0700376 loadSystemProperties();
John Reckcec24ae2013-11-05 13:27:50 -0800377 }
378
John Reck51aaf902015-12-02 15:08:07 -0800379 /**
380 * Destroys the hardware rendering context.
381 */
John Reckf47a5942014-06-30 16:20:04 -0700382 void destroy() {
John Reckf7d9c1d2014-04-09 10:01:03 -0700383 mInitialized = false;
384 updateEnabledState(null);
John Reck17035b02014-09-03 07:39:53 -0700385 nDestroy(mNativeProxy);
John Reckcec24ae2013-11-05 13:27:50 -0800386 }
387
John Reck51aaf902015-12-02 15:08:07 -0800388 /**
389 * Indicates whether hardware acceleration is currently enabled.
390 *
391 * @return True if hardware acceleration is in use, false otherwise.
392 */
393 boolean isEnabled() {
394 return mEnabled;
395 }
396
397 /**
398 * Indicates whether hardware acceleration is currently enabled.
399 *
400 * @param enabled True if the hardware renderer is in use, false otherwise.
401 */
402 void setEnabled(boolean enabled) {
403 mEnabled = enabled;
404 }
405
406 /**
407 * Indicates whether hardware acceleration is currently request but not
408 * necessarily enabled yet.
409 *
410 * @return True if requested, false otherwise.
411 */
412 boolean isRequested() {
413 return mRequested;
414 }
415
416 /**
417 * Indicates whether hardware acceleration is currently requested but not
418 * necessarily enabled yet.
419 *
420 * @return True to request hardware acceleration, false otherwise.
421 */
422 void setRequested(boolean requested) {
423 mRequested = requested;
424 }
425
John Reckf7d9c1d2014-04-09 10:01:03 -0700426 private void updateEnabledState(Surface surface) {
427 if (surface == null || !surface.isValid()) {
428 setEnabled(false);
429 } else {
430 setEnabled(mInitialized);
431 }
432 }
433
John Reck51aaf902015-12-02 15:08:07 -0800434 /**
435 * Initializes the hardware renderer for the specified surface.
436 *
437 * @param surface The surface to hardware accelerate
438 *
439 * @return True if the initialization was successful, false otherwise.
440 */
John Reckcec24ae2013-11-05 13:27:50 -0800441 boolean initialize(Surface surface) throws OutOfResourcesException {
Thomas Buhot0bcd0cb2015-12-04 12:18:03 +0100442 boolean status = !mInitialized;
John Reckf7d9c1d2014-04-09 10:01:03 -0700443 mInitialized = true;
444 updateEnabledState(surface);
Thomas Buhot0bcd0cb2015-12-04 12:18:03 +0100445 nInitialize(mNativeProxy, surface);
Dan Stoza5795d642014-06-20 13:01:36 -0700446 return status;
John Reckcec24ae2013-11-05 13:27:50 -0800447 }
448
John Reck51aaf902015-12-02 15:08:07 -0800449 /**
450 * Initializes the hardware renderer for the specified surface and setup the
451 * renderer for drawing, if needed. This is invoked when the ViewAncestor has
452 * potentially lost the hardware renderer. The hardware renderer should be
453 * reinitialized and setup when the render {@link #isRequested()} and
454 * {@link #isEnabled()}.
455 *
456 * @param width The width of the drawing surface.
457 * @param height The height of the drawing surface.
458 * @param attachInfo Information about the window.
459 * @param surface The surface to hardware accelerate
460 * @param surfaceInsets The drawing surface insets to apply
461 *
462 * @return true if the surface was initialized, false otherwise. Returning
463 * false might mean that the surface was already initialized.
464 */
465 boolean initializeIfNeeded(int width, int height, View.AttachInfo attachInfo,
466 Surface surface, Rect surfaceInsets) throws OutOfResourcesException {
467 if (isRequested()) {
468 // We lost the gl context, so recreate it.
469 if (!isEnabled()) {
470 if (initialize(surface)) {
471 setup(width, height, attachInfo, surfaceInsets);
472 return true;
473 }
474 }
475 }
476 return false;
477 }
478
479 /**
480 * Updates the hardware renderer for the specified surface.
481 *
482 * @param surface The surface to hardware accelerate
483 */
John Reckcec24ae2013-11-05 13:27:50 -0800484 void updateSurface(Surface surface) throws OutOfResourcesException {
John Reckf7d9c1d2014-04-09 10:01:03 -0700485 updateEnabledState(surface);
John Reck4f02bf42014-01-03 18:09:17 -0800486 nUpdateSurface(mNativeProxy, surface);
John Reckcec24ae2013-11-05 13:27:50 -0800487 }
488
John Reck51aaf902015-12-02 15:08:07 -0800489 /**
490 * Stops any rendering into the surface. Use this if it is unclear whether
491 * or not the surface used by the HardwareRenderer will be changing. It
492 * Suspends any rendering into the surface, but will not do any destruction
493 */
John Reck01a5ea32014-12-03 13:01:07 -0800494 boolean pauseSurface(Surface surface) {
495 return nPauseSurface(mNativeProxy, surface);
John Reckf7d9c1d2014-04-09 10:01:03 -0700496 }
497
John Reck51aaf902015-12-02 15:08:07 -0800498 /**
499 * Destroys all hardware rendering resources associated with the specified
500 * view hierarchy.
501 *
502 * @param view The root of the view hierarchy
503 */
John Reckcec24ae2013-11-05 13:27:50 -0800504 void destroyHardwareResources(View view) {
John Reck4f02bf42014-01-03 18:09:17 -0800505 destroyResources(view);
John Reckf47a5942014-06-30 16:20:04 -0700506 nDestroyHardwareResources(mNativeProxy);
John Reck4f02bf42014-01-03 18:09:17 -0800507 }
508
509 private static void destroyResources(View view) {
510 view.destroyHardwareResources();
511
512 if (view instanceof ViewGroup) {
513 ViewGroup group = (ViewGroup) view;
514
515 int count = group.getChildCount();
516 for (int i = 0; i < count; i++) {
517 destroyResources(group.getChildAt(i));
518 }
519 }
John Reckcec24ae2013-11-05 13:27:50 -0800520 }
521
John Reck51aaf902015-12-02 15:08:07 -0800522 /**
523 * This method should be invoked whenever the current hardware renderer
524 * context should be reset.
525 *
526 * @param surface The surface to hardware accelerate
527 */
John Reckcec24ae2013-11-05 13:27:50 -0800528 void invalidate(Surface surface) {
John Reck4f02bf42014-01-03 18:09:17 -0800529 updateSurface(surface);
John Reckcec24ae2013-11-05 13:27:50 -0800530 }
531
John Reck51aaf902015-12-02 15:08:07 -0800532 /**
533 * Detaches the layer's surface texture from the GL context and releases
534 * the texture id
535 */
John Reck918ad522014-06-27 14:45:25 -0700536 void detachSurfaceTexture(long hardwareLayer) {
537 nDetachSurfaceTexture(mNativeProxy, hardwareLayer);
John Reckcec24ae2013-11-05 13:27:50 -0800538 }
539
John Reck51aaf902015-12-02 15:08:07 -0800540 /**
541 * Sets up the renderer for drawing.
542 *
543 * @param width The width of the drawing surface.
544 * @param height The height of the drawing surface.
545 * @param attachInfo Information about the window.
546 * @param surfaceInsets The drawing surface insets to apply
547 */
Alan Viverette50210d92015-05-14 18:05:36 -0700548 void setup(int width, int height, AttachInfo attachInfo, Rect surfaceInsets) {
John Reckcec24ae2013-11-05 13:27:50 -0800549 mWidth = width;
550 mHeight = height;
Alan Viverette50210d92015-05-14 18:05:36 -0700551
Alan Viverette3aa1ffb2014-10-30 12:22:08 -0700552 if (surfaceInsets != null && (surfaceInsets.left != 0 || surfaceInsets.right != 0
553 || surfaceInsets.top != 0 || surfaceInsets.bottom != 0)) {
Alan Viverette57774a82014-07-15 15:49:55 -0700554 mHasInsets = true;
Alan Viveretteccb11e12014-07-08 16:04:02 -0700555 mInsetLeft = surfaceInsets.left;
556 mInsetTop = surfaceInsets.top;
557 mSurfaceWidth = width + mInsetLeft + surfaceInsets.right;
558 mSurfaceHeight = height + mInsetTop + surfaceInsets.bottom;
Alan Viverette57774a82014-07-15 15:49:55 -0700559
560 // If the surface has insets, it can't be opaque.
561 setOpaque(false);
Alan Viveretteccb11e12014-07-08 16:04:02 -0700562 } else {
Alan Viverette57774a82014-07-15 15:49:55 -0700563 mHasInsets = false;
Alan Viveretteccb11e12014-07-08 16:04:02 -0700564 mInsetLeft = 0;
565 mInsetTop = 0;
566 mSurfaceWidth = width;
567 mSurfaceHeight = height;
568 }
Alan Viverette50210d92015-05-14 18:05:36 -0700569
Alan Viveretteccb11e12014-07-08 16:04:02 -0700570 mRootNode.setLeftTopRightBottom(-mInsetLeft, -mInsetTop, mSurfaceWidth, mSurfaceHeight);
Alan Viverette50210d92015-05-14 18:05:36 -0700571 nSetup(mNativeProxy, mSurfaceWidth, mSurfaceHeight, mLightRadius,
John Reckb36016c2015-03-11 08:50:53 -0700572 mAmbientShadowAlpha, mSpotShadowAlpha);
Alan Viverette50210d92015-05-14 18:05:36 -0700573
574 setLightCenter(attachInfo);
575 }
576
John Reck51aaf902015-12-02 15:08:07 -0800577 /**
578 * Updates the light position based on the position of the window.
579 *
580 * @param attachInfo Information about the window.
581 */
Alan Viverette50210d92015-05-14 18:05:36 -0700582 void setLightCenter(AttachInfo attachInfo) {
583 // Adjust light position for window offsets.
584 final Point displaySize = attachInfo.mPoint;
585 attachInfo.mDisplay.getRealSize(displaySize);
586 final float lightX = displaySize.x / 2f - attachInfo.mWindowLeft;
587 final float lightY = mLightY - attachInfo.mWindowTop;
588
589 nSetLightCenter(mNativeProxy, lightX, lightY, mLightZ);
John Reckcec24ae2013-11-05 13:27:50 -0800590 }
591
John Reck51aaf902015-12-02 15:08:07 -0800592 /**
593 * Change the HardwareRenderer's opacity
594 */
John Reck63a06672014-05-07 13:45:54 -0700595 void setOpaque(boolean opaque) {
Alan Viverette57774a82014-07-15 15:49:55 -0700596 nSetOpaque(mNativeProxy, opaque && !mHasInsets);
John Reck63a06672014-05-07 13:45:54 -0700597 }
598
John Reck51aaf902015-12-02 15:08:07 -0800599 /**
600 * Gets the current width of the surface. This is the width that the surface
601 * was last set to in a call to {@link #setup(int, int, View.AttachInfo, Rect)}.
602 *
603 * @return the current width of the surface
604 */
John Reckcec24ae2013-11-05 13:27:50 -0800605 int getWidth() {
606 return mWidth;
607 }
608
John Reck51aaf902015-12-02 15:08:07 -0800609 /**
610 * Gets the current height of the surface. This is the height that the surface
611 * was last set to in a call to {@link #setup(int, int, View.AttachInfo, Rect)}.
612 *
613 * @return the current width of the surface
614 */
John Reckcec24ae2013-11-05 13:27:50 -0800615 int getHeight() {
616 return mHeight;
617 }
618
John Reck51aaf902015-12-02 15:08:07 -0800619 /**
620 * Outputs extra debugging information in the specified file descriptor.
621 */
John Reckba6adf62015-02-19 14:36:50 -0800622 void dumpGfxInfo(PrintWriter pw, FileDescriptor fd, String[] args) {
John Reckfe5e7b72014-05-23 17:42:28 -0700623 pw.flush();
John Reckba6adf62015-02-19 14:36:50 -0800624 int flags = 0;
625 for (int i = 0; i < args.length; i++) {
626 switch (args[i]) {
627 case "framestats":
628 flags |= FLAG_DUMP_FRAMESTATS;
629 break;
630 case "reset":
631 flags |= FLAG_DUMP_RESET;
632 break;
633 }
John Reckfe5e7b72014-05-23 17:42:28 -0700634 }
John Reckba6adf62015-02-19 14:36:50 -0800635 nDumpProfileInfo(mNativeProxy, fd, flags);
John Reckcec24ae2013-11-05 13:27:50 -0800636 }
637
John Reck51aaf902015-12-02 15:08:07 -0800638 /**
639 * Loads system properties used by the renderer. This method is invoked
640 * whenever system properties are modified. Implementations can use this
641 * to trigger live updates of the renderer based on properties.
642 *
643 * @return True if a property has changed.
644 */
John Reckcec24ae2013-11-05 13:27:50 -0800645 boolean loadSystemProperties() {
John Reckfe5e7b72014-05-23 17:42:28 -0700646 boolean changed = nLoadSystemProperties(mNativeProxy);
John Reck23d307c2014-10-27 12:38:48 -0700647 if (changed) {
648 invalidateRoot();
649 }
John Reckfe5e7b72014-05-23 17:42:28 -0700650 return changed;
John Reckcec24ae2013-11-05 13:27:50 -0800651 }
652
John Reck0a973302014-07-16 13:29:45 -0700653 private void updateViewTreeDisplayList(View view) {
John Reckcec24ae2013-11-05 13:27:50 -0800654 view.mPrivateFlags |= View.PFLAG_DRAWN;
John Reckcec24ae2013-11-05 13:27:50 -0800655 view.mRecreateDisplayList = (view.mPrivateFlags & View.PFLAG_INVALIDATED)
656 == View.PFLAG_INVALIDATED;
657 view.mPrivateFlags &= ~View.PFLAG_INVALIDATED;
Chris Craik31a2d062015-05-01 14:22:47 -0700658 view.updateDisplayListIfDirty();
John Reckcec24ae2013-11-05 13:27:50 -0800659 view.mRecreateDisplayList = false;
John Reckbc0cc022014-04-11 16:08:14 -0700660 }
661
John Reck61375a82014-09-18 19:27:48 +0000662 private void updateRootDisplayList(View view, HardwareDrawCallbacks callbacks) {
Chris Craik70850ea2014-11-18 10:49:23 -0800663 Trace.traceBegin(Trace.TRACE_TAG_VIEW, "Record View#draw()");
John Reck0a973302014-07-16 13:29:45 -0700664 updateViewTreeDisplayList(view);
665
666 if (mRootNodeNeedsUpdate || !mRootNode.isValid()) {
Chris Craikf6829a02015-03-10 10:28:59 -0700667 DisplayListCanvas canvas = mRootNode.start(mSurfaceWidth, mSurfaceHeight);
John Reck0a973302014-07-16 13:29:45 -0700668 try {
Alan Viverettedbed8932014-08-06 17:54:52 -0700669 final int saveCount = canvas.save();
John Reck0a973302014-07-16 13:29:45 -0700670 canvas.translate(mInsetLeft, mInsetTop);
671 callbacks.onHardwarePreDraw(canvas);
Chris Craikabedca32014-08-28 15:03:55 -0700672
673 canvas.insertReorderBarrier();
Chris Craik31a2d062015-05-01 14:22:47 -0700674 canvas.drawRenderNode(view.updateDisplayListIfDirty());
Chris Craikabedca32014-08-28 15:03:55 -0700675 canvas.insertInorderBarrier();
676
John Reck0a973302014-07-16 13:29:45 -0700677 callbacks.onHardwarePostDraw(canvas);
Alan Viverettedbed8932014-08-06 17:54:52 -0700678 canvas.restoreToCount(saveCount);
John Reck0a973302014-07-16 13:29:45 -0700679 mRootNodeNeedsUpdate = false;
680 } finally {
681 mRootNode.end(canvas);
682 }
683 }
684 Trace.traceEnd(Trace.TRACE_TAG_VIEW);
685 }
686
Skuhneea7a7fb2015-08-28 07:10:31 -0700687 /**
688 * Adds a rendernode to the renderer which can be drawn and changed asynchronously to the
689 * rendernode of the UI thread.
690 * @param node The node to add.
691 * @param placeFront If true, the render node will be placed in front of the content node,
692 * otherwise behind the content node.
693 */
694 public void addRenderNode(RenderNode node, boolean placeFront) {
695 nAddRenderNode(mNativeProxy, node.mNativeRenderNode, placeFront);
696 }
697
698 /**
699 * Only especially added render nodes can be removed.
700 * @param node The node which was added via addRenderNode which should get removed again.
701 */
702 public void removeRenderNode(RenderNode node) {
703 nRemoveRenderNode(mNativeProxy, node.mNativeRenderNode);
704 }
705
706 /**
707 * Draws a particular render node. If the node is not the content node, only the additional
708 * nodes will get drawn and the content remains untouched.
709 * @param node The node to be drawn.
710 */
711 public void drawRenderNode(RenderNode node) {
712 nDrawRenderNode(mNativeProxy, node.mNativeRenderNode);
713 }
714
715 /**
716 * To avoid unnecessary overdrawing of the main content all additionally passed render nodes
717 * will be prevented to overdraw this area. It will be synchronized with the draw call.
718 * This should be updated in the content view's draw call.
719 * @param left The left side of the protected bounds.
720 * @param top The top side of the protected bounds.
721 * @param right The right side of the protected bounds.
722 * @param bottom The bottom side of the protected bounds.
723 */
Skuhneb8160872015-09-22 09:51:39 -0700724 public void setContentDrawBounds(int left, int top, int right, int bottom) {
Skuhneea7a7fb2015-08-28 07:10:31 -0700725 mStagedContentBounds.set(left, top, right, bottom);
726 }
727
John Reck51aaf902015-12-02 15:08:07 -0800728 /**
729 * Interface used to receive callbacks whenever a view is drawn by
730 * a hardware renderer instance.
731 */
732 interface HardwareDrawCallbacks {
733 /**
734 * Invoked before a view is drawn by a hardware renderer.
735 * This method can be used to apply transformations to the
736 * canvas but no drawing command should be issued.
737 *
738 * @param canvas The Canvas used to render the view.
739 */
740 void onHardwarePreDraw(DisplayListCanvas canvas);
741
742 /**
743 * Invoked after a view is drawn by a hardware renderer.
744 * It is safe to invoke drawing commands from this method.
745 *
746 * @param canvas The Canvas used to render the view.
747 */
748 void onHardwarePostDraw(DisplayListCanvas canvas);
749 }
750
751 /**
752 * Indicates that the content drawn by HardwareDrawCallbacks needs to
753 * be updated, which will be done by the next call to draw()
754 */
John Reck0a973302014-07-16 13:29:45 -0700755 void invalidateRoot() {
756 mRootNodeNeedsUpdate = true;
757 }
758
John Reck51aaf902015-12-02 15:08:07 -0800759 /**
760 * Draws the specified view.
761 *
762 * @param view The view to draw.
763 * @param attachInfo AttachInfo tied to the specified view.
764 * @param callbacks Callbacks invoked when drawing happens.
765 */
John Reck61375a82014-09-18 19:27:48 +0000766 void draw(View view, AttachInfo attachInfo, HardwareDrawCallbacks callbacks) {
John Reckbc0cc022014-04-11 16:08:14 -0700767 attachInfo.mIgnoreDirtyState = true;
John Reckbc0cc022014-04-11 16:08:14 -0700768
John Reckba6adf62015-02-19 14:36:50 -0800769 final Choreographer choreographer = attachInfo.mViewRootImpl.mChoreographer;
770 choreographer.mFrameInfo.markDrawStart();
John Reckfe5e7b72014-05-23 17:42:28 -0700771
John Reck61375a82014-09-18 19:27:48 +0000772 updateRootDisplayList(view, callbacks);
Skuhneea7a7fb2015-08-28 07:10:31 -0700773 // The main content view was updating the content bounds and we transfer them to the
774 // renderer.
775 if (!mCurrentContentBounds.equals(mStagedContentBounds)) {
776 mCurrentContentBounds.set(mStagedContentBounds);
Skuhneb8160872015-09-22 09:51:39 -0700777 nSetContentDrawBounds(mNativeProxy, mCurrentContentBounds.left,
778 mCurrentContentBounds.top, mCurrentContentBounds.right,
779 mCurrentContentBounds.bottom);
Skuhneea7a7fb2015-08-28 07:10:31 -0700780 }
John Reckcec24ae2013-11-05 13:27:50 -0800781
John Reck6313b922014-04-16 18:59:21 -0700782 attachInfo.mIgnoreDirtyState = false;
783
John Reck119907c2014-08-14 09:02:01 -0700784 // register animating rendernodes which started animating prior to renderer
785 // creation, which is typical for animators started prior to first draw
786 if (attachInfo.mPendingAnimatingRenderNodes != null) {
787 final int count = attachInfo.mPendingAnimatingRenderNodes.size();
788 for (int i = 0; i < count; i++) {
789 registerAnimatingRenderNode(
790 attachInfo.mPendingAnimatingRenderNodes.get(i));
791 }
792 attachInfo.mPendingAnimatingRenderNodes.clear();
793 // We don't need this anymore as subsequent calls to
794 // ViewRootImpl#attachRenderNodeAnimator will go directly to us.
795 attachInfo.mPendingAnimatingRenderNodes = null;
796 }
797
John Reckba6adf62015-02-19 14:36:50 -0800798 final long[] frameInfo = choreographer.mFrameInfo.mFrameInfo;
799 int syncResult = nSyncAndDrawFrame(mNativeProxy, frameInfo, frameInfo.length);
John Reckaa95a882014-11-07 11:02:07 -0800800 if ((syncResult & SYNC_LOST_SURFACE_REWARD_IF_FOUND) != 0) {
801 setEnabled(false);
John Reckb13de072014-11-19 16:33:47 -0800802 attachInfo.mViewRootImpl.mSurface.release();
John Reckaa95a882014-11-07 11:02:07 -0800803 // Invalidate since we failed to draw. This should fetch a Surface
804 // if it is still needed or do nothing if we are no longer drawing
805 attachInfo.mViewRootImpl.invalidate();
806 }
John Reckf9be7792014-05-02 18:21:16 -0700807 if ((syncResult & SYNC_INVALIDATE_REQUIRED) != 0) {
808 attachInfo.mViewRootImpl.invalidate();
809 }
John Reckcec24ae2013-11-05 13:27:50 -0800810 }
811
John Reck3b202512014-06-23 13:13:08 -0700812 static void invokeFunctor(long functor, boolean waitForCompletion) {
813 nInvokeFunctor(functor, waitForCompletion);
John Reck0d1f6342014-03-28 20:30:27 -0700814 }
815
John Reck51aaf902015-12-02 15:08:07 -0800816 /**
817 * Creates a new hardware layer. A hardware layer built by calling this
818 * method will be treated as a texture layer, instead of as a render target.
819 *
820 * @return A hardware layer
821 */
John Reck19b6bcf2014-02-14 20:03:38 -0800822 HardwareLayer createTextureLayer() {
823 long layer = nCreateTextureLayer(mNativeProxy);
824 return HardwareLayer.adoptTextureLayer(this, layer);
825 }
826
John Reck51aaf902015-12-02 15:08:07 -0800827
John Reck3e824952014-08-20 10:08:39 -0700828 void buildLayer(RenderNode node) {
829 nBuildLayer(mNativeProxy, node.getNativeDisplayList());
830 }
831
John Reck51aaf902015-12-02 15:08:07 -0800832
John Reck19b6bcf2014-02-14 20:03:38 -0800833 boolean copyLayerInto(final HardwareLayer layer, final Bitmap bitmap) {
834 return nCopyLayerInto(mNativeProxy,
John Reck3731dc22015-04-13 15:20:29 -0700835 layer.getDeferredLayerUpdater(), bitmap);
John Reck19b6bcf2014-02-14 20:03:38 -0800836 }
837
John Reck51aaf902015-12-02 15:08:07 -0800838 /**
839 * Indicates that the specified hardware layer needs to be updated
840 * as soon as possible.
841 *
842 * @param layer The hardware layer that needs an update
843 */
John Reck19b6bcf2014-02-14 20:03:38 -0800844 void pushLayerUpdate(HardwareLayer layer) {
John Reckd72e0a32014-05-29 18:56:11 -0700845 nPushLayerUpdate(mNativeProxy, layer.getDeferredLayerUpdater());
John Reck19b6bcf2014-02-14 20:03:38 -0800846 }
847
John Reck51aaf902015-12-02 15:08:07 -0800848 /**
849 * Tells the HardwareRenderer that the layer is destroyed. The renderer
850 * should remove the layer from any update queues.
851 */
John Reck19b6bcf2014-02-14 20:03:38 -0800852 void onLayerDestroyed(HardwareLayer layer) {
John Reckd72e0a32014-05-29 18:56:11 -0700853 nCancelLayerUpdate(mNativeProxy, layer.getDeferredLayerUpdater());
John Reck19b6bcf2014-02-14 20:03:38 -0800854 }
855
John Reck51aaf902015-12-02 15:08:07 -0800856 /**
857 * Optional, sets the name of the renderer. Useful for debugging purposes.
858 *
859 * @param name The name of this renderer, can be null
860 */
John Reckcec24ae2013-11-05 13:27:50 -0800861 void setName(String name) {
John Reckb36016c2015-03-11 08:50:53 -0700862 nSetName(mNativeProxy, name);
John Reckcec24ae2013-11-05 13:27:50 -0800863 }
864
John Reck51aaf902015-12-02 15:08:07 -0800865 /**
866 * Blocks until all previously queued work has completed.
867 */
John Reck28ad7b52014-04-07 16:59:25 -0700868 void fence() {
869 nFence(mNativeProxy);
870 }
871
John Reck51aaf902015-12-02 15:08:07 -0800872 /**
873 * Prevents any further drawing until draw() is called. This is a signal
874 * that the contents of the RenderNode tree are no longer safe to play back.
875 * In practice this usually means that there are Functor pointers in the
876 * display list that are no longer valid.
877 */
John Reckf47a5942014-06-30 16:20:04 -0700878 void stopDrawing() {
879 nStopDrawing(mNativeProxy);
880 }
881
John Reck51aaf902015-12-02 15:08:07 -0800882 /**
883 * Called by {@link ViewRootImpl} when a new performTraverals is scheduled.
884 */
John Recka5dda642014-05-22 15:43:54 -0700885 public void notifyFramePending() {
886 nNotifyFramePending(mNativeProxy);
887 }
888
John Reck51aaf902015-12-02 15:08:07 -0800889
John Reck119907c2014-08-14 09:02:01 -0700890 void registerAnimatingRenderNode(RenderNode animator) {
891 nRegisterAnimatingRenderNode(mRootNode.mNativeRenderNode, animator.mNativeRenderNode);
892 }
893
John Recke248bd12015-08-05 13:53:53 -0700894 public void serializeDisplayListTree() {
895 nSerializeDisplayListTree(mNativeProxy);
896 }
897
John Reck119907c2014-08-14 09:02:01 -0700898 @Override
John Reck4f02bf42014-01-03 18:09:17 -0800899 protected void finalize() throws Throwable {
900 try {
901 nDeleteProxy(mNativeProxy);
John Reck0ed751d2014-04-08 14:10:17 -0700902 mNativeProxy = 0;
John Reck4f02bf42014-01-03 18:09:17 -0800903 } finally {
904 super.finalize();
John Reckcec24ae2013-11-05 13:27:50 -0800905 }
906 }
907
John Reckedc524c2015-03-18 15:24:33 -0700908 private static class ProcessInitializer {
909 static ProcessInitializer sInstance = new ProcessInitializer();
John Reckedc524c2015-03-18 15:24:33 -0700910 private static IBinder sProcToken;
John Reck66f0be62014-05-13 13:39:31 -0700911
912 private boolean mInitialized = false;
913
John Reckedc524c2015-03-18 15:24:33 -0700914 private ProcessInitializer() {}
John Reck66f0be62014-05-13 13:39:31 -0700915
John Reck3b202512014-06-23 13:13:08 -0700916 synchronized void init(Context context, long renderProxy) {
John Reck66f0be62014-05-13 13:39:31 -0700917 if (mInitialized) return;
John Reckedc524c2015-03-18 15:24:33 -0700918 mInitialized = true;
919 initGraphicsStats(context, renderProxy);
920 initAssetAtlas(context, renderProxy);
921 }
922
923 private static void initGraphicsStats(Context context, long renderProxy) {
John Reckedc524c2015-03-18 15:24:33 -0700924 try {
John Reck828698b2015-06-30 12:56:03 -0700925 IBinder binder = ServiceManager.getService("graphicsstats");
926 if (binder == null) return;
927 IGraphicsStats graphicsStatsService = IGraphicsStats.Stub
928 .asInterface(binder);
929 sProcToken = new Binder();
John Reckedc524c2015-03-18 15:24:33 -0700930 final String pkg = context.getApplicationInfo().packageName;
John Reck828698b2015-06-30 12:56:03 -0700931 ParcelFileDescriptor pfd = graphicsStatsService.
John Reckedc524c2015-03-18 15:24:33 -0700932 requestBufferForProcess(pkg, sProcToken);
933 nSetProcessStatsBuffer(renderProxy, pfd.getFd());
934 pfd.close();
John Reck828698b2015-06-30 12:56:03 -0700935 } catch (Throwable t) {
936 Log.w(LOG_TAG, "Could not acquire gfx stats buffer", t);
John Reckedc524c2015-03-18 15:24:33 -0700937 }
938 }
939
940 private static void initAssetAtlas(Context context, long renderProxy) {
John Reck66f0be62014-05-13 13:39:31 -0700941 IBinder binder = ServiceManager.getService("assetatlas");
942 if (binder == null) return;
943
944 IAssetAtlas atlas = IAssetAtlas.Stub.asInterface(binder);
945 try {
946 if (atlas.isCompatible(android.os.Process.myPpid())) {
947 GraphicBuffer buffer = atlas.getBuffer();
948 if (buffer != null) {
949 long[] map = atlas.getMap();
950 if (map != null) {
John Reck3b202512014-06-23 13:13:08 -0700951 nSetAtlas(renderProxy, buffer, map);
John Reck66f0be62014-05-13 13:39:31 -0700952 }
953 // If IAssetAtlas is not the same class as the IBinder
954 // we are using a remote service and we can safely
955 // destroy the graphic buffer
956 if (atlas.getClass() != binder.getClass()) {
957 buffer.destroy();
958 }
959 }
960 }
961 } catch (RemoteException e) {
962 Log.w(LOG_TAG, "Could not acquire atlas", e);
963 }
964 }
965 }
966
Andres Morales06f5bc72015-12-15 15:21:31 -0800967 void addFrameStatsObserver(FrameStatsObserver fso) {
968 if (mFrameStatsObservers == null) {
969 mFrameStatsObservers = new HashSet<>();
970 }
971
972 long nativeFso = nAddFrameStatsObserver(mNativeProxy, fso);
973 fso.mRenderer = this;
974 fso.mNative = new VirtualRefBasePtr(nativeFso);
975 mFrameStatsObservers.add(fso);
976 }
977
978 void removeFrameStatsObserver(FrameStatsObserver fso) {
979 if (!mFrameStatsObservers.remove(fso)) {
980 throw new IllegalArgumentException("attempt to remove FrameStatsObserver that was never added");
981 }
982
983 nRemoveFrameStatsObserver(mNativeProxy, fso.mNative.get());
984 fso.mRenderer = null;
985 fso.mNative = null;
986 }
987
988 long getDroppedFrameReportCount() {
989 return nGetDroppedFrameReportCount(mNativeProxy);
990 }
991
John Reck84a4c882014-05-30 14:34:03 -0700992 static native void setupShadersDiskCache(String cacheFile);
Michael Lentine03d8f7682016-01-31 15:37:11 -0600993 static native void setupVulkanLayerPath(String layerPath);
John Reck84a4c882014-05-30 14:34:03 -0700994
John Reck3b202512014-06-23 13:13:08 -0700995 private static native void nSetAtlas(long nativeProxy, GraphicBuffer buffer, long[] map);
John Reckedc524c2015-03-18 15:24:33 -0700996 private static native void nSetProcessStatsBuffer(long nativeProxy, int fd);
John Reck4f02bf42014-01-03 18:09:17 -0800997
John Recke45b1fd2014-04-15 09:50:16 -0700998 private static native long nCreateRootRenderNode();
999 private static native long nCreateProxy(boolean translucent, long rootRenderNode);
John Reck4f02bf42014-01-03 18:09:17 -08001000 private static native void nDeleteProxy(long nativeProxy);
1001
John Recke4280ba2014-05-05 16:39:37 -07001002 private static native boolean nLoadSystemProperties(long nativeProxy);
John Reckb36016c2015-03-11 08:50:53 -07001003 private static native void nSetName(long nativeProxy, String name);
John Reck18f16e62014-05-02 16:46:41 -07001004
Thomas Buhot0bcd0cb2015-12-04 12:18:03 +01001005 private static native void nInitialize(long nativeProxy, Surface window);
John Reck4f02bf42014-01-03 18:09:17 -08001006 private static native void nUpdateSurface(long nativeProxy, Surface window);
John Reck01a5ea32014-12-03 13:01:07 -08001007 private static native boolean nPauseSurface(long nativeProxy, Surface window);
Chris Craik797b95b2014-05-20 18:10:25 -07001008 private static native void nSetup(long nativeProxy, int width, int height,
Alan Viverette50210d92015-05-14 18:05:36 -07001009 float lightRadius, int ambientShadowAlpha, int spotShadowAlpha);
1010 private static native void nSetLightCenter(long nativeProxy,
1011 float lightX, float lightY, float lightZ);
John Reck63a06672014-05-07 13:45:54 -07001012 private static native void nSetOpaque(long nativeProxy, boolean opaque);
John Reckba6adf62015-02-19 14:36:50 -08001013 private static native int nSyncAndDrawFrame(long nativeProxy, long[] frameInfo, int size);
John Reck17035b02014-09-03 07:39:53 -07001014 private static native void nDestroy(long nativeProxy);
John Reck119907c2014-08-14 09:02:01 -07001015 private static native void nRegisterAnimatingRenderNode(long rootRenderNode, long animatingNode);
John Reck4f02bf42014-01-03 18:09:17 -08001016
John Reck3b202512014-06-23 13:13:08 -07001017 private static native void nInvokeFunctor(long functor, boolean waitForCompletion);
John Reck19b6bcf2014-02-14 20:03:38 -08001018
John Reck19b6bcf2014-02-14 20:03:38 -08001019 private static native long nCreateTextureLayer(long nativeProxy);
John Reck3e824952014-08-20 10:08:39 -07001020 private static native void nBuildLayer(long nativeProxy, long node);
John Reck3731dc22015-04-13 15:20:29 -07001021 private static native boolean nCopyLayerInto(long nativeProxy, long layer, Bitmap bitmap);
John Reckd72e0a32014-05-29 18:56:11 -07001022 private static native void nPushLayerUpdate(long nativeProxy, long layer);
1023 private static native void nCancelLayerUpdate(long nativeProxy, long layer);
John Reck918ad522014-06-27 14:45:25 -07001024 private static native void nDetachSurfaceTexture(long nativeProxy, long layer);
John Reck28ad7b52014-04-07 16:59:25 -07001025
John Reckf47a5942014-06-30 16:20:04 -07001026 private static native void nDestroyHardwareResources(long nativeProxy);
1027 private static native void nTrimMemory(int level);
Chris Craik2507c342015-05-04 14:36:49 -07001028 private static native void nOverrideProperty(String name, String value);
John Recke1628b72014-05-23 15:11:19 -07001029
John Reck28ad7b52014-04-07 16:59:25 -07001030 private static native void nFence(long nativeProxy);
John Reckf47a5942014-06-30 16:20:04 -07001031 private static native void nStopDrawing(long nativeProxy);
John Recka5dda642014-05-22 15:43:54 -07001032 private static native void nNotifyFramePending(long nativeProxy);
John Reckfe5e7b72014-05-23 17:42:28 -07001033
John Recke248bd12015-08-05 13:53:53 -07001034 private static native void nSerializeDisplayListTree(long nativeProxy);
1035
John Reckba6adf62015-02-19 14:36:50 -08001036 private static native void nDumpProfileInfo(long nativeProxy, FileDescriptor fd,
1037 @DumpFlags int dumpFlags);
John Reckedc524c2015-03-18 15:24:33 -07001038 private static native void nDumpProfileData(byte[] data, FileDescriptor fd);
Skuhneea7a7fb2015-08-28 07:10:31 -07001039
1040 private static native void nAddRenderNode(long nativeProxy, long rootRenderNode,
1041 boolean placeFront);
1042 private static native void nRemoveRenderNode(long nativeProxy, long rootRenderNode);
1043 private static native void nDrawRenderNode(long nativeProxy, long rootRenderNode);
Skuhneb8160872015-09-22 09:51:39 -07001044 private static native void nSetContentDrawBounds(long nativeProxy, int left,
Skuhneea7a7fb2015-08-28 07:10:31 -07001045 int top, int right, int bottom);
Andres Morales06f5bc72015-12-15 15:21:31 -08001046
1047 private static native long nAddFrameStatsObserver(long nativeProxy, FrameStatsObserver fso);
1048 private static native void nRemoveFrameStatsObserver(long nativeProxy, long nativeFso);
1049 private static native long nGetDroppedFrameReportCount(long nativeProxy);
John Reckcec24ae2013-11-05 13:27:50 -08001050}