Skip to content

Commit

Permalink
[TextureMapper] Use OptionSet for TextureMapperFlags
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264033

Reviewed by Adrian Perez de Castro.

And move it to its own header, since we are including TextureMapper.h in
several places where we only need the flags.

* Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameHolder.cpp:
(WebCore::GstVideoFrameHolder::GstVideoFrameHolder):
* Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameHolder.h:
(WebCore::GstVideoFrameHolder::flags const):
* Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::pushTextureToCompositor):
(WebCore::MediaPlayerPrivateGStreamer::updateTextureMapperFlags):
* Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.h:
* Source/WebCore/platform/graphics/nicosia/NicosiaGCGLANGLELayer.cpp:
(Nicosia::GCGLANGLELayer::swapBuffersIfNeeded):
* Source/WebCore/platform/graphics/nicosia/NicosiaImageBufferPipe.cpp:
(Nicosia::NicosiaImageBufferPipeSource::handle):
* Source/WebCore/platform/graphics/texmap/BitmapTexture.cpp:
(WebCore::BitmapTexture::didReset):
(WebCore::BitmapTexture::updateContents):
* Source/WebCore/platform/graphics/texmap/BitmapTexture.h:
* Source/WebCore/platform/graphics/texmap/TextureMapper.cpp:
(WebCore::TextureMapper::drawBorder):
(WebCore::colorSpaceMatrixForFlags):
(WebCore::TextureMapper::drawTexture):
(WebCore::prepareTransformationMatrixWithFlags):
(WebCore::TextureMapper::drawTexturePlanarYUV):
(WebCore::TextureMapper::drawTextureSemiPlanarYUV):
(WebCore::TextureMapper::drawTexturePackedYUV):
(WebCore::TextureMapper::drawSolidColor):
(WebCore::TextureMapper::draw):
(WebCore::TextureMapper::drawTexturedQuadWithProgram):
(WebCore::TextureMapper::drawTextureCopy):
(WebCore::TextureMapper::drawBlurred):
(WebCore::TextureMapper::applyDropShadowFilter):
(WebCore::TextureMapper::applySinglePassFilter):
(WebCore::TextureMapper::drawTextureExternalOES):
* Source/WebCore/platform/graphics/texmap/TextureMapper.h:
* Source/WebCore/platform/graphics/texmap/TextureMapperFlags.h: Added.
* Source/WebCore/platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp:
(WebCore::TextureMapperGCGLPlatformLayer::paintToTextureMapper):
* Source/WebCore/platform/graphics/texmap/TextureMapperLayer.cpp:
* Source/WebCore/platform/graphics/texmap/TextureMapperLayer.h:
* Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp:
(WebCore::TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer):
(WebCore::TextureMapperPlatformLayerBuffer::clone):
(WebCore::TextureMapperPlatformLayerBuffer::paintToTextureMapper):
* Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.h:
(WebCore::TextureMapperPlatformLayerBuffer::TextureMapperPlatformLayerBuffer):
(WebCore::TextureMapperPlatformLayerBuffer::setExtraFlags):
* Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyDMABuf.cpp:
(WebCore::TextureMapperPlatformLayerProxyDMABuf::DMABufLayer::DMABufLayer):
* Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerProxyDMABuf.h:
* Source/WebCore/platform/graphics/texmap/TextureMapperTile.h:
* Source/WebCore/platform/graphics/texmap/coordinated/CoordinatedBackingStore.h:
* Source/WebKit/WebProcess/GPU/graphics/gbm/RemoteGraphicsContextGLProxyGBM.cpp:
(WebKit::NicosiaDisplayDelegate::swapBuffersIfNeeded):

Canonical link: https://commits.webkit.org/270051@main
  • Loading branch information
carlosgcampos committed Nov 1, 2023
1 parent 36d4015 commit bcb36a6
Show file tree
Hide file tree
Showing 21 changed files with 195 additions and 132 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@

#include "BitmapTexture.h"
#include "BitmapTexturePool.h"
#include "TextureMapper.h"
#include "TextureMapperContextAttributes.h"
#include "TextureMapperFlags.h"

