Skip to content

Commit

Permalink
Move SetRenderTargetType to EmbedderTestCompositor
Browse files Browse the repository at this point in the history
SetRenderTargetType is used to configure the backingstore producer on
the compositor, but the backingstore types available to any given
compositor are limited to the specific graphics backend in use:
Software, GL, Metal, or Vulkan.

This moves SetRenderTargetType to EmbedderTestCompositor and its
subclasses and adds RenderTargetType validation. A follow-up patch will
refactor EmbedderTestBackingStoreProducer into backend-specific
subclasses.

For OpenGL backingstore producers, the egl_context_ from
EmbedderTestContext (which is actually set in the EmbedderTestContextGL
subclass and should live there, but that's a separate cleanup) is
required in SetRenderTargetType, so we now inject it into
EmbedderTestCompositor in the constructor so it's available when needed.
  • Loading branch information
cbracken committed Nov 15, 2024
1 parent 5f8e6e4 commit 7b0f438
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 37 deletions.
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_(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:
// no-op.
break;
case EmbedderTestBackingStoreProducer::RenderTargetType::kMetalTexture:
case EmbedderTestBackingStoreProducer::RenderTargetType::kSoftwareBuffer:
case EmbedderTestBackingStoreProducer::RenderTargetType::kSoftwareBuffer2:
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
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

0 comments on commit 7b0f438

Please sign in to comment.