Flutter Engine
embedder_render_target_cache.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "flutter/shell/platform/embedder/embedder_render_target_cache.h"
6 
7 namespace flutter {
8 
10 
12 
16  const EmbedderExternalView::PendingViews& pending_views) {
17  RenderTargets resolved_render_targets;
18  EmbedderExternalView::ViewIdentifierSet unmatched_identifiers;
19 
20  for (const auto& view : pending_views) {
21  const auto& external_view = view.second;
22  if (!external_view->HasEngineRenderedContents()) {
23  continue;
24  }
25  auto& compatible_targets =
26  cached_render_targets_[external_view->CreateRenderTargetDescriptor()];
27  if (compatible_targets.size() == 0) {
28  unmatched_identifiers.insert(view.first);
29  } else {
30  std::unique_ptr<EmbedderRenderTarget> target =
31  std::move(compatible_targets.top());
32  compatible_targets.pop();
33  resolved_render_targets[view.first] = std::move(target);
34  }
35  }
36  return {std::move(resolved_render_targets), std::move(unmatched_identifiers)};
37 }
38 
39 std::set<std::unique_ptr<EmbedderRenderTarget>>
41  std::set<std::unique_ptr<EmbedderRenderTarget>> cleared_targets;
42  for (auto& targets : cached_render_targets_) {
43  auto& targets_stack = targets.second;
44  while (!targets_stack.empty()) {
45  cleared_targets.emplace(std::move(targets_stack.top()));
46  targets_stack.pop();
47  }
48  }
49  cached_render_targets_.clear();
50  return cleared_targets;
51 }
52 
55  std::unique_ptr<EmbedderRenderTarget> target) {
56  if (target == nullptr) {
57  return;
58  }
59  auto surface = target->GetRenderSurface();
61  view_identifier, SkISize::Make(surface->width(), surface->height())};
62  cached_render_targets_[desc].push(std::move(target));
63 }
64 
66  size_t count = 0;
67  for (const auto& targets : cached_render_targets_) {
68  count += targets.second.size();
69  }
70  return count;
71 }
72 
73 } // namespace flutter
std::unordered_map< EmbedderExternalView::ViewIdentifier, std::unique_ptr< EmbedderRenderTarget >, EmbedderExternalView::ViewIdentifier::Hash, EmbedderExternalView::ViewIdentifier::Equal > RenderTargets
std::pair< RenderTargets, EmbedderExternalView::ViewIdentifierSet > GetExistingTargetsInCache(const EmbedderExternalView::PendingViews &pending_views)
std::set< std::unique_ptr< EmbedderRenderTarget > > ClearAllRenderTargetsInCache()
void CacheRenderTarget(EmbedderExternalView::ViewIdentifier view_identifier, std::unique_ptr< EmbedderRenderTarget > target)
std::unordered_set< ViewIdentifier, ViewIdentifier::Hash, ViewIdentifier::Equal > ViewIdentifierSet
std::unordered_map< ViewIdentifier, std::unique_ptr< EmbedderExternalView >, ViewIdentifier::Hash, ViewIdentifier::Equal > PendingViews