重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

flutter好处,Flutter缺点

一种更优雅的Flutter Dialog解决方案

系统自带的Dialog实际上就是Push了一个新页面,这样存在很多好处,但是也存在一些很难解决的问题

成都创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于网站制作、做网站、平乡网络推广、成都微信小程序、平乡网络营销、平乡企业策划、平乡品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;成都创新互联公司为所有大学生创业者提供平乡建站搭建服务,24小时服务热线:028-86922220,官方网址:www.cdcxhl.com

上面这些痛点,简直个个致命 ,当然,还存在一些其它的解决方案,例如:

很明显,使用Overlay可移植性最好,目前很多toast和dialog三方库便是使用该方案,使用了一些loading库,看了其中源码,穿透背景解决方案,和预期想要的效果大相径庭、一些dialog库自带toast显示,但是toast显示却又不能和dialog共存(toast属于特殊的信息展示,理应能独立存在),导致我需要多依赖一个Toast库

基于上面那些难以解决的问题,只能自己去实现,花了一些时间,实现了一个Pub包,基本该解决的痛点都已解决了,用于实际业务没什么问题

使用 FlutterSmartDialog 包裹下child即可,下面就可以愉快的使用SmartDialog了

使用Overlay的依赖库,基本都存在一个问题,难以对返回事件的监听,导致触犯返回事件难以关闭弹窗布局之类,想了很多办法,没办法在依赖库中解决该问题,此处提供一个 BaseScaffold ,在每个页面使用 BaseScaffold ,便能解决返回事件关闭Dialog问题

当时想解决穿透暗色背景,和背景后面的控件互动的时候,我几乎立马想到这俩个控件,先了解下这俩个控件吧

分析

这种方案,成功实现想要的穿透效果,这里了解下 behavior 的几种属性

有戏了!很明显translucent是有希望的,尝试了几次,然后成功实现了想要的效果

注意,这边有几个坑点,提一下

下面是写的一个验证小示例

这个库花了一些时间去构思和实现,算是解决几个很大的痛点

FlutterSmartDialog一些信息

状态管理

高三英语作文

在平平淡淡的日常中,大家都不可避免地要接触到作文吧,作文是人们以书面形式表情达意的言语活动。如何写一篇有思想、有文采的作文呢?下面是我整理的高三英语作文10篇,欢迎阅读与收藏。

高三英语作文 篇1

Plan For Wnter Holiday

I’m looking forward to the coming of my winter holiday. In order to have a good time in the vacation, I have made a plan for it. At first, my mother must ask me to do homework. If I don’t follow her words, I wouldn’t have peace in the following days until I finish my homework. So the first thing I will do in the winter holiday is to finish my homework. And then I will take full use of my time to go out play with my friends, because I will have to help my mother to prepare for the Spring Festival when it’s in the corner. Three days before Spring Festival, I will go to my grandmother’s home for a visit with my parents. After the Spring Festival I am going to travel with my family. As for where to go, I don’t have any plan now. Maybe we will go to Harbin to the snow. Being the southern local person, I have never seen snow and eager to see it once. After the trip, I think I have to go back to school. This is my plan for the coming winter vacation. What’s yours?

寒假计划

我期待寒假的到来。为了过一个愉快的假期,我制定了一个寒假计划。首先,我的妈妈肯定会叫我去写作业的。如果我不听她的话,在接下来的日子里我就不会过得安宁,除非我完成了作业。所以寒假里我要做的第一件事就是完成我的作业。然后我会充分利用我的时间去和我的朋友玩,因为在春节即将到来的时候我要帮我妈妈准备春节的事情。春节前三天,我会和爸爸妈妈去外婆家。春节后我打算与我的家人去旅行。至于去哪里,我还没有计划。也许为了看雪我们会去哈尔滨。作为南方本地人,我从未见过雪,很希望能看一次。旅行之后,我想我也该准备回学校了。这是我即将到来的假期计划。你的是什么呢?

高三英语作文 篇2

Notice

