SkMetalDeviceToGrContext: no longer needs any Skia headers

Also: mv experimental/skottie_ios tools/skottie_ios_app

Motivation:  make using SkMetalViewBridge that much easier for clients.

Change-Id: I985930ae0751d218e89c48c57b69d85ad7a1e703
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259279
Reviewed-by: Hal Canary <halcanary@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
This commit is contained in:
Hal Canary 2019-12-11 10:32:59 -05:00 committed by Skia Commit-Bot
parent d6df7b55a5
commit efb4ed86cf
15 changed files with 88 additions and 52 deletions

View File

@ -2514,7 +2514,7 @@ if (is_ios && skia_use_metal && !skia_enable_flutter_defines) {
if (is_ios && !skia_enable_flutter_defines) { if (is_ios && !skia_enable_flutter_defines) {
group("skottie_ios") { group("skottie_ios") {
deps = [ deps = [
"experimental/skottie_ios", "tools/skottie_ios_app",
] ]
} }
} }

View File

@ -6,7 +6,7 @@
// Much of this code is copied from the default application created by XCode. // Much of this code is copied from the default application created by XCode.
#include "experimental/skottie_ios/SkMetalViewBridge.h" #include "tools/skottie_ios_app/SkMetalViewBridge.h"
#include "include/core/SkCanvas.h" #include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h" #include "include/core/SkPaint.h"
@ -14,8 +14,6 @@
#include "include/core/SkTime.h" #include "include/core/SkTime.h"
#include "include/effects/SkGradientShader.h" #include "include/effects/SkGradientShader.h"
#include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/GrContextOptions.h"
#include "include/gpu/mtl/GrMtlTypes.h" #include "include/gpu/mtl/GrMtlTypes.h"
#import <Metal/Metal.h> #import <Metal/Metal.h>
@ -90,7 +88,7 @@ static void draw_example(SkSurface* surface, const SkPaint& paint, double rotati
@end @end
@implementation AppViewController { @implementation AppViewController {
sk_sp<GrContext> fGrContext; GrContextHolder fGrContext;
} }
- (void)loadView { - (void)loadView {
@ -102,8 +100,7 @@ static void draw_example(SkSurface* surface, const SkPaint& paint, double rotati
if (!fGrContext) { if (!fGrContext) {
[self setMetalDevice:MTLCreateSystemDefaultDevice()]; [self setMetalDevice:MTLCreateSystemDefaultDevice()];
[self setMetalQueue:[[self metalDevice] newCommandQueue]]; [self setMetalQueue:[[self metalDevice] newCommandQueue]];
GrContextOptions grContextOptions; // set different options here. fGrContext = SkMetalDeviceToGrContext([self metalDevice], [self metalQueue]);
fGrContext = SkMetalDeviceToGrContext([self metalDevice], [self metalQueue], grContextOptions);
} }
if (![self view] || ![self metalDevice]) { if (![self view] || ![self metalDevice]) {
NSLog(@"Metal is not supported on this device"); NSLog(@"Metal is not supported on this device");

View File

@ -1,21 +0,0 @@
##`skottie_ios`
How to compile:
cd $SKIA_ROOT_DIRECTORY
mkdir -p out/ios_arm64_mtl
cat > out/ios_arm64_mtl/args.gn <<EOM
target_os="ios"
target_cpu="arm64"
skia_use_metal=true
skia_use_expat=false
skia_enable_pdf=false
EOM
tools/git-sync-deps
bin/gn gen out/ios_arm64_mtl
ninja -C out/ios_arm64_mtl skottie_ios
Then install the `out/ios_arm64_mtl/skottie_ios.app` bundle.

View File

@ -18,7 +18,15 @@
'../../dm', '../../dm',
'../../docs/examples', '../../docs/examples',
'../../example', '../../example',
'../../experimental', '../../experimental/Networking/SkSockets.cpp',
'../../experimental/Networking/SkSockets.h',
'../../experimental/c-api-example/skia-c-example.c',
'../../experimental/ffmpeg',
'../../experimental/minimal_ios_mtl_skia_app/BUILD.gn',
'../../experimental/svg/model',
'../../experimental/tools/coreGraphicsPdf2png.cpp',
'../../experimental/wasm-skp-debugger/debugger_bindings.cpp',
'../../experimental/xform',
'../../fuzz', '../../fuzz',
'../../gm', '../../gm',
'../../gn', '../../gn',

View File

@ -5,7 +5,12 @@
import("../../gn/ios.gni") import("../../gn/ios.gni")
if (is_ios) { if (is_ios) {
ios_app_bundle("skottie_ios") { group("skottie_ios_app") {
deps = [
":skottie_example",
]
}
ios_app_bundle("skottie_example") {
sources = [ sources = [
"SkAnimationDraw.h", "SkAnimationDraw.h",
"SkTimeKeeper.h", "SkTimeKeeper.h",

View File

@ -0,0 +1,42 @@
# Skottie iOS Example App
## Metal
How to compile for the Metal backend:
cd $SKIA_ROOT_DIRECTORY
mkdir -p out/ios_arm64_mtl
cat > out/ios_arm64_mtl/args.gn <<EOM
target_os="ios"
target_cpu="arm64"
skia_use_metal=true
skia_use_expat=false
skia_enable_pdf=false
EOM
tools/git-sync-deps
bin/gn gen out/ios_arm64_mtl
ninja -C out/ios_arm64_mtl skottie_example
Then install the `out/ios_arm64_mtl/skottie_example.app` bundle.
## CPU
How to compile for the CPU backend:
cd $SKIA_ROOT_DIRECTORY
mkdir -p out/ios_arm64_cpu
cat > out/ios_arm64_cpu/args.gn <<EOM
target_cpu="arm64"
target_os="ios"
skia_enable_gpu=false
skia_enable_pdf=false
skia_use_expat=false
tools/git-sync-deps
bin/gn gen out/ios_arm64_cpu
ninja -C out/ios_arm64_cpu skottie_example
Then install the `out/ios_arm64_cpu/skottie_example.app` bundle.

View File

@ -5,14 +5,19 @@
#import <MetalKit/MetalKit.h> #import <MetalKit/MetalKit.h>
#include <memory>
class SkSurface; class SkSurface;
class GrContext; class GrContext;
class GrContextOptions;
template <typename T> class sk_sp; template <typename T> class sk_sp;
sk_sp<SkSurface> SkMtkViewToSurface(MTKView*, GrContext*); sk_sp<SkSurface> SkMtkViewToSurface(MTKView*, GrContext*);
sk_sp<GrContext> SkMetalDeviceToGrContext(id<MTLDevice>, id<MTLCommandQueue>, const GrContextOptions&); struct GrContextRelease { void operator()(GrContext*); };
using GrContextHolder = std::unique_ptr<GrContext, GrContextRelease>;
GrContextHolder SkMetalDeviceToGrContext(id<MTLDevice>, id<MTLCommandQueue>);
void SkMtkViewConfigForSkia(MTKView*); void SkMtkViewConfigForSkia(MTKView*);

View File

@ -1,7 +1,7 @@
// Copyright 2019 Google LLC. // Copyright 2019 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "experimental/skottie_ios/SkMetalViewBridge.h" #include "tools/skottie_ios_app/SkMetalViewBridge.h"
#include "include/core/SkSurface.h" #include "include/core/SkSurface.h"
#include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrBackendSurface.h"
@ -41,8 +41,13 @@ sk_sp<SkSurface> SkMtkViewToSurface(MTKView* mtkView, GrContext* grContext) {
} }
} }
sk_sp<GrContext> SkMetalDeviceToGrContext(id<MTLDevice> device, id<MTLCommandQueue> queue, const GrContextOptions& opts) { void GrContextRelease::operator()(GrContext* ptr) { SkSafeUnref(ptr); }
return GrContext::MakeMetal((__bridge void*)device, (__bridge void*)queue, opts);
GrContextHolder SkMetalDeviceToGrContext(id<MTLDevice> device, id<MTLCommandQueue> queue) {
GrContextOptions grContextOptions; // set different options here.
return GrContextHolder(GrContext::MakeMetal((__bridge void*)device,
(__bridge void*)queue,
grContextOptions).release());
} }
void SkMtkViewConfigForSkia(MTKView* mtkView) { void SkMtkViewConfigForSkia(MTKView* mtkView) {

View File

@ -1,10 +1,10 @@
//Copyright 2019 Google LLC. //Copyright 2019 Google LLC.
//Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. //Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "experimental/skottie_ios/SkottieMtkView.h" #include "tools/skottie_ios_app/SkottieMtkView.h"
#include "experimental/skottie_ios/SkAnimationDraw.h" #include "tools/skottie_ios_app/SkAnimationDraw.h"
#include "experimental/skottie_ios/SkTimeKeeper.h" #include "tools/skottie_ios_app/SkTimeKeeper.h"
#include "include/core/SkCanvas.h" #include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h" #include "include/core/SkPaint.h"
@ -13,7 +13,7 @@
#include "modules/skottie/include/Skottie.h" #include "modules/skottie/include/Skottie.h"
#include "experimental/skottie_ios/SkMetalViewBridge.h" #include "tools/skottie_ios_app/SkMetalViewBridge.h"
@implementation SkottieMtkView { @implementation SkottieMtkView {
SkAnimationDraw fDraw; SkAnimationDraw fDraw;

View File

@ -1,10 +1,10 @@
// Copyright 2019 Google LLC. // Copyright 2019 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "experimental/skottie_ios/SkottieUIView.h" #include "tools/skottie_ios_app/SkottieUIView.h"
#include "experimental/skottie_ios/SkAnimationDraw.h" #include "tools/skottie_ios_app/SkAnimationDraw.h"
#include "experimental/skottie_ios/SkTimeKeeper.h" #include "tools/skottie_ios_app/SkTimeKeeper.h"
#include "include/core/SkCanvas.h" #include "include/core/SkCanvas.h"
#include "include/core/SkPaint.h" #include "include/core/SkPaint.h"

View File

@ -4,16 +4,13 @@
#include "include/core/SkTypes.h" #include "include/core/SkTypes.h"
#ifdef SK_METAL #ifdef SK_METAL
#include "experimental/skottie_ios/SkMetalViewBridge.h" #include "tools/skottie_ios_app/SkMetalViewBridge.h"
#include "experimental/skottie_ios/SkottieMtkView.h" #include "tools/skottie_ios_app/SkottieMtkView.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/GrContextOptions.h"
#import <Metal/Metal.h> #import <Metal/Metal.h>
#import <MetalKit/MetalKit.h> #import <MetalKit/MetalKit.h>
#else #else
#include "experimental/skottie_ios/SkottieUIView.h" #include "tools/skottie_ios_app/SkottieUIView.h"
#endif #endif
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@ -81,7 +78,7 @@ static UIStackView* make_skottie_stack(CGFloat width) {
@implementation AppViewController { @implementation AppViewController {
#ifdef SK_METAL #ifdef SK_METAL
sk_sp<GrContext> fGrContext; GrContextHolder fGrContext;
#endif #endif
} }
@ -99,9 +96,7 @@ static UIStackView* make_skottie_stack(CGFloat width) {
return; return;
} }
[self setMetalQueue:[[self metalDevice] newCommandQueue]]; [self setMetalQueue:[[self metalDevice] newCommandQueue]];
GrContextOptions grContextOptions; // set different options here. fGrContext = SkMetalDeviceToGrContext([self metalDevice], [self metalQueue]);
fGrContext = SkMetalDeviceToGrContext([self metalDevice], [self metalQueue],
grContextOptions);
} }
[self setStackView:make_skottie_stack([[UIScreen mainScreen] bounds].size.width, [self setStackView:make_skottie_stack([[UIScreen mainScreen] bounds].size.width,
[self metalDevice], [self metalQueue], fGrContext.get())]; [self metalDevice], [self metalQueue], fGrContext.get())];