Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
Resources.cpp File Reference
#include "tools/Resources.h"
#include "include/core/SkData.h"
#include "include/core/SkStream.h"
#include "include/private/base/SkDebug.h"
#include "src/utils/SkOSPath.h"
#include "tools/flags/CommandLineFlags.h"
#include <utility>

Go to the source code of this file.

Functions

static DEFINE_string2 (resourcePath, i, "resources", "Directory with test resources: images, fonts, etc.")
 
SkString GetResourcePath (const char *resource)
 
void SetResourcePath (const char *resource)
 
std::unique_ptr< SkStreamAssetGetResourceAsStream (const char *resource, bool useFileStream)
 
sk_sp< SkDataGetResourceAsData (const char *resource)
 

Variables

sk_sp< SkData >(* gResourceFactory )(const char *) = nullptr
 

Function Documentation

◆ DEFINE_string2()

static DEFINE_string2 ( resourcePath  ,
,
"resources"  ,
"Directory with test resources:  images,
fonts  ,
etc."   
)
static

◆ GetResourceAsData()

sk_sp< SkData > GetResourceAsData ( const char *  resource)

Definition at line 42 of file Resources.cpp.

42 {
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}
sk_sp< SkData >(* gResourceFactory)(const char *)
Definition Resources.cpp:21
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
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41

◆ GetResourceAsStream()

std::unique_ptr< SkStreamAsset > GetResourceAsStream ( const char *  resource,
bool  useFileStream 
)

Definition at line 31 of file Resources.cpp.

31 {
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}
sk_sp< SkData > GetResourceAsData(const char *resource)
Definition Resources.cpp:42
static std::unique_ptr< SkFILEStream > Make(const char path[])
Definition SkStream.h:314
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
Definition switches.h:57

◆ GetResourcePath()

SkString GetResourcePath ( const char *  resource)

Definition at line 23 of file Resources.cpp.

23 {
24 return SkOSPath::Join(FLAGS_resourcePath[0], resource);
25}
static SkString Join(const char *rootPath, const char *relativePath)
Definition SkOSPath.cpp:14

◆ SetResourcePath()

void SetResourcePath ( const char *  resource)

Definition at line 27 of file Resources.cpp.

27 {
28 FLAGS_resourcePath.set(0, resource);
29}

Variable Documentation

◆ gResourceFactory

sk_sp< SkData >(* gResourceFactory) (const char *) ( const char *  ) = nullptr

Definition at line 18 of file Resources.cpp.