Title: [133803] trunk/Source/WebCore
Revision
133803
Author
ach...@adobe.com
Date
2012-11-07 13:30:54 -0800 (Wed, 07 Nov 2012)

Log Message

[CSS Shaders] Remove the dependency on CustomFilterValidatedProgram from CustomFilterRenderer
https://bugs.webkit.org/show_bug.cgi?id=101071

Reviewed by Dean Jackson.

I've removed the need to get a CustomFilterValidatedProgram from FilterEffectRenderer. It was only
used to delay the compilation of the shader until it was really needed. Instead, the FilterEffectRenderer
will directly get the compiled shader in the constructor. The callers that still want to avoid
compiling the shader until it is really needed can use the setCompiledProgram to inject the shader
at a later time, before painting.

No new tests, the change is covered by the css3/filters/custom/ tests.

* platform/graphics/filters/CustomFilterConstants.h:
* platform/graphics/filters/CustomFilterProgramInfo.h:
* platform/graphics/filters/CustomFilterRenderer.cpp:
(WebCore::CustomFilterRenderer::create):
(WebCore::CustomFilterRenderer::CustomFilterRenderer):
(WebCore::CustomFilterRenderer::premultipliedAlpha):
(WebCore::CustomFilterRenderer::setCompiledProgram):
(WebCore):
(WebCore::CustomFilterRenderer::prepareForDrawing):
(WebCore::CustomFilterRenderer::bindProgramAndBuffers):
* platform/graphics/filters/CustomFilterRenderer.h:
(WebCore):
(CustomFilterRenderer):
(WebCore::CustomFilterRenderer::compiledProgram):
* platform/graphics/filters/FECustomFilter.cpp:
(WebCore::FECustomFilter::FECustomFilter):
(WebCore::FECustomFilter::prepareForDrawing):
* platform/graphics/filters/FECustomFilter.h:
(FECustomFilter):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (133802 => 133803)


--- trunk/Source/WebCore/ChangeLog	2012-11-07 21:30:05 UTC (rev 133802)
+++ trunk/Source/WebCore/ChangeLog	2012-11-07 21:30:54 UTC (rev 133803)
@@ -1,3 +1,38 @@
+2012-11-07  Alexandru Chiculita  <ach...@adobe.com>
+
+        [CSS Shaders] Remove the dependency on CustomFilterValidatedProgram from CustomFilterRenderer
+        https://bugs.webkit.org/show_bug.cgi?id=101071
+
+        Reviewed by Dean Jackson.
+
+        I've removed the need to get a CustomFilterValidatedProgram from FilterEffectRenderer. It was only
+        used to delay the compilation of the shader until it was really needed. Instead, the FilterEffectRenderer
+        will directly get the compiled shader in the constructor. The callers that still want to avoid 
+        compiling the shader until it is really needed can use the setCompiledProgram to inject the shader
+        at a later time, before painting.
+
+        No new tests, the change is covered by the css3/filters/custom/ tests.
+
+        * platform/graphics/filters/CustomFilterConstants.h:
+        * platform/graphics/filters/CustomFilterProgramInfo.h:
+        * platform/graphics/filters/CustomFilterRenderer.cpp:
+        (WebCore::CustomFilterRenderer::create):
+        (WebCore::CustomFilterRenderer::CustomFilterRenderer):
+        (WebCore::CustomFilterRenderer::premultipliedAlpha):
+        (WebCore::CustomFilterRenderer::setCompiledProgram):
+        (WebCore):
+        (WebCore::CustomFilterRenderer::prepareForDrawing):
+        (WebCore::CustomFilterRenderer::bindProgramAndBuffers):
+        * platform/graphics/filters/CustomFilterRenderer.h:
+        (WebCore):
+        (CustomFilterRenderer):
+        (WebCore::CustomFilterRenderer::compiledProgram):
+        * platform/graphics/filters/FECustomFilter.cpp:
+        (WebCore::FECustomFilter::FECustomFilter):
+        (WebCore::FECustomFilter::prepareForDrawing):
+        * platform/graphics/filters/FECustomFilter.h:
+        (FECustomFilter):
+
 2012-11-07  Adam Barth  <aba...@webkit.org>
 
         [V8] IntrusiveDOMWrapperMap is no longer needed and can be deleted

