首页 > 其他分享 >Android显示系统-基本概念梳理

Android显示系统-基本概念梳理

时间:2023-06-24 17:56:26浏览次数:33  
标签:uint32 layer const 梳理 00000000 float 基本概念 Android 图层

DisplayState

struct DisplayState {
    // 这里定义了Display变更类型,说明Display可能发生的变化类型
    enum {
        eSurfaceChanged = 0x01,
        eLayerStackChanged = 0x02,
        eDisplayProjectionChanged = 0x04,
        eDisplaySizeChanged = 0x08,
        eFlagsChanged = 0x10
    };

    DisplayState();
    void merge(const DisplayState& other);
    void sanitize(int32_t permissions); // 清除无效(无权限)的变换标记,即若无权限进行某些变更,则拦截对应的变更操作

    uint32_t what = 0;  // 变化标记,表示发生了什么变化
    uint32_t flags = 0;
    sp<IBinder> token;
    sp<IGraphicBufferProducer> surface;

    ui::LayerStack layerStack = ui::DEFAULT_LAYER_STACK;    // 属于此display的layer栈,即需要显示在此display上的所有图层
    ui::Rotation orientation = ui::ROTATION_0;              // display的显示方向
    Rect layerStackSpaceRect = Rect::EMPTY_RECT;            // 表示原始layers区域大小,即图层的原始大小和位置
    Rect orientedDisplaySpaceRect = Rect::EMPTY_RECT;       // 表示进行一系列变换后,图层应该显示在的区域(大小、位置),即图层应该显示在屏幕的哪个位置及大小

    uint32_t width = 0;  // display宽度
    uint32_t height = 0; // display高度

    status_t write(Parcel& output) const;
    status_t read(const Parcel& input);
};
  • orientation表示屏幕显示的方向,一般为0/90/180/270。
  • layerStackSpaceRect定义的矩形区域用于表示原始layers区域大小,即图层的原始大小和位置。
  • orientedDisplaySpaceRect定义的矩形区域用于表示进行一系列变换后,图层应该显示在的区域(大小、位置),即图层应该显示在屏幕的哪个位置及大小

DisplayState指定了如何将图层显示到物理屏幕上,首先要先将从layerslayerStackSpaceRect平移(translate)和缩放到orientedDisplaySpaceRect区域,然后再根据orientation/width/height进行旋转,将图层显示到物理屏上指定的位置。

例如,假设定义了一个Rect(0, 0, 200, 100)的layerStackSpaceRect区域(大小为200x100),而orientedDisplaySpaceRect区域为Rect(20, 10, 420, 210),其大小为400x200,物理屏display的尺寸为WxH。当orientation为0时,首先需要将layers进行放大2倍以匹配目标显示区域的大小,然后将其从(0,0)点移动到(20,10)点。当orientation为1时,在进行完缩放和平衡动作后,还需要顺时钟旋转90度,再平衡(W, 0)后,就变换到了指定的物理屏上的显示位置。

ComposerState

ComposeState的定义如下,其中最关键的是layer_state_t结构体:

struct ComposerState {
    layer_state_t state;
    status_t write(Parcel& output) const;
    status_t read(const Parcel& input);
};

layer_state_t结构体内容较多,拆开来看
首先,定义了三个权限,含义比较简单

enum Permission {
    ACCESS_SURFACE_FLINGER = 0x1, // 访问权限
    ROTATE_SURFACE_FLINGER = 0x2, // 旋转权限
    INTERNAL_SYSTEM_WINDOW = 0x4, // 系统窗口权限
};

接口定义一组layer相关类型,一般用于创建图层时指定layer的类型

enum {
    eLayerHidden = 0x01,         // 隐藏此图层
    eLayerOpaque = 0x02,         // Layer不透明
    eLayerSkipScreenshot = 0x40, // 截图(屏)时跳过此layer,即截屏截不到此图层
    eLayerSecure = 0x80,         // 是否为安全图层,安全图层投屏时不会被投到外接屏
    // 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
    eLayerIsDisplayDecoration = 0x200, // 装饰图层,如屏幕顶部和底部的圆角图层,隐私指示器图层等
    // Ignore any destination frame set on the layer. This is used when the buffer scaling mode
    // is freeze and the destination frame is applied asynchronously with the buffer submission.
    // This is needed to maintain compatibility for SurfaceView scaling behavior.
    // See SurfaceView scaling behavior for more details.
    eIgnoreDestinationFrame = 0x400,
};

这一组定义含义比较明确,用于表示layer发生了什么变化,一般配合transaction的各种setXXX方法进行使用,当transaction提交到SurfaceFlinger时,SurfaceFlinger于依据不同类型的变化进行相应的处理。

enum {
    ePositionChanged = 0x00000001,
    eLayerChanged = 0x00000002,
    eSizeChanged = 0x00000004,
    eAlphaChanged = 0x00000008,
    eMatrixChanged = 0x00000010,
    eTransparentRegionChanged = 0x00000020,
    eFlagsChanged = 0x00000040,
    eLayerStackChanged = 0x00000080,
    eDimmingEnabledChanged = 0x00000400,
    eShadowRadiusChanged = 0x00000800,
    /* unused 0x00001000, */
    eBufferCropChanged = 0x00002000,
    eRelativeLayerChanged = 0x00004000,
    eReparent = 0x00008000,
    eColorChanged = 0x00010000,
    eDestroySurface = 0x00020000,
    eTransformChanged = 0x00040000,
    eTransformToDisplayInverseChanged = 0x00080000,
    eCropChanged = 0x00100000,
    eBufferChanged = 0x00200000,
    /* unused 0x00400000, */
    eDataspaceChanged = 0x00800000,
    eHdrMetadataChanged = 0x01000000,
    eSurfaceDamageRegionChanged = 0x02000000,
    eApiChanged = 0x04000000,
    eSidebandStreamChanged = 0x08000000,
    eColorTransformChanged = 0x10000000,
    eHasListenerCallbacksChanged = 0x20000000,
    eInputInfoChanged = 0x40000000,
    eCornerRadiusChanged = 0x80000000,
    eDestinationFrameChanged = 0x1'00000000,
    /* unused = 0x2'00000000, */
    eBackgroundColorChanged = 0x4'00000000,
    eMetadataChanged = 0x8'00000000,
    eColorSpaceAgnosticChanged = 0x10'00000000,
    eFrameRateSelectionPriority = 0x20'00000000,
    eFrameRateChanged = 0x40'00000000,
    eBackgroundBlurRadiusChanged = 0x80'00000000,
    eProducerDisconnect = 0x100'00000000,
    eFixedTransformHintChanged = 0x200'00000000,
    /* unused 0x400'00000000, */
    eBlurRegionsChanged = 0x800'00000000,
    eAutoRefreshChanged = 0x1000'00000000,
    eStretchChanged = 0x2000'00000000,
    eTrustedOverlayChanged = 0x4000'00000000,
    eDropInputModeChanged = 0x8000'00000000
};
struct layer_state_t {
    // ......
    layer_state_t();

    void merge(const layer_state_t& other);
    status_t write(Parcel& output) const;
    status_t read(const Parcel& input);
    bool hasBufferChanges() const;
    bool hasValidBuffer() const;
    void sanitize(int32_t permissions);

    struct matrix22_t {
        float dsdx{0};
        float dtdx{0};
        float dtdy{0};
        float dsdy{0};
        status_t write(Parcel& output) const;
        status_t read(const Parcel& input);
    };
    sp<IBinder> surface;
    int32_t layerId;
    uint64_t what;
    float x;    // layer位置的x坐标
    float y;    // layer位置的y坐标
    int32_t z;  // layer的z轴顺序
    uint32_t w; // layer的宽度w
    uint32_t h; // layer的高度h
    ui::LayerStack layerStack = ui::DEFAULT_LAYER_STACK;
    float alpha;    // layer的透明度
    uint32_t flags; // layer发生变化的flags标记,参考前面layer发生变化的enum定义
    uint32_t mask;
    uint8_t reserved;
    matrix22_t matrix;
    float cornerRadius;  // layer的圆角半径
    uint32_t backgroundBlurRadius;
    sp<SurfaceControl> reparentSurfaceControl;

    sp<SurfaceControl> relativeLayerSurfaceControl;

    sp<SurfaceControl> parentSurfaceControlForChild;

    half3 color;

    Region transparentRegion; // non POD must be last. see write/read

    uint32_t transform;
    bool transformToDisplayInverse;
    Rect crop;
    std::shared_ptr<BufferData> bufferData = nullptr;
    ui::Dataspace dataspace;
    HdrMetadata hdrMetadata;
    Region surfaceDamageRegion;
    int32_t api;
    sp<NativeHandle> sidebandStream;
    mat4 colorTransform;
    std::vector<BlurRegion> blurRegions;
    sp<gui::WindowInfoHandle> windowInfoHandle = new gui::WindowInfoHandle();
    LayerMetadata metadata;

    float bgColorAlpha; // The following refer to the alpha, and dataspace, respectively of the background color layer
    ui::Dataspace bgColorDataspace;

    bool colorSpaceAgnostic;  // A color space agnostic layer means the color of this layer can be interpreted in any color space.

    std::vector<ListenerCallbacks> listeners;

    float shadowRadius; // 此layer的阴影半径
    int32_t frameRateSelectionPriority;
    
    float frameRate; // 此layer设定的预期刷新率
    int8_t frameRateCompatibility;
    int8_t changeFrameRateStrategy;

    // Set by window manager indicating the layer and all its children are
    // in a different orientation than the display. The hint suggests that
    // the graphic producers should receive a transform hint as if the
    // display was in this orientation. When the display changes to match
    // the layer orientation, the graphic producer may not need to allocate
    // a buffer of a different size. -1 means the transform hint is not set,
    // otherwise the value will be a valid ui::Rotation.
    ui::Transform::RotationFlags fixedTransformHint;

