23#import <Metal/Metal.h>
24#import <MetalKit/MetalKit.h>
25#import <UIKit/UIKit.h>
30 if (!
paint->getShader()) {
49@property (assign, nonatomic) id<MTLCommandQueue>
metalQueue;
56- (void)drawInMTKView:(nonnull MTKView *)view {
67 NSLog(
@"error: no sksurface");
77 id<MTLCommandBuffer> commandBuffer = [[
self metalQueue] commandBuffer];
78 [commandBuffer presentDrawable:[view currentDrawable]];
79 [commandBuffer commit];
82- (void)mtkView:(nonnull MTKView *)view drawableSizeWillChange:(CGSize)size {
91@property (strong, nonatomic) id<MTLCommandQueue>
metalQueue;
99 [
self setView:[[MTKView alloc] initWithFrame:[[UIScreen mainScreen] bounds] device:nil]];
105 [
self setMetalDevice:MTLCreateSystemDefaultDevice()];
106 [
self setMetalQueue:[[
self metalDevice] newCommandQueue]];
109 if (![
self view] || ![
self metalDevice]) {
110 NSLog(
@"Metal is not supported on this device");
111 self.view = [[UIView alloc] initWithFrame:self.view.frame];
114 MTKView* mtkView = (MTKView*)[
self view];
115 [mtkView setDevice:[
self metalDevice]];
116 [mtkView setBackgroundColor:[UIColor blackColor]];
119 [viewDelegate setGrContext:fGrContext.get()];
120 [viewDelegate setMetalQueue:[
self metalQueue]];
122 [mtkView setDelegate:viewDelegate];
128@interface AppDelegate : UIResponder <UIApplicationDelegate>
129@property (strong, nonatomic) UIWindow *
window;
133- (
BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary*)opts {
135 [
self setWindow:[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]];
136 [[
self window] setFrame:[[UIScreen mainScreen] bounds]];
138 [[
self window] makeKeyAndVisible];
147 return UIApplicationMain(argc,
argv, nil, NSStringFromClass([
AppDelegate class]));
std::unique_ptr< GrDirectContext, GrContextRelease > GrContextHolder
static const int points[]
void translate(SkScalar dx, SkScalar dy)
void drawPaint(const SkPaint &paint)
void rotate(SkScalar degrees)
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
id< MTLDevice > metalDevice
id< MTLCommandQueue > metalQueue
GrDirectContext * grContext
id< MTLCommandQueue > metalQueue
void mtkView:drawableSizeWillChange:(nonnull MTKView *view, [drawableSizeWillChange] CGSize size)
constexpr SkColor4f kWhite
constexpr SkColor4f kBlack
PODArray< SkColor > colors
SK_API GrSemaphoresSubmitted Flush(sk_sp< SkSurface >)
int main(int argc, char *argv[])
static void config_paint(SkPaint *paint)
static void draw_example(SkSurface *surface, const SkPaint &paint, double rotation)