blob: 78a63a6f88e178deb97114548fd8174f244bb79c [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 /**
255 * Creates a hardware renderer using OpenGL.
256 *
257 * @param translucent True if the surface is translucent, false otherwise
258 *
259 * @return A hardware renderer backed by OpenGL.
260 */
261 public static ThreadedRenderer create(Context context, boolean translucent) {
262 ThreadedRenderer renderer = null;
263 if (DisplayListCanvas.isAvailable()) {
264 renderer = new ThreadedRenderer(context, translucent);
265 }
266 return renderer;
267 }
268
269 /**
270 * Invoke this method when the system is running out of memory. This
271 * method will attempt to recover as much memory as possible, based on
272 * the specified hint.
273 *
274 * @param level Hint about the amount of memory that should be trimmed,
275 * see {@link android.content.ComponentCallbacks}
276 */
277 public static void trimMemory(int level) {
278 nTrimMemory(level);
279 }
280
281 public static void overrideProperty(@NonNull String name, @NonNull String value) {
282 if (name == null || value == null) {
283 throw new IllegalArgumentException("name and value must be non-null");
284 }
285 nOverrideProperty(name, value);
286 }
287
288 public static void dumpProfileData(byte[] data, FileDescriptor fd) {
289 nDumpProfileData(data, fd);
290 }
John Reckcec24ae2013-11-05 13:27:50 -0800291
John Reckf9be7792014-05-02 18:21:16 -0700292 // Keep in sync with DrawFrameTask.h SYNC_* flags
293 // Nothing interesting to report
John Reckcd028f32014-06-24 08:44:29 -0700294 private static final int SYNC_OK = 0;
John Reckf9be7792014-05-02 18:21:16 -0700295 // Needs a ViewRoot invalidate
John Reckcd028f32014-06-24 08:44:29 -0700296 private static final int SYNC_INVALIDATE_REQUIRED = 1 << 0;
John Reckaa95a882014-11-07 11:02:07 -0800297 // Spoiler: the reward is GPU-accelerated drawing, better find that Surface!
298 private static final int SYNC_LOST_SURFACE_REWARD_IF_FOUND = 1 << 1;
John Reckf9be7792014-05-02 18:21:16 -0700299
John Reckfe5e7b72014-05-23 17:42:28 -0700300 private static final String[] VISUALIZERS = {
301 PROFILE_PROPERTY_VISUALIZE_BARS,
302 };
303
John Reckba6adf62015-02-19 14:36:50 -0800304 private static final int FLAG_DUMP_FRAMESTATS = 1 << 0;
305 private static final int FLAG_DUMP_RESET = 1 << 1;
306
307 @IntDef(flag = true, value = {
308 FLAG_DUMP_FRAMESTATS, FLAG_DUMP_RESET })
309 @Retention(RetentionPolicy.SOURCE)
310 public @interface DumpFlags {}
311
Alan Viveretteccb11e12014-07-08 16:04:02 -0700312 // Size of the rendered content.
John Reckcec24ae2013-11-05 13:27:50 -0800313 private int mWidth, mHeight;
Alan Viveretteccb11e12014-07-08 16:04:02 -0700314
315 // Actual size of the drawing surface.
316 private int mSurfaceWidth, mSurfaceHeight;
317
318 // Insets between the drawing surface and rendered content. These are
319 // applied as translation when updating the root render node.
320 private int mInsetTop, mInsetLeft;
321
Alan Viverette57774a82014-07-15 15:49:55 -0700322 // Whether the surface has insets. Used to protect opacity.
323 private boolean mHasInsets;
324
Alan Viverette58c42c32014-07-12 20:33:45 -0700325 // Light and shadow properties specified by the theme.
326 private final float mLightY;
327 private final float mLightZ;
328 private final float mLightRadius;
Chris Craik058fc642014-07-23 18:19:28 -0700329 private final int mAmbientShadowAlpha;
330 private final int mSpotShadowAlpha;
Alan Viverette58c42c32014-07-12 20:33:45 -0700331
John Reck4f02bf42014-01-03 18:09:17 -0800332 private long mNativeProxy;
John Reckf7d9c1d2014-04-09 10:01:03 -0700333 private boolean mInitialized = false;
John Reckbc0cc022014-04-11 16:08:14 -0700334 private RenderNode mRootNode;
John Reck18f16e62014-05-02 16:46:41 -0700335 private Choreographer mChoreographer;
John Reck0a973302014-07-16 13:29:45 -0700336 private boolean mRootNodeNeedsUpdate;
John Reckcec24ae2013-11-05 13:27:50 -0800337
Skuhneea7a7fb2015-08-28 07:10:31 -0700338 // In case of multi threaded render nodes, these bounds indicate the content bounds against
339 // which the backdrop needs to be cropped against.
340 private final Rect mCurrentContentBounds = new Rect();
341 private final Rect mStagedContentBounds = new Rect();
342
John Reck51aaf902015-12-02 15:08:07 -0800343 private boolean mEnabled;
344 private boolean mRequested = true;
345
Andres Morales06f5bc72015-12-15 15:21:31 -0800346 private HashSet<FrameStatsObserver> mFrameStatsObservers;
347
John Reckb8802b12014-06-16 15:28:50 -0700348 ThreadedRenderer(Context context, boolean translucent) {
Alan Viveretteed6f14a2014-08-26 14:53:28 -0700349 final TypedArray a = context.obtainStyledAttributes(null, R.styleable.Lighting, 0, 0);
Alan Viverette58c42c32014-07-12 20:33:45 -0700350 mLightY = a.getDimension(R.styleable.Lighting_lightY, 0);
351 mLightZ = a.getDimension(R.styleable.Lighting_lightZ, 0);
352 mLightRadius = a.getDimension(R.styleable.Lighting_lightRadius, 0);
Alan Viveretteed6f14a2014-08-26 14:53:28 -0700353 mAmbientShadowAlpha =
354 (int) (255 * a.getFloat(R.styleable.Lighting_ambientShadowAlpha, 0) + 0.5f);
355 mSpotShadowAlpha = (int) (255 * a.getFloat(R.styleable.Lighting_spotShadowAlpha, 0) + 0.5f);
Alan Viverette58c42c32014-07-12 20:33:45 -0700356 a.recycle();
357
John Recke45b1fd2014-04-15 09:50:16 -0700358 long rootNodePtr = nCreateRootRenderNode();
359 mRootNode = RenderNode.adopt(rootNodePtr);
John Reckbc0cc022014-04-11 16:08:14 -0700360 mRootNode.setClipToBounds(false);
John Recke45b1fd2014-04-15 09:50:16 -0700361 mNativeProxy = nCreateProxy(translucent, rootNodePtr);
John Reck18f16e62014-05-02 16:46:41 -0700362
John Reckedc524c2015-03-18 15:24:33 -0700363 ProcessInitializer.sInstance.init(context, mNativeProxy);
John Reck3b202512014-06-23 13:13:08 -0700364
John Reckfe5e7b72014-05-23 17:42:28 -0700365 loadSystemProperties();
John Reckcec24ae2013-11-05 13:27:50 -0800366 }
367
John Reck51aaf902015-12-02 15:08:07 -0800368 /**
369 * Destroys the hardware rendering context.
370 */
John Reckf47a5942014-06-30 16:20:04 -0700371 void destroy() {
John Reckf7d9c1d2014-04-09 10:01:03 -0700372 mInitialized = false;
373 updateEnabledState(null);
John Reck17035b02014-09-03 07:39:53 -0700374 nDestroy(mNativeProxy);
John Reckcec24ae2013-11-05 13:27:50 -0800375 }
376
John Reck51aaf902015-12-02 15:08:07 -0800377 /**
378 * Indicates whether hardware acceleration is currently enabled.
379 *
380 * @return True if hardware acceleration is in use, false otherwise.
381 */
382 boolean isEnabled() {
383 return mEnabled;
384 }
385
386 /**
387 * Indicates whether hardware acceleration is currently enabled.
388 *
389 * @param enabled True if the hardware renderer is in use, false otherwise.
390 */
391 void setEnabled(boolean enabled) {
392 mEnabled = enabled;
393 }
394
395 /**
396 * Indicates whether hardware acceleration is currently request but not
397 * necessarily enabled yet.
398 *
399 * @return True if requested, false otherwise.
400 */
401 boolean isRequested() {
402 return mRequested;
403 }
404
405 /**
406 * Indicates whether hardware acceleration is currently requested but not
407 * necessarily enabled yet.
408 *
409 * @return True to request hardware acceleration, false otherwise.
410 */
411 void setRequested(boolean requested) {
412 mRequested = requested;
413 }
414
John Reckf7d9c1d2014-04-09 10:01:03 -0700415 private void updateEnabledState(Surface surface) {
416 if (surface == null || !surface.isValid()) {
417 setEnabled(false);
418 } else {
419 setEnabled(mInitialized);
420 }
421 }
422
John Reck51aaf902015-12-02 15:08:07 -0800423 /**
424 * Initializes the hardware renderer for the specified surface.
425 *
426 * @param surface The surface to hardware accelerate
427 *
428 * @return True if the initialization was successful, false otherwise.
429 */
John Reckcec24ae2013-11-05 13:27:50 -0800430 boolean initialize(Surface surface) throws OutOfResourcesException {
Thomas Buhot0bcd0cb2015-12-04 12:18:03 +0100431 boolean status = !mInitialized;
John Reckf7d9c1d2014-04-09 10:01:03 -0700432 mInitialized = true;
433 updateEnabledState(surface);
Thomas Buhot0bcd0cb2015-12-04 12:18:03 +0100434 nInitialize(mNativeProxy, surface);
Dan Stoza5795d642014-06-20 13:01:36 -0700435 return status;
John Reckcec24ae2013-11-05 13:27:50 -0800436 }
437
John Reck51aaf902015-12-02 15:08:07 -0800438 /**
439 * Initializes the hardware renderer for the specified surface and setup the
440 * renderer for drawing, if needed. This is invoked when the ViewAncestor has
441 * potentially lost the hardware renderer. The hardware renderer should be
442 * reinitialized and setup when the render {@link #isRequested()} and
443 * {@link #isEnabled()}.
444 *
445 * @param width The width of the drawing surface.
446 * @param height The height of the drawing surface.
447 * @param attachInfo Information about the window.
448 * @param surface The surface to hardware accelerate
449 * @param surfaceInsets The drawing surface insets to apply
450 *
451 * @return true if the surface was initialized, false otherwise. Returning
452 * false might mean that the surface was already initialized.
453 */
454 boolean initializeIfNeeded(int width, int height, View.AttachInfo attachInfo,
455 Surface surface, Rect surfaceInsets) throws OutOfResourcesException {
456 if (isRequested()) {
457 // We lost the gl context, so recreate it.
458 if (!isEnabled()) {
459 if (initialize(surface)) {
460 setup(width, height, attachInfo, surfaceInsets);
461 return true;
462 }
463 }
464 }
465 return false;
466 }
467
468 /**
469 * Updates the hardware renderer for the specified surface.
470 *
471 * @param surface The surface to hardware accelerate
472 */
John Reckcec24ae2013-11-05 13:27:50 -0800473 void updateSurface(Surface surface) throws OutOfResourcesException {
John Reckf7d9c1d2014-04-09 10:01:03 -0700474 updateEnabledState(surface);
John Reck4f02bf42014-01-03 18:09:17 -0800475 nUpdateSurface(mNativeProxy, surface);
John Reckcec24ae2013-11-05 13:27:50 -0800476 }
477
John Reck51aaf902015-12-02 15:08:07 -0800478 /**
479 * Stops any rendering into the surface. Use this if it is unclear whether
480 * or not the surface used by the HardwareRenderer will be changing. It
481 * Suspends any rendering into the surface, but will not do any destruction
482 */
John Reck01a5ea32014-12-03 13:01:07 -0800483 boolean pauseSurface(Surface surface) {
484 return nPauseSurface(mNativeProxy, surface);
John Reckf7d9c1d2014-04-09 10:01:03 -0700485 }
486
John Reck51aaf902015-12-02 15:08:07 -0800487 /**
488 * Destroys all hardware rendering resources associated with the specified
489 * view hierarchy.
490 *
491 * @param view The root of the view hierarchy
492 */
John Reckcec24ae2013-11-05 13:27:50 -0800493 void destroyHardwareResources(View view) {
John Reck4f02bf42014-01-03 18:09:17 -0800494 destroyResources(view);
John Reckf47a5942014-06-30 16:20:04 -0700495 nDestroyHardwareResources(mNativeProxy);
John Reck4f02bf42014-01-03 18:09:17 -0800496 }
497
498 private static void destroyResources(View view) {
499 view.destroyHardwareResources();
500
501 if (view instanceof ViewGroup) {
502 ViewGroup group = (ViewGroup) view;
503
504 int count = group.getChildCount();
505 for (int i = 0; i < count; i++) {
506 destroyResources(group.getChildAt(i));
507 }
508 }
John Reckcec24ae2013-11-05 13:27:50 -0800509 }
510
John Reck51aaf902015-12-02 15:08:07 -0800511 /**
512 * This method should be invoked whenever the current hardware renderer
513 * context should be reset.
514 *
515 * @param surface The surface to hardware accelerate
516 */
John Reckcec24ae2013-11-05 13:27:50 -0800517 void invalidate(Surface surface) {
John Reck4f02bf42014-01-03 18:09:17 -0800518 updateSurface(surface);
John Reckcec24ae2013-11-05 13:27:50 -0800519 }
520
John Reck51aaf902015-12-02 15:08:07 -0800521 /**
522 * Detaches the layer's surface texture from the GL context and releases
523 * the texture id
524 */
John Reck918ad522014-06-27 14:45:25 -0700525 void detachSurfaceTexture(long hardwareLayer) {
526 nDetachSurfaceTexture(mNativeProxy, hardwareLayer);
John Reckcec24ae2013-11-05 13:27:50 -0800527 }
528
John Reck51aaf902015-12-02 15:08:07 -0800529 /**
530 * Sets up the renderer for drawing.
531 *
532 * @param width The width of the drawing surface.
533 * @param height The height of the drawing surface.
534 * @param attachInfo Information about the window.
535 * @param surfaceInsets The drawing surface insets to apply
536 */
Alan Viverette50210d92015-05-14 18:05:36 -0700537 void setup(int width, int height, AttachInfo attachInfo, Rect surfaceInsets) {
John Reckcec24ae2013-11-05 13:27:50 -0800538 mWidth = width;
539 mHeight = height;
Alan Viverette50210d92015-05-14 18:05:36 -0700540
Alan Viverette3aa1ffb2014-10-30 12:22:08 -0700541 if (surfaceInsets != null && (surfaceInsets.left != 0 || surfaceInsets.right != 0
542 || surfaceInsets.top != 0 || surfaceInsets.bottom != 0)) {
Alan Viverette57774a82014-07-15 15:49:55 -0700543 mHasInsets = true;
Alan Viveretteccb11e12014-07-08 16:04:02 -0700544 mInsetLeft = surfaceInsets.left;
545 mInsetTop = surfaceInsets.top;
546 mSurfaceWidth = width + mInsetLeft + surfaceInsets.right;
547 mSurfaceHeight = height + mInsetTop + surfaceInsets.bottom;
Alan Viverette57774a82014-07-15 15:49:55 -0700548
549 // If the surface has insets, it can't be opaque.
550 setOpaque(false);
Alan Viveretteccb11e12014-07-08 16:04:02 -0700551 } else {
Alan Viverette57774a82014-07-15 15:49:55 -0700552 mHasInsets = false;
Alan Viveretteccb11e12014-07-08 16:04:02 -0700553 mInsetLeft = 0;
554 mInsetTop = 0;
555 mSurfaceWidth = width;
556 mSurfaceHeight = height;
557 }
Alan Viverette50210d92015-05-14 18:05:36 -0700558
Alan Viveretteccb11e12014-07-08 16:04:02 -0700559 mRootNode.setLeftTopRightBottom(-mInsetLeft, -mInsetTop, mSurfaceWidth, mSurfaceHeight);
Alan Viverette50210d92015-05-14 18:05:36 -0700560 nSetup(mNativeProxy, mSurfaceWidth, mSurfaceHeight, mLightRadius,
John Reckb36016c2015-03-11 08:50:53 -0700561 mAmbientShadowAlpha, mSpotShadowAlpha);
Alan Viverette50210d92015-05-14 18:05:36 -0700562
563 setLightCenter(attachInfo);
564 }
565
John Reck51aaf902015-12-02 15:08:07 -0800566 /**
567 * Updates the light position based on the position of the window.
568 *
569 * @param attachInfo Information about the window.
570 */
Alan Viverette50210d92015-05-14 18:05:36 -0700571 void setLightCenter(AttachInfo attachInfo) {
572 // Adjust light position for window offsets.
573 final Point displaySize = attachInfo.mPoint;
574 attachInfo.mDisplay.getRealSize(displaySize);
575 final float lightX = displaySize.x / 2f - attachInfo.mWindowLeft;
576 final float lightY = mLightY - attachInfo.mWindowTop;
577
578 nSetLightCenter(mNativeProxy, lightX, lightY, mLightZ);
John Reckcec24ae2013-11-05 13:27:50 -0800579 }
580
John Reck51aaf902015-12-02 15:08:07 -0800581 /**
582 * Change the HardwareRenderer's opacity
583 */
John Reck63a06672014-05-07 13:45:54 -0700584 void setOpaque(boolean opaque) {
Alan Viverette57774a82014-07-15 15:49:55 -0700585 nSetOpaque(mNativeProxy, opaque && !mHasInsets);
John Reck63a06672014-05-07 13:45:54 -0700586 }
587
John Reck51aaf902015-12-02 15:08:07 -0800588 /**
589 * Gets the current width of the surface. This is the width that the surface
590 * was last set to in a call to {@link #setup(int, int, View.AttachInfo, Rect)}.
591 *
592 * @return the current width of the surface
593 */
John Reckcec24ae2013-11-05 13:27:50 -0800594 int getWidth() {
595 return mWidth;
596 }
597
John Reck51aaf902015-12-02 15:08:07 -0800598 /**
599 * Gets the current height of the surface. This is the height that the surface
600 * was last set to in a call to {@link #setup(int, int, View.AttachInfo, Rect)}.
601 *
602 * @return the current width of the surface
603 */
John Reckcec24ae2013-11-05 13:27:50 -0800604 int getHeight() {
605 return mHeight;
606 }
607
John Reck51aaf902015-12-02 15:08:07 -0800608 /**
609 * Outputs extra debugging information in the specified file descriptor.
610 */
John Reckba6adf62015-02-19 14:36:50 -0800611 void dumpGfxInfo(PrintWriter pw, FileDescriptor fd, String[] args) {
John Reckfe5e7b72014-05-23 17:42:28 -0700612 pw.flush();
John Reckba6adf62015-02-19 14:36:50 -0800613 int flags = 0;
614 for (int i = 0; i < args.length; i++) {
615 switch (args[i]) {
616 case "framestats":
617 flags |= FLAG_DUMP_FRAMESTATS;
618 break;
619 case "reset":
620 flags |= FLAG_DUMP_RESET;
621 break;
622 }
John Reckfe5e7b72014-05-23 17:42:28 -0700623 }
John Reckba6adf62015-02-19 14:36:50 -0800624 nDumpProfileInfo(mNativeProxy, fd, flags);
John Reckcec24ae2013-11-05 13:27:50 -0800625 }
626
John Reck51aaf902015-12-02 15:08:07 -0800627 /**
628 * Loads system properties used by the renderer. This method is invoked
629 * whenever system properties are modified. Implementations can use this
630 * to trigger live updates of the renderer based on properties.
631 *
632 * @return True if a property has changed.
633 */
John Reckcec24ae2013-11-05 13:27:50 -0800634 boolean loadSystemProperties() {
John Reckfe5e7b72014-05-23 17:42:28 -0700635 boolean changed = nLoadSystemProperties(mNativeProxy);
John Reck23d307c2014-10-27 12:38:48 -0700636 if (changed) {
637 invalidateRoot();
638 }
John Reckfe5e7b72014-05-23 17:42:28 -0700639 return changed;
John Reckcec24ae2013-11-05 13:27:50 -0800640 }
641
John Reck0a973302014-07-16 13:29:45 -0700642 private void updateViewTreeDisplayList(View view) {
John Reckcec24ae2013-11-05 13:27:50 -0800643 view.mPrivateFlags |= View.PFLAG_DRAWN;
John Reckcec24ae2013-11-05 13:27:50 -0800644 view.mRecreateDisplayList = (view.mPrivateFlags & View.PFLAG_INVALIDATED)
645 == View.PFLAG_INVALIDATED;
646 view.mPrivateFlags &= ~View.PFLAG_INVALIDATED;
Chris Craik31a2d062015-05-01 14:22:47 -0700647 view.updateDisplayListIfDirty();
John Reckcec24ae2013-11-05 13:27:50 -0800648 view.mRecreateDisplayList = false;
John Reckbc0cc022014-04-11 16:08:14 -0700649 }
650
John Reck61375a82014-09-18 19:27:48 +0000651 private void updateRootDisplayList(View view, HardwareDrawCallbacks callbacks) {
Chris Craik70850ea2014-11-18 10:49:23 -0800652 Trace.traceBegin(Trace.TRACE_TAG_VIEW, "Record View#draw()");
John Reck0a973302014-07-16 13:29:45 -0700653 updateViewTreeDisplayList(view);
654
655 if (mRootNodeNeedsUpdate || !mRootNode.isValid()) {
Chris Craikf6829a02015-03-10 10:28:59 -0700656 DisplayListCanvas canvas = mRootNode.start(mSurfaceWidth, mSurfaceHeight);
John Reck0a973302014-07-16 13:29:45 -0700657 try {
Alan Viverettedbed8932014-08-06 17:54:52 -0700658 final int saveCount = canvas.save();
John Reck0a973302014-07-16 13:29:45 -0700659 canvas.translate(mInsetLeft, mInsetTop);
660 callbacks.onHardwarePreDraw(canvas);
Chris Craikabedca32014-08-28 15:03:55 -0700661
662 canvas.insertReorderBarrier();
Chris Craik31a2d062015-05-01 14:22:47 -0700663 canvas.drawRenderNode(view.updateDisplayListIfDirty());
Chris Craikabedca32014-08-28 15:03:55 -0700664 canvas.insertInorderBarrier();
665
John Reck0a973302014-07-16 13:29:45 -0700666 callbacks.onHardwarePostDraw(canvas);
Alan Viverettedbed8932014-08-06 17:54:52 -0700667 canvas.restoreToCount(saveCount);
John Reck0a973302014-07-16 13:29:45 -0700668 mRootNodeNeedsUpdate = false;
669 } finally {
670 mRootNode.end(canvas);
671 }
672 }
673 Trace.traceEnd(Trace.TRACE_TAG_VIEW);
674 }
675
Skuhneea7a7fb2015-08-28 07:10:31 -0700676 /**
677 * Adds a rendernode to the renderer which can be drawn and changed asynchronously to the
678 * rendernode of the UI thread.
679 * @param node The node to add.
680 * @param placeFront If true, the render node will be placed in front of the content node,
681 * otherwise behind the content node.
682 */
683 public void addRenderNode(RenderNode node, boolean placeFront) {
684 nAddRenderNode(mNativeProxy, node.mNativeRenderNode, placeFront);
685 }
686
687 /**
688 * Only especially added render nodes can be removed.
689 * @param node The node which was added via addRenderNode which should get removed again.
690 */
691 public void removeRenderNode(RenderNode node) {
692 nRemoveRenderNode(mNativeProxy, node.mNativeRenderNode);
693 }
694
695 /**
696 * Draws a particular render node. If the node is not the content node, only the additional
697 * nodes will get drawn and the content remains untouched.
698 * @param node The node to be drawn.
699 */
700 public void drawRenderNode(RenderNode node) {
701 nDrawRenderNode(mNativeProxy, node.mNativeRenderNode);
702 }
703
704 /**
705 * To avoid unnecessary overdrawing of the main content all additionally passed render nodes
706 * will be prevented to overdraw this area. It will be synchronized with the draw call.
707 * This should be updated in the content view's draw call.
708 * @param left The left side of the protected bounds.
709 * @param top The top side of the protected bounds.
710 * @param right The right side of the protected bounds.
711 * @param bottom The bottom side of the protected bounds.
712 */
Skuhneb8160872015-09-22 09:51:39 -0700713 public void setContentDrawBounds(int left, int top, int right, int bottom) {
Skuhneea7a7fb2015-08-28 07:10:31 -0700714 mStagedContentBounds.set(left, top, right, bottom);
715 }
716
John Reck51aaf902015-12-02 15:08:07 -0800717 /**
718 * Interface used to receive callbacks whenever a view is drawn by
719 * a hardware renderer instance.
720 */
721 interface HardwareDrawCallbacks {
722 /**
723 * Invoked before a view is drawn by a hardware renderer.
724 * This method can be used to apply transformations to the
725 * canvas but no drawing command should be issued.
726 *
727 * @param canvas The Canvas used to render the view.
728 */
729 void onHardwarePreDraw(DisplayListCanvas canvas);
730
731 /**
732 * Invoked after a view is drawn by a hardware renderer.
733 * It is safe to invoke drawing commands from this method.
734 *
735 * @param canvas The Canvas used to render the view.
736 */
737 void onHardwarePostDraw(DisplayListCanvas canvas);
738 }
739
740 /**
741 * Indicates that the content drawn by HardwareDrawCallbacks needs to
742 * be updated, which will be done by the next call to draw()
743 */
John Reck0a973302014-07-16 13:29:45 -0700744 void invalidateRoot() {
745 mRootNodeNeedsUpdate = true;
746 }
747
John Reck51aaf902015-12-02 15:08:07 -0800748 /**
749 * Draws the specified view.
750 *
751 * @param view The view to draw.
752 * @param attachInfo AttachInfo tied to the specified view.
753 * @param callbacks Callbacks invoked when drawing happens.
754 */
John Reck61375a82014-09-18 19:27:48 +0000755 void draw(View view, AttachInfo attachInfo, HardwareDrawCallbacks callbacks) {
John Reckbc0cc022014-04-11 16:08:14 -0700756 attachInfo.mIgnoreDirtyState = true;
John Reckbc0cc022014-04-11 16:08:14 -0700757
John Reckba6adf62015-02-19 14:36:50 -0800758 final Choreographer choreographer = attachInfo.mViewRootImpl.mChoreographer;
759 choreographer.mFrameInfo.markDrawStart();
John Reckfe5e7b72014-05-23 17:42:28 -0700760
John Reck61375a82014-09-18 19:27:48 +0000761 updateRootDisplayList(view, callbacks);
Skuhneea7a7fb2015-08-28 07:10:31 -0700762 // The main content view was updating the content bounds and we transfer them to the
763 // renderer.
764 if (!mCurrentContentBounds.equals(mStagedContentBounds)) {
765 mCurrentContentBounds.set(mStagedContentBounds);
Skuhneb8160872015-09-22 09:51:39 -0700766 nSetContentDrawBounds(mNativeProxy, mCurrentContentBounds.left,
767 mCurrentContentBounds.top, mCurrentContentBounds.right,
768 mCurrentContentBounds.bottom);
Skuhneea7a7fb2015-08-28 07:10:31 -0700769 }
John Reckcec24ae2013-11-05 13:27:50 -0800770
John Reck6313b922014-04-16 18:59:21 -0700771 attachInfo.mIgnoreDirtyState = false;
772
John Reck119907c2014-08-14 09:02:01 -0700773 // register animating rendernodes which started animating prior to renderer
774 // creation, which is typical for animators started prior to first draw
775 if (attachInfo.mPendingAnimatingRenderNodes != null) {
776 final int count = attachInfo.mPendingAnimatingRenderNodes.size();
777 for (int i = 0; i < count; i++) {
778 registerAnimatingRenderNode(
779 attachInfo.mPendingAnimatingRenderNodes.get(i));
780 }
781 attachInfo.mPendingAnimatingRenderNodes.clear();
782 // We don't need this anymore as subsequent calls to
783 // ViewRootImpl#attachRenderNodeAnimator will go directly to us.
784 attachInfo.mPendingAnimatingRenderNodes = null;
785 }
786
John Reckba6adf62015-02-19 14:36:50 -0800787 final long[] frameInfo = choreographer.mFrameInfo.mFrameInfo;
788 int syncResult = nSyncAndDrawFrame(mNativeProxy, frameInfo, frameInfo.length);
John Reckaa95a882014-11-07 11:02:07 -0800789 if ((syncResult & SYNC_LOST_SURFACE_REWARD_IF_FOUND) != 0) {
790 setEnabled(false);
John Reckb13de072014-11-19 16:33:47 -0800791 attachInfo.mViewRootImpl.mSurface.release();
John Reckaa95a882014-11-07 11:02:07 -0800792 // Invalidate since we failed to draw. This should fetch a Surface
793 // if it is still needed or do nothing if we are no longer drawing
794 attachInfo.mViewRootImpl.invalidate();
795 }
John Reckf9be7792014-05-02 18:21:16 -0700796 if ((syncResult & SYNC_INVALIDATE_REQUIRED) != 0) {
797 attachInfo.mViewRootImpl.invalidate();
798 }
John Reckcec24ae2013-11-05 13:27:50 -0800799 }
800
John Reck3b202512014-06-23 13:13:08 -0700801 static void invokeFunctor(long functor, boolean waitForCompletion) {
802 nInvokeFunctor(functor, waitForCompletion);
John Reck0d1f6342014-03-28 20:30:27 -0700803 }
804
John Reck51aaf902015-12-02 15:08:07 -0800805 /**
806 * Creates a new hardware layer. A hardware layer built by calling this
807 * method will be treated as a texture layer, instead of as a render target.
808 *
809 * @return A hardware layer
810 */
John Reck19b6bcf2014-02-14 20:03:38 -0800811 HardwareLayer createTextureLayer() {
812 long layer = nCreateTextureLayer(mNativeProxy);
813 return HardwareLayer.adoptTextureLayer(this, layer);
814 }
815
John Reck51aaf902015-12-02 15:08:07 -0800816
John Reck3e824952014-08-20 10:08:39 -0700817 void buildLayer(RenderNode node) {
818 nBuildLayer(mNativeProxy, node.getNativeDisplayList());
819 }
820
John Reck51aaf902015-12-02 15:08:07 -0800821
John Reck19b6bcf2014-02-14 20:03:38 -0800822 boolean copyLayerInto(final HardwareLayer layer, final Bitmap bitmap) {
823 return nCopyLayerInto(mNativeProxy,
John Reck3731dc22015-04-13 15:20:29 -0700824 layer.getDeferredLayerUpdater(), bitmap);
John Reck19b6bcf2014-02-14 20:03:38 -0800825 }
826
John Reck51aaf902015-12-02 15:08:07 -0800827 /**
828 * Indicates that the specified hardware layer needs to be updated
829 * as soon as possible.
830 *
831 * @param layer The hardware layer that needs an update
832 */
John Reck19b6bcf2014-02-14 20:03:38 -0800833 void pushLayerUpdate(HardwareLayer layer) {
John Reckd72e0a32014-05-29 18:56:11 -0700834 nPushLayerUpdate(mNativeProxy, layer.getDeferredLayerUpdater());
John Reck19b6bcf2014-02-14 20:03:38 -0800835 }
836
John Reck51aaf902015-12-02 15:08:07 -0800837 /**
838 * Tells the HardwareRenderer that the layer is destroyed. The renderer
839 * should remove the layer from any update queues.
840 */
John Reck19b6bcf2014-02-14 20:03:38 -0800841 void onLayerDestroyed(HardwareLayer layer) {
John Reckd72e0a32014-05-29 18:56:11 -0700842 nCancelLayerUpdate(mNativeProxy, layer.getDeferredLayerUpdater());
John Reck19b6bcf2014-02-14 20:03:38 -0800843 }
844
John Reck51aaf902015-12-02 15:08:07 -0800845 /**
846 * Optional, sets the name of the renderer. Useful for debugging purposes.
847 *
848 * @param name The name of this renderer, can be null
849 */
John Reckcec24ae2013-11-05 13:27:50 -0800850 void setName(String name) {
John Reckb36016c2015-03-11 08:50:53 -0700851 nSetName(mNativeProxy, name);
John Reckcec24ae2013-11-05 13:27:50 -0800852 }
853
John Reck51aaf902015-12-02 15:08:07 -0800854 /**
855 * Blocks until all previously queued work has completed.
856 */
John Reck28ad7b52014-04-07 16:59:25 -0700857 void fence() {
858 nFence(mNativeProxy);
859 }
860
John Reck51aaf902015-12-02 15:08:07 -0800861 /**
862 * Prevents any further drawing until draw() is called. This is a signal
863 * that the contents of the RenderNode tree are no longer safe to play back.
864 * In practice this usually means that there are Functor pointers in the
865 * display list that are no longer valid.
866 */
John Reckf47a5942014-06-30 16:20:04 -0700867 void stopDrawing() {
868 nStopDrawing(mNativeProxy);
869 }
870
John Reck51aaf902015-12-02 15:08:07 -0800871 /**
872 * Called by {@link ViewRootImpl} when a new performTraverals is scheduled.
873 */
John Recka5dda642014-05-22 15:43:54 -0700874 public void notifyFramePending() {
875 nNotifyFramePending(mNativeProxy);
876 }
877
John Reck51aaf902015-12-02 15:08:07 -0800878
John Reck119907c2014-08-14 09:02:01 -0700879 void registerAnimatingRenderNode(RenderNode animator) {
880 nRegisterAnimatingRenderNode(mRootNode.mNativeRenderNode, animator.mNativeRenderNode);
881 }
882
John Recke248bd12015-08-05 13:53:53 -0700883 public void serializeDisplayListTree() {
884 nSerializeDisplayListTree(mNativeProxy);
885 }
886
John Reck119907c2014-08-14 09:02:01 -0700887 @Override
John Reck4f02bf42014-01-03 18:09:17 -0800888 protected void finalize() throws Throwable {
889 try {
890 nDeleteProxy(mNativeProxy);
John Reck0ed751d2014-04-08 14:10:17 -0700891 mNativeProxy = 0;
John Reck4f02bf42014-01-03 18:09:17 -0800892 } finally {
893 super.finalize();
John Reckcec24ae2013-11-05 13:27:50 -0800894 }
895 }
896
John Reckedc524c2015-03-18 15:24:33 -0700897 private static class ProcessInitializer {
898 static ProcessInitializer sInstance = new ProcessInitializer();
John Reckedc524c2015-03-18 15:24:33 -0700899 private static IBinder sProcToken;
John Reck66f0be62014-05-13 13:39:31 -0700900
901 private boolean mInitialized = false;
902
John Reckedc524c2015-03-18 15:24:33 -0700903 private ProcessInitializer() {}
John Reck66f0be62014-05-13 13:39:31 -0700904
John Reck3b202512014-06-23 13:13:08 -0700905 synchronized void init(Context context, long renderProxy) {
John Reck66f0be62014-05-13 13:39:31 -0700906 if (mInitialized) return;
John Reckedc524c2015-03-18 15:24:33 -0700907 mInitialized = true;
908 initGraphicsStats(context, renderProxy);
909 initAssetAtlas(context, renderProxy);
910 }
911
912 private static void initGraphicsStats(Context context, long renderProxy) {
John Reckedc524c2015-03-18 15:24:33 -0700913 try {
John Reck828698b2015-06-30 12:56:03 -0700914 IBinder binder = ServiceManager.getService("graphicsstats");
915 if (binder == null) return;
916 IGraphicsStats graphicsStatsService = IGraphicsStats.Stub
917 .asInterface(binder);
918 sProcToken = new Binder();
John Reckedc524c2015-03-18 15:24:33 -0700919 final String pkg = context.getApplicationInfo().packageName;
John Reck828698b2015-06-30 12:56:03 -0700920 ParcelFileDescriptor pfd = graphicsStatsService.
John Reckedc524c2015-03-18 15:24:33 -0700921 requestBufferForProcess(pkg, sProcToken);
922 nSetProcessStatsBuffer(renderProxy, pfd.getFd());
923 pfd.close();
John Reck828698b2015-06-30 12:56:03 -0700924 } catch (Throwable t) {
925 Log.w(LOG_TAG, "Could not acquire gfx stats buffer", t);
John Reckedc524c2015-03-18 15:24:33 -0700926 }
927 }
928
929 private static void initAssetAtlas(Context context, long renderProxy) {
John Reck66f0be62014-05-13 13:39:31 -0700930 IBinder binder = ServiceManager.getService("assetatlas");
931 if (binder == null) return;
932
933 IAssetAtlas atlas = IAssetAtlas.Stub.asInterface(binder);
934 try {
935 if (atlas.isCompatible(android.os.Process.myPpid())) {
936 GraphicBuffer buffer = atlas.getBuffer();
937 if (buffer != null) {
938 long[] map = atlas.getMap();
939 if (map != null) {
John Reck3b202512014-06-23 13:13:08 -0700940 nSetAtlas(renderProxy, buffer, map);
John Reck66f0be62014-05-13 13:39:31 -0700941 }
942 // If IAssetAtlas is not the same class as the IBinder
943 // we are using a remote service and we can safely
944 // destroy the graphic buffer
945 if (atlas.getClass() != binder.getClass()) {
946 buffer.destroy();
947 }
948 }
949 }
950 } catch (RemoteException e) {
951 Log.w(LOG_TAG, "Could not acquire atlas", e);
952 }
953 }
954 }
955
Andres Morales06f5bc72015-12-15 15:21:31 -0800956 void addFrameStatsObserver(FrameStatsObserver fso) {
957 if (mFrameStatsObservers == null) {
958 mFrameStatsObservers = new HashSet<>();
959 }
960
961 long nativeFso = nAddFrameStatsObserver(mNativeProxy, fso);
962 fso.mRenderer = this;
963 fso.mNative = new VirtualRefBasePtr(nativeFso);
964 mFrameStatsObservers.add(fso);
965 }
966
967 void removeFrameStatsObserver(FrameStatsObserver fso) {
968 if (!mFrameStatsObservers.remove(fso)) {
969 throw new IllegalArgumentException("attempt to remove FrameStatsObserver that was never added");
970 }
971
972 nRemoveFrameStatsObserver(mNativeProxy, fso.mNative.get());
973 fso.mRenderer = null;
974 fso.mNative = null;
975 }
976
977 long getDroppedFrameReportCount() {
978 return nGetDroppedFrameReportCount(mNativeProxy);
979 }
980
John Reck84a4c882014-05-30 14:34:03 -0700981 static native void setupShadersDiskCache(String cacheFile);
982
John Reck3b202512014-06-23 13:13:08 -0700983 private static native void nSetAtlas(long nativeProxy, GraphicBuffer buffer, long[] map);
John Reckedc524c2015-03-18 15:24:33 -0700984 private static native void nSetProcessStatsBuffer(long nativeProxy, int fd);
John Reck4f02bf42014-01-03 18:09:17 -0800985
John Recke45b1fd2014-04-15 09:50:16 -0700986 private static native long nCreateRootRenderNode();
987 private static native long nCreateProxy(boolean translucent, long rootRenderNode);
John Reck4f02bf42014-01-03 18:09:17 -0800988 private static native void nDeleteProxy(long nativeProxy);
989
John Recke4280ba2014-05-05 16:39:37 -0700990 private static native boolean nLoadSystemProperties(long nativeProxy);
John Reckb36016c2015-03-11 08:50:53 -0700991 private static native void nSetName(long nativeProxy, String name);
John Reck18f16e62014-05-02 16:46:41 -0700992
Thomas Buhot0bcd0cb2015-12-04 12:18:03 +0100993 private static native void nInitialize(long nativeProxy, Surface window);
John Reck4f02bf42014-01-03 18:09:17 -0800994 private static native void nUpdateSurface(long nativeProxy, Surface window);
John Reck01a5ea32014-12-03 13:01:07 -0800995 private static native boolean nPauseSurface(long nativeProxy, Surface window);
Chris Craik797b95b2014-05-20 18:10:25 -0700996 private static native void nSetup(long nativeProxy, int width, int height,
Alan Viverette50210d92015-05-14 18:05:36 -0700997 float lightRadius, int ambientShadowAlpha, int spotShadowAlpha);
998 private static native void nSetLightCenter(long nativeProxy,
999 float lightX, float lightY, float lightZ);
John Reck63a06672014-05-07 13:45:54 -07001000 private static native void nSetOpaque(long nativeProxy, boolean opaque);
John Reckba6adf62015-02-19 14:36:50 -08001001 private static native int nSyncAndDrawFrame(long nativeProxy, long[] frameInfo, int size);
John Reck17035b02014-09-03 07:39:53 -07001002 private static native void nDestroy(long nativeProxy);
John Reck119907c2014-08-14 09:02:01 -07001003 private static native void nRegisterAnimatingRenderNode(long rootRenderNode, long animatingNode);
John Reck4f02bf42014-01-03 18:09:17 -08001004
John Reck3b202512014-06-23 13:13:08 -07001005 private static native void nInvokeFunctor(long functor, boolean waitForCompletion);
John Reck19b6bcf2014-02-14 20:03:38 -08001006
John Reck19b6bcf2014-02-14 20:03:38 -08001007 private static native long nCreateTextureLayer(long nativeProxy);
John Reck3e824952014-08-20 10:08:39 -07001008 private static native void nBuildLayer(long nativeProxy, long node);
John Reck3731dc22015-04-13 15:20:29 -07001009 private static native boolean nCopyLayerInto(long nativeProxy, long layer, Bitmap bitmap);
John Reckd72e0a32014-05-29 18:56:11 -07001010 private static native void nPushLayerUpdate(long nativeProxy, long layer);
1011 private static native void nCancelLayerUpdate(long nativeProxy, long layer);
John Reck918ad522014-06-27 14:45:25 -07001012 private static native void nDetachSurfaceTexture(long nativeProxy, long layer);
John Reck28ad7b52014-04-07 16:59:25 -07001013
John Reckf47a5942014-06-30 16:20:04 -07001014 private static native void nDestroyHardwareResources(long nativeProxy);
1015 private static native void nTrimMemory(int level);
Chris Craik2507c342015-05-04 14:36:49 -07001016 private static native void nOverrideProperty(String name, String value);
John Recke1628b72014-05-23 15:11:19 -07001017
John Reck28ad7b52014-04-07 16:59:25 -07001018 private static native void nFence(long nativeProxy);
John Reckf47a5942014-06-30 16:20:04 -07001019 private static native void nStopDrawing(long nativeProxy);
John Recka5dda642014-05-22 15:43:54 -07001020 private static native void nNotifyFramePending(long nativeProxy);
John Reckfe5e7b72014-05-23 17:42:28 -07001021
John Recke248bd12015-08-05 13:53:53 -07001022 private static native void nSerializeDisplayListTree(long nativeProxy);
1023
John Reckba6adf62015-02-19 14:36:50 -08001024 private static native void nDumpProfileInfo(long nativeProxy, FileDescriptor fd,
1025 @DumpFlags int dumpFlags);
John Reckedc524c2015-03-18 15:24:33 -07001026 private static native void nDumpProfileData(byte[] data, FileDescriptor fd);
Skuhneea7a7fb2015-08-28 07:10:31 -07001027
1028 private static native void nAddRenderNode(long nativeProxy, long rootRenderNode,
1029 boolean placeFront);
1030 private static native void nRemoveRenderNode(long nativeProxy, long rootRenderNode);
1031 private static native void nDrawRenderNode(long nativeProxy, long rootRenderNode);
Skuhneb8160872015-09-22 09:51:39 -07001032 private static native void nSetContentDrawBounds(long nativeProxy, int left,
Skuhneea7a7fb2015-08-28 07:10:31 -07001033 int top, int right, int bottom);
Andres Morales06f5bc72015-12-15 15:21:31 -08001034
1035 private static native long nAddFrameStatsObserver(long nativeProxy, FrameStatsObserver fso);
1036 private static native void nRemoveFrameStatsObserver(long nativeProxy, long nativeFso);
1037 private static native long nGetDroppedFrameReportCount(long nativeProxy);
John Reckcec24ae2013-11-05 13:27:50 -08001038}