namespace WebCore {

GstVideoFrameHolder::GstVideoFrameHolder(GstSample* sample, std::optional<GstVideoDecoderPlatform> videoDecoderPlatform, TextureMapper::Flags flags, bool gstGLEnabled)
GstVideoFrameHolder::GstVideoFrameHolder(GstSample* sample, std::optional<GstVideoDecoderPlatform> videoDecoderPlatform, OptionSet<TextureMapperFlags> flags, bool gstGLEnabled)
: m_videoDecoderPlatform(videoDecoderPlatform)
#if USE(GSTREAMER_GL)
, m_flags(flags)
#endif
{
RELEASE_ASSERT(GST_IS_SAMPLE(sample));

Expand All @@ -46,7 +49,8 @@ GstVideoFrameHolder::GstVideoFrameHolder(GstSample* sample, std::optional<GstVid
return;

#if USE(GSTREAMER_GL)
m_flags = flags | (m_hasAlphaChannel ? TextureMapper::ShouldBlend | TextureMapper::ShouldPremultiply : 0);
if (m_hasAlphaChannel)
m_flags.add({ TextureMapperFlags::ShouldBlend, TextureMapperFlags::ShouldPremultiply });

GstMemory* memory = gst_buffer_peek_memory(m_buffer.get(), 0);
if (gst_is_gl_memory(memory))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,15 @@

#include "MediaPlayerPrivateGStreamer.h"
#include "TextureMapperPlatformLayerBuffer.h"
#include <wtf/OptionSet.h>

namespace WebCore {

enum class TextureMapperFlags : uint16_t;

class GstVideoFrameHolder : public TextureMapperPlatformLayerBuffer::UnmanagedBufferDataHolder {
public:
explicit GstVideoFrameHolder(GstSample*, std::optional<GstVideoDecoderPlatform>, TextureMapper::Flags, bool gstGLEnabled);
explicit GstVideoFrameHolder(GstSample*, std::optional<GstVideoDecoderPlatform>, OptionSet<TextureMapperFlags>, bool gstGLEnabled);
virtual ~GstVideoFrameHolder();

#if USE(GSTREAMER_GL)
Expand All @@ -38,7 +41,7 @@ class GstVideoFrameHolder : public TextureMapperPlatformLayerBuffer::UnmanagedBu

const IntSize& size() const { return m_size; }
bool hasAlphaChannel() const { return m_hasAlphaChannel; }
TextureMapper::Flags flags() const { return m_flags; }
OptionSet<TextureMapperFlags> flags() const { return m_flags; }
GLuint textureID() const { return m_textureID; }
bool hasMappedTextures() const { return m_hasMappedTextures; }
const GstVideoFrame& videoFrame() const { return m_videoFrame; }
Expand All @@ -53,7 +56,7 @@ class GstVideoFrameHolder : public TextureMapperPlatformLayerBuffer::UnmanagedBu
IntSize m_size;
bool m_hasAlphaChannel;
std::optional<GstVideoDecoderPlatform> m_videoDecoderPlatform;
TextureMapper::Flags m_flags { };
OptionSet<TextureMapperFlags> m_flags;
GLuint m_textureID { 0 };
#if USE(GSTREAMER_GL)
GstGLTextureTarget m_textureTarget { GST_GL_TEXTURE_TARGET_NONE };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3270,7 +3270,10 @@ void MediaPlayerPrivateGStreamer::pushTextureToCompositor()
layerBuffer = makeUnique<TextureMapperPlatformLayerBuffer>(WTFMove(texture));
}
frameHolder->updateTexture(layerBuffer->texture());
layerBuffer->setExtraFlags(m_textureMapperFlags | (frameHolder->hasAlphaChannel() ? TextureMapper::ShouldBlend | TextureMapper::ShouldPremultiply : 0));
auto extraFlags = m_textureMapperFlags;
if (frameHolder->hasAlphaChannel())
extraFlags.add({ TextureMapperFlags::ShouldBlend, TextureMapperFlags::ShouldPremultiply });
layerBuffer->setExtraFlags(extraFlags);
}
proxy.pushNextBuffer(WTFMove(layerBuffer));
};
Expand Down Expand Up @@ -3938,23 +3941,23 @@ void MediaPlayerPrivateGStreamer::updateTextureMapperFlags()
{
switch (m_videoSourceOrientation.orientation()) {
case ImageOrientation::Orientation::OriginTopLeft:
m_textureMapperFlags = 0;
m_textureMapperFlags = { };
break;
case ImageOrientation::Orientation::OriginRightTop:
m_textureMapperFlags = TextureMapper::ShouldRotateTexture90;
m_textureMapperFlags = { TextureMapperFlags::ShouldRotateTexture90 };
break;
case ImageOrientation::Orientation::OriginBottomRight:
m_textureMapperFlags = TextureMapper::ShouldRotateTexture180;
m_textureMapperFlags = { TextureMapperFlags::ShouldRotateTexture180 };
break;
case ImageOrientation::Orientation::OriginLeftBottom:
m_textureMapperFlags = TextureMapper::ShouldRotateTexture270;
m_textureMapperFlags = { TextureMapperFlags::ShouldRotateTexture270 };
break;
case ImageOrientation::Orientation::OriginBottomLeft:
m_textureMapperFlags = TextureMapper::ShouldFlipTexture;
m_textureMapperFlags = { TextureMapperFlags::ShouldFlipTexture };
break;
default:
// FIXME: Handle OriginTopRight, OriginLeftTop and OriginRightBottom.
m_textureMapperFlags = 0;
m_textureMapperFlags = { };
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <wtf/Forward.h>
#include <wtf/Lock.h>
#include <wtf/LoggerHelper.h>
#include <wtf/OptionSet.h>
#include <wtf/RunLoop.h>
#include <wtf/WeakPtr.h>
#include <wtf/text/AtomStringHash.h>
Expand All @@ -60,7 +61,6 @@ typedef struct _GstMpegtsSection GstMpegtsSection;
#endif

#if USE(TEXTURE_MAPPER)
#include "TextureMapper.h"
#if USE(NICOSIA)
#include "NicosiaContentLayer.h"
#else
Expand Down Expand Up @@ -102,6 +102,8 @@ class VideoTrackPrivateGStreamer;
class GBMBufferSwapchain;
#endif

enum class TextureMapperFlags : uint16_t;

void registerWebKitGStreamerElements();

// Use eager initialization for the WeakPtrFactory since we construct WeakPtrs on another thread.
Expand Down Expand Up @@ -374,7 +376,7 @@ class MediaPlayerPrivateGStreamer : public MediaPlayerPrivateInterface
bool m_areVolumeAndMuteInitialized { false };

#if USE(TEXTURE_MAPPER)
TextureMapper::Flags m_textureMapperFlags { TextureMapper::NoFlag };
OptionSet<TextureMapperFlags> m_textureMapperFlags;
#endif

GRefPtr<GstStreamVolume> m_volumeElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#if USE(NICOSIA) && USE(TEXTURE_MAPPER)

#include "GraphicsContextGLTextureMapperANGLE.h"
#include "TextureMapperFlags.h"
#include "TextureMapperPlatformLayerBuffer.h"
#include "TextureMapperPlatformLayerProxyGL.h"
#include <epoxy/gl.h>
Expand All @@ -56,9 +57,9 @@ void GCGLANGLELayer::swapBuffersIfNeeded()
if (bo) {
Locker locker { proxy.lock() };

TextureMapper::Flags flags = TextureMapper::ShouldFlipTexture;
OptionSet<TextureMapperFlags> flags = TextureMapperFlags::ShouldFlipTexture;
if (m_context.contextAttributes().alpha)
flags |= TextureMapper::ShouldBlend;
flags.add(TextureMapperFlags::ShouldBlend);

downcast<TextureMapperPlatformLayerProxyDMABuf>(proxy).pushDMABuf(
DMABufObject(reinterpret_cast<uintptr_t>(swapchain.swapchain.get()) + bo->handle()),
Expand All @@ -71,10 +72,10 @@ void GCGLANGLELayer::swapBuffersIfNeeded()
ASSERT(is<TextureMapperPlatformLayerProxyGL>(proxy));
#endif

TextureMapper::Flags flags = TextureMapper::ShouldFlipTexture;
OptionSet<TextureMapperFlags> flags = TextureMapperFlags::ShouldFlipTexture;
GLint colorFormat;
if (m_context.contextAttributes().alpha) {
flags |= TextureMapper::ShouldBlend;
flags.add(TextureMapperFlags::ShouldBlend);
colorFormat = GL_RGBA;
} else
colorFormat = GL_RGB;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "ImageBuffer.h"
#include "NativeImage.h"
#include "NicosiaPlatformLayer.h"
#include "TextureMapperFlags.h"
#include "TextureMapperPlatformLayerBuffer.h"
#include "TextureMapperPlatformLayerProxyGL.h"

Expand Down Expand Up @@ -95,7 +96,7 @@ void NicosiaImageBufferPipeSource::handle(ImageBuffer& buffer)
}

auto layerBuffer = makeUnique<TextureMapperPlatformLayerBuffer>(WTFMove(texture));
layerBuffer->setExtraFlags(TextureMapper::ShouldBlend);
layerBuffer->setExtraFlags(TextureMapperFlags::ShouldBlend);
downcast<TextureMapperPlatformLayerProxyGL>(proxy).pushNextBuffer(WTFMove(layerBuffer));
});
};
Expand Down
6 changes: 4 additions & 2 deletions Source/WebCore/platform/graphics/texmap/BitmapTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "ImageBuffer.h"
#include "LengthFunctions.h"
#include "NativeImage.h"
#include "TextureMapper.h"
#include "TextureMapperFlags.h"
#include "TextureMapperShaderProgram.h"
#include <wtf/HashMap.h>
#include <wtf/RefCounted.h>
Expand Down Expand Up @@ -66,7 +68,7 @@ void BitmapTexture::didReset()
glGenTextures(1, &m_id);

m_shouldClear = true;
m_colorConvertFlags = TextureMapper::NoFlag;
m_colorConvertFlags = { };
m_filterInfo = FilterInfo();
if (m_textureSize == contentSize())
return;
Expand All @@ -86,7 +88,7 @@ void BitmapTexture::updateContents(const void* srcData, const IntRect& targetRec
// We are updating a texture with format RGBA with content from a buffer that has BGRA format. Instead of turning BGRA
// into RGBA and then uploading it, we upload it as is. This causes the texture format to be RGBA but the content to be BGRA,
// so we mark the texture to convert the colors when painting the texture.
m_colorConvertFlags = TextureMapper::ShouldConvertTextureBGRAToRGBA;
m_colorConvertFlags = TextureMapperFlags::ShouldConvertTextureBGRAToRGBA;

glBindTexture(GL_TEXTURE_2D, m_id);

Expand Down
9 changes: 6 additions & 3 deletions Source/WebCore/platform/graphics/texmap/BitmapTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,19 @@
#include "IntPoint.h"
#include "IntRect.h"
#include "IntSize.h"
#include "TextureMapper.h"
#include "TextureMapperContextAttributes.h"
#include "TextureMapperGLHeaders.h"
#include <wtf/OptionSet.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>

namespace WebCore {

class FilterOperations;
class GraphicsLayer;
class NativeImage;
class TextureMapper;
enum class TextureMapperFlags : uint16_t;

#if OS(WINDOWS)
#define USE_TEXMAP_DEPTH_STENCIL_BUFFER 1
Expand Down Expand Up @@ -108,7 +111,7 @@ class BitmapTexture final : public RefCounted<BitmapTexture> {

void copyFromExternalTexture(GLuint textureID);

TextureMapper::Flags colorConvertFlags() const { return m_colorConvertFlags; }
OptionSet<TextureMapperFlags> colorConvertFlags() const { return m_colorConvertFlags; }

private:
BitmapTexture(const TextureMapperContextAttributes&, const Flags, GLint internalFormat);
Expand All @@ -128,7 +131,7 @@ class BitmapTexture final : public RefCounted<BitmapTexture> {
bool m_shouldClear { true };
ClipStack m_clipStack;
TextureMapperContextAttributes m_contextAttributes;
TextureMapper::Flags m_colorConvertFlags { TextureMapper::NoFlag };
OptionSet<TextureMapperFlags> m_colorConvertFlags;
FilterInfo m_filterInfo;
GLint m_internalFormat { 0 };
GLenum m_format { 0 };
Expand Down
Loading

0 comments on commit bcb36a6

Please sign in to comment.