summaryrefslogtreecommitdiffstats
path: root/gfx/2d
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:13:27 +0000
commit40a355a42d4a9444dc753c04c6608dade2f06a23 (patch)
tree871fc667d2de662f171103ce5ec067014ef85e61 /gfx/2d
parentAdding upstream version 124.0.1. (diff)
downloadfirefox-40a355a42d4a9444dc753c04c6608dade2f06a23.tar.xz
firefox-40a355a42d4a9444dc753c04c6608dade2f06a23.zip
Adding upstream version 125.0.1.upstream/125.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gfx/2d')
-rw-r--r--gfx/2d/2D.h5
-rw-r--r--gfx/2d/DrawEventRecorder.cpp4
-rw-r--r--gfx/2d/DrawEventRecorder.h4
-rw-r--r--gfx/2d/DrawTargetSkia.cpp2
-rw-r--r--gfx/2d/Factory.cpp34
-rw-r--r--gfx/2d/MacIOSurface.cpp67
-rw-r--r--gfx/2d/MacIOSurface.h31
-rw-r--r--gfx/2d/ScaledFontMac.cpp6
-rw-r--r--gfx/2d/moz.build6
9 files changed, 100 insertions, 59 deletions
diff --git a/gfx/2d/2D.h b/gfx/2d/2D.h
index 024723868b..e6b94f86ea 100644
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -1987,7 +1987,7 @@ class DrawTarget : public external::AtomicRefCounted<DrawTarget> {
SurfaceFormat mFormat;
};
-class DrawEventRecorder : public RefCounted<DrawEventRecorder> {
+class DrawEventRecorder : public external::AtomicRefCounted<DrawEventRecorder> {
public:
MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawEventRecorder)
virtual RecorderType GetRecorderType() const { return RecorderType::UNKNOWN; }
@@ -2160,6 +2160,9 @@ class GFX2D_API Factory {
SurfaceFormat aFormat, SourceSurfaceDeallocator aDeallocator = nullptr,
void* aClosure = nullptr);
+ static already_AddRefed<DataSourceSurface> CopyDataSourceSurface(
+ DataSourceSurface* aSource);
+
static void CopyDataSourceSurface(DataSourceSurface* aSource,
DataSourceSurface* aDest);
diff --git a/gfx/2d/DrawEventRecorder.cpp b/gfx/2d/DrawEventRecorder.cpp
index 967c02f8a0..51f8b836ec 100644
--- a/gfx/2d/DrawEventRecorder.cpp
+++ b/gfx/2d/DrawEventRecorder.cpp
@@ -16,9 +16,7 @@ namespace gfx {
DrawEventRecorderPrivate::DrawEventRecorderPrivate() : mExternalFonts(false) {}
-DrawEventRecorderPrivate::~DrawEventRecorderPrivate() {
- NS_ASSERT_OWNINGTHREAD(DrawEventRecorderPrivate);
-}
+DrawEventRecorderPrivate::~DrawEventRecorderPrivate() = default;
void DrawEventRecorderPrivate::SetDrawTarget(ReferencePtr aDT) {
NS_ASSERT_OWNINGTHREAD(DrawEventRecorderPrivate);
diff --git a/gfx/2d/DrawEventRecorder.h b/gfx/2d/DrawEventRecorder.h
index 13380b014a..d62f098784 100644
--- a/gfx/2d/DrawEventRecorder.h
+++ b/gfx/2d/DrawEventRecorder.h
@@ -41,7 +41,7 @@ class DrawEventRecorderPrivate : public DrawEventRecorder {
return true;
}
virtual void FlushItem(IntRect) {}
- void DetachResources() {
+ virtual void DetachResources() {
NS_ASSERT_OWNINGTHREAD(DrawEventRecorderPrivate);
nsTHashSet<ScaledFont*> fonts = std::move(mStoredFonts);
@@ -116,7 +116,7 @@ class DrawEventRecorderPrivate : public DrawEventRecorder {
return mStoredObjects.EnsureInserted(aObject);
}
- void AddPendingDeletion(std::function<void()>&& aPendingDeletion) {
+ virtual void AddPendingDeletion(std::function<void()>&& aPendingDeletion) {
auto lockedPendingDeletions = mPendingDeletions.Lock();
lockedPendingDeletions->emplace_back(std::move(aPendingDeletion));
}
diff --git a/gfx/2d/DrawTargetSkia.cpp b/gfx/2d/DrawTargetSkia.cpp
index 098ff81117..508dac3f62 100644
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -1398,7 +1398,7 @@ void DrawTargetSkia::Mask(const Pattern& aSource, const Pattern& aMask,
SkPaint maskPaint;
SetPaintPattern(maskPaint, aMask, lock);
- sk_sp<SkShader> maskShader(maskPaint.getShader());
+ sk_sp<SkShader> maskShader(maskPaint.refShader());
if (!maskShader && maskPaint.getAlpha() != 0xFF) {
if (maskPaint.getAlpha() == 0) {
return;
diff --git a/gfx/2d/Factory.cpp b/gfx/2d/Factory.cpp
index abf7a8669b..1bdf597142 100644
--- a/gfx/2d/Factory.cpp
+++ b/gfx/2d/Factory.cpp
@@ -1106,6 +1106,40 @@ already_AddRefed<DataSourceSurface> Factory::CreateDataSourceSurfaceWithStride(
return nullptr;
}
+already_AddRefed<DataSourceSurface> Factory::CopyDataSourceSurface(
+ DataSourceSurface* aSource) {
+ // Don't worry too much about speed.
+ MOZ_ASSERT(aSource->GetFormat() == SurfaceFormat::R8G8B8A8 ||
+ aSource->GetFormat() == SurfaceFormat::R8G8B8X8 ||
+ aSource->GetFormat() == SurfaceFormat::B8G8R8A8 ||
+ aSource->GetFormat() == SurfaceFormat::B8G8R8X8);
+
+ DataSourceSurface::ScopedMap srcMap(aSource, DataSourceSurface::READ);
+ if (NS_WARN_IF(!srcMap.IsMapped())) {
+ MOZ_ASSERT_UNREACHABLE("CopyDataSourceSurface: Failed to map surface.");
+ return nullptr;
+ }
+
+ IntSize size = aSource->GetSize();
+ SurfaceFormat format = aSource->GetFormat();
+
+ RefPtr<DataSourceSurface> dst = CreateDataSourceSurfaceWithStride(
+ size, format, srcMap.GetStride(), /* aZero */ false);
+ if (NS_WARN_IF(!dst)) {
+ return nullptr;
+ }
+
+ DataSourceSurface::ScopedMap dstMap(dst, DataSourceSurface::WRITE);
+ if (NS_WARN_IF(!dstMap.IsMapped())) {
+ MOZ_ASSERT_UNREACHABLE("CopyDataSourceSurface: Failed to map surface.");
+ return nullptr;
+ }
+
+ SwizzleData(srcMap.GetData(), srcMap.GetStride(), format, dstMap.GetData(),
+ dstMap.GetStride(), format, size);
+ return dst.forget();
+}
+
void Factory::CopyDataSourceSurface(DataSourceSurface* aSource,
DataSourceSurface* aDest) {
// Don't worry too much about speed.
diff --git a/gfx/2d/MacIOSurface.cpp b/gfx/2d/MacIOSurface.cpp
index 8c1c24bc10..1701731d61 100644
--- a/gfx/2d/MacIOSurface.cpp
+++ b/gfx/2d/MacIOSurface.cpp
@@ -5,11 +5,17 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "MacIOSurface.h"
-#include <OpenGL/gl.h>
-#include <OpenGL/CGLIOSurface.h>
+#ifdef XP_MACOSX
+# include <OpenGL/gl.h>
+# include <OpenGL/CGLIOSurface.h>
+#endif
#include <QuartzCore/QuartzCore.h>
#include "GLConsts.h"
-#include "GLContextCGL.h"
+#ifdef XP_MACOSX
+# include "GLContextCGL.h"
+#else
+# include "GLContextEAGL.h"
+#endif
#include "gfxMacUtils.h"
#include "nsPrintfCString.h"
#include "mozilla/Assertions.h"
@@ -223,6 +229,7 @@ already_AddRefed<MacIOSurface> MacIOSurface::CreateNV12OrP010Surface(
surfaceRef.get(), CFSTR("IOSurfaceTransferFunction"),
gfxMacUtils::CFStringForTransferFunction(aTransferFunction));
+#ifdef XP_MACOSX
// Override the color space to be the same as the main display, so that
// CoreAnimation won't try to do any color correction (from the IOSurface
// space, to the display). In the future we may want to try specifying this
@@ -234,6 +241,7 @@ already_AddRefed<MacIOSurface> MacIOSurface::CreateNV12OrP010Surface(
CGColorSpaceCopyICCData(colorSpace.get()));
IOSurfaceSetValue(surfaceRef.get(), CFSTR("IOSurfaceColorSpace"),
colorData.get());
+#endif
RefPtr<MacIOSurface> ioSurface =
new MacIOSurface(std::move(surfaceRef), false, aColorSpace);
@@ -285,6 +293,8 @@ already_AddRefed<MacIOSurface> MacIOSurface::CreateYUV422Surface(
IOSurfaceSetValue(surfaceRef.get(), CFSTR("IOSurfaceYCbCrMatrix"),
CFSTR("ITU_R_709_2"));
}
+
+#ifdef XP_MACOSX
// Override the color space to be the same as the main display, so that
// CoreAnimation won't try to do any color correction (from the IOSurface
// space, to the display). In the future we may want to try specifying this
@@ -296,6 +306,7 @@ already_AddRefed<MacIOSurface> MacIOSurface::CreateYUV422Surface(
CGColorSpaceCopyICCData(colorSpace.get()));
IOSurfaceSetValue(surfaceRef.get(), CFSTR("IOSurfaceColorSpace"),
colorData.get());
+#endif
RefPtr<MacIOSurface> ioSurface =
new MacIOSurface(std::move(surfaceRef), false, aColorSpace);
@@ -482,19 +493,10 @@ ColorDepth MacIOSurface::GetColorDepth() const {
}
}
-CGLError MacIOSurface::CGLTexImageIOSurface2D(CGLContextObj ctx, GLenum target,
- GLenum internalFormat,
- GLsizei width, GLsizei height,
- GLenum format, GLenum type,
- GLuint plane) const {
- return ::CGLTexImageIOSurface2D(ctx, target, internalFormat, width, height,
- format, type, mIOSurfaceRef.get(), plane);
-}
-
-CGLError MacIOSurface::CGLTexImageIOSurface2D(
- mozilla::gl::GLContext* aGL, CGLContextObj ctx, size_t plane,
- mozilla::gfx::SurfaceFormat* aOutReadFormat) {
- MOZ_ASSERT(plane >= 0);
+bool MacIOSurface::BindTexImage(mozilla::gl::GLContext* aGL, size_t aPlane,
+ mozilla::gfx::SurfaceFormat* aOutReadFormat) {
+#ifdef XP_MACOSX
+ MOZ_ASSERT(aPlane >= 0);
bool isCompatibilityProfile = aGL->IsCompatibilityProfile();
OSType pixelFormat = GetPixelFormat();
@@ -504,12 +506,12 @@ CGLError MacIOSurface::CGLTexImageIOSurface2D(
if (pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange ||
pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) {
MOZ_ASSERT(GetPlaneCount() == 2);
- MOZ_ASSERT(plane < 2);
+ MOZ_ASSERT(aPlane < 2);
// The LOCAL_GL_LUMINANCE and LOCAL_GL_LUMINANCE_ALPHA are the deprecated
// format. So, use LOCAL_GL_RED and LOCAL_GL_RB if we use core profile.
// https://www.khronos.org/opengl/wiki/Image_Format#Legacy_Image_Formats
- if (plane == 0) {
+ if (aPlane == 0) {
internalFormat = format =
(isCompatibilityProfile) ? (LOCAL_GL_LUMINANCE) : (LOCAL_GL_RED);
} else {
@@ -523,12 +525,12 @@ CGLError MacIOSurface::CGLTexImageIOSurface2D(
} else if (pixelFormat == kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange ||
pixelFormat == kCVPixelFormatType_420YpCbCr10BiPlanarFullRange) {
MOZ_ASSERT(GetPlaneCount() == 2);
- MOZ_ASSERT(plane < 2);
+ MOZ_ASSERT(aPlane < 2);
// The LOCAL_GL_LUMINANCE and LOCAL_GL_LUMINANCE_ALPHA are the deprecated
// format. So, use LOCAL_GL_RED and LOCAL_GL_RB if we use core profile.
// https://www.khronos.org/opengl/wiki/Image_Format#Legacy_Image_Formats
- if (plane == 0) {
+ if (aPlane == 0) {
internalFormat = format =
(isCompatibilityProfile) ? (LOCAL_GL_LUMINANCE) : (LOCAL_GL_RED);
} else {
@@ -541,7 +543,7 @@ CGLError MacIOSurface::CGLTexImageIOSurface2D(
}
} else if (pixelFormat == kCVPixelFormatType_422YpCbCr8_yuvs ||
pixelFormat == kCVPixelFormatType_422YpCbCr8FullRange) {
- MOZ_ASSERT(plane == 0);
+ MOZ_ASSERT(aPlane == 0);
// The YCBCR_422_APPLE ext is only available in compatibility profile. So,
// we should use RGB_422_APPLE for core profile. The difference between
// YCBCR_422_APPLE and RGB_422_APPLE is that the YCBCR_422_APPLE converts
@@ -565,7 +567,7 @@ CGLError MacIOSurface::CGLTexImageIOSurface2D(
internalFormat = LOCAL_GL_RGB;
type = LOCAL_GL_UNSIGNED_SHORT_8_8_REV_APPLE;
} else {
- MOZ_ASSERT(plane == 0);
+ MOZ_ASSERT(aPlane == 0);
internalFormat = HasAlpha() ? LOCAL_GL_RGBA : LOCAL_GL_RGB;
format = LOCAL_GL_BGRA;
@@ -576,10 +578,13 @@ CGLError MacIOSurface::CGLTexImageIOSurface2D(
}
}
- auto err =
- CGLTexImageIOSurface2D(ctx, LOCAL_GL_TEXTURE_RECTANGLE_ARB,
- internalFormat, GetDevicePixelWidth(plane),
- GetDevicePixelHeight(plane), format, type, plane);
+ size_t width = GetDevicePixelWidth(aPlane);
+ size_t height = GetDevicePixelHeight(aPlane);
+
+ auto err = ::CGLTexImageIOSurface2D(
+ gl::GLContextCGL::Cast(aGL)->GetCGLContext(),
+ LOCAL_GL_TEXTURE_RECTANGLE_ARB, internalFormat, width, height, format,
+ type, mIOSurfaceRef.get(), aPlane);
if (err) {
const auto formatChars = (const char*)&pixelFormat;
const char formatStr[] = {formatChars[3], formatChars[2], formatChars[1],
@@ -587,13 +592,15 @@ CGLError MacIOSurface::CGLTexImageIOSurface2D(
const nsPrintfCString errStr(
"CGLTexImageIOSurface2D(context, target, 0x%04x,"
" %u, %u, 0x%04x, 0x%04x, iosurfPtr, %u) -> %i",
- internalFormat, uint32_t(GetDevicePixelWidth(plane)),
- uint32_t(GetDevicePixelHeight(plane)), format, type,
- (unsigned int)plane, err);
+ internalFormat, uint32_t(width), uint32_t(height), format, type,
+ (unsigned int)aPlane, err);
gfxCriticalError() << errStr.get() << " (iosurf format: " << formatStr
<< ")";
}
- return err;
+ return !err;
+#else
+ MOZ_CRASH("unimplemented");
+#endif
}
void MacIOSurface::SetColorSpace(const mozilla::gfx::ColorSpace2 cs) const {
diff --git a/gfx/2d/MacIOSurface.h b/gfx/2d/MacIOSurface.h
index ef176430d1..d0ee3baeef 100644
--- a/gfx/2d/MacIOSurface.h
+++ b/gfx/2d/MacIOSurface.h
@@ -8,7 +8,7 @@
#define MacIOSurface_h__
#ifdef XP_DARWIN
# include <CoreVideo/CoreVideo.h>
-# include <IOSurface/IOSurface.h>
+# include <IOSurface/IOSurfaceRef.h>
# include <QuartzCore/QuartzCore.h>
# include <dlfcn.h>
@@ -21,20 +21,19 @@ class GLContext;
}
} // namespace mozilla
+# ifdef XP_MACOSX
struct _CGLContextObject;
typedef _CGLContextObject* CGLContextObj;
-typedef uint32_t IOSurfaceID;
-
-# ifdef XP_IOS
-typedef kern_return_t IOReturn;
-typedef int CGLError;
# endif
+typedef uint32_t IOSurfaceID;
# ifdef XP_MACOSX
# import <OpenGL/OpenGL.h>
# else
-# import <OpenGLES/ES2/gl.h>
+# include "GLTypes.h"
+typedef realGLboolean GLboolean;
+# include <OpenGLES/ES2/gl.h>
# endif
# include "2D.h"
@@ -123,15 +122,15 @@ class MacIOSurface final
return mozilla::gfx::ColorRange::LIMITED;
}
- // We would like to forward declare NSOpenGLContext, but it is an @interface
- // and this file is also used from c++, so we use a void *.
- CGLError CGLTexImageIOSurface2D(
- mozilla::gl::GLContext* aGL, CGLContextObj ctxt, size_t plane,
- mozilla::gfx::SurfaceFormat* aOutReadFormat = nullptr);
- CGLError CGLTexImageIOSurface2D(CGLContextObj ctxt, GLenum target,
- GLenum internalFormat, GLsizei width,
- GLsizei height, GLenum format, GLenum type,
- GLuint plane) const;
+ // Bind this IOSurface to a texture using the most efficient mechanism
+ // available on the current platform.
+ //
+ // Note that on iOS simulator, due to incomplete support for
+ // texImageIOSurface, this will only use texImage2D to upload, and cannot be
+ // used to read-back the GL texture to an IOSurface.
+ bool BindTexImage(mozilla::gl::GLContext* aGL, size_t aPlane,
+ mozilla::gfx::SurfaceFormat* aOutReadFormat = nullptr);
+
already_AddRefed<SourceSurface> GetAsSurface();
// Creates a DrawTarget that wraps the data in the IOSurface. Rendering to
diff --git a/gfx/2d/ScaledFontMac.cpp b/gfx/2d/ScaledFontMac.cpp
index 9528b3527e..7ac1cfc9c9 100644
--- a/gfx/2d/ScaledFontMac.cpp
+++ b/gfx/2d/ScaledFontMac.cpp
@@ -7,7 +7,9 @@
#include "ScaledFontMac.h"
#include "UnscaledFontMac.h"
#include "mozilla/webrender/WebRenderTypes.h"
-#include "nsCocoaFeatures.h"
+#ifdef MOZ_WIDGET_COCOA
+# include "nsCocoaFeatures.h"
+#endif
#include "PathSkia.h"
#include "skia/include/core/SkPaint.h"
#include "skia/include/core/SkPath.h"
@@ -73,6 +75,7 @@ class AutoRelease final {
CTFontRef CreateCTFontFromCGFontWithVariations(CGFontRef aCGFont, CGFloat aSize,
bool aInstalledFont,
CTFontDescriptorRef aFontDesc) {
+#ifdef MOZ_WIDGET_COCOA
// New implementation (see bug 1856035) for macOS 13+.
if (nsCocoaFeatures::OnVenturaOrLater()) {
// Create CTFont, applying any descriptor that was passed (used by
@@ -96,6 +99,7 @@ CTFontRef CreateCTFontFromCGFontWithVariations(CGFontRef aCGFont, CGFloat aSize,
// No variations to set, just return the default CTFont.
return ctFont.forget();
}
+#endif
// Older implementation used up to macOS 12.
CTFontRef ctFont;
diff --git a/gfx/2d/moz.build b/gfx/2d/moz.build
index c04530c72b..d1408b9dc9 100644
--- a/gfx/2d/moz.build
+++ b/gfx/2d/moz.build
@@ -69,6 +69,7 @@ if CONFIG["MOZ_WIDGET_TOOLKIT"] in ("cocoa", "uikit"):
"UnscaledFontMac.h",
]
UNIFIED_SOURCES += [
+ "MacIOSurface.cpp",
"NativeFontResourceMac.cpp",
"ScaledFontMac.cpp",
]
@@ -188,11 +189,6 @@ SOURCES += [
"InlineTranslator.cpp",
]
-if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
- SOURCES += [
- "MacIOSurface.cpp",
- ]
-
if CONFIG["TARGET_CPU"] == "aarch64" or CONFIG["BUILD_ARM_NEON"]:
SOURCES += [
"BlurNEON.cpp",