Skip to content

Commit

Permalink
Limit some compositor frame metadata fields to Android
Browse files Browse the repository at this point in the history
These fields are not used on other platforms; so there is no need to
send them:
 - |max_page_scale_factor|;
 - |root_layer_size|;
 - |root_overflow_y_hidden|.

Note that |min_page_scale_factor| is used on Mac.

BUG=859969

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;master.tryserver.blink:linux_trusty_blink_rel
Change-Id: I27d23f9b32e93805ab204b44a0999fb0c72e585f
Reviewed-on: https://chromium-review.googlesource.com/1158856
Reviewed-by: vmpstr <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Commit-Queue: Mohsen Izadi <[email protected]>
Cr-Commit-Position: refs/heads/master@{#585617}
  • Loading branch information
Mohsen Izadi authored and Commit Bot committed Aug 23, 2018
1 parent 0c3a585 commit 6f48ce6
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 59 deletions.
20 changes: 12 additions & 8 deletions cc/trees/layer_tree_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1898,9 +1898,6 @@ viz::CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() {

metadata.page_scale_factor = active_tree_->current_page_scale_factor();
metadata.scrollable_viewport_size = active_tree_->ScrollableViewportSize();
metadata.root_layer_size = active_tree_->ScrollableSize();
metadata.min_page_scale_factor = active_tree_->min_page_scale_factor();
metadata.max_page_scale_factor = active_tree_->max_page_scale_factor();
metadata.top_controls_height =
browser_controls_offset_manager_->TopControlsHeight();
metadata.top_controls_shown_ratio =
Expand All @@ -1926,11 +1923,6 @@ viz::CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() {
DCHECK_LE(frame_token_infos_.size(), 25u);
}

if (const auto* outer_viewport_scroll_node = OuterViewportScrollNode()) {
metadata.root_overflow_y_hidden =
!outer_viewport_scroll_node->user_scrollable_vertical;
}

if (GetDrawMode() == DRAW_MODE_RESOURCELESS_SOFTWARE) {
metadata.is_resourceless_software_draw_with_scroll_or_animation =
IsActivelyScrolling() || mutator_host_->NeedsTickAnimations();
Expand All @@ -1944,16 +1936,28 @@ viz::CompositorFrameMetadata LayerTreeHostImpl::MakeCompositorFrameMetadata() {
if (last_draw_referenced_surfaces_ != referenced_surfaces)
last_draw_referenced_surfaces_ = referenced_surfaces;

metadata.min_page_scale_factor = active_tree_->min_page_scale_factor();

#if defined(OS_ANDROID)
metadata.max_page_scale_factor = active_tree_->max_page_scale_factor();
metadata.root_layer_size = active_tree_->ScrollableSize();

if (const auto* outer_viewport_scroll_node = OuterViewportScrollNode()) {
metadata.root_overflow_y_hidden =
!outer_viewport_scroll_node->user_scrollable_vertical;
}

active_tree_->GetViewportSelection(&metadata.selection);
#endif

const auto* inner_viewport_scroll_node = InnerViewportScrollNode();
if (!inner_viewport_scroll_node)
return metadata;

#if defined(OS_ANDROID)
metadata.root_overflow_y_hidden |=
!inner_viewport_scroll_node->user_scrollable_vertical;
#endif

// TODO(miletus) : Change the metadata to hold ScrollOffset.
metadata.root_scroll_offset =
Expand Down
27 changes: 24 additions & 3 deletions cc/trees/layer_tree_host_impl_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -908,9 +908,11 @@ TEST_F(LayerTreeHostImplTest, ResourcelessDrawWithEmptyViewport) {
const bool resourceless_software_draw = true;
host_impl_->OnDraw(identity, viewport, resourceless_software_draw, false);
ASSERT_EQ(fake_layer_tree_frame_sink->num_sent_frames(), 1u);
#if defined(OS_ANDROID)
EXPECT_EQ(
gfx::SizeF(100.f, 100.f),
fake_layer_tree_frame_sink->last_sent_frame()->metadata.root_layer_size);
#endif
}

TEST_F(LayerTreeHostImplTest, ScrollDeltaNoLayers) {
Expand Down Expand Up @@ -4521,10 +4523,13 @@ TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) {
EXPECT_EQ(gfx::Vector2dF(), metadata.root_scroll_offset);
EXPECT_EQ(1.f, metadata.page_scale_factor);
EXPECT_EQ(gfx::SizeF(50.f, 50.f), metadata.scrollable_viewport_size);
EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size);
EXPECT_EQ(0.5f, metadata.min_page_scale_factor);

#if defined(OS_ANDROID)
EXPECT_EQ(4.f, metadata.max_page_scale_factor);
EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size);
EXPECT_FALSE(metadata.root_overflow_y_hidden);
#endif
}

// Scrolling should update metadata immediately.
Expand Down Expand Up @@ -4556,15 +4561,19 @@ TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) {
host_impl_->active_tree()->BuildPropertyTreesForTesting();
viz::CompositorFrameMetadata metadata =
host_impl_->MakeCompositorFrameMetadata();
#if defined(OS_ANDROID)
EXPECT_FALSE(metadata.root_overflow_y_hidden);
#endif

host_impl_->active_tree()
->OuterViewportScrollLayer()
->test_properties()
->user_scrollable_vertical = false;
host_impl_->active_tree()->BuildPropertyTreesForTesting();
metadata = host_impl_->MakeCompositorFrameMetadata();
#if defined(OS_ANDROID)
EXPECT_TRUE(metadata.root_overflow_y_hidden);
#endif
}

// Re-enable scrollability and verify that overflows are no longer hidden.
Expand All @@ -4580,7 +4589,9 @@ TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) {
host_impl_->active_tree()->BuildPropertyTreesForTesting();
viz::CompositorFrameMetadata metadata =
host_impl_->MakeCompositorFrameMetadata();
#if defined(OS_ANDROID)
EXPECT_FALSE(metadata.root_overflow_y_hidden);
#endif
}

