@threenative/runtime-native 0.3.3 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/NOTICE +1 -1
  2. package/android/README.md +10 -0
  3. package/android/app/build.gradle.kts +23 -0
  4. package/android/app/src/main/java/com/mystral/engine/MystralActivity.java +87 -2
  5. package/android/app/src/main/java/com/mystral/engine/TnUiOverlay.java +170 -8
  6. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  7. package/build/web/tn-native-engine-web.mjs +2 -0
  8. package/build/web/tn-native-engine-web.wasm +0 -0
  9. package/package.json +20 -6
  10. package/scripts/asset-manifest.mjs +38 -19
  11. package/scripts/bundle-native-engine.mjs +303 -0
  12. package/scripts/bundle.mjs +38 -41
  13. package/scripts/check-source-list.mjs +11 -5
  14. package/scripts/desktop-distribution.mjs +19 -5
  15. package/scripts/inspect-macos-icon.mjs +169 -0
  16. package/scripts/install-prebuilt.mjs +33 -21
  17. package/scripts/package-android.mjs +64 -6
  18. package/scripts/package-desktop.mjs +51 -14
  19. package/scripts/package-engine-desktop.mjs +102 -0
  20. package/scripts/package-ios.mjs +36 -32
  21. package/scripts/physical-device-evidence.mjs +135 -1
  22. package/scripts/production-evidence.mjs +36 -9
  23. package/scripts/profile-production.mjs +696 -146
  24. package/scripts/qualify-physical-mobile.mjs +286 -69
  25. package/scripts/verify-starter-consumer.mjs +58 -8
  26. package/scripts/verify-starter-desktop-base.mjs +12 -2
  27. package/scripts/windows-installer.mjs +12 -5
  28. package/scripts/xvfb.sh +15 -0
  29. package/src/engine/player/core-addons.mjs +15 -0
  30. package/src/engine/player/core-assets.mjs +59 -0
  31. package/src/engine/player/core-audio.mjs +11 -0
  32. package/src/engine/player/core-hdr.mjs +29 -0
  33. package/src/engine/player/core-host.mjs +148 -0
  34. package/src/engine/player/core-lut.mjs +7 -0
  35. package/src/engine/player/core-textures.mjs +167 -0
  36. package/src/engine/player/core-three.mjs +294 -0
  37. package/src/engine/player/core-tsl.mjs +80 -0
  38. package/src/engine/player/core-unused.mjs +21 -0
  39. package/src/engine/player/core-webgpu.mjs +207 -0
package/NOTICE CHANGED
@@ -3,7 +3,7 @@ ThreeNative Native Runtime
3
3
  This package is a maintained fork of MystralNative, originally published by Mystral
4
4
  Engine under the MIT License: https://github.com/mystralengine/mystralnative
5
5
 
6
- Upstream provenance baseline: 841fe379ca1ab23c87c99fac3b901e37487ce8f2 (v0.1.5)
6
+ Upstream provenance baseline: bafab09d599bd55aeb7433ba7131c3f320334c99 (v0.1.6)
7
7
  Imported maintained-fork state: c705b16eef02bc49e68fe6c9b4114698aa6b3d7f
8
8
 
9
9
  The upstream license is preserved in LICENSE. Third-party dependencies are not vendored;
package/android/README.md CHANGED
@@ -141,6 +141,16 @@ adb logcat -s Mystral SDL
141
141
  adb logcat --pid=$(adb shell pidof com.threenative.game)
142
142
  ```
143
143
 
144
+ A native crash on Android leaves a tombstone in `adb shell dumpsys dropbox --print
145
+ data_app_native_crash`, because the host installs no signal handlers there (PRD-210). The APK
146
+ carries a stripped `libmystral-runtime.so`, so the tombstone names functions but not lines. A debug
147
+ build keeps the unstripped copy beside it. Pass that directory to `ndk-stack`:
148
+
149
+ ```bash
150
+ adb logcat -d | "$ANDROID_HOME"/ndk/<version>/ndk-stack \
151
+ -sym app/build/intermediates/merged_native_libs/debug/mergeDebugNativeLibs/out/lib/<abi>
152
+ ```
153
+
144
154
  Run the gate's emulator-free unit coverage with:
145
155
 
146
156
  ```bash
