| Flutter Impeller |

playground_impl.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/playground/playground_impl.h"
6 #include "flutter/testing/testing.h"
7
8 #define GLFW_INCLUDE_NONE
9 #include "third_party/glfw/include/GLFW/glfw3.h"
10
11 #if IMPELLER_ENABLE_METAL
12 #include "impeller/playground/backend/metal/playground_impl_mtl.h"
13 #endif // IMPELLER_ENABLE_METAL
14
15 #if IMPELLER_ENABLE_OPENGLES
16 #include "impeller/playground/backend/gles/playground_impl_gles.h"
17 #endif // IMPELLER_ENABLE_OPENGLES
18
19 #if IMPELLER_ENABLE_VULKAN
20 #include "impeller/playground/backend/vulkan/playground_impl_vk.h"
21 #endif // IMPELLER_ENABLE_VULKAN
22
23 namespace impeller {
24
25 std::unique_ptr<PlaygroundImpl> PlaygroundImpl::Create(
26 PlaygroundBackend backend,
27 PlaygroundSwitches switches) {
28 switch (backend) {
29 #if IMPELLER_ENABLE_METAL
30 case PlaygroundBackend::kMetal:
31 return std::make_unique<PlaygroundImplMTL>(switches);
32 #endif // IMPELLER_ENABLE_METAL
33 #if IMPELLER_ENABLE_OPENGLES
34 case PlaygroundBackend::kOpenGLES:
35 return std::make_unique<PlaygroundImplGLES>(switches);
36 #endif // IMPELLER_ENABLE_OPENGLES
37 #if IMPELLER_ENABLE_VULKAN
38 case PlaygroundBackend::kVulkan:
39 if (!PlaygroundImplVK::IsVulkanDriverPresent()) {
40 FML_CHECK(false) << "Attempted to create playground with backend that "
41 "isn't available or was disabled on this platform: "
42 << PlaygroundBackendToString(backend);
43 }
44 switches.enable_vulkan_validation = true;
45 return std::make_unique<PlaygroundImplVK>(switches);
46 #endif // IMPELLER_ENABLE_VULKAN
47 default:
48 FML_CHECK(false) << "Attempted to create playground with backend that "
49 "isn't available or was disabled on this platform: "
50 << PlaygroundBackendToString(backend);
51 }
52 FML_UNREACHABLE();
53 }
54
55 PlaygroundImpl::PlaygroundImpl(PlaygroundSwitches switches)
56 : switches_(switches) {}
57
58 PlaygroundImpl::~PlaygroundImpl() = default;
59
60 Vector2 PlaygroundImpl::GetContentScale() const {
61 auto window = reinterpret_cast<GLFWwindow*>(GetWindowHandle());
62
63 Vector2 scale(1, 1);
64 ::glfwGetWindowContentScale(window, &scale.x, &scale.y);
65
66 return scale;
67 }
68
69 Playground::GLProcAddressResolver PlaygroundImpl::CreateGLProcAddressResolver()
70 const {
71 return nullptr;
72 }
73
74 } // namespace impeller
impeller::PlaygroundImpl::CreateGLProcAddressResolver
virtual Playground::GLProcAddressResolver CreateGLProcAddressResolver() const
Definition: playground_impl.cc:69
impeller::PlaygroundImplVK::IsVulkanDriverPresent
static bool IsVulkanDriverPresent()
Definition: playground_impl_vk.cc:220
impeller::PlaygroundBackend::kVulkan
@ kVulkan
playground_impl_gles.h
impeller::PlaygroundBackend::kMetal
@ kMetal
impeller::PlaygroundBackendToString
std::string PlaygroundBackendToString(PlaygroundBackend backend)
Definition: playground.cc:45
impeller::PlaygroundBackend
PlaygroundBackend
Definition: playground.h:26
impeller::PlaygroundImpl::~PlaygroundImpl
virtual ~PlaygroundImpl()
impeller::PlaygroundImpl::GetContentScale
Vector2 GetContentScale() const
Definition: playground_impl.cc:60
playground_impl_mtl.h
impeller::PlaygroundImpl::Create
static std::unique_ptr< PlaygroundImpl > Create(PlaygroundBackend backend, PlaygroundSwitches switches)
Definition: playground_impl.cc:25
impeller::PlaygroundImpl::GetWindowHandle
virtual WindowHandle GetWindowHandle() const =0
impeller::PlaygroundBackend::kOpenGLES
@ kOpenGLES
playground_impl_vk.h
impeller::PlaygroundSwitches
Definition: switches.h:15
impeller::TPoint< Scalar >
scale
const Scalar scale
Definition: stroke_path_geometry.cc:301
impeller::PlaygroundSwitches::enable_vulkan_validation
bool enable_vulkan_validation
Definition: switches.h:21
playground_impl.h
impeller::Playground::GLProcAddressResolver
std::function< void *(const char *proc_name)> GLProcAddressResolver
Definition: playground.h:117
impeller::PlaygroundImpl::PlaygroundImpl
PlaygroundImpl(PlaygroundSwitches switches)
Definition: playground_impl.cc:55
impeller
Definition: allocation.cc:12