|
Lines 46-58
static constexpr auto s_yuvVertexShaderTexture2D {
a/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.cpp_sec1
|
| 46 |
"attribute vec2 a_position;" |
46 |
"attribute vec2 a_position;" |
| 47 |
"uniform vec2 u_yTextureSize;" |
47 |
"uniform vec2 u_yTextureSize;" |
| 48 |
"uniform vec2 u_uvTextureSize;" |
48 |
"uniform vec2 u_uvTextureSize;" |
|
|
49 |
"uniform mat3 u_transform;" |
| 49 |
"uniform int u_flipY;" |
50 |
"uniform int u_flipY;" |
| 50 |
"varying vec2 v_yTextureCoordinate;" |
51 |
"varying vec2 v_yTextureCoordinate;" |
| 51 |
"varying vec2 v_uvTextureCoordinate;" |
52 |
"varying vec2 v_uvTextureCoordinate;" |
| 52 |
"void main()" |
53 |
"void main()" |
| 53 |
"{" |
54 |
"{" |
| 54 |
" gl_Position = vec4(a_position, 0, 1.0);" |
55 |
" gl_Position = vec4(a_position, 0, 1.0);" |
| 55 |
" vec2 normalizedPosition = a_position * .5 + .5;" |
56 |
" vec2 normalizedPosition = (u_transform * vec3(a_position * .5 + .5, 1.0)).xy;" |
| 56 |
" if (u_flipY == 1)" |
57 |
" if (u_flipY == 1)" |
| 57 |
" normalizedPosition.y = 1.0 - normalizedPosition.y;" |
58 |
" normalizedPosition.y = 1.0 - normalizedPosition.y;" |
| 58 |
" v_yTextureCoordinate = normalizedPosition;" |
59 |
" v_yTextureCoordinate = normalizedPosition;" |
|
Lines 64-76
static constexpr auto s_yuvVertexShaderTextureRectangle {
a/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.cpp_sec2
|
| 64 |
"attribute vec2 a_position;" |
65 |
"attribute vec2 a_position;" |
| 65 |
"uniform vec2 u_yTextureSize;" |
66 |
"uniform vec2 u_yTextureSize;" |
| 66 |
"uniform vec2 u_uvTextureSize;" |
67 |
"uniform vec2 u_uvTextureSize;" |
|
|
68 |
"uniform mat3 u_transform;" |
| 67 |
"uniform int u_flipY;" |
69 |
"uniform int u_flipY;" |
| 68 |
"varying vec2 v_yTextureCoordinate;" |
70 |
"varying vec2 v_yTextureCoordinate;" |
| 69 |
"varying vec2 v_uvTextureCoordinate;" |
71 |
"varying vec2 v_uvTextureCoordinate;" |
| 70 |
"void main()" |
72 |
"void main()" |
| 71 |
"{" |
73 |
"{" |
| 72 |
" gl_Position = vec4(a_position, 0, 1.0);" |
74 |
" gl_Position = vec4(a_position, 0, 1.0);" |
| 73 |
" vec2 normalizedPosition = a_position * .5 + .5;" |
75 |
" vec2 normalizedPosition = (u_transform * vec3(a_position * .5 + .5, 1.0)).xy;" |
| 74 |
" if (u_flipY == 1)" |
76 |
" if (u_flipY == 1)" |
| 75 |
" normalizedPosition.y = 1.0 - normalizedPosition.y;" |
77 |
" normalizedPosition.y = 1.0 - normalizedPosition.y;" |
| 76 |
" v_yTextureCoordinate = normalizedPosition * u_yTextureSize;" |
78 |
" v_yTextureCoordinate = normalizedPosition * u_yTextureSize;" |
|
Lines 523-528
bool GraphicsContextGLCVANGLE::initializeUVContextObjects()
a/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.cpp_sec3
|
| 523 |
m_yTextureUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_yTexture"_s); |
525 |
m_yTextureUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_yTexture"_s); |
| 524 |
m_uvTextureUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_uvTexture"_s); |
526 |
m_uvTextureUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_uvTexture"_s); |
| 525 |
m_colorMatrixUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_colorMatrix"_s); |
527 |
m_colorMatrixUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_colorMatrix"_s); |
|
|
528 |
m_transformUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_transform"_s); |
| 526 |
m_yuvFlipYUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_flipY"_s); |
529 |
m_yuvFlipYUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_flipY"_s); |
| 527 |
m_yTextureSizeUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_yTextureSize"_s); |
530 |
m_yTextureSizeUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_yTextureSize"_s); |
| 528 |
m_uvTextureSizeUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_uvTextureSize"_s); |
531 |
m_uvTextureSizeUniformLocation = m_context->getUniformLocation(m_yuvProgram, "u_uvTextureSize"_s); |
|
Lines 591-597
void GraphicsContextGLCVANGLE::detachIOSurfaceFromTexture(void* handle)
a/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.cpp_sec4
|
| 591 |
EGL_DestroySurface(display, handle); |
594 |
EGL_DestroySurface(display, handle); |
| 592 |
} |
595 |
} |
| 593 |
|
596 |
|
| 594 |
bool GraphicsContextGLCVANGLE::copyPixelBufferToTexture(CVPixelBufferRef image, PlatformGLObject outputTexture, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, FlipY flipY) |
597 |
bool GraphicsContextGLCVANGLE::copyPixelBufferToTexture(CVPixelBufferRef image, AffineTransform transform, PlatformGLObject outputTexture, GCGLint level, GCGLenum internalFormat, GCGLenum format, GCGLenum type, FlipY flipY) |
| 595 |
{ |
598 |
{ |
| 596 |
// FIXME: This currently only supports '420v' and '420f' pixel formats. Investigate supporting more pixel formats. |
599 |
// FIXME: This currently only supports '420v' and '420f' pixel formats. Investigate supporting more pixel formats. |
| 597 |
OSType pixelFormat = CVPixelBufferGetPixelFormatType(image); |
600 |
OSType pixelFormat = CVPixelBufferGetPixelFormatType(image); |
|
Lines 608-614
bool GraphicsContextGLCVANGLE::copyPixelBufferToTexture(CVPixelBufferRef image,
a/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.cpp_sec5
|
| 608 |
IOSurfaceRef surface = CVPixelBufferGetIOSurface(image); |
611 |
IOSurfaceRef surface = CVPixelBufferGetIOSurface(image); |
| 609 |
if (!surface) |
612 |
if (!surface) |
| 610 |
return false; |
613 |
return false; |
| 611 |
|
614 |
transform = *transform.inverse(); |
| 612 |
auto newSurfaceSeed = IOSurfaceGetSeed(surface); |
615 |
auto newSurfaceSeed = IOSurfaceGetSeed(surface); |
| 613 |
if (flipY == m_lastFlipY |
616 |
if (flipY == m_lastFlipY |
| 614 |
&& surface == m_lastSurface |
617 |
&& surface == m_lastSurface |
|
Lines 618-632
bool GraphicsContextGLCVANGLE::copyPixelBufferToTexture(CVPixelBufferRef image,
a/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.cpp_sec6
|
| 618 |
// image hasn't been modified since the last time it was copied, this is a no-op. |
621 |
// image hasn't been modified since the last time it was copied, this is a no-op. |
| 619 |
return true; |
622 |
return true; |
| 620 |
} |
623 |
} |
| 621 |
|
|
|
| 622 |
if (!m_yuvProgram) { |
624 |
if (!m_yuvProgram) { |
| 623 |
if (!initializeUVContextObjects()) { |
625 |
if (!initializeUVContextObjects()) { |
| 624 |
LOG(WebGL, "GraphicsContextGLCVANGLE::copyVideoTextureToPlatformTexture(%p) - Unable to initialize OpenGL context objects.", this); |
626 |
LOG(WebGL, "GraphicsContextGLCVANGLE::copyVideoTextureToPlatformTexture(%p) - Unable to initialize OpenGL context objects.", this); |
| 625 |
return false; |
627 |
return false; |
| 626 |
} |
628 |
} |
| 627 |
} |
629 |
} |
| 628 |
size_t width = CVPixelBufferGetWidth(image); |
630 |
IntRect imageRect { { }, { static_cast<int>(CVPixelBufferGetWidth(image)), static_cast<int>(CVPixelBufferGetHeight(image)) } }; |
| 629 |
size_t height = CVPixelBufferGetHeight(image); |
631 |
auto outputRect = transform.mapRect(imageRect); |
|
|
632 |
|
| 633 |
size_t width = outputRect.width(); |
| 634 |
size_t height = outputRect.height(); |
| 630 |
|
635 |
|
| 631 |
m_context->bindFramebuffer(GraphicsContextGL::FRAMEBUFFER, m_framebuffer); |
636 |
m_context->bindFramebuffer(GraphicsContextGL::FRAMEBUFFER, m_framebuffer); |
| 632 |
|
637 |
|
|
Lines 704-709
bool GraphicsContextGLCVANGLE::copyPixelBufferToTexture(CVPixelBufferRef image,
a/Source/WebCore/platform/graphics/cv/GraphicsContextGLCVANGLE.cpp_sec7
|
| 704 |
auto transferFunction = transferFunctionFromString(dynamic_cf_cast<CFStringRef>(CVBufferGetAttachment(image, kCVImageBufferYCbCrMatrixKey, nil))); |
709 |
auto transferFunction = transferFunctionFromString(dynamic_cf_cast<CFStringRef>(CVBufferGetAttachment(image, kCVImageBufferYCbCrMatrixKey, nil))); |
| 705 |
auto colorMatrix = YCbCrToRGBMatrixForRangeAndTransferFunction(range, transferFunction); |
710 |
auto colorMatrix = YCbCrToRGBMatrixForRangeAndTransferFunction(range, transferFunction); |
| 706 |
m_context->uniformMatrix4fv(m_colorMatrixUniformLocation, GL_FALSE, colorMatrix); |
711 |
m_context->uniformMatrix4fv(m_colorMatrixUniformLocation, GL_FALSE, colorMatrix); |
|
|
712 |
GLfloat transformMatrix[] = { |
| 713 |
static_cast<GLfloat>(transform.a()), |
| 714 |
static_cast<GLfloat>(transform.b()), |
| 715 |
0.f, |
| 716 |
static_cast<GLfloat>(transform.c()), |
| 717 |
static_cast<GLfloat>(transform.d()), |
| 718 |
0.f, |
| 719 |
static_cast<GLfloat>(transform.e()), |
| 720 |
static_cast<GLfloat>(transform.f()), |
| 721 |
1.f |
| 722 |
}; |
| 723 |
m_context->uniformMatrix3fv(m_transformUniformLocation, GL_FALSE, transformMatrix); |
| 707 |
|
724 |
|
| 708 |
// Do the actual drawing. |
725 |
// Do the actual drawing. |
| 709 |
m_context->drawArrays(GraphicsContextGL::TRIANGLES, 0, 6); |
726 |
m_context->drawArrays(GraphicsContextGL::TRIANGLES, 0, 6); |