Skip to content

Commit

Permalink
[TextureMapper] Remove TextureMapperContextAttributes
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=264153

Reviewed by Alejandro G. Castro.

It's used to cache the presence two gl extensions that could be cached
and provided by the GLContext which also makes easier to create bitmap
textures.

* Source/WebCore/platform/TextureMapper.cmake:
* Source/WebCore/platform/graphics/egl/GLContext.cpp:
(WebCore::GLContext::glExtensions const):
* Source/WebCore/platform/graphics/egl/GLContext.h:
* Source/WebCore/platform/graphics/gstreamer/GStreamerVideoFrameHolder.cpp:
* Source/WebCore/platform/graphics/gstreamer/MediaPlayerPrivateGStreamer.cpp:
(WebCore::MediaPlayerPrivateGStreamer::pushTextureToCompositor):
* Source/WebCore/platform/graphics/nicosia/NicosiaImageBufferPipe.cpp:
(Nicosia::NicosiaImageBufferPipeSource::handle):
* Source/WebCore/platform/graphics/texmap/BitmapTexture.cpp:
(WebCore::BitmapTexture::BitmapTexture):
(WebCore::BitmapTexture::updateContents):
* Source/WebCore/platform/graphics/texmap/BitmapTexture.h:
* Source/WebCore/platform/graphics/texmap/BitmapTexturePool.cpp:
(WebCore::BitmapTexturePool::BitmapTexturePool):
(WebCore::BitmapTexturePool::acquireTexture):
(WebCore::BitmapTexturePool::createTexture): Deleted.
* Source/WebCore/platform/graphics/texmap/BitmapTexturePool.h:
* Source/WebCore/platform/graphics/texmap/TextureMapper.cpp:
(WebCore::TextureMapperGLData::SharedGLData::currentSharedGLData):
(WebCore::TextureMapper::TextureMapper):
(WebCore::TextureMapper::drawTexture):
(WebCore::TextureMapper::drawTexturePlanarYUV):
(WebCore::TextureMapper::drawTextureSemiPlanarYUV):
(WebCore::TextureMapper::drawTexturePackedYUV):
(WebCore::TextureMapper::drawTexturedQuadWithProgram):
(WebCore::TextureMapper::createTexture): Deleted.
* Source/WebCore/platform/graphics/texmap/TextureMapper.h:
(WebCore::TextureMapper::maxTextureSize const):
* Source/WebCore/platform/graphics/texmap/TextureMapperContextAttributes.cpp: Removed.
* Source/WebCore/platform/graphics/texmap/TextureMapperContextAttributes.h: Removed.
* Source/WebCore/platform/graphics/texmap/TextureMapperPlatformLayerBuffer.cpp:
(WebCore::TextureMapperPlatformLayerBuffer::clone):
* Source/WebCore/platform/graphics/texmap/TextureMapperSparseBackingStore.cpp:
(WebCore::TextureMapperSparseBackingStore::updateContents):
* Source/WebCore/platform/graphics/texmap/TextureMapperSparseBackingStore.h:
* Source/WebCore/platform/graphics/texmap/TextureMapperTile.cpp:
(WebCore::TextureMapperTile::updateContents):
* Source/WebCore/platform/graphics/texmap/TextureMapperTile.h:
* Source/WebCore/platform/graphics/texmap/TextureMapperTiledBackingStore.cpp:
(WebCore::TextureMapperTiledBackingStore::updateContents):
* Source/WebKit/GPUProcess/graphics/wc/WCScene.cpp:
(WebKit::WCScene::update):

Canonical link: https://commits.webkit.org/270173@main
  • Loading branch information
carlosgcampos committed Nov 3, 2023
1 parent 32763a5 commit b01c2d6
Show file tree
Hide file tree
Showing 21 changed files with 56 additions and 171 deletions.
2 changes: 0 additions & 2 deletions Source/WebCore/platform/TextureMapper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ list(APPEND WebCore_SOURCES
platform/graphics/texmap/GraphicsContextGLTextureMapperANGLE.cpp
platform/graphics/texmap/TextureMapper.cpp
platform/graphics/texmap/TextureMapperBackingStore.cpp
platform/graphics/texmap/TextureMapperContextAttributes.cpp
platform/graphics/texmap/TextureMapperFPSCounter.cpp
platform/graphics/texmap/TextureMapperGCGLPlatformLayer.cpp
platform/graphics/texmap/TextureMapperLayer.cpp
Expand All @@ -29,7 +28,6 @@ list(APPEND WebCore_PRIVATE_FRAMEWORK_HEADERS
platform/graphics/texmap/GraphicsLayerTextureMapper.h
platform/graphics/texmap/TextureMapper.h
platform/graphics/texmap/TextureMapperBackingStore.h
platform/graphics/texmap/TextureMapperContextAttributes.h
platform/graphics/texmap/TextureMapperFPSCounter.h
platform/graphics/texmap/TextureMapperGLHeaders.h
platform/graphics/texmap/TextureMapperLayer.h
Expand Down
11 changes: 11 additions & 0 deletions Source/WebCore/platform/graphics/egl/GLContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,17 @@ unsigned GLContext::version()
return m_version;
}

const GLContext::GLExtensions& GLContext::glExtensions() const
{
static std::once_flag flag;
std::call_once(flag, [this] {
const char* extensionsString = reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS));
m_glExtensions.OES_texture_npot = isExtensionSupported(extensionsString, "GL_OES_texture_npot");
m_glExtensions.EXT_unpack_subimage = isExtensionSupported(extensionsString, "GL_EXT_unpack_subimage");
});
return m_glExtensions;
}

