Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scan code format #93

Merged
merged 3 commits into from
Feb 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 64 additions & 7 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,15 +1,72 @@
# Generated from CLion C/C++ Code Style settings
Language: Cpp
BasedOnStyle: Google
ColumnLimit: 100

# Only sort headers in each include block
SortIncludes: true
IncludeBlocks: Preserve
DerivePointerAlignment: false
PointerAlignment: Left
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignOperands: Align
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Always
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakTemplateDeclarations: Yes
BreakBeforeBraces: Custom
BraceWrapping:
SplitEmptyFunction: true
AfterCaseLabel: false
AfterClass: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: true
BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
CompactNamespaces: false
ContinuationIndentWidth: 4
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PointerAlignment: Left
ReflowComments: false
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
IncludeBlocks: Merge
TabWidth: 2
UseTab: Never

---
Language: ObjC
Expand All @@ -23,4 +80,4 @@ DerivePointerAlignment: false
PointerAlignment: Left
AllowShortFunctionsOnASingleLine: None
BraceWrapping:
SplitEmptyFunction: true
SplitEmptyFunction: true
24 changes: 24 additions & 0 deletions .github/workflows/code_format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: code_format

on:
pull_request:
branches: [ main ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug

jobs:
code_format:
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: Run codeformat script
run: |
npm install -g clang-format
chmod +x codeformat.sh
./codeformat.sh
shell: bash
22 changes: 22 additions & 0 deletions codeformat.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash
echo "----begin to scan code format----"
find include/ -iname '*.h' -print0 | xargs clang-format -i
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 -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

git diff
result=`git diff`
if [[ $result =~ "diff" ]]
then
echo "----Failed----"
exit 1
else
echo "----Success----"
fi
echo "----Complete the scan code format-----"

3 changes: 1 addition & 2 deletions src/base/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
//
/////////////////////////////////////////////////////////////////////////////////////////////////

#include "pag/file.h"
#include <algorithm>
#include <unordered_map>

#include "pag/file.h"

namespace pag {

static std::mutex globalLocker = {};
Expand Down
3 changes: 2 additions & 1 deletion src/codec/tags/shapes/TrimPaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ namespace pag {
std::unique_ptr<BlockConfig> TrimPathsTag(TrimPathsElement* shape) {
auto tagConfig = new BlockConfig(TagCode::TrimPaths);
AddAttribute(tagConfig, &shape->start, AttributeType::SimpleProperty, 0.0f);
// The default value of the end property should be 1.0f, but for backward compatibility we do not change it.
// The default value of the end property should be 1.0f, but for backward compatibility we do not
// change it.
AddAttribute(tagConfig, &shape->end, AttributeType::SimpleProperty, 100.0f);
AddAttribute(tagConfig, &shape->offset, AttributeType::SimpleProperty, 0.0f);
AddAttribute(tagConfig, &shape->trimType, AttributeType::Value, TrimPathsType::Simultaneously);
Expand Down
22 changes: 11 additions & 11 deletions src/platform/android/GPUDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ void GPUDecoder::InitJNI(JNIEnv* env, const std::string& className) {
"(Ljava/lang/String;II)Landroid/media/MediaFormat;");
MediaFormat_setByteBuffer = env->GetMethodID(MediaFormatClass.get(), "setByteBuffer",
"(Ljava/lang/String;Ljava/nio/ByteBuffer;)V");
MediaFormat_setFloat = env->GetMethodID(MediaFormatClass.get(), "setFloat",
"(Ljava/lang/String;F)V");
MediaFormat_setFloat =
env->GetMethodID(MediaFormatClass.get(), "setFloat", "(Ljava/lang/String;F)V");
}

GPUDecoder::GPUDecoder(const VideoConfig& config) {
Expand All @@ -71,14 +71,14 @@ GPUDecoder::GPUDecoder(const VideoConfig& config) {
return;
}
Local<jobject> outputSurface = {env, videoSurface->getOutputSurface(env)};
Local<jobject> decoder =
{env,
env->CallStaticObjectMethod(GPUDecoderClass.get(), GPUDecoder_Create, outputSurface.get())};
Local<jobject> decoder = {
env,
env->CallStaticObjectMethod(GPUDecoderClass.get(), GPUDecoder_Create, outputSurface.get())};
if (decoder.empty()) {
_isValid = false;
return;
}
videoDecoder.reset(env,decoder.get());
videoDecoder.reset(env, decoder.get());
_isValid = onConfigure(decoder.get(), config);
}

Expand All @@ -100,9 +100,9 @@ bool GPUDecoder::onConfigure(jobject decoder, const VideoConfig& config) {
return false;
}
Local<jstring> mimeType = {env, SafeConvertToJString(env, config.mimeType.c_str())};
Local<jobject> mediaFormat = {env, env->CallStaticObjectMethod(
MediaFormatClass.get(), MediaFormat_createVideoFormat, mimeType.get(), config.width,
config.height)};
Local<jobject> mediaFormat = {
env, env->CallStaticObjectMethod(MediaFormatClass.get(), MediaFormat_createVideoFormat,
mimeType.get(), config.width, config.height)};
if (config.mimeType == "video/hevc") {
if (!config.headers.empty()) {
char keyString[] = "csd-0";
Expand Down Expand Up @@ -146,8 +146,8 @@ DecodingResult GPUDecoder::onSendBytes(void* bytes, size_t length, int64_t time)
return pag::DecodingResult::Error;
}
Local<jobject> byteBuffer = {env, env->NewDirectByteBuffer(bytes, length)};
auto result = env->CallIntMethod(videoDecoder.get(), GPUDecoder_onSendBytes, byteBuffer.get(),
time);
auto result =
env->CallIntMethod(videoDecoder.get(), GPUDecoder_onSendBytes, byteBuffer.get(), time);
return static_cast<pag::DecodingResult>(result);
}

Expand Down
2 changes: 1 addition & 1 deletion src/platform/android/GPUDrawable.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

#include <android/native_window.h>
#include <android/native_window_jni.h>
#include "pag/pag.h"
#include "gpu/opengl/egl/EGLWindow.h"
#include "pag/pag.h"

namespace pag {
class GPUDrawable : public Drawable {
Expand Down
2 changes: 1 addition & 1 deletion src/platform/android/Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include "JNIEnvironment.h"

template<typename T>
template <typename T>
class Global {
public:
Global() = default;
Expand Down
4 changes: 2 additions & 2 deletions src/platform/android/JNIHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ pag::ImageInfo GetImageInfo(JNIEnv* env, jobject bitmap) {
return {};
}
pag::AlphaType alphaType = (bitmapInfo.flags & BITMAP_FLAGS_ALPHA_UNPREMUL)
? pag::AlphaType::Unpremultiplied
: pag::AlphaType::Premultiplied;
? pag::AlphaType::Unpremultiplied
: pag::AlphaType::Premultiplied;
pag::ColorType colorType;
switch (bitmapInfo.format) {
case ANDROID_BITMAP_FORMAT_RGBA_8888:
Expand Down
2 changes: 1 addition & 1 deletion src/platform/android/JPAGImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
#include <android/asset_manager_jni.h>
#include <android/bitmap.h>
#include <cassert>
#include "NativePlatform.h"
#include "JNIHelper.h"
#include "NativePlatform.h"

namespace pag {
static jfieldID PAGImage_nativeContext;
Expand Down
2 changes: 1 addition & 1 deletion src/platform/android/Local.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

#include <jni.h>

template<typename T>
template <typename T>
class Local {
public:
Local() = default;
Expand Down
11 changes: 5 additions & 6 deletions src/platform/android/PAGText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ jobject ToPAGTextObject(JNIEnv* env, pag::TextDocumentHandle textDocument) {
static_cast<jboolean>(textDocument->applyStroke));
env->SetFloatField(textData, PAGText_baselineShift, textDocument->baselineShift);
env->SetBooleanField(textData, PAGText_boxText, static_cast<jboolean>(textDocument->boxText));
Local<jobject> boxTextRect = {env, MakeRectFObject(env, textDocument->boxTextPos.x,
textDocument->boxTextPos.y,
textDocument->boxTextSize.x,
textDocument->boxTextSize.y)};
Local<jobject> boxTextRect = {
env, MakeRectFObject(env, textDocument->boxTextPos.x, textDocument->boxTextPos.y,
textDocument->boxTextSize.x, textDocument->boxTextSize.y)};
env->SetObjectField(textData, PAGText_boxTextRect, boxTextRect.get());
env->SetFloatField(textData, PAGText_firstBaseLine, textDocument->firstBaseLine);
env->SetBooleanField(textData, PAGText_fauxBold, static_cast<jboolean>(textDocument->fauxBold));
Expand Down Expand Up @@ -147,14 +146,14 @@ TextDocumentHandle ToTextDocument(JNIEnv* env, jobject textData) {
(jstring)env->GetObjectField(textData, PAGText_fontFamily)};
textDocument->fontFamily = SafeConvertToStdString(env, fontFamilyObject.get());
Local<jstring> fontStyleObject = {env, (jstring)env->GetObjectField(textData, PAGText_fontStyle)};
textDocument->fontStyle = SafeConvertToStdString(env, fontStyleObject.get());;
textDocument->fontStyle = SafeConvertToStdString(env, fontStyleObject.get());
textDocument->fontSize = env->GetFloatField(textData, PAGText_fontSize);
jint strokeColorObject = env->GetIntField(textData, PAGText_strokeColor);
textDocument->strokeColor = ToColor(env, strokeColorObject);
textDocument->strokeOverFill = env->GetBooleanField(textData, PAGText_strokeOverFill);
textDocument->strokeWidth = env->GetFloatField(textData, PAGText_strokeWidth);
Local<jstring> textObject = {env, (jstring)env->GetObjectField(textData, PAGText_text)};
textDocument->text = SafeConvertToStdString(env, textObject.get());;
textDocument->text = SafeConvertToStdString(env, textObject.get());
textDocument->justification =
static_cast<Enum>(env->GetIntField(textData, PAGText_justification));
textDocument->leading = env->GetFloatField(textData, PAGText_leading);
Expand Down
2 changes: 1 addition & 1 deletion src/platform/android/VideoImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ std::shared_ptr<VideoImage> VideoImage::MakeFrom(std::shared_ptr<VideoSurface> v

VideoImage::VideoImage(std::shared_ptr<VideoSurface> videoSurface, int width, int height)
: VideoBuffer(width, height), videoSurface(std::move(videoSurface)) {
this->videoSurface->markHasNewTextureImage();
this->videoSurface->markHasNewTextureImage();
}

std::shared_ptr<Texture> VideoImage::makeTexture(Context* context) const {
Expand Down
4 changes: 2 additions & 2 deletions src/platform/android/VideoSurface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ std::shared_ptr<VideoSurface> VideoSurface::Make(int width, int height, bool has
if (env == nullptr) {
return nullptr;
}
Local<jobject> surface =
{env, env->CallStaticObjectMethod(VideoSurfaceClass.get(), VideoSurface_Make, width, height)};
Local<jobject> surface = {
env, env->CallStaticObjectMethod(VideoSurfaceClass.get(), VideoSurface_Make, width, height)};
if (surface.empty()) {
return nullptr;
}
Expand Down
3 changes: 2 additions & 1 deletion src/platform/cocoa/PAGImageLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*/
Expand Down
2 changes: 1 addition & 1 deletion src/platform/cocoa/PAGLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
//
/////////////////////////////////////////////////////////////////////////////////////////////////

#import <Foundation/Foundation.h>
#import <CoreGraphics/CoreGraphics.h>
#import <Foundation/Foundation.h>
#import "PAGMarker.h"

typedef NS_ENUM(NSInteger, PAGLayerType) {
Expand Down
3 changes: 2 additions & 1 deletion src/platform/cocoa/PAGVideoRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Empty file modified src/platform/ios/PAGView.h
100755 → 100644
Empty file.
6 changes: 3 additions & 3 deletions src/platform/ios/PAGView.mm
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -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, ^{
Expand Down
Loading