Skip to content

Commit

Permalink
chore(💄): cpp code formatting (#2881)
Browse files Browse the repository at this point in the history
  • Loading branch information
wcandillon authored Jan 10, 2025
1 parent f45d88f commit d54e29b
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class MainThreadDispatcher {
private:
ALooper *mainLooper = nullptr;
int messagePipe[2] = { -1, -1 };
int messagePipe[2] = {-1, -1};
std::queue<std::function<void()>> taskQueue;
std::mutex queueMutex;

Expand Down
8 changes: 4 additions & 4 deletions packages/skia/android/cpp/rnskia-android/OpenGLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ class OpenGLContext {
format = GrBackendFormats::MakeGL(GR_GL_RGBA16F, GR_GL_TEXTURE_EXTERNAL);
break;
case AHARDWAREBUFFER_FORMAT_R5G6B5_UNORM:
GrBackendFormats::MakeGL(GR_GL_RGB565, GR_GL_TEXTURE_EXTERNAL);
break;
GrBackendFormats::MakeGL(GR_GL_RGB565, GR_GL_TEXTURE_EXTERNAL);
break;
case AHARDWAREBUFFER_FORMAT_R10G10B10A2_UNORM:
format = GrBackendFormats::MakeGL(GR_GL_RGB10_A2, GR_GL_TEXTURE_EXTERNAL);
break;
Expand All @@ -146,8 +146,8 @@ class OpenGLContext {
auto height = static_cast<int>(description.height);
auto backendTex = MakeGLBackendTexture(
_directContext.get(), const_cast<AHardwareBuffer *>(hardwareBuffer),
width, height, &deleteImageProc,
&updateImageProc, &deleteImageCtx, false, format, false);
width, height, &deleteImageProc, &updateImageProc, &deleteImageCtx,
false, format, false);
if (!backendTex.isValid()) {
RNSkLogger::logToConsole(
"Failed to convert HardwareBuffer to OpenGL Texture!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ namespace RNSkia {
RNSkOpenGLCanvasProvider::RNSkOpenGLCanvasProvider(
std::function<void()> requestRedraw,
std::shared_ptr<RNSkia::RNSkPlatformContext> platformContext)
: RNSkCanvasProvider(std::move(requestRedraw)), _platformContext(std::move(platformContext)) {}
: RNSkCanvasProvider(std::move(requestRedraw)),
_platformContext(std::move(platformContext)) {}

RNSkOpenGLCanvasProvider::~RNSkOpenGLCanvasProvider() = default;

Expand Down Expand Up @@ -109,8 +110,7 @@ void RNSkOpenGLCanvasProvider::surfaceAvailable(jobject jSurfaceTexture,
#if defined(SK_GRAPHITE)
_surfaceHolder = DawnContext::getInstance().MakeWindow(window, width, height);
#else
_surfaceHolder =
OpenGLContext::getInstance().MakeWindow(window);
_surfaceHolder = OpenGLContext::getInstance().MakeWindow(window);
#endif

// Post redraw request to ensure we paint in the next draw cycle.
Expand Down
46 changes: 23 additions & 23 deletions packages/skia/cpp/api/JsiSkCanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -525,32 +525,32 @@ class JsiSkCanvas : public JsiSkHostObject {

std::vector<SkColor> colors;
if (count > 5 && !arguments[5].isUndefined()) {
auto colorsArray = arguments[5].asObject(runtime).asArray(runtime);
int colorsSize = static_cast<int>(colorsArray.size(runtime));
colors.reserve(colorsSize);
for (int i = 0; i < colorsSize; i++) {
// Convert from [r,g,b,a] in [0,1] to SkColor
auto val = colorsArray.getValueAtIndex(runtime, i).asObject(runtime);
float r = val.getProperty(runtime, "0").asNumber();
float g = val.getProperty(runtime, "1").asNumber();
float b = val.getProperty(runtime, "2").asNumber();
float a = val.getProperty(runtime, "3").asNumber();

// Convert to 8-bit color channels and pack into SkColor
uint8_t r8 = static_cast<uint8_t>(r * 255);
uint8_t g8 = static_cast<uint8_t>(g * 255);
uint8_t b8 = static_cast<uint8_t>(b * 255);
uint8_t a8 = static_cast<uint8_t>(a * 255);
SkColor color = SkColorSetARGB(a8, r8, g8, b8);
colors.push_back(color);
}
auto colorsArray = arguments[5].asObject(runtime).asArray(runtime);
int colorsSize = static_cast<int>(colorsArray.size(runtime));
colors.reserve(colorsSize);
for (int i = 0; i < colorsSize; i++) {
// Convert from [r,g,b,a] in [0,1] to SkColor
auto val = colorsArray.getValueAtIndex(runtime, i).asObject(runtime);
float r = val.getProperty(runtime, "0").asNumber();
float g = val.getProperty(runtime, "1").asNumber();
float b = val.getProperty(runtime, "2").asNumber();
float a = val.getProperty(runtime, "3").asNumber();

// Convert to 8-bit color channels and pack into SkColor
uint8_t r8 = static_cast<uint8_t>(r * 255);
uint8_t g8 = static_cast<uint8_t>(g * 255);
uint8_t b8 = static_cast<uint8_t>(b * 255);
uint8_t a8 = static_cast<uint8_t>(a * 255);

SkColor color = SkColorSetARGB(a8, r8, g8, b8);
colors.push_back(color);
}
}

SkSamplingOptions sampling(SkFilterMode::kLinear, SkMipmapMode::kNone);
_canvas->drawAtlas(atlas.get(), xforms.data(), skRects.data(), colors.data(),
skRects.size(), blendMode, sampling, nullptr,
paint.get());
_canvas->drawAtlas(atlas.get(), xforms.data(), skRects.data(),
colors.data(), skRects.size(), blendMode, sampling,
nullptr, paint.get());

return jsi::Value::undefined();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/skia/cpp/api/JsiSkPaint.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class JsiSkPaint : public JsiSkWrappingSharedPtrHostObject<SkPaint> {
EXPORT_JSI_API_TYPENAME(JsiSkPaint, Paint)

JSI_HOST_FUNCTION(assign) {
SkPaint* paint = JsiSkPaint::fromValue(runtime, arguments[0]).get();
SkPaint *paint = JsiSkPaint::fromValue(runtime, arguments[0]).get();
*getObject() = *paint;
return jsi::Value::undefined();
}
Expand Down
6 changes: 2 additions & 4 deletions packages/skia/ios/RNSkia-iOS/SkiaManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,12 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
return self;
}

- (void)dealloc
{
- (void)dealloc {
sharedInstance = nil;
}

#ifdef RCT_NEW_ARCH_ENABLED
+ (std::shared_ptr<RNSkia::RNSkManager>)latestActiveSkManager
{
+ (std::shared_ptr<RNSkia::RNSkManager>)latestActiveSkManager {
if (sharedInstance != nil) {
return [sharedInstance skManager];
}
Expand Down

0 comments on commit d54e29b

Please sign in to comment.