一路向下之AOSP研究Android开发

View绘制原理(06)-ASurfaceControl

2023-07-19  本文已影响0人  代码多哥

更Surface很相似,SurfaceControl也有一个对应的定义ASurfaceControl,但是它和SurfaceControl之间并不存在继承关系,仅仅是可以相互转换而已。

1. 定义

frameworks/native/include/android/surface_control.h

struct ASurfaceControl;

/**
 * The SurfaceControl API can be used to provide a hierarchy of surfaces for
 * composition to the system compositor. ASurfaceControl represents a content node in
 * this hierarchy.
 */
typedef struct ASurfaceControl ASurfaceControl;

ASurfaceControl只是一个结构体,也没有属性。

2. 相互转换

他们之间只要进行指针强制转换就可以实现相互转换。

SurfaceControl转ASurfaeControl

ASurfaceControl* surfaceControl = reinterpret_cast<ASurfaceControl*>(surfaceControlPtr);

ASurfaceControl转SurfaeControl
frameworks/base/native/android/surface_control.cpp

SurfaceControl* ASurfaceControl_to_SurfaceControl(ASurfaceControl* aSurfaceControl) {
    return reinterpret_cast<SurfaceControl*>(aSurfaceControl);
}

3. 函数

关于ASurfaceControl定义了一系列的全局函数,他们主要在
frameworks/native/include/android/surface_control.h
frameworks/native/include/private/surface_control_private.h
这个函数的实现在
frameworks/base/native/android/surface_control.cpp,比如:

ASurfaceControl* ASurfaceControl_createFromWindow(ANativeWindow* window, const char* debug_name) {
ASurfaceControl* ASurfaceControl_create(ASurfaceControl* parent, const char* debug_name)  __INTRODUCED_IN(29);
void ASurfaceControl_acquire(ASurfaceControl* surface_control) __INTRODUCED_IN(31);
void ASurfaceControl_release(ASurfaceControl* surface_control) __INTRODUCED_IN(29);
void ASurfaceControl_registerSurfaceStatsListener(ASurfaceControl* control, void* context,
        ASurfaceControl_SurfaceStatsListener func);
void ASurfaceControl_unregisterSurfaceStatsListener(void* context,  ASurfaceControl_SurfaceStatsListener func);

int64_t ASurfaceControlStats_getAcquireTime(ASurfaceControlStats* stats);
uint64_t ASurfaceControlStats_getFrameNumber(ASurfaceControlStats* stats);

这些方法不是很复杂,主要是操作将ASurfaceControl转化成SurfaceControl之后再执行相对应的操作。

4. 总结

这个ASurfaceControl很简单,但是因为分析后续绘制流程会涉及到这个概念,因此就介绍一下

上一篇 下一篇

猜你喜欢

热点阅读