chromium/third_party/blink/renderer/platform/widget/compositing/render_frame_metadata_observer_impl.cc

// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/platform/widget/compositing/render_frame_metadata_observer_impl.h"

#include <cmath>

#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "cc/mojom/render_frame_metadata.mojom-shared.h"
#include "components/viz/common/quads/compositor_frame_metadata.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"

namespace blink {

namespace {
#if BUILDFLAG(IS_ANDROID) || BUILDFLAG(IS_IOS)
constexpr float kEdgeThreshold = 10.0f;
#endif
}  // namespace

RenderFrameMetadataObserverImpl::RenderFrameMetadataObserverImpl(
    mojo::PendingReceiver<cc::mojom::blink::RenderFrameMetadataObserver>
        receiver,
    mojo::PendingRemote<cc::mojom::blink::RenderFrameMetadataObserverClient>
        client_remote)
    :{}

RenderFrameMetadataObserverImpl::~RenderFrameMetadataObserverImpl() {}

void RenderFrameMetadataObserverImpl::BindToCurrentSequence() {}

void RenderFrameMetadataObserverImpl::OnRenderFrameSubmission(
    const cc::RenderFrameMetadata& render_frame_metadata,
    viz::CompositorFrameMetadata* compositor_frame_metadata,
    bool force_send) {}

#if BUILDFLAG(IS_ANDROID)
void RenderFrameMetadataObserverImpl::UpdateRootScrollOffsetUpdateFrequency(
    cc::mojom::blink::RootScrollOffsetUpdateFrequency frequency) {
  if (!RuntimeEnabledFeatures::CCTNewRFMPushBehaviorEnabled()) {
    root_scroll_offset_update_frequency_ = frequency;
    if (frequency ==
        cc::mojom::blink::RootScrollOffsetUpdateFrequency::kAllUpdates) {
      SendLastRenderFrameMetadata();
    }
    return;
  }

  if ((!root_scroll_offset_update_frequency_.has_value() ||
       frequency > root_scroll_offset_update_frequency_) &&
      last_render_frame_metadata_.has_value()) {
    SendLastRenderFrameMetadata();
  }
  root_scroll_offset_update_frequency_ = frequency;
}
#endif

void RenderFrameMetadataObserverImpl::ReportAllFrameSubmissionsForTesting(
    bool enabled) {}

void RenderFrameMetadataObserverImpl::SendLastRenderFrameMetadata() {}

bool RenderFrameMetadataObserverImpl::ShouldSendRenderFrameMetadata(
    const cc::RenderFrameMetadata& rfm1,
    const cc::RenderFrameMetadata& rfm2,
    bool* needs_activation_notification) const {}

#if BUILDFLAG(IS_ANDROID)
void RenderFrameMetadataObserverImpl::DidEndScroll() {
  if (!last_render_frame_metadata_.has_value()) {
    return;
  }

  auto root_scroll_offset = last_render_frame_metadata_->root_scroll_offset;
  if (!root_scroll_offset.has_value() ||
      root_scroll_offset == last_root_scroll_offset_android_) {
    return;
  }

  if (root_scroll_offset_update_frequency_.value_or(
          cc::mojom::blink::RootScrollOffsetUpdateFrequency::kNone) !=
      cc::mojom::blink::RootScrollOffsetUpdateFrequency::kOnScrollEnd) {
    return;
  }

  render_frame_metadata_observer_client_->OnRootScrollOffsetChanged(
      root_scroll_offset.value());
  last_root_scroll_offset_android_ = root_scroll_offset;
}
#endif

}  // namespace blink