In order to make our school life colorful and improve our English skills, we’re going to hold an English Play Show at 8:00 p.m. this Saturday, April 10th. in the meeting room, No.2 Teaching building, At the English Play Show, we can not only enjoy other’s plays and speeches, but also sing songs and play games. What’s more, our foreign teacher Mike will give a talk about how to improve oral English. I hope anyone who comes here will have a great time. If you’d like to come , please sign your name at the Students’ Union, Room 203, Office building.

为了使我们的学校生活更加的丰富多彩,提高我们的英语水平,我们要在四月十日本星期六下午八点在会议室2号教学楼举行英语戏剧表演。在英语戏剧表演中我们不仅可以欣赏其他的戏剧和演讲,还可以唱歌,玩游戏。更重要的是,我们的外教迈克会给我们做一个关于如何提高英语口语的讨论。我希望来的人都能玩得开心。如果你愿意来,请在学生会,办公楼203室签名。

April 7th, 20xx

Students’ Union

高三英语作文 篇3

The first fall of snow is not only an event but it is a magical event. You go to bed in one kind of world and wake up to find yourself in another quite different, and if this is not enchantment, then where is it to be found?

The very stealth, the eerie quietness, of the thing makes it more magical. Ifall the snow fell at once in one shattering crash, awakening us in the middle of the night the event would be robbed of its wonder. But it flutters down, soundless, hour after hour while we are asleep. Outside the closed curtains of the bedroom a vast transfbrmation scene is takiag place, just as if a myriad elves and brownies were at work, and we turn and yawn and stretch and know nothing about it. And then, what an extraordinary change it is! It is as if the house continent. Even the inside, which has not been touched, seems different, every room appearing smaller and cosier, just as if some power were trying to turn it into a woodcutter’s hut or a snug logcabin. Outside, where the garden was yesterday, there is now a white and glistening level, and the village beyond is no longer your own familiar cluster of roofs but a village in an old German fairy-tale.

You would not be surprised to learn that all the people there, the speetacled postmistress, the cobbler, the retired school master, and the rest, had suffered a change too and had become queer elvish beings, purveyors of invisible caps and magic shoes. You yourselves do not feel quite the same people you were yesterday. How could you not when so much has been changed? There is a curious stir, a little shiver of excite-ment, troubling the house, not unlike the feeling there is abroad when a journey has to be made. The children, of course, are all excitement but even the adults hang about and talk to one another longer than usual before setting down to the day’s work. Nobody can resist the windows. It is like being on board a ship.

高三英语作文 篇4

If the most beautiful season of the year is spring, for me, the most interesting festival of the year is the new year's Eve! On that day, we should not only eat family reunion dinner, but also staying-up late on new year's eve.

Remember that the day to eat reunion dinner, people began to play cards, chat, play mahjong, our children, began playing the fun of firecrackers, there are all kinds of varieties, "this" and "Scud", "delta ray" and so on, we played awfully.

I also went to the house to see from time to time and funny TV comic sketch "Spring Festival Gala" performance, I and my buddy will laugh and laugh, see magic in those big magician performing magic show, we were amazed.

Time flies, blink of an eye to 11:45, suddenly rang out a loud bursts of firecrackers, we are excited to join them, just open the door, I saw the fireworks are riotous with colour dark sky dancers.

At 11:50, we can't wait to just wrapped dumplings into the boiling water, mom and dad put a cover on the pot, cook for a while, 12 o'clock, finally boil the dumplings, grandma and grandpa a sung, I smell from afar dumplings fragrance, went straight to the kitchen, when the taste delicious dumplings, happy in the heart.

One year spent similar, each year is different, when the new year's Eve, it means spring is coming, the new year has begun!!!

高三英语作文 篇5

保护树木Protect the TreesEach year, people burn or cut down 143,000 square kilometers (55,000 square miles) of the forest. People who burn or cut down trees do it for different reasons: farmers cut down trees in order to get more fertilize lands to grow rice or vegetables, and use the woods as fuel. Timber companies cut down trees and turn them into furniture or paper productions. As to goal miners, they remove the forests to find out whether there are goal underground.每一年,人们都会砍伐14.3万平方千米的森林(约5.5万平方英里)。人们砍伐树木出于种种原因:农民们为了得到更肥沃的空地来种植大米蔬菜,砍下的树木用来取火。木材公司用树木来制作家具或是各类纸制品。至于那些开采煤矿的人,把树木砍掉就是为了检测是否有煤矿在下面。

