diff options
-rw-r--r-- | BUILD.gn | 21 | ||||
-rwxr-xr-x | gn/generate_binary_asset.py | 41 | ||||
-rw-r--r-- | tools/BinaryAsset.h | 18 | ||||
-rw-r--r-- | tools/Resources.cpp | 35 | ||||
-rw-r--r-- | tools/skqp/README.md | 3 | ||||
-rwxr-xr-x | tools/skqp/generate_gn_args | 1 | ||||
-rwxr-xr-x | tools/skqp/setup_resources | 11 | ||||
-rw-r--r-- | tools/skqp/skqp.cpp | 2 |
8 files changed, 15 insertions, 117 deletions
@@ -31,7 +31,6 @@ declare_args() { skia_use_metal = false skia_use_libheif = is_skia_dev_build skia_use_skcms = is_skia_dev_build - skia_embed_resources = false skia_android_serial = "" skia_enable_discrete_gpu = true @@ -939,20 +938,6 @@ if (skia_enable_tools) { ] } - if (skia_embed_resources) { - action("binary_resources.cpp") { - script = "gn/generate_binary_asset.py" - args = [ - rebase_path("resources"), - "gResources", - rebase_path("$target_gen_dir/binary_resources.cpp", root_build_dir), - ] - outputs = [ - "$target_gen_dir/binary_resources.cpp", - ] - } - } - if (skia_enable_gpu && target_cpu == "x64") { executable("fiddle") { libs = [] @@ -1289,11 +1274,6 @@ if (skia_enable_tools) { public_deps = [ "//third_party/jsoncpp", ] - if (skia_embed_resources) { - defines = [ "SK_EMBED_RESOURCES" ] - sources += [ "$target_gen_dir/binary_resources.cpp" ] - deps += [ ":binary_resources.cpp" ] - } } import("gn/gm.gni") @@ -1831,6 +1811,7 @@ if (skia_enable_tools) { deps = [ ":skia", ":skqp_lib", + ":tool_utils", "//third_party/googletest", ] } diff --git a/gn/generate_binary_asset.py b/gn/generate_binary_asset.py deleted file mode 100755 index 671231b401..0000000000 --- a/gn/generate_binary_asset.py +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env python2 -# Copyright 2017 Google Inc. -# Use of this source code is governed by a BSD-style license that can be -# found in the LICENSE file. - -import os -import sys - -def get_resources(rdir): - for root, _, files in os.walk(rdir): - for filepath in files: - fullpath = os.path.join(root, filepath) - if os.path.isfile(fullpath): - yield os.path.relpath(fullpath, rdir) - -def main(resource_dir, array_name, filename): - with open(filename, 'w') as o: - o.write('//generated file\n#include "BinaryAsset.h"\n\n'); - names = [] - for n in sorted(get_resources(resource_dir)): - o.write('static const unsigned char x%d[] = {\n' % len(names)) - with open(os.path.join(resource_dir, n), 'rb') as f: - while True: - buf = f.read(20) - if len(buf) == 0: - break - o.write(''.join('%d,' % ord(x) for x in buf) + '\n') - o.write('};\n') - names.append(n) - o.write('\nBinaryAsset %s[] = {\n' % array_name) - for i, n in enumerate(names): - o.write(' {"%s", x%d, sizeof(x%d)},\n' % (n, i, i)) - o.write(' {nullptr, nullptr, 0}\n};\n') - -if __name__ == '__main__': - if len(sys.argv) < 4: - msg = 'usage:\n %s SOURCE_DIRECTORY ARRAY_IDENTIFIER OUTPUT_PATH.cpp\n\n' - sys.stderr.write(msg % sys.argv[0]) - exit(1) - main(*sys.argv[1:4]) - diff --git a/tools/BinaryAsset.h b/tools/BinaryAsset.h deleted file mode 100644 index 6fb7157596..0000000000 --- a/tools/BinaryAsset.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - * 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 002d4111ae..0e343c4883 100644 --- a/tools/Resources.cpp +++ b/tools/Resources.cpp @@ -5,7 +5,7 @@ * found in the LICENSE file. */ -#include "BinaryAsset.h" +#include "ResourceFactory.h" #include "Resources.h" #include "SkBitmap.h" #include "SkCommandLineFlags.h" @@ -19,6 +19,8 @@ DEFINE_string2(resourcePath, i, "resources", "Directory with test resources: images, fonts, etc."); +sk_sp<SkData> (*gResourceFactory)(const char*) = nullptr; + SkString GetResourcePath(const char* resource) { return SkOSPath::Join(FLAGS_resourcePath[0], resource); } @@ -27,7 +29,6 @@ void SetResourcePath(const char* resource) { FLAGS_resourcePath.set(0, resource); } - bool DecodeDataToBitmap(sk_sp<SkData> data, SkBitmap* dst) { std::unique_ptr<SkImageGenerator> gen(SkImageGenerator::MakeFromEncoded(std::move(data))); return gen && dst->tryAllocPixels(gen->getInfo()) && @@ -41,36 +42,20 @@ std::unique_ptr<SkStreamAsset> GetResourceAsStream(const char* resource) { : nullptr; } -#ifdef SK_EMBED_RESOURCES - -#include "ResourceFactory.h" - -sk_sp<SkData> (*gResourceFactory)(const char*) = nullptr; - -extern BinaryAsset gResources[]; - sk_sp<SkData> GetResourceAsData(const char* resource) { if (gResourceFactory) { - return gResourceFactory(resource); - } - for (const BinaryAsset* ptr = gResources; ptr->name; ++ptr) { - if (0 == strcmp(resource, ptr->name)) { - return SkData::MakeWithoutCopy(ptr->data, ptr->len); + if (auto data = gResourceFactory(resource)) { + return data; } + SkDebugf("Resource \"%s\" not found.\n", resource); + SK_ABORT("missing resource"); + } + if (auto data = SkData::MakeFromFileName(GetResourcePath(resource).c_str())) { + return data; } 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) { - SkDebugf("Resource \"%s\" not found.\n", resource); - } - return data; -} -#endif sk_sp<SkTypeface> MakeResourceAsTypeface(const char* resource) { std::unique_ptr<SkStreamAsset> stream(GetResourceAsStream(resource)); diff --git a/tools/skqp/README.md b/tools/skqp/README.md index bf41b25b08..cd3f0cdf3d 100644 --- a/tools/skqp/README.md +++ b/tools/skqp/README.md @@ -35,10 +35,10 @@ How to run the SkQP tests test another architecture, replace `arm` with `x86`, `x64`, or `arm64`.) python tools/skqp/download_model + python tools/skqp/setup_resources python tools/git-sync-deps python tools/skqp/generate_gn_args out/skqp-arm "$ANDROID_NDK" arm bin/gn gen out/skqp-arm - python tools/skqp/setup_resources . out/skqp-arm 6. Build, install, and run. @@ -69,7 +69,6 @@ Run as a non-APK executable 2. Build the SkQP program, load files on the device, and run skqp: - rm -f out/skqp-arm/gen/binary_resources.cpp ninja -C out/skqp-arm skqp python tools/skqp/run_skqp_exe out/skqp-arm diff --git a/tools/skqp/generate_gn_args b/tools/skqp/generate_gn_args index 7031414d59..21009a0c1d 100755 --- a/tools/skqp/generate_gn_args +++ b/tools/skqp/generate_gn_args @@ -12,7 +12,6 @@ target_cpu = "{arch}" is_debug = false ndk = "{ndk}" ndk_api = 26 -skia_embed_resources = true skia_enable_fontmgr_empty = true skia_enable_pdf = false skia_use_dng_sdk = false diff --git a/tools/skqp/setup_resources b/tools/skqp/setup_resources index 45b9b70e09..22f27a85dd 100755 --- a/tools/skqp/setup_resources +++ b/tools/skqp/setup_resources @@ -9,16 +9,7 @@ import shutil import sys if __name__ == '__main__': - if len(sys.argv) != 3 or not os.path.isdir(sys.argv[1]) or not os.path.isdir(sys.argv[2]): - sys.stderr.write('Usage\n %s SKIA_DIR BUILD_DIR\n\n' % sys.argv[0]) - sys.exit(1) - skia = sys.argv[1] - gen = os.path.join(sys.argv[2], 'gen') - if not os.path.isdir(gen): - os.mkdir(gen) - with open(os.path.join(gen, 'binary_resources.cpp'), 'w') as o: - o.write('#include "BinaryAsset.h"\n' - 'BinaryAsset gResources[] = { {nullptr, nullptr, 0} };\n') + skia = os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir) dst = os.path.join(skia, 'platform_tools', 'android', 'apps', 'skqp', 'src', 'main', 'assets', 'resources') if os.path.isdir(dst) and not os.path.islink(dst): diff --git a/tools/skqp/skqp.cpp b/tools/skqp/skqp.cpp index b3824a817a..cba52de6be 100644 --- a/tools/skqp/skqp.cpp +++ b/tools/skqp/skqp.cpp @@ -21,6 +21,7 @@ #pragma clang diagnostic pop #endif +#include "Resources.h" #include "SkStream.h" #include "SkString.h" @@ -134,6 +135,7 @@ int main(int argc, char** argv) { << " [GTEST_ARGUMENTS] GMKB_DIRECTORY_PATH GMKB_REPORT_PATH\n\n"; return 1; } + SetResourcePath((std::string(argv[1]) + "/resources").c_str()); gAssetMgr.reset(new StdAssetManager(argv[1])); if (argc > 2) { gReportDirectoryPath = argv[2]; |