forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wire up the Skia persistent GPU related artifacts cache. (flutter#6278)
Also teaches FML to create files and directories.
- Loading branch information
1 parent
9d4b80a
commit f2a3df9
Showing
42 changed files
with
1,412 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2018 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/fml/base32.h" | ||
|
||
#include <limits> | ||
|
||
#include "flutter/fml/macros.h" | ||
|
||
namespace fml { | ||
|
||
static constexpr char kEncoding[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; | ||
|
||
std::pair<bool, std::string> Base32Encode(StringView input) { | ||
if (input.empty()) { | ||
return {true, ""}; | ||
} | ||
|
||
if (input.size() > std::numeric_limits<size_t>::max() / 8) { | ||
return {false, ""}; | ||
} | ||
|
||
std::string output; | ||
const size_t encoded_length = (input.size() * 8 + 4) / 5; | ||
output.reserve(encoded_length); | ||
|
||
uint16_t bit_stream = (static_cast<uint8_t>(input[0]) << 8); | ||
size_t next_byte_index = 1; | ||
int free_bits = 8; | ||
|
||
while (free_bits < 16) { | ||
output.push_back(kEncoding[(bit_stream & 0xf800) >> 11]); | ||
bit_stream <<= 5; | ||
free_bits += 5; | ||
|
||
if (free_bits >= 8 && next_byte_index < input.size()) { | ||
free_bits -= 8; | ||
bit_stream += static_cast<uint8_t>(input[next_byte_index++]) << free_bits; | ||
} | ||
} | ||
|
||
return {true, output}; | ||
} | ||
|
||
} // namespace fml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Copyright 2018 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. | ||
|
||
#ifndef FLUTTER_FML_BASE32_H_ | ||
#define FLUTTER_FML_BASE32_H_ | ||
|
||
#include <string> | ||
#include <utility> | ||
|
||
#include "flutter/fml/string_view.h" | ||
|
||
namespace fml { | ||
|
||
std::pair<bool, std::string> Base32Encode(StringView input); | ||
|
||
} // namespace fml | ||
|
||
#endif // FLUTTER_FML_BASE32_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright 2018 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/fml/base32.h" | ||
#include "gtest/gtest.h" | ||
|
||
TEST(Base32Test, CanEncode) { | ||
{ | ||
auto result = fml::Base32Encode("hello"); | ||
ASSERT_TRUE(result.first); | ||
ASSERT_EQ(result.second, "NBSWY3DP"); | ||
} | ||
|
||
{ | ||
auto result = fml::Base32Encode("helLo"); | ||
ASSERT_TRUE(result.first); | ||
ASSERT_EQ(result.second, "NBSWYTDP"); | ||
} | ||
|
||
{ | ||
auto result = fml::Base32Encode(""); | ||
ASSERT_TRUE(result.first); | ||
ASSERT_EQ(result.second, ""); | ||
} | ||
|
||
{ | ||
auto result = fml::Base32Encode("1"); | ||
ASSERT_TRUE(result.first); | ||
ASSERT_EQ(result.second, "GE"); | ||
} | ||
|
||
{ | ||
auto result = fml::Base32Encode("helLo"); | ||
ASSERT_TRUE(result.first); | ||
ASSERT_EQ(result.second, "NBSWYTDP"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2018 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/fml/file.h" | ||
|
||
#include "flutter/fml/logging.h" | ||
|
||
namespace fml { | ||
|
||
static fml::UniqueFD CreateDirectory(const fml::UniqueFD& base_directory, | ||
const std::vector<std::string>& components, | ||
FilePermission permission, | ||
size_t index) { | ||
FML_DCHECK(index <= components.size()); | ||
|
||
const char* file_path = components[index].c_str(); | ||
|
||
auto directory = OpenDirectory(base_directory, file_path, true, permission); | ||
|
||
if (!directory.is_valid()) { | ||
return {}; | ||
} | ||
|
||
if (index == components.size() - 1) { | ||
return directory; | ||
} | ||
|
||
return CreateDirectory(directory, components, permission, index + 1); | ||
} | ||
|
||
fml::UniqueFD CreateDirectory(const fml::UniqueFD& base_directory, | ||
const std::vector<std::string>& components, | ||
FilePermission permission) { | ||
if (!IsDirectory(base_directory)) { | ||
return {}; | ||
} | ||
|
||
if (components.size() == 0) { | ||
return {}; | ||
} | ||
|
||
return CreateDirectory(base_directory, components, permission, 0); | ||
} | ||
|
||
} // namespace fml |
Oops, something went wrong.