However, many of us fail to realize that forests are the lungs of the earth. When we cut down trees, we also push ourselves in to a dangerous situation. That is the global warming. When you come to think about it, there are only few ways to solve these negative effects: stop cutting down trees blindly; try to find some clear energy that can replace oil and coal. But these solutions can be impractical to some degreed.然而,我们中的许多人都没有意识到树木等同于地球的“肺部”。当我们砍伐树木时,我们就把自己推入一个危险的境地——会引起全球气候变暖。想到这些,只有为数不多的几个办法可以解决这个问题:停止盲目地砍伐树木;寻找可以代替石油和煤矿的新能源。但是,就目前来看,这几个策略并不可行。

Why trees can be so important to the whole nature? First of all, trees are the habitat of many animals. When we cut down trees, we not only destroy animals’ habitats but also ourselves. We just gradually destroy natural links. The result is that many spices of animals and plants are dying out. Secondly, cutting down trees cause global warming, to some degree. Naturalists compare forest to human’s lungs. The forests absorb the carbon dioxide and other gas that cause global warming, and then give off the oxygen that good for the human beings and other living creatures. It’s refreshed the air as well as reduced the noise. If the air quality is bad, people may die from cancers, or the new diseases for which they have no immunity. Forests also play an important role in the prevention of natural disasters. Warmer temperatures cause water to expand and also create more water by melting polar ice caps. That’s to say, the nations which near the ocean may have been flooded by the water. But the forests can prevent water loss and soil erosion, and cool off the global temperatures. It’s the key to keep the balance of the nature.为什么树木对整个生态环境都如此重要呢?首先,树木是小动物们的家园。当我们砍伐树木时,我们不仅仅毁掉了它们的家,也毁掉了自己的。一步步的,我们慢慢分解了整个生态链,所造成的结果就是大批的动植物种类灭绝。其二,砍伐树木在某种程度上造成全球变暖。生态学家把森林比作人类的肺。森林能够吸收二氧化碳和其他引起气候变暖的温室气体,然后转化成氧气供地球上的生物呼吸。树木不仅能净化空气,也能减少噪音。如果空气质量下降,那么人们就有可能死于肺癌,或者是其他致命菌。森林在预防疾病的过程中起到了重要的角色。气温的上升导致北极的冰层融化,水平面上升。也就是说,临海的城市也许会被海水淹没。但是森林就能够阻止水土流失,使气温下降。它是保证全球生态平衡的关键。

Sometimes people only care about money making; they don’t care about the price we pay for the pollution. When the disaster is around the corner, we may be afraid and frustrated. The earth, on which our economies have always been based, is suddenly threatening our existence. All we hope that is this overpopulated, over industrialized planet can carry on for a longer time. And maybe, it’s time for us to realize that we should protect the earth, stop cutting down trees blindly and madly.有时候人们只关心挣钱,却对我们所付出的代价不管不问。当灾难来临时,我们会害怕、会彷徨。我们赖以生存的地球,却突然变成了威胁我们生命的东西。我们只希望,在这个人口过度、工业过度的星球能继续撑下去。也许,是时候我们应该保护地球,停止盲目疯狂地砍伐树木了。

高三英语作文 篇6

My View on Hobby

Everybody has his own hobby. Hobbies not only make our life colorful, but also bring us lots of benefits. Hobbies help us to relax after a long period of hard work, and offer various activities for the people who are retiring. As to my mother, her hobby is to go square dancing after supper. She said, square dancing can make her forget her own problems and stay in good health. As to my father, his hobby is watching football games on TV. Among all my hobbies, the favorite one is reading. When I was a little girl, I love reading comic books. When I m getting old, I love fiction very much. I have so much fun from reading them. My favorite fiction is Pride and Prejudice. It not only provides knowledge, but also teaches us the right attitude toward life. I think reading makes my life complete. I will keep on reading. That s my favorite hobby.

