From 537d9c0229b296a1b19f678432011d748d73cf18 Mon Sep 17 00:00:00 2001 From: Hal Canary Date: Tue, 30 Jan 2018 11:30:48 -0500 Subject: SkQP: remove skia_embed_resources option Motivation: delete unnecessary code. ResourceFactory.h provides a much more flexible way of fixing the same problem. Change-Id: Ib8a3ce25ce98e4f752dc1e7ce88eb9ceb95a4372 Reviewed-on: https://skia-review.googlesource.com/101920 Reviewed-by: Derek Sollenberger Commit-Queue: Hal Canary --- tools/BinaryAsset.h | 18 ------------------ tools/Resources.cpp | 35 ++++++++++------------------------- tools/skqp/README.md | 3 +-- tools/skqp/generate_gn_args | 1 - tools/skqp/setup_resources | 11 +---------- tools/skqp/skqp.cpp | 2 ++ 6 files changed, 14 insertions(+), 56 deletions(-) delete mode 100644 tools/BinaryAsset.h (limited to 'tools') 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 - -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 (*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 data, SkBitmap* dst) { std::unique_ptr gen(SkImageGenerator::MakeFromEncoded(std::move(data))); return gen && dst->tryAllocPixels(gen->getInfo()) && @@ -41,36 +42,20 @@ std::unique_ptr GetResourceAsStream(const char* resource) { : nullptr; } -#ifdef SK_EMBED_RESOURCES - -#include "ResourceFactory.h" - -sk_sp (*gResourceFactory)(const char*) = nullptr; - -extern BinaryAsset gResources[]; - sk_sp 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 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 MakeResourceAsTypeface(const char* resource) { std::unique_ptr 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]; -- cgit v1.2.3