Skip to content

Commit 3105db8

Browse files
authored
SKP based shader warmup (flutter#20643)
1 parent e66a720 commit 3105db8

27 files changed

+443
-19
lines changed

assets/asset_manager.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,24 @@ std::unique_ptr<fml::Mapping> AssetManager::GetAsMapping(
5151
return nullptr;
5252
}
5353

54+
// |AssetResolver|
55+
std::vector<std::unique_ptr<fml::Mapping>> AssetManager::GetAsMappings(
56+
const std::string& asset_pattern) const {
57+
std::vector<std::unique_ptr<fml::Mapping>> mappings;
58+
if (asset_pattern.size() == 0) {
59+
return mappings;
60+
}
61+
TRACE_EVENT1("flutter", "AssetManager::GetAsMappings", "pattern",
62+
asset_pattern.c_str());
63+
for (const auto& resolver : resolvers_) {
64+
auto resolver_mappings = resolver->GetAsMappings(asset_pattern);
65+
mappings.insert(mappings.end(),
66+
std::make_move_iterator(resolver_mappings.begin()),
67+
std::make_move_iterator(resolver_mappings.end()));
68+
}
69+
return mappings;
70+
}
71+
5472
// |AssetResolver|
5573
bool AssetManager::IsValid() const {
5674
return resolvers_.size() > 0;

assets/asset_manager.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ class AssetManager final : public AssetResolver {
3737
std::unique_ptr<fml::Mapping> GetAsMapping(
3838
const std::string& asset_name) const override;
3939

40+
// |AssetResolver|
41+
std::vector<std::unique_ptr<fml::Mapping>> GetAsMappings(
42+
const std::string& asset_pattern) const override;
43+
4044
private:
4145
std::deque<std::unique_ptr<AssetResolver>> resolvers_;
4246

assets/asset_resolver.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ class AssetResolver {
4242
[[nodiscard]] virtual std::unique_ptr<fml::Mapping> GetAsMapping(
4343
const std::string& asset_name) const = 0;
4444

45+
// Same as GetAsMapping() but returns mappings for all files who's name
46+
// matches |pattern|. Returns empty vector if no matching assets are found
47+
[[nodiscard]] virtual std::vector<std::unique_ptr<fml::Mapping>>
48+
GetAsMappings(const std::string& asset_pattern) const {
49+
return {};
50+
};
51+
4552
private:
4653
FML_DISALLOW_COPY_AND_ASSIGN(AssetResolver);
4754
};

assets/directory_asset_bundle.cc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "flutter/assets/directory_asset_bundle.h"
66

7+
#include <regex>
78
#include <utility>
89

910
#include "flutter/fml/eintr_wrapper.h"
@@ -53,4 +54,32 @@ std::unique_ptr<fml::Mapping> DirectoryAssetBundle::GetAsMapping(
5354
return mapping;
5455
}
5556

57+
std::vector<std::unique_ptr<fml::Mapping>> DirectoryAssetBundle::GetAsMappings(
58+
const std::string& asset_pattern) const {
59+
std::vector<std::unique_ptr<fml::Mapping>> mappings;
60+
if (!is_valid_) {
61+
FML_DLOG(WARNING) << "Asset bundle was not valid.";
62+
return mappings;
63+
}
64+
65+
std::regex asset_regex(asset_pattern);
66+
fml::FileVisitor visitor = [&](const fml::UniqueFD& directory,
67+
const std::string& filename) {
68+
if (std::regex_match(filename, asset_regex)) {
69+
auto mapping = std::make_unique<fml::FileMapping>(fml::OpenFile(
70+
directory, filename.c_str(), false, fml::FilePermission::kRead));
71+
72+
if (mapping && mapping->IsValid()) {
73+
mappings.push_back(std::move(mapping));
74+
} else {
75+
FML_LOG(ERROR) << "Mapping " << filename << " failed";
76+
}
77+
}
78+
return true;
79+
};
80+
fml::VisitFilesRecursively(descriptor_, visitor);
81+
82+
return mappings;
83+
}
84+
5685
} // namespace flutter

assets/directory_asset_bundle.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class DirectoryAssetBundle : public AssetResolver {
3434
std::unique_ptr<fml::Mapping> GetAsMapping(
3535
const std::string& asset_name) const override;
3636

37+
// |AssetResolver|
38+
std::vector<std::unique_ptr<fml::Mapping>> GetAsMappings(
39+
const std::string& asset_pattern) const override;
40+
3741
FML_DISALLOW_COPY_AND_ASSIGN(DirectoryAssetBundle);
3842
};
3943

fml/concurrent_message_loop.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "flutter/fml/closure.h"
1414
#include "flutter/fml/macros.h"
15+
#include "flutter/fml/task_runner.h"
1516

1617
namespace fml {
1718

@@ -58,13 +59,13 @@ class ConcurrentMessageLoop
5859
FML_DISALLOW_COPY_AND_ASSIGN(ConcurrentMessageLoop);
5960
};
6061

61-
class ConcurrentTaskRunner {
62+
class ConcurrentTaskRunner : public BasicTaskRunner {
6263
public:
6364
ConcurrentTaskRunner(std::weak_ptr<ConcurrentMessageLoop> weak_loop);
6465

65-
~ConcurrentTaskRunner();
66+
virtual ~ConcurrentTaskRunner();
6667

67-
void PostTask(const fml::closure& task);
68+
void PostTask(const fml::closure& task) override;
6869

6970
private:
7071
friend ConcurrentMessageLoop;

fml/task_runner.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,17 @@ namespace fml {
1616

1717
class MessageLoopImpl;
1818

19-
class TaskRunner : public fml::RefCountedThreadSafe<TaskRunner> {
19+
class BasicTaskRunner {
20+
public:
21+
virtual void PostTask(const fml::closure& task) = 0;
22+
};
23+
24+
class TaskRunner : public fml::RefCountedThreadSafe<TaskRunner>,
25+
public BasicTaskRunner {
2026
public:
2127
virtual ~TaskRunner();
2228

23-
virtual void PostTask(const fml::closure& task);
29+
virtual void PostTask(const fml::closure& task) override;
2430

2531
virtual void PostTaskForTime(const fml::closure& task,
2632
fml::TimePoint target_time);

shell/common/persistent_cache.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,4 +391,14 @@ void PersistentCache::SetAssetManager(std::shared_ptr<AssetManager> value) {
391391
asset_manager_ = value;
392392
}
393393

394+
std::vector<std::unique_ptr<fml::Mapping>>
395+
PersistentCache::GetSkpsFromAssetManager() const {
396+
if (!asset_manager_) {
397+
FML_LOG(ERROR)
398+
<< "PersistentCache::GetSkpsFromAssetManager: Asset manager not set!";
399+
return std::vector<std::unique_ptr<fml::Mapping>>();
400+
}
401+
return asset_manager_->GetAsMappings(".*\\.skp$");
402+
}
403+
394404
} // namespace flutter

shell/common/persistent_cache.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ class PersistentCache : public GrContextOptions::PersistentCache {
7474
/// Load all the SkSL shader caches in the right directory.
7575
std::vector<SkSLCache> LoadSkSLs();
7676

77+
// Return mappings for all skp's accessible through the AssetManager
78+
std::vector<std::unique_ptr<fml::Mapping>> GetSkpsFromAssetManager() const;
79+
7780
/// Set the asset manager from which PersistentCache can load SkLSs. A nullptr
7881
/// can be provided to clear the asset manager.
7982
static void SetAssetManager(std::shared_ptr<AssetManager> value);

shell/common/rasterizer.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,7 @@ static sk_sp<SkData> ScreenshotLayerTreeAsPicture(
511511
#if defined(OS_FUCHSIA)
512512
SkSerialProcs procs = {0};
513513
procs.fImageProc = SerializeImageWithoutData;
514+
procs.fTypefaceProc = SerializeTypefaceWithoutData;
514515
#else
515516
SkSerialProcs procs = {0};
516517
procs.fTypefaceProc = SerializeTypefaceWithData;

0 commit comments

Comments
 (0)