myplspatch

This commit is contained in:
Chris Dalton
2023-09-08 08:26:00 -06:00
parent 5afb83146c
commit 9623029b0c
8 changed files with 130 additions and 296 deletions

View File

@@ -7,12 +7,14 @@
//
import UIKit
import RiveRuntime
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
RenderContextManager.shared().defaultRenderer = RendererType.skiaRenderer
return true
}

View File

@@ -44,10 +44,13 @@
04BE5436264D2A7500427B39 /* RivePrivateHeaders.h in Headers */ = {isa = PBXBuildFile; fileRef = 04BE5435264D2A7500427B39 /* RivePrivateHeaders.h */; };
04ED72F1299C114000E8DE53 /* RiveViewModelTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04ED72F0299C114000E8DE53 /* RiveViewModelTest.swift */; };
04ED72F3299C115100E8DE53 /* empty_animation_state.riv in Resources */ = {isa = PBXBuildFile; fileRef = 04ED72F2299C115100E8DE53 /* empty_animation_state.riv */; };
274175FD286DB9CE000A60D1 /* cg_skia_factory.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 274175FB286DB9CE000A60D1 /* cg_skia_factory.hpp */; };
274175FE286DB9CE000A60D1 /* cg_skia_factory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 274175FC286DB9CE000A60D1 /* cg_skia_factory.cpp */; };
2A7079352726277C00C035A1 /* rive_renderer_view.hh in Headers */ = {isa = PBXBuildFile; fileRef = 2A7079342726277C00C035A1 /* rive_renderer_view.hh */; settings = {ATTRIBUTES = (Public, ); }; };
2A707937272628AD00C035A1 /* rive_renderer_view.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2A707936272628AD00C035A1 /* rive_renderer_view.mm */; };
83DE4C912AA8DD7B00B88B72 /* RenderContextManager.mm in Sources */ = {isa = PBXBuildFile; fileRef = 83DE4C902AA8DD7B00B88B72 /* RenderContextManager.mm */; };
83DE4C932AA8DD9F00B88B72 /* RenderContextManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 83DE4C922AA8DD9F00B88B72 /* RenderContextManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
83DE4CA02AAA072B00B88B72 /* PlatformCGImage.mm in Sources */ = {isa = PBXBuildFile; fileRef = 83DE4C9F2AAA072B00B88B72 /* PlatformCGImage.mm */; };
83DE4CA22AAA077200B88B72 /* PlatformCGImage.h in Headers */ = {isa = PBXBuildFile; fileRef = 83DE4CA12AAA077200B88B72 /* PlatformCGImage.h */; };
83DE4CA72AAAE72100B88B72 /* RenderContext.hh in Headers */ = {isa = PBXBuildFile; fileRef = 83DE4CA62AAAE72000B88B72 /* RenderContext.hh */; };
C34609FC27FF9114002DBCB7 /* RiveFile+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = C34609FB27FF9114002DBCB7 /* RiveFile+Extensions.swift */; };
C3468E5827EB9887008652FD /* RiveView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3468E5727EB9887008652FD /* RiveView.swift */; };
C3468E5A27ECC7C6008652FD /* RiveViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3468E5927ECC7C6008652FD /* RiveViewModel.swift */; };
@@ -116,10 +119,13 @@
04BE5435264D2A7500427B39 /* RivePrivateHeaders.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RivePrivateHeaders.h; sourceTree = "<group>"; };
04ED72F0299C114000E8DE53 /* RiveViewModelTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RiveViewModelTest.swift; sourceTree = "<group>"; };
04ED72F2299C115100E8DE53 /* empty_animation_state.riv */ = {isa = PBXFileReference; lastKnownFileType = file; path = empty_animation_state.riv; sourceTree = "<group>"; };
274175FB286DB9CE000A60D1 /* cg_skia_factory.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = cg_skia_factory.hpp; sourceTree = "<group>"; };
274175FC286DB9CE000A60D1 /* cg_skia_factory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cg_skia_factory.cpp; sourceTree = "<group>"; };
2A7079342726277C00C035A1 /* rive_renderer_view.hh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = rive_renderer_view.hh; sourceTree = "<group>"; };
2A707936272628AD00C035A1 /* rive_renderer_view.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = rive_renderer_view.mm; sourceTree = "<group>"; };
83DE4C902AA8DD7B00B88B72 /* RenderContextManager.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = RenderContextManager.mm; path = Source/Renderer/RenderContextManager.mm; sourceTree = SOURCE_ROOT; };
83DE4C922AA8DD9F00B88B72 /* RenderContextManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderContextManager.h; sourceTree = "<group>"; };
83DE4C9F2AAA072B00B88B72 /* PlatformCGImage.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformCGImage.mm; sourceTree = "<group>"; };
83DE4CA12AAA077200B88B72 /* PlatformCGImage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformCGImage.h; sourceTree = "<group>"; };
83DE4CA62AAAE72000B88B72 /* RenderContext.hh */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = RenderContext.hh; sourceTree = "<group>"; };
C34609FB27FF9114002DBCB7 /* RiveFile+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "RiveFile+Extensions.swift"; sourceTree = "<group>"; };
C3468E5727EB9887008652FD /* RiveView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RiveView.swift; sourceTree = "<group>"; };
C3468E5927ECC7C6008652FD /* RiveViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RiveViewModel.swift; sourceTree = "<group>"; };
@@ -165,6 +171,7 @@
046FB801264EB632000129B1 /* include */ = {
isa = PBXGroup;
children = (
83DE4CA12AAA077200B88B72 /* PlatformCGImage.h */,
C9C741F224FC510200EF9516 /* Rive.h */,
046FB7E7264EAA5F000129B1 /* RiveFile.h */,
046FB7EC264EAA60000129B1 /* RiveArtboard.h */,
@@ -175,8 +182,9 @@
C9601F29250C25830032AA07 /* RiveRenderer.hpp */,
04BE542F264D1F4100427B39 /* LayerState.h */,
04BE5435264D2A7500427B39 /* RivePrivateHeaders.h */,
274175FB286DB9CE000A60D1 /* cg_skia_factory.hpp */,
E57798A12A72C81F00FF25C3 /* RiveTextValueRun.h */,
83DE4CA62AAAE72000B88B72 /* RenderContext.hh */,
83DE4C922AA8DD9F00B88B72 /* RenderContextManager.h */,
);
path = include;
sourceTree = "<group>";
@@ -219,6 +227,7 @@
isa = PBXGroup;
children = (
046FB801264EB632000129B1 /* include */,
83DE4C9F2AAA072B00B88B72 /* PlatformCGImage.mm */,
C9C741F324FC510200EF9516 /* Rive.mm */,
046FB7EF264EAA60000129B1 /* RiveFile.mm */,
046FB7E2264EAA5E000129B1 /* RiveArtboard.mm */,
@@ -229,7 +238,7 @@
C9601F2A250C25930032AA07 /* RiveRenderer.mm */,
E57798A52A72C9C500FF25C3 /* RiveTextValueRun.mm */,
04BE5431264D243D00427B39 /* LayerState.mm */,
274175FC286DB9CE000A60D1 /* cg_skia_factory.cpp */,
83DE4C902AA8DD7B00B88B72 /* RenderContextManager.mm */,
);
path = Renderer;
sourceTree = "<group>";
@@ -304,7 +313,8 @@
046FB7F7264EAA60000129B1 /* RiveFile.h in Headers */,
046FB7FC264EAA61000129B1 /* RiveArtboard.h in Headers */,
2A7079352726277C00C035A1 /* rive_renderer_view.hh in Headers */,
274175FD286DB9CE000A60D1 /* cg_skia_factory.hpp in Headers */,
83DE4CA22AAA077200B88B72 /* PlatformCGImage.h in Headers */,
83DE4C932AA8DD9F00B88B72 /* RenderContextManager.h in Headers */,
046FB800264EAA61000129B1 /* RiveStateMachineInstance.h in Headers */,
046FB7FB264EAA61000129B1 /* RiveSMIInput.h in Headers */,
E57798A72A72EEAD00FF25C3 /* RiveTextValueRun.h in Headers */,
@@ -313,6 +323,7 @@
C9C741F424FC510200EF9516 /* Rive.h in Headers */,
04BE5436264D2A7500427B39 /* RivePrivateHeaders.h in Headers */,
C9C73EE224FC478900EF9516 /* RiveRuntime.h in Headers */,
83DE4CA72AAAE72100B88B72 /* RenderContext.hh in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -432,11 +443,13 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
83DE4CA02AAA072B00B88B72 /* PlatformCGImage.mm in Sources */,
2A707937272628AD00C035A1 /* rive_renderer_view.mm in Sources */,
C34609FC27FF9114002DBCB7 /* RiveFile+Extensions.swift in Sources */,
C3468E5827EB9887008652FD /* RiveView.swift in Sources */,
04BE5434264D267900427B39 /* LayerState.mm in Sources */,
C9601F2B250C25930032AA07 /* RiveRenderer.mm in Sources */,
83DE4C912AA8DD7B00B88B72 /* RenderContextManager.mm in Sources */,
C3E2B580282F242400A8651B /* RiveStateMachineInstance+Extensions.swift in Sources */,
046FB7F5264EAA60000129B1 /* RiveSMIInput.mm in Sources */,
C3468E5A27ECC7C6008652FD /* RiveViewModel.swift in Sources */,
@@ -444,7 +457,6 @@
C9C741F524FC510200EF9516 /* Rive.mm in Sources */,
046FB7F8264EAA60000129B1 /* RiveStateMachineInstance.mm in Sources */,
C3468E5C27ED4C41008652FD /* RiveModel.swift in Sources */,
274175FE286DB9CE000A60D1 /* cg_skia_factory.cpp in Sources */,
046FB7FF264EAA61000129B1 /* RiveFile.mm in Sources */,
046FB7F2264EAA60000129B1 /* RiveArtboard.mm in Sources */,
046FB7F4264EAA60000129B1 /* RiveLinearAnimationInstance.mm in Sources */,
@@ -639,6 +651,7 @@
dependencies/includes/skia/include/config,
dependencies/includes/rive/include,
dependencies/includes/renderer/include,
dependencies/includes/pls/include,
);
INFOPLIST_FILE = Source/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
@@ -663,6 +676,7 @@
"-lrive_harfbuzz",
"-lrive_sheenbidi",
"-lrive_skia_renderer",
"-lrive_pls_renderer",
);
"OTHER_LDFLAGS[sdk=iphonesimulator*]" = (
"-lskia_ios_sim",
@@ -670,12 +684,14 @@
"-lrive_harfbuzz_sim",
"-lrive_sheenbidi_sim",
"-lrive_skia_renderer_sim",
"-lrive_pls_renderer_sim",
);
"OTHER_LDFLAGS[sdk=macosx*]" = (
"-lskia_macos",
"-lrive_harfbuzz_macos",
"-lrive_sheenbidi_macos",
"-lrive_skia_renderer_macos",
"-lrive_pls_renderer_macos",
);
PRODUCT_BUNDLE_IDENTIFIER = rive.app.ios.runtime.RiveRuntime;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
@@ -716,6 +732,7 @@
dependencies/includes/skia/include/config,
dependencies/includes/rive/include,
dependencies/includes/renderer/include,
dependencies/includes/pls/include,
);
INFOPLIST_FILE = Source/Info.plist;
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
@@ -742,6 +759,7 @@
"-lrive_harfbuzz",
"-lrive_sheenbidi",
"-lrive_skia_renderer",
"-lrive_pls_renderer",
);
"OTHER_LDFLAGS[sdk=iphonesimulator*]" = (
"-lskia_ios_sim",
@@ -749,6 +767,7 @@
"-lrive_harfbuzz_sim",
"-lrive_sheenbidi_sim",
"-lrive_skia_renderer_sim",
"-lrive_pls_renderer_sim",
);
"OTHER_LDFLAGS[sdk=macosx*]" = (
"-lskia_macos",
@@ -756,6 +775,7 @@
"-lrive_harfbuzz_macos",
"-lrive_sheenbidi_macos",
"-lrive_skia_renderer_macos",
"-lrive_pls_renderer_macos",
);
PRODUCT_BUNDLE_IDENTIFIER = rive.app.ios.runtime.RiveRuntime;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";

View File

@@ -8,9 +8,8 @@
#import <Rive.h>
#import <RivePrivateHeaders.h>
#import <cg_skia_factory.hpp>
static rive::CGSkiaFactory gFactory;
#import <RenderContext.hh>
#import <RenderContextManager.h>
/*
* RiveFile
@@ -151,7 +150,9 @@ static rive::CGSkiaFactory gFactory;
- (BOOL)import:(UInt8*)bytes byteLength:(UInt64)length error:(NSError**)error
{
rive::ImportResult result;
auto file = rive::File::import(rive::Span(bytes, length), &gFactory, &result);
RenderContext* defaultContext = [[RenderContextManager shared] getDefaultContext];
rive::Factory* factory = [defaultContext factory];
auto file = rive::File::import(rive::Span(bytes, length), factory, &result);
if (result == rive::ImportResult::success)
{
riveFile = std::move(file);

View File

@@ -1,112 +0,0 @@
/*
* Copyright 2022 Rive
*/
#include "cg_skia_factory.hpp"
#include "rive/core/type_conversions.hpp"
#include <vector>
#ifdef RIVE_BUILD_FOR_APPLE
#if defined(RIVE_BUILD_FOR_OSX)
#include <ApplicationServices/ApplicationServices.h>
#elif defined(RIVE_BUILD_FOR_IOS)
#include <CoreGraphics/CoreGraphics.h>
#include <ImageIO/ImageIO.h>
#endif
// Helper that remembers to call CFRelease when an object goes out of scope.
template <typename T> class AutoCF
{
T m_Obj;
public:
AutoCF(T obj) : m_Obj(obj) {}
~AutoCF()
{
if (m_Obj)
CFRelease(m_Obj);
}
operator T() const { return m_Obj; }
operator bool() const { return m_Obj != nullptr; }
T get() const { return m_Obj; }
};
using namespace rive;
std::vector<uint8_t> CGSkiaFactory::platformDecode(Span<const uint8_t> span,
SkiaFactory::ImageInfo* info)
{
std::vector<uint8_t> pixels;
AutoCF data = CFDataCreateWithBytesNoCopy(nullptr, span.data(), span.size(), nullptr);
if (!data)
{
return pixels;
}
AutoCF source = CGImageSourceCreateWithData(data, nullptr);
if (!source)
{
return pixels;
}
AutoCF image = CGImageSourceCreateImageAtIndex(source, 0, nullptr);
if (!image)
{
return pixels;
}
bool isOpaque = false;
switch (CGImageGetAlphaInfo(image.get()))
{
case kCGImageAlphaNone:
case kCGImageAlphaNoneSkipFirst:
case kCGImageAlphaNoneSkipLast:
isOpaque = true;
break;
default:
break;
}
// Now create a drawing context to produce RGBA pixels
const size_t bitsPerComponent = 8;
CGBitmapInfo cgInfo = kCGBitmapByteOrder32Big; // rgba
if (isOpaque)
{
cgInfo |= kCGImageAlphaNoneSkipLast;
}
else
{
cgInfo |= kCGImageAlphaPremultipliedLast; // premul
}
const size_t width = CGImageGetWidth(image);
const size_t height = CGImageGetHeight(image);
const size_t rowBytes = width * 4; // 4 bytes per pixel
const size_t size = rowBytes * height;
pixels.resize(size);
AutoCF cs = CGColorSpaceCreateDeviceRGB();
AutoCF cg =
CGBitmapContextCreate(pixels.data(), width, height, bitsPerComponent, rowBytes, cs, cgInfo);
if (!cg)
{
pixels.clear();
return pixels;
}
CGContextSetBlendMode(cg, kCGBlendModeCopy);
CGContextDrawImage(cg, CGRectMake(0, 0, width, height), image);
info->alphaType = isOpaque ? AlphaType::opaque : AlphaType::premul;
info->colorType = ColorType::rgba;
info->width = castTo<uint32_t>(width);
info->height = castTo<uint32_t>(height);
info->rowBytes = rowBytes;
return pixels;
};
#endif // RIVE_BUILD_FOR_APPLE

