Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,8 @@ FILE: ../../../flutter/fml/command_line_unittest.cc
FILE: ../../../flutter/fml/compiler_specific.h
FILE: ../../../flutter/fml/concurrent_message_loop.cc
FILE: ../../../flutter/fml/concurrent_message_loop.h
FILE: ../../../flutter/fml/container.h
FILE: ../../../flutter/fml/container_unittests.cc
FILE: ../../../flutter/fml/dart/dart_converter.cc
FILE: ../../../flutter/fml/dart/dart_converter.h
FILE: ../../../flutter/fml/delayed_task.cc
Expand Down
2 changes: 2 additions & 0 deletions fml/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ source_set("fml") {
"compiler_specific.h",
"concurrent_message_loop.cc",
"concurrent_message_loop.h",
"container.h",
"delayed_task.cc",
"delayed_task.h",
"eintr_wrapper.h",
Expand Down Expand Up @@ -310,6 +311,7 @@ if (enable_unittests) {
"backtrace_unittests.cc",
"base32_unittest.cc",
"command_line_unittest.cc",
"container_unittests.cc",
"endianness_unittests.cc",
"file_unittest.cc",
"hash_combine_unittests.cc",
Expand Down
30 changes: 30 additions & 0 deletions fml/container.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// 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.

#ifndef FLUTTER_FML_CONTAINER_H_
#define FLUTTER_FML_CONTAINER_H_

#include <functional>
#include <map>

namespace fml {

template <
class Collection =
std::unordered_map<class Key, class Value, class Hash, class Equal>>
void erase_if(Collection& container,
std::function<bool(typename Collection::iterator)> predicate) {
auto it = container.begin();
while (it != container.end()) {
if (predicate(it)) {
it = container.erase(it);
continue;
}
it++;
}
}

} // namespace fml

#endif // FLUTTER_FML_CONTAINER_H_
26 changes: 26 additions & 0 deletions fml/container_unittests.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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 <unordered_map>

#include "flutter/fml/container.h"

#include "gtest/gtest.h"

namespace fml {
namespace {

TEST(ContainerTest, MapEraseIf) {
std::unordered_map<int, int> map = {{0, 1}, {2, 3}, {4, 5}};

fml::erase_if(map, [](std::unordered_map<int, int>::iterator it) {
return it->first == 0 || it->second == 5;
});

EXPECT_EQ(map.size(), 1u);
EXPECT_TRUE(map.find(2) != map.end());
}

} // namespace
} // namespace fml
1 change: 1 addition & 0 deletions impeller/entity/contents/runtime_effect_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ bool RuntimeEffectContents::Render(const ContentContext& renderer,
runtime_stage_->GetEntrypoint(), ShaderStage::kFragment);

if (function && runtime_stage_->IsDirty()) {
context->GetPipelineLibrary()->RemovePipelinesWithEntryPoint(function);
library->UnregisterFunction(runtime_stage_->GetEntrypoint(),
ShaderStage::kFragment);

Expand Down
10 changes: 10 additions & 0 deletions impeller/renderer/backend/gles/pipeline_library_gles.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <sstream>
#include <string>

#include "flutter/fml/container.h"
#include "flutter/fml/trace_event.h"
#include "impeller/base/promise.h"
#include "impeller/renderer/backend/gles/pipeline_gles.h"
Expand Down Expand Up @@ -257,6 +258,15 @@ PipelineFuture<ComputePipelineDescriptor> PipelineLibraryGLES::GetPipeline(
return future;
}

// |PipelineLibrary|
void PipelineLibraryGLES::RemovePipelinesWithEntryPoint(
std::shared_ptr<const ShaderFunction> function) {
fml::erase_if(pipelines_, [&](auto item) {
return item->first.GetEntrypointForStage(function->GetStage())
->IsEqual(*function);
});
}

// |PipelineLibrary|
PipelineLibraryGLES::~PipelineLibraryGLES() = default;

Expand Down
4 changes: 4 additions & 0 deletions impeller/renderer/backend/gles/pipeline_library_gles.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class PipelineLibraryGLES final : public PipelineLibrary {
PipelineFuture<ComputePipelineDescriptor> GetPipeline(
ComputePipelineDescriptor descriptor) override;

// |PipelineLibrary|
void RemovePipelinesWithEntryPoint(
std::shared_ptr<const ShaderFunction> function) override;

FML_DISALLOW_COPY_AND_ASSIGN(PipelineLibraryGLES);
};

Expand Down
4 changes: 4 additions & 0 deletions impeller/renderer/backend/metal/pipeline_library_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ class PipelineLibraryMTL final : public PipelineLibrary {
PipelineFuture<ComputePipelineDescriptor> GetPipeline(
ComputePipelineDescriptor descriptor) override;

// |PipelineLibrary|
void RemovePipelinesWithEntryPoint(
std::shared_ptr<const ShaderFunction> function) override;

FML_DISALLOW_COPY_AND_ASSIGN(PipelineLibraryMTL);
};

Expand Down
10 changes: 10 additions & 0 deletions impeller/renderer/backend/metal/pipeline_library_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "impeller/renderer/backend/metal/pipeline_library_mtl.h"
#include <Metal/Metal.h>

#include "flutter/fml/container.h"
#include "impeller/base/promise.h"
#include "impeller/renderer/backend/metal/compute_pipeline_mtl.h"
#include "impeller/renderer/backend/metal/formats_mtl.h"
Expand Down Expand Up @@ -187,4 +188,13 @@ new ComputePipelineMTL(weak_this,
return future;
}

// |PipelineLibrary|
void PipelineLibraryMTL::RemovePipelinesWithEntryPoint(
std::shared_ptr<const ShaderFunction> function) {
fml::erase_if(pipelines_, [&](auto item) {
return item->first.GetEntrypointForStage(function->GetStage())
->IsEqual(*function);
});
}

} // namespace impeller
12 changes: 12 additions & 0 deletions impeller/renderer/backend/vulkan/pipeline_library_vk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <optional>

#include "flutter/fml/container.h"
#include "flutter/fml/trace_event.h"
#include "impeller/base/promise.h"
#include "impeller/base/validation.h"
Expand Down Expand Up @@ -131,6 +132,17 @@ static vk::AttachmentDescription CreatePlaceholderAttachmentDescription(
return desc;
}

// |PipelineLibrary|
void PipelineLibraryVK::RemovePipelinesWithEntryPoint(
std::shared_ptr<const ShaderFunction> function) {
Lock lock(pipelines_mutex_);

fml::erase_if(pipelines_, [&](auto item) {
return item->first.GetEntrypointForStage(function->GetStage())
->IsEqual(*function);
});
}

//----------------------------------------------------------------------------
/// Render Pass
/// We are NOT going to use the same render pass with the framebuffer (later)
Expand Down
4 changes: 4 additions & 0 deletions impeller/renderer/backend/vulkan/pipeline_library_vk.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ class PipelineLibraryVK final
PipelineFuture<ComputePipelineDescriptor> GetPipeline(
ComputePipelineDescriptor descriptor) override;

// |PipelineLibrary|
void RemovePipelinesWithEntryPoint(
std::shared_ptr<const ShaderFunction> function) override;

std::unique_ptr<PipelineCreateInfoVK> CreatePipeline(
const PipelineDescriptor& desc);

Expand Down
3 changes: 3 additions & 0 deletions impeller/renderer/pipeline_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class PipelineLibrary : public std::enable_shared_from_this<PipelineLibrary> {
virtual PipelineFuture<ComputePipelineDescriptor> GetPipeline(
ComputePipelineDescriptor descriptor) = 0;

virtual void RemovePipelinesWithEntryPoint(
std::shared_ptr<const ShaderFunction> function) = 0;

protected:
PipelineLibrary();

Expand Down