Skip to content

Commit

Permalink
Throw errors on Android for consistency (#2390)
Browse files Browse the repository at this point in the history
Co-authored-by: William Candillon <[email protected]>
  • Loading branch information
mrousavy and wcandillon authored Apr 19, 2024
1 parent 61571c3 commit 36c10bd
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ SkiaOpenGLSurfaceFactory::makeImageFromHardwareBuffer(void *buffer) {
#if __ANDROID_API__ >= 26
// Setup OpenGL and Skia:
if (!SkiaOpenGLHelper::createSkiaDirectContextIfNecessary(
&ThreadContextHolder::ThreadSkiaOpenGLContext)) {

RNSkLogger::logToConsole(
"Could not create Skia Surface from native window / surface. "
"Failed creating Skia Direct Context");
return nullptr;
&ThreadContextHolder::ThreadSkiaOpenGLContext)) [[unlikely]] {
throw std::runtime_error("Failed to create Skia Context for this Thread!");
}
const AHardwareBuffer *hardwareBuffer =
static_cast<AHardwareBuffer *>(buffer);
Expand All @@ -35,7 +31,8 @@ SkiaOpenGLSurfaceFactory::makeImageFromHardwareBuffer(void *buffer) {

AHardwareBuffer_Desc description;
AHardwareBuffer_describe(hardwareBuffer, &description);
if (description.format != AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM) {
if (description.format != AHARDWAREBUFFER_FORMAT_R8G8B8A8_UNORM)
[[unlikely]] {
throw std::runtime_error("AHardwareBuffer has unknown format (" +
std::to_string(description.format) +
") - cannot convert to SkImage!");
Expand All @@ -48,6 +45,10 @@ SkiaOpenGLSurfaceFactory::makeImageFromHardwareBuffer(void *buffer) {
const_cast<AHardwareBuffer *>(hardwareBuffer), description.width,
description.height, &deleteImageProc, &updateImageProc, &deleteImageCtx,
false, format, false);
if (!backendTex.isValid()) [[unlikely]] {
throw std::runtime_error(
"Failed to convert HardwareBuffer to OpenGL Texture!");
}
sk_sp<SkImage> image = SkImages::BorrowTextureFrom(
ThreadContextHolder::ThreadSkiaOpenGLContext.directContext.get(),
backendTex, kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType,
Expand Down

0 comments on commit 36c10bd

Please sign in to comment.