Diff
Modified: trunk/Source/WebCore/ChangeLog (220391 => 220392)
--- trunk/Source/WebCore/ChangeLog 2017-08-08 07:44:44 UTC (rev 220391)
+++ trunk/Source/WebCore/ChangeLog 2017-08-08 07:46:42 UTC (rev 220392)
@@ -1,5 +1,57 @@
2017-08-08 Zan Dobersek <zdober...@igalia.com>
+ [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:
+
+2017-08-08 Zan Dobersek <zdober...@igalia.com>
+
[TexMap] Don't expose GraphicsContext3D object
https://bugs.webkit.org/show_bug.cgi?id=175310
Modified: trunk/Source/WebCore/platform/TextureMapper.cmake (220391 => 220392)
--- trunk/Source/WebCore/platform/TextureMapper.cmake 2017-08-08 07:44:44 UTC (rev 220391)
+++ trunk/Source/WebCore/platform/TextureMapper.cmake 2017-08-08 07:46:42 UTC (rev 220392)
@@ -17,6 +17,7 @@
list(APPEND WebCore_SOURCES
platform/graphics/texmap/BitmapTextureGL.cpp
platform/graphics/texmap/ClipStack.cpp
+ platform/graphics/texmap/TextureMapperContextAttributes.cpp
platform/graphics/texmap/TextureMapperGL.cpp
platform/graphics/texmap/TextureMapperShaderProgram.cpp
)
Modified: trunk/Source/WebCore/platform/graphics/texmap/BitmapTextureGL.cpp (220391 => 220392)
--- trunk/Source/WebCore/platform/graphics/texmap/BitmapTextureGL.cpp 2017-08-08 07:44:44 UTC (rev 220391)
+++ trunk/Source/WebCore/platform/graphics/texmap/BitmapTextureGL.cpp 2017-08-08 07:46:42 UTC (rev 220392)
@@ -57,8 +57,9 @@
return static_cast<BitmapTextureGL*>(texture);
}
-BitmapTextureGL::BitmapTextureGL(RefPtr<GraphicsContext3D>&& context3D, const Flags flags, GC3Dint internalFormat)
- : m_context3D(WTFMove(context3D))
+BitmapTextureGL::BitmapTextureGL(const TextureMapperContextAttributes& contextAttributes, RefPtr<GraphicsContext3D>&& context3D, const Flags flags, GC3Dint internalFormat)
+ : m_contextAttributes(contextAttributes)
+ , m_context3D(WTFMove(context3D))
{
if (internalFormat != GraphicsContext3D::DONT_CARE) {
m_internalFormat = m_format = internalFormat;
@@ -72,8 +73,8 @@
// internal and external formats need to be BGRA
m_internalFormat = GraphicsContext3D::RGBA;
m_format = GraphicsContext3D::BGRA;
- if (m_context3D->isGLES2Compliant()) {
- if (m_context3D->getExtensions().supports("GL_EXT_texture_format_BGRA8888"))
+ if (m_contextAttributes.isGLES2Compliant) {
+ if (m_contextAttributes.supportsBGRA8888)
m_internalFormat = GraphicsContext3D::BGRA;
else
m_format = GraphicsContext3D::RGBA;
@@ -91,16 +92,6 @@
}
}
-static bool driverSupportsSubImage(GraphicsContext3D* context)
-{
- if (context->isGLES2Compliant()) {
- static bool supportsSubImage = context->getExtensions().supports("GL_EXT_unpack_subimage");
- return supportsSubImage;
- }
-
- return true;
-}
-
void BitmapTextureGL::didReset()
{
if (!m_id)
@@ -122,9 +113,12 @@
void BitmapTextureGL::updateContentsNoSwizzle(const void* srcData, const IntRect& targetRect, const IntPoint& sourceOffset, int bytesPerLine, unsigned bytesPerPixel, Platform3DObject glFormat)
{
+ // For ES drivers that don't support sub-images.
+ bool contextSupportsUnpackSubimage = m_contextAttributes.supportsUnpackSubimage;
+
m_context3D->bindTexture(GraphicsContext3D::TEXTURE_2D, m_id);
- // For ES drivers that don't support sub-images.
- if (driverSupportsSubImage(m_context3D.get())) {
+
+ if (contextSupportsUnpackSubimage) {
// Use the OpenGL sub-image extension, now that we know it's available.
m_context3D->pixelStorei(GraphicsContext3D::UNPACK_ROW_LENGTH, bytesPerLine / bytesPerPixel);
m_context3D->pixelStorei(GraphicsContext3D::UNPACK_SKIP_ROWS, sourceOffset.y());
@@ -133,8 +127,7 @@
m_context3D->texSubImage2D(GraphicsContext3D::TEXTURE_2D, 0, targetRect.x(), targetRect.y(), targetRect.width(), targetRect.height(), glFormat, m_type, srcData);
- // For ES drivers that don't support sub-images.
- if (driverSupportsSubImage(m_context3D.get())) {
+ if (contextSupportsUnpackSubimage) {
m_context3D->pixelStorei(GraphicsContext3D::UNPACK_ROW_LENGTH, 0);
m_context3D->pixelStorei(GraphicsContext3D::UNPACK_SKIP_ROWS, 0);
m_context3D->pixelStorei(GraphicsContext3D::UNPACK_SKIP_PIXELS, 0);
@@ -151,7 +144,7 @@
IntPoint adjustedSourceOffset = sourceOffset;
// Texture upload requires subimage buffer if driver doesn't support subimage and we don't have full image upload.
- bool requireSubImageBuffer = !driverSupportsSubImage(m_context3D.get())
+ bool requireSubImageBuffer = !m_contextAttributes.supportsUnpackSubimage
&& !(bytesPerLine == static_cast<int>(targetRect.width() * bytesPerPixel) && adjustedSourceOffset == IntPoint::zero());
// prepare temporaryData if necessary
Modified: trunk/Source/WebCore/platform/graphics/texmap/BitmapTextureGL.h (220391 => 220392)
--- trunk/Source/WebCore/platform/graphics/texmap/BitmapTextureGL.h 2017-08-08 07:44:44 UTC (rev 220391)
+++ trunk/Source/WebCore/platform/graphics/texmap/BitmapTextureGL.h 2017-08-08 07:46:42 UTC (rev 220392)
@@ -28,6 +28,7 @@
#include "FilterOperation.h"
#include "GraphicsContext3D.h"
#include "IntSize.h"
+#include "TextureMapperContextAttributes.h"
#include "TextureMapperGL.h"
namespace WebCore {
@@ -38,9 +39,9 @@
class BitmapTextureGL : public BitmapTexture {
public:
- static Ref<BitmapTexture> create(Ref<GraphicsContext3D>&& context3D, const Flags flags = NoFlag, GC3Dint internalFormat = GraphicsContext3D::DONT_CARE)
+ static Ref<BitmapTexture> create(const TextureMapperContextAttributes& contextAttributes, Ref<GraphicsContext3D>&& context3D, const Flags flags = NoFlag, GC3Dint internalFormat = GraphicsContext3D::DONT_CARE)
{
- return adoptRef(*new BitmapTextureGL(WTFMove(context3D), flags, internalFormat));
+ return adoptRef(*new BitmapTextureGL(contextAttributes, WTFMove(context3D), flags, internalFormat));
}
virtual ~BitmapTextureGL();
@@ -79,7 +80,7 @@
void copyFromExternalTexture(Platform3DObject textureID);
private:
- BitmapTextureGL(RefPtr<GraphicsContext3D>&&, const Flags, GC3Dint internalFormat);
+ BitmapTextureGL(const TextureMapperContextAttributes&, RefPtr<GraphicsContext3D>&&, const Flags, GC3Dint internalFormat);
Platform3DObject m_id { 0 };
IntSize m_textureSize;
@@ -89,6 +90,7 @@
Platform3DObject m_depthBufferObject { 0 };
bool m_shouldClear { true };
ClipStack m_clipStack;
+ TextureMapperContextAttributes m_contextAttributes;
RefPtr<GraphicsContext3D> m_context3D;
void clearIfNeeded();
Modified: trunk/Source/WebCore/platform/graphics/texmap/BitmapTexturePool.cpp (220391 => 220392)
--- trunk/Source/WebCore/platform/graphics/texmap/BitmapTexturePool.cpp 2017-08-08 07:44:44 UTC (rev 220391)
+++ trunk/Source/WebCore/platform/graphics/texmap/BitmapTexturePool.cpp 2017-08-08 07:46:42 UTC (rev 220392)
@@ -37,8 +37,9 @@
static const Seconds releaseUnusedTexturesTimerInterval { 500_ms };
#if USE(TEXTURE_MAPPER_GL)
-BitmapTexturePool::BitmapTexturePool(RefPtr<GraphicsContext3D>&& context3D)
- : m_context3D(WTFMove(context3D))
+BitmapTexturePool::BitmapTexturePool(const TextureMapperContextAttributes& contextAttributes, RefPtr<GraphicsContext3D>&& context3D)
+ : m_contextAttributes(contextAttributes)
+ , m_context3D(WTFMove(context3D))
, m_releaseUnusedTexturesTimer(RunLoop::current(), this, &BitmapTexturePool::releaseUnusedTexturesTimerFired)
{
}
@@ -93,7 +94,7 @@
RefPtr<BitmapTexture> BitmapTexturePool::createTexture(const BitmapTexture::Flags flags)
{
#if USE(TEXTURE_MAPPER_GL)
- return BitmapTextureGL::create(*m_context3D, flags);
+ return BitmapTextureGL::create(m_contextAttributes, *m_context3D, flags);
#else
UNUSED_PARAM(flags);
return nullptr;
Modified: trunk/Source/WebCore/platform/graphics/texmap/BitmapTexturePool.h (220391 => 220392)
--- trunk/Source/WebCore/platform/graphics/texmap/BitmapTexturePool.h 2017-08-08 07:44:44 UTC (rev 220391)
+++ trunk/Source/WebCore/platform/graphics/texmap/BitmapTexturePool.h 2017-08-08 07:46:42 UTC (rev 220392)
@@ -28,6 +28,7 @@
#define BitmapTexturePool_h
#include "BitmapTexture.h"
+#include "TextureMapperContextAttributes.h"
#include <wtf/CurrentTime.h>
#include <wtf/RunLoop.h>
@@ -45,7 +46,7 @@
WTF_MAKE_FAST_ALLOCATED;
public:
#if USE(TEXTURE_MAPPER_GL)
- explicit BitmapTexturePool(RefPtr<GraphicsContext3D>&&);
+ explicit BitmapTexturePool(const TextureMapperContextAttributes&, RefPtr<GraphicsContext3D>&&);
#endif
RefPtr<BitmapTexture> acquireTexture(const IntSize&, const BitmapTexture::Flags);
@@ -68,6 +69,7 @@
RefPtr<BitmapTexture> createTexture(const BitmapTexture::Flags);
#if USE(TEXTURE_MAPPER_GL)
+ TextureMapperContextAttributes m_contextAttributes;
RefPtr<GraphicsContext3D> m_context3D;
#endif
Added: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperContextAttributes.cpp (0 => 220392)
--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperContextAttributes.cpp (rev 0)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperContextAttributes.cpp 2017-08-08 07:46:42 UTC (rev 220392)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "TextureMapperContextAttributes.h"
+
+#if USE(TEXTURE_MAPPER_GL)
+
+#include <wtf/text/WTFString.h>
+
+#if USE(LIBEPOXY)
+#include <epoxy/gl.h>
+#elif USE(OPENGL_ES_2)
+#include <GLES2/gl2.h>
+#else
+#include "OpenGLShims.h"
+#endif
+
+namespace WebCore {
+
+void TextureMapperContextAttributes::initialize()
+{
+#if USE(OPENGL_ES_2)
+ isGLES2Compliant = true;
+#endif
+
+ String extensionsString(reinterpret_cast<const char*>(glGetString(GL_EXTENSIONS)));
+
+ supportsNPOTTextures = !isGLES2Compliant || extensionsString.contains(ASCIILiteral("GL_OES_texture_npot"));
+ supportsBGRA8888 = extensionsString.contains(ASCIILiteral("GL_EXT_texture_format_BGRA8888"));
+ supportsUnpackSubimage = !isGLES2Compliant || extensionsString.contains(ASCIILiteral("GL_EXT_unpack_subimage"));
+}
+
+} // namespace WebCore
+
+#endif // USE(TEXTURE_MAPPER_GL)
Added: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperContextAttributes.h (0 => 220392)
--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperContextAttributes.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperContextAttributes.h 2017-08-08 07:46:42 UTC (rev 220392)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2017 Igalia S.L.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(TEXTURE_MAPPER_GL)
+
+namespace WebCore {
+
+struct TextureMapperContextAttributes {
+ void initialize();
+
+ bool isGLES2Compliant { false };
+
+ bool supportsNPOTTextures { false };
+ bool supportsBGRA8888 { false };
+ bool supportsUnpackSubimage { false };
+};
+
+} // namespace WebCore
+
+#endif // USE(TEXTURE_MAPPER_GL)
Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp (220391 => 220392)
--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp 2017-08-08 07:44:44 UTC (rev 220391)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp 2017-08-08 07:46:42 UTC (rev 220392)
@@ -165,12 +165,14 @@
TextureMapperGL::TextureMapperGL()
: m_enableEdgeDistanceAntialiasing(false)
{
+ m_contextAttributes.initialize();
+
m_context3D = GraphicsContext3D::createForCurrentGLContext();
ASSERT(m_context3D);
m_data = new TextureMapperGLData(*m_context3D);
#if USE(TEXTURE_MAPPER_GL)
- m_texturePool = std::make_unique<BitmapTexturePool>(m_context3D.copyRef());
+ m_texturePool = std::make_unique<BitmapTexturePool>(m_contextAttributes, m_context3D.copyRef());
#endif
}
@@ -436,16 +438,6 @@
drawTexture(textureGL.id(), textureGL.isOpaque() ? 0 : ShouldBlend, textureGL.size(), targetRect, matrix, opacity, exposedEdges);
}
-static bool driverSupportsNPOTTextures(GraphicsContext3D& context)
-{
- if (context.isGLES2Compliant()) {
- static bool supportsNPOTTextures = context.getExtensions().supports("GL_OES_texture_npot");
- return supportsNPOTTextures;
- }
-
- return true;
-}
-
void TextureMapperGL::drawTexture(Platform3DObject texture, Flags flags, const IntSize& textureSize, const FloatRect& targetRect, const TransformationMatrix& modelViewMatrix, float opacity, unsigned exposedEdges)
{
bool useRect = flags & ShouldUseARBTextureRect;
@@ -462,7 +454,7 @@
options |= TextureMapperShaderProgram::Antialiasing;
flags |= ShouldAntialias;
}
- if (wrapMode() == RepeatWrap && !driverSupportsNPOTTextures(*m_context3D))
+ if (wrapMode() == RepeatWrap && !m_contextAttributes.supportsNPOTTextures)
options |= TextureMapperShaderProgram::ManualRepeat;
RefPtr<FilterOperation> filter = data().filterInfo ? data().filterInfo->filter: 0;
@@ -591,7 +583,7 @@
GC3Denum target = flags & ShouldUseARBTextureRect ? GC3Denum(Extensions3D::TEXTURE_RECTANGLE_ARB) : GC3Denum(GraphicsContext3D::TEXTURE_2D);
m_context3D->bindTexture(target, texture);
m_context3D->uniform1i(program.samplerLocation(), 0);
- if (wrapMode() == RepeatWrap && driverSupportsNPOTTextures(*m_context3D)) {
+ if (wrapMode() == RepeatWrap && m_contextAttributes.supportsNPOTTextures) {
m_context3D->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_S, GraphicsContext3D::REPEAT);
m_context3D->texParameteri(GraphicsContext3D::TEXTURE_2D, GraphicsContext3D::TEXTURE_WRAP_T, GraphicsContext3D::REPEAT);
}
@@ -768,7 +760,7 @@
Ref<BitmapTexture> TextureMapperGL::createTexture(GC3Dint internalFormat)
{
- return BitmapTextureGL::create(*m_context3D, internalFormat);
+ return BitmapTextureGL::create(m_contextAttributes, *m_context3D, internalFormat);
}
std::unique_ptr<TextureMapper> TextureMapper::platformCreateAccelerated()
Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h (220391 => 220392)
--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h 2017-08-08 07:44:44 UTC (rev 220391)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.h 2017-08-08 07:46:42 UTC (rev 220392)
@@ -28,6 +28,7 @@
#include "GraphicsContext3D.h"
#include "IntSize.h"
#include "TextureMapper.h"
+#include "TextureMapperContextAttributes.h"
#include "TransformationMatrix.h"
namespace WebCore {
@@ -90,6 +91,8 @@
void bindDefaultSurface();
ClipStack& clipStack();
inline TextureMapperGLData& data() { return *m_data; }
+
+ TextureMapperContextAttributes m_contextAttributes;
RefPtr<GraphicsContext3D> m_context3D;
TextureMapperGLData* m_data;
ClipStack m_clipStack;