Backed out 2 changesets (bug 1884836) for causing mochitests failures in test_2_conformance__textures__misc__texture-corner-case-videos.html. CLOSED TREE

Backed out changeset 56bbc2a419e8 (bug 1884836)
Backed out changeset cc464f6e2cfb (bug 1884836)
This commit is contained in:
Stanca Serban 2024-03-15 01:59:29 +02:00
parent 292681f20b
commit 25baf2ac1a
24 changed files with 184 additions and 192 deletions

View File

@ -5,17 +5,11 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "MacIOSurface.h"
#ifdef XP_MACOSX
# include <OpenGL/gl.h>
# include <OpenGL/CGLIOSurface.h>
#endif
#include <OpenGL/gl.h>
#include <OpenGL/CGLIOSurface.h>
#include <QuartzCore/QuartzCore.h>
#include "GLConsts.h"
#ifdef XP_MACOSX
# include "GLContextCGL.h"
#else
# include "GLContextEAGL.h"
#endif
#include "GLContextCGL.h"
#include "gfxMacUtils.h"
#include "nsPrintfCString.h"
#include "mozilla/Assertions.h"
@ -229,7 +223,6 @@ 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
@ -241,7 +234,6 @@ 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);
@ -293,8 +285,6 @@ 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
@ -306,7 +296,6 @@ 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);
@ -493,10 +482,19 @@ ColorDepth MacIOSurface::GetColorDepth() const {
}
}
bool MacIOSurface::BindTexImage(mozilla::gl::GLContext* aGL, size_t aPlane,
mozilla::gfx::SurfaceFormat* aOutReadFormat) {
#ifdef XP_MACOSX
MOZ_ASSERT(aPlane >= 0);
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 isCompatibilityProfile = aGL->IsCompatibilityProfile();
OSType pixelFormat = GetPixelFormat();
@ -506,12 +504,12 @@ bool MacIOSurface::BindTexImage(mozilla::gl::GLContext* aGL, size_t aPlane,
if (pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarVideoRange ||
pixelFormat == kCVPixelFormatType_420YpCbCr8BiPlanarFullRange) {
MOZ_ASSERT(GetPlaneCount() == 2);
MOZ_ASSERT(aPlane < 2);
MOZ_ASSERT(plane < 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 (aPlane == 0) {
if (plane == 0) {
internalFormat = format =
(isCompatibilityProfile) ? (LOCAL_GL_LUMINANCE) : (LOCAL_GL_RED);
} else {
@ -525,12 +523,12 @@ bool MacIOSurface::BindTexImage(mozilla::gl::GLContext* aGL, size_t aPlane,
} else if (pixelFormat == kCVPixelFormatType_420YpCbCr10BiPlanarVideoRange ||
pixelFormat == kCVPixelFormatType_420YpCbCr10BiPlanarFullRange) {
MOZ_ASSERT(GetPlaneCount() == 2);
MOZ_ASSERT(aPlane < 2);
MOZ_ASSERT(plane < 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 (aPlane == 0) {
if (plane == 0) {
internalFormat = format =
(isCompatibilityProfile) ? (LOCAL_GL_LUMINANCE) : (LOCAL_GL_RED);
} else {
@ -543,7 +541,7 @@ bool MacIOSurface::BindTexImage(mozilla::gl::GLContext* aGL, size_t aPlane,
}
} else if (pixelFormat == kCVPixelFormatType_422YpCbCr8_yuvs ||
pixelFormat == kCVPixelFormatType_422YpCbCr8FullRange) {
MOZ_ASSERT(aPlane == 0);
MOZ_ASSERT(plane == 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
@ -567,7 +565,7 @@ bool MacIOSurface::BindTexImage(mozilla::gl::GLContext* aGL, size_t aPlane,
internalFormat = LOCAL_GL_RGB;
type = LOCAL_GL_UNSIGNED_SHORT_8_8_REV_APPLE;
} else {
MOZ_ASSERT(aPlane == 0);
MOZ_ASSERT(plane == 0);
internalFormat = HasAlpha() ? LOCAL_GL_RGBA : LOCAL_GL_RGB;
format = LOCAL_GL_BGRA;
@ -578,13 +576,10 @@ bool MacIOSurface::BindTexImage(mozilla::gl::GLContext* aGL, size_t aPlane,
}
}
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);
auto err =
CGLTexImageIOSurface2D(ctx, LOCAL_GL_TEXTURE_RECTANGLE_ARB,
internalFormat, GetDevicePixelWidth(plane),
GetDevicePixelHeight(plane), format, type, plane);
if (err) {
const auto formatChars = (const char*)&pixelFormat;
const char formatStr[] = {formatChars[3], formatChars[2], formatChars[1],
@ -592,15 +587,13 @@ bool MacIOSurface::BindTexImage(mozilla::gl::GLContext* aGL, size_t aPlane,
const nsPrintfCString errStr(
"CGLTexImageIOSurface2D(context, target, 0x%04x,"
" %u, %u, 0x%04x, 0x%04x, iosurfPtr, %u) -> %i",
internalFormat, uint32_t(width), uint32_t(height), format, type,
(unsigned int)aPlane, err);
internalFormat, uint32_t(GetDevicePixelWidth(plane)),
uint32_t(GetDevicePixelHeight(plane)), format, type,
(unsigned int)plane, err);
gfxCriticalError() << errStr.get() << " (iosurf format: " << formatStr
<< ")";
}
return !err;
#else
MOZ_CRASH("unimplemented");
#endif
return err;
}
void MacIOSurface::SetColorSpace(const mozilla::gfx::ColorSpace2 cs) const {

View File

@ -8,7 +8,7 @@
#define MacIOSurface_h__
#ifdef XP_DARWIN
# include <CoreVideo/CoreVideo.h>
# include <IOSurface/IOSurfaceRef.h>
# include <IOSurface/IOSurface.h>
# include <QuartzCore/QuartzCore.h>
# include <dlfcn.h>
@ -21,19 +21,20 @@ class GLContext;
}
} // namespace mozilla
# ifdef XP_MACOSX
struct _CGLContextObject;
typedef _CGLContextObject* CGLContextObj;
# endif
typedef uint32_t IOSurfaceID;
# ifdef XP_IOS
typedef kern_return_t IOReturn;
typedef int CGLError;
# endif
# ifdef XP_MACOSX
# import <OpenGL/OpenGL.h>
# else
# include "GLTypes.h"
typedef realGLboolean GLboolean;
# include <OpenGLES/ES2/gl.h>
# import <OpenGLES/ES2/gl.h>
# endif
# include "2D.h"
@ -122,15 +123,15 @@ class MacIOSurface final
return mozilla::gfx::ColorRange::LIMITED;
}
// 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);
// 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;
already_AddRefed<SourceSurface> GetAsSurface();
// Creates a DrawTarget that wraps the data in the IOSurface. Rendering to

View File

@ -69,7 +69,6 @@ if CONFIG["MOZ_WIDGET_TOOLKIT"] in ("cocoa", "uikit"):
"UnscaledFontMac.h",
]
UNIFIED_SOURCES += [
"MacIOSurface.cpp",
"NativeFontResourceMac.cpp",
"ScaledFontMac.cpp",
]
@ -189,6 +188,11 @@ 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",

View File

@ -1176,6 +1176,8 @@ bool GLBlitHelper::BlitImage(MacIOSurface* const iosurf,
MOZ_ASSERT(false);
return false;
}
const auto glCGL = static_cast<GLContextCGL*>(mGL);
const auto cglContext = glCGL->GetCGLContext();
const auto& srcOrigin = OriginPos::BottomLeft;
@ -1266,7 +1268,7 @@ bool GLBlitHelper::BlitImage(MacIOSurface* const iosurf,
mGL->fBindTexture(texTarget, texs[p]);
mGL->TexParams_SetClampNoMips(texTarget);
auto err = iosurf->BindTexImage(mGL, p);
auto err = iosurf->CGLTexImageIOSurface2D(mGL, cglContext, p);
if (err) {
return false;
}

View File

@ -10,11 +10,7 @@
#include "GLContext.h"
#include <CoreGraphics/CoreGraphics.h>
#ifdef __OBJC__
# include <OpenGLES/EAGL.h>
#else
typedef void EAGLContext;
#endif
#include <OpenGLES/EAGL.h>
namespace mozilla {
namespace gl {
@ -40,6 +36,8 @@ class GLContextEAGL : public GLContext {
return static_cast<GLContextEAGL*>(gl);
}
bool AttachToWindow(nsIWidget* aWidget);
EAGLContext* GetEAGLContext() const { return mContext; }
virtual bool MakeCurrentImpl() const override;
@ -56,9 +54,18 @@ class GLContextEAGL : public GLContext {
virtual GLuint GetDefaultFramebuffer() override { return mBackbufferFB; }
virtual bool RenewSurface(widget::CompositorWidget*) override {
// FIXME: should use the passed widget instead of the existing one.
return RecreateRB();
}
private:
GLuint mBackbufferRB = 0;
GLuint mBackbufferFB = 0;
void* mLayer = nullptr;
bool RecreateRB();
};
} // namespace gl

View File

@ -60,6 +60,10 @@ namespace gl {
# define GL_CONTEXT_PROVIDER_DEFAULT GLContextProviderLinux
#endif
#ifndef GL_CONTEXT_PROVIDER_DEFAULT
# define GL_CONTEXT_PROVIDER_DEFAULT GLContextProviderEGL
#endif
#if defined(MOZ_WIDGET_UIKIT)
# define GL_CONTEXT_PROVIDER_NAME GLContextProviderEAGL
# include "GLContextProviderImpl.h"
@ -69,10 +73,6 @@ namespace gl {
# endif
#endif
#ifndef GL_CONTEXT_PROVIDER_DEFAULT
# define GL_CONTEXT_PROVIDER_DEFAULT GLContextProviderEGL
#endif
#ifdef MOZ_GL_PROVIDER
# define GL_CONTEXT_PROVIDER_NAME MOZ_GL_PROVIDER
# include "GLContextProviderImpl.h"

View File

@ -39,12 +39,58 @@ GLContextEAGL::~GLContextEAGL() {
MarkDestroyed();
if (mLayer) {
mLayer = nil;
}
if (mContext) {
[EAGLContext setCurrentContext:nil];
[mContext release];
}
}
bool GLContextEAGL::AttachToWindow(nsIWidget* aWidget) {
// This should only be called once
MOZ_ASSERT(!mBackbufferFB && !mBackbufferRB);
UIView* view =
reinterpret_cast<UIView*>(aWidget->GetNativeData(NS_NATIVE_WIDGET));
if (!view) {
MOZ_CRASH("no view!");
}
mLayer = [view layer];
fGenFramebuffers(1, &mBackbufferFB);
return RecreateRB();
}
bool GLContextEAGL::RecreateRB() {
MakeCurrent();
CAEAGLLayer* layer = (CAEAGLLayer*)mLayer;
if (mBackbufferRB) {
// It doesn't seem to be enough to just call renderbufferStorage: below,
// we apparently have to recreate the RB.
fDeleteRenderbuffers(1, &mBackbufferRB);
mBackbufferRB = 0;
}
fGenRenderbuffers(1, &mBackbufferRB);
fBindRenderbuffer(LOCAL_GL_RENDERBUFFER, mBackbufferRB);
[mContext renderbufferStorage:LOCAL_GL_RENDERBUFFER fromDrawable:layer];
fBindFramebuffer(LOCAL_GL_FRAMEBUFFER, mBackbufferFB);
fFramebufferRenderbuffer(LOCAL_GL_FRAMEBUFFER, LOCAL_GL_COLOR_ATTACHMENT0,
LOCAL_GL_RENDERBUFFER, mBackbufferRB);
return LOCAL_GL_FRAMEBUFFER_COMPLETE ==
fCheckFramebufferStatus(LOCAL_GL_FRAMEBUFFER);
}
bool GLContextEAGL::MakeCurrentImpl() const {
if (mContext) {
GLContext::ResetTLSCurrentContext();
@ -128,20 +174,29 @@ static RefPtr<GLContext> CreateEAGLContext(const GLContextDesc& desc,
already_AddRefed<GLContext> GLContextProviderEAGL::CreateForCompositorWidget(
CompositorWidget* aCompositorWidget, bool aHardwareWebRender,
bool aForceAccelerated) {
CreateContextFlags flags = CreateContextFlags::ALLOW_OFFLINE_RENDERER;
if (aForceAccelerated) {
flags |= CreateContextFlags::FORBID_SOFTWARE;
if (!aCompositorWidget) {
MOZ_ASSERT(false);
return nullptr;
}
if (!aHardwareWebRender) {
flags |= CreateContextFlags::REQUIRE_COMPAT_PROFILE;
const GLContextDesc desc = {};
auto glContext = CreateEAGLContext(desc, GetGlobalContextEAGL());
if (!glContext) {
return nullptr;
}
nsCString failureUnused;
return CreateHeadless({flags}, &failureUnused);
if (!GLContextEAGL::Cast(glContext)->AttachToWindow(
aCompositorWidget->RealWidget())) {
return nullptr;
}
return glContext.forget();
}
already_AddRefed<GLContext> GLContextProviderEAGL::CreateHeadless(
const GLContextCreateDesc& createDesc, nsACString* const out_failureId) {
auto desc = GLContextDesc{createDesc};
desc.isOffscreen = true;
return CreateEAGLContext(desc, GetGlobalContextEAGL()).forget();
}

View File

@ -55,13 +55,6 @@ typedef signed long int GLsizeiptr;
#endif /* #if !defined(__gltypes_h_) && !defined(__gl_h_) */
#ifdef XP_IOS
# ifndef GLdouble_defined
typedef double GLdouble;
# endif
typedef double GLclampd;
#endif
#include <stdint.h>
// ARB_sync

View File

@ -28,7 +28,7 @@ SurfaceFactory_IOSurface::SurfaceFactory_IOSurface(GLContext& gl)
// -
// Surface
static bool BackTextureWithIOSurf(GLContext* const gl, const GLuint tex,
static void BackTextureWithIOSurf(GLContext* const gl, const GLuint tex,
MacIOSurface* const ioSurf) {
MOZ_ASSERT(gl->IsCurrent());
@ -43,7 +43,10 @@ static bool BackTextureWithIOSurf(GLContext* const gl, const GLuint tex,
gl->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_T,
LOCAL_GL_CLAMP_TO_EDGE);
return ioSurf->BindTexImage(gl, 0);
CGLContextObj cgl = GLContextCGL::Cast(gl)->GetCGLContext();
MOZ_ASSERT(cgl);
ioSurf->CGLTexImageIOSurface2D(gl, cgl, 0);
}
/*static*/
@ -62,9 +65,7 @@ UniquePtr<SharedSurface_IOSurface> SharedSurface_IOSurface::Create(
// -
auto tex = MakeUnique<Texture>(*desc.gl);
if (!BackTextureWithIOSurf(desc.gl, tex->name, ioSurf)) {
return nullptr;
}
BackTextureWithIOSurf(desc.gl, tex->name, ioSurf);
const GLenum target = LOCAL_GL_TEXTURE_RECTANGLE;
auto fb = MozFramebuffer::CreateForBacking(desc.gl, desc.size, 0, false,

View File

@ -12,7 +12,6 @@ elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
gl_provider = "CGL"
elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "uikit":
gl_provider = "EAGL"
DEFINES["GLES_SILENCE_DEPRECATION"] = 1
elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "gtk":
gl_provider = "Linux"
elif CONFIG["MOZ_WIDGET_TOOLKIT"] == "android":

View File

@ -34,7 +34,7 @@
#include "nsProxyRelease.h"
#include "nsISupportsUtils.h" // for NS_IF_ADDREF
#ifdef XP_DARWIN
#ifdef XP_MACOSX
# include "MacIOSurfaceImage.h"
#endif
@ -563,7 +563,7 @@ ImageContainer::GetD3D11YCbCrRecycleAllocator(
}
#endif
#ifdef XP_DARWIN
#ifdef XP_MACOSX
already_AddRefed<MacIOSurfaceRecycleAllocator>
ImageContainer::GetMacIOSurfaceRecycleAllocator() {
RecursiveMutexAutoLock lock(mRecursiveMutex);

View File

@ -63,7 +63,7 @@ class MemoryOrShmem;
class D3D11RecycleAllocator;
class D3D11YCbCrRecycleAllocator;
#endif
#ifdef XP_DARWIN
#ifdef XP_MACOSX
class MacIOSurfaceRecycleAllocator;
#endif
class SurfaceDescriptorBuffer;
@ -80,7 +80,7 @@ class GLImage;
class SharedRGBImage;
#ifdef MOZ_WIDGET_ANDROID
class SurfaceTextureImage;
#elif defined(XP_DARWIN)
#elif defined(XP_MACOSX)
class MacIOSurfaceImage;
#elif MOZ_WIDGET_GTK
class DMABUFSurfaceImage;
@ -159,7 +159,7 @@ class Image {
#ifdef MOZ_WIDGET_ANDROID
virtual SurfaceTextureImage* AsSurfaceTextureImage() { return nullptr; }
#endif
#ifdef XP_DARWIN
#ifdef XP_MACOSX
virtual MacIOSurfaceImage* AsMacIOSurfaceImage() { return nullptr; }
#endif
virtual PlanarYCbCrImage* AsPlanarYCbCrImage() { return nullptr; }
@ -530,7 +530,7 @@ class ImageContainer final : public SupportsThreadSafeWeakPtr<ImageContainer> {
KnowsCompositor* aKnowsCompositor);
#endif
#ifdef XP_DARWIN
#ifdef XP_MACOSX
already_AddRefed<MacIOSurfaceRecycleAllocator>
GetMacIOSurfaceRecycleAllocator();
#endif
@ -618,7 +618,7 @@ class ImageContainer final : public SupportsThreadSafeWeakPtr<ImageContainer> {
RefPtr<D3D11YCbCrRecycleAllocator> mD3D11YCbCrRecycleAllocator
MOZ_GUARDED_BY(mRecursiveMutex);
#endif
#ifdef XP_DARWIN
#ifdef XP_MACOSX
RefPtr<MacIOSurfaceRecycleAllocator> mMacIOSurfaceRecycleAllocator
MOZ_GUARDED_BY(mRecursiveMutex);
#endif

View File

@ -6,7 +6,7 @@
#ifndef mozilla_layers_NativeLayerCA_h
#define mozilla_layers_NativeLayerCA_h
#include <IOSurface/IOSurfaceRef.h>
#include <IOSurface/IOSurface.h>
#include <deque>
#include <unordered_map>
@ -39,9 +39,7 @@ class RenderMacIOSurfaceTextureHost;
namespace layers {
#ifdef XP_MACOSX
class NativeLayerRootSnapshotterCA;
#endif
class SurfacePoolHandleCA;
enum class VideoLowPowerType {
@ -104,10 +102,8 @@ class NativeLayerRootCA : public NativeLayerRoot {
bool CommitToScreen() override;
void CommitOffscreen();
#ifdef XP_MACOSX
void OnNativeLayerRootSnapshotterDestroyed(
NativeLayerRootSnapshotterCA* aNativeLayerRootSnapshotter);
#endif
// Enters a mode during which CommitToScreen(), when called on a non-main
// thread, will not apply any updates to the CALayer tree.
@ -164,9 +160,7 @@ class NativeLayerRootCA : public NativeLayerRoot {
Mutex mMutex MOZ_UNANNOTATED; // protects all other fields
Representation mOnscreenRepresentation;
Representation mOffscreenRepresentation;
#ifdef XP_MACOSX
NativeLayerRootSnapshotterCA* mWeakSnapshotter = nullptr;
#endif
nsTArray<RefPtr<NativeLayerCA>> mSublayers; // in z-order
float mBackingScale = 1.0f;
bool mMutated = false;
@ -194,7 +188,6 @@ class NativeLayerRootCA : public NativeLayerRoot {
class RenderSourceNLRS;
#ifdef XP_MACOSX
class NativeLayerRootSnapshotterCA final : public NativeLayerRootSnapshotter {
public:
static UniquePtr<NativeLayerRootSnapshotterCA> Create(
@ -224,7 +217,6 @@ class NativeLayerRootSnapshotterCA final : public NativeLayerRootSnapshotter {
RefPtr<RenderSourceNLRS> mSnapshot;
CARenderer* mRenderer = nullptr; // strong
};
#endif
// NativeLayerCA wraps a CALayer and lets you draw to it. It ensures that only
// fully-drawn frames make their way to the screen, by maintaining a swap chain

View File

@ -5,12 +5,10 @@
#include "mozilla/layers/NativeLayerCA.h"
#ifdef XP_MACOSX
# import <AppKit/NSAnimationContext.h>
# import <AppKit/NSColor.h>
# import <OpenGL/gl.h>
#endif
#import <AppKit/NSAnimationContext.h>
#import <AppKit/NSColor.h>
#import <AVFoundation/AVFoundation.h>
#import <OpenGL/gl.h>
#import <QuartzCore/QuartzCore.h>
#include <algorithm>
@ -21,11 +19,7 @@
#include "gfxUtils.h"
#include "GLBlitHelper.h"
#ifdef XP_MACOSX
# include "GLContextCGL.h"
#else
# include "GLContextEAGL.h"
#endif
#include "GLContextCGL.h"
#include "GLContextProvider.h"
#include "MozFramebuffer.h"
#include "mozilla/gfx/Swizzle.h"
@ -51,9 +45,7 @@ using gfx::IntSize;
using gfx::Matrix4x4;
using gfx::SurfaceFormat;
using gl::GLContext;
#ifdef XP_MACOSX
using gl::GLContextCGL;
#endif
static Maybe<Telemetry::LABELS_GFX_MACOS_VIDEO_LOW_POWER>
VideoLowPowerTypeToTelemetryType(VideoLowPowerType aVideoLowPower) {
@ -158,23 +150,13 @@ class AsyncReadbackBufferNLRS
// protection, see bug 1585523.
struct MOZ_STACK_CLASS AutoCATransaction final {
AutoCATransaction() {
#ifdef XP_MACOSX
[NSAnimationContext beginGrouping];
#else
[CATransaction begin];
#endif
// By default, mutating a CALayer property triggers an animation which
// smoothly transitions the property to the new value. We don't need these
// animations, and this call turns them off:
[CATransaction setDisableActions:YES];
}
~AutoCATransaction() {
#ifdef XP_MACOSX
[NSAnimationContext endGrouping];
#else
[CATransaction commit];
#endif
}
~AutoCATransaction() { [NSAnimationContext endGrouping]; }
};
/* static */ already_AddRefed<NativeLayerRootCA>
@ -196,9 +178,9 @@ static CALayer* MakeOffscreenRootCALayer() {
// down).
AutoCATransaction transaction;
CALayer* layer = [CALayer layer];
layer.position = CGPointZero;
layer.bounds = CGRectZero;
layer.anchorPoint = CGPointZero;
layer.position = NSZeroPoint;
layer.bounds = NSZeroRect;
layer.anchorPoint = NSZeroPoint;
layer.contentsGravity = kCAGravityTopLeft;
layer.masksToBounds = YES;
layer.geometryFlipped = YES;
@ -365,7 +347,6 @@ bool NativeLayerRootCA::CommitToScreen() {
}
UniquePtr<NativeLayerRootSnapshotter> NativeLayerRootCA::CreateSnapshotter() {
#ifdef XP_MACOSX
MutexAutoLock lock(mMutex);
MOZ_RELEASE_ASSERT(!mWeakSnapshotter,
"No NativeLayerRootSnapshotter for this NativeLayerRoot "
@ -377,19 +358,14 @@ UniquePtr<NativeLayerRootSnapshotter> NativeLayerRootCA::CreateSnapshotter() {
mWeakSnapshotter = cr.get();
}
return cr;
#else
return nullptr;
#endif
}
#ifdef XP_MACOSX
void NativeLayerRootCA::OnNativeLayerRootSnapshotterDestroyed(
NativeLayerRootSnapshotterCA* aNativeLayerRootSnapshotter) {
MutexAutoLock lock(mMutex);
MOZ_RELEASE_ASSERT(mWeakSnapshotter == aNativeLayerRootSnapshotter);
mWeakSnapshotter = nullptr;
}
#endif
void NativeLayerRootCA::CommitOffscreen() {
MutexAutoLock lock(mMutex);
@ -463,7 +439,7 @@ void NativeLayerRootCA::Representation::Commit(
mustRebuild |= layer->WillUpdateAffectLayers(aRepresentation);
layer->ApplyChanges(aRepresentation, NativeLayerCA::UpdateType::All);
CALayer* caLayer = layer->UnderlyingCALayer(aRepresentation);
if (!caLayer.masksToBounds || !CGRectIsEmpty(caLayer.bounds)) {
if (!caLayer.masksToBounds || !NSIsEmptyRect(caLayer.bounds)) {
// This layer has an extent. If it didn't before, we need to rebuild.
mustRebuild |= !layer->HasExtent();
layer->SetHasExtent(true);
@ -496,7 +472,6 @@ void NativeLayerRootCA::Representation::Commit(
mMutatedLayerStructure = false;
}
#ifdef XP_MACOSX
/* static */ UniquePtr<NativeLayerRootSnapshotterCA>
NativeLayerRootSnapshotterCA::Create(NativeLayerRootCA* aLayerRoot,
CALayer* aRootCALayer) {
@ -523,7 +498,6 @@ NativeLayerRootSnapshotterCA::Create(NativeLayerRootCA* aLayerRoot,
new NativeLayerRootSnapshotterCA(aLayerRoot, std::move(gl),
aRootCALayer));
}
#endif
void NativeLayerRootCA::DumpLayerTreeToFile(const char* aPath) {
MutexAutoLock lock(mMutex);
@ -667,7 +641,6 @@ VideoLowPowerType NativeLayerRootCA::CheckVideoLowPower(
return VideoLowPowerType::LowPower;
}
#ifdef XP_MACOSX
NativeLayerRootSnapshotterCA::NativeLayerRootSnapshotterCA(
NativeLayerRootCA* aLayerRoot, RefPtr<GLContext>&& aGL,
CALayer* aRootCALayer)
@ -806,7 +779,6 @@ NativeLayerRootSnapshotterCA::CreateAsyncReadbackBuffer(const IntSize& aSize) {
LOCAL_GL_STREAM_READ);
return MakeAndAddRef<AsyncReadbackBufferNLRS>(mGL, aSize, bufferHandle);
}
#endif
NativeLayerCA::NativeLayerCA(const IntSize& aSize, bool aIsOpaque,
SurfacePoolHandleCA* aSurfacePoolHandle)
@ -1485,10 +1457,8 @@ static NSString* NSStringForOSType(OSType type) {
CFRelease(surfaceValues);
if (aBuffer) {
#ifdef XP_MACOSX
CGColorSpaceRef colorSpace = CVImageBufferGetColorSpace(aBuffer);
NSLog(@"ColorSpace is %@.\n", colorSpace);
#endif
CFDictionaryRef bufferAttachments =
CVBufferGetAttachments(aBuffer, kCVAttachmentMode_ShouldPropagate);
@ -1542,7 +1512,7 @@ bool NativeLayerCA::Representation::EnqueueSurface(IOSurfaceRef aSurfaceRef) {
return false;
}
#if defined(NIGHTLY_BUILD) && defined(XP_MACOSX)
#ifdef NIGHTLY_BUILD
if (StaticPrefs::gfx_core_animation_specialize_video_check_color_space()) {
// Ensure the resulting pixel buffer has a color space. If it doesn't, then
// modify the surface and create the buffer again.
@ -1794,10 +1764,10 @@ bool NativeLayerCA::Representation::ApplyChanges(
mOpaquenessTintLayer.contentsGravity = kCAGravityTopLeft;
if (aIsOpaque) {
mOpaquenessTintLayer.backgroundColor =
CGColorCreateGenericRGB(0, 1, 0, 0.5);
[[[NSColor greenColor] colorWithAlphaComponent:0.5] CGColor];
} else {
mOpaquenessTintLayer.backgroundColor =
CGColorCreateGenericRGB(1, 0, 0, 0.5);
[[[NSColor redColor] colorWithAlphaComponent:0.5] CGColor];
}
[mWrappingCALayer addSublayer:mOpaquenessTintLayer];
} else if (!shouldTintOpaqueness && mOpaquenessTintLayer) {

View File

@ -31,7 +31,7 @@ class SurfacePool {
public:
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(SurfacePool);
#if defined(XP_DARWIN) || defined(MOZ_WAYLAND)
#if defined(XP_MACOSX) || defined(MOZ_WAYLAND)
static RefPtr<SurfacePool> Create(size_t aPoolSizeLimit);
#endif

View File

@ -6,7 +6,7 @@
#ifndef mozilla_layers_SurfacePoolCA_h
#define mozilla_layers_SurfacePoolCA_h
#include <IOSurface/IOSurfaceRef.h>
#include <IOSurface/IOSurface.h>
#include <deque>
#include <unordered_map>

View File

@ -6,7 +6,6 @@
#include "mozilla/layers/SurfacePoolCA.h"
#import <CoreVideo/CVPixelBuffer.h>
#include <IOSurface/IOSurfaceTypes.h>
#include <algorithm>
#include <unordered_set>
@ -17,12 +16,7 @@
#include "mozilla/StaticMutex.h"
#include "mozilla/StaticPrefs_gfx.h"
#ifdef XP_MACOSX
# include "GLContextCGL.h"
#else
# include "GLContextEAGL.h"
#endif
#include "GLContextCGL.h"
#include "MozFramebuffer.h"
#include "ScopedGLHelpers.h"
@ -34,11 +28,7 @@ using gfx::IntRect;
using gfx::IntRegion;
using gfx::IntSize;
using gl::GLContext;
#ifdef XP_MACOSX
using gl::GLContextCGL;
#else
using gl::GLContextEAGL;
#endif
/* static */ RefPtr<SurfacePool> SurfacePool::Create(size_t aPoolSizeLimit) {
return new SurfacePoolCA(aPoolSizeLimit);
@ -316,13 +306,8 @@ Maybe<GLuint> SurfacePoolCA::LockedPool::GetFramebufferForSurface(
"Framebuffer creation", GRAPHICS_TileAllocation,
nsPrintfCString("%dx%d", entry.mSize.width, entry.mSize.height));
#ifdef XP_MACOSX
RefPtr<GLContextCGL> cgl = GLContextCGL::Cast(aGL);
MOZ_RELEASE_ASSERT(cgl, "Unexpected GLContext type");
#else
RefPtr<GLContextEAGL> eagl = GLContextEAGL::Cast(aGL);
MOZ_RELEASE_ASSERT(eagl, "Unexpected GLContext type");
#endif
if (!aGL->MakeCurrent()) {
// Context may have been destroyed.
@ -333,14 +318,10 @@ Maybe<GLuint> SurfacePoolCA::LockedPool::GetFramebufferForSurface(
{
const gl::ScopedBindTexture bindTex(aGL, tex,
LOCAL_GL_TEXTURE_RECTANGLE_ARB);
#ifdef XP_MACOSX
CGLTexImageIOSurface2D(cgl->GetCGLContext(), LOCAL_GL_TEXTURE_RECTANGLE_ARB,
LOCAL_GL_RGBA, entry.mSize.width, entry.mSize.height,
LOCAL_GL_BGRA, LOCAL_GL_UNSIGNED_INT_8_8_8_8_REV,
entry.mIOSurface.get(), 0);
#else
MOZ_CRASH("unimplemented");
#endif
}
auto fb =

View File

@ -260,7 +260,7 @@ if CONFIG["MOZ_WAYLAND"]:
"SurfacePoolWayland.cpp",
]
if CONFIG["MOZ_WIDGET_TOOLKIT"] in ("cocoa", "uikit"):
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
EXPORTS.mozilla.layers += [
"NativeLayerCA.h",
"SurfacePoolCA.h",

View File

@ -31,7 +31,7 @@
# include "mozilla/webrender/RenderCompositorNative.h"
#endif
#ifdef XP_DARWIN
#ifdef XP_MACOSX
# include "mozilla/webrender/RenderCompositorNative.h"
#endif
@ -168,7 +168,7 @@ void wr_partial_present_compositor_set_buffer_damage_region(
UniquePtr<RenderCompositor> RenderCompositor::Create(
const RefPtr<widget::CompositorWidget>& aWidget, nsACString& aError) {
if (aWidget->GetCompositorOptions().UseSoftwareWebRender()) {
#ifdef XP_DARWIN
#ifdef XP_MACOSX
// Mac uses NativeLayerCA
if (!gfxPlatform::IsHeadless()) {
return RenderCompositorNativeSWGL::Create(aWidget, aError);
@ -216,7 +216,7 @@ UniquePtr<RenderCompositor> RenderCompositor::Create(
#if defined(MOZ_WIDGET_ANDROID)
// RenderCompositorOGL is not used on android
return nullptr;
#elif defined(XP_DARWIN)
#elif defined(XP_MACOSX)
// Mac uses NativeLayerCA
return RenderCompositorNativeOGL::Create(aWidget, aError);
#else

View File

@ -31,7 +31,7 @@ RenderCompositorNative::RenderCompositorNative(
mNativeLayerRoot(GetWidget()->GetNativeLayerRoot()) {
LOG("RenderCompositorNative::RenderCompositorNative()");
#if defined(XP_DARWIN) || defined(MOZ_WAYLAND)
#if defined(XP_MACOSX) || defined(MOZ_WAYLAND)
auto pool = RenderThread::Get()->SharedSurfacePool();
if (pool) {
mSurfacePoolHandle = pool->GetHandleForGL(aGL);
@ -103,7 +103,7 @@ bool RenderCompositorNative::Resume() { return true; }
inline layers::WebRenderCompositor RenderCompositorNative::CompositorType()
const {
if (gfx::gfxVars::UseWebRenderCompositor()) {
#if defined(XP_DARWIN)
#if defined(XP_MACOSX)
return layers::WebRenderCompositor::CORE_ANIMATION;
#elif defined(MOZ_WAYLAND)
return layers::WebRenderCompositor::WAYLAND;
@ -123,7 +123,7 @@ bool RenderCompositorNative::ShouldUseNativeCompositor() {
void RenderCompositorNative::GetCompositorCapabilities(
CompositorCapabilities* aCaps) {
RenderCompositor::GetCompositorCapabilities(aCaps);
#if defined(XP_DARWIN)
#if defined(XP_MACOSX)
aCaps->supports_surface_for_backdrop = !gfx::gfxVars::UseSoftwareWebRender();
#endif
}
@ -509,7 +509,7 @@ void RenderCompositorNativeOGL::DoSwap() {
void RenderCompositorNativeOGL::DoFlush() { mGL->fFlush(); }
void RenderCompositorNativeOGL::InsertFrameDoneSync() {
#ifdef XP_DARWIN
#ifdef XP_MACOSX
// Only do this on macOS.
// On other platforms, SwapBuffers automatically applies back-pressure.
if (mThisFrameDoneSync) {

View File

@ -6,20 +6,16 @@
#include "RenderMacIOSurfaceTextureHost.h"
#ifdef XP_MACOSX
# include "GLContextCGL.h"
#else
# include "GLContextEAGL.h"
#endif
#include "GLContextCGL.h"
#include "mozilla/gfx/Logging.h"
#include "ScopedGLHelpers.h"
namespace mozilla {
namespace wr {
static bool CreateTextureForPlane(uint8_t aPlaneID, gl::GLContext* aGL,
MacIOSurface* aSurface, GLuint* aTexture) {
static CGLError CreateTextureForPlane(uint8_t aPlaneID, gl::GLContext* aGL,
MacIOSurface* aSurface,
GLuint* aTexture) {
MOZ_ASSERT(aGL && aSurface && aTexture);
aGL->fGenTextures(1, aTexture);
@ -30,8 +26,10 @@ static bool CreateTextureForPlane(uint8_t aPlaneID, gl::GLContext* aGL,
aGL->fTexParameteri(LOCAL_GL_TEXTURE_RECTANGLE_ARB, LOCAL_GL_TEXTURE_WRAP_S,
LOCAL_GL_CLAMP_TO_EDGE);
CGLError result = kCGLNoError;
gfx::SurfaceFormat readFormat = gfx::SurfaceFormat::UNKNOWN;
bool result = aSurface->BindTexImage(aGL, aPlaneID, &readFormat);
result = aSurface->CGLTexImageIOSurface2D(
aGL, gl::GLContextCGL::Cast(aGL)->GetCGLContext(), aPlaneID, &readFormat);
// If this is a yuv format, the Webrender only supports YUV422 interleaving
// format.
MOZ_ASSERT(aSurface->GetFormat() != gfx::SurfaceFormat::YUV422 ||
@ -91,11 +89,7 @@ wr::WrExternalImage RenderMacIOSurfaceTextureHost::Lock(uint8_t aChannelIndex,
}
if (!mTextureHandles[0]) {
#ifdef XP_MACOSX
MOZ_ASSERT(gl::GLContextCGL::Cast(mGL.get())->GetCGLContext());
#else
MOZ_ASSERT(gl::GLContextEAGL::Cast(mGL.get())->GetEAGLContext());
#endif
// The result of GetPlaneCount() is 0 for single plane format, but it will
// be 2 if the format has 2 planar data.

View File

@ -1398,7 +1398,7 @@ RenderThread::GetProgramsForCompositorOGL() {
}
RefPtr<layers::SurfacePool> RenderThread::SharedSurfacePool() {
#if defined(XP_DARWIN) || defined(MOZ_WAYLAND)
#if defined(XP_MACOSX) || defined(MOZ_WAYLAND)
if (!mSurfacePool) {
size_t poolSizeLimit =
StaticPrefs::gfx_webrender_compositor_surface_pool_size_AtStartup();
@ -1575,7 +1575,7 @@ static already_AddRefed<gl::GLContext> CreateGLContextEGL() {
}
#endif
#ifdef XP_DARWIN
#ifdef XP_MACOSX
static already_AddRefed<gl::GLContext> CreateGLContextCGL() {
nsCString failureUnused;
return gl::GLContextProvider::CreateHeadless(
@ -1598,7 +1598,7 @@ static already_AddRefed<gl::GLContext> CreateGLContext(nsACString& aError) {
if (gfx::gfxVars::UseEGL()) {
gl = CreateGLContextEGL();
}
#elif XP_DARWIN
#elif XP_MACOSX
gl = CreateGLContextCGL();
#endif

View File

@ -51,7 +51,7 @@ UNIFIED_SOURCES += [
"WebRenderTypes.cpp",
]
if CONFIG["MOZ_WIDGET_TOOLKIT"] in ("cocoa", "uikit"):
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "cocoa":
EXPORTS.mozilla.webrender += [
"RenderCompositorNative.h",
"RenderMacIOSurfaceTextureHost.h",

View File

@ -5902,7 +5902,7 @@
value: false
mirror: always
#ifdef XP_DARWIN
#ifdef XP_MACOSX
# Create specialized video-only layers for video content in
# fullscreen windows. Consistently works well on Apple Silicon,
# some issues remain on Intel hardware.
@ -5916,7 +5916,7 @@
mirror: always
#endif
#if defined(XP_DARWIN) && defined(NIGHTLY_BUILD)
#if defined(XP_MACOSX) && defined(NIGHTLY_BUILD)
# Spoof the timing of the video sample instead of marking the untimed
# sample to be displayed immediately.
- name: gfx.core-animation.specialize-video.spoof-timing
@ -5938,7 +5938,7 @@
mirror: always
#endif
#ifdef XP_DARWIN
#ifdef XP_MACOSX
- name: gfx.core-animation.low-power-telemetry-frames
type: int32_t
value: 600
@ -6704,7 +6704,7 @@
mirror: always
#endif
#ifdef XP_DARWIN
#ifdef XP_MACOSX
# Files show up in $HOME/Desktop/nativelayerdumps-PID/frame-123.html
- name: gfx.webrender.debug.dump-native-layer-tree-to-file
type: RelaxedAtomicBool