Skip to content

Commit

Permalink
Merge pull request #2087 from Shopify/m121
Browse files Browse the repository at this point in the history
⬆️ Update to m121
  • Loading branch information
wcandillon authored Dec 20, 2023
2 parents 27df594 + de6b6a2 commit ffb4f37
Show file tree
Hide file tree
Showing 13 changed files with 226 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[submodule "externals/skia"]
path = externals/skia
url = https://chromium.googlesource.com/skia/
branch = chrome/m119
branch = chrome/m121
[submodule "externals/depot_tools"]
path = externals/depot_tools
url = https://chromium.googlesource.com/chromium/tools/depot_tools.git
2 changes: 1 addition & 1 deletion externals/depot_tools
Submodule depot_tools updated from c51829 to 390005
2 changes: 1 addition & 1 deletion externals/skia
Submodule skia updated from ab212d to e8d7db
1 change: 1 addition & 0 deletions package/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ add_library(
"${PROJECT_SOURCE_DIR}/../cpp/rnskia/dom/base/ConcatablePaint.cpp"

"${PROJECT_SOURCE_DIR}/../cpp/api/third_party/CSSColorParser.cpp"
"${PROJECT_SOURCE_DIR}/../cpp/api/third_party/base64.cpp"

)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ sk_sp<SkSurface> SkiaOpenGLSurfaceFactory::makeOffscreenSurface(int width,
// Create texture
auto texture =
ThreadContextHolder::ThreadSkiaOpenGLContext.directContext
->createBackendTexture(width, height, colorType, GrMipMapped::kNo,
GrRenderable::kYes);
->createBackendTexture(width, height, colorType,
skgpu::Mipmapped::kNo, GrRenderable::kYes);

struct ReleaseContext {
SkiaOpenGLContext *context;
Expand Down
2 changes: 1 addition & 1 deletion package/cpp/api/JsiSkAnimatedImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
#include <utility>

#include "JsiSkHostObjects.h"
#include "third_party/base64.h"

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation"

#include "JsiSkImage.h"
#include "SkBase64.h"
#include "SkStream.h"
#include "include/codec/SkEncodedImageFormat.h"

Expand Down
12 changes: 6 additions & 6 deletions package/cpp/api/JsiSkDataFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include "JsiPromises.h"
#include "JsiSkData.h"
#include "SkBase64.h"
#include "third_party/base64.h"

namespace RNSkia {

Expand Down Expand Up @@ -67,17 +67,17 @@ class JsiSkDataFactory : public JsiSkHostObject {
// Calculate length
size_t len;
auto err =
SkBase64::Decode(&base64.utf8(runtime).c_str()[0], size, nullptr, &len);
if (err != SkBase64::Error::kNoError) {
Base64::Decode(&base64.utf8(runtime).c_str()[0], size, nullptr, &len);
if (err != Base64::Error::kNone) {
throw jsi::JSError(runtime, "Error decoding base64 string");
return jsi::Value::undefined();
}

// Create data object and decode
auto data = SkData::MakeUninitialized(len);
err = SkBase64::Decode(&base64.utf8(runtime).c_str()[0], size,
data->writable_data(), &len);
if (err != SkBase64::Error::kNoError) {
err = Base64::Decode(&base64.utf8(runtime).c_str()[0], size,
data->writable_data(), &len);
if (err != Base64::Error::kNone) {
throw jsi::JSError(runtime, "Error decoding base64 string");
return jsi::Value::undefined();
}
Expand Down
8 changes: 4 additions & 4 deletions package/cpp/api/JsiSkImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#include "JsiSkImageInfo.h"
#include "JsiSkMatrix.h"
#include "JsiSkShader.h"
#include "third_party/base64.h"

#include "RNSkTypedArray.h"

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation"

#include "SkBase64.h"
#include "SkImage.h"
#include "SkStream.h"
#include "include/codec/SkEncodedImageFormat.h"
Expand Down Expand Up @@ -133,10 +133,10 @@ class JsiSkImage : public JsiSkWrappingSkPtrHostObject<SkImage> {
JSI_HOST_FUNCTION(encodeToBase64) {
auto data = encodeImageData(arguments, count);

auto len = SkBase64::Encode(data->bytes(), data->size(), nullptr);
auto len = Base64::Encode(data->bytes(), data->size(), nullptr);
auto buffer = std::string(len, 0);
SkBase64::Encode(data->bytes(), data->size(),
reinterpret_cast<void *>(&buffer[0]));
Base64::Encode(data->bytes(), data->size(),
reinterpret_cast<void *>(&buffer[0]));
return jsi::String::createFromAscii(runtime, buffer);
}

Expand Down
153 changes: 153 additions & 0 deletions package/cpp/api/third_party/base64.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* Copyright 2006 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "third_party/base64.h"

#include <cstdint>

#define DecodePad -2
#define EncodePad 64

static const char kDefaultEncode[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/=";

static const signed char kDecodeData[] = {
62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1,
-1, -1, DecodePad, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
-1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51};

namespace RNSkia {

Base64::Error Base64::Decode(const void *srcv, size_t srcLength, void *dstv,
size_t *dstLength) {
const unsigned char *src = static_cast<const unsigned char *>(srcv);
unsigned char *dst = static_cast<unsigned char *>(dstv);

int i = 0;
bool padTwo = false;
bool padThree = false;
char unsigned const *const end = src + srcLength;
while (src < end) {
unsigned char bytes[4] = {0, 0, 0, 0};
int byte = 0;
do {
unsigned char srcByte = *src++;
if (srcByte == 0) {
*dstLength = i;
return Error::kNone;
}
if (srcByte <= ' ') {
continue; // treat as white space
}
if (srcByte < '+' || srcByte > 'z') {
return Error::kBadChar;
}
signed char decoded = kDecodeData[srcByte - '+'];
bytes[byte] = decoded;
if (decoded != DecodePad) {
if (decoded < 0) {
return Error::kBadChar;
}
byte++;
if (*src) {
continue;
}
if (byte == 0) {
*dstLength = i;
return Error::kNone;
}
if (byte == 4) {
break;
}
}
// As an optimization, if we find an equals sign
// we assume all future bytes to read are the
// appropriate number of padding equals signs.
if (byte < 2) {
return Error::kBadPadding;
}
padThree = true;
if (byte == 2) {
padTwo = true;
}
break;
} while (byte < 4);
int two = 0;
int three = 0;
if (dst) {
int one = (uint8_t)(bytes[0] << 2);
two = bytes[1];
one |= two >> 4;
two = (uint8_t)((two << 4) & 0xFF);
three = bytes[2];
two |= three >> 2;
three = (uint8_t)((three << 6) & 0xFF);
three |= bytes[3];
dst[i] = (unsigned char)one;
}
i++;
if (padTwo) {
break;
}
if (dst) {
dst[i] = (unsigned char)two;
}
i++;
if (padThree) {
break;
}
if (dst) {
dst[i] = (unsigned char)three;
}
i++;
}
*dstLength = i;
return Error::kNone;
}

size_t Base64::Encode(const void *srcv, size_t length, void *dstv) {
const unsigned char *src = static_cast<const unsigned char *>(srcv);
unsigned char *dst = static_cast<unsigned char *>(dstv);

const char *encode = kDefaultEncode;
if (dst) {
size_t remainder = length % 3;
char unsigned const *const end = &src[length - remainder];
while (src < end) {
unsigned a = *src++;
unsigned b = *src++;
unsigned c = *src++;
int d = c & 0x3F;
c = (c >> 6 | b << 2) & 0x3F;
b = (b >> 4 | a << 4) & 0x3F;
a = a >> 2;
*dst++ = encode[a];
*dst++ = encode[b];
*dst++ = encode[c];
*dst++ = encode[d];
}
if (remainder > 0) {
int k1 = 0;
int k2 = EncodePad;
int a = (uint8_t)*src++;
if (remainder == 2) {
int b = *src++;
k1 = b >> 4;
k2 = (b << 2) & 0x3F;
}
*dst++ = encode[a >> 2];
*dst++ = encode[(k1 | a << 4) & 0x3F];
*dst++ = encode[k2];
*dst++ = encode[EncodePad];
}
}
return (length + 2) / 3 * 4;
}

} // namespace RNSkia
50 changes: 50 additions & 0 deletions package/cpp/api/third_party/base64.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright 2006 The Android Open Source Project
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#pragma once

#include <cstddef>

namespace RNSkia {

struct Base64 {
public:
enum class Error {
kNone,
kBadPadding,
kBadChar,
};

/**
Base64 encodes src into dst.
Normally this is called once with 'dst' nullptr to get the required size,
then again with an allocated 'dst' pointer to do the actual encoding.
@param dst nullptr or a pointer to a buffer large enough to receive the
result
@return the required length of dst for encoding.
*/
static size_t Encode(const void *src, size_t length, void *dst);

/**
Base64 decodes src into dst.
Normally this is called once with 'dst' nullptr to get the required size,
then again with an allocated 'dst' pointer to do the actual encoding.
@param dst nullptr or a pointer to a buffer large enough to receive the
result
@param dstLength assigned the length dst is required to be. Must not be
nullptr.
*/
[[nodiscard]] static Error Decode(const void *src, size_t srcLength,
void *dst, size_t *dstLength);
};

} // namespace RNSkia
2 changes: 1 addition & 1 deletion package/cpp/jsi/JsiPromises.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <jsi/jsi.h>

#include "SkBase64.h"
#include "third_party/base64.h"

namespace RNJsi {
namespace jsi = facebook::jsi;
Expand Down
5 changes: 4 additions & 1 deletion package/cpp/rnskia/dom/props/FontProp.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ class FontProp : public DerivedProp<SkFont> {
"Expected SkFont object or null/undefined for the Font property.");
}
} else {
auto font = std::make_shared<SkFont>(SkFont());
auto fm = SkFontMgr::RefDefault();
sk_sp<SkTypeface> typeface =
fm->legacyMakeTypeface(nullptr, SkFontStyle());
auto font = std::make_shared<SkFont>(SkFont(typeface));
font->setSize(14);
setDerivedValue(font);
}
Expand Down
2 changes: 1 addition & 1 deletion package/ios/RNSkia-iOS/SkiaMetalSurfaceFactory.mm
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
// Create a GrBackendTexture from the Metal texture
GrMtlTextureInfo info;
info.fTexture.retain((__bridge void *)ctx->texture);
GrBackendTexture backendTexture(width, height, GrMipMapped::kNo, info);
GrBackendTexture backendTexture(width, height, skgpu::Mipmapped::kNo, info);

// Create a SkSurface from the GrBackendTexture
auto surface = SkSurfaces::WrapBackendTexture(
Expand Down

0 comments on commit ffb4f37

Please sign in to comment.