mirror of
https://github.com/grishka/NearDrop.git
synced 2025-12-16 19:57:41 +01:00
47 lines
1.2 KiB
Swift
47 lines
1.2 KiB
Swift
//
|
|
// QrCodeBackgroundView.swift
|
|
// ShareExtension
|
|
//
|
|
// Created by Grishka on 07.08.2025.
|
|
//
|
|
|
|
import Foundation
|
|
import Metal
|
|
import MetalKit
|
|
|
|
class QrCodeBackgroundView:MTKView{
|
|
private var commandQueue:MTLCommandQueue?
|
|
private var commandBuffer:MTLCommandBuffer?
|
|
|
|
override func awakeFromNib() {
|
|
super.awakeFromNib()
|
|
isPaused=true
|
|
enableSetNeedsDisplay=false
|
|
device=MTLCreateSystemDefaultDevice()
|
|
let brightness=1.5
|
|
clearColor=MTLClearColor(red: brightness, green: brightness, blue: brightness, alpha: 1)
|
|
|
|
let mtlLayer:CAMetalLayer=(layer as? CAMetalLayer)!
|
|
mtlLayer.wantsExtendedDynamicRangeContent=true
|
|
mtlLayer.cornerRadius=20
|
|
mtlLayer.masksToBounds=true
|
|
colorspace=CGColorSpace(name: CGColorSpace.extendedSRGB)
|
|
colorPixelFormat = .rgba16Float
|
|
|
|
commandQueue=device!.makeCommandQueue()
|
|
commandBuffer=commandQueue!.makeCommandBuffer()
|
|
draw()
|
|
}
|
|
|
|
override func draw(_ dirtyRect: NSRect) {
|
|
guard let commandBuffer=commandBuffer else {return}
|
|
if let descriptor=currentRenderPassDescriptor, let encoder=commandBuffer.makeRenderCommandEncoder(descriptor: descriptor){
|
|
encoder.endEncoding()
|
|
if let currentDrawable=currentDrawable{
|
|
commandBuffer.present(currentDrawable)
|
|
}
|
|
}
|
|
commandBuffer.commit()
|
|
}
|
|
}
|