View File

@@ -19,6 +19,7 @@
#import <RiveRuntime/RiveStateMachineInstance.h>
#import <RiveRuntime/RiveTextValueRun.h>
#import <RiveRuntime/LayerState.h>
#import <RiveRuntime/RenderContextManager.h>
NS_ASSUME_NONNULL_BEGIN

View File

@@ -1,18 +0,0 @@
/*
* Copyright 2022 Rive
*/
#ifndef _RIVE_CGSkiaFactory_HPP_
#define _RIVE_CGSkiaFactory_HPP_
#include "skia_factory.hpp"
namespace rive
{
struct CGSkiaFactory : public SkiaFactory
{
std::vector<uint8_t> platformDecode(Span<const uint8_t>, SkiaFactory::ImageInfo*) override;
};
} // namespace rive
#endif // _RIVE_CGSkiaFactory_HPP_

View File

@@ -9,153 +9,40 @@
#import <AppKit/AppKit.h>
#endif
#include "include/core/SkCanvas.h"
#include "include/core/SkSurface.h"
#include "include/core/SkSurfaceProps.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/mtl/GrMtlBackendContext.h"
#include "skia_renderer.hpp"
#import "RivePrivateHeaders.h"
/// SkiaMetalContext knows how to construct & provide a graphics context for a given device.
/// This Can be used directly as an alternative to using the SkiaContextManager, for more
/// fine grained control of skia contexts
@interface SkiaMetalContext : NSObject
@property(strong) id<MTLDevice> metalDevice;
@property(strong) id<MTLCommandQueue> metalQueue;
@property sk_sp<GrDirectContext> graphicsContext;
@end
@implementation SkiaMetalContext
- (instancetype)init
{
self = [super init];
[self setMetalDevice:MTLCreateSystemDefaultDevice()];
if (![self metalDevice])
{
NSLog(@"Metal is not supported on this device");
return nil;
}
[self setMetalQueue:[[self metalDevice] newCommandQueue]];
GrMtlBackendContext metalBackendContext;
metalBackendContext.fDevice = sk_ret_cfp((__bridge const void*)self.metalDevice);
metalBackendContext.fQueue = sk_ret_cfp((__bridge const void*)self.metalQueue);
_graphicsContext = GrDirectContext::MakeMetal(metalBackendContext, GrContextOptions());
if (!_graphicsContext)
{
NSLog(@"GrDirectContext::MakeMetal failed");
return nil;
}
return self;
}
- (void)dealloc
{
_graphicsContext.reset(nil);
}
@end
SkiaMetalContext* MakeSkiaMetalContext() { return [[SkiaMetalContext alloc] init]; }
/// The SkiaContextManager is used to allow us to share a skia context, while there is an active
/// view. It has a weak ref to a SkiaMetalContext, which means that when no more RiveRenderViews
/// require these, they can be freed When that drops to 0, we allow the SkiaContext to be garbage
/// collected.
@interface SkiaContextManager : NSObject
- (SkiaMetalContext*)getContext;
+ (SkiaContextManager*)shared;
@end
@implementation SkiaContextManager
__weak SkiaMetalContext* skiaMetalContext;
// The context manager is a singleton.
+ (SkiaContextManager*)shared
{
static SkiaContextManager* single = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
single = [[self alloc] init];
});
return single;
}
- (SkiaMetalContext*)getContext
{
if (skiaMetalContext != nullptr)
{
return skiaMetalContext;
}
else
{
SkiaMetalContext* temp = skiaMetalContext = MakeSkiaMetalContext();
skiaMetalContext = temp;
return temp;
}
}
@end
sk_sp<SkSurface> SkMtkViewToSurface(MTKView* mtkView, GrDirectContext* grContext)
{
if (!grContext || MTLPixelFormatDepth32Float_Stencil8 != [mtkView depthStencilPixelFormat] ||
MTLPixelFormatBGRA8Unorm != [mtkView colorPixelFormat])
{
return nullptr;
}
const SkColorType colorType = kBGRA_8888_SkColorType;
sk_sp<SkColorSpace> colorSpace = nullptr;
const GrSurfaceOrigin origin = kTopLeft_GrSurfaceOrigin;
const SkSurfaceProps surfaceProps(SkSurfaceProps::kUseDeviceIndependentFonts_Flag,
SkPixelGeometry::kUnknown_SkPixelGeometry);
int sampleCount = (int)[mtkView sampleCount];
return SkSurface::MakeFromMTKView(grContext,
(__bridge GrMTLHandle)mtkView,
origin,
sampleCount,
colorType,
colorSpace,
&surfaceProps);
}
#import <RenderContext.hh>
#import <RenderContextManager.h>
@implementation RiveRendererView
{
SkiaMetalContext* skiaContext;
rive::SkiaRenderer* _renderer;
RenderContext* renderContext;
rive::Renderer* _renderer;
}
- (instancetype)initWithCoder:(NSCoder*)decoder
{
self = [super initWithCoder:decoder];
skiaContext = [[SkiaContextManager shared] getContext];
self.device = [skiaContext metalDevice];
renderContext = [[RenderContextManager shared] getDefaultContext];
self.device = [renderContext metalDevice];
[self setDepthStencilPixelFormat:MTLPixelFormatDepth32Float_Stencil8];
[self setDepthStencilPixelFormat:renderContext.depthStencilPixelFormat];
[self setColorPixelFormat:MTLPixelFormatBGRA8Unorm];
[self setFramebufferOnly:false];
[self setFramebufferOnly:renderContext.framebufferOnly];
[self setSampleCount:1];
return self;
}
- (instancetype)initWithFrame:(CGRect)frameRect
{
skiaContext = [[SkiaContextManager shared] getContext];
renderContext = [[RenderContextManager shared] getDefaultContext];
auto value = [super initWithFrame:frameRect device:[skiaContext metalDevice]];
auto value = [super initWithFrame:frameRect device:renderContext.metalDevice];
[self setDepthStencilPixelFormat:MTLPixelFormatDepth32Float_Stencil8];
[self setDepthStencilPixelFormat:renderContext.depthStencilPixelFormat];
[self setColorPixelFormat:MTLPixelFormatBGRA8Unorm];
[self setFramebufferOnly:false];
[self setFramebufferOnly:renderContext.framebufferOnly];
[self setSampleCount:1];
// [self setPreferredFramesPerSecond:60];
return value;
}
@@ -202,28 +89,15 @@ sk_sp<SkSurface> SkMtkViewToSurface(MTKView* mtkView, GrDirectContext* grContext
{
return;
}
CGSize size = [self drawableSize];
sk_sp<SkSurface> surface = SkMtkViewToSurface(self, [skiaContext graphicsContext].get());
if (!surface)
{
NSLog(@"error: no sksurface");
return;
}
auto canvas = surface->getCanvas();
rive::SkiaRenderer renderer(canvas);
_renderer = &renderer;
canvas->clear(SkColor((0x00000000)));
_renderer = [renderContext beginFrame:self];
_renderer->save();
[self drawRive:rect size:size];
[self drawRive:rect size:self.drawableSize];
_renderer->restore();
surface->flushAndSubmit();
surface = nullptr;
[renderContext endFrame];
_renderer = nullptr;
id<MTLCommandBuffer> commandBuffer = [[skiaContext metalQueue] commandBuffer];
id<MTLCommandBuffer> commandBuffer = [renderContext.metalQueue commandBuffer];
[commandBuffer presentDrawable:[self currentDrawable]];
[commandBuffer commit];
bool paused = [self isPaused];

View File

@@ -13,6 +13,8 @@ else
export RIVE_RUNTIME_DIR="$DEV_SCRIPT_DIR/../../runtime"
fi
RIVE_PLS_DIR=$RIVE_RUNTIME_DIR/../pls
make_dependency_directories() {
rm -fr $DEV_SCRIPT_DIR/../dependencies
@@ -23,9 +25,10 @@ make_dependency_directories() {
mkdir -p $DEV_SCRIPT_DIR/../dependencies/includes/skia
mkdir -p $DEV_SCRIPT_DIR/../dependencies/includes/renderer
mkdir -p $DEV_SCRIPT_DIR/../dependencies/includes/rive
mkdir -p $DEV_SCRIPT_DIR/../dependencies/includes/pls
}
build_renderer() {
build_skia_renderer() {
# NOTE: we do not currently use debug, so lets not build debug
pushd $RIVE_RUNTIME_DIR/skia/renderer
./build.sh -p ios clean
@@ -40,7 +43,7 @@ build_renderer() {
cp -r $RIVE_RUNTIME_DIR/include $DEV_SCRIPT_DIR/../dependencies/includes/rive
}
build_renderer_sim() {
build_skia_renderer_sim() {
# NOTE: we do not currently use debug, so lets not build debug
pushd $RIVE_RUNTIME_DIR/skia/renderer
./build.sh -p ios_sim clean
@@ -56,7 +59,7 @@ build_renderer_sim() {
cp -r $RIVE_RUNTIME_DIR/include $DEV_SCRIPT_DIR/../dependencies/includes/rive
}
build_renderer_macosx() {
build_skia_renderer_macosx() {
# NOTE: we do not currently use debug, so lets not build debug
pushd $RIVE_RUNTIME_DIR/skia/renderer
./build.sh -p macosx clean
@@ -71,6 +74,60 @@ build_renderer_macosx() {
cp -r $RIVE_RUNTIME_DIR/include $DEV_SCRIPT_DIR/../dependencies/includes/rive
}
build_pls_renderer() {
if [ -d "$RIVE_PLS_DIR" ]; then
pushd $RIVE_PLS_DIR/out
premake5 --scripts=$RIVE_RUNTIME_DIR/build --file=premake5_pls_renderer.lua --no-rive-decoders --os=ios gmake2
make config=$1 clean
make config=$1 -j12 rive_pls_renderer
popd
cp -r $RIVE_PLS_DIR/out/iphoneos_$1/librive_pls_renderer.a $DEV_SCRIPT_DIR/../dependencies/$1/librive_pls_renderer.a
cp -r $RIVE_PLS_DIR/include $DEV_SCRIPT_DIR/../dependencies/includes/pls
else
# TODO: this fixes the compile without PLS, but linking will still fail because it won't
# find librive_pls_renderer.a.
cp -r $DEV_SCRIPT_DIR/../Source/Renderer/NullPLS/include $DEV_SCRIPT_DIR/../dependencies/includes/pls
fi
}
build_pls_renderer_sim() {
if [ -d "$RIVE_PLS_DIR" ]; then
pushd $RIVE_PLS_DIR/out
premake5 --scripts=$RIVE_RUNTIME_DIR/build --file=premake5_pls_renderer.lua --no-rive-decoders --os=ios --variant=simulator gmake2
make config=$1 clean
make config=$1 -j12 rive_pls_renderer
popd
cp -r $RIVE_PLS_DIR/out/iphonesimulator_$1/librive_pls_renderer.a $DEV_SCRIPT_DIR/../dependencies/$1/librive_pls_renderer_sim.a
cp -r $RIVE_PLS_DIR/include $DEV_SCRIPT_DIR/../dependencies/includes/pls
else
# TODO: this fixes the compile without PLS, but linking will still fail because it won't
# find librive_pls_renderer_sim.a.
cp -r $DEV_SCRIPT_DIR/../Source/Renderer/NullPLS/include $DEV_SCRIPT_DIR/../dependencies/includes/pls
fi
}
build_pls_renderer_macosx() {
if [ -d "$RIVE_PLS_DIR" ]; then
pushd $RIVE_PLS_DIR/out
premake5 --scripts=$RIVE_RUNTIME_DIR/build --file=premake5_pls_renderer.lua --no-rive-decoders --os=macosx gmake2
make config=$1 clean
make config=$1 -j12 rive_pls_renderer
popd
cp -r $RIVE_PLS_DIR/out/$1/librive_pls_renderer_macos.a $DEV_SCRIPT_DIR/../dependencies/$1/librive_pls_renderer.a
cp -r $RIVE_PLS_DIR/include $DEV_SCRIPT_DIR/../dependencies/includes/pls
else
# TODO: this fixes the compile without PLS, but linking will still fail because it won't
# find librive_pls_renderer_macosx.a.
cp -r $DEV_SCRIPT_DIR/../Source/Renderer/NullPLS/include $DEV_SCRIPT_DIR/../dependencies/includes/pls
fi
}
finalize_skia() {
# COMBINE SKIA
# make fat library, note that the ios64 library is already fat with arm64 and arm64e so we don't specify arch there.
@@ -103,12 +160,18 @@ case $1 in
all)
make_dependency_directories
finalize_skia
build_renderer debug
build_renderer release
build_renderer_sim debug
build_renderer_sim release
build_renderer_macosx debug
build_renderer_macosx release
build_skia_renderer debug
build_skia_renderer release
build_skia_renderer_sim debug
build_skia_renderer_sim release
build_skia_renderer_macosx debug
build_skia_renderer_macosx release
build_pls_renderer debug
build_pls_renderer release
build_pls_renderer_sim debug
build_pls_renderer_sim release
build_pls_renderer_macosx debug
build_pls_renderer_macosx release
;;
macosx)
if (($# < 2)); then
@@ -118,7 +181,8 @@ macosx)
release | debug)
make_dependency_directories
finalize_skia
build_renderer_macosx $2
build_skia_renderer_macosx $2
build_pls_renderer_macosx $2
;;
*)
usage
@@ -133,7 +197,8 @@ ios)
release | debug)
make_dependency_directories
finalize_skia
build_renderer $2
build_skia_renderer $2
build_pls_renderer $2
;;
*)
usage
@@ -148,7 +213,8 @@ ios_sim)
release | debug)
make_dependency_directories
finalize_skia
build_renderer_sim $2
build_skia_renderer_sim $2
build_pls_renderer_sim $2
;;
*)
usage