Skip to content

Commit

Permalink
#73 Optimize the issue of high CPU usage during idle time
Browse files Browse the repository at this point in the history
  • Loading branch information
Harley-xk committed Feb 21, 2020
1 parent 0b8b7bd commit cbb1cf4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion MaLiang.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Pod::Spec.new do |s|

s.name = 'MaLiang'
s.version = '2.6.4'
s.version = '2.6.5'
s.summary = 'MaLiang is a painting Framework based on Metal.'
s.description = 'The name of "MaLiang" comes from a boy who had a magical brush in Chinese ancient fairy story.'

Expand Down
6 changes: 5 additions & 1 deletion MaLiang/Classes/MetalBase/MetalView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ open class MetalView: MTKView {
open override func draw(_ rect: CGRect) {
super.draw(rect)

guard metalAvaliable, let texture = screenTarget?.texture else {
guard metalAvaliable,
let target = screenTarget, target.modified,
let texture = target.texture else {
return
}

Expand All @@ -172,6 +174,8 @@ open class MetalView: MTKView {
commandBuffer?.present(drawable)
}
commandBuffer?.commit()

target.modified = false
}
}

Expand Down
2 changes: 2 additions & 0 deletions MaLiang/Classes/MetalBase/RenderTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ open class RenderTarget {
internal var commandBuffer: MTLCommandBuffer?
internal var commandQueue: MTLCommandQueue?
internal var device: MTLDevice?
internal var modified = false

internal func updateBuffer(with size: CGSize) {
self.drawableSize = size
Expand Down Expand Up @@ -99,6 +100,7 @@ open class RenderTarget {
internal func commitCommands() {
commandBuffer?.commit()
commandBuffer = nil
modified = true
}

// make empty testure
Expand Down

0 comments on commit cbb1cf4

Please sign in to comment.