    // Indicates that the consumer should acquire the next frame as soon as it
    // can and not wait for a frame to become available. This is only relevant
    // in shared buffer mode.
    bool autoRefresh;

    // An inherited state that indicates that this surface control and its children
    // should be trusted for input occlusion detection purposes
    bool isTrustedOverlay;

    StretchEffect stretchEffect; // 此layer的拉伸效果
    Rect bufferCrop;
    Rect destinationFrame;

    gui::DropInputMode dropInputMode; // 强制inputflinger忽略所有此图层及其子图层接收到的input事件,即此图层不处理input事件。

    bool dimmingEnabled;
};

标签:uint32,layer,const,梳理,00000000,float,基本概念,Android,图层
From: https://www.cnblogs.com/tsts/p/17501413.html

相关文章

  • pg基本基本概念——模式、表、空间、用户间的关系
    表空间用于定义数据库对象在物理存储设备上的位置,不特定于某个单独的数据库。数据库是数据库对象的物理集合,而schema则是数据库内部用于组织管理数据库对象的逻辑集合,schema名字空间之下则是各种应用程序会接触到的对象,比如表、索引、数据类型、函数、操作符等。角色(用户)则是......
  • Android:recyclerview无法显示分隔线
      由图,已创建分隔线,可在右侧无法显示。之后回想,这分隔线存在的位置  两个xml文件中,文件默认背景颜色为白色或透明,将背景颜色修改即可。以下仅修改linear的 再修改recycler的背景颜色,则白条更改颜色。 ......
  • Springboot web 项目开发流程梳理总结
    项目开发流程梳理总结1.环境准备1.准备数据库表(user,order);2.创建springboot工程,引入对应的起步依赖(web,mybatis,mybatisx,mysql驱动,lombok);3.配置文件application.properties中引入mybatis的配置信息,准备对应的实体类;4.准备对应的mapper,service(接口,实现类),controlle......
  • 关于Prompt Engineering你该了解啥?OpenAI应用研究负责人帮你梳理了
    随着ChatGPT、GPT-4等模型的兴起,人们对如何创建提示以获得想要的输出越来越感兴趣。研究者对特定提示的响应可能很难预测,并且会因模型的不同而不同。本文来自OpenAI的翁丽莲(LilianWeng)撰文介绍了关于提示的一些内容,包括基础提示、指令提示等内容。Prompt工程,也称为In-......
  • blendOS 2 已经问世,并支持开箱即用的Android应用程序
    导读当我第一次看到 blendOS 时,这个发行版承诺提供 Arch Linux、FedoraLinux和Ubuntu的混合体,但现在 blendOS2 已经发布了,并承诺更多,例如开箱即用的 Android 应用程序支持。blendOS2 内置的 Android 应用支持实现得益于 WayDroid 项目,这是一个基于容......
  • Android 线性布局平分宽度item的隐藏问题
    原文:Android线性布局平分宽度item的隐藏问题-Stars-One的杂货小窝一直只使用layout_weight来平分布局,但是如果隐藏了某个item,会导致其他item宽高有所变化于是询问了ChatGpt后,才是了解到LinearLayout的weightSum这个属性的使用需求一行有3个item平分线性布局,宽度都是......
  • 字节、百度、美团、腾讯技术面,面试题及答案分享(Android岗)
    字节(3轮技术面):一面:1.final2.类加载3.双亲委派机制,为什么要使用4.GC5.leackcanary6.hashmap7.concurrenthashmap8.事件分发9.handler算法:1.LeetCode61:旋转链表2.合并两个有序链表二面:1.final修饰int类型的变量能不能改变?怎么改变?2.反射可以改变这个int值吗?怎么改变?反射......
  • 【Android】我用 ARCore 做了一个 1:1 高达
    最近看到一个新闻,一个1:1的自由高达落户在上海金桥。作为高达爱好者的我一直想去现场感受一下高达真实的压迫感,无奈一直没机会去上海。不过这难不倒我,借助AR技术自己动手做了一个1:1的高达怎么样,这效果不比上海金桥的差吧~什么是AR(AugementedReality)AR(增强现实)是近几......
  • 腾讯技术团队最新出品,Android Framework系统框架底层原理解密
    今年以来,Android就业形势愈发严峻,各公司对开发人员的要求也是逐渐提高,在筛选Android程序员的时候也越来越看重其对于底层的理解和思考。作为一个AndroidAPP开发者,我们也不能当温水里的青蛙,必须对Android系统的组成和AndroidFramework的层次架构有所了解,才能突破和进阶。在这里就......
  • 爆火的2022版腾讯Android面试手册,最新最细致,终于拿到手了
    据腾讯HR部门6月8号发布的最新信息,2022年6月Android开发岗位数将同比增长21%,伴随应届生求职季的到来,想进腾讯的小伙伴竞争会异常激烈。面试的深度和难度将不断增加,很多想进腾讯的朋友都在问,如何准备才能顺利拿下offer?第一章Java基础静态内部类和非静态内部类的比较多态的理解与应......