Android 13 Layer数据结构

Layer::State

state的定义

State mDrawingState; 一个mDrawingState的变量
 
 
 struct State {
        Geometry active_legacy;
        Geometry requested_legacy;
        int32_t z;
        ui::LayerStack layerStack;

#endif
        uint32_t flags;
        uint8_t reserved[2];
        int32_t sequence; // changes when visible regions can change
        bool modified;
 
        // Crop is expressed in layer space coordinate.
        Rect crop;
        Rect requestedCrop;
 
        // the transparentRegion hint is a bit special, it's latched only
        // when we receive a buffer -- this is because it's "content"
        // dependent.
        Region activeTransparentRegion_legacy;
        Region requestedTransparentRegion_legacy;
 
        LayerMetadata metadata;
 
        // If non-null, a Surface this Surface's Z-order is interpreted relative to.
        wp<Layer> zOrderRelativeOf;
        bool isRelativeOf{false};
 
        // A list of surfaces whose Z-order is interpreted relative to ours.
        SortedVector<wp<Layer>> zOrderRelatives;
 
        half4 color;
        float cornerRadius;
        int backgroundBlurRadius;
 
        gui::WindowInfo inputInfo;
        wp<Layer> touchableRegionCrop;
 
        // dataspace is only used by BufferStateLayer and EffectLayer
        ui::Dataspace dataspace;
 
        // The fields below this point are only used by BufferStateLayer
        uint64_t frameNumber;
        uint32_t width;
        uint32_t height;
        ui::Transform transform;   //变换矩阵,表示layer的平移,旋转,缩放,反转
 
        uint32_t bufferTransform;
        bool transformToDisplayInverse;
 
        Region transparentRegionHint;
 
        std::shared_ptr<renderengine::ExternalTexture> buffer;
        client_cache_t clientCacheId;
        sp<Fence> acquireFence;
        std::shared_ptr<FenceTime> acquireFenceTime;
        HdrMetadata hdrMetadata;
        Region surfaceDamageRegion;
        int32_t api;
 
        sp<NativeHandle> sidebandStream;
        mat4 colorTransform;
        bool hasColorTransform;
 
        // pointer to background color layer that, if set, appears below the buffer state layer
        // and the buffer state layer's children.  Z order will be set to
        // INT_MIN
        sp<Layer> bgColorLayer;
 
        // The deque of callback handles for this frame. The back of the deque contains the most
        // recent callback handle.
        std::deque<sp<CallbackHandle>> callbackHandles;
        bool colorSpaceAgnostic;
        nsecs_t desiredPresentTime = 0;
        bool isAutoTimestamp = true;
 
        // Length of the cast shadow. If the radius is > 0, a shadow of length shadowRadius will
        // be rendered around the layer.
        float shadowRadius;
 
        // Layer regions that are made of custom materials, like frosted glass
        std::vector<BlurRegion> blurRegions;
 
        // Priority of the layer assigned by Window Manager.
        int32_t frameRateSelectionPriority;
 
        FrameRate frameRate;
 
        // The combined frame rate of parents / children of this layer
        FrameRate frameRateForLayerTree;
 
        // 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. ui::Transform::ROT_INVALID means the
        // a fixed transform hint is not set.
        ui::Transform::RotationFlags fixedTransformHint;
 
        // The vsync info that was used to start the transaction
        FrameTimelineInfo frameTimelineInfo;
 
        // When the transaction was posted
        nsecs_t postTime;
 
        sp<ITransactionCompletedListener> releaseBufferListener;
        // SurfaceFrame that tracks the timeline of Transactions that contain a Buffer. Only one
        // such SurfaceFrame exists because only one buffer can be presented on the layer per vsync.
        // If multiple buffers are queued, the prior ones will be dropped, along with the
        // SurfaceFrame that's tracking them.
        std::shared_ptr<frametimeline::SurfaceFrame> bufferSurfaceFrameTX;
        // A map of token(frametimelineVsyncId) to the SurfaceFrame that's tracking a transaction
        // that contains the token. Only one SurfaceFrame exisits for transactions that share the
        // same token, unless they are presented in different vsyncs.
        std::unordered_map<int64_t, std::shared_ptr<frametimeline::SurfaceFrame>>
                bufferlessSurfaceFramesTX;
        // An arbitrary threshold for the number of BufferlessSurfaceFrames in the state. Used to
        // trigger a warning if the number of SurfaceFrames crosses the threshold.
        static constexpr uint32_t kStateSurfaceFramesThreshold = 25;
 
        // Stretch effect to apply to this layer
        StretchEffect stretchEffect;
 
        // Whether or not this layer is a trusted overlay for input
        bool isTrustedOverlay;
 
        Rect bufferCrop;
        Rect destinationFrame;
 
        sp<IBinder> releaseBufferEndpoint;
 
        gui::DropInputMode dropInputMode;
 
        bool autoRefresh = false;
 
        bool dimmingEnabled = true;
    };
