diff options
author | Hal Canary <halcanary@google.com> | 2017-12-08 13:35:47 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-12-11 22:06:38 +0000 |
commit | a4935104a5dfd646bfecb01b5f4618785bedaff7 (patch) | |
tree | 8f13a056c4fc765da4eaa7ceb7f865bcb4e3aeae /tools | |
parent | 94f509b5042c29540d0b4ef255798b8daed5ace6 (diff) |
resources: optionally link them into our binary
To enable, set skia_embed_resources=true in args.gn.
Also add *-EmbededResouces bots.
Change-Id: Ia69b26e926a3ad4676a4fa021894432ea2104538
Reviewed-on: https://skia-review.googlesource.com/82626
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/BinaryAsset.h | 18 | ||||
-rw-r--r-- | tools/Resources.cpp | 15 |
2 files changed, 33 insertions, 0 deletions
diff --git a/tools/BinaryAsset.h b/tools/BinaryAsset.h new file mode 100644 index 0000000000..6fb7157596 --- /dev/null +++ b/tools/BinaryAsset.h @@ -0,0 +1,18 @@ +/* + * Copyright 2017 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#ifndef BinaryAsset_DEFINED +#define BinaryAsset_DEFINED + +#include <cstddef> + +struct BinaryAsset { + const char* name; + const void* data; + size_t len; +}; + +#endif // BinaryAsset_DEFINED diff --git a/tools/Resources.cpp b/tools/Resources.cpp index 6436a0ddb8..9d54026986 100644 --- a/tools/Resources.cpp +++ b/tools/Resources.cpp @@ -5,6 +5,7 @@ * found in the LICENSE file. */ +#include "BinaryAsset.h" #include "Resources.h" #include "SkBitmap.h" #include "SkCommandLineFlags.h" @@ -40,6 +41,19 @@ std::unique_ptr<SkStreamAsset> GetResourceAsStream(const char* resource) { : nullptr; } +#ifdef SK_EMBED_RESOURCES +extern BinaryAsset gResources[]; +sk_sp<SkData> GetResourceAsData(const char* resource) { + for (const BinaryAsset* ptr = gResources; ptr->name; ++ptr) { + if (0 == strcmp(resource, ptr->name)) { + return SkData::MakeWithoutCopy(ptr->data, ptr->len); + } + } + SkDebugf("Resource \"%s\" not found.\n", resource); + SK_ABORT("missing resource"); + return nullptr; +} +#else sk_sp<SkData> GetResourceAsData(const char* resource) { auto data = SkData::MakeFromFileName(GetResourcePath(resource).c_str()); if (!data) { @@ -47,6 +61,7 @@ sk_sp<SkData> GetResourceAsData(const char* resource) { } return data; } +#endif sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource) { std::unique_ptr<SkStreamAsset> stream(GetResourceAsStream(resource)); |