Skip to content

Commit

Permalink
Forward delegated ink point from browser to viz
Browse files Browse the repository at this point in the history
Start forwarding points from the browser process directly to viz via the
UI compositor when delegated ink trails are being drawn. This CL gets
the point to Display, the next CL will start storing the points and
using them as they arrive.

This CL only supports aura, follow up CLs will add support for Android
and Mac.

Bug: 1052145
Change-Id: Ic36d45bd960d358ececaf0312ce801da33686966
Cq-Do-Not-Cancel-Tryjobs: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2259015
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Jonathan Ross <jonross@chromium.org>
Reviewed-by: kylechar <kylechar@chromium.org>
Reviewed-by: Daniel Libby <dlibby@microsoft.com>
Commit-Queue: Mario Bianucci <mabian@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#792419}
  • Loading branch information
mabian-ms authored and Commit Bot committed Jul 28, 2020
1 parent 8660836 commit f190dba
Show file tree
Hide file tree
Showing 23 changed files with 630 additions and 0 deletions.
2 changes: 2 additions & 0 deletions components/viz/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ viz_component("common") {
"constants.h",
"delegated_ink_metadata.cc",
"delegated_ink_metadata.h",
"delegated_ink_point.cc",
"delegated_ink_point.h",
"display/de_jelly.cc",
"display/de_jelly.h",
"display/overlay_strategy.cc",
Expand Down
19 changes: 19 additions & 0 deletions components/viz/common/delegated_ink_point.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2020 The Chromium 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 "components/viz/common/delegated_ink_point.h"

#include <inttypes.h>

#include "base/strings/stringprintf.h"

namespace viz {

std::string DelegatedInkPoint::ToString() const {
return base::StringPrintf("point: %s, timestamp: %" PRId64,
point_.ToString().c_str(),
timestamp_.since_origin().InMicroseconds());
}

} // namespace viz
55 changes: 55 additions & 0 deletions components/viz/common/delegated_ink_point.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_VIZ_COMMON_DELEGATED_INK_POINT_H_
#define COMPONENTS_VIZ_COMMON_DELEGATED_INK_POINT_H_

#include <string>

#include "base/time/time.h"
#include "components/viz/common/viz_common_export.h"
#include "mojo/public/cpp/bindings/struct_traits.h"
#include "ui/gfx/geometry/point_f.h"

namespace viz {

namespace mojom {
class DelegatedInkPointDataView;
} // namespace mojom

// This class stores the information required to draw a single point of a
// delegated ink trail. When the WebAPI |updateInkTrailStartPoint| is called,
// the renderer requests that the browser begin sending these to viz. Viz
// will collect them, and then during |DrawAndSwap| will use the
// DelegatedInkPoints that have arrived from the browser along with the
// DelegatedInkMetadata that the renderer sent to draw a delegated ink trail on
// the screen, connected to the end of the already rendered ink stroke.
//
// Explainer for the feature:
// https://github.com/WICG/ink-enhancement/blob/master/README.md
class VIZ_COMMON_EXPORT DelegatedInkPoint {
public:
DelegatedInkPoint() = default;
DelegatedInkPoint(const gfx::PointF& pt, base::TimeTicks timestamp)
: point_(pt), timestamp_(timestamp) {}

const gfx::PointF& point() const { return point_; }
base::TimeTicks timestamp() const { return timestamp_; }
std::string ToString() const;

private:
friend struct mojo::StructTraits<mojom::DelegatedInkPointDataView,
DelegatedInkPoint>;

// Location of the input event relative to the root window in device pixels.
// Scale is device scale factor at time of input.
gfx::PointF point_;

// Timestamp from the input event.
base::TimeTicks timestamp_;
};

} // namespace viz

#endif // COMPONENTS_VIZ_COMMON_DELEGATED_INK_POINT_H_
2 changes: 2 additions & 0 deletions components/viz/service/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ viz_component("service") {
"display/bsp_walk_action.h",
"display/damage_frame_annotator.cc",
"display/damage_frame_annotator.h",
"display/delegated_ink_point_renderer.cc",
"display/delegated_ink_point_renderer.h",
"display/direct_renderer.cc",
"display/direct_renderer.h",
"display/display.cc",
Expand Down
3 changes: 3 additions & 0 deletions components/viz/service/display/DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,7 @@ specific_include_rules = {
"+third_party/libyuv",
"+ui/gl/gl_implementation.h",
],
"delegated_ink_point_renderer\.*" : [
"+mojo/public/cpp/bindings",
],
}
30 changes: 30 additions & 0 deletions components/viz/service/display/delegated_ink_point_renderer.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2020 The Chromium 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 "components/viz/service/display/delegated_ink_point_renderer.h"

#include <utility>

#include "base/trace_event/trace_event.h"

namespace viz {

DelegatedInkPointRendererImpl::DelegatedInkPointRendererImpl(
mojo::PendingReceiver<mojom::DelegatedInkPointRenderer> receiver)
: receiver_(this, std::move(receiver)) {}
DelegatedInkPointRendererImpl::~DelegatedInkPointRendererImpl() = default;

void DelegatedInkPointRendererImpl::StoreDelegatedInkPoint(
const DelegatedInkPoint& point) {
TRACE_EVENT_INSTANT1(
"viz",
"DelegatedInkPointRendererImpl::StoreDelegatedInkPoint - "
"Point arrived in viz",
TRACE_EVENT_SCOPE_THREAD, "point", point.ToString());
// TODO(1052145): Start storing these points in something to be used during
// |Display::DrawAndSwap()| to draw the delegated ink trail. These points will
// need to be cleared when |device_scale_factor_| changes.
}

} // namespace viz
41 changes: 41 additions & 0 deletions components/viz/service/display/delegated_ink_point_renderer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_VIZ_SERVICE_DISPLAY_DELEGATED_INK_POINT_RENDERER_H_
#define COMPONENTS_VIZ_SERVICE_DISPLAY_DELEGATED_INK_POINT_RENDERER_H_

#include "components/viz/service/viz_service_export.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "services/viz/public/mojom/compositing/delegated_ink_point.mojom.h"

namespace viz {

// This class is used for rendering delegated ink trails on the end of strokes
// to reduce user perceived latency. On initialization, it binds the mojo
// interface required for receiving delegated ink points that are made and sent
// from the browser process.
// TODO(1052145): Expand on this comment as more functionality is added to this
// function - it will ultimately be where the rendering actually occurs.
//
// For more information on the feature, please see the explainer:
// https://github.com/WICG/ink-enhancement/blob/master/README.md
class VIZ_SERVICE_EXPORT DelegatedInkPointRendererImpl
: public mojom::DelegatedInkPointRenderer {
public:
explicit DelegatedInkPointRendererImpl(
mojo::PendingReceiver<mojom::DelegatedInkPointRenderer> receiver);
~DelegatedInkPointRendererImpl() override;
DelegatedInkPointRendererImpl(const DelegatedInkPointRendererImpl&) = delete;
DelegatedInkPointRendererImpl& operator=(
const DelegatedInkPointRendererImpl&) = delete;

void StoreDelegatedInkPoint(const DelegatedInkPoint& point) override;

private:
mojo::Receiver<mojom::DelegatedInkPointRenderer> receiver_;
};

} // namespace viz

#endif // COMPONENTS_VIZ_SERVICE_DISPLAY_DELEGATED_INK_POINT_RENDERER_H_
14 changes: 14 additions & 0 deletions components/viz/service/display/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#define COMPONENTS_VIZ_SERVICE_DISPLAY_DISPLAY_H_

#include <memory>
#include <utility>
#include <vector>

#include "base/containers/circular_deque.h"
Expand All @@ -19,6 +20,7 @@
#include "components/viz/common/resources/returned_resource.h"
#include "components/viz/common/surfaces/frame_sink_id.h"
#include "components/viz/common/surfaces/surface_id.h"
#include "components/viz/service/display/delegated_ink_point_renderer.h"
#include "components/viz/service/display/display_resource_provider.h"
#include "components/viz/service/display/display_scheduler.h"
#include "components/viz/service/display/frame_rate_decider.h"
Expand Down Expand Up @@ -183,6 +185,14 @@ class VIZ_SERVICE_EXPORT Display : public DisplaySchedulerClient,
bool IsRootFrameMissing() const;
bool HasPendingSurfaces(const BeginFrameArgs& args) const;

// Set the delegated ink renderer, which will be responsible for rendering
// the delegated ink trails. This should only be called when the delegated
// ink trails feature is being used.
void set_delegated_ink_point_renderer(
std::unique_ptr<DelegatedInkPointRendererImpl> ink_renderer) {
delegated_ink_point_renderer_ = std::move(ink_renderer);
}

private:
friend class DisplayTest;
// PresentationGroupTiming stores rendering pipeline stage timings associated
Expand Down Expand Up @@ -286,6 +296,10 @@ class VIZ_SERVICE_EXPORT Display : public DisplaySchedulerClient,
// The height of the top-controls in the previously drawn frame.
float last_top_controls_visible_height_ = 0.f;

// The renderer responsible for drawing delegated ink trails to the screen
// before swapping the buffers in DrawAndSwap().
std::unique_ptr<DelegatedInkPointRendererImpl> delegated_ink_point_renderer_;

DISALLOW_COPY_AND_ASSIGN(Display);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
#include "components/viz/common/frame_sinks/begin_frame_source.h"
#include "components/viz/service/display/delegated_ink_point_renderer.h"
#include "components/viz/service/display/display.h"
#include "components/viz/service/display/output_surface.h"
#include "components/viz/service/display_embedder/output_surface_provider.h"
Expand Down Expand Up @@ -303,6 +304,12 @@ void RootCompositorFrameSinkImpl::AddVSyncParameterObserver(
std::make_unique<VSyncParameterListener>(std::move(observer));
}

void RootCompositorFrameSinkImpl::SetDelegatedInkPointRenderer(
mojo::PendingReceiver<mojom::DelegatedInkPointRenderer> receiver) {
display_->set_delegated_ink_point_renderer(
std::make_unique<DelegatedInkPointRendererImpl>(std::move(receiver)));
}

void RootCompositorFrameSinkImpl::SetNeedsBeginFrame(bool needs_begin_frame) {
support_->SetNeedsBeginFrame(needs_begin_frame);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class RootCompositorFrameSinkImpl : public mojom::CompositorFrameSink,
void AddVSyncParameterObserver(
mojo::PendingRemote<mojom::VSyncParameterObserver> observer) override;

void SetDelegatedInkPointRenderer(
mojo::PendingReceiver<mojom::DelegatedInkPointRenderer> receiver)
override;

// mojom::CompositorFrameSink:
void SetNeedsBeginFrame(bool needs_begin_frame) override;
void SetWantsAnimateOnlyBeginFrames() override;
Expand Down
Loading

0 comments on commit f190dba

Please sign in to comment.