mDrawingState的值通过如下的函数设置
bool Layer::setSize(uint32_t w, uint32_t h) {
    if (mDrawingState.requested_legacy.w == w && mDrawingState.requested_legacy.h == h)
        return false;
 
    if (!MiSurfaceFlingerStub::validateLayerSize(w, h)) {
         return false;
    }
 
    mDrawingState.requested_legacy.w = w;
    mDrawingState.requested_legacy.h = h;
    mDrawingState.modified = true;
    setTransactionFlags(eTransactionNeeded);
 
    // record the new size, from this point on, when the client request
    // a buffer, it'll get the new size.
    setDefaultBufferSize(mDrawingState.requested_legacy.w, mDrawingState.requested_legacy.h);
    return true;
}
 
bool Layer::setAlpha(float alpha) {
    MiSurfaceFlingerStub::getHBMLayerAlpha(this, alpha);
    if (mDrawingState.color.a == alpha) return false;
    mDrawingState.sequence++;
    mDrawingState.color.a = alpha;
    mDrawingState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
}
bool Layer::setBackgroundColor(const half3& color, float alpha, ui::Dataspace dataspace) {
    if (!mDrawingState.bgColorLayer && alpha == 0) {
        return false;
    }
    mDrawingState.sequence++;
    mDrawingState.modified = true;
    setTransactionFlags(eTransactionNeeded);
 
    if (!mDrawingState.bgColorLayer && alpha != 0) {
        // create background color layer if one does not yet exist
        uint32_t flags = ISurfaceComposerClient::eFXSurfaceEffect;
        std::string name = mName + "BackgroundColorLayer";
        mDrawingState.bgColorLayer = mFlinger->getFactory().createEffectLayer(
                LayerCreationArgs(mFlinger.get(), nullptr, std::move(name), flags,
                                  LayerMetadata()));
 
        // add to child list
        addChild(mDrawingState.bgColorLayer);
        mFlinger->mLayersAdded = true;
        // set up SF to handle added color layer
        if (isRemovedFromCurrentState()) {
            mDrawingState.bgColorLayer->onRemovedFromCurrentState();
        }
        mFlinger->setTransactionFlags(eTransactionNeeded);
    } else if (mDrawingState.bgColorLayer && alpha == 0) {
        mDrawingState.bgColorLayer->reparent(nullptr);
        mDrawingState.bgColorLayer = nullptr;
        return true;
    }
 
    mDrawingState.bgColorLayer->setColor(color);
    mDrawingState.bgColorLayer->setLayer(std::numeric_limits<int32_t>::min());
    mDrawingState.bgColorLayer->setAlpha(alpha);
    mDrawingState.bgColorLayer->setDataspace(dataspace);
 
    return true;
}
 
bool Layer::setCornerRadius(float cornerRadius) {
    if (mDrawingState.cornerRadius == cornerRadius) return false;
 
    mDrawingState.sequence++;
    mDrawingState.cornerRadius = cornerRadius;
    mDrawingState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
}
 
bool Layer::setBackgroundBlurRadius(int backgroundBlurRadius) {
    if (mDrawingState.backgroundBlurRadius == backgroundBlurRadius) return false;
    // If we start or stop drawing blur then the layer's visibility state may change so increment
    // the magic sequence number.
    if (mDrawingState.backgroundBlurRadius == 0 || backgroundBlurRadius == 0) {
        mDrawingState.sequence++;
    }
    mDrawingState.backgroundBlurRadius = backgroundBlurRadius;
    mDrawingState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
}
bool Layer::setMatrix(const layer_state_t::matrix22_t& matrix) {
    ui::Transform t;
    t.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
 
    mDrawingState.sequence++;
    mDrawingState.transform.set(matrix.dsdx, matrix.dtdy, matrix.dtdx, matrix.dsdy);
    mDrawingState.modified = true;
 
    setTransactionFlags(eTransactionNeeded);
    return true;
}
bool Layer::setTransparentRegionHint(const Region& transparent) {
    mDrawingState.requestedTransparentRegion_legacy = transparent;
    mDrawingState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
}
 
bool Layer::setBlurRegions(const std::vector<BlurRegion>& blurRegions) {
    // If we start or stop drawing blur then the layer's visibility state may change so increment
    // the magic sequence number.
    if (mDrawingState.blurRegions.size() == 0 || blurRegions.size() == 0) {
        mDrawingState.sequence++;
    }
    mDrawingState.blurRegions = blurRegions;
    mDrawingState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
}
 
bool Layer::setFlags(uint32_t flags, uint32_t mask) {
    const uint32_t newFlags = (mDrawingState.flags & ~mask) | (flags & mask);
    if (mDrawingState.flags == newFlags) return false;
    mDrawingState.sequence++;
    mDrawingState.flags = newFlags;
    mDrawingState.modified = true;
#if MI_SCREEN_PROJECTION
        MiSurfaceFlingerStub::setChildImeFlags(flags, mask,this);
#endif
 
    setTransactionFlags(eTransactionNeeded);
    return true;
}
 
bool Layer::setCrop(const Rect& crop) {
    if (mDrawingState.requestedCrop == crop) return false;
    mDrawingState.sequence++;
    mDrawingState.requestedCrop = crop;
    mDrawingState.crop = crop;
 
    mDrawingState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
}
bool Layer::setMetadata(const LayerMetadata& data) {
    if (!mDrawingState.metadata.merge(data, true /* eraseEmpty */)) return false;
    mDrawingState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
}
 
bool Layer::setLayerStack(ui::LayerStack layerStack) {
    if (mDrawingState.layerStack == layerStack) return false;
    mDrawingState.sequence++;
    mDrawingState.layerStack = layerStack;
    mDrawingState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
}
 
bool Layer::setColorSpaceAgnostic(const bool agnostic) {
    if (mDrawingState.colorSpaceAgnostic == agnostic) {
        return false;
    }
    mDrawingState.sequence++;
    mDrawingState.colorSpaceAgnostic = agnostic;
    mDrawingState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
}
 
bool Layer::setDimmingEnabled(const bool dimmingEnabled) {
    if (mDrawingState.dimmingEnabled == dimmingEnabled) return false;
 
    mDrawingState.sequence++;
    mDrawingState.dimmingEnabled = dimmingEnabled;
    mDrawingState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
}
 
bool Layer::setFrameRateSelectionPriority(int32_t priority) {
    if (mDrawingState.frameRateSelectionPriority == priority) return false;
    mDrawingState.frameRateSelectionPriority = priority;
    mDrawingState.sequence++;
    mDrawingState.modified = true;
    setTransactionFlags(eTransactionNeeded);
    return true;
}

 

Layer::Geometry

struct Geometry {
    uint32_t w; //size的宽高
    uint32_t h;
    ui::Transform transform;
 
    inline bool operator==(const Geometry& rhs) const {
        return (w == rhs.w && h == rhs.h) && (transform.tx() == rhs.transform.tx()) &&
                (transform.ty() == rhs.transform.ty());
    }
    inline bool operator!=(const Geometry& rhs) const { return !operator==(rhs); }
};

Layer Transform

frameworks/native/include/ui/Transform.h

frameworks/native/include/ui/Transform.cpp

成员变量:
Mmatrix: mat33类型,就是一个3X3矩阵
mType: uint32_t类型,最低位为1表示需要translate(还有其他位表示ROT_90…)

成员函数:
transform(): 执行变换的函数

mat33矩阵

// dsdx dtdy 0   
// dtdx dsdy 0
// tx   ty  1 

意义如下:
// dsdx(x的缩放)      dtdy               0 
// dtdx              dsdy(y的缩放)       0
// tx(x的位置偏移)    ty (y的位置偏移)   1 



// scalX      skewY      0 
// skewX      scalY      0
// translateX translateY 1 

右边的矩阵是mat33,每个变量的分别表示:
scaleX: x轴的缩放因子
skewX: x轴的斜交因子(错切因子)
translateX: x轴的平移向量
scaleY: y轴的缩放因子
skewY: y轴的斜交因子
translateX: y轴的平移向量
最后一列: 3D效果,透视变换
 

Transform.mat33 的值由position和 matrix组成,由Layer 中的setMatirx和setPosition赋值

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/572784.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

解决Oracle锁表的方法

在实际工作中&#xff0c;并发量比较大的项目&#xff0c;经常会出现锁表的问题&#xff0c;下面我将复现这个问题&#xff0c;并给出解决方法。 一、问题复现 1、session1修改aabb表的B字段为迪迦奥特曼&#xff0c;但是不提交该事务。 2、session2也修改这行的这个字段。 发…

基于Springboot的网上商城购物系统

基于SpringbootVue的网上商城购物系统的设计与实现 开发语言&#xff1a;Java数据库&#xff1a;MySQL技术&#xff1a;SpringbootMybatis工具&#xff1a;IDEA、Maven、Navicat 系统展示 用户登录 首页 商品信息 商品资讯 后台登录页面 后台管理首页 用户管理 商品分类管…

SVG 绘制微信订阅号icon

效果 代码 <!DOCTYPE html> <html> <body><svg xmlns"http://www.w3.org/2000/svg" version"1.1" width"600" height"600"><rect x"0" y"0" rx"0" ry"0" width&…

【C++】5.C语言/C++内存管理

一、C/C内存分布 栈中存储的是局部变量&#xff0c;函数参数&#xff0c;返回值等 堆主要用于动态内存分配 数据段用以存储全局数据和静态数据 代码段存储可执行代码和常量 二、C语言和C中的内存管理方式 在C语言中&#xff0c;我们使用 malloc、calloc、realloc、free来进…

AI-数学-高中-43常见函数的导数

原作者视频&#xff1a;【导数】【一数辞典】2常见函数的导数_哔哩哔哩_bilibili

【C++】——类和对象(构造函数,析构函数,拷贝构造函数,赋值运算符重载)

创作不易&#xff0c;多多支持&#xff01; 前言 相信你对这几个知识点有点混淆&#xff0c;相信看完以后&#xff0c;你会对此有一个清晰的认识。 一 类的6个默认成员函数 如果我们写一个类&#xff0c;但是类里面什么都没有&#xff0c;我们称之为空类。 其实这个类也不…

AWS SES发送邮件如何正确配置?操作指南?

AWS SES发送邮件有哪些限制&#xff1f;AWS SES发信的注意事项&#xff1f; AWS SES作为亚马逊云服务提供的一项高效、可靠的电子邮件发送服务&#xff0c;受到了众多企业的青睐。然而&#xff0c;如何正确配置AWS SES发送邮件。AokSend将详细解析AWS SES发送邮件的配置过程&a…

《苍穹外卖》Day07部分知识点记录

一、菜品缓存 减少查询数据库的次数&#xff0c;优化性能 客户端&#xff1a; package com.sky.controller.user;import com.sky.constant.StatusConstant; import com.sky.entity.Dish; import com.sky.result.Result; import com.sky.service.DishService; import com.sky…

搜维尔科技:如何选择最佳的xsens动作捕捉设备

xsens介绍 如何选择最佳的xsens动作捕捉设备 选择最佳的 Xsens 动作捕捉设置并不总是像我们希望的那样简单。根据每个人的情况&#xff0c;会有不同的选择、要求和挑战。 这就是我们创建此博客的原因&#xff1a;帮助您做出最适合您的决定。 您已经决定继续使用 Xsens 了吗…

电表抄表系统:现代能源管理的革新

1.界定和功能 电表抄表系统是一种前沿的自动化控制&#xff0c;用以远程控制搜集、解决与分析电表数据。它取代了传统的人工抄水表方法&#xff0c;提高了效率&#xff0c;降低了不正确&#xff0c;并且为供电公司带来了实时能源消耗信息。系统软件的主要作用包含全自动载入电…

大模型实战—通义千问大模型微调

