LayerState.h
中定义了结构体 layer_state_t
,它是客户端和 SurfaceFlinger 交互时传递的数据。还有结构体 ComposerState 封装了 layer_state_t
,同时定义了 write()
和 read()
函数。
struct layer_state_t {
enum Permission {
ACCESS_SURFACE_FLINGER = 0x1,
ROTATE_SURFACE_FLINGER = 0x2,
INTERNAL_SYSTEM_WINDOW = 0x4,
};
layer_state_t
中一些字段的变更需要 ACCESS_SURFACE_FLINGER
或 ROTATE_SURFACE_FLINGER
权限。 enum {
eLayerHidden = 0x01,// SURFACE_HIDDEN in SurfaceControl.java
eLayerOpaque = 0x02,// SURFACE_OPAQUE
eLayerSkipScreenshot = 0x40,// SKIP_SCREENSHOT
eLayerSecure = 0x80,// SECURE// Queue up BufferStateLayer buffers instead of dropping the oldest buffer when this flag is// set. This blocks the client until all the buffers have been presented. If the buffers// have presentation timestamps, then we may drop buffers.
eEnableBackpressure = 0x100,// ENABLE_BACKPRESSURE
};
flags
的定义,如果变更了上面的 flag,则给 what
或操作 eFlagsChanged
。 enum {
ePositionChanged = 0x00000001,
eLayerChanged = 0x00000002,
eSizeChanged = 0x00000004,
eAlphaChanged = 0x00000008,
...
eFlagsChanged = 0x00000040,
eLayerStackChanged = 0x00000080,
...
};
what
的定义。 void merge(const layer_state_t& other);
status_t write(Parcel& output) const;
status_t read(const Parcel& input);
merge()
函数是用 other
覆盖原 layer_state_t
。write()
和 read()
是读写 Parcel。 void sanitize(int32_t permissions);
sanitize()
检查权限,如果没有权限,则取消相应的变更 what
。例如,eInputInfoChanged
和 eFrameRateChanged
需要 ACCESS_SURFACE_FLINGER
。 sp<IBinder> surface;
int32_t layerId;
surface
和 layerId
是 SurfaceControl 的 mHandle
和 mLayerId
。它们是在 Transaction::getLayerState() 中第一次新建 layer_state_t
并设置的。