Skip to content

Commit

Permalink
Android Evict Child Frames As Well
Browse files Browse the repository at this point in the history
DelegatedFrameHostAndroid::EvictDelegatedFrame only evicts the topmost
frame. However when using site isolation this doesn't evict any child
frames. Desktop platforms make use of
RenderViewHostImpl::CollectSurfaceIdsForEviction to collect the child
frames.

This change implements the usage of that on Android as well.

(cherry picked from commit 4ee1006)

Bug: 1393349
Change-Id: Ie361fe82de4753c3ab617923341e7d5ffc21db2a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4112523
Commit-Queue: Jonathan Ross <jonross@chromium.org>
Reviewed-by: Benoit Lize <lizeb@chromium.org>
Reviewed-by: Bo Liu <boliu@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1085422}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4156391
Reviewed-by: Jonathan Ross <jonross@chromium.org>
Cr-Commit-Position: refs/branch-heads/5481@{#276}
Cr-Branched-From: 130f3e4-refs/heads/main@{#1084008}
  • Loading branch information
Jonathan Ross authored and Chromium LUCI CQ committed Jan 13, 2023
1 parent 5e44208 commit 56f0304
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 2 deletions.
8 changes: 8 additions & 0 deletions components/viz/common/features.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,14 @@ BASE_FEATURE(kRendererAllocatesImages,
#endif
);

#if BUILDFLAG(IS_ANDROID)
// By default on Android, when a client is being evicted, it only evicts itself.
// This differs from Destkop platforms which evict the entire FrameTree along
// with the topmost viz::Surface. When this feature is enabled, Android will
// begin also evicting the entire FrameTree.
BASE_FEATURE(kEvictSubtree, "EvictSubtree", base::FEATURE_DISABLED_BY_DEFAULT);
#endif

bool IsOverlayPrioritizationEnabled() {
return base::FeatureList::IsEnabled(kEnableOverlayPrioritization);
}
Expand Down
3 changes: 3 additions & 0 deletions components/viz/common/features.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ VIZ_COMMON_EXPORT BASE_DECLARE_FEATURE(kEagerSurfaceGarbageCollection);
VIZ_COMMON_EXPORT BASE_DECLARE_FEATURE(kOverrideThrottledFrameRateParams);
VIZ_COMMON_EXPORT BASE_DECLARE_FEATURE(kRendererAllocatesImages);
VIZ_COMMON_EXPORT BASE_DECLARE_FEATURE(kBufferQueueImageSetPurgeable);
#if BUILDFLAG(IS_ANDROID)
VIZ_COMMON_EXPORT BASE_DECLARE_FEATURE(kEvictSubtree);
#endif

VIZ_COMMON_EXPORT extern const char kDraw1Point12Ms[];
VIZ_COMMON_EXPORT extern const char kDraw2Points6Ms[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,9 @@ void DelegatedFrameHostClientAndroid::OnSurfaceIdChanged() {
render_widget_host_view_->OnSurfaceIdChanged();
}

std::vector<viz::SurfaceId>
DelegatedFrameHostClientAndroid::CollectSurfaceIdsForEviction() const {
return render_widget_host_view_->host()->CollectSurfaceIdsForEviction();
}

} // namespace content
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
#ifndef CONTENT_BROWSER_RENDERER_HOST_DELEGATED_FRAME_HOST_CLIENT_ANDROID_H_
#define CONTENT_BROWSER_RENDERER_HOST_DELEGATED_FRAME_HOST_CLIENT_ANDROID_H_

#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/time/time.h"
#include "components/viz/common/frame_timing_details_map.h"
#include "components/viz/common/surfaces/surface_id.h"
#include "content/common/content_export.h"
#include "ui/android/delegated_frame_host_android.h"

Expand All @@ -34,6 +37,7 @@ class CONTENT_EXPORT DelegatedFrameHostClientAndroid
base::TimeTicks activation_time) override;
void WasEvicted() override;
void OnSurfaceIdChanged() override;
std::vector<viz::SurfaceId> CollectSurfaceIdsForEviction() const override;

raw_ptr<RenderWidgetHostViewAndroid> render_widget_host_view_;
};
Expand Down
12 changes: 12 additions & 0 deletions tools/metrics/histograms/metadata/memory/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2891,6 +2891,18 @@ chromium-metrics-reviews@google.com.
</summary>
</histogram>

