โก Ultra-fast native screen capture engine for Java โ 240โ2000 FPS zero-copy streaming via DirectX DXGI Desktop Duplication & hardware fallback.
FastScreen is the hardware-accelerated desktop capture and video ingestion substrate of the FastJava ecosystem. Powered by DirectX 11 and the DXGI 1.2+ Desktop Duplication API, FastScreen provides ultra-low latency desktop streaming (240โ2000 FPS), GPU-side hardware scaling via HLSL pixel shaders, zero JVM heap allocations through native frame pooling, and native window-capture exclusion (SetWindowDisplayAffinity) to completely eliminate recursive screen-mirroring (Droste effect).
import fastscreen.FastScreen;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.nio.ByteBuffer;
public class Demo {
public static void main(String[] args) {
// 1. Initialize FastScreen capture engine
FastScreen screen = new FastScreen();
// 2. Exclude your application window from capture (prevents Droste mirror recursion)
// FastScreen.excludeWindow(windowHandle);
// FastScreen.excludeWindow("My App Title");
// 3. Single-shot desktop screenshot
BufferedImage shot = screen.captureScreen();
// 4. Ultra-high-FPS desktop streaming (240+ FPS)
screen.startStream(0, 0, 1920, 1080);
// Optional: Hardware-accelerated GPU scaling with bilinear filter
// screen.enableHardwareScaling(1280, 720, true);
while (running) {
// ZERO-COPY: Read directly from native GPU staging memory
ByteBuffer directBuffer = screen.getNextFrameDirect();
if (directBuffer != null) {
// Process frame with 0 JVM garbage collection overhead
}
}
screen.stopStream();
screen.dispose();
}
}- Why FastScreen?
- Quick Start
- Key Features
- Real-Life Examples & Use Cases
- Architecture & Hardware Pipeline
- Performance Benchmarks
- API Quick Reference
- Window Capture Exclusion
- Installation
- Technical Examples & Hero Demos
- Documentation
- Platform Support
- Related Projects
- License
For over two decades, Java developers needing screen capture have been constrained to java.awt.Robot.createScreenCapture(). While adequate for occasional static screenshots, Robot fails catastrophically for modern high-performance use cases:
- Crippling Latency & Low Frame Rates:
java.awt.Robotrelies on legacy GDIGetDC/BitBltunder the hood, synchronized on the Java AWT Event Dispatch Thread (EDT). Capturing a full-screen frame takes 15โ50 ms, capping capture throughput at a sluggish 15โ20 FPS. - Severe JVM Heap Churn (GC Pauses): Every call to
robot.createScreenCapture()instantiates a newBufferedImage, aRaster, aDataBufferInt, and an underlyingint[]array (~8 MB for 1080p, ~33 MB for 4K). At 30 FPS, this generates gigabytes of heap garbage per minute, causing devastating Garbage Collection freezes. - No Hardware Acceleration or Scaling: Standard Java forces CPU-bound pixel downsampling, burning precious CPU cores that should be dedicated to computer vision or inference.
- Recursive Mirror Loops (Droste Effect): Capturing the screen while displaying the stream inside a window causes infinite visual recursion (hall of mirrors) unless cumbersome coordinates are manually cropped.
FastScreen eliminates all these bottlenecks by interfacing directly with the Windows GPU compositor:
- GPU Direct Duplication: Intercepts the composited desktop texture directly from the Desktop Window Manager (DWM) using DXGI 1.2+
IDXGIOutputDuplication. - Zero-Copy Architecture: Provides native Direct
ByteBufferviews into mapped GPU memory. 0 heap allocations, 0 GC pauses. - Hardware HLSL Scaling: Performs format conversion (BGRAโRGBA) and resolution downsampling entirely on GPU execution units before CPU readback.
- Native Window Exclusion: Sets Win32
WDA_EXCLUDEFROMCAPTURE(0x00000011) so DWM automatically renders what is behind your window directly into the capture stream.
- โก 240โ2000 FPS Capture Throughput โ Direct GPU framebuffer access via DirectX 11 Desktop Duplication.
- ๐๏ธ Zero GC Pressure โ Triple-buffered native frame pooling (
POOL_SIZE = 3) andByteBuffer.allocateDirectzero-copy streams. - ๐ก๏ธ Native Window Capture Exclusion โ Hide your app from capture via
FastScreen.excludeWindow(hwnd)orFastScreen.excludeWindow(title). - ๐ฎ Hardware GPU Scaling โ Bilinear and Point filtering implemented in custom embedded HLSL vertex/pixel shaders.
- ๐ Automatic Resilient Fallback โ Seamless fallback to high-speed GDI DIBSection (
CAPTUREBLT) for headless/RDP sessions. - ๐ฑ๏ธ Multi-Monitor Support โ Capture any physical display by monitor index.
- ๐ฆ Multiple Output Modes โ Direct
ByteBuffer, rawint[]RGBA pixel buffer, or standardBufferedImage. - ๐ FastCore Integration โ Unified zero-dependency native DLL loading across the FastJava ecosystem.
1. ๐ฎ Live Desktop Distortion & Magic Lens (FastVulkan)
By combining FastScreen.startStream(...) with FastScreen.excludeWindow(windowHandle), FastVulkan streams the live desktop behind itself at 120 FPS, deforming the desktop in real time across a 240ร135 mesh (64,800 triangles) using organic shaders (ripples, black holes, vortexes) without capturing itself.
Vision-guided automation agents and reinforcement learning models require sub-5ms screen frames. FastScreen feeds raw RGBA frames directly into OpenCV, TensorRT, or ONNX runtimes with zero latency and zero GC spikes.
3. ๐๏ธ Ultra-Fast Screen OCR & Live Scraping (FastOCR)
Ingest live text from any on-screen window, trading terminal, or dashboard with instantaneous pixel retrieval (screen.getPixelColor(x, y) or sub-region capture).
Broadcast or record high-refresh rate displays (144 Hz, 240 Hz, 360 Hz) without dropping frames or bottlenecking the CPU.
Build screen-sharing utilities, streamers' HUDs, or annotation overlays that are completely invisible to OBS, Discord, Zoom, or FastScreen itself.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Windows DWM Compositor โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
IDXGIOutputDuplication
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Direct3D 11 Desktop Texture โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
HLSL Pixel Shader (BGRA โ RGBA)
+ Hardware Scaling (Point / Linear)
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ CPU-Accessible Staging Texture / Pool โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
Zero-Copy Direct JNI
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Java Application (Direct ByteBuffer / int[]) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Measured on an Intel Core i7 with Windows 11 (Desktop resolution: 1440ร960). Test suite executed via examples/03-benchmark:
cd examples/03-benchmark
mvn clean compile exec:java| Benchmark Metric | Java java.awt.Robot |
FastScreen Native | Improvement |
|---|---|---|---|
| Streaming Frame Rate | ~15โ20 FPS | 229.8 FPS | 11.5โ15ร faster |
| Captured Frames (5s test) | 75โ100 frames | 1,149 frames | 1,149 / 1,149 (0 dropped) |
| Frame Capture Latency | 11.52 ms (P95: 18 ms, Max: 49 ms) | < 1.00 ms (P95: 0 ms) | Immediate / Zero-wait |
| JVM Garbage Generated | ~5.5 MB per frame (~110 MB/s) | 0 Bytes (Zero-Copy) | 100% Elimination |
| GPU Scaling Overhead | High CPU consumption | 0% CPU (GPU Shaders) | Hardware Offloaded |
Note
When running with full DXGI Desktop Duplication on dedicated GPUs, streaming throughput scales to 500โ2000 FPS.
| Method | Return Type | Description |
|---|---|---|
captureScreen() |
BufferedImage |
Captures full desktop screen |
captureScreen(Rectangle rect) |
BufferedImage |
Captures specified sub-rectangle |
captureRaw(int x, int y, int w, int h) |
int[] |
Returns raw RGBA pixel array |
startStream(int x, int y, int w, int h) |
boolean |
Starts continuous high-FPS streaming capture |
enableHardwareScaling(int w, int h, boolean smooth) |
boolean |
Configures GPU shader downsampling |
hasNewFrame() |
boolean |
Checks if a new frame is ready from DWM |
getNextFrame() |
int[] |
Retrieves next frame from triple-buffered pool |
getNextFrameDirect() |
ByteBuffer |
Zero-Copy: Returns direct native pointer |
stopStream() |
void |
Stops continuous streaming |
getPixelColor(int x, int y) |
int |
Fast single-pixel RGBA lookup |
excludeWindow(long hwnd) |
boolean |
Makes window invisible to capture by handle |
excludeWindow(String title) |
boolean |
Makes window invisible to capture by title |
includeWindow(long hwnd) |
boolean |
Restores normal window capture affinity |
dispose() |
void |
Releases all GPU and native staging resources |
To make any window invisible to screen capture (so capture tools record whatever is behind the window), FastScreen provides direct Win32 display affinity controls:
// Option A: Exclude by native HWND handle
FastScreen.excludeWindow(windowHandle);
// Option B: Exclude by window title (automatically enumerates top-level windows)
FastScreen.excludeWindow("FastVulkan โ 120 FPS Mesh Warp");
// Re-include when done
FastScreen.includeWindow(windowHandle);Under the hood, FastScreen applies SetWindowDisplayAffinity(hwnd, 0x00000011) (WDA_EXCLUDEFROMCAPTURE). Both DXGI Desktop Duplication and Win32 GDI honor this flag natively.
FastScreen is distributed via JitPack. It requires FastCore as the unified native library loader.
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<!-- FastScreen Core -->
<dependency>
<groupId>com.github.andrestubbe</groupId>
<artifactId>FastScreen</artifactId>
<version>0.1.2</version>
</dependency>
<!-- FastImage Native Bridge & Processing -->
<dependency>
<groupId>com.github.andrestubbe</groupId>
<artifactId>FastImage</artifactId>
<version>0.1.2</version>
</dependency>
<!-- FastCore Native Loader -->
<dependency>
<groupId>com.github.andrestubbe</groupId>
<artifactId>FastCore</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.andrestubbe:FastScreen:0.1.2'
implementation 'com.github.andrestubbe:FastImage:0.1.2'
implementation 'com.github.andrestubbe:FastCore:0.1.0'
}Download the latest pre-compiled JARs directly to add them to your project's classpath:
- ๐ฆ FastScreen-0.1.2.jar (The Core Library)
- โก FastImage-0.1.2.jar (The SIMD Image Engine)
- โ๏ธ FastCore-0.1.0.jar (The Mandatory JNI Loader)
Important
Both JARs must be present in your classpath for FastScreen's native functions to operate correctly.
See the examples/ directory for ready-to-run interactive implementations, benchmarks, and tests:
| Example / Demo | Description | Path | Run Command |
|---|---|---|---|
| Visual Showcase Hero Demo | Scalable FastTheme interactive window featuring live 240+ FPS desktop duplication, FastProportion COVER edge-to-edge scaling, [E] Window Exclusion toggle (Droste mirror vs. transparent magic window), and real-time title bar telemetry. |
examples/Demo/Demo.java |
run-demo.bat |
| High-Precision JMH Benchmarks | Standardized microbenchmarks measuring capture latency, frame rate throughput, and memory pressure. | examples/Benchmark |
run-benchmark.bat |
- COMPILE.md: Full compilation guide (MSVC C++17 build chain + JNI Setup).
- REFERENCE.md: Full API descriptions and method reference.
- PHILOSOPHY.md: The engineering rationale for zero-allocation performance.
- ROADMAP.md: Future milestones and planned features.
| Platform | Status |
|---|---|
| Windows 10/11 | โ Fully Supported |
| Linux | ๐ง Planned |
| macOS | ๐ง Planned |
MIT License โ See LICENSE file for details.
- FastCore โ Native Library Loader for Java
- FastRobot โ High-FPS Screen Capture & Native Automation for Java
- FastImage โ Ultra-Fast Native Image Processing for Java
- FastOCR โ Ultra-Fast Native OCR for Java
Part of the FastJava Ecosystem โ Making the JVM faster. โก
