Changeset 283362 in webkit
- Timestamp:
- Oct 1, 2021, 5:53:49 AM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 11 edited
-
ChangeLog (modified) (1 diff)
-
SourcesCocoa.txt (modified) (1 diff)
-
WebCore.xcodeproj/project.pbxproj (modified) (4 diffs)
-
platform/graphics/GraphicsContextGL.cpp (modified) (1 diff)
-
platform/graphics/GraphicsContextGL.h (modified) (1 diff)
-
platform/graphics/angle/GraphicsContextGLANGLE.cpp (modified) (1 diff)
-
platform/graphics/cocoa/ANGLEUtilitiesCocoa.cpp (added)
-
platform/graphics/cocoa/ANGLEUtilitiesCocoa.h (added)
-
platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm (modified) (12 diffs)
-
platform/graphics/cv/GraphicsContextGLCVANGLE.cpp (modified) (6 diffs)
-
platform/graphics/cv/GraphicsContextGLCVANGLE.h (modified) (3 diffs)
-
platform/graphics/opengl/GraphicsContextGLOpenGL.h (modified) (6 diffs)
-
platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r283361 r283362 1 2021-10-01 Kimmo Kinnunen <kkinnunen@apple.com> 2 3 Cocoa GraphicsContextGLOpenGL should not be used by GraphicsContextGLCVANGLE 4 https://bugs.webkit.org/show_bug.cgi?id=231010 5 6 Reviewed by Kenneth Russell. 7 8 GraphicsContextGLOpenGL creates a GraphicsContextGLCVANGLE helper to do 9 do YUV texture uploads. This GraphicsContextGLCVANGLE creates a OpenGL ES context that 10 shares the OpenGL state by the caller. 11 12 Previously the new context would be a GraphicsContextGLOpenGL. This would be a problem 13 since GraphicsContextGLOpenGL has compositor related logic and objects, for example 14 the WebGL layer as well as resources for default framebuffer operation. Shared context 15 would also go to the GraphicsContextGLOpenGLManager context list even though 16 they could not be deleted behind the owners back during context recycling. 17 18 Instead, create just a normal ANGLE context and call ANGLE directly from 19 GraphicsContextGLCVANGLE. This is more consistent with software layers: 20 GraphicsContextGLOpenGL and GraphicsContextGLCVANGLE are at the same software 21 level, part of the same GraphicsContextGLOpenGL implementation. 22 23 Makes it possible to remove otherwise unused and unfitting "shared context" 24 related functionality from WebGL level from GraphicsContextGL. 25 26 No new tests, refactor. 27 28 * SourcesCocoa.txt: 29 * WebCore.xcodeproj/project.pbxproj: 30 * platform/graphics/GraphicsContextGL.cpp: 31 (WebCore::GraphicsContextGL::GraphicsContextGL): 32 * platform/graphics/GraphicsContextGL.h: 33 * platform/graphics/angle/GraphicsContextGLANGLE.cpp: 34 (WebCore::GraphicsContextGLOpenGL::asCV): Deleted. 35 * platform/graphics/cocoa/ANGLEUtilitiesCocoa.cpp: Added. 36 (WebCore::createPbufferAndAttachIOSurface): 37 (WebCore::destroyPbufferAndDetachIOSurface): 38 * platform/graphics/cocoa/ANGLEUtilitiesCocoa.h: Added. 39 Move the createPbufferAndAttachIOSurface to Cocoa specific 40 ANGLE utility file. 41 See also bug 226504 - Adopt createPbufferAndAttachIOSurface/destroyPbufferAndDetachIOSurface 42 in GraphicsContextGLCVANGLE.cpp and GraphicsContextGLOpenGLCocoa.mm 43 44 * platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm: 45 (WebCore::GraphicsContextGLOpenGL::create): 46 (WebCore::GraphicsContextGLOpenGL::createForGPUProcess): 47 (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL): 48 (WebCore::GraphicsContextGLOpenGL::~GraphicsContextGLOpenGL): 49 (WebCore::GraphicsContextGLOpenGL::checkGPUStatus): 50 (WebCore::GraphicsContextGLOpenGL::makeCurrent): 51 Add a new function to make the EGL context current and maintain 52 the GraphicsContextGLOpenGL::currentContext cache value correctly. 53 Cache needs to be invalidated always when EGL context changes. 54 The cache value is reset always, and then set only when needed 55 during GraphicsContextGLOpenGL::makeContextCurrent(). 56 57 Make GraphicsContextGLCVANGLE friend of GraphicsContextGLOpenGL, since 58 essentially the former is part of the implementation of latter. 59 60 (WebCore::GraphicsContextGLOpenGL::createPbufferAndAttachIOSurface): 61 (WebCore::GraphicsContextGLOpenGL::destroyPbufferAndDetachIOSurface): 62 Move the implementation to a ANGLE related helper files above. 63 64 (WebCore::GraphicsContextGLOpenGL::asCV): 65 Move the asCV to the implementaton file for Cococa, as that is 66 the platform which uses the implementation. 67 68 (WebCore::GraphicsContextGLOpenGL::createShared): Deleted. 69 (WebCore::GraphicsContextGLOpenGL::clearCurrentContext): Deleted. 70 Replace with GraphicsContextGLOpenGL::makeCurrent(). 71 72 * platform/graphics/cv/GraphicsContextGLCVANGLE.cpp: 73 (WebCore::YCbCrMatrix::operator const GLfloat* const): 74 (WebCore::YCbCrToRGBMatrixForRangeAndTransferFunction): 75 (WebCore::GraphicsContextGLCVANGLE::create): 76 (WebCore::GraphicsContextGLCVANGLE::~GraphicsContextGLCVANGLE): 77 (WebCore::GraphicsContextGLCVANGLE::GraphicsContextGLCVANGLE): 78 Reorder the resource initialization with ScopeExit cleanup functions. 79 Avoid storing the yuvProgram, instead just use the program as program 80 binary and delete the program. 81 82 (WebCore::GraphicsContextGLCVANGLE::copyPixelBufferToTexture): 83 (WebCore::YCbCrMatrix::operator GCGLSpan<const GLfloat, 16> const): Deleted. 84 (WebCore::GraphicsContextGLCVANGLE::initializeUVContextObjects): Deleted. 85 Move the resource initialization into the constructor. The object 86 itself is already initialized only on demand. 87 (WebCore::GraphicsContextGLCVANGLE::attachIOSurfaceToTexture): Deleted. 88 (WebCore::GraphicsContextGLCVANGLE::detachIOSurfaceFromTexture): Deleted. 89 Share the implementation with the existing implementation from 90 WebCore::GraphicsContextGLOpenGL::createPbufferAndAttachIOSurface that 91 was moved to WebCore::createPbufferAndAttachIOSurface. 92 93 * platform/graphics/cv/GraphicsContextGLCVANGLE.h: 94 Remove the m_yuvProgram, rather use just the program binary. 95 96 * platform/graphics/opengl/GraphicsContextGLOpenGL.h: 97 * platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp: 98 (WebCore::GraphicsContextGLOpenGL::GraphicsContextGLOpenGL): 99 Remove the redundant sharedContext parameter. 100 1 101 2021-10-01 Carlos Garcia Campos <cgarcia@igalia.com> 2 102 -
trunk/Source/WebCore/SourcesCocoa.txt
r283217 r283362 360 360 platform/graphics/cg/TransformationMatrixCG.cpp 361 361 platform/graphics/cg/UTIRegistry.cpp 362 platform/graphics/cocoa/ANGLEUtilitiesCocoa.cpp 362 363 platform/graphics/cocoa/AudioTrackPrivateWebM.cpp 363 364 platform/graphics/cocoa/ColorCocoa.mm -
trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj
r283347 r283362 10648 10648 7BB680B725BA1BE3002B8738 /* GraphicsChecksMac.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = GraphicsChecksMac.cpp; sourceTree = "<group>"; }; 10649 10649 7BB680B825BA1BE4002B8738 /* GraphicsChecksMac.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GraphicsChecksMac.h; sourceTree = "<group>"; }; 10650 7BCD42DA2705C94900EB2127 /* ANGLEUtilitiesCocoa.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = ANGLEUtilitiesCocoa.cpp; sourceTree = "<group>"; }; 10651 7BCD42DC2705C94900EB2127 /* ANGLEUtilitiesCocoa.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ANGLEUtilitiesCocoa.h; sourceTree = "<group>"; }; 10650 10652 7BE7265B25763B8D00E85D98 /* RemoteGraphicsContextGLProxyBase.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteGraphicsContextGLProxyBase.cpp; sourceTree = "<group>"; }; 10651 10653 7C011F3D24FAD360005BEF10 /* Settings.cpp.erb */ = {isa = PBXFileReference; lastKnownFileType = text; path = Settings.cpp.erb; sourceTree = "<group>"; }; … … 27331 27333 isa = PBXGroup; 27332 27334 children = ( 27335 7BCD42DA2705C94900EB2127 /* ANGLEUtilitiesCocoa.cpp */, 27336 7BCD42DC2705C94900EB2127 /* ANGLEUtilitiesCocoa.h */, 27333 27337 CDF9950124C28149002EA062 /* AudioTrackPrivateWebM.cpp */, 27334 27338 CDF9950024C28149002EA062 /* AudioTrackPrivateWebM.h */, … … 31402 31406 27E3C808257F5E6E00C986AB /* ANGLEHeaders.h in Headers */, 31403 31407 31A795C71888BCB200382F90 /* ANGLEInstancedArrays.h in Headers */, 31408 7BB34A1725345CB200029D08 /* ANGLEUtilities.h in Headers */, 31404 31409 49E912AB0EFAC906009D0CAF /* Animation.h in Headers */, 31405 31410 71EFCEDC202B38A900D7C411 /* AnimationEffect.h in Headers */, … … 32649 32654 313DE87023A96973008FC47B /* GraphicsContextGL.h in Headers */, 32650 32655 7B45AB5525FBA9DE00FD27F4 /* GraphicsContextGLANGLEEGLUtilities.h in Headers */, 32651 7BB34A1725345CB200029D08 /* GraphicsContextGLANGLEUtilities.h in Headers */,32652 32656 7C330A021DF8FAC600D3395C /* GraphicsContextGLAttributes.h in Headers */, 32653 32657 7B10339E2549721700C8C1AC /* GraphicsContextGLCV.h in Headers */, -
trunk/Source/WebCore/platform/graphics/GraphicsContextGL.cpp
r283238 r283362 358 358 } 359 359 360 GraphicsContextGL::GraphicsContextGL(GraphicsContextGLAttributes attrs , GraphicsContextGL*)360 GraphicsContextGL::GraphicsContextGL(GraphicsContextGLAttributes attrs) 361 361 : m_attrs(attrs) 362 362 { -
trunk/Source/WebCore/platform/graphics/GraphicsContextGL.h
r283238 r283362 915 915 WEBCORE_EXPORT static RefPtr<GraphicsContextGL> create(const GraphicsContextGLAttributes&, HostWindow*); 916 916 917 GraphicsContextGL(GraphicsContextGLAttributes , GraphicsContextGL* sharedContext = nullptr);917 GraphicsContextGL(GraphicsContextGLAttributes); 918 918 virtual ~GraphicsContextGL() = default; 919 919 -
trunk/Source/WebCore/platform/graphics/angle/GraphicsContextGLANGLE.cpp
r281613 r283362 2843 2843 } 2844 2844 2845 #if ENABLE(VIDEO) && USE(AVFOUNDATION)2846 GraphicsContextGLCV* GraphicsContextGLOpenGL::asCV()2847 {2848 if (!m_cv)2849 m_cv = makeUnique<GraphicsContextGLCVANGLE>(*this);2850 return m_cv.get();2851 }2852 #endif2853 2854 2845 bool GraphicsContextGLOpenGL::waitAndUpdateOldestFrame() 2855 2846 { -
trunk/Source/WebCore/platform/graphics/cocoa/GraphicsContextGLOpenGLCocoa.mm
r283308 r283362 29 29 #import "GraphicsContextGLOpenGL.h" 30 30 31 #import "ANGLEUtilitiesCocoa.h" 31 32 #import "CVUtilities.h" 32 33 #import "ExtensionsGLANGLE.h" … … 49 50 50 51 #if ENABLE(VIDEO) && USE(AVFOUNDATION) 51 #include "GraphicsContextGLCV .h"52 #include "GraphicsContextGLCVANGLE.h" 52 53 #endif 53 54 … … 198 199 return nullptr; 199 200 200 RefPtr<GraphicsContextGLOpenGL> context = adoptRef(new GraphicsContextGLOpenGL(attrs, hostWindow, nullptr , nullptr));201 RefPtr<GraphicsContextGLOpenGL> context = adoptRef(new GraphicsContextGLOpenGL(attrs, hostWindow, nullptr)); 201 202 202 203 if (!context->m_contextObj) … … 208 209 } 209 210 210 Ref<GraphicsContextGLOpenGL> GraphicsContextGLOpenGL::createShared(GraphicsContextGLOpenGL& sharedContext)211 {212 213 auto context = adoptRef(*new GraphicsContextGLOpenGL(sharedContext.contextAttributes(), nullptr, &sharedContext, nullptr));214 215 GraphicsContextGLOpenGLManager::sharedManager().addContext(context.ptr());216 217 return context;218 }219 220 211 Ref<GraphicsContextGLOpenGL> GraphicsContextGLOpenGL::createForGPUProcess(const GraphicsContextGLAttributes& attrs, GraphicsContextGLIOSurfaceSwapChain* swapChain) 221 212 { 222 return adoptRef(*new GraphicsContextGLOpenGL(attrs, nullptr, nullptr,swapChain));223 } 224 225 GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attrs, HostWindow*, GraphicsContextGL OpenGL* sharedContext, GraphicsContextGLIOSurfaceSwapChain* swapChain)226 : GraphicsContextGL(attrs , sharedContext)213 return adoptRef(*new GraphicsContextGLOpenGL(attrs, nullptr, swapChain)); 214 } 215 216 GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attrs, HostWindow*, GraphicsContextGLIOSurfaceSwapChain* swapChain) 217 : GraphicsContextGL(attrs) 227 218 { 228 219 m_isForWebGL2 = attrs.webGLVersion == GraphicsContextGLWebGLVersion::WebGL2; … … 293 284 eglContextAttributes.append(EGL_FALSE); 294 285 } 295 if (!sharedContext) { 296 // The shared context is only non-null when creating a context 297 // on behalf of the VideoTextureCopier. WebGL-specific rendering 298 // feedback loop validation does not work in multi-context 299 // scenarios, and must be disabled for the VideoTextureCopier's 300 // context. 301 eglContextAttributes.append(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE); 302 eglContextAttributes.append(EGL_TRUE); 303 // WebGL requires that all resources are cleared at creation. 304 // FIXME: performing robust resource initialization in the VideoTextureCopier adds a large amount of overhead 305 // so it would be nice to avoid that there (we should always be touching every pixel as we copy). 306 eglContextAttributes.append(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE); 307 eglContextAttributes.append(EGL_TRUE); 308 } 286 eglContextAttributes.append(EGL_CONTEXT_WEBGL_COMPATIBILITY_ANGLE); 287 eglContextAttributes.append(EGL_TRUE); 288 289 // WebGL requires that all resources are cleared at creation. 290 eglContextAttributes.append(EGL_ROBUST_RESOURCE_INITIALIZATION_ANGLE); 291 eglContextAttributes.append(EGL_TRUE); 309 292 310 293 // WebGL doesn't allow client arrays. … … 317 300 eglContextAttributes.append(EGL_NONE); 318 301 319 m_contextObj = EGL_CreateContext(m_displayObj, m_configObj, sharedContext ? static_cast<EGLContext>(sharedContext->m_contextObj) :EGL_NO_CONTEXT, eglContextAttributes.data());320 if (m_contextObj == EGL_NO_CONTEXT ) {302 m_contextObj = EGL_CreateContext(m_displayObj, m_configObj, EGL_NO_CONTEXT, eglContextAttributes.data()); 303 if (m_contextObj == EGL_NO_CONTEXT || !makeCurrent(m_displayObj, m_contextObj)) { 321 304 LOG(WebGL, "EGLContext Initialization failed."); 322 305 return; 323 306 } 324 307 LOG(WebGL, "Got EGLContext"); 325 326 EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, m_contextObj);327 308 328 309 if (m_isForWebGL2) … … 464 445 } 465 446 if (m_contextObj) { 466 clearCurrentContext();447 makeCurrent(m_displayObj, EGL_NO_CONTEXT); 467 448 EGL_DestroyContext(m_displayObj, m_contextObj); 468 449 } … … 528 509 } 529 510 530 void GraphicsContextGLOpenGL::clearCurrentContext()531 {532 EGLBoolean result = EGL_MakeCurrent(m_displayObj, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);533 ASSERT_UNUSED(result, result);534 currentContext = nullptr;535 }536 537 511 #if PLATFORM(IOS_FAMILY) 538 512 bool GraphicsContextGLOpenGL::releaseCurrentContext(ReleaseBehavior releaseBehavior) … … 580 554 m_failNextStatusCheck = false; 581 555 forceContextLost(); 582 clearCurrentContext();556 makeCurrent(m_displayObj, EGL_NO_CONTEXT); 583 557 return; 584 558 } … … 681 655 } 682 656 657 bool GraphicsContextGLOpenGL::makeCurrent(PlatformGraphicsContextGLDisplay display, PlatformGraphicsContextGL context) 658 { 659 currentContext = nullptr; 660 return EGL_MakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, context); 661 } 662 683 663 void* GraphicsContextGLOpenGL::createPbufferAndAttachIOSurface(GCGLenum target, PbufferAttachmentUsage usage, GCGLenum internalFormat, GCGLsizei width, GCGLsizei height, GCGLenum type, IOSurfaceRef surface, GCGLuint plane) 684 664 { 685 if (target != GraphicsContextGL ::TEXTURE_RECTANGLE_ARB && target != GraphicsContextGL::TEXTURE_2D) {665 if (target != GraphicsContextGLOpenGL::drawingBufferTextureTarget()) { 686 666 LOG(WebGL, "Unknown texture target %d.", static_cast<int>(target)); 687 667 return nullptr; 688 668 } 689 669 690 auto eglTextureTarget = [&] () -> EGLint { 691 if (target == GraphicsContextGL::TEXTURE_RECTANGLE_ARB) 692 return EGL_TEXTURE_RECTANGLE_ANGLE; 693 return EGL_TEXTURE_2D; 694 }(); 695 696 if (eglTextureTarget != GraphicsContextGLOpenGL::EGLDrawingBufferTextureTarget()) { 697 LOG(WebGL, "Mismatch in EGL texture target: %d should be %d.", static_cast<int>(target), GraphicsContextGLOpenGL::EGLDrawingBufferTextureTarget()); 698 return nullptr; 699 } 700 701 auto usageHintAngle = [&] () -> EGLint { 670 auto usageHint = [&] () -> EGLint { 702 671 if (usage == PbufferAttachmentUsage::Read) 703 672 return EGL_IOSURFACE_READ_HINT_ANGLE; … … 707 676 }(); 708 677 709 const EGLint surfaceAttributes[] = { 710 EGL_WIDTH, width, 711 EGL_HEIGHT, height, 712 EGL_IOSURFACE_PLANE_ANGLE, static_cast<EGLint>(plane), 713 EGL_TEXTURE_TARGET, static_cast<EGLint>(eglTextureTarget), 714 EGL_TEXTURE_INTERNAL_FORMAT_ANGLE, static_cast<EGLint>(internalFormat), 715 EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA, 716 EGL_TEXTURE_TYPE_ANGLE, static_cast<EGLint>(type), 717 // Only has an effect on the iOS Simulator. 718 EGL_IOSURFACE_USAGE_HINT_ANGLE, usageHintAngle, 719 EGL_NONE, EGL_NONE 720 }; 721 722 auto display = platformDisplay(); 723 EGLSurface pbuffer = EGL_CreatePbufferFromClientBuffer(display, EGL_IOSURFACE_ANGLE, surface, platformConfig(), surfaceAttributes); 724 if (!pbuffer) { 725 LOG(WebGL, "EGL_CreatePbufferFromClientBuffer failed."); 726 return nullptr; 727 } 728 729 if (!EGL_BindTexImage(display, pbuffer, EGL_BACK_BUFFER)) { 730 LOG(WebGL, "EGL_BindTexImage failed."); 731 EGL_DestroySurface(display, pbuffer); 732 return nullptr; 733 } 734 735 return pbuffer; 678 return WebCore::createPbufferAndAttachIOSurface(m_displayObj, m_configObj, target, usageHint, internalFormat, width, height, type, surface, plane); 736 679 } 737 680 738 681 void GraphicsContextGLOpenGL::destroyPbufferAndDetachIOSurface(void* handle) 739 682 { 740 auto display = platformDisplay(); 741 EGL_ReleaseTexImage(display, handle, EGL_BACK_BUFFER); 742 EGL_DestroySurface(display, handle); 683 WebCore::destroyPbufferAndDetachIOSurface(m_displayObj, handle); 743 684 } 744 685 … … 845 786 } 846 787 } 788 789 790 #if ENABLE(VIDEO) && USE(AVFOUNDATION) 791 GraphicsContextGLCV* GraphicsContextGLOpenGL::asCV() 792 { 793 if (!m_cv) 794 m_cv = GraphicsContextGLCVANGLE::create(*this); 795 return m_cv.get(); 796 } 797 #endif 847 798 848 799 std::optional<PixelBuffer> GraphicsContextGLOpenGL::readCompositedResults() -
trunk/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.cpp
r281791 r283362 29 29 #if ENABLE(WEBGL) && ENABLE(VIDEO) && USE(AVFOUNDATION) 30 30 31 #include "ANGLE Headers.h"31 #include "ANGLEUtilitiesCocoa.h" 32 32 #include "FourCC.h" 33 #include "GraphicsContextGLOpenGL.h" 33 34 #include "Logging.h" 34 35 #include <pal/spi/cf/CoreVideoSPI.h> 35 36 #include <pal/spi/cocoa/IOSurfaceSPI.h> 36 37 #include <wtf/NeverDestroyed.h> 38 #include <wtf/Scope.h> 37 39 #include <wtf/StdMap.h> 38 40 #include <wtf/cf/TypeCastsCF.h> … … 231 233 constexpr YCbCrMatrix(PixelRange, GLfloat cbCoefficient, GLfloat crCoefficient); 232 234 233 operator GCGLSpan<const GLfloat, 16>() const235 operator const GLfloat*() const 234 236 { 235 return makeGCGLSpan<16>(&rows[0][0]);237 return &rows[0][0]; 236 238 } 237 239 … … 305 307 } 306 308 307 static GCGLSpan<const GLfloat, 16>YCbCrToRGBMatrixForRangeAndTransferFunction(PixelRange range, TransferFunctionCV transferFunction)309 static const GLfloat* YCbCrToRGBMatrixForRangeAndTransferFunction(PixelRange range, TransferFunctionCV transferFunction) 308 310 { 309 311 using MapKey = std::pair<PixelRange, TransferFunctionCV>; … … 431 433 } 432 434 433 namespace { 434 435 // Scoped holder of a cleanup function. Calls the function at the end of the scope. 436 // Note: Releases the reference to the function only after the scope, not 437 // at the time of `reset()` call. 438 template <typename F> 439 class ScopedCleanup { 440 public: 441 explicit ScopedCleanup(F&& function) 442 : m_function(WTFMove(function)) 443 { 444 } 445 ~ScopedCleanup() 446 { 447 if (m_shouldCall) 448 m_function(); 449 } 450 void reset() { m_shouldCall = false; } 451 private: 452 bool m_shouldCall = true; 453 const F m_function; 454 }; 455 456 } 457 458 GraphicsContextGLCVANGLE::GraphicsContextGLCVANGLE(GraphicsContextGLOpenGL& context) 459 : m_context(GraphicsContextGLOpenGL::createShared(context)) 460 , m_framebuffer(m_context->createFramebuffer()) 461 { 435 std::unique_ptr<GraphicsContextGLCVANGLE> GraphicsContextGLCVANGLE::create(GraphicsContextGLOpenGL& context) 436 { 437 std::unique_ptr<GraphicsContextGLCVANGLE> cv { new GraphicsContextGLCVANGLE(context) }; 438 if (!cv->m_context) 439 return nullptr; 440 return cv; 462 441 } 463 442 464 443 GraphicsContextGLCVANGLE::~GraphicsContextGLCVANGLE() 465 444 { 466 if (m_yuvVertexBuffer) 467 m_context->deleteBuffer(m_yuvVertexBuffer); 468 if (m_yuvProgram) 469 m_context->deleteProgram(m_yuvProgram); 470 m_context->deleteFramebuffer(m_framebuffer); 471 } 472 473 bool GraphicsContextGLCVANGLE::initializeUVContextObjects() 474 { 475 const bool useTexture2D = GraphicsContextGLOpenGL::drawingBufferTextureTarget() == GraphicsContextGL::TEXTURE_2D; 476 477 PlatformGLObject vertexShader = m_context->createShader(GraphicsContextGL::VERTEX_SHADER); 478 if (useTexture2D) 479 m_context->shaderSource(vertexShader, s_yuvVertexShaderTexture2D); 480 else 481 m_context->shaderSource(vertexShader, s_yuvVertexShaderTextureRectangle); 482 483 m_context->compileShaderDirect(vertexShader); 484 485 GCGLint status = m_context->getShaderi(vertexShader, GraphicsContextGL::COMPILE_STATUS); 445 if (!m_context || !GraphicsContextGLOpenGL::makeCurrent(m_display, m_context)) 446 return; 447 gl::DeleteBuffers(1, &m_yuvVertexBuffer); 448 gl::DeleteFramebuffers(1, &m_framebuffer); 449 EGL_DestroyContext(m_display, m_context); 450 } 451 452 GraphicsContextGLCVANGLE::GraphicsContextGLCVANGLE(GraphicsContextGLOpenGL& owner) 453 : m_owner(owner) 454 { 455 // Create compatible context that shares state with owner, but one that does not 456 // have robustness or WebGL compatibility. 457 const EGLint contextAttributes[] = { 458 EGL_CONTEXT_CLIENT_VERSION, 459 owner.m_isForWebGL2 ? 3 : 2, 460 EGL_CONTEXT_OPENGL_BACKWARDS_COMPATIBLE_ANGLE, 461 EGL_FALSE, 462 EGL_CONTEXT_CLIENT_ARRAYS_ENABLED_ANGLE, 463 EGL_FALSE, 464 EGL_CONTEXT_BIND_GENERATES_RESOURCE_CHROMIUM, 465 EGL_FALSE, 466 EGL_NONE 467 }; 468 EGLDisplay display = owner.platformDisplay(); 469 EGLConfig config = owner.platformConfig(); 470 EGLContext context = EGL_CreateContext(display, config, owner.m_contextObj, contextAttributes); 471 if (context == EGL_NO_CONTEXT) 472 return; 473 GraphicsContextGLOpenGL::makeCurrent(display, context); 474 475 auto contextCleanup = makeScopeExit([display, context] { 476 GraphicsContextGLOpenGL::makeCurrent(display, EGL_NO_CONTEXT); 477 EGL_DestroyContext(display, context); 478 }); 479 480 const bool useTexture2D = GraphicsContextGLOpenGL::drawingBufferTextureTarget() == GL_TEXTURE_2D; 481 482 #if PLATFORM(MAC) || PLATFORM(MACCATALYST) 483 if (!useTexture2D) { 484 gl::RequestExtensionANGLE("GL_ANGLE_texture_rectangle"); 485 gl::RequestExtensionANGLE("GL_EXT_texture_format_BGRA8888"); 486 if (gl::GetError() != GL_NO_ERROR) 487 return; 488 } 489 #endif 490 491 GLint vertexShader = gl::CreateShader(GL_VERTEX_SHADER); 492 GLint fragmentShader = gl::CreateShader(GL_FRAGMENT_SHADER); 493 GLuint yuvProgram = gl::CreateProgram(); 494 auto programCleanup = makeScopeExit([vertexShader, fragmentShader, yuvProgram] { 495 gl::DeleteShader(vertexShader); 496 gl::DeleteShader(fragmentShader); 497 gl::DeleteProgram(yuvProgram); 498 }); 499 // These are written so strlen might be compile-time. 500 GLint vsLength = useTexture2D ? s_yuvVertexShaderTexture2D.length() : s_yuvVertexShaderTextureRectangle.length(); 501 GLint fsLength = useTexture2D ? s_yuvFragmentShaderTexture2D.length() : s_yuvFragmentShaderTextureRectangle.length(); 502 const char* vertexShaderSource = useTexture2D ? s_yuvVertexShaderTexture2D : s_yuvVertexShaderTextureRectangle; 503 const char* fragmentShaderSource = useTexture2D ? s_yuvFragmentShaderTexture2D : s_yuvFragmentShaderTextureRectangle; 504 505 gl::ShaderSource(vertexShader, 1, &vertexShaderSource, &vsLength); 506 gl::ShaderSource(fragmentShader, 1, &fragmentShaderSource, &fsLength); 507 gl::CompileShader(vertexShader); 508 gl::CompileShader(fragmentShader); 509 gl::AttachShader(yuvProgram, vertexShader); 510 gl::AttachShader(yuvProgram, fragmentShader); 511 gl::LinkProgram(yuvProgram); 512 // Link status is checked afterwards for theoretical parallel compilation benefit. 513 514 GLuint yuvVertexBuffer = 0; 515 gl::GenBuffers(1, &yuvVertexBuffer); 516 auto yuvVertexBufferCleanup = makeScopeExit([yuvVertexBuffer] { 517 gl::DeleteBuffers(1, &yuvVertexBuffer); 518 }); 519 float vertices[12] = { -1, -1, 1, -1, 1, 1, 1, 1, -1, 1, -1, -1 }; 520 gl::BindBuffer(GL_ARRAY_BUFFER, yuvVertexBuffer); 521 gl::BufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); 522 523 GLuint framebuffer = 0; 524 gl::GenFramebuffers(1, &framebuffer); 525 auto framebufferCleanup = makeScopeExit([framebuffer] { 526 gl::DeleteFramebuffers(1, &framebuffer); 527 }); 528 529 GLint status = 0; 530 gl::GetProgramivRobustANGLE(yuvProgram, GL_LINK_STATUS, 1, nullptr, &status); 486 531 if (!status) { 487 LOG(WebGL, "GraphicsContextGLCVANGLE::initializeUVContextObjects(%p) - Vertex shader failed to compile.", this); 488 m_context->deleteShader(vertexShader); 489 return false; 490 } 491 492 PlatformGLObject fragmentShader = m_context->createShader(GraphicsContextGL::FRAGMENT_SHADER); 493 if (useTexture2D) 494 m_context->shaderSource(fragmentShader, s_yuvFragmentShaderTexture2D); 495 else 496 m_context->shaderSource(fragmentShader, s_yuvFragmentShaderTextureRectangle); 497 498 m_context->compileShaderDirect(fragmentShader); 499 500 status = m_context->getShaderi(fragmentShader, GraphicsContextGL::COMPILE_STATUS); 501 if (!status) { 502 LOG(WebGL, "GraphicsContextGLCVANGLE::initializeUVContextObjects(%p) - Fragment shader failed to compile.", this); 503 m_context->deleteShader(vertexShader); 504 m_context->deleteShader(fragmentShader); 505 return false; 506 } 507 508 m_yuvProgram = m_context->createProgram(); 509 m_context->attachShader(m_yuvProgram, vertexShader); 510 m_context->attachShader(m_yuvProgram, fragmentShader); 511 m_context->linkProgram(m_yuvProgram); 512 513 status = m_context->getProgrami(m_yuvProgram, GraphicsContextGL::LINK_STATUS); 514 if (!status) { 515 LOG(WebGL, "GraphicsContextGLCVANGLE::initializeUVContextObjects(%p) - Program failed to link.", this); 516 m_context->deleteShader(vertexShader); 517 m_context->deleteShader(fragmentShader); 518 m_context->deleteProgram(m_yuvProgram); 519 m_yuvProgram = 0; 520 return false; 521 } 522 523 m_yTextureUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_yTexture"_s); 524 m_uvTextureUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_uvTexture"_s); 525 m_colorMatrixUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_colorMatrix"_s); 526 m_yuvFlipYUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_flipY"_s); 527 m_yTextureSizeUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_yTextureSize"_s); 528 m_uvTextureSizeUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_uvTextureSize"_s); 529 m_yuvPositionAttributeLocation = m_context->getAttribLocationDirect(m_yuvProgram, "a_position"_s); 530 531 m_context->detachShader(m_yuvProgram, vertexShader); 532 m_context->detachShader(m_yuvProgram, fragmentShader); 533 m_context->deleteShader(vertexShader); 534 m_context->deleteShader(fragmentShader); 535 536 m_yuvVertexBuffer = m_context->createBuffer(); 537 float vertices[12] = { -1, -1, 1, -1, 1, 1, 1, 1, -1, 1, -1, -1 }; 538 539 m_context->bindBuffer(GraphicsContextGL::ARRAY_BUFFER, m_yuvVertexBuffer); 540 m_context->bufferData(GraphicsContextGL::ARRAY_BUFFER, GCGLSpan<const GCGLvoid>(vertices, sizeof(vertices)), GraphicsContextGL::STATIC_DRAW); 541 m_context->enableVertexAttribArray(m_yuvPositionAttributeLocation); 542 m_context->vertexAttribPointer(m_yuvPositionAttributeLocation, 2, GraphicsContextGL::FLOAT, false, 0, 0); 543 544 return true; 545 } 546 547 void* GraphicsContextGLCVANGLE::attachIOSurfaceToTexture(GCGLenum target, GCGLenum internalFormat, GCGLsizei width, GCGLsizei height, GCGLenum type, IOSurfaceRef surface, GCGLuint plane) 548 { 549 auto display = m_context->platformDisplay(); 550 EGLint eglTextureTarget = 0; 551 552 if (target == GraphicsContextGL::TEXTURE_RECTANGLE_ARB) 553 eglTextureTarget = EGL_TEXTURE_RECTANGLE_ANGLE; 554 else if (target == GraphicsContextGL::TEXTURE_2D) 555 eglTextureTarget = EGL_TEXTURE_2D; 556 else { 557 LOG(WebGL, "Unknown texture target %d.", static_cast<int>(target)); 558 return nullptr; 559 } 560 if (eglTextureTarget != GraphicsContextGLOpenGL::EGLDrawingBufferTextureTarget()) { 561 LOG(WebGL, "Mismatch in EGL texture target %d.", static_cast<int>(target)); 562 return nullptr; 563 } 564 565 const EGLint surfaceAttributes[] = { 566 EGL_WIDTH, width, 567 EGL_HEIGHT, height, 568 EGL_IOSURFACE_PLANE_ANGLE, static_cast<EGLint>(plane), 569 EGL_TEXTURE_TARGET, static_cast<EGLint>(eglTextureTarget), 570 EGL_TEXTURE_INTERNAL_FORMAT_ANGLE, static_cast<EGLint>(internalFormat), 571 EGL_TEXTURE_FORMAT, EGL_TEXTURE_RGBA, 572 EGL_TEXTURE_TYPE_ANGLE, static_cast<EGLint>(type), 573 // Only has an effect on the iOS Simulator. 574 EGL_IOSURFACE_USAGE_HINT_ANGLE, EGL_IOSURFACE_READ_HINT_ANGLE, 575 EGL_NONE, EGL_NONE 576 }; 577 EGLSurface pbuffer = EGL_CreatePbufferFromClientBuffer(display, EGL_IOSURFACE_ANGLE, surface, m_context->platformConfig(), surfaceAttributes); 578 if (!pbuffer) 579 return nullptr; 580 if (!EGL_BindTexImage(display, pbuffer, EGL_BACK_BUFFER)) { 581 EGL_DestroySurface(display, pbuffer); 582 return nullptr; 583 } 584 return pbuffer; 585 } 586 587 void GraphicsContextGLCVANGLE::detachIOSurfaceFromTexture(void* handle) 588 { 589 auto display = m_context->platformDisplay(); 590 EGL_ReleaseTexImage(display, handle, EGL_BACK_BUFFER); 591 EGL_DestroySurface(display, handle); 592 } 593 594 bool GraphicsContextGLCVANGLE::copyPixelBufferToTexture(CVPixelBufferRef image, PlatformGLObject outputTexture, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, FlipY flipY) 532 GLint vsStatus = 0; 533 gl::GetShaderivRobustANGLE(vertexShader, GL_COMPILE_STATUS, 1, nullptr, &vsStatus); 534 GLint fsStatus = 0; 535 gl::GetShaderivRobustANGLE(fragmentShader, GL_COMPILE_STATUS, 1, nullptr, &fsStatus); 536 LOG(WebGL, "GraphicsContextGLCVANGLE(%p) - YUV program failed to link: %d, %d, %d.", this, status, vsStatus, fsStatus); 537 return; 538 } 539 contextCleanup.release(); 540 yuvVertexBufferCleanup.release(); 541 framebufferCleanup.release(); 542 m_display = display; 543 m_context = context; 544 m_config = config; 545 m_yuvVertexBuffer = yuvVertexBuffer; 546 m_framebuffer = framebuffer; 547 m_yTextureUniformLocation = gl::GetUniformLocation(yuvProgram, "u_yTexture"); 548 m_uvTextureUniformLocation = gl::GetUniformLocation(yuvProgram, "u_uvTexture"); 549 m_colorMatrixUniformLocation = gl::GetUniformLocation(yuvProgram, "u_colorMatrix"); 550 m_yuvFlipYUniformLocation = gl::GetUniformLocation(yuvProgram, "u_flipY"); 551 m_yTextureSizeUniformLocation = gl::GetUniformLocation(yuvProgram, "u_yTextureSize"); 552 m_uvTextureSizeUniformLocation = gl::GetUniformLocation(yuvProgram, "u_uvTextureSize"); 553 m_yuvPositionAttributeLocation = gl::GetAttribLocation(yuvProgram, "a_position"); 554 // Program is deleted by the cleanup while the program binary stays in use. 555 gl::UseProgram(yuvProgram); 556 gl::EnableVertexAttribArray(m_yuvPositionAttributeLocation); 557 gl::VertexAttribPointer(m_yuvPositionAttributeLocation, 2, GL_FLOAT, false, 0, 0); 558 gl::ClearColor(0, 0, 0, 0); 559 gl::BindFramebuffer(GL_FRAMEBUFFER, m_framebuffer); 560 } 561 562 bool GraphicsContextGLCVANGLE::copyPixelBufferToTexture(CVPixelBufferRef image, PlatformGLObject outputTexture, GLint level, GLenum internalFormat, GLenum format, GLenum type, FlipY flipY) 595 563 { 596 564 // FIXME: This currently only supports '420v' and '420f' pixel formats. Investigate supporting more pixel formats. … … 612 580 auto newSurfaceSeed = IOSurfaceGetSeed(surface); 613 581 if (flipY == m_lastFlipY 614 && surface == m_lastSurface 582 && surface == m_lastSurface 615 583 && newSurfaceSeed == m_lastSurfaceSeed 616 && lastTextureSeed(outputTexture) == m_ context->textureSeed(outputTexture)) {584 && lastTextureSeed(outputTexture) == m_owner.textureSeed(outputTexture)) { 617 585 // If the texture hasn't been modified since the last time we copied to it, and the 618 586 // image hasn't been modified since the last time it was copied, this is a no-op. 619 587 return true; 620 588 } 621 622 if (!m_yuvProgram) { 623 if (!initializeUVContextObjects()) { 624 LOG(WebGL, "GraphicsContextGLCVANGLE::copyVideoTextureToPlatformTexture(%p) - Unable to initialize OpenGL context objects.", this); 625 return false; 626 } 627 } 589 if (!m_context || !GraphicsContextGLOpenGL::makeCurrent(m_display, m_context)) 590 return false; 591 628 592 size_t width = CVPixelBufferGetWidth(image); 629 593 size_t height = CVPixelBufferGetHeight(image); 630 594 631 m_context->bindFramebuffer(GraphicsContextGL::FRAMEBUFFER, m_framebuffer);595 gl::Viewport(0, 0, width, height); 632 596 633 597 // The outputTexture might contain uninitialized content on early-outs. Clear it in cases 634 598 // autoClearTextureOnError is not reset. 635 auto autoClearTextureOnError = ScopedCleanup { 636 [outputTexture, level, internalFormat, format, type, context = m_context.ptr()] { 637 context->bindTexture(GraphicsContextGL::TEXTURE_2D, outputTexture); 638 context->texImage2DDirect(GL_TEXTURE_2D, level, internalFormat, 0, 0, 0, format, type, nullptr); 639 context->bindTexture(GraphicsContextGL::TEXTURE_2D, 0); 640 } 641 }; 599 auto autoClearTextureOnError = makeScopeExit([outputTexture, level, internalFormat, format, type] { 600 gl::BindTexture(GL_TEXTURE_2D, outputTexture); 601 gl::TexImage2D(GL_TEXTURE_2D, level, internalFormat, 0, 0, 0, format, type, nullptr); 602 gl::BindTexture(GL_TEXTURE_2D, 0); 603 }); 642 604 // Allocate memory for the output texture. 643 m_context->bindTexture(GraphicsContextGL::TEXTURE_2D, outputTexture);644 m_context->texParameteri(GraphicsContextGL::TEXTURE_2D, GraphicsContextGL::TEXTURE_MAG_FILTER, GraphicsContextGL::LINEAR);645 m_context->texParameteri(GraphicsContextGL::TEXTURE_2D, GraphicsContextGL::TEXTURE_MIN_FILTER, GraphicsContextGL::LINEAR);646 m_context->texParameteri(GraphicsContextGL::TEXTURE_2D, GraphicsContextGL::TEXTURE_WRAP_S, GraphicsContextGL::CLAMP_TO_EDGE);647 m_context->texParameteri(GraphicsContextGL::TEXTURE_2D, GraphicsContextGL::TEXTURE_WRAP_T, GraphicsContextGL::CLAMP_TO_EDGE);648 m_context->texImage2DDirect(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type, nullptr);649 650 m_context->framebufferTexture2D(GraphicsContextGL::FRAMEBUFFER, GraphicsContextGL::COLOR_ATTACHMENT0, GraphicsContextGL::TEXTURE_2D, outputTexture, level);651 G CGLenum status = m_context->checkFramebufferStatus(GraphicsContextGL::FRAMEBUFFER);652 if (status != G raphicsContextGL::FRAMEBUFFER_COMPLETE) {605 gl::BindTexture(GL_TEXTURE_2D, outputTexture); 606 gl::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 607 gl::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 608 gl::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 609 gl::TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 610 gl::TexImage2D(GL_TEXTURE_2D, level, internalFormat, width, height, 0, format, type, nullptr); 611 612 gl::FramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, outputTexture, level); 613 GLenum status = gl::CheckFramebufferStatus(GL_FRAMEBUFFER); 614 if (status != GL_FRAMEBUFFER_COMPLETE) { 653 615 LOG(WebGL, "GraphicsContextGLCVANGLE::copyVideoTextureToPlatformTexture(%p) - Unable to create framebuffer for outputTexture.", this); 654 616 return false; 655 617 } 656 m_context->bindTexture(GraphicsContextGL::TEXTURE_2D, 0); 657 658 m_context->useProgram(m_yuvProgram); 659 m_context->viewport(0, 0, width, height); 618 gl::BindTexture(GL_TEXTURE_2D, 0); 660 619 661 620 // Bind and set up the textures for the video source. … … 665 624 auto uvPlaneHeight = IOSurfaceGetHeightOfPlane(surface, 1); 666 625 667 GCGLenum videoTextureTarget = GraphicsContextGLOpenGL::drawingBufferTextureTarget(); 668 669 auto uvTexture = m_context->createTexture(); 670 m_context->activeTexture(GraphicsContextGL::TEXTURE1); 671 m_context->bindTexture(videoTextureTarget, uvTexture); 672 m_context->texParameteri(videoTextureTarget, GraphicsContextGL::TEXTURE_MAG_FILTER, GraphicsContextGL::LINEAR); 673 m_context->texParameteri(videoTextureTarget, GraphicsContextGL::TEXTURE_MIN_FILTER, GraphicsContextGL::LINEAR); 674 m_context->texParameteri(videoTextureTarget, GraphicsContextGL::TEXTURE_WRAP_S, GraphicsContextGL::CLAMP_TO_EDGE); 675 m_context->texParameteri(videoTextureTarget, GraphicsContextGL::TEXTURE_WRAP_T, GraphicsContextGL::CLAMP_TO_EDGE); 676 auto uvHandle = attachIOSurfaceToTexture(videoTextureTarget, GraphicsContextGL::RG, uvPlaneWidth, uvPlaneHeight, GraphicsContextGL::UNSIGNED_BYTE, surface, 1); 677 if (!uvHandle) { 678 m_context->deleteTexture(uvTexture); 626 GLenum videoTextureTarget = GraphicsContextGLOpenGL::drawingBufferTextureTarget(); 627 628 GLuint uvTexture = 0; 629 gl::GenTextures(1, &uvTexture); 630 auto uvTextureCleanup = makeScopeExit([uvTexture] { 631 gl::DeleteTextures(1, &uvTexture); 632 }); 633 gl::ActiveTexture(GL_TEXTURE1); 634 gl::BindTexture(videoTextureTarget, uvTexture); 635 gl::TexParameteri(videoTextureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 636 gl::TexParameteri(videoTextureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 637 gl::TexParameteri(videoTextureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 638 gl::TexParameteri(videoTextureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 639 auto uvHandle = WebCore::createPbufferAndAttachIOSurface(m_display, m_config, videoTextureTarget, EGL_IOSURFACE_READ_HINT_ANGLE, GL_RG, uvPlaneWidth, uvPlaneHeight, GL_UNSIGNED_BYTE, surface, 1); 640 if (!uvHandle) 679 641 return false; 680 } 681 682 auto yTexture = m_context->createTexture(); 683 m_context->activeTexture(GraphicsContextGL::TEXTURE0); 684 m_context->bindTexture(videoTextureTarget, yTexture); 685 m_context->texParameteri(videoTextureTarget, GraphicsContextGL::TEXTURE_MAG_FILTER, GraphicsContextGL::LINEAR); 686 m_context->texParameteri(videoTextureTarget, GraphicsContextGL::TEXTURE_MIN_FILTER, GraphicsContextGL::LINEAR); 687 m_context->texParameteri(videoTextureTarget, GraphicsContextGL::TEXTURE_WRAP_S, GraphicsContextGL::CLAMP_TO_EDGE); 688 m_context->texParameteri(videoTextureTarget, GraphicsContextGL::TEXTURE_WRAP_T, GraphicsContextGL::CLAMP_TO_EDGE); 689 auto yHandle = attachIOSurfaceToTexture(videoTextureTarget, GraphicsContextGL::RED, yPlaneWidth, yPlaneHeight, GraphicsContextGL::UNSIGNED_BYTE, surface, 0); 690 if (!yHandle) { 691 m_context->deleteTexture(yTexture); 692 m_context->deleteTexture(uvTexture); 642 auto uvHandleCleanup = makeScopeExit([display = m_display, uvHandle] { 643 WebCore::destroyPbufferAndDetachIOSurface(display, uvHandle); 644 }); 645 646 GLuint yTexture = 0; 647 gl::GenTextures(1, &yTexture); 648 auto yTextureCleanup = makeScopeExit([yTexture] { 649 gl::DeleteTextures(1, &yTexture); 650 }); 651 gl::ActiveTexture(GL_TEXTURE0); 652 gl::BindTexture(videoTextureTarget, yTexture); 653 gl::TexParameteri(videoTextureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 654 gl::TexParameteri(videoTextureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 655 gl::TexParameteri(videoTextureTarget, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 656 gl::TexParameteri(videoTextureTarget, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 657 auto yHandle = WebCore::createPbufferAndAttachIOSurface(m_display, m_config, videoTextureTarget, EGL_IOSURFACE_READ_HINT_ANGLE, GL_RED, yPlaneWidth, yPlaneHeight, GL_UNSIGNED_BYTE, surface, 0); 658 if (!yHandle) 693 659 return false; 694 } 660 auto yHandleCleanup = makeScopeExit([display = m_display, yHandle] { 661 destroyPbufferAndDetachIOSurface(display, yHandle); 662 }); 695 663 696 664 // Configure the drawing parameters. 697 m_context->uniform1i(m_yTextureUniformLocation, 0);698 m_context->uniform1i(m_uvTextureUniformLocation, 1);699 m_context->uniform1i(m_yuvFlipYUniformLocation, flipY == FlipY::Yes ? 1 : 0);700 m_context->uniform2f(m_yTextureSizeUniformLocation, yPlaneWidth, yPlaneHeight);701 m_context->uniform2f(m_uvTextureSizeUniformLocation, uvPlaneWidth, uvPlaneHeight);665 gl::Uniform1i(m_yTextureUniformLocation, 0); 666 gl::Uniform1i(m_uvTextureUniformLocation, 1); 667 gl::Uniform1i(m_yuvFlipYUniformLocation, flipY == FlipY::Yes ? 1 : 0); 668 gl::Uniform2f(m_yTextureSizeUniformLocation, yPlaneWidth, yPlaneHeight); 669 gl::Uniform2f(m_uvTextureSizeUniformLocation, uvPlaneWidth, uvPlaneHeight); 702 670 703 671 auto range = pixelRangeFromPixelFormat(pixelFormat); 704 672 auto transferFunction = transferFunctionFromString(dynamic_cf_cast<CFStringRef>(CVBufferGetAttachment(image, kCVImageBufferYCbCrMatrixKey, nil))); 705 673 auto colorMatrix = YCbCrToRGBMatrixForRangeAndTransferFunction(range, transferFunction); 706 m_context->uniformMatrix4fv(m_colorMatrixUniformLocation, GL_FALSE, colorMatrix);674 gl::UniformMatrix4fv(m_colorMatrixUniformLocation, 1, GL_FALSE, colorMatrix); 707 675 708 676 // Do the actual drawing. 709 m_context->drawArrays(GraphicsContextGL::TRIANGLES, 0, 6); 710 711 // Clean-up. 712 m_context->deleteTexture(yTexture); 713 m_context->deleteTexture(uvTexture); 714 detachIOSurfaceFromTexture(yHandle); 715 detachIOSurfaceFromTexture(uvHandle); 677 gl::DrawArrays(GL_TRIANGLES, 0, 6); 716 678 717 679 m_lastSurface = surface; 718 680 m_lastSurfaceSeed = newSurfaceSeed; 719 m_lastTextureSeed.set(outputTexture, m_ context->textureSeed(outputTexture));681 m_lastTextureSeed.set(outputTexture, m_owner.textureSeed(outputTexture)); 720 682 m_lastFlipY = flipY; 721 autoClearTextureOnError.re set();683 autoClearTextureOnError.release(); 722 684 return true; 723 685 } -
trunk/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.h
r270477 r283362 28 28 #if ENABLE(WEBGL) && ENABLE(VIDEO) && USE(AVFOUNDATION) 29 29 30 #import "GraphicsContextGLCV.h" 31 #import "GraphicsContextGLOpenGL.h" 30 #include "GraphicsContextGLCV.h" 32 31 33 #import <wtf/UnsafePointer.h> 32 #include <memory> 33 #include <wtf/UnsafePointer.h> 34 34 35 35 namespace WebCore { 36 class GraphicsContextGLOpenGL; 36 37 37 38 // GraphicsContextGLCV implementation for ANGLE flavour of GraphicsContextGLOpenGL. 39 // This class is part of the internal implementation of GraphicsContextGLOpenGL for ANGLE Cocoa. 38 40 class GraphicsContextGLCVANGLE final : public GraphicsContextGLCV { 39 41 WTF_MAKE_FAST_ALLOCATED; 40 42 public: 41 GraphicsContextGLCVANGLE(GraphicsContextGLOpenGL&); 43 static std::unique_ptr<GraphicsContextGLCVANGLE> create(GraphicsContextGLOpenGL&); 44 42 45 ~GraphicsContextGLCVANGLE() final; 43 46 … … 45 48 46 49 private: 47 bool initializeUVContextObjects();50 GraphicsContextGLCVANGLE(GraphicsContextGLOpenGL&); 48 51 49 52 unsigned lastTextureSeed(GCGLuint texture) … … 52 55 } 53 56 54 // Returns a handle which, if non-null, must be released via the 55 // detach call below. 56 void* attachIOSurfaceToTexture(GCGLenum target, GCGLenum internalFormat, GCGLsizei width, GCGLsizei height, GCGLenum type, IOSurfaceRef, GCGLuint plane); 57 void detachIOSurfaceFromTexture(void* handle); 58 59 Ref<GraphicsContextGLOpenGL> m_context; 57 GraphicsContextGLOpenGL& m_owner; 58 PlatformGraphicsContextGLDisplay m_display { nullptr }; 59 PlatformGraphicsContextGL m_context { nullptr }; 60 PlatformGraphicsContextGLConfig m_config { nullptr }; 60 61 61 62 PlatformGLObject m_framebuffer { 0 }; 62 PlatformGLObject m_yuvProgram { 0 };63 63 PlatformGLObject m_yuvVertexBuffer { 0 }; 64 64 GCGLint m_yTextureUniformLocation { -1 }; -
trunk/Source/WebCore/platform/graphics/opengl/GraphicsContextGLOpenGL.h
r283308 r283362 70 70 namespace WebCore { 71 71 class GraphicsContextGLIOSurfaceSwapChain; 72 class GraphicsContextGLCVANGLE; 72 73 } 73 74 #endif // PLATFORM(COCOA) … … 105 106 106 107 #if PLATFORM(COCOA) 107 static Ref<GraphicsContextGLOpenGL> createShared(GraphicsContextGLOpenGL& sharedContext);108 108 static Ref<GraphicsContextGLOpenGL> createForGPUProcess(const GraphicsContextGLAttributes&, GraphicsContextGLIOSurfaceSwapChain*); 109 109 … … 543 543 private: 544 544 #if PLATFORM(COCOA) 545 GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*, GraphicsContextGL OpenGL* sharedContext = nullptr, GraphicsContextGLIOSurfaceSwapChain* = nullptr);545 GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*, GraphicsContextGLIOSurfaceSwapChain* = nullptr); 546 546 #else 547 GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow* , GraphicsContextGLOpenGL* sharedContext = nullptr);547 GraphicsContextGLOpenGL(GraphicsContextGLAttributes, HostWindow*); 548 548 #endif 549 549 … … 551 551 // Called once by all the public entry points of ExtensionsGL that eventually call OpenGL. 552 552 bool makeContextCurrent() WARN_UNUSED_RETURN; 553 void clearCurrentContext();554 553 555 554 // Take into account the user's requested context creation attributes, … … 578 577 bool allocateAndBindDisplayBufferBacking(); 579 578 bool bindDisplayBufferBacking(std::unique_ptr<IOSurface> backing, void* pbuffer); 579 static bool makeCurrent(PlatformGraphicsContextGLDisplay, PlatformGraphicsContextGL); 580 friend class GraphicsContextGLCVANGLE; 580 581 #endif 581 582 #if USE(ANGLE) … … 794 795 #endif 795 796 #if ENABLE(VIDEO) && USE(AVFOUNDATION) 796 std::unique_ptr<GraphicsContextGLCV > m_cv;797 std::unique_ptr<GraphicsContextGLCVANGLE> m_cv; 797 798 #endif 798 799 #if USE(ANGLE) -
trunk/Source/WebCore/platform/graphics/texmap/GraphicsContextGLTextureMapper.cpp
r276528 r283362 105 105 106 106 #if USE(ANGLE) 107 GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attributes, HostWindow*, GraphicsContextGLOpenGL* sharedContext) 108 : GraphicsContextGL(attributes, sharedContext) 109 { 110 ASSERT_UNUSED(sharedContext, !sharedContext); 107 GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attributes, HostWindow*) 108 : GraphicsContextGL(attributes) 109 { 111 110 #if ENABLE(WEBGL2) 112 111 m_isForWebGL2 = attributes.webGLVersion == GraphicsContextGLWebGLVersion::WebGL2; … … 175 174 } 176 175 #else 177 GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attributes, HostWindow*, GraphicsContextGLOpenGL* sharedContext) 178 : GraphicsContextGL(attributes, sharedContext) 179 { 180 ASSERT_UNUSED(sharedContext, !sharedContext); 176 GraphicsContextGLOpenGL::GraphicsContextGLOpenGL(GraphicsContextGLAttributes attributes, HostWindow*) 177 : GraphicsContextGL(attributes) 178 { 181 179 #if USE(NICOSIA) 182 180 m_nicosiaLayer = makeUnique<Nicosia::GCGLLayer>(*this);
Note:
See TracChangeset
for help on using the changeset viewer.