android::Surface 如何获取SurfaceControl
时间: 2023-08-22 12:08:37 浏览: 165
Android_Surface系统的实现
要获取到 `android::SurfaceControl`,可以通过以下代码:
```c++
#include <gui/Surface.h>
#include <gui/SurfaceControl.h>
sp<IBinder> display = SurfaceComposerClient::getBuiltInDisplay(ISurfaceComposer::eDisplayIdMain);
DisplayInfo dinfo;
SurfaceComposerClient::getDisplayInfo(display, &dinfo);
ssize_t displayWidth = dinfo.w;
ssize_t displayHeight = dinfo.h;
sp<SurfaceControl> surfaceControl = SurfaceComposerClient::getInstance()->createSurface(
String8("MySurface"),
displayWidth, displayHeight, PIXEL_FORMAT_RGBA_8888, 0);
sp<Surface> surface = surfaceControl->getSurface();
```
这里我们调用 `SurfaceComposerClient::getInstance()->createSurface()` 方法创建了一个 `SurfaceControl` 对象,并通过 `getSurface()` 方法获取到了对应的 `Surface` 对象。
阅读全文