mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This reverts commit ef9e7b1a1365c07ab0df2e2016c4442c3963c2c7 with the following changes to accommodate an embedder for whom the original optimizations caused issues: * Ensure stable order in the backing stores presented to the embedder. This is a pessimization that will be reverted when the embedder migrates. Tracked in https://github.com/flutter/flutter/issues/51228 * Forego the optimization where the unused layers would be collected before allocation of new layers needs to happen. This is a pessimization that will be reverted when the embedder migrates. Tracked in https://github.com/flutter/flutter/issues/51229 More context in b/146142979.
74 lines
2.5 KiB
C++
74 lines
2.5 KiB
C++
// 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/shell/platform/embedder/embedder_render_target_cache.h"
|
|
|
|
namespace flutter {
|
|
|
|
EmbedderRenderTargetCache::EmbedderRenderTargetCache() = default;
|
|
|
|
EmbedderRenderTargetCache::~EmbedderRenderTargetCache() = default;
|
|
|
|
std::pair<EmbedderRenderTargetCache::RenderTargets,
|
|
EmbedderExternalView::ViewIdentifierSet>
|
|
EmbedderRenderTargetCache::GetExistingTargetsInCache(
|
|
const EmbedderExternalView::PendingViews& pending_views) {
|
|
RenderTargets resolved_render_targets;
|
|
EmbedderExternalView::ViewIdentifierSet unmatched_identifiers;
|
|
|
|
for (const auto& view : pending_views) {
|
|
const auto& external_view = view.second;
|
|
if (!external_view->HasEngineRenderedContents()) {
|
|
continue;
|
|
}
|
|
auto& compatible_targets =
|
|
cached_render_targets_[external_view->CreateRenderTargetDescriptor()];
|
|
if (compatible_targets.size() == 0) {
|
|
unmatched_identifiers.insert(view.first);
|
|
} else {
|
|
std::unique_ptr<EmbedderRenderTarget> target =
|
|
std::move(compatible_targets.top());
|
|
compatible_targets.pop();
|
|
resolved_render_targets[view.first] = std::move(target);
|
|
}
|
|
}
|
|
return {std::move(resolved_render_targets), std::move(unmatched_identifiers)};
|
|
}
|
|
|
|
std::set<std::unique_ptr<EmbedderRenderTarget>>
|
|
EmbedderRenderTargetCache::ClearAllRenderTargetsInCache() {
|
|
std::set<std::unique_ptr<EmbedderRenderTarget>> cleared_targets;
|
|
for (auto& targets : cached_render_targets_) {
|
|
auto& targets_stack = targets.second;
|
|
while (!targets_stack.empty()) {
|
|
cleared_targets.emplace(std::move(targets_stack.top()));
|
|
targets_stack.pop();
|
|
}
|
|
}
|
|
cached_render_targets_.clear();
|
|
return cleared_targets;
|
|
}
|
|
|
|
void EmbedderRenderTargetCache::CacheRenderTarget(
|
|
EmbedderExternalView::ViewIdentifier view_identifier,
|
|
std::unique_ptr<EmbedderRenderTarget> target) {
|
|
if (target == nullptr) {
|
|
return;
|
|
}
|
|
auto surface = target->GetRenderSurface();
|
|
auto desc = EmbedderExternalView::RenderTargetDescriptor{
|
|
view_identifier, SkISize::Make(surface->width(), surface->height())};
|
|
cached_render_targets_[desc].push(std::move(target));
|
|
}
|
|
|
|
size_t EmbedderRenderTargetCache::GetCachedTargetsCount() const {
|
|
size_t count = 0;
|
|
for (const auto& targets : cached_render_targets_) {
|
|
count += targets.second.size();
|
|
}
|
|
return count;
|
|
}
|
|
|
|
} // namespace flutter
|