Skip to content

Commit

Permalink
Add ShellTest.DiscardLayerTreeOnResize
Browse files Browse the repository at this point in the history
  • Loading branch information
knopp committed Sep 17, 2020
1 parent 8dcecc6 commit 1e524f5
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 6 deletions.
9 changes: 8 additions & 1 deletion shell/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ if (enable_unittests) {
]
}

config("shell_test_fixture_sources_config") {
defines = [
# Required for MSVC STL
"_ENABLE_ATOMIC_ALIGNMENT_FIX",
]
}

source_set("shell_test_fixture_sources") {
testonly = true

Expand Down Expand Up @@ -214,7 +221,7 @@ if (enable_unittests) {
"//third_party/skia",
]

public_configs = []
public_configs = [ ":shell_test_fixture_sources_config" ]

# SwiftShader only supports x86/x64_64
if (target_cpu == "x86" || target_cpu == "x64") {
Expand Down
5 changes: 0 additions & 5 deletions shell/common/shell_test_external_view_embedder.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@
#include "flutter/flow/embedded_views.h"
#include "flutter/fml/raster_thread_merger.h"

// Required for MSVC STL
#ifndef _ENABLE_ATOMIC_ALIGNMENT_FIX
#define _ENABLE_ATOMIC_ALIGNMENT_FIX
#endif

namespace flutter {

//------------------------------------------------------------------------------
Expand Down
55 changes: 55 additions & 0 deletions shell/common/shell_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2014,5 +2014,60 @@ TEST_F(ShellTest, OnServiceProtocolEstimateRasterCacheMemoryWorks) {
DestroyShell(std::move(shell));
}

TEST_F(ShellTest, DiscardLayerTreeOnResize) {
auto settings = CreateSettingsForFixture();

SkISize wrong_size = SkISize::Make(400, 100);
SkISize expected_size = SkISize::Make(400, 200);

fml::AutoResetWaitableEvent end_frame_latch;

auto end_frame_callback = [&](bool, fml::RefPtr<fml::RasterThreadMerger>) {
end_frame_latch.Signal();
};

std::shared_ptr<ShellTestExternalViewEmbedder> external_view_embedder =
std::make_shared<ShellTestExternalViewEmbedder>(
std::move(end_frame_callback), PostPrerollResult::kSuccess, true);

std::unique_ptr<Shell> shell = CreateShell(
settings, GetTaskRunnersForFixture(), false, external_view_embedder);

// Create the surface needed by rasterizer
PlatformViewNotifyCreated(shell.get());

fml::TaskRunner::RunNowOrPostTask(
shell->GetTaskRunners().GetPlatformTaskRunner(),
[&shell, &expected_size]() {
shell->GetPlatformView()->SetViewportMetrics(
{1.0, static_cast<double>(expected_size.width()),
static_cast<double>(expected_size.height())});
});

auto configuration = RunConfiguration::InferFromSettings(settings);
configuration.SetEntrypoint("emptyMain");

RunEngine(shell.get(), std::move(configuration));

fml::WeakPtr<RuntimeDelegate> runtime_delegate = shell->GetEngine();

PumpOneFrame(shell.get(), static_cast<double>(wrong_size.width()),
static_cast<double>(wrong_size.height()));

end_frame_latch.Wait();

ASSERT_EQ(0, external_view_embedder->GetSubmittedFrameCount());

PumpOneFrame(shell.get(), static_cast<double>(expected_size.width()),
static_cast<double>(expected_size.height()));

end_frame_latch.Wait();

ASSERT_EQ(1, external_view_embedder->GetSubmittedFrameCount());
ASSERT_EQ(expected_size, external_view_embedder->GetLastSubmittedFrameSize());

DestroyShell(std::move(shell));
}

} // namespace testing
} // namespace flutter

0 comments on commit 1e524f5

Please sign in to comment.