通义千问大模型微调 在之前的文章中&#xff0c;我分享了一些使用大语言模型开发应用的方法&#xff0c;也介绍了几个开源大语言模型的部署方式&#xff0c; 有同学给我留言说想知道怎么训练自己的大语言模型&#xff0c;让它更贴合自己的业务场景。完整的大语言模型训练成本…

第十五届蓝桥杯省赛第二场PythonB组A题【进制】题解(AC)

解题思路 按照题意进行模拟&#xff0c;计算 x x x 的 b b b 进制过程中&#xff0c;若出现余数大于 9 9 9&#xff0c;则说明 x x x 的 b b b 进制一定要用字母进行表示。 x 8100178706957568def check(x, b):while x:if x % b > 10:return Falsex // breturn True…

Flink的安装、项目创建、任务打包和部署完整实现,任务实现使用JAVA语言

Flink资源下载地址 Flink安装包下载地址 一、本地模式安装Flink 1、在Linux服务上&#xff0c;创建flink文件夹 mkdir flink 2、上传文件并解压 tar -zxvf flink-1.14.6-bin-scala_2.11.tgz 解压完成后&#xff0c;如图&#xff1a; 3、启动Flink 进入到解压目录下&#x…

男士休闲裤比较好的品牌有哪些?高品质休闲男装推荐

穿衣服最重要的并不是要求多好看多时尚&#xff0c;相信绝大部分年纪在23岁以上的男同胞们更希望穿一些简约好搭配的款式&#xff0c;更重要的其实就是要求质量耐穿&#xff0c;以及有足够好的舒适性。 但是现在市面上的品牌实在是太多了&#xff0c;而且质量也参差不齐&#x…

【保姆级讲解下gateway基本配置】

&#x1f3a5;博主&#xff1a;程序员不想YY啊 &#x1f4ab;CSDN优质创作者&#xff0c;CSDN实力新星&#xff0c;CSDN博客专家 &#x1f917;点赞&#x1f388;收藏⭐再看&#x1f4ab;养成习惯 ✨希望本文对您有所裨益&#xff0c;如有不足之处&#xff0c;欢迎在评论区提出…

pwn--realloc [CISCN 2019东南]PWN5

首先学习一下realloc这个函数&#xff0c;以下是文心一言的解释&#xff1a; realloc是C语言库函数之一&#xff0c;用于重新分配内存空间。它的主要功能是调整一块内存空间的大小。当需要增加内存空间时&#xff0c;realloc会分配一个新的更大的内存块&#xff0c;然后将原内…

QT从入门到实战x篇_22_番外1_Qt事件系统

文章目录 1. Qt事件系统简介1.1 事件的来源和传递1.2 事件循环和事件分发1.2.1 QT消息/事件循环机制1.2.1.1 机制解释1.2.1.2 两个问题 1.2.2 事件分发 2. 事件过滤基础2.1 什么是事件过滤器&#xff08;Event Filter&#xff09;&#xff1f;2.2 如何安装事件过滤器 3. 事件过…

《QT实用小工具·四十》显示帧率的控件

1、概述 源码放在文章末尾 该项目实现了可以显示帧率的控件&#xff0c;项目demo演示如下所示&#xff1a; 、 项目部分代码如下所示&#xff1a; #ifndef FPSITEM_H #define FPSITEM_H#include <QQuickItem>class FpsItem : public QQuickItem {Q_OBJECTQ_PROPERTY(i…

制作自己的YOLOv8数据集

制作自己的YOLO8数据集 前言 该数据集的格式参照于coco数据集结构✨ 步骤一&#xff1a;收集图像数据 从互联网上下载公开的数据集&#xff0c;也可以使用摄像头或其他设备自行采集图像&#xff0c;确保你的图像数据覆盖了你感兴趣的目标和场景 步骤二&#xff1a;安装Labe…

提升工作效率必备,桌面待办事项提醒软件

在快节奏的现代社会&#xff0c;提升工作效率成为众多上班族的共同追求。有效的时间管理、合理的工作计划和正确的工具选择&#xff0c;是实现高效工作的三大关键。尤其是选择一款优秀的待办事项管理软件&#xff0c;能够极大地助力我们提升工作效率。 而我在网上找到了一款提…
最新文章