Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move SetRenderTargetType to EmbedderTestCompositor #56626

Merged
merged 1 commit into from
Nov 15, 2024
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
2 changes: 1 addition & 1 deletion shell/platform/embedder/tests/embedder_config_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ FlutterCompositor& EmbedderConfigBuilder::GetCompositor() {
void EmbedderConfigBuilder::SetRenderTargetType(
EmbedderTestBackingStoreProducer::RenderTargetType type,
FlutterSoftwarePixelFormat software_pixfmt) {
context_.SetRenderTargetType(type, software_pixfmt);
context_.GetCompositor().SetRenderTargetType(type, software_pixfmt);
}

UniqueEngine EmbedderConfigBuilder::LaunchEngine() const {
Expand Down
5 changes: 0 additions & 5 deletions shell/platform/embedder/tests/embedder_test_compositor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,6 @@ bool EmbedderTestCompositor::CollectBackingStore(
return true;
}

void EmbedderTestCompositor::SetBackingStoreProducer(
std::unique_ptr<EmbedderTestBackingStoreProducer> backingstore_producer) {
backingstore_producer_ = std::move(backingstore_producer);
}

sk_sp<SkImage> EmbedderTestCompositor::GetLastComposition() {
return last_composition_;
}
Expand Down
5 changes: 3 additions & 2 deletions shell/platform/embedder/tests/embedder_test_compositor.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ class EmbedderTestCompositor {

virtual ~EmbedderTestCompositor();

void SetBackingStoreProducer(
std::unique_ptr<EmbedderTestBackingStoreProducer> backingstore_producer);
virtual void SetRenderTargetType(
EmbedderTestBackingStoreProducer::RenderTargetType type,
FlutterSoftwarePixelFormat software_pixfmt) = 0;

bool CreateBackingStore(const FlutterBackingStoreConfig* config,
FlutterBackingStore* backing_store_out);
Expand Down
27 changes: 26 additions & 1 deletion shell/platform/embedder/tests/embedder_test_compositor_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,37 @@ namespace flutter {
namespace testing {

EmbedderTestCompositorGL::EmbedderTestCompositorGL(
std::shared_ptr<TestEGLContext> egl_context,
SkISize surface_size,
sk_sp<GrDirectContext> context)
: EmbedderTestCompositor(surface_size, std::move(context)) {}
: EmbedderTestCompositor(surface_size, std::move(context)),
egl_context_(std::move(egl_context)) {}

EmbedderTestCompositorGL::~EmbedderTestCompositorGL() = default;

void EmbedderTestCompositorGL::SetRenderTargetType(
EmbedderTestBackingStoreProducer::RenderTargetType type,
FlutterSoftwarePixelFormat software_pixfmt) {
switch (type) {
case EmbedderTestBackingStoreProducer::RenderTargetType::kOpenGLFramebuffer:
case EmbedderTestBackingStoreProducer::RenderTargetType::kOpenGLSurface:
case EmbedderTestBackingStoreProducer::RenderTargetType::kOpenGLTexture:
case EmbedderTestBackingStoreProducer::RenderTargetType::kSoftwareBuffer:
case EmbedderTestBackingStoreProducer::RenderTargetType::kSoftwareBuffer2:
// no-op: Rendering into GL and software render targets is supported.
break;
case EmbedderTestBackingStoreProducer::RenderTargetType::kMetalTexture:
case EmbedderTestBackingStoreProducer::RenderTargetType::kVulkanImage:
FML_LOG(FATAL) << "Unsupported render target type: "
<< static_cast<int>(type);
break;
}
auto producer = std::make_unique<EmbedderTestBackingStoreProducer>(
context_, type, software_pixfmt);
producer->SetEGLContext(egl_context_);
backingstore_producer_ = std::move(producer);
}

bool EmbedderTestCompositorGL::UpdateOffscrenComposition(
const FlutterLayer** layers,
size_t layers_count) {
Expand Down
11 changes: 10 additions & 1 deletion shell/platform/embedder/tests/embedder_test_compositor_gl.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,30 @@
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_TEST_COMPOSITOR_GL_H_
#define FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_TEST_COMPOSITOR_GL_H_

#include <memory>

#include "flutter/fml/macros.h"
#include "flutter/shell/platform/embedder/embedder.h"
#include "flutter/shell/platform/embedder/tests/embedder_test_compositor.h"
#include "flutter/testing/test_gl_surface.h"

namespace flutter {
namespace testing {

class EmbedderTestCompositorGL : public EmbedderTestCompositor {
public:
EmbedderTestCompositorGL(SkISize surface_size,
EmbedderTestCompositorGL(std::shared_ptr<TestEGLContext> egl_context,
SkISize surface_size,
sk_sp<GrDirectContext> context);

~EmbedderTestCompositorGL() override;

void SetRenderTargetType(
EmbedderTestBackingStoreProducer::RenderTargetType type,
FlutterSoftwarePixelFormat software_pixfmt) override;

private:
std::shared_ptr<TestEGLContext> egl_context_;
bool UpdateOffscrenComposition(const FlutterLayer** layers,
size_t layers_count) override;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class EmbedderTestCompositorMetal : public EmbedderTestCompositor {

~EmbedderTestCompositorMetal() override;

void SetRenderTargetType(
EmbedderTestBackingStoreProducer::RenderTargetType type,
FlutterSoftwarePixelFormat software_pixfmt) override;

private:
bool UpdateOffscrenComposition(const FlutterLayer** layers,
size_t layers_count) override;
Expand Down
20 changes: 20 additions & 0 deletions shell/platform/embedder/tests/embedder_test_compositor_metal.mm
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,26 @@

EmbedderTestCompositorMetal::~EmbedderTestCompositorMetal() = default;

void EmbedderTestCompositorMetal::SetRenderTargetType(
EmbedderTestBackingStoreProducer::RenderTargetType type,
FlutterSoftwarePixelFormat software_pixfmt) {
switch (type) {
case EmbedderTestBackingStoreProducer::RenderTargetType::kMetalTexture:
// no-op.
break;
case EmbedderTestBackingStoreProducer::RenderTargetType::kOpenGLFramebuffer:
case EmbedderTestBackingStoreProducer::RenderTargetType::kOpenGLSurface:
case EmbedderTestBackingStoreProducer::RenderTargetType::kOpenGLTexture:
case EmbedderTestBackingStoreProducer::RenderTargetType::kSoftwareBuffer:
case EmbedderTestBackingStoreProducer::RenderTargetType::kSoftwareBuffer2:
case EmbedderTestBackingStoreProducer::RenderTargetType::kVulkanImage:
FML_LOG(FATAL) << "Unsupported render target type: " << static_cast<int>(type);
break;
}
backingstore_producer_ =
std::make_unique<EmbedderTestBackingStoreProducer>(context_, type, software_pixfmt);
}

bool EmbedderTestCompositorMetal::UpdateOffscrenComposition(const FlutterLayer** layers,
size_t layers_count) {
last_composition_ = nullptr;
Expand Down
21 changes: 21 additions & 0 deletions shell/platform/embedder/tests/embedder_test_compositor_software.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,27 @@ EmbedderTestCompositorSoftware::EmbedderTestCompositorSoftware(

EmbedderTestCompositorSoftware::~EmbedderTestCompositorSoftware() = default;

void EmbedderTestCompositorSoftware::SetRenderTargetType(
EmbedderTestBackingStoreProducer::RenderTargetType type,
FlutterSoftwarePixelFormat software_pixfmt) {
switch (type) {
case EmbedderTestBackingStoreProducer::RenderTargetType::kSoftwareBuffer:
case EmbedderTestBackingStoreProducer::RenderTargetType::kSoftwareBuffer2:
// no-op.
break;
case EmbedderTestBackingStoreProducer::RenderTargetType::kMetalTexture:
case EmbedderTestBackingStoreProducer::RenderTargetType::kOpenGLFramebuffer:
case EmbedderTestBackingStoreProducer::RenderTargetType::kOpenGLSurface:
case EmbedderTestBackingStoreProducer::RenderTargetType::kOpenGLTexture:
case EmbedderTestBackingStoreProducer::RenderTargetType::kVulkanImage:
FML_LOG(FATAL) << "Unsupported render target type: "
<< static_cast<int>(type);
break;
}
backingstore_producer_ = std::make_unique<EmbedderTestBackingStoreProducer>(
context_, type, software_pixfmt);
}

bool EmbedderTestCompositorSoftware::UpdateOffscrenComposition(
const FlutterLayer** layers,
size_t layers_count) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class EmbedderTestCompositorSoftware : public EmbedderTestCompositor {

~EmbedderTestCompositorSoftware() override;

void SetRenderTargetType(
EmbedderTestBackingStoreProducer::RenderTargetType type,
FlutterSoftwarePixelFormat software_pixfmt) override;

private:
bool UpdateOffscrenComposition(const FlutterLayer** layers,
size_t layers_count);
Expand Down
21 changes: 21 additions & 0 deletions shell/platform/embedder/tests/embedder_test_compositor_vulkan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,27 @@ EmbedderTestCompositorVulkan::EmbedderTestCompositorVulkan(

EmbedderTestCompositorVulkan::~EmbedderTestCompositorVulkan() = default;

void EmbedderTestCompositorVulkan::SetRenderTargetType(
EmbedderTestBackingStoreProducer::RenderTargetType type,
FlutterSoftwarePixelFormat software_pixfmt) {
switch (type) {
case EmbedderTestBackingStoreProducer::RenderTargetType::kVulkanImage:
// no-op.
break;
case EmbedderTestBackingStoreProducer::RenderTargetType::kMetalTexture:
case EmbedderTestBackingStoreProducer::RenderTargetType::kOpenGLFramebuffer:
case EmbedderTestBackingStoreProducer::RenderTargetType::kOpenGLSurface:
case EmbedderTestBackingStoreProducer::RenderTargetType::kOpenGLTexture:
case EmbedderTestBackingStoreProducer::RenderTargetType::kSoftwareBuffer:
case EmbedderTestBackingStoreProducer::RenderTargetType::kSoftwareBuffer2:
FML_LOG(FATAL) << "Unsupported render target type: "
<< static_cast<int>(type);
break;
}
backingstore_producer_ = std::make_unique<EmbedderTestBackingStoreProducer>(
context_, type, software_pixfmt);
}

bool EmbedderTestCompositorVulkan::UpdateOffscrenComposition(
const FlutterLayer** layers,
size_t layers_count) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class EmbedderTestCompositorVulkan : public EmbedderTestCompositor {

~EmbedderTestCompositorVulkan() override;

void SetRenderTargetType(
EmbedderTestBackingStoreProducer::RenderTargetType type,
FlutterSoftwarePixelFormat software_pixfmt) override;

private:
bool UpdateOffscrenComposition(const FlutterLayer** layers,
size_t layers_count) override;
Expand Down
26 changes: 0 additions & 26 deletions shell/platform/embedder/tests/embedder_test_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,32 +96,6 @@ void EmbedderTestContext::SetRootSurfaceTransformation(SkMatrix matrix) {
root_surface_transformation_ = matrix;
}

void EmbedderTestContext::SetRenderTargetType(
EmbedderTestBackingStoreProducer::RenderTargetType type,
FlutterSoftwarePixelFormat software_pixfmt) {
// TODO(wrightgeorge): figure out a better way of plumbing through the
// GrDirectContext
Copy link
Member Author

Choose a reason for hiding this comment

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

Figured out a better way of plumbing through GrDirectContext.

auto& compositor = GetCompositor();
auto producer = std::make_unique<EmbedderTestBackingStoreProducer>(
compositor.GetGrContext(), type, software_pixfmt);
#ifdef SHELL_ENABLE_GL
switch (type) {
case EmbedderTestBackingStoreProducer::RenderTargetType::kOpenGLFramebuffer:
case EmbedderTestBackingStoreProducer::RenderTargetType::kOpenGLTexture:
case EmbedderTestBackingStoreProducer::RenderTargetType::kOpenGLSurface:
producer->SetEGLContext(egl_context_);
break;
case EmbedderTestBackingStoreProducer::RenderTargetType::kSoftwareBuffer:
case EmbedderTestBackingStoreProducer::RenderTargetType::kSoftwareBuffer2:
case EmbedderTestBackingStoreProducer::RenderTargetType::kMetalTexture:
case EmbedderTestBackingStoreProducer::RenderTargetType::kVulkanImage:
// no-op.
break;
}
#endif // SHELL_ENABLE_GL
compositor.SetBackingStoreProducer(std::move(producer));
}

void EmbedderTestContext::AddIsolateCreateCallback(
const fml::closure& closure) {
if (closure) {
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/embedder/tests/embedder_test_context_gl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void EmbedderTestContextGL::SetupCompositor() {
FML_CHECK(gl_surface_)
<< "Set up the GL surface before setting up a compositor.";
compositor_ = std::make_unique<EmbedderTestCompositorGL>(
gl_surface_->GetSurfaceSize(), gl_surface_->GetGrContext());
egl_context_, gl_surface_->GetSurfaceSize(), gl_surface_->GetGrContext());
GLClearCurrent();
}

Expand Down