兴趣爱好之我见

每个人都有自己的兴趣爱好。爱好不仅让我们的生活变得丰富多彩,也给予了我们诸多好处。爱好有助于我们在长时间的工作后得到放松,还为退休的人们提供各种各样的活动。就我妈妈来说,她最大的兴趣爱好就是晚饭之后去跳广场舞。她说,广场舞让她忘记了自己的烦恼,保持身体健康。至于我爸爸,他最喜欢看足球比赛。就我自己来说,在我所以的爱好里面,我最喜欢的就是阅读小说。当我还是个小女孩的时候,我很喜欢看动漫。长大一点的`时候,我爱上了小说。看小说充满了乐趣。我最喜爱的小说是《傲慢与偏见》。它不仅教给了我很多知识,也让我对人生有了个正确的态度。阅读使我的生活变得完整,我会一直读下去,因为这是我的爱好所在。

高三英语作文 篇7

日记:高三学习十分紧张,所以班长建议本周去郊外放松一下,享受秋天的美景。请你在今天的日记里发表对班长建议的想法。

October 12, 20xx, Monday Fine

It is universally acknowledged that Senior Three is undoubtedly a critical phase of life. The school life is extremely busy, so our monitor suggests that we have an outing to relax ourselves this weekend.

It is terrific! After a month s study, I feel we really need a break for one day, and so do some of my friends. Senior Three should not be filled with study only and relaxation is also an important part. Sometimes relaxation is more useful than an hour s hard work. While having an outing, we can relax ourselves and enjoy the beautiful scenery of autumn --- yellow leaves, attractive sunset against the blue sky and so on. Isn t it enjoyable? After the outing, I think all the students will have a better physical and mental state to meet the further challenges we may come across and cope with difficulties for ourselves.

高三英语作文 篇8

I like Christmas, it is just like our Spring Festival.

Maybe the Spring Festival is much more important and interesting than Christmas, but I like Christmas Day better. Because we can spend time with our friends and classmates during Christmas. When it is snowy,

Christmas becomes much more lovely, just like in fairytales. I can imagine I am in a fairytale, the girl who sold the matches is my friend, the ugly duck becoming more and more beautiful and so on. What a beautiful place! So we can also call Christmas “Snowy Lovely Day.”

On Christmas Day, shops are red and green. There are so many Christmas cards, Christmas hats, Christmas dolls and many colourful things. So shops look very beautiful. We can give a card or a doll to our friends and say “Merry Christmas.” By the way, I think studying can also become much more interesting.

Christmas is coming, it also means a new year will come. Let’s study harder to welcome

我喜欢圣诞节,它就像我们的春节。

也许春节比圣诞节更重要和有趣的,但我更喜欢圣诞节。因为我们可以花时间与我们的朋友和同学在圣诞节。当它下雪的,

圣诞节变得更加可爱,就像在童话。我可以想象我在童话中,卖火柴的女孩是我的朋友,丑鸭越来越漂亮等等。一个美丽的地方!我们也可以叫圣诞“雪可爱的一天。”

在圣诞节这一天,商店是红色和绿色。有很多圣诞卡,圣诞帽、圣诞娃娃和许多五颜六色的东西。所以商店看起来很漂亮。我们可以给我们的朋友和一个卡或一个娃娃说“圣诞快乐。“顺便说一下,我觉得学习也可以变得更有趣。

圣诞节即将来临,这也意味着新的一年。让我们更加努力地学习,欢迎

高三英语作文 篇9

你知道是什么在维系着我们的生命吗?是血液。血液一直被视为活力与健康之源,具有重要的生理意义。如今,越来越多的人愿意献血,而且还是无偿献血,它已经成为了爱的奉献。这不,一件件感人的事例正在涌上心头

你一定知道周杰伦,一定喜欢韩庚,但是,你知道王则谦吗?王则谦是一个普通的农民。每过三个月,他都会走上几十里的山路到县城,然后车到血液中心,为的是在这里捐献出一份机采血小板。11年了,无论刮风,下雨,还是农忙农闲,他一直默默坚持着。

王则谦啊王则谦,你让我们知道原来需要坚持的,并不一定是某一习惯或自己的梦想。我们还可以去献血。本着“无偿献血,拯救生命 ”的思想,让无数条生命可以重新看到生命的曙光,可以与我们生活在这美好的人间。

接下来,要跟大家介绍的是一位鲜血英雄。这位英雄,5年间无偿献血毫升。这是一个什么量呢?它相当于5个成年人全身的血液。而做出这个壮举的只是一位普通工人——郭青建。但遗憾的是这位英雄的生命因为一次车祸而戛然而止。直到这时,人们才知道,他把献血当成他毕生的荣耀。我注视着屏幕里这位英雄的遗像,以及他留下的14本献血证与3本全国献血荣誉证书,我的眼睛湿润了。在这里,让我们对英雄说,一路走好!

无偿献血者出于高尚的救死扶伤的目的去献血,是一种“人人为我,我为人人 ”的社会共济行为,是一种爱的奉献,是人道主义精神的重要体现。

实行无偿献血,有利于弘扬中华民族的传统美德,也是促进文明建设的一项重要举措。每一个健康公民都应积极参与。我想,等我成年了,我也要去献血呢!

Do you know what sustains our lives? It's blood. Blood has been regarded as the source of vitality and health, and has important physiological significance. Nowadays, more and more people are willing to donate blood, but also unpaid blood donation, it has become the dedication of love. No, a moving story is pouring in

You must know Jay Chou. You must like Han Geng, but do you know Wang Zeqian? Wang Zeqian is an ordinary farmer. Every three months, he would walk dozens of miles of mountain roads to the county seat, and then the car to the blood center, in order to donate a apheresis platelet here. For 11 years, regardless of wind and rain, busy or slack, he has been quietly persisted.

Wang Zeqian ah, Wang Zeqian, you let us know that the original need to adhere to, not necessarily a habit or own dream. We can also donate blood. In accordance with the idea of "donating blood without blood and saving lives", countless lives can see the dawn of life again, and can live with us in this wonderful world.

Next, I'd like to introduce you to a blood hero. The hero has donated blood for 5 years. What amount is this? It's equivalent to the blood of 5 adults. And the only one who made this feat was Guo Qingjian, an ordinary worker. But unfortunately, the hero's life ended abruptly because of a car accident. Until then, people knew that he had donated blood as his lifelong glory. I watched the hero portrait screen, and he left the 14 and the 3 national blood donation certificate certificate of honor, my eyes moist. Here, let's say to the hero, all the way!

Blood donors for the noble life-saving purpose to donate blood, is a kind of "all for me, I for social relief behavior all", is a kind of love, is an important manifestation of the humanitarian spirit.

The implementation of voluntary blood donation is conducive to carrying forward the traditional virtues of the Chinese nation, and is also an important measure to promote civilization construction. Every healthy citizen should take an active part in it. I think, when I'm adult, I'm going to donate blood!

高三英语作文 篇10

Thanks for your last letter. Don’t worry about my new school life here. I’m fine here because I like my new school life. My new school life is busy but interesting. Every day I get to school at 7:00 am and go home at 4:30 pm. We have four classes in the morning and three classes in the afternoon. My favorite day is Thursday, because I have English and art that day. The two subjects are my favorite. But I don’t like math, because it’s difficult. At school, I also have a new friend, Zhang Qiang. He often helps me with math. After school, I often have art club with him.

做混合的话Uniapp和Flutter我应该学哪个啊?

Uniapp目前比较成熟,而且用的是Vue语法,学习成本比较低,而且行业里面用的也比较广泛,而Flutter的话,学习成本略高,因为要学习新的语言,还有就是目前生态不是特别完备,等他再发展发展吧。黑马程序员官网有成套免费视频哦,有什么不懂的可以直接过去学习。您的采纳是对我成长的鞭策

Flutter浪潮下的音视频研发探索

文/陈炉军

整理/LiveVideoStack

大家好,我是阿里巴巴闲鱼事业部的陈炉军,本次分享的主题是Flutter浪潮下的音视频研发探索,主要内容是针对闲鱼APP在当下流行的跨平台框架Flutter的大规模实践,介绍其在音视频领域碰到的一些困难以及解决方案。

分享内容主要分为四个方面,首先会对Flutter有一个简单介绍以及选择Flutter作为跨平台框架的原因,其次会介绍Flutter中与音视频关系非常大的外接纹理概念,以及对它做出的一些优化。之后会对闲鱼在音视频实践过程中碰到的一些Flutter问题提出了一些解决方案——TPM音视频框架。最后是闲鱼Flutter多媒体开源组件的介绍。

Flutter

Flutter是一个跨平台框架,以往的做法是将音频、视频和网络这些模块都下沉到C++层或者ARM层,在其上封装成一个音视频的SDK,供UI层的PC、iOS和Android调用。

而Flutter做为一个UI层的跨平台框架,顾名思义就是在UI层也实现了一个跨平台开发。可以预想的是未Flutter发展的好的话,会逐渐变为一个从底层到UI层的一个全链路的跨平台开发,技术人员分别负责SDK和UI层的开发。

在Flutter之前已经有很多跨平台UI解决方案,那为什么选择Flutter呢?

我们主要考虑性能和跨平台的能力。

以往的跨平台方案比如Weex,ReactNative,Cordova等等因为架构的原因无法满足性能要求,尤其是在音视频这种性能要求几乎苛刻的场景。

而诸如Xamarin等,虽然性能可以和原生App一致,但是大部分逻辑还是需要分平台实现。

我们可以看一下,为什么Flutter可以实现高性能:

原生的native组件渲染以IOS为例,苹果的UIKit通过调用平台自己的绘制框架QuaztCore来实现UI的绘制,图形绘制也是调用底层的API,比如OpenGL、Metal等。

而Flutter也是和原生API逻辑一致,也是通过调用底层的绘制框架层SKIA实现UI层。这样相当于Flutter他自己实现了一套UI框架,提供了一种性能超越原生API的跨平台可能性。

但是我们说一个框架最终性能怎样,其实取决于设计者和开发者。至于现在到底是一个什么状况:

在闲鱼的实践中,我们发现在正常的开发没有特意的去优化UI代码的情况下,在一些低端机上,Flutter界面的流畅性是比Native界面要好的。

虽然现在闲鱼某些场景下会有卡顿闪退等情况,但是这是一个新事物发展过程中的必然问题,我们相信未来性能肯定不会成为限制Flutter发展的瓶颈的。

在闲鱼实践Flutter的过程中,混合栈和音视频是其中比较难解决的两个问题,混合栈是指一个APP在Flutter过程中不可能一口气将所有业务全部重写为Flutter,所以这是一个逐步迭代的过程,这期间原生native界面与Flutter界面共存的状态就称之为混合栈。闲鱼在混合栈上也有一些比较好的输出,例如FlutterBoost。

外接纹理

在讲音视频之前需要简要介绍一下外接纹理的概念,我们将它称之为是Flutter和Frame之间的桥梁。

Flutter渲染一帧屏幕数据首先要做的是,GPU发出的VC信号在Flutter的UI线程,通过AOT编译的机器码结合当前Dart Runtime,生成Layer Tree UI树,Layer Tree上每一个叶子节点都代表了当前屏幕上所需要渲染的每一个元素,包含了这些元素渲染所需要的内容。将Layer Tree抛给GPU线程,在GPU线程内调用Skia去完成整个UI的渲染过程。Layer Tree中有PictureLayer和TextureLayer两个比较重要的节点。PictureLayer主要负责屏幕图片的渲染,Flutter内部实现了一套图片解码逻辑,在IO线程将图片读取或者从网络上拉取之后,通过解码能够在IO线程上加载出纹理,交给GPU线程将图片渲染到屏幕上。但是由于音视频场景下系统API太过繁多,业务场景过于复杂。Flutter没有一套逻辑去实现跨平台的音视频组件,所以说Flutter提出了一种让第三方开发者来实现音视频组件的方式,而这些音视频组件的视频渲染出口,就是TextureLayer。

在整个Layer Tree渲染的过程中,TextureLayer的数据纹理需要由外部第三方开发者来指定,可以把视频数据和播放器数据送到TextureLayer里,由Flutter将这些数据渲染出来。

TextureLayer渲染过程:首先判断Layer是否已经初始化,如果没有就创建一个Texture,然后将Texture Attach到一个SufaceTexture上。

这个SufaceTexture是音视频的native代码可以获取到的对象,通过这个对象创建的Suface,我们可以将视频数据、摄像头数据解码放到Suface中,然后Flutter端通过监听SufaceTexture的数据更新就可以顺利把刚才创建的数据更新到它的纹理中,然后再将纹理交给SKIA渲染到屏幕上。

然而我们如果需要用Flutter实现美颜,滤镜,人脸贴图等等功能,就需要将视频数据读取出来,更新到纹理中,再将GPU纹理经过美颜滤镜处理后生成一个处理后的纹理。按Flutter提供的现有能力,必须先将纹理中的数据从GPU读出到CPU中,生成Bitmap后再写入Surface中,这样在Flutter中才能顺利的更新到视频数据,这样做对系统性能的消耗很大。

通过对Flutter渲染过程分析,我们知道Flutter底层需要渲染的数据就是GPU纹理,而我们经过美颜滤镜处理完成以后的结果也是GPU纹理,如果可以将它直接交给Flutter渲染,那就可以避免GPU-CPU-GPU这样的无用循环。这样的方法是可行的,但是需要一个条件,就是OpenGL上下文共享。

OpenGL

在说上下文之前,得提到一个和上线文息息相关的概念:线程。

Flutter引擎启动后会启动四个线程:

第一个线程是UI线程,这是Flutter自己定义的UI线程,主要负责GPU发出的VSync信号时候用当前Dart编译的机器码和当前运行环境创建出Layer Tree。

还有就是IO线程和GPU线程。和大部分OpenGL处理解决方案中一样,Flutter也采取一个线程责资源加载,一部分负责资源渲染这种思路。

两个线程之间纹理共享有两种方式。一种是EGLImage(IOS是 CVOpenGLESTextureCache)。一种是OpenGL Share Context。Flutter通过Share Context来实现纹理共享,将IO线程的Context和GPU线程的Context进行Share,放到同一个Share Group下面,这样两个线程下资源是互相可见可以共享的。

Platform线程是主线程,Flutter中有一个很奇怪的设定,GPU线程和主线程共用一个Context。并且在主线程也有很多OpenGL 操作。

这样的设计会给音视频开发带来很多问题,后面会详细说。

音视频端美颜处理完成的OpenGL纹理能够让Flutter直接使用的条件就是Flutter的上下文需要和平台音视频相关的OpenGL上下文处在一个Share Group下面。

由于Flutter主线程的Context就是GPU的Context,所以在音视频端主线程中有一些OpenGL操作的话,很有可能使Flutter整个OpenGL被破坏掉。所以需要将所有的OpenGL操作都限制在子线程中。

通过上述这两个条件的处理,我们就可以在没有增加GPU消耗的前提下实现美颜和滤镜等等功能。

TPM

在经过demo验证之后,我们将这个方案应用到闲鱼音视频组件中,但改造过程中发现了一些问题。

上图是摄像头采集数据转换为纹理的一段代码,其中有两个操作:首先是切进程,将后面的OpenGL操作都切到cameraQueue中。然后是设置一次上下文。然后这种限制条件或者说是潜规则往往在开发过程中容易被忽略的。而这个条件一旦忽略后果就是出现一些莫名其妙的诡异问题极难排查。因此我们就希望能抽象出一套框架,由框架本身实现线程的切换、上下文和模块生命周期等的管理,开发者接入框架以后只需要安心实现自己的算法,而不需要关心这些潜规则还有其他一些重复的逻辑操作。

在引入Flutter之前闲鱼的音视频架构与大部分音视频逻辑一样采用分层架构:

1:底层是一些独立模块

2:SDK层是对底层模块的封装

3:最上层是UI层。

引入Flutter之后,通过分析各个模块的使用场景,我们可以得出一个假设或者说是抽象:音视频应用在终端上可以归纳为视频帧解码之后视频数据帧在各个模块之间流动的过程,基于这种假设去做Flutter音视频框架的抽象。

咸鱼Flutter多媒体开源组件

整个Flutter音视频框架抽象分为管线和数据的抽象、模块的抽象、线程统一管理和上下文同一管理四部分。

管线,其实就是视频帧流动的管道。数据,音视频中涉及到的数据包括纹理、Bit Map以及时间戳等。结合现有的应用场景我们定义了管线流通数据以Texture为主数据,同时可以选择性的添加Bit Map等作为辅助数据。这样的数据定义方式,避免重复的创建和销毁纹理带来的性能开销以及多线程访问纹理带来的一些问题。也满足一些特殊模块对特殊数据的需求。同时也设计了纹理池来管理管线中的纹理数据。

模块:如果把管线和数据比喻成血管和血液,那框架音视频的场景就可以比喻成器官,我们根据模块所在管线的位置抽象出采集、处理和输出三个基类。这三个基类里实现了刚才说的线程切换,上下文切换,格式转换等等共同逻辑,各个功能模块通过集成自这些基类,可以避免很多重复劳动。

线程:每一个模块初始化的时候,初始化函数就会去线程管理的模块去获取自己的线程,线程管理模块可以决定给初始化函数分配新的线程或者已经分配过其他模块的线程。

这样有三个好处:

一是可以根据需要去决定一个线程可以挂载多少模块,做到线程间的负载均衡。第二,多线程并发式能够保证模块内的OpenGL操作是在当前线程内而不会跑到主线程去,彻底避免Flutter的OpenGL 环境被破坏。第三,多线程并行可以充分利用CPU多核架构,提升处理速度。

从Flutter端修改Flutter引擎将Context取出后,根据Context创建上下文的统一管理模块,每一个模块在初始化的时候会获取它的线程,获取之后会调用上下文管理模块获取自己的上下文。这样可以保证每一个模块的上下文都是与Flutter的上下文进行Share的,每个模块之间资源都是共享可见的,Flutter和音视频native之间也是互相共享可见的。

基于上述框架如果要实现一个简单的场景,比如画面实时预览和滤镜处理功能,

1:需要选择功能模块,功能模块包括摄像头模块、滤镜处理模块和Flutter画面渲染模块,

2:需要配置模块参数,比如采集分辨率、滤镜参数和前后摄像头设置等,

3:在创建视频管线后使用已配置的参数创建模块

4:最后管线搭载模块,开启管线就可以实现这样简单的功能。

上图为整个功能实现的代码和结构图。

结合上述音视频框架,闲鱼实现了Flutter多媒体开源组件。

组要包含四个基本组件分别是:

1:视频图像拍摄组件

2:播放器组件

3:视频图像编辑组件

4:相册选择组件

现在这些组件正在走内部开源流程。预计9月份,相册和播放器会实现开源。

后续展望和规划

1:实现开头所说的从底层SDK到UI的全链路的跨端开发。目前底层框架层和模块层都是各个平台各自实现,反而是Flutter的UI端进行了跨平台的统一,所以后续会将底层也按照音视频常用做法把逻辑下沉到C++层,尽可能的实现全链路跨平台。

2:第二部分内容为开源共建,闲鱼开源的内容不仅包括拍摄、编辑组件,还包括了很多底层模块,希望有开发者在基于Flutter开发音视频应用时可以充分利用闲鱼开源出的音视频模块能力,搭建APP框架,开发者只要去负责实现特殊需求模块就可以,尽可能的减少重复劳动。

Flutter开发App和原生iOS开发App各有什么优缺点?

自己写flutter也有段时间了,这次来聊聊flutter开发App和原生iOS开发App各有什么优缺点.

不废话,直奔主题????


新闻标题:flutter好处,Flutter缺点
文章起源:http://cqcxhl.cn/article/dsdjcpe.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP