Two USB monitors, one phone: a dual-screen DeX desktop from a Galaxy S24+

Illustration: a phone connected by cables to two monitors, each showing its own desktop; coloured tiles mark the parts of the screen being updated

I own two cheap USB-C portable monitors (PEAQ PMO-P150-FDB) and a Samsung Galaxy S24+ (SM-S926B, Android 17, One UI 9.0). I wanted the phone to work like a small computer with two screens, the way “Extend” works on Windows: a Bluetooth mouse that moves from one screen to the other, a different app on each panel, and no laptop in between.

The panels came with a vendor app that mirrors the phone. It mirrors instead of extending, and it treats the phone as a video source. This post describes how I replaced it. I reverse-engineered the panel protocol, wrote an encoder that runs on the phone, plugged the panels into Samsung DeX as two real desktops, and then spent several rounds on performance and on getting enough power into the phone.

The code is on GitHub at barancuru/peaq-dual-usb-android under the MIT license. It is a personal research project. It is not affiliated with the panel maker and contains no vendor code or firmware.

What the panels are

The monitors identify as RACERTECH USB DISP controllers (34C7:2114). They do not use DisplayPort Alt Mode. The phone sends compressed images over plain USB bulk transfers, and a small controller in the panel decodes them.

The vendor app and USB traces showed the format:

  • The 1920 × 1080 screen is cut into 8,100 tiles of 32 × 8 pixels.
  • Each tile is a small baseline JPEG scan (four 8 × 8 blocks per component) behind a 32-bit header, 0xd0000000 | tile << 10 | (size − 4) | table slot, where size is the record length in bytes rounded up to a multiple of 4. The last record of a frame sets an extra flag, and the packet is padded to 128 bytes.
  • Quantisation tables go into three slots with control transfers. Two header bits pick the slot for each tile.
  • The panel keeps two frame buffers and alternates between them.

The two buffers mattered later. To send only the tiles that changed, the phone has to track what each buffer holds, which is not the same as the previous frame.

Diagram: a shell helper creates two virtual displays; each draws into a SurfaceTexture; a GPU compute pass copies and encodes the frame; the CPU builds sparse packets and sends them over USB to panel A and panel B
How a frame travels from DeX to the panels

Architecture

The system has three parts.

A shell helper creates the displays. Android lets only privileged code create virtual displays that DeX accepts as desktops, so the helper is a small Java program started with app_process from ADB, running as the shell user (UID 2000). It creates two VirtualDisplays with the trusted flag and the flag that allows a content mode switch. DeX then gives each one a launcher and a taskbar, and the display topology API puts them side by side so the mouse crosses between them.

An Android app captures and encodes. Each virtual display draws into a surface owned by the app, which turns the frames into the panel’s tile format and writes them to the two USB devices.

The panels only decode.

The first working version used an ImageReader per display, copied each frame into a buffer and encoded it on the CPU with several threads, using an integer DCT, Huffman coding and per-tile caching. It worked, but the phone got hot and video was not smooth.

Making it fast

Most of the remaining work was performance. My guesses about the bottleneck were wrong more than once, and only measurements settled them.

Send only what changed

A desktop is mostly static. In sparse mode the encoder sends only the tiles whose content the target buffer does not have yet, plus a few refresh tiles in rotation. Because the panel alternates buffers, a tile that changes in frame N goes out twice, once for each buffer. When more than half of the tiles in the target buffer need updating, as in full-screen video, the encoder assembles a complete frame from cached columns instead, which costs less CPU time than building a long sparse packet.

Different quality per tile

Text needs fine quantisation. Video looks fine with coarse tables and costs much more to send finely. The encoder keeps both table sets. A tile that keeps changing switches to the coarse tables and goes back to fine after 15 calm frames. A tile with enough strong luma edges is never coarsened, so text inside a moving area stays sharp.

Move the encoder to the GPU

The phone’s Xclipse 940 GPU runs OpenGL ES 3.1 compute shaders through ANGLE on Vulkan. I wrote a single-pass shader with one tile per thread: colour conversion, DCT, quantisation and Huffman coding into a 768-byte slot. To check it, I ran the same shader on a desktop software GPU (Mesa llvmpipe) and compared it byte for byte with the Java encoder. The app also tests itself at start-up. It encodes the first real frame on both the GPU and the CPU and uses the GPU only if the bytes match.

Profile before guessing

GPU timer queries showed that the shader needed 5 to 8 ms for all 8,100 tiles, while a frame took 18 to 39 ms. The rest was waiting on a GPU queue shared with video decoding and the DeX compositor. Pipelining fixed that. The encoder submits frame N before it reads the results of frame N−1, using two sets of buffers. Packets run one frame behind, and an idle frame flushes the pipeline so the last change still reaches the panel.

