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") { ...@@ -333,6 +333,8 @@ component("ash") {
"events/switch_access_event_handler.h", "events/switch_access_event_handler.h",
"fast_ink/cursor/cursor_view.cc", "fast_ink/cursor/cursor_view.cc",
"fast_ink/cursor/cursor_view.h", "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.cc",
"fast_ink/fast_ink_pointer_controller.h", "fast_ink/fast_ink_pointer_controller.h",
"fast_ink/fast_ink_points.cc", "fast_ink/fast_ink_points.cc",
......
...@@ -86,9 +86,9 @@ CursorView::CursorView(aura::Window* container, ...@@ -86,9 +86,9 @@ CursorView::CursorView(aura::Window* container,
// Create transform used to convert cursor controller coordinates to screen // Create transform used to convert cursor controller coordinates to screen
// coordinates. // coordinates.
bool rv = bool inversible = host()->window_to_buffer_transform().GetInverse(
screen_to_buffer_transform_.GetInverse(&buffer_to_screen_transform_); &buffer_to_screen_transform_);
DCHECK(rv); DCHECK(inversible);
ui::CursorController::GetInstance()->AddCursorObserver(this); ui::CursorController::GetInstance()->AddCursorObserver(this);
} }
...@@ -226,8 +226,7 @@ void CursorView::OnTimerTick() { ...@@ -226,8 +226,7 @@ void CursorView::OnTimerTick() {
TRACE_EVENT1("ui", "CursorView::Paint", "damage_rect", TRACE_EVENT1("ui", "CursorView::Paint", "damage_rect",
damage_rect.ToString()); damage_rect.ToString());
ScopedPaint paint(gpu_memory_buffer_.get(), screen_to_buffer_transform_, ScopedPaint paint(this, damage_rect);
damage_rect);
cc::PaintCanvas* sk_canvas = paint.canvas().sk_canvas(); cc::PaintCanvas* sk_canvas = paint.canvas().sk_canvas();
sk_canvas->translate(SkIntToScalar(location_.x() - cursor_hotspot_.x()), sk_canvas->translate(SkIntToScalar(location_.x() - cursor_hotspot_.x()),
SkIntToScalar(location_.y() - cursor_hotspot_.y())); 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 @@ ...@@ -8,10 +8,8 @@
#include <memory> #include <memory>
#include <vector> #include <vector>
#include "ash/fast_ink/fast_ink_host.h"
#include "base/containers/flat_map.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/gfx/canvas.h"
#include "ui/views/view.h" #include "ui/views/view.h"
...@@ -21,7 +19,6 @@ class Window; ...@@ -21,7 +19,6 @@ class Window;
namespace gfx { namespace gfx {
class GpuMemoryBuffer; class GpuMemoryBuffer;
struct PresentationFeedback;
} // namespace gfx } // namespace gfx
namespace views { namespace views {
...@@ -30,76 +27,49 @@ class Widget; ...@@ -30,76 +27,49 @@ class Widget;
namespace fast_ink { namespace fast_ink {
// FastInkView is a view supporting low-latency rendering. The view can enter // FastInkView is a view supporting low-latency rendering by using FastInkHost.
// 'auto-refresh' mode in order to provide minimum latency updates for the // THe view's widget must have the same bounds as a root window (covers the
// associated widget. 'auto-refresh' mode will take advantage of HW overlays // entire display). FastInkHost for more details.
// when possible and trigger continious updates.
class FastInkView : public views::View { class FastInkView : public views::View {
public: public:
using PresentationCallback =
base::RepeatingCallback<void(const gfx::PresentationFeedback&)>;
// Creates a FastInkView filling the bounds of |root_window|. // Creates a FastInkView filling the bounds of |root_window|.
// If |root_window| is resized (e.g. due to a screen size change), // If |root_window| is resized (e.g. due to a screen size change),
// a new instance of FastInkView should be created. // a new instance of FastInkView should be created.
FastInkView(aura::Window* container, FastInkView(aura::Window* container,
const PresentationCallback& presentation_callback); const FastInkHost::PresentationCallback& presentation_callback);
~FastInkView() override; ~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: protected:
// Helper class that provides flicker free painting to a GPU memory buffer. // Helper class that provides flicker free painting to a GPU memory buffer.
class ScopedPaint { class ScopedPaint {
public: public:
ScopedPaint(gfx::GpuMemoryBuffer* gpu_memory_buffer, ScopedPaint(FastInkView* view, const gfx::Rect& damage_rect_in_window);
const gfx::Transform& screen_to_buffer_transform,
const gfx::Rect& rect);
~ScopedPaint(); ~ScopedPaint();
gfx::Canvas& canvas() { return canvas_; } gfx::Canvas& canvas() { return canvas_; }
private: private:
gfx::GpuMemoryBuffer* const gpu_memory_buffer_; 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_; gfx::Canvas canvas_;
DISALLOW_COPY_AND_ASSIGN(ScopedPaint); DISALLOW_COPY_AND_ASSIGN(ScopedPaint);
}; };
// Update content and damage rectangles for surface. |auto_refresh| should FastInkHost* host() { return host_.get(); }
// 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_;
private: 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_; std::unique_ptr<views::Widget> widget_;
gfx::Rect content_rect_; std::unique_ptr<FastInkHost> host_;
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);
}; };
} // namespace fast_ink } // namespace fast_ink
......
...@@ -160,7 +160,7 @@ LaserPointerView::LaserPointerView(base::TimeDelta life_duration, ...@@ -160,7 +160,7 @@ LaserPointerView::LaserPointerView(base::TimeDelta life_duration,
base::TimeDelta presentation_delay, base::TimeDelta presentation_delay,
base::TimeDelta stationary_point_delay, base::TimeDelta stationary_point_delay,
aura::Window* container) aura::Window* container)
: FastInkView(container, PresentationCallback()), : FastInkView(container, fast_ink::FastInkHost::PresentationCallback()),
laser_points_(life_duration), laser_points_(life_duration),
predicted_laser_points_(life_duration), predicted_laser_points_(life_duration),
presentation_delay_(presentation_delay), presentation_delay_(presentation_delay),
...@@ -231,8 +231,7 @@ void LaserPointerView::UpdateBuffer() { ...@@ -231,8 +231,7 @@ void LaserPointerView::UpdateBuffer() {
TRACE_EVENT1("ui", "LaserPointerView::UpdateBuffer::Paint", "damage", TRACE_EVENT1("ui", "LaserPointerView::UpdateBuffer::Paint", "damage",
damage_rect.ToString()); damage_rect.ToString());
ScopedPaint paint(gpu_memory_buffer_.get(), screen_to_buffer_transform_, ScopedPaint paint(this, damage_rect);
damage_rect);
Draw(paint.canvas()); Draw(paint.canvas());
} }
......
...@@ -73,7 +73,7 @@ const gfx::SizeF HighlighterView::kPenTipSize(kPenTipWidth, kPenTipHeight); ...@@ -73,7 +73,7 @@ const gfx::SizeF HighlighterView::kPenTipSize(kPenTipWidth, kPenTipHeight);
HighlighterView::HighlighterView(base::TimeDelta presentation_delay, HighlighterView::HighlighterView(base::TimeDelta presentation_delay,
aura::Window* container) aura::Window* container)
: FastInkView(container, PresentationCallback()), : FastInkView(container, fast_ink::FastInkHost::PresentationCallback()),
points_(base::TimeDelta()), points_(base::TimeDelta()),
predicted_points_(base::TimeDelta()), predicted_points_(base::TimeDelta()),
presentation_delay_(presentation_delay) {} presentation_delay_(presentation_delay) {}
...@@ -187,8 +187,7 @@ void HighlighterView::UpdateBuffer() { ...@@ -187,8 +187,7 @@ void HighlighterView::UpdateBuffer() {
pending_update_buffer_ = false; pending_update_buffer_ = false;
{ {
ScopedPaint paint(gpu_memory_buffer_.get(), screen_to_buffer_transform_, ScopedPaint paint(this, highlighter_damage_rect_);
highlighter_damage_rect_);
Draw(paint.canvas()); 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