Three ways to use Surface

Three ways of using

Surface The Surface working modes of the Native layer are: only on the Proxy side, Proxy and Service side work together, and only on the Service side (the third method is to be confirmed). The first two methods have common preprocessing work to be done on the Proxy side, as follows:
Proxy side
1. Create SurfaceFlinger's local proxy
sp<SurfaceComposerClient> client = new SurfaceComposerClient();

2. Create SurfaceControl's local proxy
sp<SurfaceControl> surfaceControl = client->createSurface(...);

3. Get the Surface local proxy
sp<Surface> surface = surfaceControl->getSurface();

After getting the Surface local proxy, you can use it for subsequent related operations

Method 1: Refer to Implementation of resize.cpp
Proxy side
1. Get Surface buffer
ANativeWindow_Buffer outBuffer;
surface->lock(&outBuffer, NULL);

2. Directly operate outBuffer.bits member
android_memset16((uint16_t*)outBuffer.bits, 0xF800, bpr*outBuffer .height);

3. Send it to SurfaceFlinger to display
surface->unlockAndPost();

Method 2: Refer to the implementation of Camera
Proxy
1. Get the local proxy of IGraphicBufferProducer
sp<IGraphicBufferProducer> gbp = surface->getIGraphicBufferProducer();

2. Pass it to the Service side
camera- > setPreviewTarget(gbp);

Service side
3. Create a new Surface based on gbp
sp<ANativeWindow> window = new Surface(gpb, /*controlledByApp*/ true);

4. Connect the window to the corresponding api set (purpose???)
result = native_window_api_connect(window.get(), NATIVE_WINDOW_API_CAMERA);

5. Use window related interfaces, such as setting the number of queue buffers to 3
window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, 3);

Method 3: in the constructor of Surface There is a parameter controlledByApp that indicates whether it is used by the Proxy side. If it is only used on the Service side, the Surface can be created by default. There is relevant code in SurfaceMediaSource_test:
1. Create BufferQueue
sp<BufferQueuem> BufferQueue = new BufferQueue();

2. Create consumer listener
wp<ConsumerListener> listener = static_cast<ConsumerListener*>(this);

3. Create consumer listener proxy
sp<BufferQueue:: ProxyConsumerListener> proxy = new BufferQueue::ProxyConsumerListener(listener);

4. Connect the consumer to the BufferQueue
mBufferQueue->consumerConnect(proxy, false);

5. Create a new Surface based on the BufferQueue
sp<IGraphicBufferProducer> sms = mBufferQueue;
sp<Surface> stc = new Surface(sms);

6. Use window related interfaces, such as perform()
sp<ANativeWindow> window = stc;
window->perform(window, NATIVE_WINDOW_SET_BUFFER_COUNT, 3);

Note:
1. Method 3 is to be confirmed
2. For the operation of ANativeWindow, the official provides a window. h Auxiliary tools.

From:http://blog.csdn.net/alien75/article/details/41078963

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326268700&siteId=291194637