--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/skia-discuss/8109a971-1dbe-4f8f-9078-9316e2727fdbn%40googlegroups.com.
#import "SkiaView.h"
#import <MetalKit/MetalKit.h>
#import <Metal/Metal.h>
#define SK_GANESH
#define SK_METAL
#import "include/gpu/ganesh/GrTypes.h"
#import "include/gpu/ganesh/SkSurfaceGanesh.h"
#import "include/gpu/ganesh/mtl/GrMtlTypes.h"
#import "include/gpu/ganesh/GrBackendSurface.h"
#import "include/gpu/ganesh/SkSurfaceGanesh.h"
#import "include/gpu/ganesh/mtl/GrMtlBackendContext.h"
#import "include/gpu/ganesh/mtl/GrMtlBackendSurface.h"
#import "include/gpu/ganesh/mtl/GrMtlDirectContext.h"
#import "include/gpu/ganesh/mtl/SkSurfaceMetal.h"
#import "include/gpu/ganesh/GrDirectContext.h"
#import "include/core/SkCanvas.h"
#import "include/core/SkColorSpace.h"
@implementation SkiaView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self commonInit];
}
return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (self) {
[self commonInit];
}
return self;
}
- (void)commonInit {
#ifndef SK_GANESH
NSLog(@"SK_GANESH is undefined");
#endif
#ifndef SK_METAL
NSLog(@"SK_METAL is undefined");
#endif
self.metalDevice = MTLCreateSystemDefaultDevice();
if (!self.metalDevice) {
NSLog(@"Metal is not supported on this device");
return;
}
self.metalQueue = [self.metalDevice newCommandQueue];
if (!self.metalQueue) {
NSLog(@"Failed to create Metal command queue");
return;
}
self.device = self.metalDevice;
self.delegate = self;
self.enableSetNeedsDisplay = YES;
self.depthStencilPixelFormat = MTLPixelFormatDepth32Float_Stencil8;
self.colorPixelFormat = MTLPixelFormatBGRA8Unorm;
self.sampleCount = 1;
self.layer.borderWidth = 2.0;
self.layer.borderColor = [UIColor redColor].CGColor;
}
- (void) didMoveToWindow {
NSLog(@"didMoveToWindow");
GrMtlBackendContext backendContext = {};
backendContext.fDevice.retain((__bridge_retained GrMTLHandle)[self metalDevice]);
backendContext.fQueue.retain((__bridge_retained GrMTLHandle)[self metalQueue]);
GrContextOptions grContextOptions;
self.grDirectContext = GrDirectContexts::MakeMetal(backendContext, grContextOptions);
if (!self.grDirectContext) {
NSLog(@"Failed to create GrDirectContext");
return;
}
NSLog(@"Created GrDirectContext");
GrMTLHandle mtlHandle = (__bridge_retained GrMTLHandle)self;
self.surface = SkSurfaces::WrapMTKView(
self.grDirectContext.get(),
mtlHandle,
kTopLeft_GrSurfaceOrigin,
1,
kBGRA_8888_SkColorType,
SkColorSpace::MakeSRGB(),
nullptr
);
if (!self.surface) {
NSLog(@"Failed to create Skia surface");
return;
}
NSLog(@"Created Surface");
}
#pragma mark - MTKViewDelegate
- (void)drawInMTKView:(nonnull MTKView *)view {
}
- (void)mtkView:(nonnull MTKView *)view drawableSizeWillChange:(CGSize)size {
}
@end
And it's always crashing in MakeMetal when I'm using it in a static iOS library (on an iOS simulator). And it works in application project for some reason. I've also tried `__bridge_retained`, nothing changed.
Usually it looks like this:
* thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x20)
frame #0: 0x0000000180069858 libobjc.A.dylib`objc_retain + 16
* frame #1: 0x0000000105190618 SkiaViewTestApp`GrMtlGpu::GrMtlGpu(this=0x0000000107117630,
I'm not an iOS developer and not familiar that much with Obj-C memory management, so I have no idea how to fix it — could someone please help with it?