mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-03 21:16:35 +00:00
Various fixes
This commit is contained in:
parent
c98abdd025
commit
4afc8c1af3
@ -59,7 +59,13 @@ final class DrawingMetalView: MTKView {
|
|||||||
|
|
||||||
override var isHidden: Bool {
|
override var isHidden: Bool {
|
||||||
didSet {
|
didSet {
|
||||||
self.isPaused = self.isHidden
|
if self.isHidden {
|
||||||
|
Queue.mainQueue().after(0.2) {
|
||||||
|
self.isPaused = true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
self.isPaused = self.isHidden
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,7 +144,6 @@ final class DrawingMetalView: MTKView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override var frame: CGRect {
|
override var frame: CGRect {
|
||||||
get {
|
get {
|
||||||
return super.frame
|
return super.frame
|
||||||
@ -157,7 +162,7 @@ final class DrawingMetalView: MTKView {
|
|||||||
|
|
||||||
let renderPassDescriptor = MTLRenderPassDescriptor()
|
let renderPassDescriptor = MTLRenderPassDescriptor()
|
||||||
let attachment = renderPassDescriptor.colorAttachments[0]
|
let attachment = renderPassDescriptor.colorAttachments[0]
|
||||||
attachment?.clearColor = clearColor
|
attachment?.clearColor = self.clearColor
|
||||||
attachment?.texture = self.currentDrawable?.texture
|
attachment?.texture = self.currentDrawable?.texture
|
||||||
attachment?.loadAction = .clear
|
attachment?.loadAction = .clear
|
||||||
attachment?.storeAction = .store
|
attachment?.storeAction = .store
|
||||||
@ -185,7 +190,7 @@ final class DrawingMetalView: MTKView {
|
|||||||
func reset() {
|
func reset() {
|
||||||
let renderPassDescriptor = MTLRenderPassDescriptor()
|
let renderPassDescriptor = MTLRenderPassDescriptor()
|
||||||
let attachment = renderPassDescriptor.colorAttachments[0]
|
let attachment = renderPassDescriptor.colorAttachments[0]
|
||||||
attachment?.clearColor = clearColor
|
attachment?.clearColor = self.clearColor
|
||||||
attachment?.texture = self.currentDrawable?.texture
|
attachment?.texture = self.currentDrawable?.texture
|
||||||
attachment?.loadAction = .clear
|
attachment?.loadAction = .clear
|
||||||
attachment?.storeAction = .store
|
attachment?.storeAction = .store
|
||||||
@ -250,6 +255,15 @@ private class Drawable {
|
|||||||
|
|
||||||
func clear() {
|
func clear() {
|
||||||
self.texture?.clear()
|
self.texture?.clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
func reset() {
|
||||||
|
self.prepareForDraw()
|
||||||
|
|
||||||
|
if let commandEncoder = self.makeCommandEncoder() {
|
||||||
|
commandEncoder.endEncoding()
|
||||||
|
}
|
||||||
|
|
||||||
self.commit(wait: true)
|
self.commit(wait: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,6 +287,7 @@ private class Drawable {
|
|||||||
return commandBuffer.makeRenderCommandEncoder(descriptor: renderPassDescriptor)
|
return commandBuffer.makeRenderCommandEncoder(descriptor: renderPassDescriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
internal func commit(wait: Bool = false) {
|
internal func commit(wait: Bool = false) {
|
||||||
self.commandBuffer?.commit()
|
self.commandBuffer?.commit()
|
||||||
if wait {
|
if wait {
|
||||||
@ -632,57 +647,23 @@ final class Texture {
|
|||||||
self.width = width
|
self.width = width
|
||||||
self.height = height
|
self.height = height
|
||||||
self.bytesPerRow = bytesPerRow
|
self.bytesPerRow = bytesPerRow
|
||||||
|
|
||||||
|
self.buffer = nil
|
||||||
|
|
||||||
// if #available(iOS 12.0, *) {
|
let textureDescriptor = MTLTextureDescriptor()
|
||||||
//#if targetEnvironment(simulator)
|
textureDescriptor.textureType = .type2D
|
||||||
// self.buffer = nil
|
textureDescriptor.pixelFormat = .bgra8Unorm
|
||||||
// let textureDescriptor = MTLTextureDescriptor()
|
textureDescriptor.width = width
|
||||||
// textureDescriptor.textureType = .type2D
|
textureDescriptor.height = height
|
||||||
// textureDescriptor.pixelFormat = .bgra8Unorm
|
textureDescriptor.usage = [.renderTarget, .shaderRead]
|
||||||
// textureDescriptor.width = width
|
textureDescriptor.storageMode = .shared
|
||||||
// textureDescriptor.height = height
|
|
||||||
// textureDescriptor.usage = [.renderTarget, .shaderRead]
|
guard let texture = device.makeTexture(descriptor: textureDescriptor) else {
|
||||||
// textureDescriptor.storageMode = .shared
|
return nil
|
||||||
//
|
}
|
||||||
// guard let texture = device.makeTexture(descriptor: textureDescriptor) else {
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
//#else
|
|
||||||
// guard let buffer = device.makeBuffer(length: bytesPerRow * height, options: MTLResourceOptions.storageModeShared) else {
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
// self.buffer = buffer
|
|
||||||
//
|
|
||||||
// let textureDescriptor = MTLTextureDescriptor()
|
|
||||||
// textureDescriptor.textureType = .type2D
|
|
||||||
// textureDescriptor.pixelFormat = .bgra8Unorm
|
|
||||||
// textureDescriptor.width = width
|
|
||||||
// textureDescriptor.height = height
|
|
||||||
// textureDescriptor.usage = [.renderTarget, .shaderRead]
|
|
||||||
// textureDescriptor.storageMode = buffer.storageMode
|
|
||||||
//
|
|
||||||
// guard let texture = buffer.makeTexture(descriptor: textureDescriptor, offset: 0, bytesPerRow: bytesPerRow) else {
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
//#endif
|
|
||||||
// self.texture = texture
|
|
||||||
// } else {
|
|
||||||
self.buffer = nil
|
|
||||||
|
|
||||||
let textureDescriptor = MTLTextureDescriptor()
|
|
||||||
textureDescriptor.textureType = .type2D
|
|
||||||
textureDescriptor.pixelFormat = .bgra8Unorm
|
|
||||||
textureDescriptor.width = width
|
|
||||||
textureDescriptor.height = height
|
|
||||||
textureDescriptor.usage = [.renderTarget, .shaderRead]
|
|
||||||
textureDescriptor.storageMode = .shared
|
|
||||||
|
|
||||||
guard let texture = device.makeTexture(descriptor: textureDescriptor) else {
|
self.texture = texture
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
self.texture = texture
|
|
||||||
// }
|
|
||||||
self.clear()
|
self.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -699,37 +680,17 @@ final class Texture {
|
|||||||
|
|
||||||
func createCGImage() -> CGImage? {
|
func createCGImage() -> CGImage? {
|
||||||
let dataProvider: CGDataProvider
|
let dataProvider: CGDataProvider
|
||||||
// if #available(iOS 12.0, *) {
|
|
||||||
//#if targetEnvironment(simulator)
|
guard let data = NSMutableData(capacity: self.bytesPerRow * self.height) else {
|
||||||
// guard let data = NSMutableData(capacity: self.bytesPerRow * self.height) else {
|
return nil
|
||||||
// return nil
|
}
|
||||||
// }
|
data.length = self.bytesPerRow * self.height
|
||||||
// data.length = self.bytesPerRow * self.height
|
self.texture.getBytes(data.mutableBytes, bytesPerRow: self.bytesPerRow, bytesPerImage: self.bytesPerRow * self.height, from: MTLRegion(origin: MTLOrigin(), size: MTLSize(width: self.width, height: self.height, depth: 1)), mipmapLevel: 0, slice: 0)
|
||||||
// self.texture.getBytes(data.mutableBytes, bytesPerRow: self.bytesPerRow, bytesPerImage: self.bytesPerRow * self.height, from: MTLRegion(origin: MTLOrigin(), size: MTLSize(width: self.width, height: self.height, depth: 1)), mipmapLevel: 0, slice: 0)
|
|
||||||
//
|
guard let provider = CGDataProvider(data: data as CFData) else {
|
||||||
// guard let provider = CGDataProvider(data: data as CFData) else {
|
return nil
|
||||||
// return nil
|
}
|
||||||
// }
|
dataProvider = provider
|
||||||
// dataProvider = provider
|
|
||||||
//#else
|
|
||||||
// guard let buffer = self.buffer, let provider = CGDataProvider(data: Data(bytesNoCopy: buffer.contents(), count: buffer.length, deallocator: .custom { _, _ in
|
|
||||||
// }) as CFData) else {
|
|
||||||
// return nil
|
|
||||||
// }
|
|
||||||
// dataProvider = provider
|
|
||||||
//#endif
|
|
||||||
// } else {
|
|
||||||
guard let data = NSMutableData(capacity: self.bytesPerRow * self.height) else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
data.length = self.bytesPerRow * self.height
|
|
||||||
self.texture.getBytes(data.mutableBytes, bytesPerRow: self.bytesPerRow, bytesPerImage: self.bytesPerRow * self.height, from: MTLRegion(origin: MTLOrigin(), size: MTLSize(width: self.width, height: self.height, depth: 1)), mipmapLevel: 0, slice: 0)
|
|
||||||
|
|
||||||
guard let provider = CGDataProvider(data: data as CFData) else {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
dataProvider = provider
|
|
||||||
// }
|
|
||||||
|
|
||||||
guard let image = CGImage(
|
guard let image = CGImage(
|
||||||
width: Int(self.width),
|
width: Int(self.width),
|
||||||
|
|||||||
@ -76,8 +76,8 @@ final class NeonTool: DrawingElement {
|
|||||||
let renderColor: UIColor
|
let renderColor: UIColor
|
||||||
|
|
||||||
private var pathStarted = false
|
private var pathStarted = false
|
||||||
private let path = UIBezierPath()
|
private let path = UIBezierPath()
|
||||||
private var activePath: UIBezierPath?
|
private var activePath: UIBezierPath?
|
||||||
private var addedPaths = 0
|
private var addedPaths = 0
|
||||||
|
|
||||||
fileprivate var renderPath: CGPath?
|
fileprivate var renderPath: CGPath?
|
||||||
|
|||||||
@ -241,11 +241,11 @@
|
|||||||
if (animated) {
|
if (animated) {
|
||||||
[UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
|
[UIView animateWithDuration:0.2 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
|
||||||
_inputPanelView.frame = CGRectMake(edgeInsets.left, y, frame.size.width, panelHeight);
|
_inputPanelView.frame = CGRectMake(edgeInsets.left, y, frame.size.width, panelHeight);
|
||||||
_backgroundView.frame = CGRectMake(edgeInsets.left, y, frame.size.width, backgroundHeight + 1.0);
|
_backgroundView.frame = CGRectMake(edgeInsets.left, y, frame.size.width, backgroundHeight);
|
||||||
} completion:nil];
|
} completion:nil];
|
||||||
} else {
|
} else {
|
||||||
_inputPanelView.frame = CGRectMake(edgeInsets.left, y, frame.size.width, panelHeight);
|
_inputPanelView.frame = CGRectMake(edgeInsets.left, y, frame.size.width, panelHeight);
|
||||||
_backgroundView.frame = CGRectMake(edgeInsets.left, y, frame.size.width, backgroundHeight + 1.0);
|
_backgroundView.frame = CGRectMake(edgeInsets.left, y, frame.size.width, backgroundHeight);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -81,6 +81,11 @@ const CGSize TGPhotoPaintingMaxSize = { 1920.0f, 1920.0f };
|
|||||||
_context = context;
|
_context = context;
|
||||||
_stickersContext = stickersContext;
|
_stickersContext = stickersContext;
|
||||||
|
|
||||||
|
if (entitiesView != nil) {
|
||||||
|
_skipEntitiesSetup = true;
|
||||||
|
entitiesView.userInteractionEnabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
CGSize size = TGScaleToSize(photoEditor.originalSize, [TGPhotoDrawingController maximumPaintingSize]);
|
CGSize size = TGScaleToSize(photoEditor.originalSize, [TGPhotoDrawingController maximumPaintingSize]);
|
||||||
_drawingAdapter = [_stickersContext drawingAdapter:size originalSize:photoEditor.originalSize isVideo:photoEditor.forVideo isAvatar:isAvatar entitiesView:entitiesView];
|
_drawingAdapter = [_stickersContext drawingAdapter:size originalSize:photoEditor.originalSize isVideo:photoEditor.forVideo isAvatar:isAvatar entitiesView:entitiesView];
|
||||||
_interfaceController = (UIViewController<TGPhotoDrawingInterfaceController> *)_drawingAdapter.interfaceController;
|
_interfaceController = (UIViewController<TGPhotoDrawingInterfaceController> *)_drawingAdapter.interfaceController;
|
||||||
|
|||||||
@ -336,7 +336,8 @@
|
|||||||
_fullPaintingView = [[UIImageView alloc] init];
|
_fullPaintingView = [[UIImageView alloc] init];
|
||||||
_fullPaintingView.frame = _fullPreviewView.frame;
|
_fullPaintingView.frame = _fullPreviewView.frame;
|
||||||
|
|
||||||
_fullEntitiesView = [_stickersContext drawingEntitiesViewWithSize:_photoEditor.originalSize];
|
CGSize size = TGScaleToSize(_photoEditor.originalSize, [TGPhotoDrawingController maximumPaintingSize]);
|
||||||
|
_fullEntitiesView = [_stickersContext drawingEntitiesViewWithSize:size];
|
||||||
_fullEntitiesView.userInteractionEnabled = false;
|
_fullEntitiesView.userInteractionEnabled = false;
|
||||||
CGRect rect = [TGPhotoDrawingController fittedCropRect:_photoEditor.cropRect originalSize:_photoEditor.originalSize keepOriginalSize:true];
|
CGRect rect = [TGPhotoDrawingController fittedCropRect:_photoEditor.cropRect originalSize:_photoEditor.originalSize keepOriginalSize:true];
|
||||||
_fullEntitiesView.frame = CGRectMake(0, 0, rect.size.width, rect.size.height);
|
_fullEntitiesView.frame = CGRectMake(0, 0, rect.size.width, rect.size.height);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user