GLContext::ScopedGLContext::ScopedGLContext(std::unique_ptr<GLContext>&& context)
: m_context(WTFMove(context))
{
Expand Down
7 changes: 7 additions & 0 deletions Source/WebCore/platform/graphics/egl/GLContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ class GLContext {
WEBCORE_EXPORT void swapBuffers();
GCGLContext platformContext() const;

struct GLExtensions {
bool OES_texture_npot { false };
bool EXT_unpack_subimage { false };
};
const GLExtensions& glExtensions() const;

class ScopedGLContext {
WTF_MAKE_NONCOPYABLE(ScopedGLContext);
public:
Expand Down Expand Up @@ -193,6 +199,7 @@ class GLContext {
#if USE(WPE_RENDERER)
struct wpe_renderer_backend_egl_offscreen_target* m_wpeTarget { nullptr };
#endif
mutable GLExtensions m_glExtensions;
};

} // namespace WebCore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

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

namespace WebCore {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@
#include "BitmapTexture.h"
#include "BitmapTexturePool.h"
#include "GStreamerVideoFrameHolder.h"
#include "TextureMapperContextAttributes.h"
#include "TextureMapperPlatformLayerBuffer.h"
#include "TextureMapperPlatformLayerProxyGL.h"
#endif // USE(TEXTURE_MAPPER)
Expand Down Expand Up @@ -3265,7 +3264,7 @@ void MediaPlayerPrivateGStreamer::pushTextureToCompositor()
} else {
layerBuffer = proxy.getAvailableBuffer(frameHolder->size(), GL_DONT_CARE);
if (UNLIKELY(!layerBuffer)) {
auto texture = BitmapTexture::create(TextureMapperContextAttributes::get());
auto texture = BitmapTexture::create();
texture->reset(frameHolder->size(), frameHolder->hasAlphaChannel() ? BitmapTexture::SupportsAlpha : BitmapTexture::NoFlag);
layerBuffer = makeUnique<TextureMapperPlatformLayerBuffer>(WTFMove(texture));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void NicosiaImageBufferPipeSource::handle(ImageBuffer& buffer)
if (!proxy.isActive())
return;

auto texture = BitmapTexture::create(TextureMapperContextAttributes::get());
auto texture = BitmapTexture::create();

{
Locker locker { m_imageBufferLock };
Expand Down
13 changes: 7 additions & 6 deletions Source/WebCore/platform/graphics/texmap/BitmapTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#if USE(TEXTURE_MAPPER)

#include "FilterOperations.h"
#include "GLContext.h"
#include "GraphicsContext.h"
#include "GraphicsLayer.h"
#include "ImageBuffer.h"
Expand All @@ -50,9 +51,8 @@

namespace WebCore {

BitmapTexture::BitmapTexture(const TextureMapperContextAttributes& contextAttributes, const Flags, GLint internalFormat)
: m_contextAttributes(contextAttributes)
, m_format(GL_RGBA)
BitmapTexture::BitmapTexture(const Flags, GLint internalFormat)
: m_format(GL_RGBA)
{
if (internalFormat != GL_DONT_CARE) {
m_internalFormat = internalFormat;
Expand Down Expand Up @@ -98,7 +98,8 @@ void BitmapTexture::updateContents(const void* srcData, const IntRect& targetRec
IntPoint adjustedSourceOffset = sourceOffset;

// Texture upload requires subimage buffer if driver doesn't support subimage and we don't have full image upload.
bool requireSubImageBuffer = !m_contextAttributes.supportsUnpackSubimage
bool supportsUnpackSubimage = GLContext::current()->glExtensions().EXT_unpack_subimage;
bool requireSubImageBuffer = !supportsUnpackSubimage
&& !(bytesPerLine == static_cast<int>(targetRect.width() * bytesPerPixel) && adjustedSourceOffset == IntPoint::zero());

// prepare temporaryData if necessary
Expand All @@ -121,7 +122,7 @@ void BitmapTexture::updateContents(const void* srcData, const IntRect& targetRec

glBindTexture(GL_TEXTURE_2D, m_id);

if (m_contextAttributes.supportsUnpackSubimage) {
if (supportsUnpackSubimage) {
// Use the OpenGL sub-image extension, now that we know it's available.
glPixelStorei(GL_UNPACK_ROW_LENGTH, bytesPerLine / bytesPerPixel);
glPixelStorei(GL_UNPACK_SKIP_ROWS, adjustedSourceOffset.y());
Expand All @@ -130,7 +131,7 @@ void BitmapTexture::updateContents(const void* srcData, const IntRect& targetRec

glTexSubImage2D(GL_TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), m_format, m_type, data);

if (m_contextAttributes.supportsUnpackSubimage) {
if (supportsUnpackSubimage) {
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
Expand Down
8 changes: 3 additions & 5 deletions Source/WebCore/platform/graphics/texmap/BitmapTexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
#include "IntPoint.h"
#include "IntRect.h"
#include "IntSize.h"
#include "TextureMapperContextAttributes.h"
#include "TextureMapperGLHeaders.h"
#include <wtf/OptionSet.h>
#include <wtf/RefCounted.h>
Expand Down Expand Up @@ -61,9 +60,9 @@ class BitmapTexture final : public RefCounted<BitmapTexture> {

typedef unsigned Flags;

static Ref<BitmapTexture> create(const TextureMapperContextAttributes& contextAttributes, const Flags flags = NoFlag, GLint internalFormat = GL_DONT_CARE)
static Ref<BitmapTexture> create(const Flags flags = NoFlag, GLint internalFormat = GL_DONT_CARE)
{
return adoptRef(*new BitmapTexture(contextAttributes, flags, internalFormat));
return adoptRef(*new BitmapTexture(flags, internalFormat));
}

WEBCORE_EXPORT ~BitmapTexture();
Expand Down Expand Up @@ -114,7 +113,7 @@ class BitmapTexture final : public RefCounted<BitmapTexture> {
OptionSet<TextureMapperFlags> colorConvertFlags() const { return m_colorConvertFlags; }

private:
BitmapTexture(const TextureMapperContextAttributes&, const Flags, GLint internalFormat);
BitmapTexture(const Flags, GLint internalFormat);

void clearIfNeeded();
void createFboIfNeeded();
Expand All @@ -130,7 +129,6 @@ class BitmapTexture final : public RefCounted<BitmapTexture> {
GLuint m_depthBufferObject { 0 };
bool m_shouldClear { true };
ClipStack m_clipStack;
TextureMapperContextAttributes m_contextAttributes;
OptionSet<TextureMapperFlags> m_colorConvertFlags;
FilterInfo m_filterInfo;
GLint m_internalFormat { 0 };
Expand Down
12 changes: 3 additions & 9 deletions Source/WebCore/platform/graphics/texmap/BitmapTexturePool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ namespace WebCore {
static const Seconds releaseUnusedSecondsTolerance { 3_s };
static const Seconds releaseUnusedTexturesTimerInterval { 500_ms };

BitmapTexturePool::BitmapTexturePool(const TextureMapperContextAttributes& contextAttributes)
: m_contextAttributes(contextAttributes)
, m_releaseUnusedTexturesTimer(RunLoop::current(), this, &BitmapTexturePool::releaseUnusedTexturesTimerFired)
BitmapTexturePool::BitmapTexturePool()
: m_releaseUnusedTexturesTimer(RunLoop::current(), this, &BitmapTexturePool::releaseUnusedTexturesTimerFired)
{
}

Expand All @@ -51,7 +50,7 @@ RefPtr<BitmapTexture> BitmapTexturePool::acquireTexture(const IntSize& size, con
});

if (selectedEntry == m_textures.end()) {
m_textures.append(Entry(createTexture(flags)));
m_textures.append(Entry(BitmapTexture::create(flags)));
selectedEntry = &m_textures.last();
}

Expand Down Expand Up @@ -84,11 +83,6 @@ void BitmapTexturePool::releaseUnusedTexturesTimerFired()
scheduleReleaseUnusedTextures();
}

RefPtr<BitmapTexture> BitmapTexturePool::createTexture(const BitmapTexture::Flags flags)
{
return BitmapTexture::create(m_contextAttributes, flags);
}

} // namespace WebCore

#endif // USE(TEXTURE_MAPPER)
5 changes: 1 addition & 4 deletions Source/WebCore/platform/graphics/texmap/BitmapTexturePool.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#if USE(TEXTURE_MAPPER)

#include "BitmapTexture.h"
#include "TextureMapperContextAttributes.h"
#include <wtf/RunLoop.h>

namespace WebCore {
Expand All @@ -40,7 +39,7 @@ class BitmapTexturePool {
WTF_MAKE_NONCOPYABLE(BitmapTexturePool);
WTF_MAKE_FAST_ALLOCATED;
public:
explicit BitmapTexturePool(const TextureMapperContextAttributes&);
BitmapTexturePool();

RefPtr<BitmapTexture> acquireTexture(const IntSize&, const BitmapTexture::Flags);
void releaseUnusedTexturesTimerFired();
Expand All @@ -59,9 +58,7 @@ class BitmapTexturePool {
};

void scheduleReleaseUnusedTextures();
RefPtr<BitmapTexture> createTexture(const BitmapTexture::Flags);

TextureMapperContextAttributes m_contextAttributes;
Vector<Entry> m_textures;
RunLoop::Timer m_releaseUnusedTexturesTimer;
};
Expand Down
25 changes: 9 additions & 16 deletions Source/WebCore/platform/graphics/texmap/TextureMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class TextureMapperGLData {
public:
static Ref<SharedGLData> currentSharedGLData(void* platformContext)
{
ASSERT(platformContext);

auto it = contextDataMap().find(platformContext);
if (it != contextDataMap().end())
return *it->value;
Expand Down Expand Up @@ -176,13 +178,9 @@ std::unique_ptr<TextureMapper> TextureMapper::create()
}

TextureMapper::TextureMapper()
: m_contextAttributes(TextureMapperContextAttributes::get())
: m_texturePool(makeUnique<BitmapTexturePool>())
, m_data(new TextureMapperGLData(GLContext::current()->platformContext()))
{
void* platformContext = GLContext::current()->platformContext();
ASSERT(platformContext);

m_data = new TextureMapperGLData(platformContext);
m_texturePool = makeUnique<BitmapTexturePool>(m_contextAttributes);
}

RefPtr<BitmapTexture> TextureMapper::acquireTextureFromPool(const IntSize& size, const BitmapTexture::Flags flags)
Expand Down Expand Up @@ -478,7 +476,7 @@ void TextureMapper::drawTexture(GLuint texture, OptionSet<TextureMapperFlags> fl
options.add(TextureMapperShaderProgram::Antialiasing);
flags.add(TextureMapperFlags::ShouldAntialias);
}
if (m_wrapMode == WrapMode::Repeat && !m_contextAttributes.supportsNPOTTextures)
if (m_wrapMode == WrapMode::Repeat && !GLContext::current()->glExtensions().OES_texture_npot)
options.add(TextureMapperShaderProgram::ManualRepeat);

RefPtr<const FilterOperation> filter = data().filterInfo ? data().filterInfo->filter: nullptr;
Expand Down Expand Up @@ -543,7 +541,7 @@ void TextureMapper::drawTexturePlanarYUV(const std::array<GLuint, 3>& textures,
options.add(TextureMapperShaderProgram::Antialiasing);
flags.add(TextureMapperFlags::ShouldAntialias);
}
if (m_wrapMode == WrapMode::Repeat && !m_contextAttributes.supportsNPOTTextures)
if (m_wrapMode == WrapMode::Repeat && !GLContext::current()->glExtensions().OES_texture_npot)
options.add(TextureMapperShaderProgram::ManualRepeat);

RefPtr<const FilterOperation> filter = data().filterInfo ? data().filterInfo->filter: nullptr;
Expand Down Expand Up @@ -599,7 +597,7 @@ void TextureMapper::drawTextureSemiPlanarYUV(const std::array<GLuint, 2>& textur
options.add(TextureMapperShaderProgram::Antialiasing);
flags.add(TextureMapperFlags::ShouldAntialias);
}
if (m_wrapMode == WrapMode::Repeat && !m_contextAttributes.supportsNPOTTextures)
if (m_wrapMode == WrapMode::Repeat && !GLContext::current()->glExtensions().OES_texture_npot)
options.add(TextureMapperShaderProgram::ManualRepeat);

RefPtr<const FilterOperation> filter = data().filterInfo ? data().filterInfo->filter: nullptr;
Expand Down Expand Up @@ -647,7 +645,7 @@ void TextureMapper::drawTexturePackedYUV(GLuint texture, const std::array<GLfloa
options.add(TextureMapperShaderProgram::Antialiasing);
flags.add(TextureMapperFlags::ShouldAntialias);
}
if (m_wrapMode == WrapMode::Repeat && !m_contextAttributes.supportsNPOTTextures)
if (m_wrapMode == WrapMode::Repeat && !GLContext::current()->glExtensions().OES_texture_npot)
options.add(TextureMapperShaderProgram::ManualRepeat);

RefPtr<const FilterOperation> filter = data().filterInfo ? data().filterInfo->filter: nullptr;
Expand Down Expand Up @@ -794,7 +792,7 @@ void TextureMapper::drawTexturedQuadWithProgram(TextureMapperShaderProgram& prog
{
glUseProgram(program.programID());

bool repeatWrap = m_wrapMode == WrapMode::Repeat && m_contextAttributes.supportsNPOTTextures;
bool repeatWrap = m_wrapMode == WrapMode::Repeat && GLContext::current()->glExtensions().OES_texture_npot;
GLenum target = GLenum(GL_TEXTURE_2D);
if (flags.contains(TextureMapperFlags::ShouldUseExternalOESTextureRect))
target = GLenum(GL_TEXTURE_EXTERNAL_OES);
Expand Down Expand Up @@ -1320,11 +1318,6 @@ IntRect TextureMapper::clipBounds()
return clipStack().current().scissorBox;
}

Ref<BitmapTexture> TextureMapper::createTexture()
{
return BitmapTexture::create(m_contextAttributes);
}

void TextureMapper::setDepthRange(double zNear, double zFar)
{
data().zNear = zNear;
Expand Down
3 changes: 0 additions & 3 deletions Source/WebCore/platform/graphics/texmap/TextureMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "FilterOperation.h"
#include "IntRect.h"
#include "IntSize.h"
#include "TextureMapperContextAttributes.h"
#include "TextureMapperGLHeaders.h"
#include "TransformationMatrix.h"
#include <array>
Expand Down Expand Up @@ -84,7 +83,6 @@ class TextureMapper {
void endClip();
IntRect clipBounds();
IntSize maxTextureSize() const { return IntSize(2000, 2000); }
Ref<BitmapTexture> createTexture();
void setDepthRange(double zNear, double zFar);
void setMaskMode(bool m) { m_isMaskMode = m; }
void setWrapMode(WrapMode m) { m_wrapMode = m; }
Expand Down Expand Up @@ -130,7 +128,6 @@ class TextureMapper {
bool m_isMaskMode { false };
TransformationMatrix m_patternTransform;
WrapMode m_wrapMode { WrapMode::Stretch };
TextureMapperContextAttributes m_contextAttributes;
TextureMapperGLData* m_data;
ClipStack m_clipStack;
};
Expand Down
Loading

0 comments on commit b01c2d6

Please sign in to comment.