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:
parent
d6df7b55a5
commit
efb4ed86cf
2
BUILD.gn
2
BUILD.gn
@ -2514,7 +2514,7 @@ if (is_ios && skia_use_metal && !skia_enable_flutter_defines) {
|
||||
if (is_ios && !skia_enable_flutter_defines) {
|
||||
group("skottie_ios") {
|
||||
deps = [
|
||||
"experimental/skottie_ios",
|
||||
"tools/skottie_ios_app",
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
// 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/SkPaint.h"
|
||||
@ -14,8 +14,6 @@
|
||||
#include "include/core/SkTime.h"
|
||||
#include "include/effects/SkGradientShader.h"
|
||||
#include "include/gpu/GrBackendSurface.h"
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "include/gpu/GrContextOptions.h"
|
||||
#include "include/gpu/mtl/GrMtlTypes.h"
|
||||
|
||||
#import <Metal/Metal.h>
|
||||
@ -90,7 +88,7 @@ static void draw_example(SkSurface* surface, const SkPaint& paint, double rotati
|
||||
@end
|
||||
|
||||
@implementation AppViewController {
|
||||
sk_sp<GrContext> fGrContext;
|
||||
GrContextHolder fGrContext;
|
||||
}
|
||||
|
||||
- (void)loadView {
|
||||
@ -102,8 +100,7 @@ static void draw_example(SkSurface* surface, const SkPaint& paint, double rotati
|
||||
if (!fGrContext) {
|
||||
[self setMetalDevice:MTLCreateSystemDefaultDevice()];
|
||||
[self setMetalQueue:[[self metalDevice] newCommandQueue]];
|
||||
GrContextOptions grContextOptions; // set different options here.
|
||||
fGrContext = SkMetalDeviceToGrContext([self metalDevice], [self metalQueue], grContextOptions);
|
||||
fGrContext = SkMetalDeviceToGrContext([self metalDevice], [self metalQueue]);
|
||||
}
|
||||
if (![self view] || ![self metalDevice]) {
|
||||
NSLog(@"Metal is not supported on this device");
|
||||
|
@ -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.
|
||||
|
@ -18,7 +18,15 @@
|
||||
'../../dm',
|
||||
'../../docs/examples',
|
||||
'../../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',
|
||||
'../../gm',
|
||||
'../../gn',
|
||||
|
@ -5,7 +5,12 @@
|
||||
import("../../gn/ios.gni")
|
||||
|
||||
if (is_ios) {
|
||||
ios_app_bundle("skottie_ios") {
|
||||
group("skottie_ios_app") {
|
||||
deps = [
|
||||
":skottie_example",
|
||||
]
|
||||
}
|
||||
ios_app_bundle("skottie_example") {
|
||||
sources = [
|
||||
"SkAnimationDraw.h",
|
||||
"SkTimeKeeper.h",
|
42
tools/skottie_ios_app/README.md
Normal file
42
tools/skottie_ios_app/README.md
Normal 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.
|
@ -5,14 +5,19 @@
|
||||
|
||||
#import <MetalKit/MetalKit.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
class SkSurface;
|
||||
class GrContext;
|
||||
class GrContextOptions;
|
||||
template <typename T> class sk_sp;
|
||||
|
||||
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*);
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// 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/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) {
|
||||
return GrContext::MakeMetal((__bridge void*)device, (__bridge void*)queue, opts);
|
||||
void GrContextRelease::operator()(GrContext* ptr) { SkSafeUnref(ptr); }
|
||||
|
||||
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) {
|
@ -1,10 +1,10 @@
|
||||
//Copyright 2019 Google LLC.
|
||||
//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 "experimental/skottie_ios/SkTimeKeeper.h"
|
||||
#include "tools/skottie_ios_app/SkAnimationDraw.h"
|
||||
#include "tools/skottie_ios_app/SkTimeKeeper.h"
|
||||
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkPaint.h"
|
||||
@ -13,7 +13,7 @@
|
||||
|
||||
#include "modules/skottie/include/Skottie.h"
|
||||
|
||||
#include "experimental/skottie_ios/SkMetalViewBridge.h"
|
||||
#include "tools/skottie_ios_app/SkMetalViewBridge.h"
|
||||
|
||||
@implementation SkottieMtkView {
|
||||
SkAnimationDraw fDraw;
|
@ -1,10 +1,10 @@
|
||||
// Copyright 2019 Google LLC.
|
||||
// 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 "experimental/skottie_ios/SkTimeKeeper.h"
|
||||
#include "tools/skottie_ios_app/SkAnimationDraw.h"
|
||||
#include "tools/skottie_ios_app/SkTimeKeeper.h"
|
||||
|
||||
#include "include/core/SkCanvas.h"
|
||||
#include "include/core/SkPaint.h"
|
@ -4,16 +4,13 @@
|
||||
#include "include/core/SkTypes.h"
|
||||
|
||||
#ifdef SK_METAL
|
||||
#include "experimental/skottie_ios/SkMetalViewBridge.h"
|
||||
#include "experimental/skottie_ios/SkottieMtkView.h"
|
||||
|
||||
#include "include/gpu/GrContext.h"
|
||||
#include "include/gpu/GrContextOptions.h"
|
||||
#include "tools/skottie_ios_app/SkMetalViewBridge.h"
|
||||
#include "tools/skottie_ios_app/SkottieMtkView.h"
|
||||
|
||||
#import <Metal/Metal.h>
|
||||
#import <MetalKit/MetalKit.h>
|
||||
#else
|
||||
#include "experimental/skottie_ios/SkottieUIView.h"
|
||||
#include "tools/skottie_ios_app/SkottieUIView.h"
|
||||
#endif
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
@ -81,7 +78,7 @@ static UIStackView* make_skottie_stack(CGFloat width) {
|
||||
|
||||
@implementation AppViewController {
|
||||
#ifdef SK_METAL
|
||||
sk_sp<GrContext> fGrContext;
|
||||
GrContextHolder fGrContext;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -99,9 +96,7 @@ static UIStackView* make_skottie_stack(CGFloat width) {
|
||||
return;
|
||||
}
|
||||
[self setMetalQueue:[[self metalDevice] newCommandQueue]];
|
||||
GrContextOptions grContextOptions; // set different options here.
|
||||
fGrContext = SkMetalDeviceToGrContext([self metalDevice], [self metalQueue],
|
||||
grContextOptions);
|
||||
fGrContext = SkMetalDeviceToGrContext([self metalDevice], [self metalQueue]);
|
||||
}
|
||||
[self setStackView:make_skottie_stack([[UIScreen mainScreen] bounds].size.width,
|
||||
[self metalDevice], [self metalQueue], fGrContext.get())];
|
Loading…
Reference in New Issue
Block a user