From 1a36e4013212e7e42d075eced7d0cb8162d798e1 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Sun, 28 Jun 2020 23:40:14 -0700 Subject: [PATCH 01/12] define EGL_EXT_gl_colorspace_bt2020_* --- src/libANGLE/Caps.cpp | 2 ++ src/libANGLE/Caps.h | 6 ++++++ src/libANGLE/renderer/gl/egl/DisplayEGL.cpp | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/libANGLE/Caps.cpp b/src/libANGLE/Caps.cpp index 5d66178d11..07d8c48d7b 100644 --- a/src/libANGLE/Caps.cpp +++ b/src/libANGLE/Caps.cpp @@ -1222,6 +1222,8 @@ std::vector DisplayExtensions::getStrings() const InsertExtensionString("EGL_EXT_gl_colorspace_display_p3", glColorspaceDisplayP3, &extensionStrings); InsertExtensionString("EGL_EXT_gl_colorspace_display_p3_linear", glColorspaceDisplayP3Linear, &extensionStrings); InsertExtensionString("EGL_EXT_gl_colorspace_display_p3_passthrough", glColorspaceDisplayP3Passthrough, &extensionStrings); + InsertExtensionString("EGL_EXT_gl_colorspace_bt2020_linear", glColorspaceBT2020, &extensionStrings); + InsertExtensionString("EGL_EXT_gl_colorspace_bt2020_pq", glColorspaceBT2020PQ, &extensionStrings); InsertExtensionString("EGL_KHR_gl_texture_2D_image", glTexture2DImage, &extensionStrings); InsertExtensionString("EGL_KHR_gl_texture_cubemap_image", glTextureCubemapImage, &extensionStrings); InsertExtensionString("EGL_KHR_gl_texture_3D_image", glTexture3DImage, &extensionStrings); diff --git a/src/libANGLE/Caps.h b/src/libANGLE/Caps.h index 7b2767ca8c..90de648af9 100644 --- a/src/libANGLE/Caps.h +++ b/src/libANGLE/Caps.h @@ -961,6 +961,12 @@ struct DisplayExtensions // EGL_EXT_gl_colorspace_display_p3_passthrough bool glColorspaceDisplayP3Passthrough = false; + + // EGL_EXT_gl_colorspace_bt2020_linear + bool glColorspaceBT2020 = false; + + // EGL_EXT_gl_colorspace_bt2020_pq + bool glColorspaceBT2020PQ = false; }; struct DeviceExtensions diff --git a/src/libANGLE/renderer/gl/egl/DisplayEGL.cpp b/src/libANGLE/renderer/gl/egl/DisplayEGL.cpp index 1ac24cf893..ed68bdf540 100644 --- a/src/libANGLE/renderer/gl/egl/DisplayEGL.cpp +++ b/src/libANGLE/renderer/gl/egl/DisplayEGL.cpp @@ -149,6 +149,10 @@ void DisplayEGL::generateExtensions(egl::DisplayExtensions *outExtensions) const mEGL->hasExtension("EGL_EXT_gl_colorspace_scrgb_linear"); outExtensions->glColorspaceDisplayP3Passthrough = mEGL->hasExtension("EGL_EXT_gl_colorspace_display_p3_passthrough"); + outExtensions->glColorspaceBT2020 = + mEGL->hasExtension("EGL_EXT_gl_colorspace_bt2020_linear"); + outExtensions->glColorspaceBT2020PQ = + mEGL->hasExtension("EGL_EXT_gl_colorspace_bt2020_pq"); } outExtensions->imageNativeBuffer = mEGL->hasExtension("EGL_ANDROID_image_native_buffer"); From 684d67b6210cdaf85eff77b78380576fdafcd615 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Sun, 28 Jun 2020 23:41:07 -0700 Subject: [PATCH 02/12] implement EGL_GL_COLORSPACE_BT2020_PQ_EXT for Metal --- src/libANGLE/renderer/metal/DisplayMtl.mm | 1 + src/libANGLE/renderer/metal/SurfaceMtl.mm | 8 ++++++++ src/libANGLE/renderer/metal/mtl_format_utils.h | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/libANGLE/renderer/metal/DisplayMtl.mm b/src/libANGLE/renderer/metal/DisplayMtl.mm index eb82c75897..0b400c31dc 100644 --- a/src/libANGLE/renderer/metal/DisplayMtl.mm +++ b/src/libANGLE/renderer/metal/DisplayMtl.mm @@ -238,6 +238,7 @@ bool IsMetalDisplayAvailable() outExtensions->fenceSync = true; outExtensions->waitSync = true; outExtensions->glColorspace = true; + outExtensions->glColorspaceBT2020PQ = true; } void DisplayMtl::generateCaps(egl::Caps *outCaps) const {} diff --git a/src/libANGLE/renderer/metal/SurfaceMtl.mm b/src/libANGLE/renderer/metal/SurfaceMtl.mm index d69f872292..9dac69c0b3 100644 --- a/src/libANGLE/renderer/metal/SurfaceMtl.mm +++ b/src/libANGLE/renderer/metal/SurfaceMtl.mm @@ -206,6 +206,13 @@ void StopFrameCapture() { mColorFormat = display->getPixelFormat(angle::FormatID::B8G8R8A8_UNORM_SRGB); } + else if (attribs.get(EGL_GL_COLORSPACE, EGL_GL_COLORSPACE_LINEAR) == EGL_GL_COLORSPACE_BT2020_PQ_EXT) + { + mColorFormat.intendedFormatId = mColorFormat.actualFormatId = + angle::FormatID::R16G16B16A16_FLOAT; + mColorFormat.metalFormat = MTLPixelFormatRGBA16Float; + mColorFormat.metalColorspace = CGColorSpaceCreateWithName(kCGColorSpaceITUR_2020_PQ); + } else { // https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf says that BGRA8Unorm is @@ -302,6 +309,7 @@ void StopFrameCapture() mMetalLayer.get().device = metalDevice; mMetalLayer.get().pixelFormat = mColorFormat.metalFormat; + mMetalLayer.get().colorspace = mColorFormat.metalColorspace; mMetalLayer.get().framebufferOnly = NO; // Support blitting and glReadPixels #if TARGET_OS_OSX || TARGET_OS_MACCATALYST diff --git a/src/libANGLE/renderer/metal/mtl_format_utils.h b/src/libANGLE/renderer/metal/mtl_format_utils.h index e1cf271f35..f042a39f11 100644 --- a/src/libANGLE/renderer/metal/mtl_format_utils.h +++ b/src/libANGLE/renderer/metal/mtl_format_utils.h @@ -12,6 +12,7 @@ #define LIBANGLE_RENDERER_METAL_MTL_FORMAT_UTILS_H_ #import +#import #include @@ -81,6 +82,7 @@ struct Format : public FormatBase bool needConversion(angle::FormatID srcFormatId) const; MTLPixelFormat metalFormat = MTLPixelFormatInvalid; + CGColorSpaceRef metalColorspace = nil; LoadFunctionMap textureLoadFunctions = nullptr; InitializeTextureDataFunction initFunction = nullptr; From f0fe6f874dd5aa67e4871fbee60933c657d06685 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Mon, 29 Jun 2020 00:06:19 -0700 Subject: [PATCH 03/12] expose MGLDrawableColorFormatRGBA16 and MGLDrawableColorSpaceBT2020PQ --- ios/xcode/MGLKit/MGLLayer.h | 10 ++++++++++ ios/xcode/MGLKit/MGLLayer.mm | 13 +++++++++++++ 2 files changed, 23 insertions(+) diff --git a/ios/xcode/MGLKit/MGLLayer.h b/ios/xcode/MGLKit/MGLLayer.h index e8da23244b..1c857a58a9 100644 --- a/ios/xcode/MGLKit/MGLLayer.h +++ b/ios/xcode/MGLKit/MGLLayer.h @@ -23,6 +23,7 @@ typedef enum MGLDrawableColorFormat : int MGLDrawableColorFormatRGBA8888 = 32, MGLDrawableColorFormatSRGBA8888 = -32, MGLDrawableColorFormatRGB565 = 16, + MGLDrawableColorFormatRGBA16 = 64, } MGLDrawableColorFormat; typedef enum MGLDrawableStencilFormat : int @@ -44,6 +45,14 @@ typedef enum MGLDrawableMultisample : int MGLDrawableMultisample4X = 4, } MGLDrawableMultisample; +typedef enum MGLDrawableColorSpace : int +{ + MGLDrawableColorSpaceUnspecified = 0, + MGLDrawableColorSpaceLinear = 1, + MGLDrawableColorSpaceSRGB = 2, + MGLDrawableColorSpaceBT2020PQ = 2020, +} MGLDrawableColorSpace; + @interface MGLLayer : CALayer // Return the size of the OpenGL framebuffer. @@ -57,6 +66,7 @@ typedef enum MGLDrawableMultisample : int @property(nonatomic) MGLDrawableStencilFormat drawableStencilFormat; // Default is StencilNone @property(nonatomic) MGLDrawableMultisample drawableMultisample; // Default is MGLDrawableMultisampleNone +@property(nonatomic) MGLDrawableColorSpace drawableColorSpace; // Default is ColorSpaceUnspecified // Default value is NO. Setting to YES will keep the framebuffer data after presenting. // Doing so will reduce performance and increase memory usage. diff --git a/ios/xcode/MGLKit/MGLLayer.mm b/ios/xcode/MGLKit/MGLLayer.mm index 47ffa4f8f2..edb08fc1fa 100644 --- a/ios/xcode/MGLKit/MGLLayer.mm +++ b/ios/xcode/MGLKit/MGLLayer.mm @@ -347,6 +347,7 @@ - (void)constructor _drawableDepthFormat = MGLDrawableDepthFormatNone; _drawableStencilFormat = MGLDrawableStencilFormatNone; _drawableMultisample = MGLDrawableMultisampleNone; + _drawableColorSpace = MGLDrawableColorSpaceUnspecified; _display = [MGLDisplay defaultDisplay]; @@ -710,6 +711,18 @@ - (void)ensureSurfaceCreated red = green = blue = alpha = 8; colorSpace = EGL_GL_COLORSPACE_SRGB_KHR; break; + case MGLDrawableColorFormatRGBA16: + red = green = blue = alpha = 16; + switch (_drawableColorSpace) + { + case MGLDrawableColorSpaceBT2020PQ: + colorSpace = EGL_GL_COLORSPACE_BT2020_PQ_EXT; + break; + default: + colorSpace = EGL_GL_COLORSPACE_LINEAR_KHR; + break; + } + break; default: UNREACHABLE(); break; From c5334b4edfb17ed6c700cb5daa66cb7ce3296ccf Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Mon, 29 Jun 2020 00:09:45 -0700 Subject: [PATCH 04/12] add to MGLKView also --- ios/xcode/MGLKit/MGLKView.h | 1 + ios/xcode/MGLKit/MGLKView.mm | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/ios/xcode/MGLKit/MGLKView.h b/ios/xcode/MGLKit/MGLKView.h index e7203a5b27..39426f7744 100644 --- a/ios/xcode/MGLKit/MGLKView.h +++ b/ios/xcode/MGLKit/MGLKView.h @@ -34,6 +34,7 @@ @property(nonatomic) MGLDrawableStencilFormat drawableStencilFormat; // Default is StencilNone @property(nonatomic) MGLDrawableMultisample drawableMultisample; // Default is MGLDrawableMultisampleNone +@property(nonatomic) MGLDrawableColorSpace drawableColorSpace; // Default is ColorSpaceUnspecified // Return the size of the OpenGL default framebuffer. @property(readonly) CGSize drawableSize; diff --git a/ios/xcode/MGLKit/MGLKView.mm b/ios/xcode/MGLKit/MGLKView.mm index 21f771045a..8d1b7a8cc7 100644 --- a/ios/xcode/MGLKit/MGLKView.mm +++ b/ios/xcode/MGLKit/MGLKView.mm @@ -105,6 +105,11 @@ - (void)setDrawableMultisample:(MGLDrawableMultisample)drawableMultisample self.glLayer.drawableMultisample = _drawableMultisample = drawableMultisample; } +- (void)setDrawableColorSpace:(MGLDrawableColorSpace)drawableColorSpace +{ + self.glLayer.drawableColorSpace = _drawableColorSpace = drawableColorSpace; +} + - (void)display { [self drawRect:self.bounds]; From f5d8be7ce2ebd0218bc310e0bfe4b9f6ee7e648d Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Mon, 29 Jun 2020 16:57:35 -0700 Subject: [PATCH 05/12] switch back to 8bit window format --- ios/xcode/MGLKit/MGLLayer.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/xcode/MGLKit/MGLLayer.mm b/ios/xcode/MGLKit/MGLLayer.mm index edb08fc1fa..fc0d23f007 100644 --- a/ios/xcode/MGLKit/MGLLayer.mm +++ b/ios/xcode/MGLKit/MGLLayer.mm @@ -712,7 +712,7 @@ - (void)ensureSurfaceCreated colorSpace = EGL_GL_COLORSPACE_SRGB_KHR; break; case MGLDrawableColorFormatRGBA16: - red = green = blue = alpha = 16; + red = green = blue = alpha = 8; switch (_drawableColorSpace) { case MGLDrawableColorSpaceBT2020PQ: From 4f44fe127f803a2aa7987b1735024fb5492227f1 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Mon, 29 Jun 2020 16:57:44 -0700 Subject: [PATCH 06/12] add missing validation checks for EGL_GL_COLORSPACE_BT2020_PQ_EXT --- src/libANGLE/formatutils.h | 1 + src/libANGLE/validationEGL.cpp | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/libANGLE/formatutils.h b/src/libANGLE/formatutils.h index d25baaa88f..893343c262 100644 --- a/src/libANGLE/formatutils.h +++ b/src/libANGLE/formatutils.h @@ -84,6 +84,7 @@ ANGLE_INLINE bool ColorspaceFormatOverride(const EGLenum colorspace, GLenum *ren case EGL_GL_COLORSPACE_DISPLAY_P3_PASSTHROUGH_EXT: // App, not the HW, will specify the // transfer function case EGL_GL_COLORSPACE_SCRGB_EXT: // App, not the HW, will specify the transfer function + case EGL_GL_COLORSPACE_BT2020_PQ_EXT: // No translation return true; case EGL_GL_COLORSPACE_SRGB_KHR: diff --git a/src/libANGLE/validationEGL.cpp b/src/libANGLE/validationEGL.cpp index 05fb08da81..80330ad05e 100644 --- a/src/libANGLE/validationEGL.cpp +++ b/src/libANGLE/validationEGL.cpp @@ -353,6 +353,12 @@ Error ValidateColorspaceAttribute(const DisplayExtensions &displayExtensions, EG return EglBadAttribute() << "EXT_gl_colorspace_scrgb_linear is not available."; } break; + case EGL_GL_COLORSPACE_BT2020_PQ_EXT: + if (!displayExtensions.glColorspaceBT2020PQ) + { + return EglBadAttribute() << "EXT_gl_colorspace_bt2020_pq is not available."; + } + break; default: return EglBadAttribute(); } From c9b9642d67b108501e228236b414941730f87d2e Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Mon, 29 Jun 2020 18:39:37 -0700 Subject: [PATCH 07/12] remove MGLDrawableColorSpace --- ios/xcode/MGLKit/MGLKView.h | 1 - ios/xcode/MGLKit/MGLKView.mm | 5 ----- ios/xcode/MGLKit/MGLLayer.h | 9 --------- ios/xcode/MGLKit/MGLLayer.mm | 10 ---------- 4 files changed, 25 deletions(-) diff --git a/ios/xcode/MGLKit/MGLKView.h b/ios/xcode/MGLKit/MGLKView.h index 39426f7744..e7203a5b27 100644 --- a/ios/xcode/MGLKit/MGLKView.h +++ b/ios/xcode/MGLKit/MGLKView.h @@ -34,7 +34,6 @@ @property(nonatomic) MGLDrawableStencilFormat drawableStencilFormat; // Default is StencilNone @property(nonatomic) MGLDrawableMultisample drawableMultisample; // Default is MGLDrawableMultisampleNone -@property(nonatomic) MGLDrawableColorSpace drawableColorSpace; // Default is ColorSpaceUnspecified // Return the size of the OpenGL default framebuffer. @property(readonly) CGSize drawableSize; diff --git a/ios/xcode/MGLKit/MGLKView.mm b/ios/xcode/MGLKit/MGLKView.mm index 8d1b7a8cc7..21f771045a 100644 --- a/ios/xcode/MGLKit/MGLKView.mm +++ b/ios/xcode/MGLKit/MGLKView.mm @@ -105,11 +105,6 @@ - (void)setDrawableMultisample:(MGLDrawableMultisample)drawableMultisample self.glLayer.drawableMultisample = _drawableMultisample = drawableMultisample; } -- (void)setDrawableColorSpace:(MGLDrawableColorSpace)drawableColorSpace -{ - self.glLayer.drawableColorSpace = _drawableColorSpace = drawableColorSpace; -} - - (void)display { [self drawRect:self.bounds]; diff --git a/ios/xcode/MGLKit/MGLLayer.h b/ios/xcode/MGLKit/MGLLayer.h index 1c857a58a9..20e6e1c943 100644 --- a/ios/xcode/MGLKit/MGLLayer.h +++ b/ios/xcode/MGLKit/MGLLayer.h @@ -45,14 +45,6 @@ typedef enum MGLDrawableMultisample : int MGLDrawableMultisample4X = 4, } MGLDrawableMultisample; -typedef enum MGLDrawableColorSpace : int -{ - MGLDrawableColorSpaceUnspecified = 0, - MGLDrawableColorSpaceLinear = 1, - MGLDrawableColorSpaceSRGB = 2, - MGLDrawableColorSpaceBT2020PQ = 2020, -} MGLDrawableColorSpace; - @interface MGLLayer : CALayer // Return the size of the OpenGL framebuffer. @@ -66,7 +58,6 @@ typedef enum MGLDrawableColorSpace : int @property(nonatomic) MGLDrawableStencilFormat drawableStencilFormat; // Default is StencilNone @property(nonatomic) MGLDrawableMultisample drawableMultisample; // Default is MGLDrawableMultisampleNone -@property(nonatomic) MGLDrawableColorSpace drawableColorSpace; // Default is ColorSpaceUnspecified // Default value is NO. Setting to YES will keep the framebuffer data after presenting. // Doing so will reduce performance and increase memory usage. diff --git a/ios/xcode/MGLKit/MGLLayer.mm b/ios/xcode/MGLKit/MGLLayer.mm index fc0d23f007..e5c6f8b1cd 100644 --- a/ios/xcode/MGLKit/MGLLayer.mm +++ b/ios/xcode/MGLKit/MGLLayer.mm @@ -347,7 +347,6 @@ - (void)constructor _drawableDepthFormat = MGLDrawableDepthFormatNone; _drawableStencilFormat = MGLDrawableStencilFormatNone; _drawableMultisample = MGLDrawableMultisampleNone; - _drawableColorSpace = MGLDrawableColorSpaceUnspecified; _display = [MGLDisplay defaultDisplay]; @@ -713,15 +712,6 @@ - (void)ensureSurfaceCreated break; case MGLDrawableColorFormatRGBA16: red = green = blue = alpha = 8; - switch (_drawableColorSpace) - { - case MGLDrawableColorSpaceBT2020PQ: - colorSpace = EGL_GL_COLORSPACE_BT2020_PQ_EXT; - break; - default: - colorSpace = EGL_GL_COLORSPACE_LINEAR_KHR; - break; - } break; default: UNREACHABLE(); From b9a86f97992ab30b771118f5f008cef9f31e05ed Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Mon, 29 Jun 2020 18:39:51 -0700 Subject: [PATCH 08/12] add MGLDrawableColorFormatRGBA16BT2020PQ --- ios/xcode/MGLKit/MGLLayer.h | 4 +++- ios/xcode/MGLKit/MGLLayer.mm | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ios/xcode/MGLKit/MGLLayer.h b/ios/xcode/MGLKit/MGLLayer.h index 20e6e1c943..d82d050d25 100644 --- a/ios/xcode/MGLKit/MGLLayer.h +++ b/ios/xcode/MGLKit/MGLLayer.h @@ -23,7 +23,9 @@ typedef enum MGLDrawableColorFormat : int MGLDrawableColorFormatRGBA8888 = 32, MGLDrawableColorFormatSRGBA8888 = -32, MGLDrawableColorFormatRGB565 = 16, - MGLDrawableColorFormatRGBA16 = 64, + + MGLDrawableColorFormatRGBA16 = 64, + MGLDrawableColorFormatRGBA16BT2020PQ = 65, } MGLDrawableColorFormat; typedef enum MGLDrawableStencilFormat : int diff --git a/ios/xcode/MGLKit/MGLLayer.mm b/ios/xcode/MGLKit/MGLLayer.mm index e5c6f8b1cd..cd6c1d7e0f 100644 --- a/ios/xcode/MGLKit/MGLLayer.mm +++ b/ios/xcode/MGLKit/MGLLayer.mm @@ -711,7 +711,12 @@ - (void)ensureSurfaceCreated colorSpace = EGL_GL_COLORSPACE_SRGB_KHR; break; case MGLDrawableColorFormatRGBA16: - red = green = blue = alpha = 8; + red = green = blue = alpha = 16; + colorSpace = EGL_GL_COLORSPACE_LINEAR_KHR; + break; + case MGLDrawableColorFormatRGBA16BT2020PQ: + red = green = blue = alpha = 16; + colorSpace = EGL_GL_COLORSPACE_BT2020_PQ_EXT; break; default: UNREACHABLE(); From 3503d77ea4ab596d46c16ef502b0d74b950a3882 Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Mon, 29 Jun 2020 18:44:27 -0700 Subject: [PATCH 09/12] move metal layer colorspace into SurfaceMtl --- src/libANGLE/renderer/metal/SurfaceMtl.h | 1 + src/libANGLE/renderer/metal/SurfaceMtl.mm | 9 +++++++-- src/libANGLE/renderer/metal/mtl_format_utils.h | 1 - 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/libANGLE/renderer/metal/SurfaceMtl.h b/src/libANGLE/renderer/metal/SurfaceMtl.h index ad9820567f..5f6f8fcba6 100644 --- a/src/libANGLE/renderer/metal/SurfaceMtl.h +++ b/src/libANGLE/renderer/metal/SurfaceMtl.h @@ -98,6 +98,7 @@ class SurfaceMtl : public SurfaceImpl const mtl::TextureRef &oldDepthTexture, const mtl::TextureRef &oldStencilTexture); + CGColorSpaceRef mMetalLayerColorSpace; mtl::AutoObjCObj mMetalLayer = nil; CALayer *mLayer; mtl::AutoObjCPtr> mCurrentDrawable = nil; diff --git a/src/libANGLE/renderer/metal/SurfaceMtl.mm b/src/libANGLE/renderer/metal/SurfaceMtl.mm index 9dac69c0b3..397a2ebbb5 100644 --- a/src/libANGLE/renderer/metal/SurfaceMtl.mm +++ b/src/libANGLE/renderer/metal/SurfaceMtl.mm @@ -211,7 +211,7 @@ void StopFrameCapture() mColorFormat.intendedFormatId = mColorFormat.actualFormatId = angle::FormatID::R16G16B16A16_FLOAT; mColorFormat.metalFormat = MTLPixelFormatRGBA16Float; - mColorFormat.metalColorspace = CGColorSpaceCreateWithName(kCGColorSpaceITUR_2020_PQ); + mMetalLayerColorSpace = CGColorSpaceCreateWithName(kCGColorSpaceITUR_2020_PQ); } else { @@ -278,6 +278,11 @@ void StopFrameCapture() mDepthRenderTarget.reset(); mStencilRenderTarget.reset(); + if (mMetalLayerColorSpace) { + CGColorSpaceRelease(mMetalLayerColorSpace); + mMetalLayerColorSpace = nullptr; + } + mCurrentDrawable = nil; if (mMetalLayer && mMetalLayer.get() != mLayer) { @@ -309,7 +314,7 @@ void StopFrameCapture() mMetalLayer.get().device = metalDevice; mMetalLayer.get().pixelFormat = mColorFormat.metalFormat; - mMetalLayer.get().colorspace = mColorFormat.metalColorspace; + mMetalLayer.get().colorspace = mMetalLayerColorSpace; mMetalLayer.get().framebufferOnly = NO; // Support blitting and glReadPixels #if TARGET_OS_OSX || TARGET_OS_MACCATALYST diff --git a/src/libANGLE/renderer/metal/mtl_format_utils.h b/src/libANGLE/renderer/metal/mtl_format_utils.h index f042a39f11..a6f97ebcc9 100644 --- a/src/libANGLE/renderer/metal/mtl_format_utils.h +++ b/src/libANGLE/renderer/metal/mtl_format_utils.h @@ -82,7 +82,6 @@ struct Format : public FormatBase bool needConversion(angle::FormatID srcFormatId) const; MTLPixelFormat metalFormat = MTLPixelFormatInvalid; - CGColorSpaceRef metalColorspace = nil; LoadFunctionMap textureLoadFunctions = nullptr; InitializeTextureDataFunction initFunction = nullptr; From 247bf5988584a121c2191612eca1ce5eaa49f0ef Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Mon, 29 Jun 2020 18:56:46 -0700 Subject: [PATCH 10/12] fix mMetalLayerColorSpace lifecycle --- src/libANGLE/renderer/metal/SurfaceMtl.h | 2 +- src/libANGLE/renderer/metal/SurfaceMtl.mm | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/libANGLE/renderer/metal/SurfaceMtl.h b/src/libANGLE/renderer/metal/SurfaceMtl.h index 5f6f8fcba6..eb3c1b3492 100644 --- a/src/libANGLE/renderer/metal/SurfaceMtl.h +++ b/src/libANGLE/renderer/metal/SurfaceMtl.h @@ -98,7 +98,7 @@ class SurfaceMtl : public SurfaceImpl const mtl::TextureRef &oldDepthTexture, const mtl::TextureRef &oldStencilTexture); - CGColorSpaceRef mMetalLayerColorSpace; + CGColorSpaceRef mMetalLayerColorSpace = NULL; mtl::AutoObjCObj mMetalLayer = nil; CALayer *mLayer; mtl::AutoObjCPtr> mCurrentDrawable = nil; diff --git a/src/libANGLE/renderer/metal/SurfaceMtl.mm b/src/libANGLE/renderer/metal/SurfaceMtl.mm index 397a2ebbb5..796c57a46b 100644 --- a/src/libANGLE/renderer/metal/SurfaceMtl.mm +++ b/src/libANGLE/renderer/metal/SurfaceMtl.mm @@ -261,7 +261,12 @@ void StopFrameCapture() } } -SurfaceMtl::~SurfaceMtl() {} +SurfaceMtl::~SurfaceMtl() { + if (mMetalLayerColorSpace) { + CGColorSpaceRelease(mMetalLayerColorSpace); + mMetalLayerColorSpace = NULL; + } +} void SurfaceMtl::destroy(const egl::Display *display) { @@ -278,11 +283,6 @@ void StopFrameCapture() mDepthRenderTarget.reset(); mStencilRenderTarget.reset(); - if (mMetalLayerColorSpace) { - CGColorSpaceRelease(mMetalLayerColorSpace); - mMetalLayerColorSpace = nullptr; - } - mCurrentDrawable = nil; if (mMetalLayer && mMetalLayer.get() != mLayer) { From 075dbc485ad373437a3e1f53836f452b430173db Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Mon, 29 Jun 2020 19:01:55 -0700 Subject: [PATCH 11/12] support 16-bit configs --- src/libANGLE/renderer/metal/DisplayMtl.mm | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/libANGLE/renderer/metal/DisplayMtl.mm b/src/libANGLE/renderer/metal/DisplayMtl.mm index 0b400c31dc..a6f1036e59 100644 --- a/src/libANGLE/renderer/metal/DisplayMtl.mm +++ b/src/libANGLE/renderer/metal/DisplayMtl.mm @@ -302,17 +302,19 @@ bool IsMetalDisplayAvailable() config.colorComponentType = EGL_COLOR_COMPONENT_TYPE_FIXED_EXT; constexpr int samplesSupported[] = {0, 4}; + constexpr int sizesSupported[] = {8, 16}; + for (int size : sizesSupported) for (int samples : samplesSupported) { config.samples = samples; config.sampleBuffers = (samples == 0) ? 0 : 1; // Buffer sizes - config.redSize = 8; - config.greenSize = 8; - config.blueSize = 8; - config.alphaSize = 8; + config.redSize = size; + config.greenSize = size; + config.blueSize = size; + config.alphaSize = size; config.bufferSize = config.redSize + config.greenSize + config.blueSize + config.alphaSize; // With DS From 7a8cd44b434a779bcf8f5994fe1e2e785bb3396c Mon Sep 17 00:00:00 2001 From: Aman Gupta Date: Mon, 29 Jun 2020 19:04:02 -0700 Subject: [PATCH 12/12] remove unused header --- src/libANGLE/renderer/metal/mtl_format_utils.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libANGLE/renderer/metal/mtl_format_utils.h b/src/libANGLE/renderer/metal/mtl_format_utils.h index a6f97ebcc9..e1cf271f35 100644 --- a/src/libANGLE/renderer/metal/mtl_format_utils.h +++ b/src/libANGLE/renderer/metal/mtl_format_utils.h @@ -12,7 +12,6 @@ #define LIBANGLE_RENDERER_METAL_MTL_FORMAT_UTILS_H_ #import -#import #include