Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Resources.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 Google Inc.
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
8#include "tools/Resources.h"
9
10#include "include/core/SkData.h"
13#include "src/utils/SkOSPath.h"
15
16#include <utility>
17
18static DEFINE_string2(resourcePath, i, "resources",
19 "Directory with test resources: images, fonts, etc.");
20
21sk_sp<SkData> (*gResourceFactory)(const char*) = nullptr;
22
23SkString GetResourcePath(const char* resource) {
24 return SkOSPath::Join(FLAGS_resourcePath[0], resource);
25}
26
27void SetResourcePath(const char* resource) {
28 FLAGS_resourcePath.set(0, resource);
29}
30
31std::unique_ptr<SkStreamAsset> GetResourceAsStream(const char* resource, bool useFileStream) {
32 if (useFileStream) {
33 auto path = GetResourcePath(resource);
34 return SkFILEStream::Make(path.c_str());
35 } else {
36 auto data = GetResourceAsData(resource);
37 return data ? std::unique_ptr<SkStreamAsset>(new SkMemoryStream(std::move(data)))
38 : nullptr;
39 }
40}
41
42sk_sp<SkData> GetResourceAsData(const char* resource) {
44 ? gResourceFactory(resource)
45 : SkData::MakeFromFileName(GetResourcePath(resource).c_str())) {
46 return data;
47 }
48 SkDebugf("Resource \"%s\" not found.\n", GetResourcePath(resource).c_str());
49 #ifdef SK_TOOLS_REQUIRE_RESOURCES
50 SK_ABORT("missing resource");
51 #endif
52 return nullptr;
53}
#define DEFINE_string2(name, shortName, defaultValue, helpString)
std::unique_ptr< SkStreamAsset > GetResourceAsStream(const char *resource, bool useFileStream)
Definition Resources.cpp:31
void SetResourcePath(const char *resource)
Definition Resources.cpp:27
sk_sp< SkData >(* gResourceFactory)(const char *)
Definition Resources.cpp:21
sk_sp< SkData > GetResourceAsData(const char *resource)
Definition Resources.cpp:42
SkString GetResourcePath(const char *resource)
Definition Resources.cpp:23
#define SK_ABORT(message,...)
Definition SkAssert.h:70
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static sk_sp< SkData > MakeFromFileName(const char path[])
Definition SkData.cpp:148
static std::unique_ptr< SkFILEStream > Make(const char path[])
Definition SkStream.h:314
static SkString Join(const char *rootPath, const char *relativePath)
Definition SkOSPath.cpp:14