Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0d187f5

Browse files
committed
Don't rerender if unnecesary.
1 parent59354fd commit0d187f5

File tree

1 file changed

+46
-31
lines changed

1 file changed

+46
-31
lines changed

‎flutter-engine/src/texture_registry.rs

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use crate::ffi::{ExternalTexture, ExternalTextureFrame, TextureId};
22
usecrate::FlutterEngine;
33
#[cfg(feature ="image")]
44
use image::RgbaImage;
5+
#[cfg(feature ="image")]
6+
use parking_lot::Mutex;
57
use parking_lot::RwLock;
68
use std::collections::HashMap;
79
use std::sync::Arc;
@@ -62,9 +64,9 @@ impl TextureRegistry {
6264
texture_id:TextureId,
6365
_size:(usize,usize),
6466
) ->Option<ExternalTextureFrame>{
65-
let textures =self.textures.read();
67+
letmuttextures =self.textures.write();
6668
textures
67-
.get(&texture_id)
69+
.get_mut(&texture_id)
6870
.map(|texture| texture.get_texture_frame())
6971
}
7072

@@ -99,7 +101,7 @@ impl FlutterTexture {
99101
self.texture.mark_frame_available();
100102
}
101103

102-
fnget_texture_frame(&self) ->ExternalTextureFrame{
104+
fnget_texture_frame(&mutself) ->ExternalTextureFrame{
103105
self.gl.get_texture_frame()
104106
}
105107
}
@@ -112,51 +114,64 @@ impl Drop for FlutterTexture {
112114
}
113115

114116
pubtraitGlTexture:Send +Sync{
115-
fnget_texture_frame(&self) ->ExternalTextureFrame;
117+
fnget_texture_frame(&mutself) ->ExternalTextureFrame;
116118
}
117119

118120
#[cfg(feature ="image")]
119121
#[derive(Clone)]
120-
pubstructRgbaTexture(Arc<RwLock<RgbaImage>>);
122+
pubstructRgbaTexture{
123+
data:Arc<Mutex<Option<RgbaImage>>>,
124+
id:u32,
125+
}
121126

122127
#[cfg(feature ="image")]
123128
implRgbaTexture{
124129
pubfnnew(img:RgbaImage) ->Self{
125-
Self(Arc::new(RwLock::new(img)))
130+
Self{
131+
data:Arc::new(Mutex::new(Some(img))),
132+
id:0,
133+
}
126134
}
127135

128136
pubfnpost_frame_rgba(&mutself,img:RgbaImage){
129-
*self.0.write() = img;
137+
*self.data.lock() =Some(img);
130138
}
131139
}
132140

133141
#[cfg(feature ="image")]
134142
implGlTextureforRgbaTexture{
135-
fnget_texture_frame(&self) ->ExternalTextureFrame{
136-
letmut id:u32 =0;
137-
let img =self.0.read();
138-
let(width, height) = img.dimensions();
143+
fnget_texture_frame(&mutself) ->ExternalTextureFrame{
144+
ifletSome(img) =self.data.lock().take(){
145+
let(width, height) = img.dimensions();
146+
unsafe{
147+
gl::GenTextures(1,&mutself.idas*mut_);
148+
gl::BindTexture(gl::TEXTURE_2D,self.id);
149+
gl::PixelStorei(gl::UNPACK_ALIGNMENT,1);
150+
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEARas_);
151+
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::LINEARas_);
152+
gl::TexImage2D(
153+
gl::TEXTURE_2D,
154+
0,// mipmap level
155+
gl::RGBAas_,// internal format of the texture
156+
widthas_,
157+
heightas_,
158+
0,// border, must be 0
159+
gl::RGBA,// format of the pixel data
160+
gl::UNSIGNED_BYTE,// data type of the pixel data
161+
(&img).as_ptr()as*const_,// pixel data
162+
);
163+
log::debug!("created gl texture with id {}",self.id);
164+
}
165+
}
166+
ExternalTextureFrame::new(gl::TEXTURE_2D,self.id, gl::RGBA8, ||{})
167+
}
168+
}
169+
170+
#[cfg(feature ="image")]
171+
implDropforRgbaTexture{
172+
fndrop(&mutself){
139173
unsafe{
140-
gl::GenTextures(1,&mut idas*mut_);
141-
gl::BindTexture(gl::TEXTURE_2D, id);
142-
gl::PixelStorei(gl::UNPACK_ALIGNMENT,1);
143-
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::LINEARas_);
144-
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::LINEARas_);
145-
gl::TexImage2D(
146-
gl::TEXTURE_2D,
147-
0,// mipmap level
148-
gl::RGBAas_,// internal format of the texture
149-
widthas_,
150-
heightas_,
151-
0,// border, must be 0
152-
gl::RGBA,// format of the pixel data
153-
gl::UNSIGNED_BYTE,// data type of the pixel data
154-
(&img).as_ptr()as*const_,// pixel data
155-
);
174+
gl::DeleteTextures(1,&self.idas*const_);
156175
}
157-
log::debug!("created gl texture with id {}", id);
158-
ExternalTextureFrame::new(gl::TEXTURE_2D, id, gl::RGBA8,move ||unsafe{
159-
gl::DeleteTextures(1,&idas*const_);
160-
})
161176
}
162177
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp