Bug 43589

Summary: Compositing should be exposed in terms of GraphicsContext3D, not WebGL specifically
Product: WebKit Reporter: James Robinson <jamesr>
Component: New BugsAssignee: James Robinson <jamesr>
Status: RESOLVED FIXED    
Severity: Normal CC: cmarrin, eric, senorblanco, simon.fraser, vangelis
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Other   
OS: OS X 10.5   
Bug Depends on:    
Bug Blocks: 43362    
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
compile tested on mac with and without 3D_CANVAS enabled
none
Patch none

Description James Robinson 2010-08-05 16:45:56 PDT
Compositing should be exposed in terms of GraphicsContext3D, not WebGL specifically
Comment 1 James Robinson 2010-08-05 18:23:36 PDT
Created attachment 63673 [details]
Patch
Comment 2 James Robinson 2010-08-05 18:24:36 PDT
Vangelis, would you mind checking the chromium bits over?

I've tested this by running the layout tests and testing the Khronos WebGL demos manually in Chromium/Linux and Safari/Snow Leopard.
Comment 3 Eric Seidel (no email) 2010-08-05 18:32:41 PDT
Attachment 63673 [details] did not build on mac:
Build output: http://queues.webkit.org/results/3588897
Comment 4 James Robinson 2010-08-05 18:37:07 PDT
Fixing the compile issue.  Not sure how I missed that locally.
Comment 5 Vangelis Kokkevis 2010-08-05 18:42:33 PDT
Comment on attachment 63673 [details]
Patch

> diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
> index 19a735623a68b6ce2346f941715910ade685ba56..ec106884b9e87ff8b39d7bceb831cf40891e1f04 100644
> --- a/WebCore/ChangeLog
> +++ b/WebCore/ChangeLog
> @@ -1,3 +1,51 @@
> +2010-08-05  James Robinson  <jamesr@chromium.org>
> +
> +        Reviewed by NOBODY (OOPS!).
> +
> +        Compositing should be exposed in terms of GraphicsContext3D, not WebGL specifically
> +        https://bugs.webkit.org/show_bug.cgi?id=43589
> +
> +        This treats all GraphicsContext3D-backed layers the same instead of special casing WebGL.
> +        The cross-platform change is to rename GraphicsLayer::setContentsToWebGL() to
> +        GraphicsLayer::setContentsToGraphicsContext3D and to rename all implementations.
> +
> +        This patch also renames the chromium class used for accelerating these layers.
> +
> +        * WebCore.gypi:
> +        * platform/graphics/GraphicsLayer.h:
> +        (WebCore::GraphicsLayer::setContentsToGraphicsContext3D):
> +        * platform/graphics/chromium/GraphicsContext3DLayerChromium.cpp: Added.
> +        (WebCore::GraphicsContext3DLayerChromium::create):
> +        (WebCore::GraphicsContext3DLayerChromium::GraphicsContext3DLayerChromium):
> +        (WebCore::GraphicsContext3DLayerChromium::textureId):
> +        (WebCore::GraphicsContext3DLayerChromium::updateTextureContents):
> +        (WebCore::GraphicsContext3DLayerChromium::setContext):
> +        * platform/graphics/chromium/GraphicsContext3DLayerChromium.h: Added.
> +        (WebCore::GraphicsContext3DLayerChromium::drawsContent):
> +        (WebCore::GraphicsContext3DLayerChromium::ownsTexture):
> +        (WebCore::GraphicsContext3DLayerChromium::shaderProgramId):
> +        (WebCore::GraphicsContext3DLayerChromium::setShaderProgramId):
> +        (WebCore::GraphicsContext3DLayerChromium::setPrepareTextureCallback):
> +        * platform/graphics/chromium/GraphicsLayerChromium.cpp:
> +        (WebCore::GraphicsLayerChromium::setContentsNeedsDisplay):
> +        (WebCore::GraphicsLayerChromium::setContentsToGraphicsContext3D):
> +        * platform/graphics/chromium/GraphicsLayerChromium.h:
> +        (WebCore::GraphicsLayerChromium::):
> +        * platform/graphics/chromium/LayerRendererChromium.cpp:
> +        (WebCore::LayerRendererChromium::drawLayer):
> +        (WebCore::LayerRendererChromium::initializeSharedGLObjects):
> +        * platform/graphics/chromium/LayerRendererChromium.h:
> +        (WebCore::LayerRendererChromium::):
> +        * platform/graphics/chromium/WebGLLayerChromium.cpp: Removed.
> +        * platform/graphics/chromium/WebGLLayerChromium.h: Removed.
> +        * platform/graphics/mac/GraphicsLayerCA.h:
> +        * platform/graphics/mac/GraphicsLayerCA.mm:
> +        (WebCore::GraphicsLayerCA::setContentsToGraphicsContext3D):
> +        * rendering/RenderLayerBacking.cpp:
> +        (WebCore::RenderLayerBacking::updateGraphicsLayerConfiguration):
> +        (WebCore::RenderLayerBacking::containsPaintedContent):
> +        (WebCore::RenderLayerBacking::rendererContentChanged):
> +
>  2010-08-05  Eric Seidel  <eric@webkit.org>
>  
>          Reviewed by Nikolas Zimmermann.
> diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
> index bad123ee2337b6a9e026b44ea2e1ac46fa3d1389..d8fdbb4f808a5db2766b2d3c50bbebfc11ac11a3 100644
> --- a/WebCore/WebCore.gypi
> +++ b/WebCore/WebCore.gypi
> @@ -2194,6 +2194,8 @@
>              'platform/graphics/chromium/GLES2Texture.h',
>              'platform/graphics/chromium/GlyphPageTreeNodeChromiumWin.cpp',
>              'platform/graphics/chromium/GlyphPageTreeNodeLinux.cpp',
> +            'platform/graphics/chromium/GraphicsContext3DLayerChromium.cpp',
> +            'platform/graphics/chromium/GraphicsContext3DLayerChromium.h',
>              'platform/graphics/chromium/GraphicsLayerChromium.cpp',
>              'platform/graphics/chromium/GraphicsLayerChromium.h',
>              'platform/graphics/chromium/IconChromiumLinux.cpp',
> @@ -2221,8 +2223,6 @@
>              'platform/graphics/chromium/UniscribeHelperTextRun.h',
>              'platform/graphics/chromium/VideoLayerChromium.cpp',
>              'platform/graphics/chromium/VideoLayerChromium.h',
> -            'platform/graphics/chromium/WebGLLayerChromium.cpp',
> -            'platform/graphics/chromium/WebGLLayerChromium.h',
>              'platform/graphics/filters/FEBlend.cpp',
>              'platform/graphics/filters/FEBlend.h',
>              'platform/graphics/filters/FEColorMatrix.cpp',
> diff --git a/WebCore/platform/graphics/GraphicsLayer.h b/WebCore/platform/graphics/GraphicsLayer.h
> index a5819f49d9abb6158da1d913d3691e4b0f2ceb0f..9582ca9b8912f840a07a4726c2299b82d02c1aa2 100644
> --- a/WebCore/platform/graphics/GraphicsLayer.h
> +++ b/WebCore/platform/graphics/GraphicsLayer.h
> @@ -298,9 +298,7 @@ public:
>      virtual void setContentsToImage(Image*) { }
>      virtual void setContentsToMedia(PlatformLayer*) { } // video or plug-in
>      virtual void setContentsBackgroundColor(const Color&) { }
> -#if ENABLE(3D_CANVAS)
> -    virtual void setContentsToWebGL(PlatformLayer*) { }
> -#endif
> +    virtual void setContentsToGraphicsContext3D(PlatformLayer*) { }
>      virtual bool hasContentsLayer() const { return false; }
>  
>      // Callback from the underlying graphics system to draw layer contents.
> diff --git a/WebCore/platform/graphics/chromium/WebGLLayerChromium.cpp b/WebCore/platform/graphics/chromium/GraphicsContext3DLayerChromium.cpp
> similarity index 83%
> rename from WebCore/platform/graphics/chromium/WebGLLayerChromium.cpp
> rename to WebCore/platform/graphics/chromium/GraphicsContext3DLayerChromium.cpp
> index ebd9ebe61608d23edd4f0a20fc56584f389ad8d6..5ae4a34c2637dde78e0d68a3d27b6b20dd6a29bd 100644
> --- a/WebCore/platform/graphics/chromium/WebGLLayerChromium.cpp
> +++ b/WebCore/platform/graphics/chromium/GraphicsContext3DLayerChromium.cpp
> @@ -32,21 +32,21 @@
>  
>  #if USE(ACCELERATED_COMPOSITING)
>  
> -#include "WebGLLayerChromium.h"
> +#include "GraphicsContext3DLayerChromium.h"
>  
>  #include "GraphicsContext3D.h"
>  #include <GLES2/gl2.h>
>  
>  namespace WebCore {
>  
> -unsigned WebGLLayerChromium::m_shaderProgramId = 0;
> +unsigned GraphicsContext3DLayerChromium::m_shaderProgramId = 0;
>  
> -PassRefPtr<WebGLLayerChromium> WebGLLayerChromium::create(GraphicsLayerChromium* owner)
> +PassRefPtr<GraphicsContext3DLayerChromium> GraphicsContext3DLayerChromium::create(GraphicsLayerChromium* owner)
>  {
> -    return adoptRef(new WebGLLayerChromium(owner));
> +    return adoptRef(new GraphicsContext3DLayerChromium(owner));
>  }
>  
> -WebGLLayerChromium::WebGLLayerChromium(GraphicsLayerChromium* owner)
> +GraphicsContext3DLayerChromium::GraphicsContext3DLayerChromium(GraphicsLayerChromium* owner)
>      : LayerChromium(owner)
>      , m_context(0)
>      , m_textureId(0)
> @@ -54,12 +54,12 @@ WebGLLayerChromium::WebGLLayerChromium(GraphicsLayerChromium* owner)
>  {
>  }
>  
> -unsigned WebGLLayerChromium::textureId()
> +unsigned GraphicsContext3DLayerChromium::textureId()
>  {
>      return m_textureId;
>  }
>  
> -void WebGLLayerChromium::updateTextureContents(unsigned textureId)
> +void GraphicsContext3DLayerChromium::updateTextureContents(unsigned textureId)
>  {
>      ASSERT(textureId == m_textureId);
>      ASSERT(m_context);
> @@ -80,7 +80,7 @@ void WebGLLayerChromium::updateTextureContents(unsigned textureId)
>      }
>  }
>  
> -void WebGLLayerChromium::setContext(const GraphicsContext3D* context)
> +void GraphicsContext3DLayerChromium::setContext(const GraphicsContext3D* context)
>  {
>      m_context = const_cast<GraphicsContext3D*>(context);
>  
> diff --git a/WebCore/platform/graphics/chromium/WebGLLayerChromium.h b/WebCore/platform/graphics/chromium/GraphicsContext3DLayerChromium.h
> similarity index 85%
> rename from WebCore/platform/graphics/chromium/WebGLLayerChromium.h
> rename to WebCore/platform/graphics/chromium/GraphicsContext3DLayerChromium.h
> index abd0c93c3b835877fd8dd7708f2ba59ceddff48d..1b2a8a690ba7cf3e953e530b8f7754822c124b14 100644
> --- a/WebCore/platform/graphics/chromium/WebGLLayerChromium.h
> +++ b/WebCore/platform/graphics/chromium/GraphicsContext3DLayerChromium.h
> @@ -29,8 +29,8 @@
>   */
>  
>  
> -#ifndef WebGLLayerChromium_h
> -#define WebGLLayerChromium_h
> +#ifndef GraphicsContext3DLayerChromium_h
> +#define GraphicsContext3DLayerChromium_h
>  
>  #if USE(ACCELERATED_COMPOSITING)
>  
> @@ -40,10 +40,10 @@ namespace WebCore {
>  
>  class GraphicsContext3D;
>  
> -// A Layer that contains a WebGL element.
> -class WebGLLayerChromium : public LayerChromium {
> +// A Layer that containing GraphicsContext3D-rendered content
> +class GraphicsContext3DLayerChromium : public LayerChromium {
>  public:
> -    static PassRefPtr<WebGLLayerChromium> create(GraphicsLayerChromium* owner = 0);
> +    static PassRefPtr<GraphicsContext3DLayerChromium> create(GraphicsLayerChromium* owner = 0);
>      virtual bool drawsContent() { return m_context; }
>      virtual bool ownsTexture() { return true; }
>      virtual void updateTextureContents(unsigned);
> @@ -55,7 +55,7 @@ public:
>      static void setShaderProgramId(unsigned shaderProgramId) { m_shaderProgramId = shaderProgramId; }
>  
>  private:
> -    WebGLLayerChromium(GraphicsLayerChromium* owner);
> +    explicit GraphicsContext3DLayerChromium(GraphicsLayerChromium* owner);
>      GraphicsContext3D* m_context;
>      unsigned m_textureId;
>      bool m_textureChanged;
> diff --git a/WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp b/WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp
> index e895cee09a60da517477465e9737fed21ae9bb1d..d0a6f5db0dd06223c72a349d42b893da716727b6 100644
> --- a/WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp
> +++ b/WebCore/platform/graphics/chromium/GraphicsLayerChromium.cpp
> @@ -47,13 +47,14 @@
>  
>  #include "FloatConversion.h"
>  #include "FloatRect.h"
> +#include "GraphicsContext3DLayerChromium.h"
>  #include "Image.h"
>  #include "ImageLayerChromium.h"
>  #include "LayerChromium.h"
>  #include "PlatformString.h"
>  #include "SystemTime.h"
>  #include "TransformLayerChromium.h"
> -#include "WebGLLayerChromium.h"
> +
>  #include <wtf/CurrentTime.h>
>  #include <wtf/StringExtras.h>
>  #include <wtf/text/CString.h>
> @@ -285,6 +286,11 @@ void GraphicsLayerChromium::setOpacity(float opacity)
>      primaryLayer()->setOpacity(opacity);
>  }
>  
> +void GraphicsLayerChromium::setContentsNeedsDisplay()
> +{
> +    if (m_contentsLayer)
> +        m_contentsLayer->setNeedsDisplay();
> +}
>  void GraphicsLayerChromium::setNeedsDisplay()
>  {
>      if (drawsContent())
> @@ -334,19 +340,18 @@ void GraphicsLayerChromium::setContentsToImage(Image* image)
>          updateSublayerList();
>  }
>  
> -#if ENABLE(3D_CANVAS)
> -void GraphicsLayerChromium::setContentsToWebGL(PlatformLayer* platformLayer)
> +void GraphicsLayerChromium::setContentsToGraphicsContext3D(PlatformLayer* platformLayer)
>  {
>      bool childrenChanged = false;
>      if (platformLayer) {
> -        if (!m_contentsLayer.get() || m_contentsLayerPurpose != ContentsLayerForWebGL) {
> -            WebGLLayerChromium* webGLLayer = static_cast<WebGLLayerChromium*>(platformLayer);
> -            setupContentsLayer(webGLLayer);
> -            m_contentsLayer = webGLLayer;
> -            m_contentsLayerPurpose = ContentsLayerForWebGL;
> +        platformLayer->setOwner(this);
> +        if (!m_contentsLayer.get() || m_contentsLayerPurpose != ContentsLayerForGraphicsContext3D) {
> +            GraphicsContext3DLayerChromium* graphicsContext3DLayer = static_cast<GraphicsContext3DLayerChromium*>(platformLayer);
> +            setupContentsLayer(graphicsContext3DLayer);
> +            m_contentsLayer = graphicsContext3DLayer;
> +            m_contentsLayerPurpose = ContentsLayerForGraphicsContext3D;
>              childrenChanged = true;
>          }
> -        platformLayer->setOwner(this);
>          platformLayer->setNeedsDisplay();
>          updateContentsRect();
>      } else {
> @@ -361,7 +366,6 @@ void GraphicsLayerChromium::setContentsToWebGL(PlatformLayer* platformLayer)
>      if (childrenChanged)
>          updateSublayerList();
>  }
> -#endif
>  
>  void GraphicsLayerChromium::setContentsToMedia(PlatformLayer* layer)
>  {
> diff --git a/WebCore/platform/graphics/chromium/GraphicsLayerChromium.h b/WebCore/platform/graphics/chromium/GraphicsLayerChromium.h
> index cd5e4799ab4f031a41831200e8a58d27920e3420..bc72e6e75ed6d843a76b8afa66864012c7210316 100644
> --- a/WebCore/platform/graphics/chromium/GraphicsLayerChromium.h
> +++ b/WebCore/platform/graphics/chromium/GraphicsLayerChromium.h
> @@ -81,12 +81,13 @@ public:
>  
>      virtual void setNeedsDisplay();
>      virtual void setNeedsDisplayInRect(const FloatRect&);
> +    virtual void setContentsNeedsDisplay();
>  
>      virtual void setContentsRect(const IntRect&);
>  
>      virtual void setContentsToImage(Image*);
>      virtual void setContentsToMedia(PlatformLayer*);
> -    virtual void setContentsToWebGL(PlatformLayer*);
> +    virtual void setContentsToGraphicsContext3D(PlatformLayer*);
>  
>      virtual PlatformLayer* platformLayer() const;
>  
> @@ -137,7 +138,7 @@ private:
>          NoContentsLayer = 0,
>          ContentsLayerForImage,
>          ContentsLayerForVideo,
> -        ContentsLayerForWebGL
> +        ContentsLayerForGraphicsContext3D
>      };
>  
>      ContentsLayerPurpose m_contentsLayerPurpose;
> diff --git a/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp b/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp
> index e98a65a2c23662b68650883e9ca8e5546d81c934..c5c26f77c24c36f9e053a92ecb8c012443d695b4 100644
> --- a/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp
> +++ b/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp
> @@ -35,10 +35,10 @@
>  #include "LayerRendererChromium.h"
>  
>  #include "GLES2Context.h"
> +#include "GraphicsContext3DLayerChromium.h"
>  #include "LayerChromium.h"
>  #include "NotImplemented.h"
>  #include "TransformLayerChromium.h"
> -#include "WebGLLayerChromium.h"
>  #if PLATFORM(SKIA)
>  #include "NativeImageSkia.h"
>  #include "PlatformContextSkia.h"
> @@ -691,6 +691,7 @@ void LayerRendererChromium::drawLayer(LayerChromium* layer)
>          if (layer->contentsDirty()) {
>              // Update the backing texture contents for any dirty portion of the layer.
>              layer->updateTextureContents(textureId);
> +            m_gles2Context->makeCurrent();
>          }
>  
>          if (layer->doubleSided())
> @@ -770,9 +771,9 @@ bool LayerRendererChromium::initializeSharedGLObjects()
>          "  gl_FragColor = vec4(texColor.x, texColor.y, texColor.z, texColor.w); \n"
>          "}                                                   \n";
>  
> -    // WebGL layers need to be flipped vertically and their colors shouldn't be
> +    // GraphicsContext3D layers need to be flipped vertically and their colors shouldn't be
>      // swizzled.
> -    char webGLFragmentShaderString[] =
> +    char graphicsContext3DFragmentShaderString[] =
>          "precision mediump float;                            \n"
>          "varying vec2 v_texCoord;                            \n"
>          "uniform sampler2D s_texture;                        \n"
> @@ -819,11 +820,11 @@ bool LayerRendererChromium::initializeSharedGLObjects()
>      }
>      LayerChromium::setShaderProgramId(ContentLayerProgram);
>  
> -    if (!createLayerShader(WebGLLayerProgram, vertexShaderString, webGLFragmentShaderString)) {
> -        LOG_ERROR("Failed to create shader program for WebGL layers");
> +    if (!createLayerShader(GraphicsContext3DLayerProgram, vertexShaderString, graphicsContext3DFragmentShaderString)) {
> +        LOG_ERROR("Failed to create shader program for GraphicsContext3D layers");
>          return false;
>      }
> -    WebGLLayerChromium::setShaderProgramId(WebGLLayerProgram);
> +    GraphicsContext3DLayerChromium::setShaderProgramId(GraphicsContext3DLayerProgram);
>  
>      if (!createLayerShader(ScrollLayerProgram, vertexShaderString, scrollFragmentShaderString)) {
>          LOG_ERROR("Failed to create shader program for scrolling layer");
> @@ -838,7 +839,7 @@ bool LayerRendererChromium::initializeSharedGLObjects()
>      // Specify the attrib location for the position and texCoord and make it the same for all programs to
>      // avoid binding re-binding the vertex attributes.
>      bindCommonAttribLocations(ContentLayerProgram);
> -    bindCommonAttribLocations(WebGLLayerProgram);
> +    bindCommonAttribLocations(GraphicsContext3DLayerProgram);
>      bindCommonAttribLocations(DebugBorderProgram);
>      bindCommonAttribLocations(ScrollLayerProgram);
>  
> diff --git a/WebCore/platform/graphics/chromium/LayerRendererChromium.h b/WebCore/platform/graphics/chromium/LayerRendererChromium.h
> index 17e7e5780353c1ba0ec8e9922af9dba8d283ac0f..f55f7c8b7a470dcb76df9847bc5b7c0b81d37a1c 100644
> --- a/WebCore/platform/graphics/chromium/LayerRendererChromium.h
> +++ b/WebCore/platform/graphics/chromium/LayerRendererChromium.h
> @@ -88,7 +88,7 @@ public:
>      GraphicsContext* rootLayerGraphicsContext() const { return m_rootLayerGraphicsContext.get(); }
>  
>  private:
> -    enum ShaderProgramType { DebugBorderProgram, ScrollLayerProgram, ContentLayerProgram, WebGLLayerProgram, NumShaderProgramTypes };
> +    enum ShaderProgramType { DebugBorderProgram, ScrollLayerProgram, ContentLayerProgram, GraphicsContext3DLayerProgram, NumShaderProgramTypes };
>  
>      void updateLayersRecursive(LayerChromium* layer, const TransformationMatrix& parentMatrix, float opacity, const IntRect& visibleRect);
>  
> diff --git a/WebCore/platform/graphics/mac/GraphicsLayerCA.h b/WebCore/platform/graphics/mac/GraphicsLayerCA.h
> index 80c822c65f7145484168da166c0aad68fcbd4ec9..549f31bf50b0eb8491c25968c74b64ed3ab5e1d6 100644
> --- a/WebCore/platform/graphics/mac/GraphicsLayerCA.h
> +++ b/WebCore/platform/graphics/mac/GraphicsLayerCA.h
> @@ -103,9 +103,8 @@ public:
>      
>      virtual void setContentsToImage(Image*);
>      virtual void setContentsToMedia(PlatformLayer*);
> -#if ENABLE(3D_CANVAS)
> -    virtual void setContentsToWebGL(PlatformLayer*);
> -#endif
> +    virtual void setContentsToGraphicsContext3D(PlatformLayer*);
> +
>      virtual bool hasContentsLayer() const { return m_contentsLayer; }
>      
>      virtual PlatformLayer* platformLayer() const;
> diff --git a/WebCore/platform/graphics/mac/GraphicsLayerCA.mm b/WebCore/platform/graphics/mac/GraphicsLayerCA.mm
> index 9f1ac8338f9bdc149aa3d89cad35f31f3447c837..7f0bc3fd4d55686a753d5b528ae06cec10dc3bf6 100644
> --- a/WebCore/platform/graphics/mac/GraphicsLayerCA.mm
> +++ b/WebCore/platform/graphics/mac/GraphicsLayerCA.mm
> @@ -1722,8 +1722,7 @@ void GraphicsLayerCA::pauseAnimationOnLayer(AnimatedPropertyID property, const S
>      }
>  }
>  
> -#if ENABLE(3D_CANVAS)
> -void GraphicsLayerCA::setContentsToWebGL(PlatformLayer* webglLayer)
> +void GraphicsLayerCA::setContentsToGraphicsContext3D(PlatformLayer* webglLayer)
>  {
>      if (webglLayer == m_contentsLayer)
>          return;
> @@ -1737,7 +1736,6 @@ void GraphicsLayerCA::setContentsToWebGL(PlatformLayer* webglLayer)
>      noteSublayersChanged();
>      noteLayerPropertyChanged(ContentsWebGLLayerChanged);
>  }
> -#endif
>      
>  void GraphicsLayerCA::repaintLayerDirtyRects()
>  {
> diff --git a/WebCore/rendering/RenderLayerBacking.cpp b/WebCore/rendering/RenderLayerBacking.cpp
> index 0e5933e45a839651b138c5068f54e4dc8fa9cfe7..af18247901ae6400c16771936bb89c567fa592a3 100644
> --- a/WebCore/rendering/RenderLayerBacking.cpp
> +++ b/WebCore/rendering/RenderLayerBacking.cpp
> @@ -28,13 +28,12 @@
>  #if USE(ACCELERATED_COMPOSITING)
>  
>  #include "AnimationController.h"
> -#if ENABLE(3D_CANVAS)    
> -#include "WebGLRenderingContext.h"
> -#endif
> +#include "CanvasRenderingContext.h"
>  #include "CSSPropertyNames.h"
>  #include "CSSStyleSelector.h"
>  #include "FrameView.h"
>  #include "GraphicsContext.h"
> +#include "GraphicsContext3D.h"
>  #include "GraphicsLayer.h"
>  #include "HTMLCanvasElement.h"
>  #include "HTMLElement.h"
> @@ -252,14 +251,13 @@ bool RenderLayerBacking::updateGraphicsLayerConfiguration()
>          m_graphicsLayer->setContentsToMedia(mediaElement->platformLayer());
>      }
>  #endif
> -#if ENABLE(3D_CANVAS)    
> -    else if (is3DCanvas(renderer())) {
> +    else if (renderer()->isCanvas()) {
>          HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(renderer()->node());
> -        WebGLRenderingContext* context = static_cast<WebGLRenderingContext*>(canvas->renderingContext());
> -        if (context->graphicsContext3D()->platformLayer())
> -            m_graphicsLayer->setContentsToWebGL(context->graphicsContext3D()->platformLayer());
> +        if (CanvasRenderingContext* context = canvas->renderingContext())
> +            if (context->graphicsContext3D())
> +                if (PlatformLayer* pl = context->graphicsContext3D()->platformLayer())
> +                    m_graphicsLayer->setContentsToGraphicsContext3D(pl);
>      }
> -#endif
>  
>      if (renderer()->isRenderIFrame())
>          layerConfigChanged = RenderLayerCompositor::parentIFrameContentLayers(toRenderIFrame(renderer()));
> @@ -758,6 +756,10 @@ bool RenderLayerBacking::containsPaintedContent() const
>      // and set background color on the layer in that case, instead of allocating backing store and painting.
>      if (renderer()->isVideo() || is3DCanvas(renderer()))
>          return hasBoxDecorationsOrBackground(renderer());
> +#if ENABLE(ACCELERATED_2D_CANVAS)
> +    if (renderer()->isCanvas())
> +        return hasBoxDecorationsOrBackground(renderer());
> +#endif
>  
>      return true;
>  }
> @@ -783,6 +785,12 @@ void RenderLayerBacking::rendererContentChanged()
>          return;
>      }
>  #endif
> +#if ENABLE(ACCELERATED_2D_CANVAS)
> +    if (renderer()->isCanvas()) {
> +        m_graphicsLayer->setContentsNeedsDisplay();
> +        return;
> +    }
> +#endif
>  }
>  
>  void RenderLayerBacking::updateImageContents()
> diff --git a/WebKit/chromium/ChangeLog b/WebKit/chromium/ChangeLog
> index 7048b8e1f8bbf0c3b0869f8e5d3fc48b468ad215..801d790654a30388405e2966446a6cd34e28dcbe 100644
> --- a/WebKit/chromium/ChangeLog
> +++ b/WebKit/chromium/ChangeLog
> @@ -1,3 +1,18 @@
> +2010-08-05  James Robinson  <jamesr@chromium.org>
> +
> +        Reviewed by NOBODY (OOPS!).
> +
> +        Compositing should be exposed in terms of GraphicsContext3D, not WebGL specifically
> +        https://bugs.webkit.org/show_bug.cgi?id=43589
> +
> +        Initializes the platformLayer as a Graphics3DLayerChromium, not a WebGLLayerChromium.
> +        The layer itself isn't WebGL-specific.
> +
> +        * src/GraphicsContext3D.cpp:
> +        (WebCore::GraphicsContext3DInternal::initialize):
> +        (WebCore::GraphicsContext3DInternal::platformLayer):
> +        (WebCore::GraphicsContext3D::platformLayer):
> +
>  2010-08-04  Kenneth Russell  <kbr@google.com>
>  
>          Reviewed by Dimitri Glazkov.
> diff --git a/WebKit/chromium/src/GraphicsContext3D.cpp b/WebKit/chromium/src/GraphicsContext3D.cpp
> index d6ad1a34ec495b4409e53ffcd02356f9201f7ae5..4a141dc2b67fe0417ebe8e3f5821d50b651616f0 100644
> --- a/WebKit/chromium/src/GraphicsContext3D.cpp
> +++ b/WebKit/chromium/src/GraphicsContext3D.cpp
> @@ -39,6 +39,7 @@
>  #include "Chrome.h"
>  #include "ChromeClientImpl.h"
>  #include "Float32Array.h"
> +#include "GraphicsContext3DLayerChromium.h"
>  #include "HTMLCanvasElement.h"
>  #include "HTMLImageElement.h"
>  #include "ImageBuffer.h"
> @@ -46,7 +47,6 @@
>  #include "Int32Array.h"
>  #include "Int8Array.h"
>  #include "Uint8Array.h"
> -#include "WebGLLayerChromium.h"
>  #include "WebGraphicsContext3D.h"
>  #include "WebGraphicsContext3DDefaultImpl.h"
>  #include "WebKit.h"
> @@ -111,7 +111,7 @@ public:
>      void prepareTexture();
>  
>  #if USE(ACCELERATED_COMPOSITING)
> -    WebGLLayerChromium* platformLayer() const;
> +    GraphicsContext3DLayerChromium* platformLayer() const;
>  #endif
>      bool isGLES2Compliant() const;
>  
> @@ -304,7 +304,7 @@ public:
>  private:
>      OwnPtr<WebKit::WebGraphicsContext3D> m_impl;
>  #if USE(ACCELERATED_COMPOSITING)
> -    RefPtr<WebGLLayerChromium> m_compositingLayer;
> +    RefPtr<GraphicsContext3DLayerChromium> m_compositingLayer;
>  #endif
>  #if PLATFORM(SKIA)
>      // If the width and height of the Canvas's backing store don't
> @@ -365,7 +365,7 @@ bool GraphicsContext3DInternal::initialize(GraphicsContext3D::Attributes attrs,
>      m_impl.set(webContext);
>  
>  #if USE(ACCELERATED_COMPOSITING)
> -    m_compositingLayer = WebGLLayerChromium::create(0);
> +    m_compositingLayer = GraphicsContext3DLayerChromium::create(0);
>  #endif
>      return true;
>  }
> @@ -386,7 +386,7 @@ void GraphicsContext3DInternal::prepareTexture()
>  }
>  
>  #if USE(ACCELERATED_COMPOSITING)
> -WebGLLayerChromium* GraphicsContext3DInternal::platformLayer() const
> +GraphicsContext3DLayerChromium* GraphicsContext3DInternal::platformLayer() const
>  {
>      return m_compositingLayer.get();
>  }
> @@ -1046,9 +1046,9 @@ void GraphicsContext3D::prepareTexture()
>  #if USE(ACCELERATED_COMPOSITING)
>  PlatformLayer* GraphicsContext3D::platformLayer() const
>  {
> -    WebGLLayerChromium* webGLLayer = m_internal->platformLayer();
> -    webGLLayer->setContext(this);
> -    return webGLLayer;
> +    GraphicsContext3DLayerChromium* graphicsContext3DLayer = m_internal->platformLayer();
> +    graphicsContext3DLayer->setContext(this);
> +    return graphicsContext3DLayer;
>  }
>  #endif
>  

Other than a couple of small comments, it looks good.

WebCore/platform/graphics/chromium/GraphicsContext3DLayerChromium.h:43
 +  // A Layer that containing GraphicsContext3D-rendered content
typo: Take out "that"

WebCore/rendering/RenderLayerBacking.cpp:760
 +      if (renderer()->isCanvas())
maybe a cleaner way to do this would be to replace the check for is3DCanvas() above with something that checks if you have a h/w accelerated canvas (2D or 3D)

WebCore/rendering/RenderLayerBacking.cpp:789
 +      if (renderer()->isCanvas()) {
Ditto here.
Comment 6 James Robinson 2010-08-05 19:11:16 PDT
Created attachment 63678 [details]
Patch
Comment 7 James Robinson 2010-08-05 19:14:03 PDT
Created attachment 63679 [details]
Patch
Comment 8 James Robinson 2010-08-05 19:14:50 PDT
Addressed Vangelis' comments and fixed the build for OS X 10.5.
Comment 9 Eric Seidel (no email) 2010-08-05 19:25:35 PDT
Attachment 63679 [details] did not build on mac:
Build output: http://queues.webkit.org/results/3619585
Comment 10 James Robinson 2010-08-05 20:55:32 PDT
Created attachment 63686 [details]
compile tested on mac with and without 3D_CANVAS enabled
Comment 11 Simon Fraser (smfr) 2010-08-06 08:53:10 PDT
Comment on attachment 63686 [details]
compile tested on mac with and without 3D_CANVAS enabled

> diff --git a/WebCore/platform/graphics/GraphicsLayer.h b/WebCore/platform/graphics/GraphicsLayer.h

> -#if ENABLE(3D_CANVAS)
> -    virtual void setContentsToWebGL(PlatformLayer*) { }
> -#endif
> +    virtual void setContentsToGraphicsContext3D(PlatformLayer*) { }

I think this name is a bit wordy, and not quite accurate: you're not passing a GraphicsContext3D in. I think "setContentsTo3D() would be OK, or perhaps setContentsTo3DLayer().

Even then, if this is used for an accelerated canvas, it's not just 3D. So setContentsToCanvas()? setContentsToAcceleratedCanvas()?

r=me with a better name.
Comment 12 Chris Marrin 2010-08-06 10:08:40 PDT
(In reply to comment #11)
> (From update of attachment 63686 [details])
> > diff --git a/WebCore/platform/graphics/GraphicsLayer.h b/WebCore/platform/graphics/GraphicsLayer.h
> 
> > -#if ENABLE(3D_CANVAS)
> > -    virtual void setContentsToWebGL(PlatformLayer*) { }
> > -#endif
> > +    virtual void setContentsToGraphicsContext3D(PlatformLayer*) { }
> 
> I think this name is a bit wordy, and not quite accurate: you're not passing a GraphicsContext3D in. I think "setContentsTo3D() would be OK, or perhaps setContentsTo3DLayer().
> 
> Even then, if this is used for an accelerated canvas, it's not just 3D. So setContentsToCanvas()? setContentsToAcceleratedCanvas()?
> 
> r=me with a better name.

Why not just setContents to PlatformLayer? The (current) implementation does pretty generic layer things to it - nothing specific to WebGL or 3D.
Comment 13 James Robinson 2010-08-06 11:05:48 PDT
(In reply to comment #11)
> (From update of attachment 63686 [details])
> > diff --git a/WebCore/platform/graphics/GraphicsLayer.h b/WebCore/platform/graphics/GraphicsLayer.h
> 
> > -#if ENABLE(3D_CANVAS)
> > -    virtual void setContentsToWebGL(PlatformLayer*) { }
> > -#endif
> > +    virtual void setContentsToGraphicsContext3D(PlatformLayer*) { }
> 
> I think this name is a bit wordy, and not quite accurate: you're not passing a GraphicsContext3D in. I think "setContentsTo3D() would be OK, or perhaps setContentsTo3DLayer().
> 
> Even then, if this is used for an accelerated canvas, it's not just 3D. So setContentsToCanvas()? setContentsToAcceleratedCanvas()?

I like setContentsToCanvas().  The 'accelerated'-ness is obvious from context.  I think we might want to use this for other types of layers in the future we be can rename it if/when 
> 
> r=me with a better name.

Thanks!  Will update the bug with a renamed patch.

(In reply to comment #12)
> 
> Why not just setContents to PlatformLayer? The (current) implementation does pretty generic layer things to it - nothing specific to WebGL or 3D.

That's only true in the mac compositor implementation.  In chromium we use different shaders for different layer types to control whether to flip a layer vertically, swizzle BGRA->RGBA, or do YUV->RGBA conversions.
Comment 14 Chris Marrin 2010-08-06 11:34:40 PDT
> (In reply to comment #12)
> > 
> > Why not just setContents to PlatformLayer? The (current) implementation does pretty generic layer things to it - nothing specific to WebGL or 3D.
> 
> That's only true in the mac compositor implementation.  In chromium we use different shaders for different layer types to control whether to flip a layer vertically, swizzle BGRA->RGBA, or do YUV->RGBA conversions.

Ok, that makes sense for now. But I'm getting concerned about all the setContentsTo... API's in GraphicsLayer. Right now we have setContentsToMedia and setContentsToCanvas, both of which pass a PlatformLayer. If we have to add a third, it will be time to change it to setContentsToPlatformLayer and pass in some kind of use flags or something.
Comment 15 Chris Marrin 2010-08-06 11:38:00 PDT
> (In reply to comment #12)
> > 
> > Why not just setContents to PlatformLayer? The (current) implementation does pretty generic layer things to it - nothing specific to WebGL or 3D.
> 
> That's only true in the mac compositor implementation.  In chromium we use different shaders for different layer types to control whether to flip a layer vertically, swizzle BGRA->RGBA, or do YUV->RGBA conversions.

One other thing. I don't see why GraphicsLayer needs to know about flipping and other layer specific issues. Why doesn't the passed PlatformLayer implementation deal with all this?
Comment 16 Vangelis Kokkevis 2010-08-06 11:43:34 PDT
(In reply to comment #15)
> > (In reply to comment #12)
> > > 
> > > Why not just setContents to PlatformLayer? The (current) implementation does pretty generic layer things to it - nothing specific to WebGL or 3D.
> > 
> > That's only true in the mac compositor implementation.  In chromium we use different shaders for different layer types to control whether to flip a layer vertically, swizzle BGRA->RGBA, or do YUV->RGBA conversions.
> 
> One other thing. I don't see why GraphicsLayer needs to know about flipping and other layer specific issues. Why doesn't the passed PlatformLayer implementation deal with all this?

I believe Chris is right. We can just pass a PlatformLayer of the right type which will handle the content as needed.
Comment 17 Chris Marrin 2010-08-06 11:59:58 PDT
(In reply to comment #16)
> (In reply to comment #15)
> > > (In reply to comment #12)
> > > > 
> > > > Why not just setContents to PlatformLayer? The (current) implementation does pretty generic layer things to it - nothing specific to WebGL or 3D.
> > > 
> > > That's only true in the mac compositor implementation.  In chromium we use different shaders for different layer types to control whether to flip a layer vertically, swizzle BGRA->RGBA, or do YUV->RGBA conversions.
> > 
> > One other thing. I don't see why GraphicsLayer needs to know about flipping and other layer specific issues. Why doesn't the passed PlatformLayer implementation deal with all this?
> 
> I believe Chris is right. We can just pass a PlatformLayer of the right type which will handle the content as needed.

Hmm. Ok, then maybe it would be best to make it setContentsToPlatformLayer. 

There is still the issue of setContentsToMedia, which also takes a PlatformLayer. Looking at the Mac implementation the only difference is that the webgllayer calls setNeedsDisplay and the media layer doesn't. But I bet we could make calling setNeedsDisplay on the media layer not be a bad thing. But we should do that separately. I filed a bug for this: https://bugs.webkit.org/show_bug.cgi?id=43634.

If you do make this change can you also change the other WebGL related enums and calls in GraphicsLayer (e.g., ContentsWebGLLayerChanged and updateContentsWebGLLayer())?
Comment 18 James Robinson 2010-08-06 13:38:26 PDT
> > 
> > I believe Chris is right. We can just pass a PlatformLayer of the right type which will handle the content as needed.
> 
> Hmm. Ok, then maybe it would be best to make it setContentsToPlatformLayer. 
> 
> There is still the issue of setContentsToMedia, which also takes a PlatformLayer. Looking at the Mac implementation the only difference is that the webgllayer calls setNeedsDisplay and the media layer doesn't. But I bet we could make calling setNeedsDisplay on the media layer not be a bad thing. But we should do that separately. I filed a bug for this: https://bugs.webkit.org/show_bug.cgi?id=43634.

OK - it sounds like after that bug is fixed then we should make it setContentsToPlatformLayer().  I'll update this patch to setContentsToCanvas() until that point.


> 
> If you do make this change can you also change the other WebGL related enums and calls in GraphicsLayer (e.g., ContentsWebGLLayerChanged and updateContentsWebGLLayer())?

Sure.
Comment 19 James Robinson 2010-08-06 13:40:42 PDT
Created attachment 63757 [details]
Patch
Comment 20 Simon Fraser (smfr) 2010-08-06 13:59:15 PDT
Comment on attachment 63757 [details]
Patch

r=me, assuming no regressions in WebGL tests
Comment 21 Chris Marrin 2010-08-06 14:18:27 PDT
(In reply to comment #20)
> (From update of attachment 63757 [details])
> r=me, assuming no regressions in WebGL tests

Good point. James, did you run all the WebGL tests?
Comment 22 James Robinson 2010-08-06 14:39:57 PDT
Yes, I ran the WebGL tests and tried out the Khronos-hosted WebGL demos on Safari / Snow Leopard and Chromium / Linux.
Comment 23 James Robinson 2010-08-06 14:49:39 PDT
Comment on attachment 63757 [details]
Patch

Clearing flags on attachment: 63757

Committed r64870: <http://trac.webkit.org/changeset/64870>
Comment 24 James Robinson 2010-08-06 14:49:46 PDT
All reviewed patches have been landed.  Closing bug.