<histogram name="MemoryAndroid.EvictedTreeSize" units="units"
expires_after="2023-12-01">
<owner>jonross@chromium.org</owner>
<owner>chrome-gpu-metrics@google.com</owner>
<summary>
The total count of viz::SurfaceIds being evicted for the current FrameTree.

This will be emitted whenever we evict one DelegatedFrameHostAndroid, while
the features::kEvictSubtree is enabled.
</summary>
</histogram>

<histogram name="MemoryAndroid.EvictionReason" enum="AndroidEvictionReason"
expires_after="M85">
<owner>hajimehoshi@chromium.org</owner>
Expand Down
23 changes: 21 additions & 2 deletions ui/android/delegated_frame_host_android.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@

#include "ui/android/delegated_frame_host_android.h"

#include <iterator>

#include "base/android/build_info.h"
#include "base/bind.h"
#include "base/check_op.h"
#include "base/feature_list.h"
#include "base/metrics/histogram_macros.h"
#include "base/notreached.h"
#include "base/time/time.h"
#include "cc/layers/solid_color_layer.h"
#include "cc/layers/surface_layer.h"
#include "cc/trees/layer_tree_host.h"
#include "cc/trees/swap_promise.h"
#include "components/viz/common/features.h"
#include "components/viz/common/frame_sinks/copy_output_result.h"
#include "components/viz/common/quads/compositor_frame.h"
#include "components/viz/common/surfaces/surface_id.h"
Expand Down Expand Up @@ -201,9 +206,23 @@ void DelegatedFrameHostAndroid::EvictDelegatedFrame() {
return;
}

viz::SurfaceId current = viz::SurfaceId(frame_sink_id_, local_surface_id_);
if (local_surface_id_.is_valid()) {
viz::SurfaceId current = viz::SurfaceId(frame_sink_id_, local_surface_id_);
surface_ids.push_back(current);
if (base::FeatureList::IsEnabled(features::kEvictSubtree)) {
auto child_surfaces = client_->CollectSurfaceIdsForEviction();
if (current.is_valid() && !child_surfaces.empty()) {
auto it =
std::find(child_surfaces.begin(), child_surfaces.end(), current);
CHECK(it != child_surfaces.end())
<< "Surface to Evict not in FrameTree: " << current.ToString();
}
UMA_HISTOGRAM_COUNTS_100("MemoryAndroid.EvictedTreeSize",
child_surfaces.size());
std::move(child_surfaces.begin(), child_surfaces.end(),
std::back_inserter(surface_ids));
} else {
surface_ids.push_back(current);
}
}

if (surface_ids.empty())
Expand Down
5 changes: 5 additions & 0 deletions ui/android/delegated_frame_host_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#ifndef UI_ANDROID_DELEGATED_FRAME_HOST_ANDROID_H_
#define UI_ANDROID_DELEGATED_FRAME_HOST_ANDROID_H_

#include <vector>

#include "base/memory/raw_ptr.h"
#include "base/memory/scoped_refptr.h"
#include "base/numerics/safe_conversions.h"
Expand All @@ -15,6 +17,7 @@
#include "components/viz/common/frame_sinks/copy_output_request.h"
#include "components/viz/common/frame_timing_details_map.h"
#include "components/viz/common/resources/returned_resource.h"
#include "components/viz/common/surfaces/surface_id.h"
#include "components/viz/common/surfaces/surface_info.h"
#include "components/viz/host/host_frame_sink_client.h"
#include "third_party/blink/public/common/page/content_to_visible_time_reporter.h"
Expand Down Expand Up @@ -45,6 +48,8 @@ class UI_ANDROID_EXPORT DelegatedFrameHostAndroid
base::TimeTicks activation_time) = 0;
virtual void WasEvicted() = 0;
virtual void OnSurfaceIdChanged() = 0;
virtual std::vector<viz::SurfaceId> CollectSurfaceIdsForEviction()
const = 0;
};

DelegatedFrameHostAndroid(ViewAndroid* view,
Expand Down

0 comments on commit 56f0304

Please sign in to comment.