diff --git a/codeformat.sh b/codeformat.sh index b058c55537..ef4b07b681 100755 --- a/codeformat.sh +++ b/codeformat.sh @@ -5,7 +5,7 @@ find tgfx/include -iname '*.h' -print0 | xargs clang-format -i # shellcheck disable=SC2038 find tgfx/src -iname "*.h" -print -o -iname "*.cpp" -print | xargs clang-format -i # shellcheck disable=SC2038 -find src -name "*.cpp" -print -o -name "*.h" -print | xargs clang-format -i +find src -name "*.cpp" -print -o -name "*.h" -print -o -name "*.mm" -print -o -name "*.m" -print | xargs clang-format -i # shellcheck disable=SC2038 find test \( -path test/framework/lzma \) -prune -o -name "*.cpp" -print -o -name "*.h" -print | xargs clang-format -i diff --git a/src/platform/cocoa/PAG.h b/src/platform/cocoa/PAG.h index 5219a3ee0c..f345420abf 100644 --- a/src/platform/cocoa/PAG.h +++ b/src/platform/cocoa/PAG.h @@ -18,7 +18,8 @@ #import -__attribute__((visibility("default"))) @interface PAG : NSObject +__attribute__((visibility("default"))) +@interface PAG : NSObject /** * Get SDK version information. */ diff --git a/src/platform/cocoa/PAGComposition.h b/src/platform/cocoa/PAGComposition.h index fa99de8d47..952275ff17 100644 --- a/src/platform/cocoa/PAGComposition.h +++ b/src/platform/cocoa/PAGComposition.h @@ -19,7 +19,8 @@ #import #import "PAGLayer.h" -__attribute__((visibility("default"))) @interface PAGComposition : PAGLayer +__attribute__((visibility("default"))) +@interface PAGComposition : PAGLayer /** * Make a empty PAGComposition with specified size. diff --git a/src/platform/cocoa/PAGFile.h b/src/platform/cocoa/PAGFile.h index 03ed963c79..96cd707a73 100644 --- a/src/platform/cocoa/PAGFile.h +++ b/src/platform/cocoa/PAGFile.h @@ -23,7 +23,8 @@ #import "PAGText.h" #import "PAGTimeStretchMode.h" -__attribute__((visibility("default"))) @interface PAGFile : PAGComposition +__attribute__((visibility("default"))) +@interface PAGFile : PAGComposition /** * The maximum tag level current SDK supports. */ diff --git a/src/platform/cocoa/PAGFont.h b/src/platform/cocoa/PAGFont.h index 663fac1c05..350c862cef 100644 --- a/src/platform/cocoa/PAGFont.h +++ b/src/platform/cocoa/PAGFont.h @@ -18,7 +18,8 @@ #import -__attribute__((visibility("default"))) @interface PAGFont : NSObject +__attribute__((visibility("default"))) +@interface PAGFont : NSObject /** * A string with the name of the font family. diff --git a/src/platform/cocoa/PAGImage.h b/src/platform/cocoa/PAGImage.h index 2dc0c53c7a..c8d9490c30 100644 --- a/src/platform/cocoa/PAGImage.h +++ b/src/platform/cocoa/PAGImage.h @@ -21,7 +21,8 @@ #import #import "PAGScaleMode.h" -__attribute__((visibility("default"))) @interface PAGImage : NSObject +__attribute__((visibility("default"))) +@interface PAGImage : NSObject /** * Creates a PAGImage object from a CGImage object, return null if it's not valid CGImage object. */ diff --git a/src/platform/cocoa/PAGImageLayer.h b/src/platform/cocoa/PAGImageLayer.h index 5ca16b1839..2bace70c35 100644 --- a/src/platform/cocoa/PAGImageLayer.h +++ b/src/platform/cocoa/PAGImageLayer.h @@ -23,7 +23,8 @@ @class PAGImage; @class PAGVideoRange; -__attribute__((visibility("default"))) @interface PAGImageLayer : PAGLayer +__attribute__((visibility("default"))) +@interface PAGImageLayer : PAGLayer /** * Make a PAGImageLayer with size and duration(in microseconds). */ diff --git a/src/platform/cocoa/PAGLayer.h b/src/platform/cocoa/PAGLayer.h index d8a37e0552..4a1b5176e2 100644 --- a/src/platform/cocoa/PAGLayer.h +++ b/src/platform/cocoa/PAGLayer.h @@ -33,7 +33,8 @@ typedef NS_ENUM(NSInteger, PAGLayerType) { @class PAGComposition; @class PAGFile; -__attribute__((visibility("default"))) @interface PAGLayer : NSObject +__attribute__((visibility("default"))) +@interface PAGLayer : NSObject /** * Returns the type of layer. diff --git a/src/platform/cocoa/PAGMarker.h b/src/platform/cocoa/PAGMarker.h index f8231f2c27..fbe3d9ff22 100644 --- a/src/platform/cocoa/PAGMarker.h +++ b/src/platform/cocoa/PAGMarker.h @@ -18,7 +18,8 @@ #import -__attribute__((visibility("default"))) @interface PAGMarker : NSObject +__attribute__((visibility("default"))) +@interface PAGMarker : NSObject @property(nonatomic) long long startTime; @property(nonatomic) long long duration; diff --git a/src/platform/cocoa/PAGPlayer.h b/src/platform/cocoa/PAGPlayer.h index e7cfa27b5b..c41ea583e2 100644 --- a/src/platform/cocoa/PAGPlayer.h +++ b/src/platform/cocoa/PAGPlayer.h @@ -23,7 +23,8 @@ #import "PAGScaleMode.h" #import "PAGSurface.h" -__attribute__((visibility("default"))) @interface PAGPlayer : NSObject +__attribute__((visibility("default"))) +@interface PAGPlayer : NSObject /** * Returns the current PAGComposition for PAGPlayer to render as content. */ diff --git a/src/platform/cocoa/PAGShapeLayer.h b/src/platform/cocoa/PAGShapeLayer.h index e6815b3200..5c03e6487e 100644 --- a/src/platform/cocoa/PAGShapeLayer.h +++ b/src/platform/cocoa/PAGShapeLayer.h @@ -19,6 +19,7 @@ #import #import "PAGLayer.h" -__attribute__((visibility("default"))) @interface PAGShapeLayer : PAGLayer +__attribute__((visibility("default"))) +@interface PAGShapeLayer : PAGLayer @end diff --git a/src/platform/cocoa/PAGSolidLayer.h b/src/platform/cocoa/PAGSolidLayer.h index 71c0f03db2..9d7d9ba896 100644 --- a/src/platform/cocoa/PAGSolidLayer.h +++ b/src/platform/cocoa/PAGSolidLayer.h @@ -20,7 +20,8 @@ #import "CocoaUtils.h" #import "PAGLayer.h" -__attribute__((visibility("default"))) @interface PAGSolidLayer : PAGLayer +__attribute__((visibility("default"))) +@interface PAGSolidLayer : PAGLayer /** * Returns the layer's solid color. diff --git a/src/platform/cocoa/PAGText.h b/src/platform/cocoa/PAGText.h index 0411d51d9c..dddefba2b4 100644 --- a/src/platform/cocoa/PAGText.h +++ b/src/platform/cocoa/PAGText.h @@ -32,7 +32,8 @@ enum { /** * The PAGText object stores a value for a TextLayer's Source Text property. */ -__attribute__((visibility("default"))) @interface PAGText : NSObject +__attribute__((visibility("default"))) +@interface PAGText : NSObject /** * When true, the text layer shows a fill. diff --git a/src/platform/cocoa/PAGTextLayer.h b/src/platform/cocoa/PAGTextLayer.h index 34f73d1836..c5f080658f 100644 --- a/src/platform/cocoa/PAGTextLayer.h +++ b/src/platform/cocoa/PAGTextLayer.h @@ -22,7 +22,8 @@ @class PAGFont; -__attribute__((visibility("default"))) @interface PAGTextLayer : PAGLayer +__attribute__((visibility("default"))) +@interface PAGTextLayer : PAGLayer /** * Returns the TextLayer’s fill color. diff --git a/src/platform/cocoa/PAGVideoDecoder.h b/src/platform/cocoa/PAGVideoDecoder.h index 586401a36a..3089eacd24 100644 --- a/src/platform/cocoa/PAGVideoDecoder.h +++ b/src/platform/cocoa/PAGVideoDecoder.h @@ -18,7 +18,8 @@ #import -__attribute__((visibility("default"))) @interface PAGVideoDecoder : NSObject +__attribute__((visibility("default"))) +@interface PAGVideoDecoder : NSObject /** * Register a software decoder factory to implement the decoder fallback mechanism. diff --git a/src/platform/cocoa/PAGVideoRange.h b/src/platform/cocoa/PAGVideoRange.h index 718adea39f..7d1049ca19 100644 --- a/src/platform/cocoa/PAGVideoRange.h +++ b/src/platform/cocoa/PAGVideoRange.h @@ -21,7 +21,8 @@ /** * Represents a time range from the content of PAGImageLayer. */ -__attribute__((visibility("default"))) @interface PAGVideoRange : NSObject +__attribute__((visibility("default"))) +@interface PAGVideoRange : NSObject /** * The start time of the source video, in microseconds. diff --git a/src/platform/ios/PAGSurface.h b/src/platform/ios/PAGSurface.h index 8a26bb60e1..1e6c6674a8 100644 --- a/src/platform/ios/PAGSurface.h +++ b/src/platform/ios/PAGSurface.h @@ -22,7 +22,8 @@ #import #import "PAGImageLayer.h" -__attribute__((visibility("default"))) @interface PAGSurface : NSObject +__attribute__((visibility("default"))) +@interface PAGSurface : NSObject /** * Creates a new PAGSurface from specified CAEAGLLayer. The GPU context will be created internally diff --git a/src/platform/ios/PAGView.h b/src/platform/ios/PAGView.h index ef707a52c4..62578995c4 100644 --- a/src/platform/ios/PAGView.h +++ b/src/platform/ios/PAGView.h @@ -66,7 +66,8 @@ @end -__attribute__((visibility("default"))) @interface PAGView : UIView +__attribute__((visibility("default"))) +@interface PAGView : UIView /** * Default is NO. diff --git a/src/platform/ios/PAGView.mm b/src/platform/ios/PAGView.mm old mode 100755 new mode 100644 index 0769b274e7..f5edace11f --- a/src/platform/ios/PAGView.mm +++ b/src/platform/ios/PAGView.mm @@ -64,9 +64,9 @@ + (NSOperationQueue*)FlushQueue { return pag::flushQueue; } -/// 函数用于在执行 exit() 函数时把渲染任务全部完成,防止 PAG 的全局函数被析构,导致 PAG 野指针 crash。 -/// 注意这里注册需要等待 PAG 执行一次后再进行注册。因此需要等到 bufferPerpared 并再执行一次 flush 后, -/// 否则 PAG 的 static 对象仍然会先析构 +/// 函数用于在执行 exit() 函数时把渲染任务全部完成,防止 PAG 的全局函数被析构,导致 PAG 野指针 +/// crash。 注意这里注册需要等待 PAG 执行一次后再进行注册。因此需要等到 bufferPerpared 并再执行一次 +/// flush 后, 否则 PAG 的 static 对象仍然会先析构 + (void)RegisterFlushQueueDestoryMethod { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ diff --git a/src/platform/ios/private/GPUDecoder.mm b/src/platform/ios/private/GPUDecoder.mm index 80384fd8b0..d4f131f27e 100644 --- a/src/platform/ios/private/GPUDecoder.mm +++ b/src/platform/ios/private/GPUDecoder.mm @@ -24,9 +24,10 @@ namespace pag { -GPUDecoder::GPUDecoder(const VideoConfig& config) : sourceColorSpace(config.colorSpace), - destinationColorSpace(config.colorSpace), - colorRange(config.colorRange) { +GPUDecoder::GPUDecoder(const VideoConfig& config) + : sourceColorSpace(config.colorSpace), + destinationColorSpace(config.colorSpace), + colorRange(config.colorRange) { isInitialized = initVideoToolBox(config.headers, config.mimeType); } @@ -147,11 +148,11 @@ void initParameterSets(const std::vector>& headers, CFDictionaryRef attrs = NULL; const void* keys[] = {kCVPixelBufferPixelFormatTypeKey, kCVPixelBufferOpenGLESCompatibilityKey, kCVPixelBufferIOSurfacePropertiesKey}; - + uint32_t openGLESCompatibility = true; - uint32_t pixelFormatType = - colorRange == YUVColorRange::JPEG ? kCVPixelFormatType_420YpCbCr8BiPlanarFullRange - : kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange; + uint32_t pixelFormatType = colorRange == YUVColorRange::JPEG + ? kCVPixelFormatType_420YpCbCr8BiPlanarFullRange + : kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange; CFNumberRef pixelFormatTypeValue = CFNumberCreate(NULL, kCFNumberSInt32Type, &pixelFormatType); CFNumberRef openGLESCompatibilityValue = @@ -178,18 +179,25 @@ void initParameterSets(const std::vector>& headers, if (@available(iOS 10.0, *)) { if (sourceColorSpace == YUVColorSpace::Rec2020) { - CFStringRef destinationColorPrimaries = CFStringCreateWithCString(kCFAllocatorDefault, "DestinationColorPrimaries", kCFStringEncodingUTF8); - CFStringRef destinationTransferFunction = CFStringCreateWithCString(kCFAllocatorDefault, "DestinationTransferFunction", kCFStringEncodingUTF8); - CFStringRef destinationYCbCrMatrix = CFStringCreateWithCString(kCFAllocatorDefault, "DestinationYCbCrMatrix", kCFStringEncodingUTF8); - CFStringRef pixelTransferProperties = CFStringCreateWithCString(kCFAllocatorDefault, "PixelTransferProperties", kCFStringEncodingUTF8); - - CFMutableDictionaryRef pixelTransferPropertiesParam = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, - &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); - CFDictionarySetValue(pixelTransferPropertiesParam, destinationColorPrimaries, kCVImageBufferColorPrimaries_ITU_R_709_2); - CFDictionarySetValue(pixelTransferPropertiesParam, destinationTransferFunction, kCVImageBufferTransferFunction_ITU_R_709_2); - CFDictionarySetValue(pixelTransferPropertiesParam, destinationYCbCrMatrix, kCVImageBufferYCbCrMatrix_ITU_R_709_2); + CFStringRef destinationColorPrimaries = CFStringCreateWithCString( + kCFAllocatorDefault, "DestinationColorPrimaries", kCFStringEncodingUTF8); + CFStringRef destinationTransferFunction = CFStringCreateWithCString( + kCFAllocatorDefault, "DestinationTransferFunction", kCFStringEncodingUTF8); + CFStringRef destinationYCbCrMatrix = CFStringCreateWithCString( + kCFAllocatorDefault, "DestinationYCbCrMatrix", kCFStringEncodingUTF8); + CFStringRef pixelTransferProperties = CFStringCreateWithCString( + kCFAllocatorDefault, "PixelTransferProperties", kCFStringEncodingUTF8); + + CFMutableDictionaryRef pixelTransferPropertiesParam = CFDictionaryCreateMutable( + kCFAllocatorDefault, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); + CFDictionarySetValue(pixelTransferPropertiesParam, destinationColorPrimaries, + kCVImageBufferColorPrimaries_ITU_R_709_2); + CFDictionarySetValue(pixelTransferPropertiesParam, destinationTransferFunction, + kCVImageBufferTransferFunction_ITU_R_709_2); + CFDictionarySetValue(pixelTransferPropertiesParam, destinationYCbCrMatrix, + kCVImageBufferYCbCrMatrix_ITU_R_709_2); VTSessionSetProperty(session, pixelTransferProperties, pixelTransferPropertiesParam); - + CFRelease(destinationColorPrimaries); CFRelease(destinationTransferFunction); CFRelease(destinationYCbCrMatrix); @@ -264,7 +272,9 @@ void initParameterSets(const std::vector>& headers, if (status == kVTInvalidSessionErr) { cleanResources(); isInitialized = resetVideoToolBox(); - LOGI("GPUDecoder: Resetting VideoToolBox session, which may be caused by app entered background, initialized = %d", isInitialized); + LOGI("GPUDecoder: Resetting VideoToolBox session, which may be caused by app entered " + "background, initialized = %d", + isInitialized); } else { LOGE("GPUDecoder:Decode failed status = %d", (int)status); } diff --git a/src/platform/ios/private/VideoImage.mm b/src/platform/ios/private/VideoImage.mm index e6f7e15fd7..a1b38efa02 100644 --- a/src/platform/ios/private/VideoImage.mm +++ b/src/platform/ios/private/VideoImage.mm @@ -44,13 +44,14 @@ } videoImageMap.erase(result); } - auto videoImage = std::shared_ptr(new VideoImage(pixelBuffer, colorSpace, colorRange)); + auto videoImage = + std::shared_ptr(new VideoImage(pixelBuffer, colorSpace, colorRange)); videoImageMap[pixelBuffer] = videoImage; return videoImage; } -VideoImage::VideoImage(CVPixelBufferRef pixelBuffer, - YUVColorSpace colorSpace, YUVColorRange colorRange) +VideoImage::VideoImage(CVPixelBufferRef pixelBuffer, YUVColorSpace colorSpace, + YUVColorRange colorRange) : VideoBuffer(static_cast(CVPixelBufferGetWidth(pixelBuffer)), static_cast(CVPixelBufferGetHeight(pixelBuffer))), pixelBuffer(pixelBuffer), diff --git a/src/platform/mac/PAGSurface.h b/src/platform/mac/PAGSurface.h index 45d388ada6..32a70af18d 100644 --- a/src/platform/mac/PAGSurface.h +++ b/src/platform/mac/PAGSurface.h @@ -23,7 +23,8 @@ #import #import "PAGImageLayer.h" -__attribute__((visibility("default"))) @interface PAGSurface : NSObject +__attribute__((visibility("default"))) +@interface PAGSurface : NSObject + (PAGSurface*)FromView:(NSView*)view; diff --git a/src/platform/mac/PAGView.h b/src/platform/mac/PAGView.h index 5af4b962a2..c15a5ee534 100644 --- a/src/platform/mac/PAGView.h +++ b/src/platform/mac/PAGView.h @@ -66,7 +66,8 @@ @end -__attribute__((visibility("default"))) @interface PAGView : NSView +__attribute__((visibility("default"))) +@interface PAGView : NSView /** * Adds a listener to the set of listeners that are sent events through the life of an animation,