How trev3d/questdisplayaccessdemo works
Project Type and Purpose
• This is a Unity-based full-stack application that integrates both managed (C#/Unity) and native Android components.
• Its purpose is to “capture” the display (using Android’s MediaProjection API) and then feed that display as a texture into a Unity scene. Additionally, it integrates with Google’s ML barcode scanning functionality for QR code tracking, making use of both Unity’s rendering components and native Android services.
File Structure
• The Assets directory contains key project components:
– “DepthKit”: Includes compute shaders, C# drivers, and shader files, representing the image-depth processing aspects.
– “DisplayCapture”: Contains scripts and Unity scene files (e.g., Demo.unity) and likely manages the texture feeding and display capture logic.
– “Oculus” and “XR”: These folders hold VR setup and configuration assets for Oculus/Quest.
• “Plugins/Android”: Contains AndroidManifest.xml, MainGradle template, and any other Android-specific configuration needed for native integration. This is where the project’s custom modifications (the added permissions, activities, and services for display capture) are housed.
• The .utmp directory and numerous CMake- and ninja-related files indicate that parts of the project are built with CMake. This is common when integrating C/C++ native code via JNI with Unity. It shows that the native layer is compiled for the target architecture (here, arm64-v8a).
• The ProjectSettings and Packages directories hold Unity-specific configuration and dependency information.
Key Architectural Components
a. Unity Runtime (Managed Code):
– It comprises the bulk of the Unity project (Assets, Scenes, Scripts, Shaders, etc.).
– “DepthKit” and “DisplayCapture” components manage texture handling, shader processing, and coordinate the display capture logic.
– XR and Oculus specific assets provide integration with the Quest hardware.
b. Native Android Layer:
– AndroidManifest.xml modifications and MainGradle template are configured to use Android’s MediaProjection API.
– Provided native services such as DisplayCaptureRequestActivity and DisplayCaptureNotificationService are responsible for starting the media projection session and handling system callbacks.
– CMake build files along with generated build directories under .utmp indicate the presence of native code (JNI layer) for interfacing between Unity’s C# and Android’s native code.
c. External Services and Libraries:
– MediaProjection API (for screen capture).
– Google ML Kit’s Barcode Scanning library for QR code/Barcode functions.
– Third-party libraries (e.g., AppCompat, Gson) that are added in the Gradle dependencies.
– These libraries interact with the native Android layer, providing essential functionality.
Relationships and Data Flow
• The Unity front-end (managed code) initiates display capture via C# scripts included in the “DisplayCapture” folder.
• The managed code communicates with the native Android layer via JNI calls which trigger the native display capture service.
• The native Android components (activities and services) interact with MediaProjection to capture the screen and then pass the texture data back through the JNI bridge.
• The barcode scanning integration (via Google ML Kit) processes the captured frames, and its results are sent back to the Unity layer to possibly influence scene behavior.
• Gradle and CMake configuration files ensure these native binaries are built, packaged, and integrated into the final APK.
– Unity Engine (C# Scripts, DepthKit, DisplayCapture, Scenes, XR/Oculus Assets).
– Native Android Layer (Activities, Services, JNI bridging, CMake-built binaries).
– External Dependencies (MediaProjection API, Google ML Kit, Gradle dependencies).
– Invocation from Unity to the Native Layer (e.g., when starting display capture)
– Data flow from MediaProjection (captured frames) back to Unity (texture update).
– Communication between native barcode scanning results and Unity.
– Use another for native Android components.