Move SetRenderTargetType to EmbedderTestCompositor (flutter/engine#56626)
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. Issue: https://github.com/flutter/flutter/issues/158998 [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
This commit is contained in:
parent
8b67ea6d10
commit
2b420dcf9c
@ -287,7 +287,7 @@ FlutterCompositor& EmbedderConfigBuilder::GetCompositor() {
|
|||||||
void EmbedderConfigBuilder::SetRenderTargetType(
|
void EmbedderConfigBuilder::SetRenderTargetType(
|
||||||
EmbedderTestBackingStoreProducer::RenderTargetType type,
|
EmbedderTestBackingStoreProducer::RenderTargetType type,
|
||||||
FlutterSoftwarePixelFormat software_pixfmt) {
|
FlutterSoftwarePixelFormat software_pixfmt) {
|
||||||
context_.SetRenderTargetType(type, software_pixfmt);
|
context_.GetCompositor().SetRenderTargetType(type, software_pixfmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
UniqueEngine EmbedderConfigBuilder::LaunchEngine() const {
|
UniqueEngine EmbedderConfigBuilder::LaunchEngine() const {
|
||||||
|
@ -51,11 +51,6 @@ bool EmbedderTestCompositor::CollectBackingStore(
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EmbedderTestCompositor::SetBackingStoreProducer(
|
|
||||||
std::unique_ptr<EmbedderTestBackingStoreProducer> backingstore_producer) {
|
|
||||||
backingstore_producer_ = std::move(backingstore_producer);
|
|
||||||
}
|
|
||||||
|
|
||||||
sk_sp<SkImage> EmbedderTestCompositor::GetLastComposition() {
|
sk_sp<SkImage> EmbedderTestCompositor::GetLastComposition() {
|
||||||
return last_composition_;
|
return last_composition_;
|
||||||
}
|
}
|
||||||
|
@ -29,8 +29,9 @@ class EmbedderTestCompositor {
|
|||||||
|
|
||||||
virtual ~EmbedderTestCompositor();
|
virtual ~EmbedderTestCompositor();
|
||||||
|
|
||||||
void SetBackingStoreProducer(
|
virtual void SetRenderTargetType(
|
||||||
std::unique_ptr<EmbedderTestBackingStoreProducer> backingstore_producer);
|
EmbedderTestBackingStoreProducer::RenderTargetType type,
|
||||||
|
FlutterSoftwarePixelFormat software_pixfmt) = 0;
|
||||||
|
|
||||||
bool CreateBackingStore(const FlutterBackingStoreConfig* config,
|
bool CreateBackingStore(const FlutterBackingStoreConfig* config,
|
||||||
FlutterBackingStore* backing_store_out);
|
FlutterBackingStore* backing_store_out);
|
||||||
|
@ -15,12 +15,37 @@ namespace flutter {
|
|||||||
namespace testing {
|
namespace testing {
|
||||||
|
|
||||||
EmbedderTestCompositorGL::EmbedderTestCompositorGL(
|
EmbedderTestCompositorGL::EmbedderTestCompositorGL(
|
||||||
|
std::shared_ptr<TestEGLContext> egl_context,
|
||||||
SkISize surface_size,
|
SkISize surface_size,
|
||||||
sk_sp<GrDirectContext> context)
|
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;
|
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(
|
bool EmbedderTestCompositorGL::UpdateOffscrenComposition(
|
||||||
const FlutterLayer** layers,
|
const FlutterLayer** layers,
|
||||||
size_t layers_count) {
|
size_t layers_count) {
|
||||||
|
@ -5,21 +5,30 @@
|
|||||||
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_TEST_COMPOSITOR_GL_H_
|
#ifndef FLUTTER_SHELL_PLATFORM_EMBEDDER_TESTS_EMBEDDER_TEST_COMPOSITOR_GL_H_
|
||||||
#define 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/fml/macros.h"
|
||||||
#include "flutter/shell/platform/embedder/embedder.h"
|
#include "flutter/shell/platform/embedder/embedder.h"
|
||||||
#include "flutter/shell/platform/embedder/tests/embedder_test_compositor.h"
|
#include "flutter/shell/platform/embedder/tests/embedder_test_compositor.h"
|
||||||
|
#include "flutter/testing/test_gl_surface.h"
|
||||||
|
|
||||||
namespace flutter {
|
namespace flutter {
|
||||||
namespace testing {
|
namespace testing {
|
||||||
|
|
||||||
class EmbedderTestCompositorGL : public EmbedderTestCompositor {
|
class EmbedderTestCompositorGL : public EmbedderTestCompositor {
|
||||||
public:
|
public:
|
||||||
EmbedderTestCompositorGL(SkISize surface_size,
|
EmbedderTestCompositorGL(std::shared_ptr<TestEGLContext> egl_context,
|
||||||
|
SkISize surface_size,
|
||||||
sk_sp<GrDirectContext> context);
|
sk_sp<GrDirectContext> context);
|
||||||
|
|
||||||
~EmbedderTestCompositorGL() override;
|
~EmbedderTestCompositorGL() override;
|
||||||
|
|
||||||
|
void SetRenderTargetType(
|
||||||
|
EmbedderTestBackingStoreProducer::RenderTargetType type,
|
||||||
|
FlutterSoftwarePixelFormat software_pixfmt) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::shared_ptr<TestEGLContext> egl_context_;
|
||||||
bool UpdateOffscrenComposition(const FlutterLayer** layers,
|
bool UpdateOffscrenComposition(const FlutterLayer** layers,
|
||||||
size_t layers_count) override;
|
size_t layers_count) override;
|
||||||
|
|
||||||
|
@ -19,6 +19,10 @@ class EmbedderTestCompositorMetal : public EmbedderTestCompositor {
|
|||||||
|
|
||||||
~EmbedderTestCompositorMetal() override;
|
~EmbedderTestCompositorMetal() override;
|
||||||
|
|
||||||
|
void SetRenderTargetType(
|
||||||
|
EmbedderTestBackingStoreProducer::RenderTargetType type,
|
||||||
|
FlutterSoftwarePixelFormat software_pixfmt) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool UpdateOffscrenComposition(const FlutterLayer** layers,
|
bool UpdateOffscrenComposition(const FlutterLayer** layers,
|
||||||
size_t layers_count) override;
|
size_t layers_count) override;
|
||||||
|
@ -20,6 +20,26 @@ EmbedderTestCompositorMetal::EmbedderTestCompositorMetal(SkISize surface_size,
|
|||||||
|
|
||||||
EmbedderTestCompositorMetal::~EmbedderTestCompositorMetal() = default;
|
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,
|
bool EmbedderTestCompositorMetal::UpdateOffscrenComposition(const FlutterLayer** layers,
|
||||||
size_t layers_count) {
|
size_t layers_count) {
|
||||||
last_composition_ = nullptr;
|
last_composition_ = nullptr;
|
||||||
|
@ -17,6 +17,27 @@ EmbedderTestCompositorSoftware::EmbedderTestCompositorSoftware(
|
|||||||
|
|
||||||
EmbedderTestCompositorSoftware::~EmbedderTestCompositorSoftware() = default;
|
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(
|
bool EmbedderTestCompositorSoftware::UpdateOffscrenComposition(
|
||||||
const FlutterLayer** layers,
|
const FlutterLayer** layers,
|
||||||
size_t layers_count) {
|
size_t layers_count) {
|
||||||
|
@ -16,6 +16,10 @@ class EmbedderTestCompositorSoftware : public EmbedderTestCompositor {
|
|||||||
|
|
||||||
~EmbedderTestCompositorSoftware() override;
|
~EmbedderTestCompositorSoftware() override;
|
||||||
|
|
||||||
|
void SetRenderTargetType(
|
||||||
|
EmbedderTestBackingStoreProducer::RenderTargetType type,
|
||||||
|
FlutterSoftwarePixelFormat software_pixfmt) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool UpdateOffscrenComposition(const FlutterLayer** layers,
|
bool UpdateOffscrenComposition(const FlutterLayer** layers,
|
||||||
size_t layers_count);
|
size_t layers_count);
|
||||||
|
@ -22,6 +22,27 @@ EmbedderTestCompositorVulkan::EmbedderTestCompositorVulkan(
|
|||||||
|
|
||||||
EmbedderTestCompositorVulkan::~EmbedderTestCompositorVulkan() = default;
|
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(
|
bool EmbedderTestCompositorVulkan::UpdateOffscrenComposition(
|
||||||
const FlutterLayer** layers,
|
const FlutterLayer** layers,
|
||||||
size_t layers_count) {
|
size_t layers_count) {
|
||||||
|
@ -19,6 +19,10 @@ class EmbedderTestCompositorVulkan : public EmbedderTestCompositor {
|
|||||||
|
|
||||||
~EmbedderTestCompositorVulkan() override;
|
~EmbedderTestCompositorVulkan() override;
|
||||||
|
|
||||||
|
void SetRenderTargetType(
|
||||||
|
EmbedderTestBackingStoreProducer::RenderTargetType type,
|
||||||
|
FlutterSoftwarePixelFormat software_pixfmt) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool UpdateOffscrenComposition(const FlutterLayer** layers,
|
bool UpdateOffscrenComposition(const FlutterLayer** layers,
|
||||||
size_t layers_count) override;
|
size_t layers_count) override;
|
||||||
|
@ -96,32 +96,6 @@ void EmbedderTestContext::SetRootSurfaceTransformation(SkMatrix matrix) {
|
|||||||
root_surface_transformation_ = 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(
|
void EmbedderTestContext::AddIsolateCreateCallback(
|
||||||
const fml::closure& closure) {
|
const fml::closure& closure) {
|
||||||
if (closure) {
|
if (closure) {
|
||||||
|
@ -140,7 +140,7 @@ void EmbedderTestContextGL::SetupCompositor() {
|
|||||||
FML_CHECK(gl_surface_)
|
FML_CHECK(gl_surface_)
|
||||||
<< "Set up the GL surface before setting up a compositor.";
|
<< "Set up the GL surface before setting up a compositor.";
|
||||||
compositor_ = std::make_unique<EmbedderTestCompositorGL>(
|
compositor_ = std::make_unique<EmbedderTestCompositorGL>(
|
||||||
gl_surface_->GetSurfaceSize(), gl_surface_->GetGrContext());
|
egl_context_, gl_surface_->GetSurfaceSize(), gl_surface_->GetGrContext());
|
||||||
GLClearCurrent();
|
GLClearCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user