0

Add test API for FastInkHost

Change-Id: I736d8d023f21eab4f654e5cc7cfd6e6b1013f4fa
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6350180
Reviewed-by: Vincent Chiang <vincentchiang@chromium.org>
Commit-Queue: Zoraiz Naeem <zoraiznaeem@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1432386}
This commit is contained in:
Zoraiz Naeem
2025-03-13 14:47:41 -07:00
committed by Chromium LUCI CQ
parent c47885e302
commit 5e1cedc345
5 changed files with 88 additions and 23 deletions

@ -5152,6 +5152,8 @@ static_library("test_support") {
"drag_drop/draggable_test_view.h",
"drag_drop/mock_drag_drop_observer.cc",
"drag_drop/mock_drag_drop_observer.h",
"fast_ink/fast_ink_host_test_api.cc",
"fast_ink/fast_ink_host_test_api.h",
"fast_ink/laser/laser_pointer_controller_test_api.cc",
"fast_ink/laser/laser_pointer_controller_test_api.h",
"frame_sink/frame_sink_holder_test_api.cc",

@ -26,6 +26,7 @@ class ClientSharedImage;
} // namespace gpu
namespace ash {
class FastInkHostTestApi;
// FastInkHost is used to support low-latency rendering. It supports
// 'auto-refresh' mode which provide minimum latency updates for the
@ -68,16 +69,6 @@ class ASH_EXPORT FastInkHost : public FrameSinkHost {
return window_to_buffer_transform_;
}
gpu::ClientSharedImage* client_si_for_test() const {
return client_shared_image_.get();
}
int get_pending_bitmaps_size_for_test() const {
return pending_bitmaps_.size();
}
const gpu::SyncToken& sync_token_for_test() const { return sync_token_; }
// FrameSinkHost:
void Init(aura::Window* host_window) override;
void InitForTesting(aura::Window* host_window,
@ -95,6 +86,8 @@ class ASH_EXPORT FastInkHost : public FrameSinkHost {
void OnFrameSinkLost() override;
private:
friend FastInkHostTestApi;
void InitBufferMetadata(aura::Window* host_window);
void InitializeFastInkBuffer(aura::Window* host_window);
gfx::Rect BufferRectFromWindowRect(const gfx::Rect& rect_in_window) const;

@ -0,0 +1,28 @@
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/fast_ink/fast_ink_host_test_api.h"
#include "ash/fast_ink/fast_ink_host.h"
namespace ash {
FastInkHostTestApi::FastInkHostTestApi(FastInkHost* host)
: fast_ink_host_(host) {}
FastInkHostTestApi::~FastInkHostTestApi() = default;
gpu::ClientSharedImage* FastInkHostTestApi::client_shared_image() const {
return fast_ink_host_->client_shared_image_.get();
}
const gpu::SyncToken& FastInkHostTestApi::sync_token() const {
return fast_ink_host_->sync_token_;
}
int FastInkHostTestApi::pending_bitmaps_size() const {
return fast_ink_host_->pending_bitmaps_.size();
}
} // namespace ash

@ -0,0 +1,38 @@
// Copyright 2025 The Chromium Authors
// 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_TEST_API_H_
#define ASH_FAST_INK_FAST_INK_HOST_TEST_API_H_
#include "base/memory/raw_ptr.h"
#include "gpu/command_buffer/common/sync_token.h"
namespace gpu {
class ClientSharedImage;
} // namespace gpu
namespace ash {
class FastInkHost;
class FastInkHostTestApi {
public:
explicit FastInkHostTestApi(FastInkHost* host);
FastInkHostTestApi(const FastInkHostTestApi&) = delete;
FastInkHostTestApi& operator=(const FastInkHostTestApi&) = delete;
~FastInkHostTestApi();
gpu::ClientSharedImage* client_shared_image() const;
const gpu::SyncToken& sync_token() const;
int pending_bitmaps_size() const;
private:
raw_ptr<FastInkHost> fast_ink_host_;
};
} // namespace ash
#endif // ASH_FAST_INK_FAST_INK_HOST_TEST_API_H_

@ -9,6 +9,7 @@
#include <utility>
#include <vector>
#include "ash/fast_ink/fast_ink_host_test_api.h"
#include "ash/frame_sink/frame_sink_holder.h"
#include "ash/frame_sink/test/frame_sink_host_test_base.h"
#include "ash/frame_sink/test/test_begin_frame_source.h"
@ -124,16 +125,18 @@ TEST_P(FastInkHostTest, CorrectFrameSubmittedToLayerTreeFrameSink) {
}
TEST_P(FastInkHostTest, RecreateGpuBufferOnLosingFrameSink) {
FastInkHostTestApi fast_ink_host_test(frame_sink_host());
// Buffer is not initialized when there is no begin frame received.
ASSERT_FALSE(frame_sink_host()->client_si_for_test());
ASSERT_FALSE(fast_ink_host_test.client_shared_image());
// Request the first frame. It will call
// `FrameSinkHost::OnFirstFrameRequested()` initializing the GPU buffer.
OnBeginFrame();
// MappableSI should be initialized after receiving the first begin frame.
ASSERT_TRUE(frame_sink_host()->client_si_for_test());
auto sync_token = frame_sink_host()->sync_token_for_test();
ASSERT_TRUE(fast_ink_host_test.client_shared_image());
auto sync_token = fast_ink_host_test.sync_token();
// A new frame-sink will be created. FastInkHost should also create a new
// shared image.
@ -141,8 +144,8 @@ TEST_P(FastInkHostTest, RecreateGpuBufferOnLosingFrameSink) {
->frame_sink_holder_for_testing()
->DidLoseLayerTreeFrameSink();
EXPECT_NE(sync_token, frame_sink_host()->sync_token_for_test());
sync_token = frame_sink_host()->sync_token_for_test();
EXPECT_NE(sync_token, fast_ink_host_test.sync_token());
sync_token = fast_ink_host_test.sync_token();
// This will be the first OnBeginFrame for the new frame sink, therefore
// `FrameSinkHost::OnFirstFrameRequested()` will be called again.
@ -150,13 +153,15 @@ TEST_P(FastInkHostTest, RecreateGpuBufferOnLosingFrameSink) {
// Ensure we do not recreate a shared image on
// `FrameSinkHost::OnFirstFrameRequested()`.
EXPECT_EQ(sync_token, frame_sink_host()->sync_token_for_test());
EXPECT_EQ(sync_token, fast_ink_host_test.sync_token());
}
TEST_P(FastInkHostTest, DelayPaintingUntilReceivingFirstBeginFrame) {
FastInkHostTestApi fast_ink_host_test(frame_sink_host());
// Buffer is not initialized when there is no begin frame received.
ASSERT_FALSE(frame_sink_host()->client_si_for_test());
EXPECT_EQ(frame_sink_host()->get_pending_bitmaps_size_for_test(), 0);
ASSERT_FALSE(fast_ink_host_test.client_shared_image());
EXPECT_EQ(fast_ink_host_test.pending_bitmaps_size(), 0);
int pending_bitmaps_size = 0;
for (SkColor color : {SK_ColorRED, SK_ColorYELLOW, SK_ColorGREEN}) {
@ -169,19 +174,18 @@ TEST_P(FastInkHostTest, DelayPaintingUntilReceivingFirstBeginFrame) {
// The bitmap is waiting to be drawn because no gpu memory buffer is
// initialized.
++pending_bitmaps_size;
EXPECT_EQ(frame_sink_host()->get_pending_bitmaps_size_for_test(),
pending_bitmaps_size);
EXPECT_EQ(fast_ink_host_test.pending_bitmaps_size(), pending_bitmaps_size);
}
// Request the first frame.
OnBeginFrame();
// MappableSI should be initialized after receiving the first begin frame.
ASSERT_TRUE(frame_sink_host()->client_si_for_test());
ASSERT_TRUE(fast_ink_host_test.client_shared_image());
// Pending bitmaps should be drawn and cleared.
EXPECT_EQ(frame_sink_host()->get_pending_bitmaps_size_for_test(), 0);
EXPECT_EQ(fast_ink_host_test.pending_bitmaps_size(), 0);
auto mapping = frame_sink_host()->client_si_for_test()->Map();
auto mapping = fast_ink_host_test.client_shared_image()->Map();
ASSERT_TRUE(mapping);
// Pending bitmaps should be correctly copied to the MappableSI's buffer.
EXPECT_EQ(*reinterpret_cast<SkColor*>(mapping->GetMemoryForPlane(0).data()),