| Flutter Impeller |

playground_test.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "impeller/toolkit/interop/playground_test.h"
6
7 #include "impeller/toolkit/interop/impeller.hpp"
8
9 namespace IMPELLER_HPP_NAMESPACE {
10 ProcTable gGlobalProcTable;
11 } // namespace IMPELLER_HPP_NAMESPACE
12
13 namespace impeller::interop::testing {
14
15 PlaygroundTest::PlaygroundTest() {
16 static std::once_flag sOnceFlag;
17 std::call_once(sOnceFlag, []() {
18 std::map<std::string, void*> proc_map;
19 #define IMPELLER_HPP_PROC(name) \
20 proc_map[#name] = reinterpret_cast<void*>(&name);
21 IMPELLER_HPP_EACH_PROC(IMPELLER_HPP_PROC)
22 #undef IMPELLER_HPP_PROC
23 hpp::gGlobalProcTable.Initialize(
24 [&](auto name) { return proc_map.at(name); });
25 });
26 }
27
28 PlaygroundTest::~PlaygroundTest() = default;
29
30 // |PlaygroundTest|
31 void PlaygroundTest::SetUp() {
32 ::impeller::PlaygroundTest::SetUp();
33 }
34
35 // |PlaygroundTest|
36 void PlaygroundTest::TearDown() {
37 ::impeller::PlaygroundTest::TearDown();
38 }
39
40 ScopedObject<Context> PlaygroundTest::CreateContext() const {
41 switch (GetBackend()) {
42 case PlaygroundBackend::kMetal:
43 FML_CHECK(false) << "Metal not yet implemented.";
44 return nullptr;
45 case PlaygroundBackend::kOpenGLES: {
46 Playground::GLProcAddressResolver playground_gl_proc_address_callback =
47 CreateGLProcAddressResolver();
48 ImpellerProcAddressCallback gl_proc_address_callback =
49 [](const char* proc_name, void* user_data) -> void* {
50 return (*reinterpret_cast<Playground::GLProcAddressResolver*>(
51 user_data))(proc_name);
52 };
53 return Adopt<Context>(ImpellerContextCreateOpenGLESNew(
54 ImpellerGetVersion(), gl_proc_address_callback,
55 &playground_gl_proc_address_callback));
56 }
57 case PlaygroundBackend::kVulkan:
58 FML_CHECK(false) << "Vulkan not yet implemented.";
59 return nullptr;
60 }
61 FML_UNREACHABLE();
62 }
63
64 bool PlaygroundTest::OpenPlaygroundHere(InteropPlaygroundCallback callback) {
65 auto context = GetInteropContext();
66 if (!context) {
67 return false;
68 }
69 return Playground::OpenPlaygroundHere([&](RenderTarget& target) -> bool {
70 auto impeller_surface = std::make_shared<impeller::Surface>(target);
71 auto surface = Create<Surface>(*context.Get(), impeller_surface);
72 if (!surface) {
73 return false;
74 }
75 return callback(context, surface);
76 });
77 }
78
79 ScopedObject<Context> PlaygroundTest::GetInteropContext() {
80 if (interop_context_) {
81 return interop_context_;
82 }
83 auto context = Create<Context>(GetContext(), nullptr);
84 if (!context) {
85 return nullptr;
86 }
87 interop_context_ = std::move(context);
88 return interop_context_;
89 }
90
91 } // namespace impeller::interop::testing
impeller::Playground::OpenPlaygroundHere
bool OpenPlaygroundHere(const RenderCallback &render_callback)
Definition: playground.cc:201
impeller::Playground::CreateGLProcAddressResolver
GLProcAddressResolver CreateGLProcAddressResolver() const
Definition: playground.cc:519
impeller::Playground::GetContext
std::shared_ptr< Context > GetContext() const
Definition: playground.cc:91
impeller::Playground::GLProcAddressResolver
std::function< void *(const char *proc_name)> GLProcAddressResolver
Definition: playground.h:118
impeller::PlaygroundTest::GetBackend
PlaygroundBackend GetBackend() const
Definition: playground_test.cc:72
impeller::PlaygroundTest::TearDown
void TearDown() override
Definition: playground_test.cc:76
impeller::PlaygroundTest::SetUp
void SetUp() override
Definition: playground_test.cc:45
impeller::RenderTarget
Definition: render_target.h:38
impeller::interop::ScopedObject
Definition: object.h:67
impeller::interop::testing::PlaygroundTest::SetUp
void SetUp() override
Definition: playground_test.cc:31
impeller::interop::testing::PlaygroundTest::CreateContext
ScopedObject< Context > CreateContext() const
Definition: playground_test.cc:40
impeller::interop::testing::PlaygroundTest::GetInteropContext
ScopedObject< Context > GetInteropContext()
Definition: playground_test.cc:79
impeller::interop::testing::PlaygroundTest::~PlaygroundTest
~PlaygroundTest() override
impeller::interop::testing::PlaygroundTest::TearDown
void TearDown() override
Definition: playground_test.cc:36
impeller::interop::testing::PlaygroundTest::InteropPlaygroundCallback
std::function< bool(const ScopedObject< Context > &context, const ScopedObject< Surface > &surface)> InteropPlaygroundCallback
Definition: playground_test.h:39
impeller::interop::testing::PlaygroundTest::OpenPlaygroundHere
bool OpenPlaygroundHere(InteropPlaygroundCallback callback)
Definition: playground_test.cc:64
impeller::interop::testing::PlaygroundTest::PlaygroundTest
PlaygroundTest()
Definition: playground_test.cc:15
ImpellerProcAddressCallback
void *IMPELLER_NULLABLE(* ImpellerProcAddressCallback)(const char *IMPELLER_NONNULL proc_name, void *IMPELLER_NULLABLE user_data)
Definition: impeller.h:310
impeller.hpp
IMPELLER_HPP_EACH_PROC
#define IMPELLER_HPP_EACH_PROC(PROC)
Definition: impeller.hpp:47
IMPELLER_HPP_NAMESPACE
Definition: impeller.hpp:31
IMPELLER_HPP_NAMESPACE::gGlobalProcTable
ProcTable gGlobalProcTable
Definition: playground_test.cc:10
impeller::interop::testing
Definition: impeller_unittests.cc:24
impeller::interop::ImpellerGetVersion
IMPELLER_EXTERN_C uint32_t ImpellerGetVersion()
Definition: impeller.cc:68
impeller::interop::ImpellerContextCreateOpenGLESNew
IMPELLER_EXTERN_C ImpellerContext ImpellerContextCreateOpenGLESNew(uint32_t version, ImpellerProcAddressCallback gl_proc_address_callback, void *gl_proc_address_callback_user_data)
Definition: impeller.cc:73
impeller::PlaygroundBackend::kOpenGLES
@ kOpenGLES
impeller::PlaygroundBackend::kMetal
@ kMetal
impeller::PlaygroundBackend::kVulkan
@ kVulkan
IMPELLER_HPP_NAMESPACE::ProcTable
Definition: impeller.hpp:182
IMPELLER_HPP_NAMESPACE::ProcTable::Initialize
bool Initialize(const std::function< void *(const char *function_name)> &resolver)
Definition: impeller.hpp:183
IMPELLER_HPP_PROC
#define IMPELLER_HPP_PROC(name)
playground_test.h