Android 13 Layer数据结构

news2024/10/5 16:23:50

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.coloradmin.cn/o/1622336.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

opencv图片绘制图形-------c++

绘制图形 #include <opencv2/opencv.hpp> #include <opencv2/core.hpp> #include <filesystem>bool opencvTool::drawPolygon(std::string image_p, std::vector<cv::Point> points) {cv::Mat ima cv::imread(image_p.c_str()); // 读取图像&#xf…

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. 事件过…

深入探讨回流焊技术:电子制造业的核心工艺

在现代电子制造领域&#xff0c;回流焊技术被广泛认为是实现高效率和高质量电子组件装配的关键工艺之一。本文将针对回流焊的基本原理、设备构成、过程细节以及过程优化进行全面解析&#xff0c;为电子制造业的技术人员提供实用的参考和指导。 1. 回流焊基本原理解析 回流焊主…

【Redis 开发】(长篇学习)掌握Redis的用法,各种客户端下的操作

Redis 前言RedisRedis的安装Redis启动Redis客户端 Redis常见命令Redis的java客户端jedis学习简单的jedis 入门流程Jedis连接池 SpringDataRedisSpringDataRedis快速入门 前言 我们在作者之前的文章: 快速掌握Redis安装与基本语法的基础上进行系统的学习&#xff0c;学习自黑马…

Pytorch 之torch.nn初探 池化--Pooling Layers

任务描述 本关任务&#xff1a;本关提供了一个Variable 类型的变量x&#xff0c;要求按照条件创建一个Conv2d变量conv&#xff0c;一个MaxPool2d变量pool&#xff0c;对x应用卷积和最大池化操作并赋值给变量outpout_pool&#xff0c;并输出outpout_pool 的大小。 相关知识 P…

k8s日常动手实践 ~~ pod访问 pod请求 k8s api ~ 含新版带curl的busybox镜像

前言&#xff1a; 可以使用 Kubernetes API 获取集群信息。使用 Service Account&#xff08;SA&#xff09;进行身份验证&#xff0c;可以以安全的方式访问 Kubernetes API&#xff0c;而无需在 Pod 中使用明文凭据。 以下是一个使用 Service Account 访问 Kubernetes API 获…

XV6源码阅读——进程地址空间

文章目录 前言页表实际情况 前言 一个本硕双非的小菜鸡&#xff0c;备战24年秋招。打算尝试6.S081&#xff0c;将它的Lab逐一实现&#xff0c;并记录期间心酸历程。 代码下载 官方网站&#xff1a;6.S081官方网站 页表 每个进程都有一个单独的页表&#xff0c;当xv6在进程之…

数据库变更时,OceanBase如何自动生成回滚 SQL

背景 在开发中&#xff0c;数据的变更与维护工作一般较频繁。当我们执行数据库的DML操作时&#xff0c;必须谨慎考虑变更对数据可能产生的后果&#xff0c;以及变更是否能够顺利执行。若出现意外数据丢失、操作失误或语法错误等情况&#xff0c;我们必须迅速将数据库恢复到变更…

2024王鹍申论重难点:材料的概括与处理

2024王鹍申论重难点&#xff1a;材料的概括与处理&#xff0c;是备考公务员申论考试的关键一环。王鹍老师以其深厚的理论功底和丰富的实践经验&#xff0c;深入剖析了申论材料的特点和概括方法&#xff0c;同时传授了有效的材料处理技巧。通过王鹍老师的讲解&#xff0c;考生们…

Winseeing汇信外贸软件行业版,助力面辅料外贸公司实现降本增效

面辅料外贸出口&#xff0c;一直是国民经济发展中的重要组成部分。在当前全球贸易环境动荡不安的背景下&#xff0c;面辅料外贸出口面临着诸多挑战和机遇。亚洲是我面料出口的主要市场&#xff0c;据海关数据统计显示&#xff0c;2024年1-2月我对亚洲国家累计出口面料69.3亿美元…

leetcode多个测试用例之间相互影响导致提交失败

