Commit 323de502 authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

FastInkWidget Step1: Refactor FastInkView

This CL factors out the compositor frame logic from FastInkView.

FastInkHost is now responsible for pusing CompositorFrame and
FastInkView is a client of the FastInkHost.

Bug: 1054474
Change-Id: I4b58aa19eb9ec902071fd38fa994ead2e6009311
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2101941
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarMalay Keshav <malaykeshav@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751839}
parent 721d19d7
......@@ -333,6 +333,8 @@ component("ash") {
"events/switch_access_event_handler.h",
"fast_ink/cursor/cursor_view.cc",
"fast_ink/cursor/cursor_view.h",
"fast_ink/fast_ink_host.cc",
"fast_ink/fast_ink_host.h",
"fast_ink/fast_ink_pointer_controller.cc",
"fast_ink/fast_ink_pointer_controller.h",
"fast_ink/fast_ink_points.cc",
......
......@@ -86,9 +86,9 @@ CursorView::CursorView(aura::Window* container,
// Create transform used to convert cursor controller coordinates to screen
// coordinates.
bool rv =
screen_to_buffer_transform_.GetInverse(&buffer_to_screen_transform_);
DCHECK(rv);
bool inversible = host()->window_to_buffer_transform().GetInverse(
&buffer_to_screen_transform_);
DCHECK(inversible);
ui::CursorController::GetInstance()->AddCursorObserver(this);
}
......@@ -226,8 +226,7 @@ void CursorView::OnTimerTick() {
TRACE_EVENT1("ui", "CursorView::Paint", "damage_rect",
damage_rect.ToString());
ScopedPaint paint(gpu_memory_buffer_.get(), screen_to_buffer_transform_,
damage_rect);
ScopedPaint paint(this, damage_rect);
cc::PaintCanvas* sk_canvas = paint.canvas().sk_canvas();
sk_canvas->translate(SkIntToScalar(location_.x() - cursor_hotspot_.x()),
SkIntToScalar(location_.y() - cursor_hotspot_.y()));
......
This diff is collapsed.
// Copyright 2017 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 ASH_FAST_INK_FAST_INK_HOST_H_
#define ASH_FAST_INK_FAST_INK_HOST_H_
#include <memory>
#include <vector>
#include "base/containers/flat_map.h"
#include "base/memory/weak_ptr.h"
#include "components/viz/common/quads/compositor_frame_metadata.h"
#include "components/viz/common/resources/resource_id.h"
#include "ui/gfx/canvas.h"
namespace gfx {
class GpuMemoryBuffer;
struct PresentationFeedback;
} // namespace gfx
namespace fast_ink {
// FastInkHost is used to support low-latency rendering. It supports
// 'auto-refresh' mode which provide minimum latency updates for the
// associated window. 'auto-refresh' mode will take advantage of HW overlays
// when possible and trigger continuous updates.
class FastInkHost {
public:
// Convert the rect in window's coordinate to the buffer's coordinate. If the
// window is rotated, the damaged_rect will also be rotated, for example. The
// size is clamped by |buffer_size| to ensure it does not exceeds the buffer
// size.
static gfx::Rect BufferRectFromWindowRect(
const gfx::Transform& window_to_buffer_transform,
const gfx::Size& buffer_size,
const gfx::Rect& damage_rect);
using PresentationCallback =
base::RepeatingCallback<void(const gfx::PresentationFeedback&)>;
// Creates a FastInkView.
FastInkHost(aura::Window* host_window,
const PresentationCallback& presentation_callback);
~FastInkHost();
FastInkHost(const FastInkHost&) = delete;
FastInkHost& operator=(const FastInkHost&) = delete;
// Update content and damage rectangles for surface. |auto_refresh| should
// be set to true if continuous updates are expected within content rectangle.
void UpdateSurface(const gfx::Rect& content_rect,
const gfx::Rect& damage_rect,
bool auto_refresh);
aura::Window* host_window() { return host_window_; }
const gfx::Transform& window_to_buffer_transform() const {
return window_to_buffer_transform_;
}
gfx::GpuMemoryBuffer* gpu_memory_buffer() { return gpu_memory_buffer_.get(); }
private:
class LayerTreeFrameSinkHolder;
struct Resource;
void SubmitCompositorFrame();
void SubmitPendingCompositorFrame();
void ReclaimResource(std::unique_ptr<Resource> resource);
void DidReceiveCompositorFrameAck();
void DidPresentCompositorFrame(const gfx::PresentationFeedback& feedback);
aura::Window* host_window_;
const PresentationCallback presentation_callback_;
gfx::Transform window_to_buffer_transform_;
std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_;
// The size of |gpu_memory_buffer_|.
gfx::Size buffer_size_;
// The bounds of the content to be pushed in window coordinates.
gfx::Rect content_rect_;
// The damage rect in window coordinates.
gfx::Rect damage_rect_;
// When true it keeps pushing entire buffer with hw overlay option.
bool auto_refresh_ = false;
bool pending_compositor_frame_ = false;
bool pending_compositor_frame_ack_ = false;
int next_resource_id_ = 1;
// Cached resources that can be reused.
std::vector<std::unique_ptr<Resource>> returned_resources_;
std::unique_ptr<LayerTreeFrameSinkHolder> frame_sink_holder_;
base::WeakPtrFactory<FastInkHost> weak_ptr_factory_{this};
};
} // namespace fast_ink
#endif // ASH_FAST_INK_FAST_INK_HOST_H_
This diff is collapsed.
......@@ -8,10 +8,8 @@
#include <memory>
#include <vector>
#include "ash/fast_ink/fast_ink_host.h"
#include "base/containers/flat_map.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "components/viz/common/resources/resource_id.h"
#include "ui/gfx/canvas.h"
#include "ui/views/view.h"
......@@ -21,7 +19,6 @@ class Window;
namespace gfx {
class GpuMemoryBuffer;
struct PresentationFeedback;
} // namespace gfx
namespace views {
......@@ -30,76 +27,49 @@ class Widget;
namespace fast_ink {
// FastInkView is a view supporting low-latency rendering. The view can enter
// 'auto-refresh' mode in order to provide minimum latency updates for the
// associated widget. 'auto-refresh' mode will take advantage of HW overlays
// when possible and trigger continious updates.
// FastInkView is a view supporting low-latency rendering by using FastInkHost.
// THe view's widget must have the same bounds as a root window (covers the
// entire display). FastInkHost for more details.
class FastInkView : public views::View {
public:
using PresentationCallback =
base::RepeatingCallback<void(const gfx::PresentationFeedback&)>;
// Creates a FastInkView filling the bounds of |root_window|.
// If |root_window| is resized (e.g. due to a screen size change),
// a new instance of FastInkView should be created.
FastInkView(aura::Window* container,
const PresentationCallback& presentation_callback);
const FastInkHost::PresentationCallback& presentation_callback);
~FastInkView() override;
FastInkView(const FastInkView&) = delete;
FastInkView& operator=(const FastInkView&) = delete;
// Update content and damage rectangles for surface. See
// FastInkHost::UpdateSurface for more detials.
void UpdateSurface(const gfx::Rect& content_rect,
const gfx::Rect& damage_rect,
bool auto_refresh);
protected:
// Helper class that provides flicker free painting to a GPU memory buffer.
class ScopedPaint {
public:
ScopedPaint(gfx::GpuMemoryBuffer* gpu_memory_buffer,
const gfx::Transform& screen_to_buffer_transform,
const gfx::Rect& rect);
ScopedPaint(FastInkView* view, const gfx::Rect& damage_rect_in_window);
~ScopedPaint();
gfx::Canvas& canvas() { return canvas_; }
private:
gfx::GpuMemoryBuffer* const gpu_memory_buffer_;
const gfx::Rect buffer_rect_;
// Damage rect in the buffer coordinates.
const gfx::Rect damage_rect_;
gfx::Canvas canvas_;
DISALLOW_COPY_AND_ASSIGN(ScopedPaint);
};
// Update content and damage rectangles for surface. |auto_refresh| should
// be set to true if continuous updates are expected within content rectangle.
void UpdateSurface(const gfx::Rect& content_rect,
const gfx::Rect& damage_rect,
bool auto_refresh);
// Constants initialized in constructor.
const PresentationCallback presentation_callback_;
gfx::Transform screen_to_buffer_transform_;
gfx::Size buffer_size_;
std::unique_ptr<gfx::GpuMemoryBuffer> gpu_memory_buffer_;
FastInkHost* host() { return host_.get(); }
private:
class LayerTreeFrameSinkHolder;
struct Resource;
void SubmitCompositorFrame();
void SubmitPendingCompositorFrame();
void ReclaimResource(std::unique_ptr<Resource> resource);
void DidReceiveCompositorFrameAck();
void DidPresentCompositorFrame(const gfx::PresentationFeedback& feedback);
std::unique_ptr<views::Widget> widget_;
gfx::Rect content_rect_;
gfx::Rect damage_rect_;
bool auto_refresh_ = false;
bool pending_compositor_frame_ = false;
bool pending_compositor_frame_ack_ = false;
int next_resource_id_ = 1;
viz::FrameTokenGenerator next_frame_token_;
std::vector<std::unique_ptr<Resource>> returned_resources_;
std::unique_ptr<LayerTreeFrameSinkHolder> frame_sink_holder_;
base::WeakPtrFactory<FastInkView> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(FastInkView);
std::unique_ptr<FastInkHost> host_;
};
} // namespace fast_ink
......
......@@ -160,7 +160,7 @@ LaserPointerView::LaserPointerView(base::TimeDelta life_duration,
base::TimeDelta presentation_delay,
base::TimeDelta stationary_point_delay,
aura::Window* container)
: FastInkView(container, PresentationCallback()),
: FastInkView(container, fast_ink::FastInkHost::PresentationCallback()),
laser_points_(life_duration),
predicted_laser_points_(life_duration),
presentation_delay_(presentation_delay),
......@@ -231,8 +231,7 @@ void LaserPointerView::UpdateBuffer() {
TRACE_EVENT1("ui", "LaserPointerView::UpdateBuffer::Paint", "damage",
damage_rect.ToString());
ScopedPaint paint(gpu_memory_buffer_.get(), screen_to_buffer_transform_,
damage_rect);
ScopedPaint paint(this, damage_rect);
Draw(paint.canvas());
}
......
......@@ -73,7 +73,7 @@ const gfx::SizeF HighlighterView::kPenTipSize(kPenTipWidth, kPenTipHeight);
HighlighterView::HighlighterView(base::TimeDelta presentation_delay,
aura::Window* container)
: FastInkView(container, PresentationCallback()),
: FastInkView(container, fast_ink::FastInkHost::PresentationCallback()),
points_(base::TimeDelta()),
predicted_points_(base::TimeDelta()),
presentation_delay_(presentation_delay) {}
......@@ -187,8 +187,7 @@ void HighlighterView::UpdateBuffer() {
pending_update_buffer_ = false;
{
ScopedPaint paint(gpu_memory_buffer_.get(), screen_to_buffer_transform_,
highlighter_damage_rect_);
ScopedPaint paint(this, highlighter_damage_rect_);
Draw(paint.canvas());
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment