# trev3d/questdisplayaccessdemo architecture

> Architecture diagram of the GitHub repository trev3d/questdisplayaccessdemo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/trev3d/questdisplayaccessdemo
- Repository: https://github.com/trev3d/questdisplayaccessdemo

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
graph TB
  subgraph "Unity Managed Layer"
    UDCM["Unity Display Capture Manager"]:::unity
    DK["Depth and Image Processing (DepthKit)"]:::unity
    VRXR["VR & XR Integration"]:::unity
  end

  subgraph "Integration Layer"
    JNIBridge["JNI Bridge"]:::integration
  end

  subgraph "Native Android Layer"
    NDS["Native Display Capture Services"]:::native
    BSI["Barcode Scanning Integration"]:::native
    ANDC["Android Native Plugin Configuration"]:::native
  end

  subgraph "External Dependencies"
    MPA["MediaProjection API"]:::external
    GML["Google ML Barcode Scanner"]:::external
  end

  subgraph "Native Build Layer"
    JNI_Build["Native C/C++ JNI Build Layer"]:::build
  end

  DK -->|"suppliesTexture"| UDCM
  VRXR -->|"supportsUI"| UDCM

  UDCM -->|"startCapture()"| JNIBridge
  JNIBridge -->|"JNIcall"| NDS
  NDS -->|"captureFrames"| MPA
  NDS -->|"scanFrame"| BSI
  BSI -->|"barcodeResult"| JNIBridge
  JNIBridge -->|"loadNativeLib"| JNI_Build
  ANDC -->|"configures"| NDS
  BSI -->|"uses"| GML

  click UDCM "https://github.com/trev3d/questdisplayaccessdemo/blob/master/Assets/DisplayCapture/DisplayCaptureManager.cs"
  click UDCM "https://github.com/trev3d/questdisplayaccessdemo/blob/master/Assets/DisplayCapture/DisplayCaptureManager.java"
  click NDS "https://github.com/trev3d/questdisplayaccessdemo/blob/master/Assets/DisplayCapture/DisplayCaptureRequestActivity.java"
  click NDS "https://github.com/trev3d/questdisplayaccessdemo/blob/master/Assets/DisplayCapture/DisplayCaptureNotificationService.java"
  click BSI "https://github.com/trev3d/questdisplayaccessdemo/tree/master/Assets/DisplayCapture/Barcode"
  click DK "https://github.com/trev3d/questdisplayaccessdemo/tree/master/Assets/DepthKit"
  click VRXR "https://github.com/trev3d/questdisplayaccessdemo/tree/master/Assets/Oculus"
  click VRXR "https://github.com/trev3d/questdisplayaccessdemo/tree/master/Assets/XR"
  click ANDC "https://github.com/trev3d/questdisplayaccessdemo/tree/master/Assets/Plugins/Android"
  click JNI_Build "https://github.com/trev3d/questdisplayaccessdemo/blob/master/.utmp"

  classDef unity fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
  classDef integration fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
  classDef native fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
  classDef external fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
  classDef build fill:#D6EAF8,stroke:#5DADE2,stroke-width:2px;
```