@@ -77,6 +77,9 @@ val frameLatency = providers.gradleProperty("threenativeFrameLatency").orElse("0
77
77
  val gpuDrainProfile = providers.gradleProperty("threenativeGpuDrainProfile").orElse("false")
78
78
  val nativeJsProfile = providers.gradleProperty("threenativeJsProfile").orElse("false")
79
79
  val nativeJsProfileBusyLoop = providers.gradleProperty("threenativeJsProfileBusyLoop").orElse("false")
80
+ // `ui.renderer: "native-css"`: link the CPU CSS UI (`native/css-ui`) into the runtime. Off by
81
+ // default, so every other game's APK carries none of it; `package-android.mjs` turns it on.
82
+ val nativeCssUi = providers.gradleProperty("threenativeCssUi").orElse("false")
80
83
  // V8 is the Android default, decided by the product owner on 2026-08-16 (PRD-130) on PRD-118's
81
84
  // measurement: 115.64 ms of script per frame under QuickJS against 5.25 ms under V8. It needs
82
85
  // third_party/v8-android, which `scripts/download-deps.mjs --android` now provisions.
@@ -266,6 +269,24 @@ val buildNativePhysics by tasks.registering(Exec::class) {
266
269
  outputs.dir(layout.projectDirectory.dir("../../.runtime/physics-target"))
267
270
  }
268
271
 
272
+ // One CSS UI staticlib per shipped ABI, in cargo's per-triple directory that CMake reads.
273
+ val cssUiTargets = mapOf("arm64-v8a" to "aarch64-linux-android", "x86_64" to "x86_64-linux-android")
274
+ val buildNativeCssUi by tasks.registering {
275
+ inputs.dir(layout.projectDirectory.dir("../../native/css-ui/src"))
276
+ inputs.file(layout.projectDirectory.file("../../native/css-ui/Cargo.toml"))
277
+ inputs.file(layout.projectDirectory.file("../../native/css-ui/Cargo.lock"))
278
+ inputs.property("abis", threeNativeAbis)
279
+ doLast {
280
+ for (abi in threeNativeAbis) {
281
+ project.exec {
282
+ workingDir = runtimeRoot.asFile
283
+ environment("ANDROID_HOME", android.sdkDirectory.absolutePath)
284
+ commandLine("node", "scripts/build-native-css-ui.mjs", "--target", cssUiTargets.getValue(abi))
285
+ }
286
+ }
287
+ }
288
+ }
289
+
269
290
  // Verify the complete source payload on every build, even when snapshot copying is up-to-date.
270
291
  // Published, no-NDK builds must not resolve or execute this development-only source helper.
271
292
  if (!usePrebuiltRuntime && nativeJsEngineName == "v8") {
@@ -281,6 +302,7 @@ tasks.named("preBuild") {
281
302
  if (conformanceBundle.isPresent) dependsOn("buildAndroidConformanceBundle")
282
303
  else dependsOn("buildAndroidFirstProofBundle")
283
304
  if (!usePrebuiltRuntime) dependsOn("extractSdl3JniLibs", buildNativePhysics)
305
+ if (!usePrebuiltRuntime && nativeCssUi.asCmakeBoolean("PthreenativeCssUi") == "ON") dependsOn(buildNativeCssUi)
284
306
  }
285
307
 
286
308
  dependencies {
@@ -360,6 +382,7 @@ android {
360
382
  "-DTN_ENABLE_WEBTRANSPORT=OFF",
361
383
  "-DTN_ENABLE_DEBUG_SERVER=OFF",
362
384
  "-DTN_ENABLE_NATIVE_PHYSICS=ON",
385
+ "-DTN_ENABLE_CSS_UI=${nativeCssUi.asCmakeBoolean("PthreenativeCssUi")}",
363
386
  "-DTN_ANDROID_VSYNC=${nativeVsync.asCmakeBoolean("PthreenativeVsync")}",
364
387
  "-DTN_WEBGPU_UPLOAD_STAGING=${uploadStaging.asCmakeBoolean("PthreenativeUploadStaging")}",
365
388
  "-DTN_WEBGPU_DESIRED_FRAME_LATENCY=${frameLatency.get()}",
@@ -8,6 +8,7 @@ import android.os.Build;
8
8
  import android.os.Bundle;
9
9
  import android.util.Log;
10
10
  import android.view.Choreographer;
11
+ import android.view.MotionEvent;
11
12
  import android.view.Surface;
12
13
  import android.view.SurfaceHolder;
13
14
  import android.view.View;
@@ -135,6 +136,7 @@ public class MystralActivity extends SDLActivity {
135
136
  // Belt and braces: a callback left registered when the native library unloads would call
136
137
  // into freed code. onPause normally precedes this, so the guard makes it a no-op.
137
138
  disarmPresentationFrames();
139
+ if (uiOverlay != null) uiOverlay.releaseProducer();
138
140
  super.onDestroy();
139
141
  }
140
142
 
@@ -208,7 +210,39 @@ public class MystralActivity extends SDLActivity {
208
210
  private void attachUiOverlay(Bundle metadata) {
209
211
  String renderer = metadata == null ? "native" : metadata.getString("TN_UI_RENDERER", "native");
210
212
  if (!"web".equals(renderer)) return;
211
- uiOverlay = TnUiOverlay.attach(this);
213
+ uiOverlay = inFrameRequested(metadata)
214
+ ? TnUiOverlay.attachInFrame(this)
215
+ : TnUiOverlay.attach(this);
216
+ }
217
+
218
+ /**
219
+ * Whether this run opts into in-frame UI composition (`TN_UI_INFRAME`), default off.
220
+ *
221
+ * The intent extra is the device-run override the verification harness uses; the manifest
222
+ * metadata is the packaged switch the config writes. Both default false, so a game that did
223
+ * not ask for it runs exactly today's child-WebView path.
224
+ */
225
+ private boolean inFrameRequested(Bundle metadata) {
226
+ boolean fromIntent = getIntent().getBooleanExtra("TN_UI_INFRAME", false);
227
+ boolean fromMetadata = metadata != null && metadata.getBoolean("TN_UI_INFRAME", false);
228
+ Log.i(LOG_TAG, "TN_UI_INFRAME_REQUEST:{\"intent\":" + fromIntent
229
+ + ",\"metadata\":" + fromMetadata + "}");
230
+ if (fromIntent) return true;
231
+ return fromMetadata;
232
+ }
233
+
234
+ /**
235
+ * Keep the overlay's own hit test authoritative when it composites in-frame.
236
+ *
237
+ * The in-frame WebView is not a sibling view, so the system will not route touches to it. This
238
+ * forwards each gesture to the same WebView first — its published hit regions decide ownership,
239
+ * exactly as before — and only what it does not own reaches SDL and the game.
240
+ */
241
+ @Override
242
+ public boolean dispatchTouchEvent(MotionEvent event) {
243
+ TnUiOverlay overlay = uiOverlay;
244
+ if (overlay != null && overlay.isInFrame() && overlay.dispatchTouchEvent(event)) return true;
245
+ return super.dispatchTouchEvent(event);
212
246
  }
213
247
 
214
248
  /**
@@ -325,6 +359,13 @@ public class MystralActivity extends SDLActivity {
325
359
  "TN_PLAYTEST_MAILBOX_UNAVAILABLE: cannot create " + mailboxRoot
326
360
  );
327
361
  }
362
+ String uiRenderer = metadata == null ? "native" : metadata.getString("TN_UI_RENDERER", "native");
363
+ String cssUiRoot = "native-css".equals(uiRenderer) ? extractCssUi() : "";
364
+ // The native-css UI's own test knobs, which the host reads from its environment. An Android
365
+ // app inherits none, so the runner hands them over as intent extras and they arrive as the
366
+ // last two arguments. Empty unless a playtest launch supplied them.
367
+ String fixedStepMs = getIntent().getStringExtra("TN_CSS_UI_FIXED_STEP_MS");
368
+ String stateTrace = getIntent().getStringExtra("TN_CSS_UI_STATE_TRACE");
328
369
  return new String[] {
329
370
  "asset://scripts/main.js",
330
371
  endpoint == null ? "" : endpoint,
@@ -332,7 +373,51 @@ public class MystralActivity extends SDLActivity {
332
373
  title,
333
374
  Boolean.toString(fullscreen),
334
375
  backgroundMode == null ? "pause" : backgroundMode,
335
- Integer.toString(maxFps)
376
+ Integer.toString(maxFps),
377
+ cssUiRoot,
378
+ fixedStepMs == null ? "" : fixedStepMs,
379
+ stateTrace == null ? "" : stateTrace
336
380
  };
337
381
  }
382
+
383
+ /**
384
+ * Copy the packaged `assets/ui/**` (stylesheets, fonts, images) to a real directory for the
385
+ * native CSS UI, which reads its `ui/` root from the filesystem and APK assets are not one.
386
+ * Replaced whole on every launch, so an updated APK never paints a previous install's sheets.
387
+ * Not caught: a game that asked for this HUD and cannot have it must fail with the reason named.
388
+ */
389
+ private String extractCssUi() {
390
+ java.io.File root = new java.io.File(getFilesDir(), "tn-ui-css");
391
+ deleteTree(root);
392
+ try {
393
+ copyAssetTree("ui", root);
394
+ } catch (java.io.IOException exception) {
395
+ throw new IllegalStateException("TN_UI_BUNDLE_MISSING: cannot extract assets/ui: " + exception, exception);
396
+ }
397
+ Log.i(LOG_TAG, "TN_CSS_UI_EXTRACTED:{\"root\":\"" + root.getAbsolutePath() + "\"}");
398
+ return root.getAbsolutePath();
399
+ }
400
+
401
+ private void copyAssetTree(String asset, java.io.File destination) throws java.io.IOException {
402
+ String[] children = getAssets().list(asset);
403
+ if (children != null && children.length > 0) {
404
+ if (!destination.isDirectory() && !destination.mkdirs()) {
405
+ throw new java.io.IOException("cannot create " + destination);
406
+ }
407
+ for (String child : children) copyAssetTree(asset + "/" + child, new java.io.File(destination, child));
408
+ return;
409
+ }
410
+ try (java.io.InputStream input = getAssets().open(asset);
411
+ java.io.OutputStream output = new java.io.FileOutputStream(destination)) {
412
+ byte[] buffer = new byte[65536];
413
+ int read;
414
+ while ((read = input.read(buffer)) > 0) output.write(buffer, 0, read);
415
+ }
416
+ }
417
+
418
+ private static void deleteTree(java.io.File file) {
419
+ java.io.File[] children = file.listFiles();
420
+ if (children != null) for (java.io.File child : children) deleteTree(child);
421
+ file.delete();
422
+ }
338
423
  }
@@ -1,7 +1,18 @@
1
1
  package com.threenative.runtime;
2
2
 
3
3
  import android.app.Activity;
4
+ import android.app.Presentation;
4
5
  import android.graphics.Color;
6
+ import android.graphics.PixelFormat;
7
+ import android.hardware.HardwareBuffer;
8
+ import android.hardware.display.DisplayManager;
9
+ import android.hardware.display.VirtualDisplay;
10
+ import android.media.Image;
11
+ import android.media.ImageReader;
12
+ import android.os.Handler;
13
+ import android.os.HandlerThread;
14
+ import android.util.DisplayMetrics;
15
+ import android.view.Display;
5
16
  import android.view.MotionEvent;
6
17
  import android.view.View;
7
18
  import android.view.ViewGroup;
@@ -73,6 +84,18 @@ public final class TnUiOverlay extends WebView {
73
84
 
74
85
  private static native void nativeUiOverlayAttached(boolean attached);
75
86
 
87
+ /**
88
+ * Publish one produced page frame to the native composite.
89
+ *
90
+ * `pixels` is the producer's direct `ImageReader` plane buffer; native copies it before this
91
+ * call returns, so the image can be closed immediately. `stride` is the row stride in bytes.
92
+ */
93
+ private static native void nativeUiFrame(java.nio.ByteBuffer pixels, int width, int height,
94
+ int stride);
95
+
96
+ /** Name the composite path this run took: `in-frame-cpu` or `child-window`. */
97
+ private static native void nativeUiCompositePath(String path);
98
+
76
99
  /**
77
100
  * The published islands, flat as x, y, width, height per region, normalized to the viewport.
78
101
  * Written by the message listener and read by touch dispatch, both on the UI thread; the
@@ -85,6 +108,19 @@ public final class TnUiOverlay extends WebView {
85
108
  private String pendingFrame;
86
109
  private boolean ownsGesture;
87
110
 
111
+ /**
112
+ * True when this overlay produces its pixels off-screen for the native composite instead of
113
+ * being a transparent sibling SurfaceFlinger layer. Selected by {@code TN_UI_INFRAME}.
114
+ */
115
+ private boolean inFrame;
116
+
117
+ private ImageReader frameReader;
118
+ private VirtualDisplay frameDisplay;
119
+ private Presentation framePresentation;
120
+ private HandlerThread frameThread;
121
+ private Handler frameHandler;
122
+ private long frameCounter;
123
+
88
124
  private TnUiOverlay(Activity activity) {
89
125
  super(activity);
90
126
  }
@@ -97,6 +133,38 @@ public final class TnUiOverlay extends WebView {
97
133
  * game whose HUD code is broken.
98
134
  */
99
135
  public static TnUiOverlay attach(Activity activity) {
136
+ requireMessageListener();
137
+ TnUiOverlay overlay = new TnUiOverlay(activity);
138
+ nativeUiOverlayAttached(false);
139
+ overlay.configure(activity);
140
+ activity.addContentView(
141
+ overlay,
142
+ new ViewGroup.LayoutParams(
143
+ ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
144
+ nativeUiCompositePath("child-window");
145
+ return overlay;
146
+ }
147
+
148
+ /**
149
+ * Build the overlay as an off-screen producer for the in-frame composite (`TN_UI_INFRAME`).
150
+ *
151
+ * The same WebView and the same bridge, but its pixels are produced into an `ImageReader`
152
+ * surface through a {@code VirtualDisplay}/{@code Presentation} instead of being composited as
153
+ * its own SurfaceFlinger layer, and each produced frame is handed to native. This is the
154
+ * Android counterpart of Linux's off-screen web view, and it is opt-in: the child-window path
155
+ * above is exactly what it was.
156
+ */
157
+ public static TnUiOverlay attachInFrame(Activity activity) {
158
+ requireMessageListener();
159
+ TnUiOverlay overlay = new TnUiOverlay(activity);
160
+ overlay.inFrame = true;
161
+ nativeUiOverlayAttached(false);
162
+ overlay.configure(activity);
163
+ overlay.startProducer(activity);
164
+ return overlay;
165
+ }
166
+
167
+ private static void requireMessageListener() {
100
168
  if (!WebViewFeature.isFeatureSupported(WebViewFeature.WEB_MESSAGE_LISTENER)) {
101
169
  nativeUiOverlayAttached(false);
102
170
  throw new IllegalStateException(
@@ -104,21 +172,115 @@ public final class TnUiOverlay extends WebView {
104
172
  + " UI layer has no bridge. Update Android System WebView, or build with"
105
173
  + " ui.renderer = \"native\".");
106
174
  }
107
- TnUiOverlay overlay = new TnUiOverlay(activity);
108
- nativeUiOverlayAttached(false);
109
- overlay.configure(activity);
110
- activity.addContentView(
111
- overlay,
175
+ }
176
+
177
+ /**
178
+ * Put the page on a display whose surface this host owns, and pump its frames to native.
179
+ *
180
+ * Fails closed and by name: an in-frame run that cannot build its surface must not leave the
181
+ * game with a silent black HUD. The reader uses {@code RGBA_8888} with
182
+ * {@code USAGE_GPU_SAMPLED_IMAGE} — the usage the GPU import will need once wgpu-native can
183
+ * import an {@code AHardwareBuffer}; the CPU readback now is the same buffer read back.
184
+ */
185
+ private void startProducer(Activity activity) {
186
+ // The usage-parameter ImageReader and HardwareBuffer import are API 29; on anything older
187
+ // this fails closed and by name rather than silently dropping to the child-window path.
188
+ if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.Q) {
189
+ throw new IllegalStateException(
190
+ "TN_UI_INFRAME_UNSUPPORTED: in-frame composition needs API 29 (this device is "
191
+ + android.os.Build.VERSION.SDK_INT + ").");
192
+ }
193
+ DisplayManager displayManager = (DisplayManager) activity.getSystemService(
194
+ Activity.DISPLAY_SERVICE);
195
+ if (displayManager == null) {
196
+ throw new IllegalStateException("TN_UI_INFRAME_UNSUPPORTED: no DisplayManager.");
197
+ }
198
+ DisplayMetrics metrics = new DisplayMetrics();
199
+ activity.getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
200
+ final int width = metrics.widthPixels;
201
+ final int height = metrics.heightPixels;
202
+ frameThread = new HandlerThread("tn-ui-frame");
203
+ frameThread.start();
204
+ frameHandler = new Handler(frameThread.getLooper());
205
+ frameReader = ImageReader.newInstance(
206
+ width,
207
+ height,
208
+ PixelFormat.RGBA_8888,
209
+ 2,
210
+ HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE | HardwareBuffer.USAGE_CPU_READ_OFTEN);
211
+ frameReader.setOnImageAvailableListener(this::onFrameAvailable, frameHandler);
212
+ frameDisplay = displayManager.createVirtualDisplay(
213
+ "tn-ui-inframe", width, height, metrics.densityDpi, frameReader.getSurface(), 0);
214
+ if (frameDisplay == null) {
215
+ throw new IllegalStateException("TN_UI_INFRAME_UNSUPPORTED: no virtual display.");
216
+ }
217
+ framePresentation = new Presentation(activity, frameDisplay.getDisplay());
218
+ framePresentation.setContentView(
219
+ this,
112
220
  new ViewGroup.LayoutParams(
113
221
  ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
114
- return overlay;
222
+ framePresentation.show();
223
+ // wgpu-native, the default Android lane, has no external-texture import, so the produced
224
+ // buffer is read back to CPU and uploaded by the existing composite. Report the path by
225
+ // name rather than letting a reader infer it. Cost measured at ~1.1 ms/frame on the Pixel 8.
226
+ nativeUiCompositePath("in-frame-cpu");
227
+ }
228
+
229
+ /** Hand each produced frame to native, synchronously; the image can close on return. */
230
+ private void onFrameAvailable(ImageReader reader) {
231
+ Image image = null;
232
+ try {
233
+ image = reader.acquireLatestImage();
234
+ if (image == null) return;
235
+ Image.Plane plane = image.getPlanes()[0];
236
+ java.nio.ByteBuffer pixels = plane.getBuffer();
237
+ pixels.position(0);
238
+ frameCounter += 1;
239
+ if (frameCounter == 1) {
240
+ android.util.Log.i("Mystral", "TN_UI_INFRAME_FIRST_FRAME:{\"width\":" + image.getWidth()
241
+ + ",\"height\":" + image.getHeight() + ",\"stride\":" + plane.getRowStride() + "}");
242
+ }
243
+ nativeUiFrame(pixels, image.getWidth(), image.getHeight(), plane.getRowStride());
244
+ } catch (Throwable error) {
245
+ android.util.Log.w("Mystral",
246
+ "TN_UI_INFRAME_FRAME:{\"error\":\"" + error.getClass().getSimpleName() + "\"}");
247
+ } finally {
248
+ if (image != null) image.close();
249
+ }
250
+ }
251
+
252
+ /** Whether this overlay composites in-frame. The activity routes touches on when it does. */
253
+ public boolean isInFrame() {
254
+ return inFrame;
255
+ }
256
+
257
+ /** Release the off-screen producer. Safe on the child-window path and when nothing started. */
258
+ public void releaseProducer() {
259
+ if (!inFrame) return;
260
+ if (framePresentation != null) {
261
+ framePresentation.dismiss();
262
+ framePresentation = null;
263
+ }
264
+ if (frameDisplay != null) {
265
+ frameDisplay.release();
266
+ frameDisplay = null;
267
+ }
268
+ if (frameReader != null) {
269
+ frameReader.close();
270
+ frameReader = null;
271
+ }
272
+ if (frameThread != null) {
273
+ frameThread.quitSafely();
274
+ frameThread = null;
275
+ }
115
276
  }
116
277
 
117
278
  private void configure(Activity activity) {
118
279
  setBackgroundColor(Color.TRANSPARENT);
119
280
  // A hardware layer is what lets SurfaceFlinger promote this view to an overlay plane
120
- // instead of compositing it on the GPU the game is already saturating.
121
- setLayerType(View.LAYER_TYPE_HARDWARE, null);
281
+ // instead of compositing it on the GPU the game is already saturating. In-frame the view
282
+ // is not a layer at all; it draws into the producer's surface, so the layer is left alone.
283
+ if (!inFrame) setLayerType(View.LAYER_TYPE_HARDWARE, null);
122
284
  getSettings().setJavaScriptEnabled(true);
123
285
  getSettings().setDomStorageEnabled(true);
124
286
  // The UI is a local bundle; nothing in it should be able to reach the network.