WebKit Bugzilla
Attachment 372694 Details for
Bug 132869
: [Texmap][GStreamer] Add support to upload more color formats into the texture
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
WIP
bug-132869-20190623103358.patch (text/plain), 36.26 KB, created by
Zan Dobersek
on 2019-06-23 01:33:59 PDT
(
hide
)
Description:
WIP
Filename:
MIME Type:
Creator:
Zan Dobersek
Created:
2019-06-23 01:33:59 PDT
Size:
36.26 KB
patch
obsolete
>Subversion Revision: 246709 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 80896f8e9f86f52bb683773c1f23577bb9458c6b..05addcaaf45500bb6bb6131557d11c71f8068091 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,43 @@ >+2019-06-23 Zan Dobersek <zdobersek@igalia.com> >+ >+ [Texmap][GStreamer] Add support to upload more color formats into the texture >+ https://bugs.webkit.org/show_bug.cgi?id=132869 >+ >+ Reviewed by NOBODY (OOPS!). >+ >+ No new tests (OOPS!). >+ >+ * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp: >+ (WebCore::GstVideoFrameHolder::GstVideoFrameHolder): >+ (WebCore::GstVideoFrameHolder::hasMappedTextures const): >+ (WebCore::GstVideoFrameHolder::videoFrame const): >+ (WebCore::MediaPlayerPrivateGStreamerBase::requestGLContext): >+ (WebCore::MediaPlayerPrivateGStreamerBase::ensureGstGLContext): >+ (WebCore::MediaPlayerPrivateGStreamerBase::pushTextureToCompositor): >+ (WebCore::MediaPlayerPrivateGStreamerBase::copyVideoTextureToPlatformTexture): >+ (WebCore::MediaPlayerPrivateGStreamerBase::createGLAppSink): >+ * platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h: >+ (WebCore::MediaPlayerPrivateGStreamerBase::gstGLContext const): Deleted. >+ * platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp: >+ (WebCore::VideoTextureCopierGStreamer::VideoTextureCopierGStreamer): >+ * platform/graphics/texmap/TextureMapperGL.cpp: >+ (WebCore::optionsForFilterType): >+ (WebCore::TextureMapperGL::drawTexture): >+ (WebCore::TextureMapperGL::drawTextureYUV): >+ * platform/graphics/texmap/TextureMapperGL.h: >+ * platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp: >+ (WebCore::TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer): >+ (WebCore::TextureMapperPlatformLayerBuffer::~TextureMapperPlatformLayerBuffer): >+ (WebCore::TextureMapperPlatformLayerBuffer::clone): >+ (WebCore::TextureMapperPlatformLayerBuffer::paintToTextureMapper): >+ * platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h: >+ * platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp: >+ (WebCore::TextureMapperPlatformLayerProxy::swapBuffer): >+ * platform/graphics/texmap/TextureMapperPlatformLayerProxy.h: >+ * platform/graphics/texmap/TextureMapperShaderProgram.cpp: >+ (WebCore::TextureMapperShaderProgram::create): >+ * platform/graphics/texmap/TextureMapperShaderProgram.h: >+ > 2019-06-21 Sihui Liu <sihui_liu@apple.com> > > openDatabase should return an empty object when WebSQL is disabled >diff --git a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp >index 205ee4bd296cc359062dec978b5a19cf405f3d5f..b8d9f6e1b8d66496fa50967139a76bddc95e7222 100644 >--- a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp >+++ b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.cpp >@@ -55,11 +55,11 @@ > > #if USE(GSTREAMER_GL) > #if G_BYTE_ORDER == G_LITTLE_ENDIAN >-#define GST_GL_CAPS_FORMAT "{ BGRx, BGRA }" >+#define GST_GL_CAPS_FORMAT "{ BGRx, BGRA, I420 }" > #define TEXTURE_MAPPER_COLOR_CONVERT_FLAG TextureMapperGL::ShouldConvertTextureBGRAToRGBA > #define TEXTURE_COPIER_COLOR_CONVERT_FLAG VideoTextureCopierGStreamer::ColorConversion::ConvertBGRAToRGBA > #else >-#define GST_GL_CAPS_FORMAT "{ xRGB, ARGB }" >+#define GST_GL_CAPS_FORMAT "{ xRGB, ARGB, I420 }" > #define TEXTURE_MAPPER_COLOR_CONVERT_FLAG TextureMapperGL::ShouldConvertTextureARGBToRGBA > #define TEXTURE_COPIER_COLOR_CONVERT_FLAG VideoTextureCopierGStreamer::ColorConversion::ConvertARGBToRGBA > #endif >@@ -153,7 +153,7 @@ static int greatestCommonDivisor(int a, int b) > #if USE(TEXTURE_MAPPER_GL) > class GstVideoFrameHolder : public TextureMapperPlatformLayerBuffer::UnmanagedBufferDataHolder { > public: >- explicit GstVideoFrameHolder(GstSample* sample, TextureMapperGL::Flags flags, bool gstGLEnabled) >+ explicit GstVideoFrameHolder(GstGLContext* context, GstSample* sample, TextureMapperGL::Flags flags, bool gstGLEnabled) > { > GstVideoInfo videoInfo; > if (UNLIKELY(!getSampleVideoInfo(sample, videoInfo))) >@@ -170,8 +170,10 @@ public: > > if (gstGLEnabled) { > m_isMapped = gst_video_frame_map(&m_videoFrame, &videoInfo, m_buffer, static_cast<GstMapFlags>(GST_MAP_READ | GST_MAP_GL)); >- if (m_isMapped) >+ if (m_isMapped) { > m_textureID = *reinterpret_cast<GLuint*>(m_videoFrame.data[0]); >+ m_hasMappedTextures = true; >+ } > } else > #else > UNUSED_PARAM(flags); >@@ -186,6 +188,12 @@ public: > ASSERT(GST_VIDEO_INFO_N_PLANES(&videoInfo) == 1); > } > } >+ >+ { >+ GstGLSyncMeta* meta = gst_buffer_get_gl_sync_meta (m_buffer); >+ if (meta) >+ gst_gl_sync_meta_wait_cpu(meta, context); >+ } > } > > virtual ~GstVideoFrameHolder() >@@ -200,6 +208,8 @@ public: > bool hasAlphaChannel() const { return m_hasAlphaChannel; } > TextureMapperGL::Flags flags() const { return m_flags; } > GLuint textureID() const { return m_textureID; } >+ bool hasMappedTextures() const { return m_hasMappedTextures; } >+ const GstVideoFrame& videoFrame() const { return m_videoFrame; } > > void updateTexture(BitmapTextureGL& texture) > { >@@ -227,6 +237,7 @@ private: > TextureMapperGL::Flags m_flags { }; > GLuint m_textureID { 0 }; > bool m_isMapped { false }; >+ bool m_hasMappedTextures { false }; > }; > #endif > >@@ -400,9 +411,20 @@ GstContext* MediaPlayerPrivateGStreamerBase::requestGLContext(const char* contex > GstContext* appContext = gst_context_new("gst.gl.app_context", TRUE); > GstStructure* structure = gst_context_writable_structure(appContext); > #if GST_CHECK_VERSION(1, 12, 0) >- gst_structure_set(structure, "context", GST_TYPE_GL_CONTEXT, gstGLContext(), nullptr); >+ gst_structure_set(structure, "context", GST_TYPE_GL_CONTEXT, m_glSharingContext.get(), nullptr); >+#else >+ gst_structure_set(structure, "context", GST_GL_TYPE_CONTEXT, m_glSharingContext.get(), nullptr); >+#endif >+ return appContext; >+ } >+ >+ if (!g_strcmp0(contextType, "gst.gl.local_context")) { >+ GstContext* appContext = gst_context_new("gst.gl.local_context", TRUE); >+ GstStructure* structure = gst_context_writable_structure(appContext); >+#if GST_CHECK_VERSION(1, 12, 0) >+ gst_structure_set(structure, "context", GST_TYPE_GL_CONTEXT, m_glMainContext.get(), nullptr); > #else >- gst_structure_set(structure, "context", GST_GL_TYPE_CONTEXT, gstGLContext(), nullptr); >+ gst_structure_set(structure, "context", GST_GL_TYPE_CONTEXT, m_glMainContext.get(), nullptr); > #endif > return appContext; > } >@@ -412,7 +434,7 @@ GstContext* MediaPlayerPrivateGStreamerBase::requestGLContext(const char* contex > > bool MediaPlayerPrivateGStreamerBase::ensureGstGLContext() > { >- if (m_glContext) >+ if (m_glMainContext && m_glSharingContext) > return true; > > auto& sharedDisplay = PlatformDisplay::sharedDisplayForCompositing(); >@@ -480,9 +502,13 @@ bool MediaPlayerPrivateGStreamerBase::ensureGstGLContext() > return false; > > if (shouldAdoptRef) >- m_glContext = adoptGRef(gst_gl_context_new_wrapped(m_glDisplay.get(), reinterpret_cast<guintptr>(contextHandle), glPlatform, glAPI)); >+ m_glSharingContext = adoptGRef(gst_gl_context_new_wrapped(m_glDisplay.get(), reinterpret_cast<guintptr>(contextHandle), glPlatform, glAPI)); > else >- m_glContext = gst_gl_context_new_wrapped(m_glDisplay.get(), reinterpret_cast<guintptr>(contextHandle), glPlatform, glAPI); >+ m_glSharingContext = gst_gl_context_new_wrapped(m_glDisplay.get(), reinterpret_cast<guintptr>(contextHandle), glPlatform, glAPI); >+ >+ m_glMainContext = gst_gl_context_new(m_glDisplay.get()); >+ if (m_glMainContext) >+ gst_gl_context_create(m_glMainContext.get(), m_glSharingContext.get(), nullptr); > > return true; > } >@@ -715,12 +741,47 @@ void MediaPlayerPrivateGStreamerBase::pushTextureToCompositor() > if (!proxy.isActive()) > return; > >- std::unique_ptr<GstVideoFrameHolder> frameHolder = std::make_unique<GstVideoFrameHolder>(m_sample.get(), m_textureMapperFlags, !m_usingFallbackVideoSink); >+ std::unique_ptr<GstVideoFrameHolder> frameHolder = std::make_unique<GstVideoFrameHolder>(m_glMainContext.get(), m_sample.get(), m_textureMapperFlags, !m_usingFallbackVideoSink); >+ >+ using Buffer = TextureMapperPlatformLayerBuffer; >+ std::unique_ptr<Buffer> layerBuffer; >+ if (frameHolder->hasMappedTextures()) { >+ auto& videoFrame = frameHolder->videoFrame(); >+ [&] { >+ if (GST_VIDEO_INFO_IS_RGB(&videoFrame.info)) { >+ if (GST_VIDEO_INFO_N_PLANES(&videoFrame.info) != 1) >+ return; >+ >+ layerBuffer = std::make_unique<Buffer>( >+ Buffer::TextureVariant { Buffer::RGBTexture { >+ *static_cast<GLuint*>(videoFrame.data[0]) >+ } }, frameHolder->size(), frameHolder->flags(), GraphicsContext3D::RGBA); >+ return; >+ } >+ >+ if (GST_VIDEO_INFO_IS_YUV(&videoFrame.info)) { >+ if (GST_VIDEO_INFO_N_PLANES(&videoFrame.info) != 3) >+ return; >+ >+ if (m_videoDecoderPlatform == WebKitGstVideoDecoderPlatform::ImxVPU) { >+ layerBuffer = std::make_unique<Buffer>( >+ Buffer::TextureVariant { Buffer::RGBTexture { >+ *static_cast<GLuint*>(videoFrame.data[0]) >+ } }, frameHolder->size(), frameHolder->flags(), GraphicsContext3D::RGBA); >+ } else { >+ layerBuffer = std::make_unique<Buffer>( >+ Buffer::TextureVariant { Buffer::YUVTexture { >+ *static_cast<GLuint*>(videoFrame.data[0]), >+ *static_cast<GLuint*>(videoFrame.data[1]), >+ *static_cast<GLuint*>(videoFrame.data[2]) >+ } }, frameHolder->size(), frameHolder->flags(), GraphicsContext3D::RGBA); >+ } >+ } >+ }(); >+ >+ if (!layerBuffer) >+ return; > >- GLuint textureID = frameHolder->textureID(); >- std::unique_ptr<TextureMapperPlatformLayerBuffer> layerBuffer; >- if (textureID) { >- layerBuffer = std::make_unique<TextureMapperPlatformLayerBuffer>(textureID, frameHolder->size(), frameHolder->flags(), GraphicsContext3D::RGBA); > layerBuffer->setUnmanagedBufferDataHolder(WTFMove(frameHolder)); > } else { > layerBuffer = proxy.getAvailableBuffer(frameHolder->size(), GL_DONT_CARE); >@@ -917,7 +978,7 @@ bool MediaPlayerPrivateGStreamerBase::copyVideoTextureToPlatformTexture(Graphics > if (!GST_IS_SAMPLE(m_sample.get())) > return false; > >- std::unique_ptr<GstVideoFrameHolder> frameHolder = std::make_unique<GstVideoFrameHolder>(m_sample.get(), m_textureMapperFlags, true); >+ std::unique_ptr<GstVideoFrameHolder> frameHolder = std::make_unique<GstVideoFrameHolder>(m_glMainContext.get(), m_sample.get(), m_textureMapperFlags, true); > > auto textureID = frameHolder->textureID(); > if (!textureID) >@@ -1042,6 +1103,23 @@ GstElement* MediaPlayerPrivateGStreamerBase::createGLAppSink() > > GRefPtr<GstPad> pad = adoptGRef(gst_element_get_static_pad(appsink, "sink")); > gst_pad_add_probe(pad.get(), static_cast<GstPadProbeType>(GST_PAD_PROBE_TYPE_PUSH | GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM | GST_PAD_PROBE_TYPE_EVENT_FLUSH), [] (GstPad*, GstPadProbeInfo* info, gpointer userData) -> GstPadProbeReturn { >+ auto* player = static_cast<MediaPlayerPrivateGStreamerBase*>(userData); >+ >+ if (info->type & GST_PAD_PROBE_TYPE_QUERY_DOWNSTREAM) { >+ GstQuery* query = GST_PAD_PROBE_INFO_QUERY(info); >+ if (GST_QUERY_TYPE(query) == GST_QUERY_CONTEXT) { >+ const char* contextType; >+ gst_query_parse_context_type(query, &contextType); >+ if (!g_strcmp0(contextType, "gst.gl.local_context")) { >+ auto* context = player->requestGLContext(contextType); >+ if (context) >+ gst_query_set_context(query, context); >+ return GST_PAD_PROBE_HANDLED; >+ } >+ } >+ return GST_PAD_PROBE_OK; >+ } >+ > // In some platforms (e.g. OpenMAX on the Raspberry Pi) when a resolution change occurs the > // pipeline has to be drained before a frame with the new resolution can be decoded. > // In this context, it's important that we don't hold references to any previous frame >@@ -1058,7 +1136,6 @@ GstElement* MediaPlayerPrivateGStreamerBase::createGLAppSink() > GST_DEBUG("Acting upon flush-start event"); > } > >- auto* player = static_cast<MediaPlayerPrivateGStreamerBase*>(userData); > player->flushCurrentBuffer(); > return GST_PAD_PROBE_OK; > }, this, nullptr); >diff --git a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h >index 59afdfcc01b609b5c595484fd0fc76575e90c9ef..8a32cebf6c29e269cddfd583b2f79f844ed43e27 100644 >--- a/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h >+++ b/Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamerBase.h >@@ -186,7 +186,6 @@ protected: > void flushCurrentBuffer(); > GstElement* createGLAppSink(); > GstElement* createVideoSinkGL(); >- GstGLContext* gstGLContext() const { return m_glContext.get(); } > GstGLDisplay* gstGLDisplay() const { return m_glDisplay.get(); } > void ensureGLVideoSinkContext(); > #endif >@@ -270,8 +269,10 @@ protected: > #endif > > #if USE(GSTREAMER_GL) >- GRefPtr<GstGLContext> m_glContext; > GRefPtr<GstGLDisplay> m_glDisplay; >+ GRefPtr<GstGLContext> m_glMainContext; >+ GRefPtr<GstGLContext> m_glSharingContext; >+ > GRefPtr<GstContext> m_glDisplayElementContext; > GRefPtr<GstContext> m_glAppElementContext; > std::unique_ptr<VideoTextureCopierGStreamer> m_videoTextureCopier; >diff --git a/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp b/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp >index 135333ea1b515eb5f5101cba56dbd672d80837df..c42d916b0f71bb1f3655bb61dadc9926e460158b 100644 >--- a/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp >+++ b/Source/WebCore/platform/graphics/gstreamer/VideoTextureCopierGStreamer.cpp >@@ -35,7 +35,7 @@ VideoTextureCopierGStreamer::VideoTextureCopierGStreamer(ColorConversion colorCo > ASSERT(previousContext); > PlatformDisplay::sharedDisplayForCompositing().sharingGLContext()->makeContextCurrent(); > >- m_shaderProgram = TextureMapperShaderProgram::create(TextureMapperShaderProgram::Texture); >+ m_shaderProgram = TextureMapperShaderProgram::create(TextureMapperShaderProgram::TextureRGB); > > glGenFramebuffers(1, &m_framebuffer); > glGenTextures(1, &m_resultTexture); >diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp >index 974b8578b88aa6435091e8b0c38bb2db710ef102..5f4ce23e025052ae4ffe896fd2eb975417f36c62 100644 >--- a/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp >+++ b/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp >@@ -319,21 +319,21 @@ static TextureMapperShaderProgram::Options optionsForFilterType(FilterOperation: > { > switch (type) { > case FilterOperation::GRAYSCALE: >- return TextureMapperShaderProgram::Texture | TextureMapperShaderProgram::GrayscaleFilter; >+ return TextureMapperShaderProgram::TextureRGB | TextureMapperShaderProgram::GrayscaleFilter; > case FilterOperation::SEPIA: >- return TextureMapperShaderProgram::Texture | TextureMapperShaderProgram::SepiaFilter; >+ return TextureMapperShaderProgram::TextureRGB | TextureMapperShaderProgram::SepiaFilter; > case FilterOperation::SATURATE: >- return TextureMapperShaderProgram::Texture | TextureMapperShaderProgram::SaturateFilter; >+ return TextureMapperShaderProgram::TextureRGB | TextureMapperShaderProgram::SaturateFilter; > case FilterOperation::HUE_ROTATE: >- return TextureMapperShaderProgram::Texture | TextureMapperShaderProgram::HueRotateFilter; >+ return TextureMapperShaderProgram::TextureRGB | TextureMapperShaderProgram::HueRotateFilter; > case FilterOperation::INVERT: >- return TextureMapperShaderProgram::Texture | TextureMapperShaderProgram::InvertFilter; >+ return TextureMapperShaderProgram::TextureRGB | TextureMapperShaderProgram::InvertFilter; > case FilterOperation::BRIGHTNESS: >- return TextureMapperShaderProgram::Texture | TextureMapperShaderProgram::BrightnessFilter; >+ return TextureMapperShaderProgram::TextureRGB | TextureMapperShaderProgram::BrightnessFilter; > case FilterOperation::CONTRAST: >- return TextureMapperShaderProgram::Texture | TextureMapperShaderProgram::ContrastFilter; >+ return TextureMapperShaderProgram::TextureRGB | TextureMapperShaderProgram::ContrastFilter; > case FilterOperation::OPACITY: >- return TextureMapperShaderProgram::Texture | TextureMapperShaderProgram::OpacityFilter; >+ return TextureMapperShaderProgram::TextureRGB | TextureMapperShaderProgram::OpacityFilter; > case FilterOperation::BLUR: > return TextureMapperShaderProgram::BlurFilter; > case FilterOperation::DROP_SHADOW: >@@ -470,7 +470,7 @@ void TextureMapperGL::drawTexture(GLuint texture, Flags flags, const IntSize& te > && exposedEdges == AllEdges > && !modelViewMatrix.mapQuad(targetRect).isRectilinear(); > >- TextureMapperShaderProgram::Options options = TextureMapperShaderProgram::Texture; >+ TextureMapperShaderProgram::Options options = TextureMapperShaderProgram::TextureRGB; > if (useRect) > options |= TextureMapperShaderProgram::Rect; > if (opacity < 1) >@@ -504,6 +504,114 @@ void TextureMapperGL::drawTexture(GLuint texture, Flags flags, const IntSize& te > drawTexturedQuadWithProgram(program.get(), texture, flags, textureSize, targetRect, modelViewMatrix, opacity); > } > >+void TextureMapperGL::drawTextureYUV(const std::array<GLuint,3>& textures, Flags flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, unsigned exposedEdges) >+{ >+ bool useRect = flags & ShouldUseARBTextureRect; >+ bool useAntialiasing = m_enableEdgeDistanceAntialiasing >+ && exposedEdges == AllEdges >+ && !modelViewMatrix.mapQuad(targetRect).isRectilinear(); >+ >+ TextureMapperShaderProgram::Options options = TextureMapperShaderProgram::TextureYUV; >+ if (useRect) >+ options |= TextureMapperShaderProgram::Rect; >+ if (opacity < 1) >+ options |= TextureMapperShaderProgram::Opacity; >+ if (useAntialiasing) { >+ options |= TextureMapperShaderProgram::Antialiasing; >+ flags |= ShouldAntialias; >+ } >+ if (wrapMode() == RepeatWrap && !m_contextAttributes.supportsNPOTTextures) >+ options |= TextureMapperShaderProgram::ManualRepeat; >+ >+ RefPtr<FilterOperation> filter = data().filterInfo ? data().filterInfo->filter: 0; >+ GLuint filterContentTextureID = 0; >+ >+ if (filter) { >+ if (data().filterInfo->contentTexture) >+ filterContentTextureID = toBitmapTextureGL(data().filterInfo->contentTexture.get())->id(); >+ options |= optionsForFilterType(filter->type(), data().filterInfo->pass); >+ if (filter->affectsOpacity()) >+ flags |= ShouldBlend; >+ } >+ >+ if (useAntialiasing || opacity < 1) >+ flags |= ShouldBlend; >+ >+ Ref<TextureMapperShaderProgram> program = data().getShaderProgram(options); >+ >+ if (filter) >+ prepareFilterProgram(program.get(), *filter.get(), data().filterInfo->pass, textureSize, filterContentTextureID); >+ >+ { >+ glUseProgram(program->programID()); >+ { >+ GLenum target = flags & ShouldUseARBTextureRect ? GLenum(GL_TEXTURE_RECTANGLE_ARB) : GLenum(GL_TEXTURE_2D); >+ std::array<GLuint, 3> samplers = { >+ program->samplerYLocation(), >+ program->samplerULocation(), >+ program->samplerVLocation(), >+ }; >+ >+ for (unsigned i : { 0, 1, 2 }) { >+ glActiveTexture(GL_TEXTURE0 + i); >+ glBindTexture(target, textures[i]); >+ glUniform1i(samplers[i], i); >+ >+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); >+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); >+ if (wrapMode() == RepeatWrap && m_contextAttributes.supportsNPOTTextures) { >+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); >+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); >+ } else { >+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); >+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); >+ } >+ } >+ } >+ >+ TransformationMatrix patternTransform = this->patternTransform(); >+ if (flags & ShouldRotateTexture90) { >+ patternTransform.rotate(-90); >+ patternTransform.translate(-1, 0); >+ } >+ if (flags & ShouldRotateTexture180) { >+ patternTransform.rotate(180); >+ patternTransform.translate(-1, -1); >+ } >+ if (flags & ShouldRotateTexture270) { >+ patternTransform.rotate(-270); >+ patternTransform.translate(0, -1); >+ } >+ if (flags & ShouldFlipTexture) >+ patternTransform.flipY(); >+ if (flags & ShouldUseARBTextureRect) >+ patternTransform.scaleNonUniform(textureSize.width(), textureSize.height()); >+ if (flags & ShouldFlipTexture) >+ patternTransform.translate(0, -1); >+ >+ program->setMatrix(program->textureSpaceMatrixLocation(), patternTransform); >+ program->setMatrix(program->textureColorSpaceMatrixLocation(), colorSpaceMatrixForFlags(flags)); >+ glUniform1f(program->opacityLocation(), opacity); >+ >+ if (opacity < 1) >+ flags |= ShouldBlend; >+ >+ draw(targetRect, modelViewMatrix, program, GL_TRIANGLE_FAN, flags); >+ >+ { >+ GLenum target = flags & ShouldUseARBTextureRect ? GLenum(GL_TEXTURE_RECTANGLE_ARB) : GLenum(GL_TEXTURE_2D); >+ >+ for (unsigned i : { 0, 1, 2 }) { >+ glBindTexture(target, textures[i]); >+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); >+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); >+ } >+ >+ glBindTexture(target, 0); >+ } >+ } >+} >+ > void TextureMapperGL::drawSolidColor(const FloatRect& rect, const TransformationMatrix& matrix, const Color& color, bool isBlendingAllowed) > { > Flags flags = 0; >diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h b/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h >index ca056af66030ed1eed92fa5c2a28da90cb34eb6a..b2302a0b38be24db46bb9b3f8ae66a7ca9b0fb9d 100644 >--- a/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h >+++ b/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h >@@ -30,6 +30,7 @@ > #include "TextureMapperContextAttributes.h" > #include "TextureMapperGLHeaders.h" > #include "TransformationMatrix.h" >+#include <array> > > namespace WebCore { > >@@ -64,6 +65,7 @@ public: > void drawNumber(int number, const Color&, const FloatPoint&, const TransformationMatrix&) override; > void drawTexture(const BitmapTexture&, const FloatRect&, const TransformationMatrix&, float opacity, unsigned exposedEdges) override; > virtual void drawTexture(GLuint texture, Flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, unsigned exposedEdges = AllEdges); >+ void drawTextureYUV(const std::array<GLuint, 3>& textures, Flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, unsigned exposedEdges = AllEdges); > void drawSolidColor(const FloatRect&, const TransformationMatrix&, const Color&, bool) override; > void clearColor(const Color&) override; > >diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp >index 7afdf30a05bca5397b8018bfebd89e0e1da50333..ffe035646c16c12a876508cd625cb1e2fed9161b 100644 >--- a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp >+++ b/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp >@@ -35,20 +35,40 @@ namespace WebCore { > > TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer(RefPtr<BitmapTexture>&& texture, TextureMapperGL::Flags flags) > : m_texture(WTFMove(texture)) >- , m_textureID(0) >+ , m_variant(RGBTexture { 0 }) > , m_extraFlags(flags) > , m_hasManagedTexture(true) > { > } > >+#if 0 > TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer(GLuint textureID, const IntSize& size, TextureMapperGL::Flags flags, GLint internalFormat) >- : m_textureID(textureID) >+ : m_variant(RGBTexture { textureID }) > , m_size(size) > , m_internalFormat(internalFormat) > , m_extraFlags(flags) > , m_hasManagedTexture(false) > { > } >+#endif >+ >+TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer(GLuint textureID, const IntSize& size, TextureMapperGL::Flags flags, GLint internalFormat) >+ : TextureMapperPlatformLayerBuffer({ RGBTexture { textureID } }, size, flags, internalFormat) >+{ >+} >+ >+TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer(TextureVariant&& variant, const IntSize& size, TextureMapperGL::Flags flags, GLint internalFormat) >+ : m_variant(WTFMove(variant)) >+ , m_size(size) >+ , m_internalFormat(internalFormat) >+ , m_extraFlags(flags) >+ , m_hasManagedTexture(false) >+{ >+} >+ >+TextureMapperPlatformLayerBuffer::~TextureMapperPlatformLayerBuffer() >+{ >+} > > bool TextureMapperPlatformLayerBuffer::canReuseWithoutReset(const IntSize& size, GLint internalFormat) > { >@@ -57,14 +77,24 @@ bool TextureMapperPlatformLayerBuffer::canReuseWithoutReset(const IntSize& size, > > std::unique_ptr<TextureMapperPlatformLayerBuffer> TextureMapperPlatformLayerBuffer::clone() > { >- if (m_hasManagedTexture || !m_textureID) { >+ if (m_hasManagedTexture) { > notImplemented(); > return nullptr; > } >- auto texture = BitmapTextureGL::create(TextureMapperContextAttributes::get(), m_internalFormat); >- texture->reset(m_size); >- static_cast<BitmapTextureGL&>(texture.get()).copyFromExternalTexture(m_textureID); >- return std::make_unique<TextureMapperPlatformLayerBuffer>(WTFMove(texture), m_extraFlags); >+ >+ return WTF::switchOn(m_variant, >+ [&](const RGBTexture& texture) >+ { >+ auto clonedTexture = BitmapTextureGL::create(TextureMapperContextAttributes::get(), m_internalFormat); >+ clonedTexture->reset(m_size); >+ static_cast<BitmapTextureGL&>(clonedTexture.get()).copyFromExternalTexture(texture.id); >+ return std::make_unique<TextureMapperPlatformLayerBuffer>(WTFMove(clonedTexture), m_extraFlags); >+ }, >+ [](const YUVTexture&) >+ { >+ notImplemented(); >+ return nullptr; >+ }); > } > > void TextureMapperPlatformLayerBuffer::paintToTextureMapper(TextureMapper& textureMapper, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity) >@@ -86,8 +116,19 @@ void TextureMapperPlatformLayerBuffer::paintToTextureMapper(TextureMapper& textu > return; > } > >- ASSERT(m_textureID); >- texmapGL.drawTexture(m_textureID, m_extraFlags, m_size, targetRect, modelViewMatrix, opacity); >+ glFinish(); >+ >+ WTF::switchOn(m_variant, >+ [&](const RGBTexture& texture) >+ { >+ ASSERT(texture.id); >+ texmapGL.drawTexture(texture.id, m_extraFlags, m_size, targetRect, modelViewMatrix, opacity); >+ }, >+ [&](const YUVTexture& texture) >+ { >+ texmapGL.drawTextureYUV(std::array<GLuint, 3> { texture.y, texture.u, texture.v }, >+ m_extraFlags, m_size, targetRect, modelViewMatrix, opacity); >+ }); > } > > } // namespace WebCore >diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h b/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h >index d100e24ad131649794b90692e6612a37ab7c9aeb..e2a8b8c09291eeebe59f3215f21a0ded28bf8cff 100644 >--- a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h >+++ b/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h >@@ -31,6 +31,7 @@ > #include "TextureMapperGLHeaders.h" > #include "TextureMapperPlatformLayer.h" > #include <wtf/MonotonicTime.h> >+#include <wtf/Variant.h> > > namespace WebCore { > >@@ -39,9 +40,20 @@ class TextureMapperPlatformLayerBuffer : public TextureMapperPlatformLayer { > WTF_MAKE_FAST_ALLOCATED(); > public: > TextureMapperPlatformLayerBuffer(RefPtr<BitmapTexture>&&, TextureMapperGL::Flags = 0); >+ > TextureMapperPlatformLayerBuffer(GLuint textureID, const IntSize&, TextureMapperGL::Flags, GLint internalFormat); >+ struct RGBTexture { >+ GLuint id; >+ }; >+ struct YUVTexture { >+ GLuint y; >+ GLuint u; >+ GLuint v; >+ }; >+ using TextureVariant = WTF::Variant<RGBTexture, YUVTexture>; >+ TextureMapperPlatformLayerBuffer(TextureVariant&&, const IntSize&, TextureMapperGL::Flags, GLint internalFormat); > >- virtual ~TextureMapperPlatformLayerBuffer() = default; >+ virtual ~TextureMapperPlatformLayerBuffer(); > > void paintToTextureMapper(TextureMapper&, const FloatRect&, const TransformationMatrix& modelViewMatrix = TransformationMatrix(), float opacity = 1.0) final; > >@@ -78,6 +90,7 @@ private: > RefPtr<BitmapTexture> m_texture; > MonotonicTime m_timeLastUsed; > >+ TextureVariant m_variant; > GLuint m_textureID; > IntSize m_size; > GLint m_internalFormat; >diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp >index c714f6d78c1cf1a61d4dff6b420521b02ecd7c50..eb4e77bc79024732ce14df3dbd96ce921cef5db5 100644 >--- a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp >+++ b/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.cpp >@@ -185,8 +185,12 @@ void TextureMapperPlatformLayerProxy::swapBuffer() > m_currentBuffer = WTFMove(m_pendingBuffer); > m_targetLayer->setContentsLayer(m_currentBuffer.get()); > >- if (prevBuffer && prevBuffer->hasManagedTexture()) >- appendToUnusedBuffers(WTFMove(prevBuffer)); >+ if (prevBuffer) { >+ if (prevBuffer->hasManagedTexture()) >+ appendToUnusedBuffers(WTFMove(prevBuffer)); >+ else >+ m_prevBuffer = WTFMove(prevBuffer); >+ } > } > > void TextureMapperPlatformLayerProxy::dropCurrentBufferWhilePreservingTexture(bool shouldWait) >diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h b/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h >index d38e6c21f61fb40795c9655334d1f0c35643dadf..b3760986acdb8aef6fd15a12a822cf1cbe3ae2d0 100644 >--- a/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h >+++ b/Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxy.h >@@ -83,6 +83,7 @@ private: > > std::unique_ptr<TextureMapperPlatformLayerBuffer> m_currentBuffer; > std::unique_ptr<TextureMapperPlatformLayerBuffer> m_pendingBuffer; >+ std::unique_ptr<TextureMapperPlatformLayerBuffer> m_prevBuffer; > > Lock m_lock; > >diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp b/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp >index eb8788d4ff5e889fbaf46c6016995300a78d710d..9fd18bc8b6699340c6a275cf61761e3071d1cde3 100644 >--- a/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp >+++ b/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp >@@ -207,6 +207,9 @@ static const char* fragmentTemplateGE320Vars = > static const char* fragmentTemplateCommon = > STRINGIFY( > uniform SamplerType s_sampler; >+ uniform SamplerType s_samplerY; >+ uniform SamplerType s_samplerU; >+ uniform SamplerType s_samplerV; > uniform sampler2D s_contentTexture; > uniform float u_opacity; > uniform float u_filterAmount; >@@ -231,7 +234,15 @@ static const char* fragmentTemplateCommon = > > void applyManualRepeat(inout vec2 pos) { pos = fract(pos); } > >- void applyTexture(inout vec4 color, vec2 texCoord) { color = u_textureColorSpaceMatrix * SamplerFunction(s_sampler, texCoord); } >+ void applyTextureRGB(inout vec4 color, vec2 texCoord) { color = u_textureColorSpaceMatrix * SamplerFunction(s_sampler, texCoord); } >+ void applyTextureYUV(inout vec4 color, vec2 texCoord) >+ { >+ float y = SamplerFunction(s_samplerY, texCoord).r; >+ float u = SamplerFunction(s_samplerU, texCoord).r - 0.5; >+ float v = SamplerFunction(s_samplerV, texCoord).r - 0.5; >+ vec4 data = vec4(y + 1.402 * v, y - 0.344 * u - 0.714 * v, y + 1.772 * u , 1); >+ color = u_textureColorSpaceMatrix * data.bgra; >+ } > void applyOpacity(inout vec4 color) { color *= u_opacity; } > void applyAntialiasing(inout vec4 color) { color *= antialias(); } > >@@ -343,7 +354,8 @@ static const char* fragmentTemplateCommon = > vec4 color = vec4(1., 1., 1., 1.); > vec2 texCoord = transformTexCoord(); > applyManualRepeatIfNeeded(texCoord); >- applyTextureIfNeeded(color, texCoord); >+ applyTextureRGBIfNeeded(color, texCoord); >+ applyTextureYUVIfNeeded(color, texCoord); > applySolidColorIfNeeded(color); > applyAntialiasingIfNeeded(color); > applyOpacityIfNeeded(color); >@@ -369,7 +381,8 @@ Ref<TextureMapperShaderProgram> TextureMapperShaderProgram::create(TextureMapper > (options & TextureMapperShaderProgram::Applier) ? ENABLE_APPLIER(Applier) : DISABLE_APPLIER(Applier)) > > StringBuilder optionsApplierBuilder; >- SET_APPLIER_FROM_OPTIONS(Texture); >+ SET_APPLIER_FROM_OPTIONS(TextureRGB); >+ SET_APPLIER_FROM_OPTIONS(TextureYUV); > SET_APPLIER_FROM_OPTIONS(Rect); > SET_APPLIER_FROM_OPTIONS(SolidColor); > SET_APPLIER_FROM_OPTIONS(Opacity); >diff --git a/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.h b/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.h >index 4a3420c0602cb4d60a498b9475a3f397d2d71f19..38328d6ed192c60627c261e5ac0febe49feddb87 100644 >--- a/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.h >+++ b/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.h >@@ -45,7 +45,7 @@ namespace WebCore { > class TextureMapperShaderProgram : public RefCounted<TextureMapperShaderProgram> { > public: > enum Option { >- Texture = 1L << 0, >+ TextureRGB = 1L << 0, > Rect = 1L << 1, > SolidColor = 1L << 2, > Opacity = 1L << 3, >@@ -61,7 +61,8 @@ public: > BlurFilter = 1L << 14, > AlphaBlur = 1L << 15, > ContentTexture = 1L << 16, >- ManualRepeat = 1L << 17 >+ ManualRepeat = 1L << 17, >+ TextureYUV = 1L << 18, > }; > > typedef unsigned Options; >@@ -81,6 +82,9 @@ public: > TEXMAP_DECLARE_UNIFORM(color) > TEXMAP_DECLARE_UNIFORM(expandedQuadEdgesInScreenSpace) > TEXMAP_DECLARE_SAMPLER(sampler) >+ TEXMAP_DECLARE_SAMPLER(samplerY) >+ TEXMAP_DECLARE_SAMPLER(samplerU) >+ TEXMAP_DECLARE_SAMPLER(samplerV) > TEXMAP_DECLARE_SAMPLER(mask) > > TEXMAP_DECLARE_UNIFORM(filterAmount)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 132869
:
364675
|
369494
|
372694
|
376065
|
376496
|
376751
|
377333
|
377882
|
377890