blob: f23a9276878b6f2fa29d9d30951bcfe8baecf2b0 [file] [log] [blame] [edit]
// 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 "impeller/toolkit/interop/playground_test.h"
namespace impeller::interop::testing {
PlaygroundTest::PlaygroundTest() = default;
PlaygroundTest::~PlaygroundTest() = default;
// |PlaygroundTest|
void PlaygroundTest::SetUp() {
::impeller::PlaygroundTest::SetUp();
}
// |PlaygroundTest|
void PlaygroundTest::TearDown() {
::impeller::PlaygroundTest::TearDown();
}
ScopedObject<Context> PlaygroundTest::CreateContext() const {
switch (GetBackend()) {
case PlaygroundBackend::kMetal:
FML_CHECK(false) << "Metal not yet implemented.";
return nullptr;
case PlaygroundBackend::kOpenGLES: {
Playground::GLProcAddressResolver playground_gl_proc_address_callback =
CreateGLProcAddressResolver();
ImpellerProcAddressCallback gl_proc_address_callback =
[](const char* proc_name, void* user_data) -> void* {
return (*reinterpret_cast<Playground::GLProcAddressResolver*>(
user_data))(proc_name);
};
return Adopt<Context>(ImpellerContextCreateOpenGLESNew(
ImpellerGetVersion(), gl_proc_address_callback,
&playground_gl_proc_address_callback));
}
case PlaygroundBackend::kVulkan:
FML_CHECK(false) << "Vulkan not yet implemented.";
return nullptr;
}
FML_UNREACHABLE();
}
bool PlaygroundTest::OpenPlaygroundHere(InteropPlaygroundCallback callback) {
auto context = GetInteropContext();
if (!context) {
return false;
}
return Playground::OpenPlaygroundHere([&](RenderTarget& target) -> bool {
auto impeller_surface = std::make_shared<impeller::Surface>(target);
auto surface = Create<Surface>(*context.Get(), impeller_surface);
if (!surface) {
return false;
}
return callback(context, surface);
});
}
ScopedObject<Context> PlaygroundTest::GetInteropContext() {
if (interop_context_) {
return interop_context_;
}
auto context = Create<Context>(GetContext(), nullptr);
if (!context) {
return nullptr;
}
interop_context_ = std::move(context);
return interop_context_;
}
} // namespace impeller::interop::testing