At that point I wondered whether rewriting the encoder in a faster language such as Rust would help. A simpleperf profile showed that most of the CPU time was not spent encoding at all:

Where the app’s CPU time went (two full-screen videos)Share
Tile sharpness check on the CPU20 %
Copying frames out of the ImageReader (uncached graphics memory)18 %
Other frame copies~12 %
USB writes11 %
GPU upload and readback13 %

The time went into moving data around and into CPU work the GPU could do, and a new language would have fixed neither. Three changes followed:

  1. The CPU now only marks a tile as hot. The shader applies the same edge rule and picks the tables itself.
  2. After a frame is submitted, the CPU keeps no copy of the pixels. It reads back the few tiles it must encode itself, one at a time.
  3. Each display now draws into a SurfaceTexture attached to the encoder’s GL context, and a tiny compute pass copies that texture into the encoder’s buffer. The CPU no longer copies any full frame; the only copy left is that pass inside the GPU. If the GPU self-test fails in this mode, the app turns zero-copy off and the session has to be prepared again, after which frames take the CPU path.
Bar chart of CPU samples in a 30 second profile with two videos: 25,005 in v0.76, 20,953 in v0.77 and 9,650 in v0.79, a 61 percent reduction
CPU samples per version

Under the same load (two full-screen videos, held at 20 frames per second by the thermal limit), the profiler’s CPU sample count fell from 25,005 to 9,650, a 61 % cut. The app went from more than one core to about half of one. Without the thermal limit, each panel receives about 29 frame packets per second for desktop content and 24 for full-screen video, which is the cap I set for video. These are packets delivered to the panel, which is not quite the same thing as unique frames displayed per second.

DeX on a virtual display

DeX on displays it did not create needed a few fixes.

The helper turns the phone’s own screen off after 30 seconds without a touch and back on at the next touch. It watches the touchscreen with getevent, so mouse and keyboard input do not wake it.

When a USB cable glitches, the session closes and resumes by itself. Android moves the windows from the vanished displays to the phone, and DeX brings back only some of them. The helper notes which app was on which panel and moves the missing ones back.

On a virtual panel, One UI’s Recents controller ends about 0.4 seconds after the view opens, so a second press of the taskbar button cannot close it. The helper follows the launcher’s log and removes the stuck view.

Power

With two full-screen videos playing, the phone used more power than the panel’s charging pass-through supplied. Through the panel the phone negotiates only 9 V AFC, about 15 W, and it lost about 0.8 A while plugged in. Turning the phone’s screen off barely helped. A wireless charging stand did nothing, because the phone ignores the coil while a cable is attached.

A USB-C hub with Power Delivery pass-through fixed it. The hub’s cable goes to the phone, the charger goes into the hub’s PD port, and each panel connects from its USB output (its PD output does not work here) to a USB-A port on the hub. In this layout the phone is USB host and power sink at the same time.

The first hub did pass PPS through, and the lock screen showed “Super fast charging”, but the hub kept resetting itself: under PPS, with the setting turned off, and even with the panels powered separately. A second hub ran the two-video load for about ten minutes of testing without a drop. It charges over 9 V USB Power Delivery without PPS, and the phone gains about 0.55 A instead of losing 0.8 A. I have not measured how it holds up over hours.

Heat is the remaining limit. Above 42 °C the encoder drops to 20 new frames per second and the phone lowers its charging current. A clip-on phone cooler would probably do more now than further code changes.

Security and compatibility

The setup does not need root. It does rely on an ADB shell helper that I authorised myself and on Android APIs that are not public, so an Android or One UI update can break it. Turning off the phone’s own screen only powers the panel down; it does not lock the phone.

Working with AI agents

I did this project with AI coding agents connected to the phone over wireless ADB. The early protocol analysis ran in sessions with OpenAI’s Codex. From the DeX desktop onward I worked with Claude Code, Anthropic’s coding agent. The agents traced the vendor app, wrote the encoder and the shaders, built and installed each version, read the logs and ran the measurements. I handled the hardware, made the decisions and said what I saw on the screens.

Every change was checked against something. The shader was compared byte for byte with the CPU encoder on a software GPU, the app refuses the GPU path if the bytes differ, and each encoder change came with a test against a model of the panel’s two buffers.

Decisions came after measurements. Pipelining, moving the sharpness check to the GPU and zero-copy capture all came out of profiles.

My reports mattered too. At one point I said the colours looked off. What I had actually noticed was that text had become harder to read, and correcting that led to the per-tile quality work.

Where it stands

The phone drives two 1920 × 1080 panels as two independent DeX desktops, with a Bluetooth mouse and a USB keyboard. Desktop work is smooth, video is watchable with text staying sharp, and the phone charges while doing it.

Still open: PPS through the hub for faster charging, some CPU work that could move to the GPU, and better cooling. The protocol notes, the encoder, the helper and the full measurement history are in the repository.