Changeset 220392 in webkit


Ignore:
Timestamp:
Aug 8, 2017 12:46:42 AM (7 years ago)
Author:
zandobersek@gmail.com
Message:

[TexMap] Add TextureMapperContextAttributes
https://bugs.webkit.org/show_bug.cgi?id=175311

Reviewed by Carlos Garcia Campos.

Add and use TextureMapperContextAttributes, a slim struct that holds
information about the type and extensions supported by the OpenGL
context that's being used for one specific TextureMapperGL instance.

This struct is initialized in the TextureMapperGL constructor for the
OpenGL context that's been made current on that thread, and that will
be used for that TextureMapperGL instance through its lifetime. The
struct is then also copied into any BitmapTextureGL objects that have
been created through this TextureMapperGL (or its texture pool).

The struct is initialized with information about GLES2 support (which
is at this point done through the USE_OPENGL_ES_2 macro) and about
specific OpenGL extensions that are supported. These are then used in
TextureMapperGL (NPOT textures) and BitmapTextureGL (BGRA support,
sub-image unpacking) to deploy specific optimizations or workarounds.

This ultimately serves as a replacement for clunky static functions
that need to operate on GraphicsContext3D objects to retrieve this
information.

No new tests -- no change in behavior.

  • platform/TextureMapper.cmake:
  • platform/graphics/texmap/BitmapTextureGL.cpp:

(WebCore::BitmapTextureGL::BitmapTextureGL):
(WebCore::BitmapTextureGL::updateContentsNoSwizzle):
(WebCore::BitmapTextureGL::updateContents):
(WebCore::driverSupportsSubImage): Deleted.

  • platform/graphics/texmap/BitmapTextureGL.h:

(WebCore::BitmapTextureGL::create):

  • platform/graphics/texmap/BitmapTexturePool.cpp:

(WebCore::BitmapTexturePool::BitmapTexturePool):
(WebCore::BitmapTexturePool::createTexture):

  • platform/graphics/texmap/BitmapTexturePool.h:
  • platform/graphics/texmap/TextureMapperContextAttributes.cpp: Added.

(WebCore::TextureMapperContextAttributes::initialize):

  • platform/graphics/texmap/TextureMapperContextAttributes.h: Added.
  • platform/graphics/texmap/TextureMapperGL.cpp:

(WebCore::TextureMapperGL::TextureMapperGL):
(WebCore::TextureMapperGL::drawTexture):
(WebCore::TextureMapperGL::drawTexturedQuadWithProgram):
(WebCore::TextureMapperGL::createTexture):
(WebCore::driverSupportsNPOTTextures): Deleted.

  • platform/graphics/texmap/TextureMapperGL.h:
Location:
trunk/Source/WebCore
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r220391 r220392  
     12017-08-08  Zan Dobersek  <zdobersek@igalia.com>
     2
     3        [TexMap] Add TextureMapperContextAttributes
     4        https://bugs.webkit.org/show_bug.cgi?id=175311
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        Add and use TextureMapperContextAttributes, a slim struct that holds
     9        information about the type and extensions supported by the OpenGL
     10        context that's being used for one specific TextureMapperGL instance.
     11
     12        This struct is initialized in the TextureMapperGL constructor for the
     13        OpenGL context that's been made current on that thread, and that will
     14        be used for that TextureMapperGL instance through its lifetime. The
     15        struct is then also copied into any BitmapTextureGL objects that have
     16        been created through this TextureMapperGL (or its texture pool).
     17
     18        The struct is initialized with information about GLES2 support (which
     19        is at this point done through the USE_OPENGL_ES_2 macro) and about
     20        specific OpenGL extensions that are supported. These are then used in
     21        TextureMapperGL (NPOT textures) and BitmapTextureGL (BGRA support,
     22        sub-image unpacking) to deploy specific optimizations or workarounds.
     23
     24        This ultimately serves as a replacement for clunky static functions
     25        that need to operate on GraphicsContext3D objects to retrieve this
     26        information.
     27
     28        No new tests -- no change in behavior.
     29
     30        * platform/TextureMapper.cmake:
     31        * platform/graphics/texmap/BitmapTextureGL.cpp:
     32        (WebCore::BitmapTextureGL::BitmapTextureGL):
     33        (WebCore::BitmapTextureGL::updateContentsNoSwizzle):
     34        (WebCore::BitmapTextureGL::updateContents):
     35        (WebCore::driverSupportsSubImage): Deleted.
     36        * platform/graphics/texmap/BitmapTextureGL.h:
     37        (WebCore::BitmapTextureGL::create):
     38        * platform/graphics/texmap/BitmapTexturePool.cpp:
     39        (WebCore::BitmapTexturePool::BitmapTexturePool):
     40        (WebCore::BitmapTexturePool::createTexture):
     41        * platform/graphics/texmap/BitmapTexturePool.h:
     42        * platform/graphics/texmap/TextureMapperContextAttributes.cpp: Added.
     43        (WebCore::TextureMapperContextAttributes::initialize):
     44        * platform/graphics/texmap/TextureMapperContextAttributes.h: Added.
     45        * platform/graphics/texmap/TextureMapperGL.cpp:
     46        (WebCore::TextureMapperGL::TextureMapperGL):
     47        (WebCore::TextureMapperGL::drawTexture):
     48        (WebCore::TextureMapperGL::drawTexturedQuadWithProgram):
     49        (WebCore::TextureMapperGL::createTexture):
     50        (WebCore::driverSupportsNPOTTextures): Deleted.
     51        * platform/graphics/texmap/TextureMapperGL.h:
     52
    1532017-08-08  Zan Dobersek  <zdobersek@igalia.com>
    254
  • trunk/Source/WebCore/platform/TextureMapper.cmake

    r212811 r220392  
    1818        platform/graphics/texmap/BitmapTextureGL.cpp
    1919        platform/graphics/texmap/ClipStack.cpp
     20        platform/graphics/texmap/TextureMapperContextAttributes.cpp
    2021        platform/graphics/texmap/TextureMapperGL.cpp
    2122        platform/graphics/texmap/TextureMapperShaderProgram.cpp
  • trunk/Source/WebCore/platform/graphics/texmap/BitmapTextureGL.cpp

    r218170 r220392  
    5858}
    5959
    60 BitmapTextureGL::BitmapTextureGL(RefPtr<GraphicsContext3D>&& context3D, const Flags flags, GC3Dint internalFormat)
    61     : m_context3D(WTFMove(context3D))
     60BitmapTextureGL::BitmapTextureGL(const TextureMapperContextAttributes& contextAttributes, RefPtr<GraphicsContext3D>&& context3D, const Flags flags, GC3Dint internalFormat)
     61    : m_contextAttributes(contextAttributes)
     62    , m_context3D(WTFMove(context3D))
    6263{
    6364    if (internalFormat != GraphicsContext3D::DONT_CARE) {
     
    7374        m_internalFormat = GraphicsContext3D::RGBA;
    7475        m_format = GraphicsContext3D::BGRA;
    75         if (m_context3D->isGLES2Compliant()) {
    76             if (m_context3D->getExtensions().supports("GL_EXT_texture_format_BGRA8888"))
     76        if (m_contextAttributes.isGLES2Compliant) {
     77            if (m_contextAttributes.supportsBGRA8888)
    7778                m_internalFormat = GraphicsContext3D::BGRA;
    7879            else
     
    9091            p[x] = ((p[x] << 16) & 0xff0000) | ((p[x] >> 16) & 0xff) | (p[x] & 0xff00ff00);
    9192    }
    92 }
    93 
    94 static bool driverSupportsSubImage(GraphicsContext3D* context)
    95 {
    96     if (context->isGLES2Compliant()) {
    97         static bool supportsSubImage = context->getExtensions().supports("GL_EXT_unpack_subimage");
    98         return supportsSubImage;
    99     }
    100 
    101     return true;
    10293}
    10394
     
    123114void BitmapTextureGL::updateContentsNoSwizzle(const void* srcData, const IntRect& targetRect, const IntPoint& sourceOffset, int bytesPerLine, unsigned bytesPerPixel, Platform3DObject glFormat)
    124115{
     116    // For ES drivers that don't support sub-images.
     117    bool contextSupportsUnpackSubimage = m_contextAttributes.supportsUnpackSubimage;
     118
    125119    m_context3D->bindTexture(GraphicsContext3D::TEXTURE_2D, m_id);
    126     // For ES drivers that don't support sub-images.
    127     if (driverSupportsSubImage(m_context3D.get())) {
     120
     121    if (contextSupportsUnpackSubimage) {
    128122        // Use the OpenGL sub-image extension, now that we know it's available.
    129123        m_context3D->pixelStorei(GraphicsContext3D::UNPACK_ROW_LENGTH, bytesPerLine / bytesPerPixel);
     
    134128    m_context3D->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, m_type, srcData);
    135129
    136     // For ES drivers that don't support sub-images.
    137     if (driverSupportsSubImage(m_context3D.get())) {
     130    if (contextSupportsUnpackSubimage) {
    138131        m_context3D->pixelStorei(GraphicsContext3D::UNPACK_ROW_LENGTH, 0);
    139132        m_context3D->pixelStorei(GraphicsContext3D::UNPACK_SKIP_ROWS, 0);
     
    152145
    153146    // Texture upload requires subimage buffer if driver doesn't support subimage and we don't have full image upload.
    154     bool requireSubImageBuffer = !driverSupportsSubImage(m_context3D.get())
     147    bool requireSubImageBuffer = !m_contextAttributes.supportsUnpackSubimage
    155148        && !(bytesPerLine == static_cast<int>(targetRect.width() * bytesPerPixel) && adjustedSourceOffset == IntPoint::zero());
    156149
  • trunk/Source/WebCore/platform/graphics/texmap/BitmapTextureGL.h

    r218170 r220392  
    2929#include "GraphicsContext3D.h"
    3030#include "IntSize.h"
     31#include "TextureMapperContextAttributes.h"
    3132#include "TextureMapperGL.h"
    3233
     
    3940class BitmapTextureGL : public BitmapTexture {
    4041public:
    41     static Ref<BitmapTexture> create(Ref<GraphicsContext3D>&& context3D, const Flags flags = NoFlag, GC3Dint internalFormat = GraphicsContext3D::DONT_CARE)
     42    static Ref<BitmapTexture> create(const TextureMapperContextAttributes& contextAttributes, Ref<GraphicsContext3D>&& context3D, const Flags flags = NoFlag, GC3Dint internalFormat = GraphicsContext3D::DONT_CARE)
    4243    {
    43         return adoptRef(*new BitmapTextureGL(WTFMove(context3D), flags, internalFormat));
     44        return adoptRef(*new BitmapTextureGL(contextAttributes, WTFMove(context3D), flags, internalFormat));
    4445    }
    4546
     
    8081
    8182private:
    82     BitmapTextureGL(RefPtr<GraphicsContext3D>&&, const Flags, GC3Dint internalFormat);
     83    BitmapTextureGL(const TextureMapperContextAttributes&, RefPtr<GraphicsContext3D>&&, const Flags, GC3Dint internalFormat);
    8384
    8485    Platform3DObject m_id { 0 };
     
    9091    bool m_shouldClear { true };
    9192    ClipStack m_clipStack;
     93    TextureMapperContextAttributes m_contextAttributes;
    9294    RefPtr<GraphicsContext3D> m_context3D;
    9395
  • trunk/Source/WebCore/platform/graphics/texmap/BitmapTexturePool.cpp

    r217784 r220392  
    3838
    3939#if USE(TEXTURE_MAPPER_GL)
    40 BitmapTexturePool::BitmapTexturePool(RefPtr<GraphicsContext3D>&& context3D)
    41     : m_context3D(WTFMove(context3D))
     40BitmapTexturePool::BitmapTexturePool(const TextureMapperContextAttributes& contextAttributes, RefPtr<GraphicsContext3D>&& context3D)
     41    : m_contextAttributes(contextAttributes)
     42    , m_context3D(WTFMove(context3D))
    4243    , m_releaseUnusedTexturesTimer(RunLoop::current(), this, &BitmapTexturePool::releaseUnusedTexturesTimerFired)
    4344{
     
    9495{
    9596#if USE(TEXTURE_MAPPER_GL)
    96     return BitmapTextureGL::create(*m_context3D, flags);
     97    return BitmapTextureGL::create(m_contextAttributes, *m_context3D, flags);
    9798#else
    9899    UNUSED_PARAM(flags);
  • trunk/Source/WebCore/platform/graphics/texmap/BitmapTexturePool.h

    r217213 r220392  
    2929
    3030#include "BitmapTexture.h"
     31#include "TextureMapperContextAttributes.h"
    3132#include <wtf/CurrentTime.h>
    3233#include <wtf/RunLoop.h>
     
    4647public:
    4748#if USE(TEXTURE_MAPPER_GL)
    48     explicit BitmapTexturePool(RefPtr<GraphicsContext3D>&&);
     49    explicit BitmapTexturePool(const TextureMapperContextAttributes&, RefPtr<GraphicsContext3D>&&);
    4950#endif
    5051
     
    6970
    7071#if USE(TEXTURE_MAPPER_GL)
     72    TextureMapperContextAttributes m_contextAttributes;
    7173    RefPtr<GraphicsContext3D> m_context3D;
    7274#endif
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp

    r220391 r220392  
    166166    : m_enableEdgeDistanceAntialiasing(false)
    167167{
     168    m_contextAttributes.initialize();
     169
    168170    m_context3D = GraphicsContext3D::createForCurrentGLContext();
    169171    ASSERT(m_context3D);
     
    171173    m_data = new TextureMapperGLData(*m_context3D);
    172174#if USE(TEXTURE_MAPPER_GL)
    173     m_texturePool = std::make_unique<BitmapTexturePool>(m_context3D.copyRef());
     175    m_texturePool = std::make_unique<BitmapTexturePool>(m_contextAttributes, m_context3D.copyRef());
    174176#endif
    175177}
     
    437439}
    438440
    439 static bool driverSupportsNPOTTextures(GraphicsContext3D& context)
    440 {
    441     if (context.isGLES2Compliant()) {
    442         static bool supportsNPOTTextures = context.getExtensions().supports("GL_OES_texture_npot");
    443         return supportsNPOTTextures;
    444     }
    445 
    446     return true;
    447 }
    448 
    449441void TextureMapperGL::drawTexture(Platform3DObject texture, Flags flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, unsigned exposedEdges)
    450442{
     
    463455        flags |= ShouldAntialias;
    464456    }
    465     if (wrapMode() == RepeatWrap && !driverSupportsNPOTTextures(*m_context3D))
     457    if (wrapMode() == RepeatWrap && !m_contextAttributes.supportsNPOTTextures)
    466458        options |= TextureMapperShaderProgram::ManualRepeat;
    467459
     
    592584    m_context3D->bindTexture(target, texture);
    593585    m_context3D->uniform1i(program.samplerLocation(), 0);
    594     if (wrapMode() == RepeatWrap && driverSupportsNPOTTextures(*m_context3D)) {
     586    if (wrapMode() == RepeatWrap && m_contextAttributes.supportsNPOTTextures) {
    595587        m_context3D->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::REPEAT);
    596588        m_context3D->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::REPEAT);
     
    769761Ref<BitmapTexture> TextureMapperGL::createTexture(GC3Dint internalFormat)
    770762{
    771     return BitmapTextureGL::create(*m_context3D, internalFormat);
     763    return BitmapTextureGL::create(m_contextAttributes, *m_context3D, internalFormat);
    772764}
    773765
  • trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h

    r220391 r220392  
    2929#include "IntSize.h"
    3030#include "TextureMapper.h"
     31#include "TextureMapperContextAttributes.h"
    3132#include "TransformationMatrix.h"
    3233
     
    9192    ClipStack& clipStack();
    9293    inline TextureMapperGLData& data() { return *m_data; }
     94
     95    TextureMapperContextAttributes m_contextAttributes;
    9396    RefPtr<GraphicsContext3D> m_context3D;
    9497    TextureMapperGLData* m_data;
Note: See TracChangeset for help on using the changeset viewer.