Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,10 @@ FILE: ../../../flutter/shell/common/shell_io_manager.cc
FILE: ../../../flutter/shell/common/shell_io_manager.h
FILE: ../../../flutter/shell/common/shell_test.cc
FILE: ../../../flutter/shell/common/shell_test.h
FILE: ../../../flutter/shell/common/shell_test_platform_view.cc
FILE: ../../../flutter/shell/common/shell_test_platform_view.h
FILE: ../../../flutter/shell/common/shell_test_platform_view_gl.cc
FILE: ../../../flutter/shell/common/shell_test_platform_view_gl.h
FILE: ../../../flutter/shell/common/shell_unittests.cc
FILE: ../../../flutter/shell/common/skia_event_tracer_impl.cc
FILE: ../../../flutter/shell/common/skia_event_tracer_impl.h
Expand Down
4 changes: 4 additions & 0 deletions shell/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ if (current_toolchain == host_toolchain) {
"pipeline_unittests.cc",
"shell_test.cc",
"shell_test.h",
"shell_test_platform_view.cc",
"shell_test_platform_view.h",
"shell_test_platform_view_gl.cc",
"shell_test_platform_view_gl.h",
"shell_unittests.cc",
"vsync_waiters_test.cc",
"vsync_waiters_test.h",
Expand Down
7 changes: 4 additions & 3 deletions shell/common/animator_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "flutter/shell/common/animator.h"
#include "flutter/shell/common/shell_test.h"
#include "flutter/shell/common/shell_test_platform_view.h"
#include "flutter/testing/testing.h"
#include "gtest/gtest.h"

Expand Down Expand Up @@ -51,9 +52,9 @@ TEST_F(ShellTest, VSyncTargetTime) {
shell = Shell::Create(
task_runners, settings,
[vsync_clock, &create_vsync_waiter](Shell& shell) {
return std::make_unique<ShellTestPlatformView>(
shell, shell.GetTaskRunners(), vsync_clock,
std::move(create_vsync_waiter));
return ShellTestPlatformView::Create(shell, shell.GetTaskRunners(),
vsync_clock,
std::move(create_vsync_waiter));
},
[](Shell& shell) {
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners());
Expand Down
73 changes: 4 additions & 69 deletions shell/common/shell_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
#define FML_USED_ON_EMBEDDER

#include "flutter/shell/common/shell_test.h"
#include "flutter/shell/common/shell_test_platform_view.h"

#include "flutter/flow/layers/layer_tree.h"
#include "flutter/flow/layers/transform_layer.h"
#include "flutter/fml/make_copyable.h"
#include "flutter/fml/mapping.h"
#include "flutter/runtime/dart_vm.h"
#include "flutter/shell/common/vsync_waiter_fallback.h"
#include "flutter/shell/gpu/gpu_surface_gl.h"
#include "flutter/testing/testing.h"

namespace flutter {
Expand Down Expand Up @@ -272,9 +272,9 @@ std::unique_ptr<Shell> ShellTest::CreateShell(Settings settings,
return Shell::Create(
task_runners, settings,
[vsync_clock, &create_vsync_waiter](Shell& shell) {
return std::make_unique<ShellTestPlatformView>(
shell, shell.GetTaskRunners(), vsync_clock,
std::move(create_vsync_waiter));
return ShellTestPlatformView::Create(shell, shell.GetTaskRunners(),
vsync_clock,
std::move(create_vsync_waiter));
},
[](Shell& shell) {
return std::make_unique<Rasterizer>(shell, shell.GetTaskRunners());
Expand All @@ -301,70 +301,5 @@ void ShellTest::AddNativeCallback(std::string name,
native_resolver_->AddNativeCallback(std::move(name), callback);
}

ShellTestPlatformView::ShellTestPlatformView(
PlatformView::Delegate& delegate,
TaskRunners task_runners,
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
CreateVsyncWaiter create_vsync_waiter)
: PlatformView(delegate, std::move(task_runners)),
gl_surface_(SkISize::Make(800, 600)),
create_vsync_waiter_(std::move(create_vsync_waiter)),
vsync_clock_(vsync_clock) {}

ShellTestPlatformView::~ShellTestPlatformView() = default;

std::unique_ptr<VsyncWaiter> ShellTestPlatformView::CreateVSyncWaiter() {
return create_vsync_waiter_();
}

void ShellTestPlatformView::SimulateVSync() {
vsync_clock_->SimulateVSync();
}

// |PlatformView|
std::unique_ptr<Surface> ShellTestPlatformView::CreateRenderingSurface() {
return std::make_unique<GPUSurfaceGL>(this, true);
}

// |PlatformView|
PointerDataDispatcherMaker ShellTestPlatformView::GetDispatcherMaker() {
return [](DefaultPointerDataDispatcher::Delegate& delegate) {
return std::make_unique<SmoothPointerDataDispatcher>(delegate);
};
}

// |GPUSurfaceGLDelegate|
bool ShellTestPlatformView::GLContextMakeCurrent() {
return gl_surface_.MakeCurrent();
}

// |GPUSurfaceGLDelegate|
bool ShellTestPlatformView::GLContextClearCurrent() {
return gl_surface_.ClearCurrent();
}

// |GPUSurfaceGLDelegate|
bool ShellTestPlatformView::GLContextPresent() {
return gl_surface_.Present();
}

// |GPUSurfaceGLDelegate|
intptr_t ShellTestPlatformView::GLContextFBO() const {
return gl_surface_.GetFramebuffer();
}

// |GPUSurfaceGLDelegate|
GPUSurfaceGLDelegate::GLProcResolver ShellTestPlatformView::GetGLProcResolver()
const {
return [surface = &gl_surface_](const char* name) -> void* {
return surface->GetProcAddress(name);
};
}

// |GPUSurfaceGLDelegate|
ExternalViewEmbedder* ShellTestPlatformView::GetExternalViewEmbedder() {
return nullptr;
}

} // namespace testing
} // namespace flutter
51 changes: 1 addition & 50 deletions shell/common/shell_test.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@

#include "flutter/common/settings.h"
#include "flutter/flow/layers/container_layer.h"
#include "flutter/fml/build_config.h"
#include "flutter/fml/macros.h"
#include "flutter/lib/ui/window/platform_message.h"
#include "flutter/shell/common/run_configuration.h"
#include "flutter/shell/common/shell.h"
#include "flutter/shell/common/thread_host.h"
#include "flutter/shell/common/vsync_waiters_test.h"
#include "flutter/shell/gpu/gpu_surface_gl_delegate.h"
#include "flutter/testing/test_dart_native_resolver.h"
#include "flutter/testing/test_gl_surface.h"
#include "flutter/testing/thread_test.h"

namespace flutter {
Expand Down Expand Up @@ -89,54 +88,6 @@ class ShellTest : public ThreadTest {
FML_DISALLOW_COPY_AND_ASSIGN(ShellTest);
};

class ShellTestPlatformView : public PlatformView, public GPUSurfaceGLDelegate {
public:
ShellTestPlatformView(PlatformView::Delegate& delegate,
TaskRunners task_runners,
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
CreateVsyncWaiter create_vsync_waiter);

~ShellTestPlatformView() override;

void SimulateVSync();

private:
TestGLSurface gl_surface_;

CreateVsyncWaiter create_vsync_waiter_;

std::shared_ptr<ShellTestVsyncClock> vsync_clock_;

// |PlatformView|
std::unique_ptr<Surface> CreateRenderingSurface() override;

// |PlatformView|
std::unique_ptr<VsyncWaiter> CreateVSyncWaiter() override;

// |PlatformView|
PointerDataDispatcherMaker GetDispatcherMaker() override;

// |GPUSurfaceGLDelegate|
bool GLContextMakeCurrent() override;

// |GPUSurfaceGLDelegate|
bool GLContextClearCurrent() override;

// |GPUSurfaceGLDelegate|
bool GLContextPresent() override;

// |GPUSurfaceGLDelegate|
intptr_t GLContextFBO() const override;

// |GPUSurfaceGLDelegate|
GLProcResolver GetGLProcResolver() const override;

// |GPUSurfaceGLDelegate|
ExternalViewEmbedder* GetExternalViewEmbedder() override;

FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformView);
};

} // namespace testing
} // namespace flutter

Expand Down
21 changes: 21 additions & 0 deletions shell/common/shell_test_platform_view.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/shell/common/shell_test_platform_view.h"
#include "flutter/shell/common/shell_test_platform_view_gl.h"

namespace flutter {
namespace testing {

std::unique_ptr<ShellTestPlatformView> ShellTestPlatformView::Create(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should really aim for all our tests to be as cross platform as possible. Towards this end, there is no reason that Vulkan can only be tested on Fuchsia (since it is either available or can be emulated everywhere). I suggest making this configurable via an enum that the test can select at runtime (or skip if not available). I was undertaking just such an effort that would collide with this one so I have closed it. But feel free to refer to #14023 for a guide on my thought process.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So @iskakaushik suggested I remove the Vulkan stubs entirely for now, land the changes to the rest of the ShellTestPlatformView, and iterate on the rendering API runtime changes in a future PR.

My plan was to have Vulkan not tied to Fuchsia and this was more of a stepping stone towards getting there, but after Kaushik's suggestion I agree it'd be better to land this in distinct pieces so we don't end up with behemoth patches.

PlatformView::Delegate& delegate,
TaskRunners task_runners,
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
CreateVsyncWaiter create_vsync_waiter) {
return std::make_unique<ShellTestPlatformViewGL>(
delegate, task_runners, vsync_clock, create_vsync_waiter);
}

} // namespace testing
} // namespace flutter
35 changes: 35 additions & 0 deletions shell/common/shell_test_platform_view.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2013 The Flutter 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 FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_H_
#define FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_H_

#include "flutter/shell/common/platform_view.h"
#include "flutter/shell/common/vsync_waiters_test.h"

namespace flutter {
namespace testing {

class ShellTestPlatformView : public PlatformView {
public:
static std::unique_ptr<ShellTestPlatformView> Create(
PlatformView::Delegate& delegate,
TaskRunners task_runners,
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
CreateVsyncWaiter create_vsync_waiter);

virtual void SimulateVSync() = 0;

protected:
ShellTestPlatformView(PlatformView::Delegate& delegate,
TaskRunners task_runners)
: PlatformView(delegate, task_runners) {}

FML_DISALLOW_COPY_AND_ASSIGN(ShellTestPlatformView);
};

} // namespace testing
} // namespace flutter

#endif // FLUTTER_SHELL_COMMON_SHELL_TEST_PLATFORM_VIEW_GL_H_
77 changes: 77 additions & 0 deletions shell/common/shell_test_platform_view_gl.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/shell/common/shell_test_platform_view_gl.h"
#include "flutter/shell/gpu/gpu_surface_gl.h"

namespace flutter {
namespace testing {

ShellTestPlatformViewGL::ShellTestPlatformViewGL(
PlatformView::Delegate& delegate,
TaskRunners task_runners,
std::shared_ptr<ShellTestVsyncClock> vsync_clock,
CreateVsyncWaiter create_vsync_waiter)
: ShellTestPlatformView(delegate, std::move(task_runners)),
gl_surface_(SkISize::Make(800, 600)),
create_vsync_waiter_(std::move(create_vsync_waiter)),
vsync_clock_(vsync_clock) {}

ShellTestPlatformViewGL::~ShellTestPlatformViewGL() = default;

std::unique_ptr<VsyncWaiter> ShellTestPlatformViewGL::CreateVSyncWaiter() {
return create_vsync_waiter_();
}

void ShellTestPlatformViewGL::SimulateVSync() {
vsync_clock_->SimulateVSync();
}

// |PlatformView|
std::unique_ptr<Surface> ShellTestPlatformViewGL::CreateRenderingSurface() {
return std::make_unique<GPUSurfaceGL>(this, true);
}

// |PlatformView|
PointerDataDispatcherMaker ShellTestPlatformViewGL::GetDispatcherMaker() {
return [](DefaultPointerDataDispatcher::Delegate& delegate) {
return std::make_unique<SmoothPointerDataDispatcher>(delegate);
};
}

// |GPUSurfaceGLDelegate|
bool ShellTestPlatformViewGL::GLContextMakeCurrent() {
return gl_surface_.MakeCurrent();
}

// |GPUSurfaceGLDelegate|
bool ShellTestPlatformViewGL::GLContextClearCurrent() {
return gl_surface_.ClearCurrent();
}

// |GPUSurfaceGLDelegate|
bool ShellTestPlatformViewGL::GLContextPresent() {
return gl_surface_.Present();
}

// |GPUSurfaceGLDelegate|
intptr_t ShellTestPlatformViewGL::GLContextFBO() const {
return gl_surface_.GetFramebuffer();
}

// |GPUSurfaceGLDelegate|
GPUSurfaceGLDelegate::GLProcResolver
ShellTestPlatformViewGL::GetGLProcResolver() const {
return [surface = &gl_surface_](const char* name) -> void* {
return surface->GetProcAddress(name);
};
}

// |GPUSurfaceGLDelegate|
ExternalViewEmbedder* ShellTestPlatformViewGL::GetExternalViewEmbedder() {
return nullptr;
}

} // namespace testing
} // namespace flutter
Loading