36#ifdef SK_ENABLE_ANDROID_UTILS
40#ifndef SK_BUILD_FOR_WIN
44#define MAX_SIZE (256 * 1024)
49 void* tmp = storage.
get();
58 size_t bytes =
stream->read(tmp, 1);
67 const char s[] =
"abcdefghijklmnopqrstuvwxyz";
76 for (
int i = 0;
i < 100; ++
i) {
86 std::unique_ptr<SkStreamAsset> stream2(
stream.duplicate());
91 FILE*
file = ::fopen(
path.c_str(),
"rb");
96 std::unique_ptr<SkStreamAsset> stream2(
stream.duplicate());
103 const char s[] =
"abcdefghijklmnopqrstuvwxyz";
105 for (
i = 0;
i < 100;
i++) {
110 char*
dst =
new char[100 * 26 + 1];
114 for (
i = 0;
i < 100;
i++) {
124 std::unique_ptr<SkStreamAsset> stream2(
stream->duplicate());
127 std::unique_ptr<SkStreamAsset> stream3(
stream->fork());
130 size_t bytes =
stream->read(&tmp, 1);
136 for (
i = 0;
i < 100;
i++) {
147 std::unique_ptr<SkStreamAsset> stream2(
stream->duplicate());
161 const size_t sizes[] = {
162 0, 1, 2, 0xFC, 0xFD, 0xFE, 0xFF, 0x100, 0x101, 32767, 32768, 32769,
163 0xFFFD, 0xFFFE, 0xFFFF, 0x10000, 0x10001,
164 0xFFFFFD, 0xFFFFFE, 0xFFFFFF, 0x1000000, 0x1000001,
165 0x7FFFFFFE, 0x7FFFFFFF, 0x80000000, 0x80000001, 0xFFFFFFFE, 0xFFFFFFFF
180 if (!rstream->readPackedUInt(&n)) {
215#ifndef SK_BUILD_FOR_IOS
227 void* peekPtr = peekStorage.
get();
228 void* readPtr = peekStorage.
get();
230 const size_t bytesPeeked =
stream->peek(peekPtr, bytesToPeek);
231 const size_t bytesRead =
stream->read(readPtr, bytesToPeek);
244 return bytesRead - bytesPeeked;
248 for (
size_t i = 1; !
stream->isAtEnd();
i++) {
253#ifdef SK_ENABLE_ANDROID_UTILS
257 std::unique_ptr<SkStream> dupe(original.
duplicate());
260 std::move(dupe), bufferSize);
264 for (
size_t i = 1; !bufferedStream->isAtEnd();
i++) {
266 if (unpeekableBytes > 0) {
283 const size_t bytesToPeek = bufferSize + 1;
291 const size_t bytesPeeked = bufferedStream->peek(peekStorage.get(), bytesToPeek);
292 if (0 == bytesPeeked) {
299 const size_t bytesRead = bufferedStream->read(readStorage.get(), bytesPeeked);
301 REPORTER_ASSERT(r, !memcmp(peekStorage.get(), readStorage.get(), bytesPeeked));
314 const char gAbcs[] =
"abcdefghijklmnopqrstuvwxyz";
320 if (tmpdir.isEmpty()) {
327 constexpr char filename[] =
"images/baby_tux.webp";
348#ifdef SK_ENABLE_ANDROID_UTILS
351 test_peeking_front_buffered_stream(
reporter, memStream,
i);
362 ERRORF(rep,
"Unexpected length.");
367 const uint8_t* expect = expected->
bytes();
376 ERRORF(rep,
"Peek Failed!");
380 ERRORF(rep,
"Peek returned wrong bytes!");
386 ERRORF(rep,
"Read Failed!");
393 const static int kSeed = 1234;
398 size_t totalWritten = 0;
399 for (
int i = 0;
i < 32; ++
i) {
402 for (
size_t j = 0; j <
size; ++j) {
406 totalWritten +=
size;
409 std::unique_ptr<SkStreamAsset> asset(dynamicMemoryWStream.
detachAsStream());
411 uint8_t* expectedPtr =
static_cast<uint8_t*
>(expected->
writable_data());
416 for (
size_t i = 0;
i < asset->getLength(); ++
i) {
417 expectedPtr[
i] = valueSource.
nextU() & 0xFF;
422DEF_TEST(StreamRemainingLengthIsBelow_MemoryStream, rep) {
446 DumbStream(
const uint8_t*
data,
size_t n)
451 memcpy(
buffer, &fData[fIdx], copyCount);
456 bool isAtEnd()
const override {
460 const uint8_t* fData;
475 if (
data->size() !=
N) {
479 if (0 != memcmp(
data->data(), srcData,
N)) {
485 const char az[] =
"abcdefghijklmnopqrstuvwxyz";
486 const unsigned N = 40000;
488 for (
unsigned i = 0;
i <
N; ++
i) {
494 const uint8_t* ptr =
data->bytes();
495 for (
unsigned i = 0;
i <
N; ++
i) {
496 if (0 != memcmp(ptr, az, strlen(az))) {
497 ERRORF(r,
"detachAsData() memcmp failed");
506 static const int N = 10000;
508 for (
int j = 0; j <
N; ++j) {
512 DumbStream dumbStream(
src.get(), (
size_t)
N);
532 ERRORF(r,
"Could not create SkFILEStream from %s", filename.
c_str());
542 const size_t middle =
size / 2;
543 if (!stream1.
seek(middle)) {
544 ERRORF(r,
"Could not seek SkFILEStream to %zu out of %zu", middle,
size);
551 ERRORF(r,
"Could not open %s as a FILE", filename.
c_str());
555 if (fseek(
file, (
long) middle, SEEK_SET) != 0) {
556 ERRORF(r,
"Could not fseek FILE to %zu out of %zu", middle,
size);
561 const size_t remaining =
size - middle;
565 auto test_full_read = [&r, &expected, remaining](
SkStream*
stream) {
604 auto test_seek = [&r, &expected, middle, remaining](
SkStream*
stream) {
606 const size_t arbitrary = middle / 2;
609 const size_t miniRemaining = remaining - arbitrary;
615 auto test_seek_beginning = [&r, &expected, remaining](
SkStream*
stream) {
632 const size_t middle = remaining / 2;
656 test_seek_beginning(
stream);
661 auto duplicate =
stream->duplicate();
663 ERRORF(r,
"Failed to duplicate the stream!");
665 test_all(duplicate.get(),
false);
669 auto fork =
stream->fork();
671 ERRORF(r,
"Failed to fork the stream!");
677 test_all(fork.get(),
false);
682 test_all(&stream2,
true);
sk_sp< SkData > GetResourceAsData(const char *resource)
SkString GetResourcePath(const char *resource)
static unsigned repeat(SkFixed fx, int max)
FILE * sk_fopen(const char path[], SkFILE_Flags)
bool StreamRemainingLengthIsBelow(SkStream *stream, size_t len)
bool SkStreamCopy(SkWStream *out, SkStream *input)
constexpr uint32_t SkToU32(S x)
static void test_fully_peekable_stream(skiatest::Reporter *r, SkStream *stream, size_t limit)
static void TestWStream(skiatest::Reporter *reporter)
static void TestNullData(skiatest::Reporter *reporter)
static void TestDereferencingData(skiatest::Reporter *reporter, SkMemoryStream *memStream)
static void stream_peek_test(skiatest::Reporter *rep, SkStreamAsset *asset, const SkData *expected)
static size_t compare_peek_to_read(skiatest::Reporter *reporter, SkStream *stream, size_t bytesToPeek)
static void TestPackedUInt(skiatest::Reporter *reporter)
static void stream_copy_test(skiatest::Reporter *reporter, const void *srcData, size_t N, SkStream *stream)
DEF_TEST(Stream, reporter)
static void test_loop_stream(skiatest::Reporter *reporter, SkStream *stream, const void *src, size_t len, int repeat)
static void test_filestreams(skiatest::Reporter *reporter, const char *tmpDir)
#define REPORTER_ASSERT(r, cond,...)
static void test_rewind(skiatest::Reporter *reporter)
const uint8_t * bytes() const
static sk_sp< SkData > MakeUninitialized(size_t length)
size_t bytesWritten() const override
void copyTo(void *dst) const
std::unique_ptr< SkStreamAsset > detachAsStream()
bool write(const void *buffer, size_t size) override
sk_sp< SkData > detachAsData()
bool seek(size_t position) override
size_t read(void *buffer, size_t size) override
size_t getLength() const override
size_t getPosition() const override
bool write(const void *buffer, size_t size) override
sk_sp< SkData > getData() const override
size_t read(void *buffer, size_t size) override
size_t getLength() const override
const void * getMemoryBase() override
void setData(sk_sp< SkData > data)
static SkString Join(const char *rootPath, const char *relativePath)
void setSeed(uint32_t seed)
uint32_t nextRangeU(uint32_t min, uint32_t max)
bool hasLength() const override
size_t getLength() const override=0
bool hasPosition() const override
std::unique_ptr< SkStream > duplicate() const
virtual size_t peek(void *, size_t) const
virtual bool isAtEnd() const =0
virtual size_t read(void *buffer, size_t size)=0
const char * c_str() const
bool writePackedUInt(size_t)
bool writeText(const char text[])
static std::unique_ptr< SkStreamRewindable > Make(std::unique_ptr< SkStream > stream, size_t minBufferSize)
Dart_NativeFunction function
static float max(float r, float g, float b)
static float min(float r, float g, float b)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
std::shared_ptr< const fml::Mapping > data