Skip to content

Commit

Permalink
Drop the ColumnLimit to 80 for clang-format
Browse files Browse the repository at this point in the history
This gives better support for smaller screens and side-by-side windows.

Also standardize the formatting check on GitHub on version 17.

Diffs=
e52e9fff29 Drop the ColumnLimit to 80 for clang-format (#8320)

Co-authored-by: Chris Dalton <[email protected]>
  • Loading branch information
csmartdalton and csmartdalton committed Oct 11, 2024
1 parent a57eec9 commit 17a669a
Show file tree
Hide file tree
Showing 39 changed files with 870 additions and 525 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
52913023ba59036aa8f96685f1df5d9173551f72
e52e9fff2973ce63a689e9d11ea283214109ca18
24 changes: 15 additions & 9 deletions Source/Renderer/CDNFileAssetLoader.mm
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,19 @@ - (bool)loadContentsWithAsset:(RiveFileAsset*)asset
andFactory:(RiveFactory*)factory
{
// TODO: Error handling
// TODO: Track tasks, so we can cancel them if we garbage collect the asset loader
// TODO: Track tasks, so we can cancel them if we garbage collect the asset
// loader

if ([[asset cdnUuid] length] > 0)
{
NSURL* URL = [NSURL
URLWithString:[NSString
stringWithFormat:@"%@/%@", [asset cdnBaseUrl], [asset cdnUuid]]];
NSURL* URL =
[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@",
[asset cdnBaseUrl],
[asset cdnUuid]]];
NSURLSessionTask* task = [[NSURLSession sharedSession]
downloadTaskWithURL:URL
completionHandler:^(NSURL* location, NSURLResponse* response, NSError* error) {
completionHandler:^(
NSURL* location, NSURLResponse* response, NSError* error) {
if (!error)
{
// Load the data into the reader
Expand All @@ -39,14 +42,15 @@ - (bool)loadContentsWithAsset:(RiveFileAsset*)asset
}
else if ([asset isKindOfClass:[RiveImageAsset class]])
{
[(RiveImageAsset*)asset renderImage:[factory decodeImage:data]];
[(RiveImageAsset*)asset
renderImage:[factory decodeImage:data]];
}
}
}];

// Kick off the http download
// QUESTION: Do we need to tie this into the RiveFile so we can wait for these loads to be
// completed?
// QUESTION: Do we need to tie this into the RiveFile so we can wait for
// these loads to be completed?
[task resume];
return true;
}
Expand Down Expand Up @@ -79,7 +83,9 @@ - (bool)loadContentsWithAsset:(RiveFileAsset*)asset
{
for (RiveFileAssetLoader* loader in loaders)
{
if ([loader loadContentsWithAsset:asset andData:data andFactory:factory])
if ([loader loadContentsWithAsset:asset
andData:data
andFactory:factory])
{
return true;
}
Expand Down
36 changes: 23 additions & 13 deletions Source/Renderer/CoreGraphicsRenderer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,12 @@
path = CGPathCreateMutable();
}

void CoreGraphicsRenderPath::addRenderPath(RenderPath* path, const Mat2D& transform)
void CoreGraphicsRenderPath::addRenderPath(RenderPath* path,
const Mat2D& transform)
{
// NSLog(@" --- RenderPath::addPath");
CGMutablePathRef pathToAdd = reinterpret_cast<CoreGraphicsRenderPath*>(path)->getPath();
CGMutablePathRef pathToAdd =
reinterpret_cast<CoreGraphicsRenderPath*>(path)->getPath();
CGAffineTransform affineTransform = CGAffineTransformMake(transform.xx(),
transform.xy(),
transform.yx(),
Expand Down Expand Up @@ -224,10 +226,11 @@
CGPathAddLineToPoint(path, NULL, x, y);
}

void CoreGraphicsRenderPath::cubicTo(float ox, float oy, float ix, float iy, float x, float y)
void CoreGraphicsRenderPath::cubicTo(
float ox, float oy, float ix, float iy, float x, float y)
{
// NSLog(@" --- call to RenderPath::cubicTo %.1f, %.1f, %.1f, %.1f, %.1f, %.1f, ", ox, oy,
// ix, iy, x, y);
// NSLog(@" --- call to RenderPath::cubicTo %.1f, %.1f, %.1f, %.1f, %.1f,
// %.1f, ", ox, oy, ix, iy, x, y);
CGPathAddCurveToPoint(path, NULL, ox, oy, ix, iy, x, y);
}

Expand All @@ -254,9 +257,12 @@

void CoreGraphicsRenderer::drawPath(RenderPath* path, RenderPaint* paint)
{
// NSLog(@" --- Renderer::drawPath path for type %d", rivePaint->paintStyle);
CoreGraphicsRenderPaint* rivePaint = reinterpret_cast<CoreGraphicsRenderPaint*>(paint);
CoreGraphicsRenderPath* rivePath = reinterpret_cast<CoreGraphicsRenderPath*>(path);
// NSLog(@" --- Renderer::drawPath path for type %d",
// rivePaint->paintStyle);
CoreGraphicsRenderPaint* rivePaint =
reinterpret_cast<CoreGraphicsRenderPaint*>(paint);
CoreGraphicsRenderPath* rivePath =
reinterpret_cast<CoreGraphicsRenderPath*>(path);

// Apply the stroke join
if (rivePaint->strokeJoin != CoreGraphicsStrokeJoin::None)
Expand Down Expand Up @@ -381,8 +387,8 @@
// Draw gradient
if (rivePaint->gradientType != CoreGraphicsGradient::None)
{
// If the path is a stroke, then convert the path to a stroked path to prevent the gradient
// from filling the path
// If the path is a stroke, then convert the path to a stroked path to
// prevent the gradient from filling the path
if (rivePaint->paintStyle == CoreGraphicsPaintStyle::Stroke)
{
CGContextSetLineWidth(ctx, rivePaint->paintThickness);
Expand All @@ -395,8 +401,11 @@

if (rivePaint->gradientType == CoreGraphicsGradient::Linear)
{
CGContextDrawLinearGradient(
ctx, rivePaint->gradient, rivePaint->gradientStart, rivePaint->gradientEnd, 0x3);
CGContextDrawLinearGradient(ctx,
rivePaint->gradient,
rivePaint->gradientStart,
rivePaint->gradientEnd,
0x3);
}
else if (rivePaint->gradientType == CoreGraphicsGradient::Radial)
{
Expand Down Expand Up @@ -429,7 +438,8 @@
void CoreGraphicsRenderer::clipPath(RenderPath* path)
{
// NSLog(@" --- Renderer::clipPath %@", clipPath);
const CGPath* clipPath = reinterpret_cast<CoreGraphicsRenderPath*>(path)->getPath();
const CGPath* clipPath =
reinterpret_cast<CoreGraphicsRenderPath*>(path)->getPath();
CGContextAddPath(ctx, clipPath);
if (!CGContextIsPathEmpty(ctx))
CGContextClip(ctx);
Expand Down
27 changes: 17 additions & 10 deletions Source/Renderer/FileAssetLoaderAdapter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

NS_ASSUME_NONNULL_BEGIN

rive::FileAssetLoaderAdapter::FileAssetLoaderAdapter(RiveFileAssetLoader* myLoader)
rive::FileAssetLoaderAdapter::FileAssetLoaderAdapter(
RiveFileAssetLoader* myLoader)
{
loader = myLoader;
}
Expand All @@ -26,21 +27,27 @@
RiveFactory* myFactory = [[RiveFactory alloc] initWithFactory:factory];
if (asset.is<rive::FontAsset>())
{
RiveFontAsset* fontAsset =
[[RiveFontAsset alloc] initWithFileAsset:asset.as<rive::FontAsset>()];
return [loader loadContentsWithAsset:fontAsset andData:data andFactory:myFactory];
RiveFontAsset* fontAsset = [[RiveFontAsset alloc]
initWithFileAsset:asset.as<rive::FontAsset>()];
return [loader loadContentsWithAsset:fontAsset
andData:data
andFactory:myFactory];
}
else if (asset.is<rive::ImageAsset>())
{
RiveImageAsset* imageAsset =
[[RiveImageAsset alloc] initWithFileAsset:asset.as<rive::ImageAsset>()];
return [loader loadContentsWithAsset:imageAsset andData:data andFactory:myFactory];
RiveImageAsset* imageAsset = [[RiveImageAsset alloc]
initWithFileAsset:asset.as<rive::ImageAsset>()];
return [loader loadContentsWithAsset:imageAsset
andData:data
andFactory:myFactory];
}
else if (asset.is<rive::AudioAsset>())
{
RiveAudioAsset* audioAsset =
[[RiveAudioAsset alloc] initWithFileAsset:asset.as<rive::AudioAsset>()];
return [loader loadContentsWithAsset:audioAsset andData:data andFactory:myFactory];
RiveAudioAsset* audioAsset = [[RiveAudioAsset alloc]
initWithFileAsset:asset.as<rive::AudioAsset>()];
return [loader loadContentsWithAsset:audioAsset
andData:data
andFactory:myFactory];
}
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion Source/Renderer/LayerState.mm
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ - (NSString*)name

if (animation == nil)
{
return [NSString stringWithCString:"Unknown" encoding:[NSString defaultCStringEncoding]];
return [NSString stringWithCString:"Unknown"
encoding:[NSString defaultCStringEncoding]];
}
return [NSString stringWithCString:animation->name().c_str()
encoding:[NSString defaultCStringEncoding]];
Expand Down
85 changes: 52 additions & 33 deletions Source/Renderer/RenderContextManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ @implementation RenderContext
return nil;
}

- (void)endFrame:(MTKView*)view withCompletion:(_Nullable MTLCommandBufferHandler)completionHandler;
- (void)endFrame:(MTKView*)view
withCompletion:(_Nullable MTLCommandBufferHandler)completionHandler;
{}

@end
Expand All @@ -45,16 +46,17 @@ @implementation RiveRendererContext
rive::rcp<rive::gpu::RenderTargetMetal> _renderTarget;
}

static std::unique_ptr<rive::gpu::RenderContext> make_pls_context_native(id<MTLDevice> gpu)
static std::unique_ptr<rive::gpu::RenderContext> make_pls_context_native(
id<MTLDevice> gpu)
{
return rive::gpu::RenderContextMetalImpl::MakeContext(
gpu, rive::gpu::RenderContextMetalImpl::ContextOptions());
}

- (instancetype)init
{
// Make a single static RenderContext, since it is also the factory and any objects it
// creates may outlive this 'RiveContext' instance.
// Make a single static RenderContext, since it is also the factory and any
// objects it creates may outlive this 'RiveContext' instance.
static id<MTLDevice> s_plsGPU = MTLCreateSystemDefaultDevice();
static std::unique_ptr<rive::gpu::RenderContext> s_renderContext =
make_pls_context_native(s_plsGPU);
Expand All @@ -71,8 +73,8 @@ - (instancetype)init

- (void)dealloc
{
// Once nobody is referencing a RiveContext anymore, release the global RenderContext's GPU
// resource.
// Once nobody is referencing a RiveContext anymore, release the global
// RenderContext's GPU resource.
_renderContext->releaseResources();
}

Expand Down Expand Up @@ -100,12 +102,16 @@ - (void)dealloc
return nullptr;
}

if (_renderTarget == nullptr || _renderTarget->width() != view.drawableSize.width ||
if (_renderTarget == nullptr ||
_renderTarget->width() != view.drawableSize.width ||
_renderTarget->height() != view.drawableSize.height)
{
_renderTarget =
_renderContext->static_impl_cast<rive::gpu::RenderContextMetalImpl>()->makeRenderTarget(
view.colorPixelFormat, view.drawableSize.width, view.drawableSize.height);
_renderContext
->static_impl_cast<rive::gpu::RenderContextMetalImpl>()
->makeRenderTarget(view.colorPixelFormat,
view.drawableSize.width,
view.drawableSize.height);
}
_renderTarget->setTargetTexture(surface.texture);

Expand All @@ -118,7 +124,8 @@ - (void)dealloc
return _renderer.get();
}

- (void)endFrame:(MTKView*)view withCompletion:(_Nullable MTLCommandBufferHandler)completionHandler;
- (void)endFrame:(MTKView*)view
withCompletion:(_Nullable MTLCommandBufferHandler)completionHandler;
{
id<MTLCommandBuffer> flushCommandBuffer = [self.metalQueue commandBuffer];
_renderContext->flush({
Expand Down Expand Up @@ -186,10 +193,12 @@ - (instancetype)init
switch (view.colorPixelFormat)
{
case MTLPixelFormatBGRA8Unorm:
cgBitmapInfo = kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst;
cgBitmapInfo =
kCGBitmapByteOrder32Little | kCGImageAlphaPremultipliedFirst;
break;
case MTLPixelFormatRGBA8Unorm:
cgBitmapInfo = kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast;
cgBitmapInfo =
kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast;
break;
default:
NSLog(@"error: unsupported colorPixelFormat on MTKView");
Expand All @@ -205,39 +214,46 @@ - (instancetype)init
}

_currentBufferIdx = (_currentBufferIdx + 1) % kBufferRingSize;
size_t bufferSize = _renderTargetTexture.height * _renderTargetTexture.width * 4;
size_t bufferSize =
_renderTargetTexture.height * _renderTargetTexture.width * 4;
if (_buffers[_currentBufferIdx] == nil ||
_buffers[_currentBufferIdx].allocatedSize != bufferSize)
{
_buffers[_currentBufferIdx] =
[self.metalDevice newBufferWithLength:bufferSize options:MTLResourceStorageModeShared];
[self.metalDevice newBufferWithLength:bufferSize
options:MTLResourceStorageModeShared];
}
AutoCF<CGColorSpaceRef> colorSpace = CGColorSpaceCreateDeviceRGB();
_cgContext = AutoCF(CGBitmapContextCreate(_buffers[_currentBufferIdx].contents,
_renderTargetTexture.width,
_renderTargetTexture.height,
8,
_renderTargetTexture.width * 4,
colorSpace,
cgBitmapInfo));
_cgContext =
AutoCF(CGBitmapContextCreate(_buffers[_currentBufferIdx].contents,
_renderTargetTexture.width,
_renderTargetTexture.height,
8,
_renderTargetTexture.width * 4,
colorSpace,
cgBitmapInfo));

_renderer = std::make_unique<rive::CGRenderer>(
_cgContext, _renderTargetTexture.width, _renderTargetTexture.height);
return _renderer.get();
}

- (void)endFrame:(MTKView*)view withCompletion:(_Nullable MTLCommandBufferHandler)completionHandler;
- (void)endFrame:(MTKView*)view
withCompletion:(_Nullable MTLCommandBufferHandler)completionHandler;
{
if (_cgContext != nil)
{
id<MTLCommandBuffer> commandBuffer = [self.metalQueue commandBuffer];
id<MTLBlitCommandEncoder> blitEncoder = [commandBuffer blitCommandEncoder];
id<MTLBlitCommandEncoder> blitEncoder =
[commandBuffer blitCommandEncoder];
[blitEncoder copyFromBuffer:_buffers[_currentBufferIdx]
sourceOffset:0
sourceBytesPerRow:_renderTargetTexture.width * 4
sourceBytesPerImage:_renderTargetTexture.height * _renderTargetTexture.width * 4
sourceSize:MTLSizeMake(
_renderTargetTexture.width, _renderTargetTexture.height, 1)
sourceBytesPerImage:_renderTargetTexture.height *
_renderTargetTexture.width * 4
sourceSize:MTLSizeMake(_renderTargetTexture.width,
_renderTargetTexture.height,
1)
toTexture:_renderTargetTexture
destinationSlice:0
destinationLevel:0
Expand Down Expand Up @@ -295,8 +311,8 @@ - (RenderContext*)getDefaultContext

- (RenderContext*)getRiveRendererContext
{
// Convert our weak reference to strong before trying to work with it. A weak pointer is liable
// to be released out from under us at any moment.
// Convert our weak reference to strong before trying to work with it. A
// weak pointer is liable to be released out from under us at any moment.
// https://stackoverflow.com/questions/15674320/understanding-weak-reference
RiveRendererContext* strongPtr = _riveRendererContextWeakPtr;
if (strongPtr == nil)
Expand All @@ -309,8 +325,8 @@ - (RenderContext*)getRiveRendererContext

- (RenderContext*)getCGRendererContext
{
// Convert our weak reference to strong before trying to work with it. A weak pointer is liable
// to be released out from under us at any moment.
// Convert our weak reference to strong before trying to work with it. A
// weak pointer is liable to be released out from under us at any moment.
// https://stackoverflow.com/questions/15674320/understanding-weak-reference
CGRendererContext* strongPtr = _cgContextWeakPtr;
if (strongPtr == nil)
Expand All @@ -323,17 +339,20 @@ - (RenderContext*)getCGRendererContext

- (RiveFactory*)getDefaultFactory
{
return [[RiveFactory alloc] initWithFactory:[[self getDefaultContext] factory]];
return [[RiveFactory alloc]
initWithFactory:[[self getDefaultContext] factory]];
}

- (RiveFactory*)getRiveRendererFactory
{
return [[RiveFactory alloc] initWithFactory:[[self getRiveRendererContext] factory]];
return [[RiveFactory alloc]
initWithFactory:[[self getRiveRendererContext] factory]];
}

- (RiveFactory*)getCGFactory
{
return [[RiveFactory alloc] initWithFactory:[[self getCGRendererContext] factory]];
return [[RiveFactory alloc]
initWithFactory:[[self getCGRendererContext] factory]];
}

@end
Loading

0 comments on commit 17a669a

Please sign in to comment.