// Root "overflow: hidden" properties should also be reflected on the
Expand All @@ -4593,15 +4604,19 @@ TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) {
host_impl_->active_tree()->BuildPropertyTreesForTesting();
viz::CompositorFrameMetadata metadata =
host_impl_->MakeCompositorFrameMetadata();
#if defined(OS_ANDROID)
EXPECT_FALSE(metadata.root_overflow_y_hidden);
#endif

host_impl_->active_tree()
->InnerViewportScrollLayer()
->test_properties()
->user_scrollable_vertical = false;
host_impl_->active_tree()->BuildPropertyTreesForTesting();
metadata = host_impl_->MakeCompositorFrameMetadata();
#if defined(OS_ANDROID)
EXPECT_TRUE(metadata.root_overflow_y_hidden);
#endif
}

// Page scale should update metadata correctly (shrinking only the viewport).
Expand All @@ -4617,9 +4632,12 @@ TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) {
EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset);
EXPECT_EQ(2.f, metadata.page_scale_factor);
EXPECT_EQ(gfx::SizeF(25.f, 25.f), metadata.scrollable_viewport_size);
EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size);
EXPECT_EQ(0.5f, metadata.min_page_scale_factor);

#if defined(OS_ANDROID)
EXPECT_EQ(4.f, metadata.max_page_scale_factor);
EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size);
#endif
}

// Likewise if set from the main thread.
Expand All @@ -4632,9 +4650,12 @@ TEST_F(LayerTreeHostImplTest, CompositorFrameMetadata) {
EXPECT_EQ(gfx::Vector2dF(0.f, 10.f), metadata.root_scroll_offset);
EXPECT_EQ(4.f, metadata.page_scale_factor);
EXPECT_EQ(gfx::SizeF(12.5f, 12.5f), metadata.scrollable_viewport_size);
EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size);
EXPECT_EQ(0.5f, metadata.min_page_scale_factor);

