Modified: trunk/Source/WebCore/ChangeLog (200450 => 200451)
--- trunk/Source/WebCore/ChangeLog 2016-05-05 06:13:28 UTC (rev 200450)
+++ trunk/Source/WebCore/ChangeLog 2016-05-05 06:42:32 UTC (rev 200451)
@@ -1,3 +1,35 @@
+2016-05-04 Zan Dobersek <[email protected]>
+
+ [TexMap] Clean up TextureMapperShaderProgram
+ https://bugs.webkit.org/show_bug.cgi?id=157302
+
+ Reviewed by Carlos Garcia Campos.
+
+ Clean up the header and the implementation file of the
+ TextureMapperShaderProgram class. Reference the GraphicsContext3D
+ object through a Ref<>, and have the context() return a reference,
+ not a pointer.
+
+ Sort the parts of the implementation file into something more
+ sensible. StringBuilder usage in create() is improved. getLocation()
+ only needs to do one lookup in the m_variables map by using ensure().
+
+ No new tests -- no change in behavior.
+
+ * platform/graphics/surfaces/GLTransportSurface.cpp:
+ (WebCore::GLTransportSurface::initializeShaderProgram):
+ * platform/graphics/texmap/TextureMapperGL.cpp:
+ (WebCore::TextureMapperGLData::SharedGLData::getShaderProgram):
+ (WebCore::prepareFilterProgram):
+ * platform/graphics/texmap/TextureMapperShaderProgram.cpp:
+ (WebCore::TextureMapperShaderProgram::create):
+ (WebCore::TextureMapperShaderProgram::TextureMapperShaderProgram):
+ (WebCore::TextureMapperShaderProgram::~TextureMapperShaderProgram):
+ (WebCore::TextureMapperShaderProgram::setMatrix):
+ (WebCore::TextureMapperShaderProgram::getLocation):
+ * platform/graphics/texmap/TextureMapperShaderProgram.h:
+ (WebCore::TextureMapperShaderProgram::context):
+
2016-05-03 Darin Adler <[email protected]>
Start on dictionary support for IDL, getting enough to work for one dictionary
Modified: trunk/Source/WebCore/platform/graphics/surfaces/GLTransportSurface.cpp (200450 => 200451)
--- trunk/Source/WebCore/platform/graphics/surfaces/GLTransportSurface.cpp 2016-05-05 06:13:28 UTC (rev 200450)
+++ trunk/Source/WebCore/platform/graphics/surfaces/GLTransportSurface.cpp 2016-05-05 06:42:32 UTC (rev 200451)
@@ -170,7 +170,7 @@
vertexArrayObjectSupported = m_context3D->getExtensions()->supports("GL_OES_vertex_array_object");
TextureMapperShaderProgram::Options options = TextureMapperShaderProgram::Texture;
- m_shaderProgram = TextureMapperShaderProgram::create(m_context3D, options);
+ m_shaderProgram = TextureMapperShaderProgram::create(*m_context3D, options);
::glUseProgram(m_shaderProgram->programID());
::glUniform1i(m_shaderProgram->samplerLocation(), 0);
Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp (200450 => 200451)
--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp 2016-05-05 06:13:28 UTC (rev 200450)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperGL.cpp 2016-05-05 06:42:32 UTC (rev 200451)
@@ -347,7 +347,7 @@
static void prepareFilterProgram(TextureMapperShaderProgram* program, const FilterOperation& operation, unsigned pass, const IntSize& size, GC3Duint contentTexture)
{
- RefPtr<GraphicsContext3D> context = program->context();
+ Ref<GraphicsContext3D> context = program->context();
context->useProgram(program->programID());
switch (operation.type()) {
Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp (200450 => 200451)
--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp 2016-05-05 06:13:28 UTC (rev 200450)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.cpp 2016-05-05 06:42:32 UTC (rev 200451)
@@ -24,14 +24,10 @@
#if USE(TEXTURE_MAPPER_GL)
-#include "LengthFunctions.h"
#include "Logging.h"
#include "TextureMapperGL.h"
-
#include <wtf/text/StringBuilder.h>
-#define STRINGIFY(...) #__VA_ARGS__
-
namespace WebCore {
static inline bool compositingLogEnabled()
@@ -43,77 +39,8 @@
#endif
}
-TextureMapperShaderProgram::TextureMapperShaderProgram(PassRefPtr<GraphicsContext3D> context, const String& vertex, const String& fragment)
- : m_context(context)
-{
- m_vertexShader = m_context->createShader(GraphicsContext3D::VERTEX_SHADER);
- m_fragmentShader = m_context->createShader(GraphicsContext3D::FRAGMENT_SHADER);
- m_context->shaderSource(m_vertexShader, vertex);
- m_context->shaderSource(m_fragmentShader, fragment);
- m_id = m_context->createProgram();
- m_context->compileShader(m_vertexShader);
- m_context->compileShader(m_fragmentShader);
- m_context->attachShader(m_id, m_vertexShader);
- m_context->attachShader(m_id, m_fragmentShader);
- m_context->linkProgram(m_id);
+#define STRINGIFY(...) #__VA_ARGS__
- if (!compositingLogEnabled())
- return;
-
- if (m_context->getError() == GraphicsContext3D::NO_ERROR)
- return;
-
- String log = m_context->getShaderInfoLog(m_vertexShader);
- LOG(Compositing, "Vertex shader log: %s\n", log.utf8().data());
- log = m_context->getShaderInfoLog(m_fragmentShader);
- LOG(Compositing, "Fragment shader log: %s\n", log.utf8().data());
- log = m_context->getProgramInfoLog(m_id);
- LOG(Compositing, "Program log: %s\n", log.utf8().data());
-}
-
-void TextureMapperShaderProgram::setMatrix(GC3Duint location, const TransformationMatrix& matrix)
-{
- TransformationMatrix::FloatMatrix4 floatMatrix;
- matrix.toColumnMajorFloatArray(floatMatrix);
- m_context->uniformMatrix4fv(location, 1, false, floatMatrix);
-}
-
-GC3Duint TextureMapperShaderProgram::getLocation(const AtomicString& name, VariableType type)
-{
- HashMap<AtomicString, GC3Duint>::iterator it = m_variables.find(name);
- if (it != m_variables.end())
- return it->value;
-
- GC3Duint location = 0;
- switch (type) {
- case UniformVariable:
- location = m_context->getUniformLocation(m_id, name);
- break;
- case AttribVariable:
- location = m_context->getAttribLocation(m_id, name);
- break;
- default:
- ASSERT_NOT_REACHED();
- break;
- }
-
- m_variables.add(name, location);
- return location;
-}
-
-TextureMapperShaderProgram::~TextureMapperShaderProgram()
-{
- Platform3DObject programID = m_id;
- if (!programID)
- return;
-
- m_context->detachShader(programID, m_vertexShader);
- m_context->deleteShader(m_vertexShader);
- m_context->detachShader(programID, m_fragmentShader);
- m_context->deleteShader(m_fragmentShader);
- m_context->deleteProgram(programID);
-}
-
#define GLSL_DIRECTIVE(...) "#"#__VA_ARGS__"\n"
#define TEXTURE_SPACE_MATRIX_PRECISION_DIRECTIVE \
@@ -373,13 +300,13 @@
}
);
-PassRefPtr<TextureMapperShaderProgram> TextureMapperShaderProgram::create(PassRefPtr<GraphicsContext3D> context, TextureMapperShaderProgram::Options options)
+Ref<TextureMapperShaderProgram> TextureMapperShaderProgram::create(Ref<GraphicsContext3D>&& context, TextureMapperShaderProgram::Options options)
{
- StringBuilder shaderBuilder;
#define SET_APPLIER_FROM_OPTIONS(Applier) \
- shaderBuilder.append(\
+ optionsApplierBuilder.append(\
(options & TextureMapperShaderProgram::Applier) ? ENABLE_APPLIER(Applier) : DISABLE_APPLIER(Applier))
+ StringBuilder optionsApplierBuilder;
SET_APPLIER_FROM_OPTIONS(Texture);
SET_APPLIER_FROM_OPTIONS(Rect);
SET_APPLIER_FROM_OPTIONS(SolidColor);
@@ -396,16 +323,83 @@
SET_APPLIER_FROM_OPTIONS(BlurFilter);
SET_APPLIER_FROM_OPTIONS(AlphaBlur);
SET_APPLIER_FROM_OPTIONS(ContentTexture);
- StringBuilder vertexBuilder;
- vertexBuilder.append(shaderBuilder.toString());
- vertexBuilder.append(vertexTemplate);
- shaderBuilder.append(fragmentTemplate);
- String vertexSource = vertexBuilder.toString();
- String fragmentSource = shaderBuilder.toString();
+ StringBuilder vertexShaderBuilder;
+ vertexShaderBuilder.append(optionsApplierBuilder.toString());
+ vertexShaderBuilder.append(vertexTemplate);
- return adoptRef(new TextureMapperShaderProgram(context, vertexSource, fragmentSource));
+ StringBuilder fragmentShaderBuilder;
+ fragmentShaderBuilder.append(optionsApplierBuilder.toString());
+ fragmentShaderBuilder.append(fragmentTemplate);
+
+ return adoptRef(*new TextureMapperShaderProgram(WTFMove(context), vertexShaderBuilder.toString(), fragmentShaderBuilder.toString()));
}
+TextureMapperShaderProgram::TextureMapperShaderProgram(Ref<GraphicsContext3D>&& context, const String& vertex, const String& fragment)
+ : m_context(WTFMove(context))
+{
+ m_vertexShader = m_context->createShader(GraphicsContext3D::VERTEX_SHADER);
+ m_context->shaderSource(m_vertexShader, vertex);
+
+ m_fragmentShader = m_context->createShader(GraphicsContext3D::FRAGMENT_SHADER);
+ m_context->shaderSource(m_fragmentShader, fragment);
+
+ m_id = m_context->createProgram();
+ m_context->compileShader(m_vertexShader);
+ m_context->compileShader(m_fragmentShader);
+ m_context->attachShader(m_id, m_vertexShader);
+ m_context->attachShader(m_id, m_fragmentShader);
+ m_context->linkProgram(m_id);
+
+ if (!compositingLogEnabled())
+ return;
+
+ if (m_context->getError() == GraphicsContext3D::NO_ERROR)
+ return;
+
+ String log = m_context->getShaderInfoLog(m_vertexShader);
+ LOG(Compositing, "Vertex shader log: %s\n", log.utf8().data());
+ log = m_context->getShaderInfoLog(m_fragmentShader);
+ LOG(Compositing, "Fragment shader log: %s\n", log.utf8().data());
+ log = m_context->getProgramInfoLog(m_id);
+ LOG(Compositing, "Program log: %s\n", log.utf8().data());
}
+
+TextureMapperShaderProgram::~TextureMapperShaderProgram()
+{
+ if (!m_id)
+ return;
+
+ m_context->detachShader(m_id, m_vertexShader);
+ m_context->deleteShader(m_vertexShader);
+ m_context->detachShader(m_id, m_fragmentShader);
+ m_context->deleteShader(m_fragmentShader);
+ m_context->deleteProgram(m_id);
+}
+
+void TextureMapperShaderProgram::setMatrix(GC3Duint location, const TransformationMatrix& matrix)
+{
+ TransformationMatrix::FloatMatrix4 floatMatrix;
+ matrix.toColumnMajorFloatArray(floatMatrix);
+ m_context->uniformMatrix4fv(location, 1, false, floatMatrix);
+}
+
+GC3Duint TextureMapperShaderProgram::getLocation(const AtomicString& name, VariableType type)
+{
+ auto addResult = m_variables.ensure(name,
+ [this, &name, type] {
+ switch (type) {
+ case UniformVariable:
+ return m_context->getUniformLocation(m_id, name);
+ case AttribVariable:
+ return m_context->getAttribLocation(m_id, name);
+ }
+ ASSERT_NOT_REACHED();
+ return 0;
+ });
+ return addResult.iterator->value;
+}
+
+} // namespace WebCore
+
#endif // USE(TEXTURE_MAPPER_GL)
Modified: trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.h (200450 => 200451)
--- trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.h 2016-05-05 06:13:28 UTC (rev 200450)
+++ trunk/Source/WebCore/platform/graphics/texmap/TextureMapperShaderProgram.h 2016-05-05 06:42:32 UTC (rev 200451)
@@ -22,14 +22,15 @@
#define TextureMapperShaderProgram_h
#if USE(TEXTURE_MAPPER_GL)
+
#include "GraphicsContext3D.h"
#include "TransformationMatrix.h"
#include <wtf/HashMap.h>
-#include <wtf/PassRefPtr.h>
-#include <wtf/RefPtr.h>
+#include <wtf/Ref.h>
#include <wtf/text/AtomicStringHash.h>
namespace WebCore {
+
#define TEXMAP_DECLARE_VARIABLE(Accessor, Name, Type) GC3Duint Accessor##Location() { static const AtomicString name(Name); return getLocation(name, Type); }
#define TEXMAP_DECLARE_UNIFORM(Accessor) TEXMAP_DECLARE_VARIABLE(Accessor, "u_"#Accessor, UniformVariable)
#define TEXMAP_DECLARE_ATTRIBUTE(Accessor) TEXMAP_DECLARE_VARIABLE(Accessor, "a_"#Accessor, AttribVariable)
@@ -58,10 +59,11 @@
typedef unsigned Options;
- static PassRefPtr<TextureMapperShaderProgram> create(PassRefPtr<GraphicsContext3D>, Options);
+ static Ref<TextureMapperShaderProgram> create(Ref<GraphicsContext3D>&&, Options);
virtual ~TextureMapperShaderProgram();
+
Platform3DObject programID() const { return m_id; }
- GraphicsContext3D* context() { return m_context.get(); }
+ GraphicsContext3D& context() { return m_context; }
TEXMAP_DECLARE_ATTRIBUTE(vertex)
@@ -83,14 +85,15 @@
void setMatrix(GC3Duint, const TransformationMatrix&);
private:
- TextureMapperShaderProgram(PassRefPtr<GraphicsContext3D>, const String& vertexShaderSource, const String& fragmentShaderSource);
+ TextureMapperShaderProgram(Ref<GraphicsContext3D>&&, const String& vertexShaderSource, const String& fragmentShaderSource);
+
Platform3DObject m_vertexShader;
Platform3DObject m_fragmentShader;
enum VariableType { UniformVariable, AttribVariable };
GC3Duint getLocation(const AtomicString&, VariableType);
- RefPtr<GraphicsContext3D> m_context;
+ Ref<GraphicsContext3D> m_context;
Platform3DObject m_id;
HashMap<AtomicString, GC3Duint> m_variables;
};