Skip to content

Commit

Permalink
Wire up the Skia persistent GPU related artifacts cache. (flutter#6278)
Browse files Browse the repository at this point in the history
Also teaches FML to create files and directories.
  • Loading branch information
chinmaygarde authored Sep 26, 2018
1 parent 9d4b80a commit f2a3df9
Show file tree
Hide file tree
Showing 42 changed files with 1,412 additions and 219 deletions.
6 changes: 2 additions & 4 deletions assets/directory_asset_bundle.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ std::unique_ptr<fml::Mapping> DirectoryAssetBundle::GetAsMapping(
return nullptr;
}

auto mapping = std::make_unique<fml::FileMapping>(
fml::OpenFile(descriptor_, asset_name.c_str(), fml::OpenPermission::kRead,
false /* directory */),
false /* executable */);
auto mapping = std::make_unique<fml::FileMapping>(fml::OpenFile(
descriptor_, asset_name.c_str(), false, fml::FilePermission::kRead));

if (mapping->GetMapping() == nullptr) {
return nullptr;
Expand Down
82 changes: 46 additions & 36 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -532,55 +532,28 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

====================================================================================================
LIBRARY: engine
ORIGIN: ../../../flutter/fml/platform/darwin/scoped_block.h + ../../../LICENSE
TYPE: LicenseType.bsd
FILE: ../../../flutter/fml/platform/darwin/scoped_block.h
----------------------------------------------------------------------------------------------------
Copyright (c) 2013 The Chromium Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
====================================================================================================

====================================================================================================
LIBRARY: engine
ORIGIN: ../../../flutter/fml/platform/fuchsia/paths_fuchsia.cc + ../../../LICENSE
ORIGIN: ../../../flutter/fml/platform/android/paths_android.h + ../../../LICENSE
TYPE: LicenseType.bsd
FILE: ../../../flutter/fml/base32.cc
FILE: ../../../flutter/fml/base32.h
FILE: ../../../flutter/fml/base32_unittest.cc
FILE: ../../../flutter/fml/file.cc
FILE: ../../../flutter/fml/file.h
FILE: ../../../flutter/fml/file_unittest.cc
FILE: ../../../flutter/fml/macros.h
FILE: ../../../flutter/fml/mapping.cc
FILE: ../../../flutter/fml/message.cc
FILE: ../../../flutter/fml/message.h
FILE: ../../../flutter/fml/message_unittests.cc
FILE: ../../../flutter/fml/native_library.h
FILE: ../../../flutter/fml/paths.cc
FILE: ../../../flutter/fml/platform/android/paths_android.h
FILE: ../../../flutter/fml/platform/fuchsia/paths_fuchsia.cc
FILE: ../../../flutter/fml/platform/posix/file_posix.cc
FILE: ../../../flutter/fml/platform/posix/native_library_posix.cc
FILE: ../../../flutter/fml/platform/posix/paths_posix.cc
FILE: ../../../flutter/fml/platform/win/errors_win.cc
FILE: ../../../flutter/fml/platform/win/errors_win.h
FILE: ../../../flutter/fml/platform/win/file_win.cc
FILE: ../../../flutter/fml/platform/win/native_library_win.cc
FILE: ../../../flutter/fml/platform/win/wstring_conversion.h
Expand All @@ -595,6 +568,8 @@ FILE: ../../../flutter/lib/ui/plugins/callback_cache.cc
FILE: ../../../flutter/lib/ui/plugins/callback_cache.h
FILE: ../../../flutter/shell/common/isolate_configuration.cc
FILE: ../../../flutter/shell/common/isolate_configuration.h
FILE: ../../../flutter/shell/common/persistent_cache.cc
FILE: ../../../flutter/shell/common/persistent_cache.h
FILE: ../../../flutter/shell/platform/android/android_shell_holder.cc
FILE: ../../../flutter/shell/platform/android/android_shell_holder.h
FILE: ../../../flutter/shell/platform/android/platform_message_response_android.cc
Expand Down Expand Up @@ -640,6 +615,41 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
====================================================================================================

====================================================================================================
LIBRARY: engine
ORIGIN: ../../../flutter/fml/platform/darwin/scoped_block.h + ../../../LICENSE
TYPE: LicenseType.bsd
FILE: ../../../flutter/fml/platform/darwin/scoped_block.h
----------------------------------------------------------------------------------------------------
Copyright (c) 2013 The Chromium Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
====================================================================================================

====================================================================================================
LIBRARY: engine
ORIGIN: ../../../flutter/fml/time/time_delta_unittest.cc + ../../../third_party/tonic/LICENSE
Expand Down
8 changes: 8 additions & 0 deletions fml/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
source_set("fml") {
sources = [
"arraysize.h",
"base32.cc",
"base32.h",
"build_config.h",
"closure.h",
"command_line.cc",
"command_line.h",
"compiler_specific.h",
"eintr_wrapper.h",
"export.h",
"file.cc",
"file.h",
"icu_util.cc",
"icu_util.h",
Expand Down Expand Up @@ -104,6 +107,7 @@ source_set("fml") {
"platform/android/message_loop_android.cc",
"platform/android/message_loop_android.h",
"platform/android/paths_android.cc",
"platform/android/paths_android.h",
"platform/android/scoped_java_ref.cc",
"platform/android/scoped_java_ref.h",
]
Expand Down Expand Up @@ -139,6 +143,8 @@ source_set("fml") {

if (is_win) {
sources += [
"platform/win/errors_win.cc",
"platform/win/errors_win.h",
"platform/win/file_win.cc",
"platform/win/mapping_win.cc",
"platform/win/message_loop_win.cc",
Expand All @@ -161,7 +167,9 @@ executable("fml_unittests") {
testonly = true

sources = [
"base32_unittest.cc",
"command_line_unittest.cc",
"file_unittest.cc",
"memory/ref_counted_unittest.cc",
"memory/weak_ptr_unittest.cc",
"message_loop_unittests.cc",
Expand Down
46 changes: 46 additions & 0 deletions fml/base32.cc
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
19 changes: 19 additions & 0 deletions fml/base32.h
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_
38 changes: 38 additions & 0 deletions fml/base32_unittest.cc
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");
}
}
46 changes: 46 additions & 0 deletions fml/file.cc
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
Loading

0 comments on commit f2a3df9

Please sign in to comment.