summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Varga <pvarga@inf.u-szeged.hu>2023-12-21 09:08:01 +0100
committerPeter Varga <pvarga@inf.u-szeged.hu>2024-01-12 19:31:33 +0100
commit79320b37769d659c7ec243dc4d2e4dc037f74ab0 (patch)
tree778f3c06eb06a1f52efd0ebd5a45bc65cb0cd00a
parentb79349aadbc7479938f273fcc20d6e021d94c2d2 (diff)
Get rid of native_skia_output_device_mac2.mm
This source file was used to workaround redefinition build errors when including Qt headers in native_skia_output_device_mac.mm. Introduce another workaround what doesn't redefine Q_FORWARD_DECLARE_OBJC_CLASS macro in native_skia_output_device_mac.mm thus the two source files can be merged into one. Pick-to: 6.7 Change-Id: I640c42e435514f5df0fcb8b69d0d728d9420e761 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
-rw-r--r--src/core/CMakeLists.txt1
-rw-r--r--src/core/compositor/native_skia_output_device_mac.mm83
-rw-r--r--src/core/compositor/native_skia_output_device_mac2.mm89
3 files changed, 70 insertions, 103 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 058ea4405..67f821589 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -230,7 +230,6 @@ foreach(arch ${archs})
SOURCES
native_web_keyboard_event_qt_mac.mm
compositor/native_skia_output_device_mac.mm
- compositor/native_skia_output_device_mac2.mm
)
extend_gn_target(${buildGn} CONDITION QT_FEATURE_webengine_pepper_plugins
diff --git a/src/core/compositor/native_skia_output_device_mac.mm b/src/core/compositor/native_skia_output_device_mac.mm
index ef400272c..8a23ef7c3 100644
--- a/src/core/compositor/native_skia_output_device_mac.mm
+++ b/src/core/compositor/native_skia_output_device_mac.mm
@@ -1,38 +1,95 @@
// Copyright (C) 2023 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
+// This is a workaround to be able to include Qt headers without
+// "redefinition of 'NSString' as different kind of symbol" errors.
+// TODO: Remove this when namespace ambiguity issues are fixed properly,
+// see get_forward_declaration_macro() in cmake/Functions.cmake
+#undef Q_FORWARD_DECLARE_OBJC_CLASS
+
#import <AppKit/AppKit.h>
#import <IOSurface/IOSurface.h>
#import <Metal/Metal.h>
#include <QtGui/qtguiglobal.h>
+#include <QtQuick/qquickwindow.h>
+#include <QtQuick/qsgrendererinterface.h>
+#include <QtQuick/qsgtexture.h>
-QT_BEGIN_NAMESPACE
-class QSGTexture;
-class QQuickWindow;
-QT_END_NAMESPACE
-
-@protocol MTLDevice;
+#if QT_CONFIG(opengl)
+#include <OpenGL/OpenGL.h>
+#include <QtGui/qopenglcontext.h>
+#include <QtGui/qopenglextrafunctions.h>
+#include <QtOpenGL/qopengltextureblitter.h>
+#include <QtOpenGL/qopenglframebufferobject.h>
+#endif
namespace QtWebEngineCore {
-QSGTexture *makeMetalTexture2(QQuickWindow *win, id<MTLTexture> mtlTexture, int width, int height, uint32_t textureOptions);
-id<MTLDevice> getRhiDev(QQuickWindow *win);
QSGTexture *makeMetalTexture(QQuickWindow *win, IOSurfaceRef io_surface, uint io_surface_plane, int width, int height, uint32_t textureOptions)
{
auto desc = [MTLTextureDescriptor texture2DDescriptorWithPixelFormat:MTLPixelFormatBGRA8Unorm
width:width height:height mipmapped:false];
- auto device = getRhiDev(win);
+ QSGRendererInterface *ri = win->rendererInterface();
+ auto device = (__bridge id<MTLDevice>)(ri->getResource(win, QSGRendererInterface::DeviceResource));
auto texture = [device newTextureWithDescriptor:desc iosurface:io_surface plane:io_surface_plane];
- return makeMetalTexture2(win, texture, width, height, textureOptions);
+ QQuickWindow::CreateTextureOptions texOpts(textureOptions);
+ return QNativeInterface::QSGMetalTexture::fromNative(texture, win, {width, height}, texOpts);
}
#if QT_CONFIG(opengl)
-CGLContextObj getCGLContext(NSOpenGLContext *context)
+void releaseGlTexture(uint32_t glTexture)
{
- return [context CGLContextObj];
+ auto *glContext = QOpenGLContext::currentContext();
+ if (!glContext)
+ return;
+ auto glFun = glContext->functions();
+ glFun->glDeleteTextures(1, &glTexture);
}
-#endif
+
+QSGTexture *makeCGLTexture(QQuickWindow *win, IOSurfaceRef io_surface, int width, int height, uint32_t textureOptions, uint32_t *heldTexture)
+{
+ auto glContext = QOpenGLContext::currentContext();
+ auto glFun = glContext->extraFunctions();
+ auto nscontext = glContext->nativeInterface<QNativeInterface::QCocoaGLContext>()->nativeContext();
+ CGLContextObj cglContext = [nscontext CGLContextObj];
+
+ win->beginExternalCommands();
+ // Bind the IO surface to a texture
+ GLuint glTexture;
+ glFun->glGenTextures(1, &glTexture);
+ glFun->glBindTexture(GL_TEXTURE_RECTANGLE_ARB, glTexture);
+ CGLTexImageIOSurface2D(cglContext, GL_TEXTURE_RECTANGLE_ARB, GL_RGBA, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, io_surface, 0);
+ glFun->glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
+ glFun->glViewport(0, 0, width, height);
+
+ // The bound IO surface is a weird dynamic bind, so take a snapshot of it to a normal texture
+ {
+ QOpenGLFramebufferObject fbo(width, height, GL_TEXTURE_2D);
+ auto success = fbo.bind();
+ Q_ASSERT(success);
+
+ QOpenGLTextureBlitter blitter;
+ success = blitter.create();
+ Q_ASSERT(success);
+ glFun->glDisable(GL_BLEND);
+ glFun->glDisable(GL_SCISSOR_TEST);
+ blitter.bind(GL_TEXTURE_RECTANGLE_ARB);
+ blitter.blit(glTexture, {}, QOpenGLTextureBlitter::OriginBottomLeft);
+ blitter.release();
+ blitter.destroy();
+
+ glFun->glDeleteTextures(1, &glTexture);
+ glTexture = fbo.takeTexture();
+ fbo.release();
+ }
+ win->endExternalCommands();
+
+ *heldTexture = glTexture;
+ QQuickWindow::CreateTextureOptions texOpts(textureOptions);
+ return QNativeInterface::QSGOpenGLTexture::fromNative(glTexture, win, {width, height}, texOpts);
+}
+#endif // QT_CONFIG(opengl)
} // namespace
diff --git a/src/core/compositor/native_skia_output_device_mac2.mm b/src/core/compositor/native_skia_output_device_mac2.mm
deleted file mode 100644
index 87b65855c..000000000
--- a/src/core/compositor/native_skia_output_device_mac2.mm
+++ /dev/null
@@ -1,89 +0,0 @@
-// Copyright (C) 2023 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 <QtQuick/qquickwindow.h>
-#include <QtQuick/qsgrendererinterface.h>
-#include <QtQuick/qsgtexture.h>
-
-#if QT_CONFIG(opengl)
-#include <OpenGL/OpenGL.h>
-#include <QtGui/qopenglcontext.h>
-#include <QtGui/qopenglextrafunctions.h>
-#include <QtOpenGL/qopengltextureblitter.h>
-#include <QtOpenGL/qopenglframebufferobject.h>
-#endif
-
-@protocol MTLDevice;
-@protocol MTLTexture;
-
-namespace QtWebEngineCore {
-
-id<MTLDevice> getRhiDev(QQuickWindow *win)
-{
- QSGRendererInterface *ri = win->rendererInterface();
- return (__bridge id<MTLDevice>)(ri->getResource(win, QSGRendererInterface::DeviceResource));
-}
-
-QSGTexture *makeMetalTexture2(QQuickWindow *win, id<MTLTexture> mtlTexture, int width, int height, uint32_t textureOptions)
-{
- QQuickWindow::CreateTextureOptions texOpts(textureOptions);
- return QNativeInterface::QSGMetalTexture::fromNative(mtlTexture, win, {width, height}, texOpts);
-}
-
-#if QT_CONFIG(opengl)
-CGLContextObj getCGLContext(NSOpenGLContext *context);
-
-void releaseGlTexture(uint32_t glTexture)
-{
- auto *glContext = QOpenGLContext::currentContext();
- if (!glContext)
- return;
- auto glFun = glContext->functions();
- glFun->glDeleteTextures(1, &glTexture);
-}
-
-QSGTexture *makeCGLTexture(QQuickWindow *win, IOSurfaceRef io_surface, int width, int height, uint32_t textureOptions, uint32_t *heldTexture)
-{
- auto glContext = QOpenGLContext::currentContext();
- auto glFun = glContext->extraFunctions();
- auto nscontext = glContext->nativeInterface<QNativeInterface::QCocoaGLContext>()->nativeContext();
- CGLContextObj cglContext = getCGLContext(nscontext);
-
- win->beginExternalCommands();
- // Bind the IO surface to a texture
- GLuint glTexture;
- glFun->glGenTextures(1, &glTexture);
- glFun->glBindTexture(GL_TEXTURE_RECTANGLE_ARB, glTexture);
- CGLTexImageIOSurface2D(cglContext, GL_TEXTURE_RECTANGLE_ARB, GL_RGBA, width, height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, io_surface, 0);
- glFun->glBindTexture(GL_TEXTURE_RECTANGLE_ARB, 0);
- glFun->glViewport(0, 0, width, height);
-
- // The bound IO surface is a weird dynamic bind, so take a snapshot of it to a normal texture
- {
- QOpenGLFramebufferObject fbo(width, height, GL_TEXTURE_2D);
- auto success = fbo.bind();
- Q_ASSERT(success);
-
- QOpenGLTextureBlitter blitter;
- success = blitter.create();
- Q_ASSERT(success);
- glFun->glDisable(GL_BLEND);
- glFun->glDisable(GL_SCISSOR_TEST);
- blitter.bind(GL_TEXTURE_RECTANGLE_ARB);
- blitter.blit(glTexture, {}, QOpenGLTextureBlitter::OriginBottomLeft);
- blitter.release();
- blitter.destroy();
-
- glFun->glDeleteTextures(1, &glTexture);
- glTexture = fbo.takeTexture();
- fbo.release();
- }
- win->endExternalCommands();
-
- *heldTexture = glTexture;
- QQuickWindow::CreateTextureOptions texOpts(textureOptions);
- return QNativeInterface::QSGOpenGLTexture::fromNative(glTexture, win, {width, height}, texOpts);
-}
-#endif
-
-} // namespace