forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
embedder_resources.cc
52 lines (41 loc) · 1.3 KB
/
embedder_resources.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/runtime/embedder_resources.h"
#include <string.h>
#include "flutter/fml/logging.h"
namespace flutter {
using runtime::ResourcesEntry;
EmbedderResources::EmbedderResources(ResourcesEntry* resources_table)
: resources_table_(resources_table) {}
const int EmbedderResources::kNoSuchInstance = -1;
int EmbedderResources::ResourceLookup(const char* path, const char** resource) {
for (int i = 0; resources_table_[i].path_ != nullptr; i++) {
const ResourcesEntry& entry = resources_table_[i];
if (strcmp(path, entry.path_) == 0) {
*resource = entry.resource_;
FML_DCHECK(entry.length_ > 0);
return entry.length_;
}
}
return kNoSuchInstance;
}
const char* EmbedderResources::Path(int idx) {
FML_DCHECK(idx >= 0);
ResourcesEntry* entry = At(idx);
if (entry == nullptr) {
return nullptr;
}
FML_DCHECK(entry->path_ != nullptr);
return entry->path_;
}
ResourcesEntry* EmbedderResources::At(int idx) {
FML_DCHECK(idx >= 0);
for (int i = 0; resources_table_[i].path_ != nullptr; i++) {
if (idx == i) {
return &resources_table_[i];
}
}
return nullptr;
}
} // namespace flutter