Modified: trunk/Source/WebCore/platform/graphics/filters/CustomFilterConstants.h (133802 => 133803)


--- trunk/Source/WebCore/platform/graphics/filters/CustomFilterConstants.h	2012-11-07 21:30:05 UTC (rev 133802)
+++ trunk/Source/WebCore/platform/graphics/filters/CustomFilterConstants.h	2012-11-07 21:30:54 UTC (rev 133803)
@@ -57,6 +57,11 @@
     MeshBoxTypeContent
 };
 
+enum CustomFilterProgramType {
+    PROGRAM_TYPE_NO_ELEMENT_TEXTURE,
+    PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE
+};
+
 } // namespace WebCore
 
 #endif // CustomFilterConstants_h

Modified: trunk/Source/WebCore/platform/graphics/filters/CustomFilterProgramInfo.h (133802 => 133803)


--- trunk/Source/WebCore/platform/graphics/filters/CustomFilterProgramInfo.h	2012-11-07 21:30:05 UTC (rev 133802)
+++ trunk/Source/WebCore/platform/graphics/filters/CustomFilterProgramInfo.h	2012-11-07 21:30:54 UTC (rev 133803)
@@ -39,10 +39,6 @@
 
 namespace WebCore {
 
-enum CustomFilterProgramType {
-    PROGRAM_TYPE_NO_ELEMENT_TEXTURE,
-    PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE
-};
 
 struct CustomFilterProgramMixSettings {
     CustomFilterProgramMixSettings()

Modified: trunk/Source/WebCore/platform/graphics/filters/CustomFilterRenderer.cpp (133802 => 133803)


--- trunk/Source/WebCore/platform/graphics/filters/CustomFilterRenderer.cpp	2012-11-07 21:30:05 UTC (rev 133802)
+++ trunk/Source/WebCore/platform/graphics/filters/CustomFilterRenderer.cpp	2012-11-07 21:30:54 UTC (rev 133803)
@@ -35,12 +35,12 @@
 #include "CustomFilterRenderer.h"
 
 #include "CustomFilterArrayParameter.h"
+#include "CustomFilterCompiledProgram.h"
 #include "CustomFilterConstants.h"
 #include "CustomFilterMesh.h"
 #include "CustomFilterNumberParameter.h"
 #include "CustomFilterParameter.h"
 #include "CustomFilterTransformParameter.h"
-#include "CustomFilterValidatedProgram.h"
 #include "GraphicsContext3D.h"
 #include "TransformationMatrix.h"
 
@@ -68,17 +68,16 @@
     matrix.setM44(1.0f);
 }
 
-PassRefPtr<CustomFilterRenderer> CustomFilterRenderer::create(PassRefPtr<GraphicsContext3D> context, PassRefPtr<CustomFilterValidatedProgram> validatedProgram, const CustomFilterParameterList& parameters,
+PassRefPtr<CustomFilterRenderer> CustomFilterRenderer::create(PassRefPtr<GraphicsContext3D> context, CustomFilterProgramType programType, const CustomFilterParameterList& parameters,
     unsigned meshRows, unsigned meshColumns, CustomFilterMeshBoxType meshBoxType, CustomFilterMeshType meshType)
 {
-    return adoptRef(new CustomFilterRenderer(context, validatedProgram, parameters, meshRows, meshColumns, meshBoxType, meshType));
+    return adoptRef(new CustomFilterRenderer(context, programType, parameters, meshRows, meshColumns, meshBoxType, meshType));
 }
 
-CustomFilterRenderer::CustomFilterRenderer(PassRefPtr<GraphicsContext3D> context, PassRefPtr<CustomFilterValidatedProgram> validatedProgram, const CustomFilterParameterList& parameters,
+CustomFilterRenderer::CustomFilterRenderer(PassRefPtr<GraphicsContext3D> context, CustomFilterProgramType programType, const CustomFilterParameterList& parameters,
     unsigned meshRows, unsigned meshColumns, CustomFilterMeshBoxType, CustomFilterMeshType meshType)
     : m_context(context)
-    , m_validatedProgram(validatedProgram)
-    , m_compiledProgram(0) // Don't compile the program unless we need to paint.
+    , m_programType(programType)
     , m_parameters(parameters)
     , m_meshRows(meshRows)
     , m_meshColumns(meshColumns)
@@ -92,7 +91,7 @@
 
 bool CustomFilterRenderer::premultipliedAlpha() const
 {
-    return m_validatedProgram->programInfo().programType() == PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE;
+    return m_programType == PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE;
 }
 
 bool CustomFilterRenderer::programNeedsInputTexture() const
@@ -112,27 +111,20 @@
     unbindVertexAttributes();
 }
 
+void CustomFilterRenderer::setCompiledProgram(PassRefPtr<CustomFilterCompiledProgram> compiledProgram)
+{
+    m_compiledProgram = compiledProgram;
+}
+
 bool CustomFilterRenderer::prepareForDrawing()
 {
     m_context->makeContextCurrent();
-    initializeCompiledProgramIfNeeded();
-
-    // If the shader had compiler errors we cannot draw anything.
-    if (!m_compiledProgram->isInitialized())
+    if (!m_compiledProgram || !m_compiledProgram->isInitialized())
         return false;
-
     initializeMeshIfNeeded();
     return true;
 }
 
-void CustomFilterRenderer::initializeCompiledProgramIfNeeded()
-{
-    if (m_compiledProgram.get())
-        return;
-
-    m_compiledProgram = m_validatedProgram->compiledProgram();
-}
-
 void CustomFilterRenderer::initializeMeshIfNeeded()
 {
     if (m_mesh.get())
@@ -241,7 +233,7 @@
 
     if (programNeedsInputTexture()) {
         // We should be binding the DOM element texture sampler only if the author is using the CSS mix function.
-        ASSERT(m_validatedProgram->programInfo().programType() == PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE);
+        ASSERT(m_programType == PROGRAM_TYPE_BLENDS_ELEMENT_TEXTURE);
         ASSERT(m_compiledProgram->samplerLocation() != -1);
 
         m_context->activeTexture(GraphicsContext3D::TEXTURE0);

Modified: trunk/Source/WebCore/platform/graphics/filters/CustomFilterRenderer.h (133802 => 133803)


--- trunk/Source/WebCore/platform/graphics/filters/CustomFilterRenderer.h	2012-11-07 21:30:05 UTC (rev 133802)
+++ trunk/Source/WebCore/platform/graphics/filters/CustomFilterRenderer.h	2012-11-07 21:30:54 UTC (rev 133803)
@@ -1,4 +1,5 @@
 /*
+ * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved.
  * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
  * Copyright (C) 2012 Company 100, Inc. All rights reserved.
  *
@@ -47,12 +48,11 @@
 class CustomFilterMesh;
 class CustomFilterNumberParameter;
 class CustomFilterTransformParameter;
-class CustomFilterValidatedProgram;
 class GraphicsContext3D;
 
 class CustomFilterRenderer : public RefCounted<CustomFilterRenderer> {
 public:
-    static PassRefPtr<CustomFilterRenderer> create(PassRefPtr<GraphicsContext3D>, PassRefPtr<CustomFilterValidatedProgram>, const CustomFilterParameterList&,
+    static PassRefPtr<CustomFilterRenderer> create(PassRefPtr<GraphicsContext3D>, CustomFilterProgramType, const CustomFilterParameterList&,
         unsigned meshRows, unsigned meshColumns, CustomFilterMeshBoxType, CustomFilterMeshType);
     ~CustomFilterRenderer();
 
@@ -63,8 +63,11 @@
 
     void draw(Platform3DObject, const IntSize&);
 
+    CustomFilterCompiledProgram* compiledProgram() const { return m_compiledProgram.get(); }
+    void setCompiledProgram(PassRefPtr<CustomFilterCompiledProgram>);
+
 private:
-    CustomFilterRenderer(PassRefPtr<GraphicsContext3D>, PassRefPtr<CustomFilterValidatedProgram>, const CustomFilterParameterList&,
+    CustomFilterRenderer(PassRefPtr<GraphicsContext3D>, CustomFilterProgramType, const CustomFilterParameterList&,
         unsigned meshRows, unsigned meshColumns, CustomFilterMeshBoxType, CustomFilterMeshType);
 
     void initializeCompiledProgramIfNeeded();
@@ -80,8 +83,8 @@
     void unbindVertexAttributes();
 
     RefPtr<GraphicsContext3D> m_context;
-    RefPtr<CustomFilterValidatedProgram> m_validatedProgram;
     RefPtr<CustomFilterCompiledProgram> m_compiledProgram;
+    CustomFilterProgramType m_programType;    
     RefPtr<CustomFilterMesh> m_mesh;
     IntSize m_contextSize;
 

Modified: trunk/Source/WebCore/platform/graphics/filters/FECustomFilter.cpp (133802 => 133803)


--- trunk/Source/WebCore/platform/graphics/filters/FECustomFilter.cpp	2012-11-07 21:30:05 UTC (rev 133802)
+++ trunk/Source/WebCore/platform/graphics/filters/FECustomFilter.cpp	2012-11-07 21:30:54 UTC (rev 133803)
@@ -48,7 +48,7 @@
     unsigned meshRows, unsigned meshColumns, CustomFilterMeshBoxType meshBoxType, CustomFilterMeshType meshType)
     : FilterEffect(filter)
     , m_context(context)
-    , m_customFilterRenderer(CustomFilterRenderer::create(m_context, validatedProgram, parameters, meshRows, meshColumns, meshBoxType, meshType))
+    , m_validatedProgram(validatedProgram)
     , m_inputTexture(0)
     , m_frameBuffer(0)
     , m_depthBuffer(0)
@@ -58,6 +58,8 @@
     , m_multisampleRenderBuffer(0)
     , m_multisampleDepthBuffer(0)
 {
+    // We will not pass a CustomFilterCompiledProgram here, as we only want to compile it when we actually need it in the first paint.
+    m_customFilterRenderer = CustomFilterRenderer::create(m_context, m_validatedProgram->programInfo().programType(), parameters, meshRows, meshColumns, meshBoxType, meshType);
 }
 
 PassRefPtr<FECustomFilter> FECustomFilter::create(Filter* filter, PassRefPtr<GraphicsContext3D> context, PassRefPtr<CustomFilterValidatedProgram> validatedProgram, const CustomFilterParameterList& parameters,
@@ -154,6 +156,10 @@
 {
     m_context->makeContextCurrent();
 
+    // Lazily inject the compiled program into the CustomFilterRenderer.
+    if (!m_customFilterRenderer->compiledProgram())
+        m_customFilterRenderer->setCompiledProgram(m_validatedProgram->compiledProgram());
+
     if (!m_customFilterRenderer->prepareForDrawing())
         return false;
 

Modified: trunk/Source/WebCore/platform/graphics/filters/FECustomFilter.h (133802 => 133803)


--- trunk/Source/WebCore/platform/graphics/filters/FECustomFilter.h	2012-11-07 21:30:05 UTC (rev 133802)
+++ trunk/Source/WebCore/platform/graphics/filters/FECustomFilter.h	2012-11-07 21:30:54 UTC (rev 133803)
@@ -87,6 +87,7 @@
     void deleteRenderBuffers();
 
     RefPtr<GraphicsContext3D> m_context;
+    RefPtr<CustomFilterValidatedProgram> m_validatedProgram;
     RefPtr<CustomFilterRenderer> m_customFilterRenderer;
     IntSize m_contextSize;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to