7

I’m looking for a way to assign a Surface (native window) object to a display so that the buffers submitted to that native window would be rendered to that specific display rather than to the main display. I would like to do that in native code.

In Java, it can be done by using the Presentation API.

In native code I tried to call SurfaceComposerClient::setDisplaySurface(), passing to it the display's IBinder object (returned by SurfaceComposerClient::getBuiltInDisplay()), and the IGraphicBufferProducer object (returned by Surface::getIGraphicBufferProducer()). The problem is that the display goes blank, and even though I'm submitting buffers to the native window nothing is displayed.

If I don't call SurfaceComposerClient::setDisplaySurface(), then the native window renders to the main display.

Sample code:

sp<IBinder> display(SurfaceComposerClient::getBuiltInDisplay(1));

SurfaceComposerClient::getDisplayInfo(display, &displayInfo);

surfaceControl = surfaceComposerClient->createSurface(String8(""), displayInfo.w, displayInfo.h, HAL_PIXEL_FORMAT_RGB_565);

sp<Surface> surface = surfaceControl->getSurface();

sp<IGraphicBufferProducer> iGraphicBufferProducer = surface->getIGraphicBufferProducer();

SurfaceComposerClient::setDisplaySurface(display, iGraphicBufferProducer);

Does anyone know if this can be accomplished in native code, and if so how ?

Thanks

Bilbo
  • 71
  • 3
  • 2
    Problem solved: All I needed to do was set a lyer stack id other than 0 to the display, then set the same layerstack id to the surface. – Bilbo Dec 10 '14 at 15:21
  • Thanks I was trying something similar, I wanted the mouse cursor to render on the external display and I finally discovered this post. The line of code ended up being: `surfaceControl->setLayerStack(1); // id of the display for the layer to render on` – satur9nine May 08 '18 at 21:40
  • Hey @Bilbo replying to ask for more information on your use case here. We're finding the Presentations very limiting with our use case (multiple activities, webview we don't want to remove or change on transition). At a high level I thought about looking at the NDK to circumvent this API and would I be correct in saying that is what you were able to achieve in this example? Thanks! – kelvin Jun 01 '21 at 10:24

0 Answers0