1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
// Copyright 2023 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/rounded_display/rounded_display_host.h"
#include <memory>
#include <utility>
#include <vector>
#include "ash/test/ash_test_base.h"
#include "ash/test/ash_test_helper.h"
#include "components/viz/common/frame_sinks/begin_frame_args.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/window_tree_host.h"
#include "ui/compositor/layer_type.h"
#include "ui/display/screen.h"
#include "ui/gfx/geometry/rect.h"
namespace ash {
namespace {
class TestRoundedDisplayHost : public RoundedDisplayHost {
public:
explicit TestRoundedDisplayHost(GetGuttersCallback callback)
: RoundedDisplayHost(std::move(callback)) {}
TestRoundedDisplayHost(const TestRoundedDisplayHost&) = delete;
TestRoundedDisplayHost& operator=(const TestRoundedDisplayHost&) = delete;
~TestRoundedDisplayHost() override = default;
std::unique_ptr<viz::CompositorFrame> CreateCompositorFrameForTest(
const gfx::Size& last_submitted_frame_size,
float last_submitted_frame_dsf) {
return RoundedDisplayHost::CreateCompositorFrame(
viz::BeginFrameAck::CreateManualAckWithDamage(), resource_manager_,
/*auto_update=*/false, last_submitted_frame_size,
last_submitted_frame_dsf);
}
private:
UiResourceManager resource_manager_;
};
class RoundedDisplayHostTest : public AshTestBase {
public:
RoundedDisplayHostTest() = default;
RoundedDisplayHostTest(const RoundedDisplayHostTest&) = delete;
RoundedDisplayHostTest& operator=(const RoundedDisplayHostTest&) = delete;
~RoundedDisplayHostTest() override = default;
// AshTestBase:
void SetUp() override {
AshTestBase::SetUp();
auto host_window = std::make_unique<aura::Window>(/*delegate=*/nullptr);
host_window_ = host_window.release();
host_window_->Init(ui::LayerType::LAYER_SOLID_COLOR);
auto* root_window = ash_test_helper()->GetHost()->window();
root_window->AddChild(host_window_);
host_ = std::make_unique<TestRoundedDisplayHost>(base::DoNothing());
host_->Init(host_window_);
}
// AshTestBase:
void TearDown() override {
// Host needs to outlive the `host_window_`.
host_.reset();
AshTestBase::TearDown();
}
protected:
raw_ptr<aura::Window, DanglingUntriaged> host_window_;
std::unique_ptr<TestRoundedDisplayHost> host_;
};
TEST_F(RoundedDisplayHostTest, NewSurfaceIdIsCreatedWhenNeeded) {
// RoundedDisplayHost creates the frame of the same size as the display size.
UpdateDisplay("1920x1080");
host_window_->SetBounds(gfx::Rect(1920, 1080));
auto primary_display = display::Screen::GetScreen()->GetPrimaryDisplay();
gfx::Size initial_frame_size = primary_display.GetSizeInPixel();
float initial_device_scale_factor = primary_display.device_scale_factor();
// First frame is created.
auto frame = host_->CreateCompositorFrameForTest(initial_frame_size,
initial_device_scale_factor);
auto frame_sink_id = host_window_->GetSurfaceId();
ASSERT_TRUE(frame_sink_id.is_valid());
UpdateDisplay("1920x1080*2");
// Second frame is created but the device scale has changed since the last
// submitted frame.
auto old_frame_sink_id = frame_sink_id;
frame = host_->CreateCompositorFrameForTest(frame->size_in_pixels(),
frame->device_scale_factor());
auto new_frame_sink_id = host_window_->GetSurfaceId();
ASSERT_TRUE(new_frame_sink_id.is_valid());
EXPECT_TRUE(new_frame_sink_id.IsNewerThan(old_frame_sink_id));
UpdateDisplay("1920x1080*2/r");
// Third frame is created but frame size has changed since the last submitted
// frame.
old_frame_sink_id = new_frame_sink_id;
frame = host_->CreateCompositorFrameForTest(frame->size_in_pixels(),
frame->device_scale_factor());
new_frame_sink_id = host_window_->GetSurfaceId();
ASSERT_TRUE(new_frame_sink_id.is_valid());
EXPECT_TRUE(new_frame_sink_id.IsNewerThan(old_frame_sink_id));
old_frame_sink_id = new_frame_sink_id;
// Fourth frame is created but neither frame_size nor device_scale_factor has
// changed.
frame = host_->CreateCompositorFrameForTest(frame->size_in_pixels(),
frame->device_scale_factor());
new_frame_sink_id = host_window_->GetSurfaceId();
ASSERT_TRUE(new_frame_sink_id.is_valid());
// We should have not identified a new surface.
EXPECT_EQ(new_frame_sink_id, old_frame_sink_id);
}
} // namespace
} // namespace ash
|