07.显示系统:第006节_基础知识_Region定义及操作

上小节我们讲解了surfaceflinger对Vsync信号的处理,现在我们来回顾一下,在android系统中存在一个或者多个应用程序,每个程序有一个或者多个Layer。surfaceflinger在对Vsync信号进行处理的时候,会对每一个Layer更新他的数据,接下来他就把这些更新了数据的个个层与Layer合并起来,在显示设备上显示出来。

在讲解界面显示之前,我们先来补充一些基础知识,Region定义及操作。下面是一个示意图:
在这里插入图片描述

假如上图是我们的手机屏幕,Z轴代表图像的高度。假设运行了三个应用程序,在最前面的应用程序(APP1)的z轴最大,APP2在中间位置,APP3在最下面,很显然,我们眼睛看到的APP1,他可以全部都显示出来,APP2会被APP1,遮挡一部分,同样,APP3会被APP1与2遮挡一部分,也有可能完全看不见了。

一个界面其按照透光度,可以分为3个区域:1.opaque-完全不透明。2.transparent-全透明。3.translucent-半透明。
对于不透明的程序,其会遮盖后面的程序,对于全头面的程序,他不会 遮盖后面的程序,并且全透明的区域你可以不用去绘画他。对于半透明的程序,你需要绘画半透明区域,但是他不会遮盖后面的应用程序。

我们需要一个结构体表示这些区域,这个结构体我们称之为Region,假设一个手机界面,如下:
在这里插入图片描述
Region由一系列的矩形组成,并且
1.从上到下,从左到右依次排序,
2.各矩形的Y轴坐标,要么相同(对于Y轴坐标相同的矩形,x轴坐标不交叉), 或者无交叉。

我们引入一个概念,span(一组):一组Rect,Y轴一样,x坐标无交叉。
Region:由一组Y轴无交叉的span组成。

我们查看源代码,在Region.h中

class Region : public LightFlattenable<Region>
	Vector<Rect> mStorage;

Vector mStorage;这个向量中存放着一个一个的矩形。其最后一项表示边界,如果Region只有一个Rect,那么mStorage久只含有一项,即只有一个Rect。
如果Region有两个Rect,那么mStorage含有3个Rect,这意味着mStorage永远不会有2个Rect。

下面我们开始讲解对Region的操作。我们如图:
在这里插入图片描述
假设有两个Region,但是每个Region只有一个Rect,
Region r1(0,0,2,2)
Region r2(1,1,3,3)

1.andself操作,即r1.andself(r2)-》r1 and r2。为(1,1,2,2)
2.orself,r1.orslef。即Rect(0,0,2,1),Rect(0,1,3,2),Rect(1,2,3,3),

请详细解释下这段代码Rect<float> Framer::ComputeActiveCropRegion(int frame_number) { const float min_crop_size = 1.0f / options_.max_zoom_ratio; const float new_x_crop_size = std::clamp(region_of_interest_.width * options_.target_crop_to_roi_ratio, min_crop_size, 1.0f); const float new_y_crop_size = std::clamp(region_of_interest_.height * options_.target_crop_to_roi_ratio, min_crop_size, 1.0f); // We expand the raw crop region to match the desired output aspect ratio. const float target_aspect_ratio = static_cast<float>(options_.input_size.height) / static_cast<float>(options_.input_size.width) * static_cast<float>(options_.target_aspect_ratio_x) / static_cast<float>(options_.target_aspect_ratio_y); Rect<float> new_crop; if (new_x_crop_size <= new_y_crop_size * target_aspect_ratio) { new_crop.width = std::min(new_y_crop_size * target_aspect_ratio, 1.0f); new_crop.height = new_crop.width / target_aspect_ratio; } else { new_crop.height = std::min(new_x_crop_size / target_aspect_ratio, 1.0f); new_crop.width = new_crop.height * target_aspect_ratio; } const float roi_x_mid = region_of_interest_.left + (region_of_interest_.width / 2); const float roi_y_mid = region_of_interest_.top + (region_of_interest_.height / 2); new_crop.left = std::clamp(roi_x_mid - (new_crop.width / 2), 0.0f, 1.0f - new_crop.width); new_crop.top = std::clamp(roi_y_mid - (new_crop.height / 2), 0.0f, 1.0f - new_crop.height); const float normalized_crop_strength = std::powf(options_.crop_filter_strength, ElapsedTimeMs(timestamp_) / kUnitTimeSlice); active_crop_region_.left = IirFilter(active_crop_region_.left, new_crop.left, normalized_crop_strength); active_crop_region_.top = IirFilter(active_crop_region_.top, new_crop.top, normalized_crop_strength); active_crop_region_.width = IirFilter( active_crop_region_.width, new_crop.width, normalized_crop_strength); active_crop_region_.height = IirFilter( active_crop_region_.height, new_crop.height, normalized_crop_strength); timestamp_ = base::TimeTicks::Now(); if (VLOG_IS_ON(2)) { DVLOGFID(2, frame_number) << "region_of_interest=" << region_of_interest_; DVLOGFID(2, frame_number) << "new_crop_region=" << new_crop; DVLOGFID(2, frame_number) << "active_crop_region=" << active_crop_region_; } return active_crop_region_; }
最新发布
06-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

江南才尽,年少无知!

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值