summaryrefslogtreecommitdiffstats
path: root/src/core/compositor/display_overrides.cpp
blob: ebaa96dbb568dee9bcd8ccc0397640765ea2a690 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (C) 2019 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "display_skia_output_device.h"
#include "display_software_output_surface.h"
#include "native_skia_output_device.h"

#include "components/viz/service/display_embedder/output_surface_provider_impl.h"
#include "components/viz/service/display_embedder/skia_output_surface_impl_on_gpu.h"
#include "gpu/ipc/in_process_command_buffer.h"

#include <qtgui-config.h>
#include <QtQuick/qquickwindow.h>

#if QT_CONFIG(opengl)
#include "native_skia_output_device_opengl.h"
#endif

#if BUILDFLAG(ENABLE_VULKAN)
#include "native_skia_output_device_vulkan.h"
#endif

#if defined(Q_OS_WIN)
#include "native_skia_output_device_direct3d11.h"
#endif

#if defined(Q_OS_MACOS)
#include "native_skia_output_device_metal.h"
#endif

std::unique_ptr<viz::OutputSurface>
viz::OutputSurfaceProviderImpl::CreateSoftwareOutputSurface(const RendererSettings &renderer_settings)
{
    return std::make_unique<QtWebEngineCore::DisplaySoftwareOutputSurface>(renderer_settings.requires_alpha_channel);
}

std::unique_ptr<viz::SkiaOutputDevice>
viz::SkiaOutputSurfaceImplOnGpu::CreateOutputDevice()
{
    static const auto graphicsApi = QQuickWindow::graphicsApi();

#if QT_CONFIG(opengl)
    if (graphicsApi == QSGRendererInterface::OpenGL) {
        if (gl::GetGLImplementation() != gl::kGLImplementationEGLANGLE) {
#if !defined(Q_OS_MACOS)
            return std::make_unique<QtWebEngineCore::DisplaySkiaOutputDevice>(
                    context_state_, renderer_settings_.requires_alpha_channel,
                    shared_gpu_deps_->memory_tracker(), GetDidSwapBuffersCompleteCallback());
#else
            qFatal("macOS only supports ANGLE.");
#endif // !defined(Q_OS_MACOS)
        }

        return std::make_unique<QtWebEngineCore::NativeSkiaOutputDeviceOpenGL>(
                context_state_, renderer_settings_.requires_alpha_channel,
                shared_gpu_deps_->memory_tracker(), dependency_.get(), shared_image_factory_.get(),
                shared_image_representation_factory_.get(), GetDidSwapBuffersCompleteCallback());
    }
#endif // QT_CONFIG(opengl)

#if BUILDFLAG(ENABLE_VULKAN)
    if (graphicsApi == QSGRendererInterface::Vulkan) {
#if !defined(Q_OS_MACOS)
        return std::make_unique<QtWebEngineCore::NativeSkiaOutputDeviceVulkan>(
                context_state_, renderer_settings_.requires_alpha_channel,
                shared_gpu_deps_->memory_tracker(), dependency_.get(), shared_image_factory_.get(),
                shared_image_representation_factory_.get(), GetDidSwapBuffersCompleteCallback());
#else
        qFatal("Vulkan is not supported on macOS.");
#endif // !defined(Q_OS_MACOS)
    }
#endif // BUILDFLAG(ENABLE_VULKAN)

#if defined(Q_OS_WIN)
    if (graphicsApi == QSGRendererInterface::Direct3D11) {
        if (gl::GetGLImplementation() != gl::kGLImplementationEGLANGLE)
            qFatal("Direct3D11 is only supported over ANGLE.");

        return std::make_unique<QtWebEngineCore::NativeSkiaOutputDeviceDirect3D11>(
                context_state_, renderer_settings_.requires_alpha_channel,
                shared_gpu_deps_->memory_tracker(), dependency_.get(), shared_image_factory_.get(),
                shared_image_representation_factory_.get(), GetDidSwapBuffersCompleteCallback());
    }
#endif

#if defined(Q_OS_MACOS)
    if (graphicsApi == QSGRendererInterface::Metal) {
        if (gl::GetGLImplementation() != gl::kGLImplementationEGLANGLE)
            qFatal("Metal is only supported over ANGLE.");

        return std::make_unique<QtWebEngineCore::NativeSkiaOutputDeviceMetal>(
                context_state_, renderer_settings_.requires_alpha_channel,
                shared_gpu_deps_->memory_tracker(), dependency_.get(), shared_image_factory_.get(),
                shared_image_representation_factory_.get(), GetDidSwapBuffersCompleteCallback());
    }
#endif

    qFatal() << "Unsupported Graphics API:" << graphicsApi;
    return nullptr;
}