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 1e4f2e0 commit 74b58c1
Show file tree
Hide file tree
Showing 49 changed files with 1,649 additions and 917 deletions.
2 changes: 1 addition & 1 deletion .rive_head
Original file line number Diff line number Diff line change
@@ -1 +1 @@
52913023ba59036aa8f96685f1df5d9173551f72
e52e9fff2973ce63a689e9d11ea283214109ca18
69 changes: 40 additions & 29 deletions kotlin/src/main/cpp/include/helpers/android_factories.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ bool JNIDecodeImage(rive::Span<const uint8_t> encodedBytes,
bool* isOpaque);

// Forward declare template specialization.
template <typename AssetType> rive::rcp<AssetType> decode(rive::Span<const uint8_t>, RendererType);
template <typename AssetType>
rive::rcp<AssetType> decode(rive::Span<const uint8_t>, RendererType);

template <typename AssetType>
rive::rcp<AssetType> decodeAsset(JNIEnv* env, jbyteArray byteArray, jint rendererTypeIdx)
rive::rcp<AssetType> decodeAsset(JNIEnv* env,
jbyteArray byteArray,
jint rendererTypeIdx)
{
jsize count = env->GetArrayLength(byteArray);
jbyte* buffer = env->GetByteArrayElements(byteArray, nullptr);
rive::Span<const uint8_t> data(reinterpret_cast<const uint8_t*>(buffer), count);
rive::Span<const uint8_t> data(reinterpret_cast<const uint8_t*>(buffer),
count);

RendererType rendererType = static_cast<RendererType>(rendererTypeIdx);
rive::rcp<AssetType> asset = decode<AssetType>(data, rendererType);
Expand All @@ -49,8 +53,9 @@ template <typename AssetType> void releaseAsset(jlong address)
class AndroidSkiaFactory : public rive::SkiaFactory
{
public:
std::vector<uint8_t> platformDecode(rive::Span<const uint8_t> encodedBytes,
rive::SkiaFactory::ImageInfo* info) override;
std::vector<uint8_t> platformDecode(
rive::Span<const uint8_t> encodedBytes,
rive::SkiaFactory::ImageInfo* info) override;
};

class AndroidRiveRenderFactory : public rive::RiveRenderFactory
Expand All @@ -60,34 +65,40 @@ class AndroidRiveRenderFactory : public rive::RiveRenderFactory
rive::RenderBufferFlags,
size_t) override;

rive::rcp<rive::RenderImage> decodeImage(rive::Span<const uint8_t>) override;
rive::rcp<rive::RenderImage> decodeImage(
rive::Span<const uint8_t>) override;
};
class AndroidCanvasFactory : public rive::Factory
{
public:
rive::rcp<rive::RenderBuffer> makeRenderBuffer(rive::RenderBufferType type,
rive::RenderBufferFlags flags,
size_t sizeInBytes) override;

rive::rcp<rive::RenderImage> decodeImage(rive::Span<const uint8_t> encodedBytes) override;

rive::rcp<rive::RenderShader> makeLinearGradient(float sx,
float sy,
float ex,
float ey,
const rive::ColorInt colors[], // [count]
const float stops[], // [count]
size_t count) override;

rive::rcp<rive::RenderShader> makeRadialGradient(float cx,
float cy,
float radius,
const rive::ColorInt colors[], // [count]
const float stops[], // [count]
size_t count) override;

rive::rcp<rive::RenderPath> makeRenderPath(rive::RawPath& rawPath,
rive::FillRule fillRule) override;
rive::rcp<rive::RenderBuffer> makeRenderBuffer(
rive::RenderBufferType type,
rive::RenderBufferFlags flags,
size_t sizeInBytes) override;

rive::rcp<rive::RenderImage> decodeImage(
rive::Span<const uint8_t> encodedBytes) override;

rive::rcp<rive::RenderShader> makeLinearGradient(
float sx,
float sy,
float ex,
float ey,
const rive::ColorInt colors[], // [count]
const float stops[], // [count]
size_t count) override;

rive::rcp<rive::RenderShader> makeRadialGradient(
float cx,
float cy,
float radius,
const rive::ColorInt colors[], // [count]
const float stops[], // [count]
size_t count) override;

rive::rcp<rive::RenderPath> makeRenderPath(
rive::RawPath& rawPath,
rive::FillRule fillRule) override;

rive::rcp<rive::RenderPath> makeEmptyRenderPath() override;

Expand Down
29 changes: 17 additions & 12 deletions kotlin/src/main/cpp/include/helpers/canvas_render_objects.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ class CanvasRenderPath : public rive::RenderPath

void lineTo(float x, float y) override;

void cubicTo(float ox, float oy, float ix, float iy, float x, float y) override;
void cubicTo(float ox, float oy, float ix, float iy, float x, float y)
override;

void close() override;

Expand Down Expand Up @@ -139,7 +140,8 @@ class CanvasRenderImage : public rive::RenderImage
jobject m_ktBitmap = nullptr;
jobject m_ktPaint = nullptr;

static jobject CreateKtBitmapFrom(JNIEnv* env, rive::Span<const uint8_t>& encodedBytes)
static jobject CreateKtBitmapFrom(JNIEnv* env,
rive::Span<const uint8_t>& encodedBytes)
{
jbyteArray byteArray = env->NewByteArray(encodedBytes.size());
if (byteArray == nullptr)
Expand All @@ -148,19 +150,21 @@ class CanvasRenderImage : public rive::RenderImage
return nullptr;
}

env->SetByteArrayRegion(byteArray,
0,
encodedBytes.size(),
reinterpret_cast<const jbyte*>(encodedBytes.data()));
env->SetByteArrayRegion(
byteArray,
0,
encodedBytes.size(),
reinterpret_cast<const jbyte*>(encodedBytes.data()));

jclass bitmapFactoryClass = GetAndroidBitmapFactoryClass();
jmethodID decodeByteArrayMethodID = GetDecodeByteArrayStaticMethodId();

jobject bitmap = env->CallStaticObjectMethod(bitmapFactoryClass,
decodeByteArrayMethodID,
byteArray,
0,
SizeTTOInt(encodedBytes.size()));
jobject bitmap =
env->CallStaticObjectMethod(bitmapFactoryClass,
decodeByteArrayMethodID,
byteArray,
0,
SizeTTOInt(encodedBytes.size()));
env->DeleteLocalRef(byteArray);
env->DeleteLocalRef(bitmapFactoryClass);
if (bitmap == nullptr)
Expand All @@ -185,7 +189,8 @@ class CanvasRenderImage : public rive::RenderImage
JNIEnv* env = GetJNIEnv();
jclass bitmapShaderClass = GetBitmapShaderClass();
jclass tileModeClass = GetTileModeClass();
jobject clampEnum = env->GetStaticObjectField(tileModeClass, GetClampId());
jobject clampEnum =
env->GetStaticObjectField(tileModeClass, GetClampId());
jobject ktShader = env->NewObject(bitmapShaderClass,
GetBitmapShaderConstructor(),
ktBitmap,
Expand Down
3 changes: 2 additions & 1 deletion kotlin/src/main/cpp/include/helpers/font_helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class FontHelper

static std::vector<uint8_t> getSystemFontBytes();

static rive::rcp<rive::Font> findFontFallback(rive::Span<const rive::Unichar> missing);
static rive::rcp<rive::Font> findFontFallback(
rive::Span<const rive::Unichar> missing);
};

} // namespace rive_android
Expand Down
10 changes: 7 additions & 3 deletions kotlin/src/main/cpp/include/helpers/general.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@

// Print only on debug builds.
#if defined(DEBUG) || defined(LOG)
// CMake builds print out a lot of gibberish with this macro - comment it out for now.
// #define LOG_TAG (std::string(__FILE__ ":") + std::to_string(__LINE__)).c_str()
// CMake builds print out a lot of gibberish with this macro - comment it out
// for now. #define LOG_TAG (std::string(__FILE__ ":") +
// std::to_string(__LINE__)).c_str()
#define LOG_TAG "rive-android-jni"
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
Expand Down Expand Up @@ -40,7 +41,10 @@ extern JavaVM* g_JVM;
extern long g_sdkVersion;
void SetSDKVersion();
void LogReferenceTables();
long Import(uint8_t*, jint, RendererType = RendererType::Skia, rive::FileAssetLoader* = nullptr);
long Import(uint8_t*,
jint,
RendererType = RendererType::Skia,
rive::FileAssetLoader* = nullptr);

rive::Alignment GetAlignment(JNIEnv*, jobject);
rive::Fit GetFit(JNIEnv*, jobject);
Expand Down
7 changes: 5 additions & 2 deletions kotlin/src/main/cpp/include/helpers/jni_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ template <typename T> class JniResource
JniResource(T res, JNIEnv* env) : resource(res), env(env) {}

// Move constructor to transfer ownership
JniResource(JniResource&& other) noexcept : resource(other.resource), env(other.env)
JniResource(JniResource&& other) noexcept :
resource(other.resource), env(other.env)
{
other.resource = nullptr;
}
Expand Down Expand Up @@ -67,7 +68,9 @@ template <typename T> JniResource<T> FindClass(JNIEnv* env, const char* name)
template <typename T>
JniResource<T> GetStaticObjectField(JNIEnv* env, jclass clazz, jfieldID fieldID)
{
return MakeJniResource(static_cast<T>(env->GetStaticObjectField(clazz, fieldID)), env);
return MakeJniResource(
static_cast<T>(env->GetStaticObjectField(clazz, fieldID)),
env);
}

std::vector<uint8_t> ByteArrayToUint8Vec(JNIEnv*, jbyteArray);
Expand Down
4 changes: 2 additions & 2 deletions kotlin/src/main/cpp/include/helpers/rendering_stats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class RenderingStats
mRunningMean = ((mN - 1) * mRunningMean + x) / mN;
if (mN > 1)
{
mRunningVar =
((mN - 2) * mRunningVar) / (mN - 1) + (x - prevMean) * (x - prevMean) / mN;
mRunningVar = ((mN - 2) * mRunningVar) / (mN - 1) +
(x - prevMean) * (x - prevMean) / mN;
}
if (mN == mNumToAvg)
restart();
Expand Down
3 changes: 2 additions & 1 deletion kotlin/src/main/cpp/include/helpers/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@

#define GUARDED_BY(x) THREAD_ANNOTATION_ATTRIBUTE__(guarded_by(x))

#define REQUIRES(...) THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(__VA_ARGS__))
#define REQUIRES(...) \
THREAD_ANNOTATION_ATTRIBUTE__(requires_capability(__VA_ARGS__))

namespace rive_android
{
Expand Down
8 changes: 6 additions & 2 deletions kotlin/src/main/cpp/include/helpers/thread_state_pls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class PLSThreadState : public EGLThreadState
PLSThreadState();
~PLSThreadState();

rive::gpu::RenderContext* renderContext() const { return m_renderContext.get(); }
rive::gpu::RenderContext* renderContext() const
{
return m_renderContext.get();
}

void destroySurface(EGLSurface eglSurface) override;

Expand All @@ -26,7 +29,8 @@ class PLSThreadState : public EGLThreadState
private:
std::unique_ptr<rive::gpu::RenderContext> m_renderContext;

// 1x1 Pbuffer surface that allows us to make the GL context current without a window surface.
// 1x1 Pbuffer surface that allows us to make the GL context current without
// a window surface.
EGLSurface m_backgroundSurface;
};
} // namespace rive_android
Expand Down
13 changes: 8 additions & 5 deletions kotlin/src/main/cpp/include/helpers/tracer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,21 @@ class Tracer : public ITracer
void* lib = dlopen("libandroid.so", RTLD_NOW | RTLD_LOCAL);
if (lib != NULL)
{
ATrace_beginSection =
reinterpret_cast<fp_ATrace_beginSection>(dlsym(lib, "ATrace_beginSection"));
ATrace_endSection =
reinterpret_cast<fp_ATrace_endSection>(dlsym(lib, "ATrace_endSection"));
ATrace_beginSection = reinterpret_cast<fp_ATrace_beginSection>(
dlsym(lib, "ATrace_beginSection"));
ATrace_endSection = reinterpret_cast<fp_ATrace_endSection>(
dlsym(lib, "ATrace_endSection"));
}
else
{
LOGE("Tracer cannot load libandroid.so!");
}
}
~Tracer() {}
void beginSection(const char* sectionName) override { ATrace_beginSection(sectionName); };
void beginSection(const char* sectionName) override
{
ATrace_beginSection(sectionName);
};
void endSection() override { ATrace_endSection(); };

private:
Expand Down
10 changes: 5 additions & 5 deletions kotlin/src/main/cpp/include/helpers/worker_ref.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace rive_android
class RefWorker : public WorkerThread
{
public:
// Returns the current worker of the requested renderer type, or the current Skia worker if the
// requested type is not supported.
// Returns the current worker of the requested renderer type, or the current
// Skia worker if the requested type is not supported.
static rive::rcp<RefWorker> CurrentOrFallback(RendererType);

// Returns the Rive renderer worker, or null if it is not supported.
Expand All @@ -25,9 +25,9 @@ class RefWorker : public WorkerThread

~RefWorker();

// These methods work with rive::rcp<> for tracking _external_ references. They don't
// necessarily delete this object when the external ref count goes to zero, and they may have
// other side effects as well.
// These methods work with rive::rcp<> for tracking _external_ references.
// They don't necessarily delete this object when the external ref count
// goes to zero, and they may have other side effects as well.
void ref();
void unref();

Expand Down
21 changes: 15 additions & 6 deletions kotlin/src/main/cpp/include/helpers/worker_thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ class WorkerThread
constexpr static WorkID kWorkIDAlwaysFinished = 0;

// A worker object that starts a background thread to perform its tasks.
WorkerThread(const char* name, Affinity affinity, const RendererType rendererType) :
m_RendererType(rendererType), mName(name), mAffinity(affinity), mWorkMutex{}
WorkerThread(const char* name,
Affinity affinity,
const RendererType rendererType) :
m_RendererType(rendererType),
mName(name),
mAffinity(affinity),
mWorkMutex{}
{
// Don't launch the worker thread until all of our objects are fully initialized.
// Don't launch the worker thread until all of our objects are fully
// initialized.
mThread = std::thread([this]() { threadMain(); });
}

Expand All @@ -58,7 +64,8 @@ class WorkerThread

WorkID run(Work&& work)
{
assert(work != nullptr); // Clients can't push the null termination token.
assert(work !=
nullptr); // Clients can't push the null termination token.
uint64_t pushedWorkID;
{
std::lock_guard workLock(mWorkMutex);
Expand Down Expand Up @@ -111,7 +118,8 @@ class WorkerThread
const RendererType m_RendererType;

private:
static std::unique_ptr<DrawableThreadState> MakeThreadState(const RendererType type);
static std::unique_ptr<DrawableThreadState> MakeThreadState(
const RendererType type);

void threadMain()
{
Expand All @@ -133,7 +141,8 @@ class WorkerThread

if (!work)
{
// A null function is a special token that tells the thread to terminate.
// A null function is a special token that tells the thread to
// terminate.
break;
}

Expand Down
Loading

0 comments on commit 74b58c1

Please sign in to comment.