#if defined(OS_ANDROID)
EXPECT_EQ(4.f, metadata.max_page_scale_factor);
EXPECT_EQ(gfx::SizeF(100.f, 100.f), metadata.root_layer_size);
#endif
}
}

Expand Down
3 changes: 3 additions & 0 deletions cc/trees/layer_tree_host_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7946,7 +7946,10 @@ class LayerTreeHostTestSubmitFrameMetadata : public LayerTreeHostTest {

EXPECT_EQ(drawn_viewport_, frame.render_pass_list.back()->output_rect);
EXPECT_EQ(0.5f, frame.metadata.min_page_scale_factor);

#if defined(OS_ANDROID)
EXPECT_EQ(4.f, frame.metadata.max_page_scale_factor);
#endif

EXPECT_EQ(0u, frame.resource_list.size());
EXPECT_EQ(1u, frame.render_pass_list.size());
Expand Down
15 changes: 9 additions & 6 deletions components/viz/common/quads/compositor_frame_metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,8 @@ class VIZ_COMMON_EXPORT CompositorFrameMetadata {
gfx::Vector2dF root_scroll_offset;
float page_scale_factor = 0.f;

// These limits can be used together with the scroll/scale fields above to
// determine if scrolling/scaling in a particular direction is possible.
gfx::SizeF scrollable_viewport_size;
gfx::SizeF root_layer_size;
float min_page_scale_factor = 0.f;
float max_page_scale_factor = 0.f;
bool root_overflow_y_hidden = false;

bool may_contain_video = false;

// WebView makes quality decisions for rastering resourceless software frames
Expand Down Expand Up @@ -143,7 +138,15 @@ class VIZ_COMMON_EXPORT CompositorFrameMetadata {
// will be provided to CompositorFrameSinkClient.
bool request_presentation_feedback = false;

// These limits can be used together with the scroll/scale fields above to
// determine if scrolling/scaling in a particular direction is possible.
float min_page_scale_factor = 0.f;

#if defined(OS_ANDROID)
float max_page_scale_factor = 0.f;
gfx::SizeF root_layer_size;
bool root_overflow_y_hidden = false;

// Provides selection region updates relative to the current viewport. If the
// selection is empty or otherwise unused, the bound types will indicate such.
Selection<gfx::SelectionBound> selection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "services/viz/public/cpp/compositing/compositor_frame_metadata_struct_traits.h"

#include "build/build_config.h"
#include "services/viz/public/cpp/compositing/begin_frame_args_struct_traits.h"
#include "services/viz/public/cpp/compositing/selection_struct_traits.h"
#include "services/viz/public/cpp/compositing/surface_id_struct_traits.h"
Expand All @@ -22,14 +23,9 @@ bool StructTraits<viz::mojom::CompositorFrameMetadataDataView,
return false;

out->page_scale_factor = data.page_scale_factor();
if (!data.ReadScrollableViewportSize(&out->scrollable_viewport_size) ||
!data.ReadRootLayerSize(&out->root_layer_size)) {
if (!data.ReadScrollableViewportSize(&out->scrollable_viewport_size))
return false;
}

out->min_page_scale_factor = data.min_page_scale_factor();
out->max_page_scale_factor = data.max_page_scale_factor();
out->root_overflow_y_hidden = data.root_overflow_y_hidden();
out->may_contain_video = data.may_contain_video();
out->is_resourceless_software_draw_with_scroll_or_animation =
data.is_resourceless_software_draw_with_scroll_or_animation();
Expand All @@ -42,11 +38,19 @@ bool StructTraits<viz::mojom::CompositorFrameMetadataDataView,
out->send_frame_token_to_embedder = data.send_frame_token_to_embedder();
out->request_presentation_feedback = data.request_presentation_feedback();
out->root_background_color = data.root_background_color();
out->min_page_scale_factor = data.min_page_scale_factor();

#if defined(OS_ANDROID)
out->max_page_scale_factor = data.max_page_scale_factor();
out->root_overflow_y_hidden = data.root_overflow_y_hidden();
#endif

return data.ReadLatencyInfo(&out->latency_info) &&
data.ReadReferencedSurfaces(&out->referenced_surfaces) &&
data.ReadDeadline(&out->deadline) &&
data.ReadActivationDependencies(&out->activation_dependencies) &&
#if defined(OS_ANDROID)
data.ReadRootLayerSize(&out->root_layer_size) &&
data.ReadSelection(&out->selection) &&
#endif // defined(OS_ANDROID)
data.ReadBeginFrameAck(&out->begin_frame_ack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,6 @@ struct StructTraits<viz::mojom::CompositorFrameMetadataDataView,
return metadata.scrollable_viewport_size;
}

static gfx::SizeF root_layer_size(
const viz::CompositorFrameMetadata& metadata) {
return metadata.root_layer_size;
}

static float min_page_scale_factor(
const viz::CompositorFrameMetadata& metadata) {
return metadata.min_page_scale_factor;
}

static float max_page_scale_factor(
const viz::CompositorFrameMetadata& metadata) {
return metadata.max_page_scale_factor;
}

static bool root_overflow_y_hidden(
const viz::CompositorFrameMetadata& metadata) {
return metadata.root_overflow_y_hidden;
}

static bool may_contain_video(const viz::CompositorFrameMetadata& metadata) {
return metadata.may_contain_video;
}
Expand Down Expand Up @@ -136,7 +116,27 @@ struct StructTraits<viz::mojom::CompositorFrameMetadataDataView,
return metadata.request_presentation_feedback;
}

static float min_page_scale_factor(
const viz::CompositorFrameMetadata& metadata) {
return metadata.min_page_scale_factor;
}

#if defined(OS_ANDROID)
static float max_page_scale_factor(
const viz::CompositorFrameMetadata& metadata) {
return metadata.max_page_scale_factor;
}

static const gfx::SizeF& root_layer_size(
const viz::CompositorFrameMetadata& metadata) {
return metadata.root_layer_size;
}

static bool root_overflow_y_hidden(
const viz::CompositorFrameMetadata& metadata) {
return metadata.root_overflow_y_hidden;
}

static const viz::Selection<gfx::SelectionBound>& selection(
const viz::CompositorFrameMetadata& metadata) {
return metadata.selection;
Expand Down
27 changes: 15 additions & 12 deletions services/viz/public/cpp/compositing/struct_traits_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -614,10 +614,6 @@ TEST_F(StructTraitsTest, CompositorFrameMetadata) {
const gfx::Vector2dF root_scroll_offset(1234.5f, 6789.1f);
const float page_scale_factor = 1337.5f;
const gfx::SizeF scrollable_viewport_size(1337.7f, 1234.5f);
const gfx::SizeF root_layer_size(1234.5f, 5432.1f);
const float min_page_scale_factor = 3.5f;
const float max_page_scale_factor = 4.6f;
const bool root_overflow_y_hidden = true;
const bool may_contain_video = true;
const bool is_resourceless_software_draw_with_scroll_or_animation = true;
const float top_bar_height(1234.5f);
Expand All @@ -641,7 +637,12 @@ TEST_F(StructTraitsTest, CompositorFrameMetadata) {
uint32_t frame_token = 0xdeadbeef;
uint64_t begin_frame_ack_sequence_number = 0xdeadbeef;
FrameDeadline frame_deadline(base::TimeTicks(), 4u, base::TimeDelta(), true);
const float min_page_scale_factor = 3.5f;

#if defined(OS_ANDROID)
const float max_page_scale_factor = 4.6f;
const gfx::SizeF root_layer_size(1234.5f, 5432.1f);
const bool root_overflow_y_hidden = true;
Selection<gfx::SelectionBound> selection;
selection.start.SetEdge(gfx::PointF(1234.5f, 67891.f),
gfx::PointF(5432.1f, 1987.6f));
Expand All @@ -658,10 +659,6 @@ TEST_F(StructTraitsTest, CompositorFrameMetadata) {
input.root_scroll_offset = root_scroll_offset;
input.page_scale_factor = page_scale_factor;
input.scrollable_viewport_size = scrollable_viewport_size;
input.root_layer_size = root_layer_size;
input.min_page_scale_factor = min_page_scale_factor;
input.max_page_scale_factor = max_page_scale_factor;
input.root_overflow_y_hidden = root_overflow_y_hidden;
input.may_contain_video = may_contain_video;
input.is_resourceless_software_draw_with_scroll_or_animation =
is_resourceless_software_draw_with_scroll_or_animation;
Expand All @@ -676,7 +673,12 @@ TEST_F(StructTraitsTest, CompositorFrameMetadata) {
input.deadline = frame_deadline;
input.frame_token = frame_token;
input.begin_frame_ack.sequence_number = begin_frame_ack_sequence_number;
input.min_page_scale_factor = min_page_scale_factor;

#if defined(OS_ANDROID)
input.max_page_scale_factor = max_page_scale_factor;
input.root_layer_size = root_layer_size;
input.root_overflow_y_hidden = root_overflow_y_hidden;
input.selection = selection;
#endif // defined(OS_ANDROID)

Expand All @@ -686,10 +688,6 @@ TEST_F(StructTraitsTest, CompositorFrameMetadata) {
EXPECT_EQ(root_scroll_offset, output.root_scroll_offset);
EXPECT_EQ(page_scale_factor, output.page_scale_factor);
EXPECT_EQ(scrollable_viewport_size, output.scrollable_viewport_size);
EXPECT_EQ(root_layer_size, output.root_layer_size);
EXPECT_EQ(min_page_scale_factor, output.min_page_scale_factor);
EXPECT_EQ(max_page_scale_factor, output.max_page_scale_factor);
EXPECT_EQ(root_overflow_y_hidden, output.root_overflow_y_hidden);
EXPECT_EQ(may_contain_video, output.may_contain_video);
EXPECT_EQ(is_resourceless_software_draw_with_scroll_or_animation,
output.is_resourceless_software_draw_with_scroll_or_animation);
Expand All @@ -712,7 +710,12 @@ TEST_F(StructTraitsTest, CompositorFrameMetadata) {
EXPECT_EQ(frame_token, output.frame_token);
EXPECT_EQ(begin_frame_ack_sequence_number,
output.begin_frame_ack.sequence_number);
EXPECT_EQ(min_page_scale_factor, output.min_page_scale_factor);

#if defined(OS_ANDROID)
EXPECT_EQ(max_page_scale_factor, output.max_page_scale_factor);
EXPECT_EQ(root_layer_size, output.root_layer_size);
EXPECT_EQ(root_overflow_y_hidden, output.root_overflow_y_hidden);
EXPECT_EQ(selection, output.selection);
#endif // defined(OS_ANDROID)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ struct CompositorFrameMetadata {
gfx.mojom.Vector2dF root_scroll_offset;
float page_scale_factor;
gfx.mojom.SizeF scrollable_viewport_size;
gfx.mojom.SizeF root_layer_size;
float min_page_scale_factor;
float max_page_scale_factor;
bool root_overflow_y_hidden;
bool may_contain_video;
bool is_resourceless_software_draw_with_scroll_or_animation;
float top_controls_height;
Expand All @@ -39,6 +35,17 @@ struct CompositorFrameMetadata {
bool send_frame_token_to_embedder;
bool request_presentation_feedback;

float min_page_scale_factor;

[EnableIf=is_android]
float max_page_scale_factor;

[EnableIf=is_android]
gfx.mojom.SizeF root_layer_size;

[EnableIf=is_android]
bool root_overflow_y_hidden;

[EnableIf=is_android]
Selection selection;
};

0 comments on commit 6f48ce6

Please sign in to comment.