John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.view; |
| 18 | |
John Reck | 04fc583 | 2014-02-05 16:38:25 -0800 | [diff] [blame] | 19 | import android.graphics.Bitmap; |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 20 | import android.graphics.Rect; |
| 21 | import android.graphics.SurfaceTexture; |
John Reck | 66f0be6 | 2014-05-13 13:39:31 -0700 | [diff] [blame] | 22 | import android.os.IBinder; |
| 23 | import android.os.RemoteException; |
| 24 | import android.os.ServiceManager; |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame^] | 25 | import android.os.SystemProperties; |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 26 | import android.os.Trace; |
John Reck | 66f0be6 | 2014-05-13 13:39:31 -0700 | [diff] [blame] | 27 | import android.util.Log; |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 28 | import android.util.TimeUtils; |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 29 | import android.view.Surface.OutOfResourcesException; |
| 30 | import android.view.View.AttachInfo; |
| 31 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame^] | 32 | import java.io.FileDescriptor; |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 33 | import java.io.PrintWriter; |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * Hardware renderer that proxies the rendering to a render thread. Most calls |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 37 | * are currently synchronous. |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 38 | * |
| 39 | * The UI thread can block on the RenderThread, but RenderThread must never |
| 40 | * block on the UI thread. |
| 41 | * |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 42 | * ThreadedRenderer creates an instance of RenderProxy. RenderProxy in turn creates |
| 43 | * and manages a CanvasContext on the RenderThread. The CanvasContext is fully managed |
| 44 | * by the lifecycle of the RenderProxy. |
| 45 | * |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 46 | * Note that although currently the EGL context & surfaces are created & managed |
| 47 | * by the render thread, the goal is to move that into a shared structure that can |
| 48 | * be managed by both threads. EGLSurface creation & deletion should ideally be |
| 49 | * done on the UI thread and not the RenderThread to avoid stalling the |
| 50 | * RenderThread with surface buffer allocation. |
| 51 | * |
| 52 | * @hide |
| 53 | */ |
| 54 | public class ThreadedRenderer extends HardwareRenderer { |
| 55 | private static final String LOGTAG = "ThreadedRenderer"; |
| 56 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 57 | private static final Rect NULL_RECT = new Rect(); |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 58 | |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 59 | // Keep in sync with DrawFrameTask.h SYNC_* flags |
| 60 | // Nothing interesting to report |
| 61 | private static final int SYNC_OK = 0x0; |
| 62 | // Needs a ViewRoot invalidate |
| 63 | private static final int SYNC_INVALIDATE_REQUIRED = 0x1; |
| 64 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame^] | 65 | private static final String[] VISUALIZERS = { |
| 66 | PROFILE_PROPERTY_VISUALIZE_BARS, |
| 67 | }; |
| 68 | |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 69 | private int mWidth, mHeight; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 70 | private long mNativeProxy; |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 71 | private boolean mInitialized = false; |
John Reck | bc0cc02 | 2014-04-11 16:08:14 -0700 | [diff] [blame] | 72 | private RenderNode mRootNode; |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 73 | private Choreographer mChoreographer; |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame^] | 74 | private boolean mProfilingEnabled; |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 75 | |
John Reck | 3dfe19f | 2013-12-13 14:25:19 -0800 | [diff] [blame] | 76 | ThreadedRenderer(boolean translucent) { |
John Reck | 66f0be6 | 2014-05-13 13:39:31 -0700 | [diff] [blame] | 77 | AtlasInitializer.sInstance.init(); |
| 78 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 79 | long rootNodePtr = nCreateRootRenderNode(); |
| 80 | mRootNode = RenderNode.adopt(rootNodePtr); |
John Reck | bc0cc02 | 2014-04-11 16:08:14 -0700 | [diff] [blame] | 81 | mRootNode.setClipToBounds(false); |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 82 | mNativeProxy = nCreateProxy(translucent, rootNodePtr); |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 83 | |
| 84 | // Setup timing |
| 85 | mChoreographer = Choreographer.getInstance(); |
| 86 | nSetFrameInterval(mNativeProxy, mChoreographer.getFrameIntervalNanos()); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame^] | 87 | |
| 88 | loadSystemProperties(); |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | @Override |
| 92 | void destroy(boolean full) { |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 93 | mInitialized = false; |
| 94 | updateEnabledState(null); |
John Reck | fae904d | 2014-04-14 11:01:57 -0700 | [diff] [blame] | 95 | nDestroyCanvasAndSurface(mNativeProxy); |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 96 | } |
| 97 | |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 98 | private void updateEnabledState(Surface surface) { |
| 99 | if (surface == null || !surface.isValid()) { |
| 100 | setEnabled(false); |
| 101 | } else { |
| 102 | setEnabled(mInitialized); |
| 103 | } |
| 104 | } |
| 105 | |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 106 | @Override |
| 107 | boolean initialize(Surface surface) throws OutOfResourcesException { |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 108 | mInitialized = true; |
| 109 | updateEnabledState(surface); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 110 | return nInitialize(mNativeProxy, surface); |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | @Override |
| 114 | void updateSurface(Surface surface) throws OutOfResourcesException { |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 115 | updateEnabledState(surface); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 116 | nUpdateSurface(mNativeProxy, surface); |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | @Override |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 120 | void pauseSurface(Surface surface) { |
| 121 | nPauseSurface(mNativeProxy, surface); |
| 122 | } |
| 123 | |
| 124 | @Override |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 125 | void destroyHardwareResources(View view) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 126 | destroyResources(view); |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 127 | nFlushCaches(mNativeProxy, GLES20Canvas.FLUSH_CACHES_LAYERS); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | private static void destroyResources(View view) { |
| 131 | view.destroyHardwareResources(); |
| 132 | |
| 133 | if (view instanceof ViewGroup) { |
| 134 | ViewGroup group = (ViewGroup) view; |
| 135 | |
| 136 | int count = group.getChildCount(); |
| 137 | for (int i = 0; i < count; i++) { |
| 138 | destroyResources(group.getChildAt(i)); |
| 139 | } |
| 140 | } |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | @Override |
| 144 | void invalidate(Surface surface) { |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 145 | updateSurface(surface); |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | @Override |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 149 | boolean safelyRun(Runnable action) { |
John Reck | fc53ef27 | 2014-02-11 10:40:25 -0800 | [diff] [blame] | 150 | nRunWithGlContext(mNativeProxy, action); |
| 151 | return true; |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | @Override |
Chris Craik | 797b95b | 2014-05-20 18:10:25 -0700 | [diff] [blame] | 155 | void setup(int width, int height, float lightX, float lightY, float lightZ, float lightRadius) { |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 156 | mWidth = width; |
| 157 | mHeight = height; |
John Reck | bc0cc02 | 2014-04-11 16:08:14 -0700 | [diff] [blame] | 158 | mRootNode.setLeftTopRightBottom(0, 0, mWidth, mHeight); |
Chris Craik | 797b95b | 2014-05-20 18:10:25 -0700 | [diff] [blame] | 159 | nSetup(mNativeProxy, width, height, lightX, lightY, lightZ, lightRadius); |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | @Override |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 163 | void setOpaque(boolean opaque) { |
| 164 | nSetOpaque(mNativeProxy, opaque); |
| 165 | } |
| 166 | |
| 167 | @Override |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 168 | int getWidth() { |
| 169 | return mWidth; |
| 170 | } |
| 171 | |
| 172 | @Override |
| 173 | int getHeight() { |
| 174 | return mHeight; |
| 175 | } |
| 176 | |
| 177 | @Override |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame^] | 178 | void dumpGfxInfo(PrintWriter pw, FileDescriptor fd) { |
| 179 | pw.flush(); |
| 180 | nDumpProfileInfo(mNativeProxy, fd); |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 181 | } |
| 182 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame^] | 183 | private static int search(String[] values, String value) { |
| 184 | for (int i = 0; i < values.length; i++) { |
| 185 | if (values[i].equals(value)) return i; |
| 186 | } |
| 187 | return -1; |
| 188 | } |
| 189 | |
| 190 | private static boolean checkIfProfilingRequested() { |
| 191 | String profiling = SystemProperties.get(HardwareRenderer.PROFILE_PROPERTY); |
| 192 | int graphType = search(VISUALIZERS, profiling); |
| 193 | return (graphType >= 0) || Boolean.parseBoolean(profiling); |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | @Override |
| 197 | boolean loadSystemProperties() { |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame^] | 198 | boolean changed = nLoadSystemProperties(mNativeProxy); |
| 199 | boolean wantProfiling = checkIfProfilingRequested(); |
| 200 | if (wantProfiling != mProfilingEnabled) { |
| 201 | mProfilingEnabled = wantProfiling; |
| 202 | changed = true; |
| 203 | } |
| 204 | return changed; |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 205 | } |
| 206 | |
John Reck | bc0cc02 | 2014-04-11 16:08:14 -0700 | [diff] [blame] | 207 | private void updateRootDisplayList(View view, HardwareDrawCallbacks callbacks) { |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 208 | view.mPrivateFlags |= View.PFLAG_DRAWN; |
| 209 | |
| 210 | view.mRecreateDisplayList = (view.mPrivateFlags & View.PFLAG_INVALIDATED) |
| 211 | == View.PFLAG_INVALIDATED; |
| 212 | view.mPrivateFlags &= ~View.PFLAG_INVALIDATED; |
| 213 | |
| 214 | Trace.traceBegin(Trace.TRACE_TAG_VIEW, "getDisplayList"); |
John Reck | bc0cc02 | 2014-04-11 16:08:14 -0700 | [diff] [blame] | 215 | HardwareCanvas canvas = mRootNode.start(mWidth, mHeight); |
John Reck | 05e8584 | 2014-04-23 14:48:28 -0700 | [diff] [blame] | 216 | try { |
John Reck | 86faf9e | 2014-05-19 13:19:07 -0700 | [diff] [blame] | 217 | canvas.save(); |
Alan Viverette | d5b2ec4 | 2014-05-17 16:34:09 -0700 | [diff] [blame] | 218 | callbacks.onHardwarePreDraw(canvas); |
John Reck | 05e8584 | 2014-04-23 14:48:28 -0700 | [diff] [blame] | 219 | canvas.drawDisplayList(view.getDisplayList()); |
| 220 | callbacks.onHardwarePostDraw(canvas); |
John Reck | 86faf9e | 2014-05-19 13:19:07 -0700 | [diff] [blame] | 221 | canvas.restore(); |
John Reck | 05e8584 | 2014-04-23 14:48:28 -0700 | [diff] [blame] | 222 | } finally { |
| 223 | mRootNode.end(canvas); |
| 224 | Trace.traceEnd(Trace.TRACE_TAG_VIEW); |
| 225 | } |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 226 | |
| 227 | view.mRecreateDisplayList = false; |
John Reck | bc0cc02 | 2014-04-11 16:08:14 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | @Override |
| 231 | void draw(View view, AttachInfo attachInfo, HardwareDrawCallbacks callbacks, Rect dirty) { |
| 232 | attachInfo.mIgnoreDirtyState = true; |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 233 | long frameTimeNanos = mChoreographer.getFrameTimeNanos(); |
John Reck | 315c329 | 2014-05-09 19:21:04 -0700 | [diff] [blame] | 234 | attachInfo.mDrawingTime = frameTimeNanos / TimeUtils.NANOS_PER_MS; |
John Reck | bc0cc02 | 2014-04-11 16:08:14 -0700 | [diff] [blame] | 235 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame^] | 236 | long recordDuration = 0; |
| 237 | if (mProfilingEnabled) { |
| 238 | recordDuration = System.nanoTime(); |
| 239 | } |
| 240 | |
John Reck | bc0cc02 | 2014-04-11 16:08:14 -0700 | [diff] [blame] | 241 | updateRootDisplayList(view, callbacks); |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 242 | |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame^] | 243 | if (mProfilingEnabled) { |
| 244 | recordDuration = System.nanoTime() - recordDuration; |
| 245 | } |
| 246 | |
John Reck | 6313b92 | 2014-04-16 18:59:21 -0700 | [diff] [blame] | 247 | attachInfo.mIgnoreDirtyState = false; |
| 248 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 249 | if (dirty == null) { |
| 250 | dirty = NULL_RECT; |
| 251 | } |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 252 | int syncResult = nSyncAndDrawFrame(mNativeProxy, frameTimeNanos, |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame^] | 253 | recordDuration, view.getResources().getDisplayMetrics().density, |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 254 | dirty.left, dirty.top, dirty.right, dirty.bottom); |
John Reck | f9be779 | 2014-05-02 18:21:16 -0700 | [diff] [blame] | 255 | if ((syncResult & SYNC_INVALIDATE_REQUIRED) != 0) { |
| 256 | attachInfo.mViewRootImpl.invalidate(); |
| 257 | } |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | @Override |
Bo Liu | ae738a7 | 2014-04-27 16:22:04 -0700 | [diff] [blame] | 261 | void invokeFunctor(long functor, boolean waitForCompletion) { |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 262 | nInvokeFunctor(mNativeProxy, functor, waitForCompletion); |
| 263 | } |
| 264 | |
| 265 | @Override |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 266 | HardwareLayer createDisplayListLayer(int width, int height) { |
| 267 | long layer = nCreateDisplayListLayer(mNativeProxy, width, height); |
| 268 | return HardwareLayer.adoptDisplayListLayer(this, layer); |
| 269 | } |
| 270 | |
| 271 | @Override |
| 272 | HardwareLayer createTextureLayer() { |
| 273 | long layer = nCreateTextureLayer(mNativeProxy); |
| 274 | return HardwareLayer.adoptTextureLayer(this, layer); |
| 275 | } |
| 276 | |
| 277 | @Override |
| 278 | SurfaceTexture createSurfaceTexture(final HardwareLayer layer) { |
| 279 | final SurfaceTexture[] ret = new SurfaceTexture[1]; |
| 280 | nRunWithGlContext(mNativeProxy, new Runnable() { |
| 281 | @Override |
| 282 | public void run() { |
| 283 | ret[0] = layer.createSurfaceTexture(); |
| 284 | } |
| 285 | }); |
| 286 | return ret[0]; |
| 287 | } |
| 288 | |
| 289 | @Override |
| 290 | boolean copyLayerInto(final HardwareLayer layer, final Bitmap bitmap) { |
| 291 | return nCopyLayerInto(mNativeProxy, |
| 292 | layer.getDeferredLayerUpdater(), bitmap.mNativeBitmap); |
| 293 | } |
| 294 | |
| 295 | @Override |
| 296 | void pushLayerUpdate(HardwareLayer layer) { |
| 297 | // TODO: Remove this, it's not needed outside of GLRenderer |
| 298 | } |
| 299 | |
| 300 | @Override |
| 301 | void onLayerCreated(HardwareLayer layer) { |
| 302 | // TODO: Is this actually useful? |
| 303 | } |
| 304 | |
| 305 | @Override |
| 306 | void flushLayerUpdates() { |
| 307 | // TODO: Figure out what this should do or remove it |
| 308 | } |
| 309 | |
| 310 | @Override |
| 311 | void onLayerDestroyed(HardwareLayer layer) { |
| 312 | nDestroyLayer(mNativeProxy, layer.getDeferredLayerUpdater()); |
| 313 | } |
| 314 | |
| 315 | @Override |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 316 | void setName(String name) { |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 317 | } |
| 318 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 319 | @Override |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 320 | void fence() { |
| 321 | nFence(mNativeProxy); |
| 322 | } |
| 323 | |
| 324 | @Override |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 325 | public void notifyFramePending() { |
| 326 | nNotifyFramePending(mNativeProxy); |
| 327 | } |
| 328 | |
| 329 | @Override |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 330 | protected void finalize() throws Throwable { |
| 331 | try { |
| 332 | nDeleteProxy(mNativeProxy); |
John Reck | 0ed751d | 2014-04-08 14:10:17 -0700 | [diff] [blame] | 333 | mNativeProxy = 0; |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 334 | } finally { |
| 335 | super.finalize(); |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | |
John Reck | 66f0be6 | 2014-05-13 13:39:31 -0700 | [diff] [blame] | 339 | private static class AtlasInitializer { |
| 340 | static AtlasInitializer sInstance = new AtlasInitializer(); |
| 341 | |
| 342 | private boolean mInitialized = false; |
| 343 | |
| 344 | private AtlasInitializer() {} |
| 345 | |
| 346 | synchronized void init() { |
| 347 | if (mInitialized) return; |
| 348 | IBinder binder = ServiceManager.getService("assetatlas"); |
| 349 | if (binder == null) return; |
| 350 | |
| 351 | IAssetAtlas atlas = IAssetAtlas.Stub.asInterface(binder); |
| 352 | try { |
| 353 | if (atlas.isCompatible(android.os.Process.myPpid())) { |
| 354 | GraphicBuffer buffer = atlas.getBuffer(); |
| 355 | if (buffer != null) { |
| 356 | long[] map = atlas.getMap(); |
| 357 | if (map != null) { |
| 358 | nSetAtlas(buffer, map); |
| 359 | mInitialized = true; |
| 360 | } |
| 361 | // If IAssetAtlas is not the same class as the IBinder |
| 362 | // we are using a remote service and we can safely |
| 363 | // destroy the graphic buffer |
| 364 | if (atlas.getClass() != binder.getClass()) { |
| 365 | buffer.destroy(); |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | } catch (RemoteException e) { |
| 370 | Log.w(LOG_TAG, "Could not acquire atlas", e); |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | |
| 375 | private static native void nSetAtlas(GraphicBuffer buffer, long[] map); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 376 | |
John Reck | e45b1fd | 2014-04-15 09:50:16 -0700 | [diff] [blame] | 377 | private static native long nCreateRootRenderNode(); |
| 378 | private static native long nCreateProxy(boolean translucent, long rootRenderNode); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 379 | private static native void nDeleteProxy(long nativeProxy); |
| 380 | |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 381 | private static native void nSetFrameInterval(long nativeProxy, long frameIntervalNanos); |
John Reck | e4280ba | 2014-05-05 16:39:37 -0700 | [diff] [blame] | 382 | private static native boolean nLoadSystemProperties(long nativeProxy); |
John Reck | 18f16e6 | 2014-05-02 16:46:41 -0700 | [diff] [blame] | 383 | |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 384 | private static native boolean nInitialize(long nativeProxy, Surface window); |
| 385 | private static native void nUpdateSurface(long nativeProxy, Surface window); |
John Reck | f7d9c1d | 2014-04-09 10:01:03 -0700 | [diff] [blame] | 386 | private static native void nPauseSurface(long nativeProxy, Surface window); |
Chris Craik | 797b95b | 2014-05-20 18:10:25 -0700 | [diff] [blame] | 387 | private static native void nSetup(long nativeProxy, int width, int height, |
| 388 | float lightX, float lightY, float lightZ, float lightRadius); |
John Reck | 63a0667 | 2014-05-07 13:45:54 -0700 | [diff] [blame] | 389 | private static native void nSetOpaque(long nativeProxy, boolean opaque); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame^] | 390 | private static native int nSyncAndDrawFrame(long nativeProxy, |
| 391 | long frameTimeNanos, long recordDuration, float density, |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 392 | int dirtyLeft, int dirtyTop, int dirtyRight, int dirtyBottom); |
John Reck | fc53ef27 | 2014-02-11 10:40:25 -0800 | [diff] [blame] | 393 | private static native void nRunWithGlContext(long nativeProxy, Runnable runnable); |
John Reck | fae904d | 2014-04-14 11:01:57 -0700 | [diff] [blame] | 394 | private static native void nDestroyCanvasAndSurface(long nativeProxy); |
John Reck | 4f02bf4 | 2014-01-03 18:09:17 -0800 | [diff] [blame] | 395 | |
John Reck | 0d1f634 | 2014-03-28 20:30:27 -0700 | [diff] [blame] | 396 | private static native void nInvokeFunctor(long nativeProxy, long functor, boolean waitForCompletion); |
John Reck | 19b6bcf | 2014-02-14 20:03:38 -0800 | [diff] [blame] | 397 | |
| 398 | private static native long nCreateDisplayListLayer(long nativeProxy, int width, int height); |
| 399 | private static native long nCreateTextureLayer(long nativeProxy); |
| 400 | private static native boolean nCopyLayerInto(long nativeProxy, long layer, long bitmap); |
| 401 | private static native void nDestroyLayer(long nativeProxy, long layer); |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 402 | |
John Reck | e1628b7 | 2014-05-23 15:11:19 -0700 | [diff] [blame] | 403 | private static native void nFlushCaches(long nativeProxy, int flushMode); |
| 404 | |
John Reck | 28ad7b5 | 2014-04-07 16:59:25 -0700 | [diff] [blame] | 405 | private static native void nFence(long nativeProxy); |
John Reck | a5dda64 | 2014-05-22 15:43:54 -0700 | [diff] [blame] | 406 | private static native void nNotifyFramePending(long nativeProxy); |
John Reck | fe5e7b7 | 2014-05-23 17:42:28 -0700 | [diff] [blame^] | 407 | |
| 408 | private static native void nDumpProfileInfo(long nativeProxy, FileDescriptor fd); |
John Reck | cec24ae | 2013-11-05 13:27:50 -0800 | [diff] [blame] | 409 | } |