Skip to content

Commit

Permalink
fix: reduce render count
Browse files Browse the repository at this point in the history
  • Loading branch information
vcellu committed Nov 25, 2022
1 parent 840a340 commit ee72ad7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
19 changes: 4 additions & 15 deletions ios/CanvasView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,11 @@ -(void)layoutSubviews {
prev = self.frame;
self.onReady(@{});
} else {
dispatch_async(dispatch_get_main_queue(), ^{
self->renderer->resetBounds(SkRect::MakeWH(Helium::toPx(self.frame.size.width), Helium::toPx(self.frame.size.height)));
if(prev.size.width != self.frame.size.width || prev.size.height != self.frame.size.height) {
prev = self.frame;
renderer->resetBounds(SkRect::MakeWH(Helium::toPx(self.frame.size.width), Helium::toPx(self.frame.size.height)));
self.onResized(@{});
self->renderer->draw();
});
}
}

-(void)setFrame:(CGRect)frame {
[super setFrame:frame];
if(ready) {
dispatch_async(dispatch_get_main_queue(), ^{
self->renderer->resetBounds(SkRect::MakeWH(Helium::toPx(self.frame.size.width), Helium::toPx(self.frame.size.height)));
self.onResized(@{});
self->renderer->draw();
});
}
}
}

Expand Down
10 changes: 4 additions & 6 deletions ios/MetalLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@
}

void MetalLayer::resetSize(int width, int height){
dispatch_async(dispatch_get_main_queue(), ^{
if(skContext) {
skContext->purgeUnlockedResources(false);
}
if(skContext) {
skContext->purgeUnlockedResources(false);
}
layer.frame = CGRectMake(0, 0, Helium::toDB(width), Helium::toDB(height));
layer.drawableSize = CGSizeMake(width, height);
});


}

void MetalLayer::draw(std::shared_ptr<SkiaRenderView>& renderView) {
Expand Down

0 comments on commit ee72ad7

Please sign in to comment.