Skip to content

Commit ffb4f37

Browse files
authored
Merge pull request #2087 from Shopify/m121
⬆️ Update to m121
2 parents 27df594 + de6b6a2 commit ffb4f37

File tree

13 files changed

+226
-19
lines changed

13 files changed

+226
-19
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[submodule "externals/skia"]
22
path = externals/skia
33
url = https://chromium.googlesource.com/skia/
4-
branch = chrome/m119
4+
branch = chrome/m121
55
[submodule "externals/depot_tools"]
66
path = externals/depot_tools
77
url = https://chromium.googlesource.com/chromium/tools/depot_tools.git

externals/depot_tools

Submodule depot_tools updated from c518299 to 3900055

externals/skia

Submodule skia updated from ab212df to e8d7db9

package/android/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ add_library(
6262
"${PROJECT_SOURCE_DIR}/../cpp/rnskia/dom/base/ConcatablePaint.cpp"
6363

6464
"${PROJECT_SOURCE_DIR}/../cpp/api/third_party/CSSColorParser.cpp"
65+
"${PROJECT_SOURCE_DIR}/../cpp/api/third_party/base64.cpp"
6566

6667
)
6768

package/android/cpp/rnskia-android/SkiaOpenGLSurfaceFactory.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ sk_sp<SkSurface> SkiaOpenGLSurfaceFactory::makeOffscreenSurface(int width,
3131
// Create texture
3232
auto texture =
3333
ThreadContextHolder::ThreadSkiaOpenGLContext.directContext
34-
->createBackendTexture(width, height, colorType, GrMipMapped::kNo,
35-
GrRenderable::kYes);
34+
->createBackendTexture(width, height, colorType,
35+
skgpu::Mipmapped::kNo, GrRenderable::kYes);
3636

3737
struct ReleaseContext {
3838
SkiaOpenGLContext *context;

package/cpp/api/JsiSkAnimatedImage.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
#include <utility>
66

77
#include "JsiSkHostObjects.h"
8+
#include "third_party/base64.h"
89

910
#pragma clang diagnostic push
1011
#pragma clang diagnostic ignored "-Wdocumentation"
1112

1213
#include "JsiSkImage.h"
13-
#include "SkBase64.h"
1414
#include "SkStream.h"
1515
#include "include/codec/SkEncodedImageFormat.h"
1616

package/cpp/api/JsiSkDataFactory.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "JsiPromises.h"
99
#include "JsiSkData.h"
10-
#include "SkBase64.h"
10+
#include "third_party/base64.h"
1111

1212
namespace RNSkia {
1313

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

7676
// Create data object and decode
7777
auto data = SkData::MakeUninitialized(len);
78-
err = SkBase64::Decode(&base64.utf8(runtime).c_str()[0], size,
79-
data->writable_data(), &len);
80-
if (err != SkBase64::Error::kNoError) {
78+
err = Base64::Decode(&base64.utf8(runtime).c_str()[0], size,
79+
data->writable_data(), &len);
80+
if (err != Base64::Error::kNone) {
8181
throw jsi::JSError(runtime, "Error decoding base64 string");
8282
return jsi::Value::undefined();
8383
}

package/cpp/api/JsiSkImage.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
#include "JsiSkImageInfo.h"
99
#include "JsiSkMatrix.h"
1010
#include "JsiSkShader.h"
11+
#include "third_party/base64.h"
1112

1213
#include "RNSkTypedArray.h"
1314

1415
#pragma clang diagnostic push
1516
#pragma clang diagnostic ignored "-Wdocumentation"
1617

17-
#include "SkBase64.h"
1818
#include "SkImage.h"
1919
#include "SkStream.h"
2020
#include "include/codec/SkEncodedImageFormat.h"
@@ -133,10 +133,10 @@ class JsiSkImage : public JsiSkWrappingSkPtrHostObject<SkImage> {
133133
JSI_HOST_FUNCTION(encodeToBase64) {
134134
auto data = encodeImageData(arguments, count);
135135

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

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/*
2+
* Copyright 2006 The Android Open Source Project
3+
*
4+
* Use of this source code is governed by a BSD-style license that can be
5+
* found in the LICENSE file.
6+
*/
7+
#include "third_party/base64.h"
8+
9+
#include <cstdint>
10+
11+
#define DecodePad -2
12+
#define EncodePad 64
13+
14+
static const char kDefaultEncode[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
15+
"abcdefghijklmnopqrstuvwxyz"
16+
"0123456789+/=";
17+
18+
static const signed char kDecodeData[] = {
19+
62, -1, -1, -1, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1,
20+
-1, -1, DecodePad, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
21+
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
22+
-1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35,
23+
36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51};
24+
25+
namespace RNSkia {
26+
27+
Base64::Error Base64::Decode(const void *srcv, size_t srcLength, void *dstv,
28+
size_t *dstLength) {
29+
const unsigned char *src = static_cast<const unsigned char *>(srcv);
30+
unsigned char *dst = static_cast<unsigned char *>(dstv);
31+
32+
int i = 0;
33+
bool padTwo = false;
34+
bool padThree = false;
35+
char unsigned const *const end = src + srcLength;
36+
while (src < end) {
37+
unsigned char bytes[4] = {0, 0, 0, 0};
38+
int byte = 0;
39+
do {
40+
unsigned char srcByte = *src++;
41+
if (srcByte == 0) {
42+
*dstLength = i;
43+
return Error::kNone;
44+
}
45+
if (srcByte <= ' ') {
46+
continue; // treat as white space
47+
}
48+
if (srcByte < '+' || srcByte > 'z') {
49+
return Error::kBadChar;
50+
}
51+
signed char decoded = kDecodeData[srcByte - '+'];
52+
bytes[byte] = decoded;
53+
if (decoded != DecodePad) {
54+
if (decoded < 0) {
55+
return Error::kBadChar;
56+
}
57+
byte++;
58+
if (*src) {
59+
continue;
60+
}
61+
if (byte == 0) {
62+
*dstLength = i;
63+
return Error::kNone;
64+
}
65+
if (byte == 4) {
66+
break;
67+
}
68+
}
69+
// As an optimization, if we find an equals sign
70+
// we assume all future bytes to read are the
71+
// appropriate number of padding equals signs.
72+
if (byte < 2) {
73+
return Error::kBadPadding;
74+
}
75+
padThree = true;
76+
if (byte == 2) {
77+
padTwo = true;
78+
}
79+
break;
80+
} while (byte < 4);
81+
int two = 0;
82+
int three = 0;
83+
if (dst) {
84+
int one = (uint8_t)(bytes[0] << 2);
85+
two = bytes[1];
86+
one |= two >> 4;
87+
two = (uint8_t)((two << 4) & 0xFF);
88+
three = bytes[2];
89+
two |= three >> 2;
90+
three = (uint8_t)((three << 6) & 0xFF);
91+
three |= bytes[3];
92+
dst[i] = (unsigned char)one;
93+
}
94+
i++;
95+
if (padTwo) {
96+
break;
97+
}
98+
if (dst) {
99+
dst[i] = (unsigned char)two;
100+
}
101+
i++;
102+
if (padThree) {
103+
break;
104+
}
105+
if (dst) {
106+
dst[i] = (unsigned char)three;
107+
}
108+
i++;
109+
}
110+
*dstLength = i;
111+
return Error::kNone;
112+
}
113+
114+
size_t Base64::Encode(const void *srcv, size_t length, void *dstv) {
115+
const unsigned char *src = static_cast<const unsigned char *>(srcv);
116+
unsigned char *dst = static_cast<unsigned char *>(dstv);
117+
118+
const char *encode = kDefaultEncode;
119+
if (dst) {
120+
size_t remainder = length % 3;
121+
char unsigned const *const end = &src[length - remainder];
122+
while (src < end) {
123+
unsigned a = *src++;
124+
unsigned b = *src++;
125+
unsigned c = *src++;
126+
int d = c & 0x3F;
127+
c = (c >> 6 | b << 2) & 0x3F;
128+
b = (b >> 4 | a << 4) & 0x3F;
129+
a = a >> 2;
130+
*dst++ = encode[a];
131+
*dst++ = encode[b];
132+
*dst++ = encode[c];
133+
*dst++ = encode[d];
134+
}
135+
if (remainder > 0) {
136+
int k1 = 0;
137+
int k2 = EncodePad;
138+
int a = (uint8_t)*src++;
139+
if (remainder == 2) {
140+
int b = *src++;
141+
k1 = b >> 4;
142+
k2 = (b << 2) & 0x3F;
143+
}
144+
*dst++ = encode[a >> 2];
145+
*dst++ = encode[(k1 | a << 4) & 0x3F];
146+
*dst++ = encode[k2];
147+
*dst++ = encode[EncodePad];
148+
}
149+
}
150+
return (length + 2) / 3 * 4;
151+
}
152+
153+
} // namespace RNSkia

package/cpp/api/third_party/base64.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2006 The Android Open Source Project
3+
*
4+
* Use of this source code is governed by a BSD-style license that can be
5+
* found in the LICENSE file.
6+
*/
7+
#pragma once
8+
9+
#include <cstddef>
10+
11+
namespace RNSkia {
12+
13+
struct Base64 {
14+
public:
15+
enum class Error {
16+
kNone,
17+
kBadPadding,
18+
kBadChar,
19+
};
20+
21+
/**
22+
Base64 encodes src into dst.
23+
24+
Normally this is called once with 'dst' nullptr to get the required size,
25+
then again with an allocated 'dst' pointer to do the actual encoding.
26+
27+
@param dst nullptr or a pointer to a buffer large enough to receive the
28+
result
29+
30+
@return the required length of dst for encoding.
31+
*/
32+
static size_t Encode(const void *src, size_t length, void *dst);
33+
34+
/**
35+
Base64 decodes src into dst.
36+
37+
Normally this is called once with 'dst' nullptr to get the required size,
38+
then again with an allocated 'dst' pointer to do the actual encoding.
39+
40+
@param dst nullptr or a pointer to a buffer large enough to receive the
41+
result
42+
43+
@param dstLength assigned the length dst is required to be. Must not be
44+
nullptr.
45+
*/
46+
[[nodiscard]] static Error Decode(const void *src, size_t srcLength,
47+
void *dst, size_t *dstLength);
48+
};
49+
50+
} // namespace RNSkia

0 commit comments

Comments
 (0)