背景 在做一道easy题&#xff0c;二叉树的中序遍历&#xff0c;我提交的代码如下 from typing import (Optional,List )# Definition for a binary tree node. class TreeNode:def __init__(self, val0, leftNone, rightNone):self.val valself.left leftself.right right…

利用FCL实现更加精准的碰撞检测

一&#xff0c;需求 利用OSG结合FCL实现实现精准的碰撞检测。 二&#xff0c;效果 看这里 利用FCL实现更加精准的碰撞检测 – Qt hello 三&#xff0c;分析 我们看如下这张图&#xff0c;碰撞的逻辑就是&#xff0c;在一个三维场景中&#xff0c;构造一个实体&#xff0c;…

机器学习笔记(二)回归

一、线性回归 线性回归是一种用于预测的统计方法&#xff0c;特别适用于连续值预测。&#x1f4c8;线性回归通过最小化误差的平方和来寻找一个线性关系&#xff0c;用于预测一个变量&#xff08;因变量&#xff09;基于一个或多个其他变量&#xff08;自变量&#xff09;的值。…

远程控制安卓手机:便捷、高效与安全的方法

在移动设备的领域里&#xff0c;远程控制安卓手机的能力也变得越来越重要。这种技术可以让我们在远程地点方便地操作手机&#xff0c;无论是处理紧急事务、帮助他人解决问题&#xff0c;还是仅仅为了享受科技带来的便利。本文将为你介绍2种便捷、高效且安全的方法&#xff0c;让…

笔试狂刷--Day6(岛屿数量+模拟)

大家好,我是LvZi,今天带来笔试狂刷--Day6 一.在字符串中找出连续最⻓的数字串 1.题目链接 在字符串中找出连续最⻓的数字串 2.题目分析 使用双指针模拟 3.代码实现 import java.util.Scanner; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main {p…

Linux的学习之路:20、进程信号(2)

摘要 本章讲一下进程信号的阻塞信号和捕捉信号和可重入函数 目录 摘要 一、阻塞信号 1、阻塞信号 2、信号集操作函数 二、捕捉信号 1、内核如何实现信号的捕捉 2、代码实演 三、可重入函数 一、阻塞信号 1、阻塞信号 实际执行信号的处理动作称为信号递达(Delivery) …

文末送资料 | AI大模型接入指南:免费畅聊公众号新时代!附搭建教程

目录 今天内容有点意思&#xff01; 福利&#xff1a;拉到最后&#xff0c;免费送资料&#xff0c;你想要的全都有 我把公号接入了&#xff0c;字节跳动的云雀AI大模型&#xff01; 先给大家看几个案例 重点来了 如何将公号接入AI大模型呢&#xff1f; 1、创建AI聊天机器…

海南封关怎么看?win战略会任志雄解析

今年海南自由贸易港建设也进入了新阶段:将在2025年年底前适时启动全岛封关运作,封关后的海南将以全新姿态迎接更广泛的发展机遇。 封关在即,企业有何感受?还有哪些准备工作?封关后的海南将呈现怎样的状态?近日,红星资本局记者深入实地了解海南自贸港如何成型起势。 利好当…

快手不发作品ip地址会变吗

在数字时代&#xff0c;我们每个人的在线行为都留下了独特的痕迹。这些痕迹不仅仅是我们的言论或行为&#xff0c;还包括我们的IP地址——一个在网络世界中标识我们位置的数字标签。近年来&#xff0c;随着短视频平台的兴起&#xff0c;如快手这样的应用已经深入人们的日常生活…

sentinel-1.8.7与nacos-2.3.0实现动态规则配置、双向同步

&#x1f60a; 作者&#xff1a; 一恍过去 &#x1f496; 主页&#xff1a; https://blog.csdn.net/zhuocailing3390 &#x1f38a; 社区&#xff1a; Java技术栈交流 &#x1f389; 主题&#xff1a; sentinel-1.8.7与nacos-2.3.0实现动态规则配置、双向同步 ⏱️ 创作时…