[Chromium] Compositor doesn't support translucent root layers.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 9 Jun 2012 02:29:09 +0000 (02:29 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 9 Jun 2012 02:29:09 +0000 (02:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=87821

Patch by David Reveman <reveman@chromium.org> on 2012-06-08
Reviewed by James Robinson.

Source/Platform:

* chromium/public/WebLayer.h:
(WebLayer):
* chromium/public/WebLayerTreeView.h:
(WebLayerTreeView):

Source/WebCore:

Forward the isTransparent WebView setting to WebLayerTreeView,
CCLayerTreeHost and CCLayerTreeHostImpl as hasTransparentBackground.
Use hasTransparentBackground setting to determine how to clear the
root render pass and draw the background. Set opaque flag correctly
on the NonCompositedContentHost's graphics layer to make sure
sub-pixel rendering is not used with a transparent WebView.

Unit tests: CCLayerTreeHostImplTest.hasTransparentBackground
            LayerRendererChromiumTest2.opaqueRenderPass
            LayerRendererChromiumTest2.transparentRenderPass

* platform/graphics/chromium/BitmapCanvasLayerTextureUpdater.cpp:
(WebCore::BitmapCanvasLayerTextureUpdater::prepareToUpdate):
* platform/graphics/chromium/LayerRendererChromium.cpp:
(WebCore::LayerRendererChromium::clearRenderPass):
(WebCore::LayerRendererChromium::drawRenderPass):
(WebCore::LayerRendererChromium::drawBackgroundFilters):
* platform/graphics/chromium/LayerRendererChromium.h:
(LayerRendererChromium):
* platform/graphics/chromium/SkPictureCanvasLayerTextureUpdater.cpp:
(WebCore::SkPictureCanvasLayerTextureUpdater::prepareToUpdate):
* platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
(WebCore::CCLayerTreeHost::CCLayerTreeHost):
(WebCore::CCLayerTreeHost::finishCommitOnImplThread):
* platform/graphics/chromium/cc/CCLayerTreeHost.h:
(WebCore::CCLayerTreeHost::setHasTransparentBackground):
(CCLayerTreeHost):
* platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
(WebCore::CCLayerTreeHostImpl::CCLayerTreeHostImpl):
(WebCore::CCLayerTreeHostImpl::calculateRenderPasses):
* platform/graphics/chromium/cc/CCLayerTreeHostImpl.h:
(WebCore::CCLayerTreeHostImpl::hasTransparentBackground):
(WebCore::CCLayerTreeHostImpl::setHasTransparentBackground):
(CCLayerTreeHostImpl):
* platform/graphics/chromium/cc/CCRenderPass.cpp:
(WebCore::CCRenderPass::CCRenderPass):
* platform/graphics/chromium/cc/CCRenderPass.h:
(WebCore::CCRenderPass::hasTransparentBackground):
(WebCore::CCRenderPass::setHasTransparentBackground):
(CCRenderPass):

Source/WebKit/chromium:

* src/NonCompositedContentHost.cpp:
(WebKit::NonCompositedContentHost::setOpaque):
(WebKit):
* src/NonCompositedContentHost.h:
(NonCompositedContentHost):
* src/WebLayerTreeView.cpp:
(WebKit::WebLayerTreeView::setHasTransparentBackground):
(WebKit):
* src/WebViewImpl.cpp:
(WebKit::WebViewImpl::setIsTransparent):
(WebKit::WebViewImpl::setIsAcceleratedCompositingActive):
* tests/CCLayerTreeHostImplTest.cpp:
* tests/LayerRendererChromiumTest.cpp:
(ClearCountingContext):
(ClearCountingContext::ClearCountingContext):
(ClearCountingContext::clear):
(ClearCountingContext::clearCount):
(TEST):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@119887 268f45cc-cd09-0410-ab3c-d52691b4dbfc

21 files changed:
Source/Platform/ChangeLog
Source/Platform/chromium/public/WebLayer.h
Source/Platform/chromium/public/WebLayerTreeView.h
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/chromium/BitmapCanvasLayerTextureUpdater.cpp
Source/WebCore/platform/graphics/chromium/LayerRendererChromium.cpp
Source/WebCore/platform/graphics/chromium/LayerRendererChromium.h
Source/WebCore/platform/graphics/chromium/SkPictureCanvasLayerTextureUpdater.cpp
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp
Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostImpl.h
Source/WebCore/platform/graphics/chromium/cc/CCRenderPass.cpp
Source/WebCore/platform/graphics/chromium/cc/CCRenderPass.h
Source/WebKit/chromium/ChangeLog
Source/WebKit/chromium/src/NonCompositedContentHost.cpp
Source/WebKit/chromium/src/NonCompositedContentHost.h
Source/WebKit/chromium/src/WebLayerTreeView.cpp
Source/WebKit/chromium/src/WebViewImpl.cpp
Source/WebKit/chromium/tests/CCLayerTreeHostImplTest.cpp
Source/WebKit/chromium/tests/LayerRendererChromiumTest.cpp

index c057176..8b84ce2 100644 (file)
@@ -1,3 +1,15 @@
+2012-06-08  David Reveman  <reveman@chromium.org>
+
+        [Chromium] Compositor doesn't support translucent root layers.
+        https://bugs.webkit.org/show_bug.cgi?id=87821
+
+        Reviewed by James Robinson.
+
+        * chromium/public/WebLayer.h:
+        (WebLayer):
+        * chromium/public/WebLayerTreeView.h:
+        (WebLayerTreeView):
+
 2012-06-06  Mark Pilgrim  <pilgrim@chromium.org>
 
         [Chromium] Move createMessagePortChannel to Platform.h
index 375cac5..8fc3d2d 100644 (file)
@@ -116,9 +116,9 @@ public:
 
     // Apply filters to pixels that show through the background of this layer.
     // Note: These filters are only possible on layers that are drawn directly
-    // to the root render surface. This means if an ancestor of the background-
-    // filtered layer sets certain properties (opacity, transforms), it may
-    // conflict and hide the background filters.
+    // to a root render surface with an opaque background. This means if an
+    // ancestor of the background-filtered layer sets certain properties
+    // (opacity, transforms), it may conflict and hide the background filters.
     WEBKIT_EXPORT void setBackgroundFilters(const WebFilterOperations&);
 
     WEBKIT_EXPORT void setDebugBorderColor(const WebColor&);
index 23d0d63..467f65c 100644 (file)
@@ -118,6 +118,9 @@ public:
     // Sets the background color for the viewport.
     WEBKIT_EXPORT void setBackgroundColor(WebColor);
 
+    // Sets the background transparency for the viewport. The default is 'false'.
+    WEBKIT_EXPORT void setHasTransparentBackground(bool);
+
     // Sets whether this view is visible. In threaded mode, a view that is not visible will not
     // composite or trigger updateAnimations() or layout() calls until it becomes visible.
     WEBKIT_EXPORT void setVisible(bool);
index a39f306..6066d07 100644 (file)
@@ -1,3 +1,51 @@
+2012-06-08  David Reveman  <reveman@chromium.org>
+
+        [Chromium] Compositor doesn't support translucent root layers.
+        https://bugs.webkit.org/show_bug.cgi?id=87821
+
+        Reviewed by James Robinson.
+
+        Forward the isTransparent WebView setting to WebLayerTreeView,
+        CCLayerTreeHost and CCLayerTreeHostImpl as hasTransparentBackground.
+        Use hasTransparentBackground setting to determine how to clear the
+        root render pass and draw the background. Set opaque flag correctly
+        on the NonCompositedContentHost's graphics layer to make sure
+        sub-pixel rendering is not used with a transparent WebView.
+
+        Unit tests: CCLayerTreeHostImplTest.hasTransparentBackground
+                    LayerRendererChromiumTest2.opaqueRenderPass
+                    LayerRendererChromiumTest2.transparentRenderPass
+
+        * platform/graphics/chromium/BitmapCanvasLayerTextureUpdater.cpp:
+        (WebCore::BitmapCanvasLayerTextureUpdater::prepareToUpdate):
+        * platform/graphics/chromium/LayerRendererChromium.cpp:
+        (WebCore::LayerRendererChromium::clearRenderPass):
+        (WebCore::LayerRendererChromium::drawRenderPass):
+        (WebCore::LayerRendererChromium::drawBackgroundFilters):
+        * platform/graphics/chromium/LayerRendererChromium.h:
+        (LayerRendererChromium):
+        * platform/graphics/chromium/SkPictureCanvasLayerTextureUpdater.cpp:
+        (WebCore::SkPictureCanvasLayerTextureUpdater::prepareToUpdate):
+        * platform/graphics/chromium/cc/CCLayerTreeHost.cpp:
+        (WebCore::CCLayerTreeHost::CCLayerTreeHost):
+        (WebCore::CCLayerTreeHost::finishCommitOnImplThread):
+        * platform/graphics/chromium/cc/CCLayerTreeHost.h:
+        (WebCore::CCLayerTreeHost::setHasTransparentBackground):
+        (CCLayerTreeHost):
+        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.cpp:
+        (WebCore::CCLayerTreeHostImpl::CCLayerTreeHostImpl):
+        (WebCore::CCLayerTreeHostImpl::calculateRenderPasses):
+        * platform/graphics/chromium/cc/CCLayerTreeHostImpl.h:
+        (WebCore::CCLayerTreeHostImpl::hasTransparentBackground):
+        (WebCore::CCLayerTreeHostImpl::setHasTransparentBackground):
+        (CCLayerTreeHostImpl):
+        * platform/graphics/chromium/cc/CCRenderPass.cpp:
+        (WebCore::CCRenderPass::CCRenderPass):
+        * platform/graphics/chromium/cc/CCRenderPass.h:
+        (WebCore::CCRenderPass::hasTransparentBackground):
+        (WebCore::CCRenderPass::setHasTransparentBackground):
+        (CCRenderPass):
+
 2012-06-08  Ian Vollick  <vollick@chromium.org>
 
         [chromium] Single thread proxy's animation timer should short circuit if the layer renderer has not been initialized
index 8245aa9..d205a17 100644 (file)
@@ -88,8 +88,9 @@ void BitmapCanvasLayerTextureUpdater::prepareToUpdate(const IntRect& contentRect
     // Assumption: if a tiler is using border texels, then it is because the
     // layer is likely to be filtered or transformed. Because of it might be
     // transformed, draw the text in grayscale instead of subpixel antialiasing.
+    bool useGrayscaleText = borderTexels || !layerIsOpaque;
     PlatformCanvas::Painter::TextOption textOption =
-        borderTexels ? PlatformCanvas::Painter::GrayscaleText : PlatformCanvas::Painter::SubpixelText;
+        useGrayscaleText ? PlatformCanvas::Painter::GrayscaleText : PlatformCanvas::Painter::SubpixelText;
     PlatformCanvas::Painter canvasPainter(&m_canvas, textOption);
     canvasPainter.skiaContext()->setTrackOpaqueRegion(!layerIsOpaque);
     paintContents(*canvasPainter.context(), *canvasPainter.skiaContext(), contentRect, contentsScale, resultingOpaqueRect);
index 55cf74f..780fc32 100644 (file)
@@ -402,15 +402,14 @@ void LayerRendererChromium::viewportChanged()
     m_currentRenderPass = 0;
 }
 
-void LayerRendererChromium::clearRenderPass(const CCRenderPass* renderPass, const CCRenderPass* rootRenderPass, const FloatRect& framebufferDamageRect)
+void LayerRendererChromium::clearRenderPass(const CCRenderPass* renderPass, const FloatRect& framebufferDamageRect)
 {
-    // Non-root layers should clear their entire contents to transparent. On DEBUG builds, the root layer
-    // is cleared to blue to easily see regions that were not drawn on the screen. If we
+    // On DEBUG builds, opaque render passes are cleared to blue to easily see regions that were not drawn on the screen. If we
     // are using partial swap / scissor optimization, then the surface should only
     // clear the damaged region, so that we don't accidentally clear un-changed portions
     // of the screen.
 
-    if (renderPass != rootRenderPass)
+    if (renderPass->hasTransparentBackground())
         GLC(m_context, m_context->clearColor(0, 0, 0, 0));
     else
         GLC(m_context, m_context->clearColor(0, 0, 1, 1));
@@ -421,7 +420,7 @@ void LayerRendererChromium::clearRenderPass(const CCRenderPass* renderPass, cons
         GLC(m_context, m_context->disable(GraphicsContext3D::SCISSOR_TEST));
 
 #if defined(NDEBUG)
-    if (renderPass != rootRenderPass)
+    if (renderPass->hasTransparentBackground())
 #endif
         m_context->clear(GraphicsContext3D::COLOR_BUFFER_BIT);
 
@@ -475,7 +474,7 @@ void LayerRendererChromium::drawRenderPass(const CCRenderPass* renderPass, const
     if (!useRenderPass(renderPass))
         return;
 
-    clearRenderPass(renderPass, m_defaultRenderPass, framebufferDamageRect);
+    clearRenderPass(renderPass, framebufferDamageRect);
 
     const CCQuadList& quadList = renderPass->quadList();
     for (CCQuadList::constBackToFrontIterator it = quadList.backToFrontBegin(); it != quadList.backToFrontEnd(); ++it)
@@ -615,10 +614,11 @@ void LayerRendererChromium::drawBackgroundFilters(const CCRenderPassDrawQuad* qu
     if (quad->backgroundFilters().isEmpty())
         return;
 
-    // FIXME: We only allow background filters on the root render surface because other surfaces may contain
+    // FIXME: We only allow background filters on an opaque render surface because other surfaces may contain
     // translucent pixels, and the contents behind those translucent pixels wouldn't have the filter applied.
-    if (!isCurrentRenderPass(m_defaultRenderPass))
+    if (m_currentRenderPass->hasTransparentBackground())
         return;
+    ASSERT(!m_currentManagedTexture);
 
     // FIXME: Do a single readback for both the surface and replica and cache the filtered results (once filter textures are not reused).
     IntRect deviceRect = enclosingIntRect(CCMathUtil::mapClippedRect(contentsDeviceTransform, sharedGeometryQuad().boundingBox()));
index fa52b73..82bd691 100644 (file)
@@ -152,7 +152,7 @@ private:
 
     bool bindFramebufferToTexture(ManagedTexture*, const IntRect& viewportRect);
 
-    void clearRenderPass(const CCRenderPass*, const CCRenderPass* rootRenderPass, const FloatRect& framebufferDamageRect);
+    void clearRenderPass(const CCRenderPass*, const FloatRect& framebufferDamageRect);
 
     void releaseRenderPassTextures();
 
index 39327d0..b499012 100644 (file)
@@ -58,7 +58,8 @@ void SkPictureCanvasLayerTextureUpdater::prepareToUpdate(const IntRect& contentR
     // layer is likely to be filtered or transformed. Because it might be
     // transformed, set image buffer flag to draw the text in grayscale
     // instead of using subpixel antialiasing.
-    platformContext.setDrawingToImageBuffer(borderTexels ? true : false);
+    bool useGrayscaleText = borderTexels || !m_layerIsOpaque;
+    platformContext.setDrawingToImageBuffer(useGrayscaleText);
     GraphicsContext graphicsContext(&platformContext);
     paintContents(graphicsContext, platformContext, contentRect, contentsScale, resultingOpaqueRect);
     m_picture.endRecording();
index fa0eb64..0a0154c 100644 (file)
@@ -86,6 +86,7 @@ CCLayerTreeHost::CCLayerTreeHost(CCLayerTreeHostClient* client, const CCSettings
     , m_maxPageScaleFactor(1)
     , m_triggerIdlePaints(true)
     , m_backgroundColor(Color::white)
+    , m_hasTransparentBackground(false)
     , m_partialTextureUpdateRequests(0)
 {
     ASSERT(CCProxy::isMainThread());
@@ -252,6 +253,7 @@ void CCLayerTreeHost::finishCommitOnImplThread(CCLayerTreeHostImpl* hostImpl)
     hostImpl->setViewportSize(viewportSize());
     hostImpl->setPageScaleFactorAndLimits(m_pageScaleFactor, m_minPageScaleFactor, m_maxPageScaleFactor);
     hostImpl->setBackgroundColor(m_backgroundColor);
+    hostImpl->setHasTransparentBackground(m_hasTransparentBackground);
     hostImpl->setVisible(m_visible);
     hostImpl->setSourceFrameCanBeDrawn(m_frameIsForDisplay);
 
index 434aec2..481d3ce 100644 (file)
@@ -231,6 +231,8 @@ public:
 
     void setBackgroundColor(const Color& color) { m_backgroundColor = color; }
 
+    void setHasTransparentBackground(bool transparent) { m_hasTransparentBackground = transparent; }
+
     TextureManager* contentsTextureManager() const;
     void setContentsMemoryAllocationLimitBytes(size_t);
 
@@ -309,6 +311,7 @@ private:
     float m_minPageScaleFactor, m_maxPageScaleFactor;
     bool m_triggerIdlePaints;
     Color m_backgroundColor;
+    bool m_hasTransparentBackground;
 
     TextureList m_deleteTextureAfterCommitList;
     size_t m_partialTextureUpdateRequests;
index a416301..441fa0a 100644 (file)
@@ -124,6 +124,7 @@ CCLayerTreeHostImpl::CCLayerTreeHostImpl(const CCSettings& settings, CCLayerTree
     , m_sentPageScaleDelta(1)
     , m_minPageScale(0)
     , m_maxPageScale(0)
+    , m_hasTransparentBackground(false)
     , m_needsAnimateLayers(false)
     , m_pinchGestureActive(false)
     , m_fpsCounter(CCFrameRateCounter::create())
@@ -321,7 +322,10 @@ bool CCLayerTreeHostImpl::calculateRenderPasses(CCRenderPassList& passes, CCLaye
         occlusionTracker.leaveLayer(it);
     }
 
-    passes.last()->appendQuadsToFillScreen(m_rootLayerImpl.get(), m_backgroundColor, occlusionTracker);
+    if (!m_hasTransparentBackground) {
+        passes.last()->setHasTransparentBackground(false);
+        passes.last()->appendQuadsToFillScreen(m_rootLayerImpl.get(), m_backgroundColor, occlusionTracker);
+    }
 
     if (drawFrame)
         occlusionTracker.overdrawMetrics().recordMetrics(this);
index 46191f1..095c0e5 100644 (file)
@@ -160,6 +160,9 @@ public:
     const Color& backgroundColor() const { return m_backgroundColor; }
     void setBackgroundColor(const Color& color) { m_backgroundColor = color; }
 
+    bool hasTransparentBackground() const { return m_hasTransparentBackground; }
+    void setHasTransparentBackground(bool transparent) { m_hasTransparentBackground = transparent; }
+
     bool needsAnimateLayers() const { return m_needsAnimateLayers; }
     void setNeedsAnimateLayers() { m_needsAnimateLayers = true; }
 
@@ -228,6 +231,7 @@ private:
     float m_minPageScale, m_maxPageScale;
 
     Color m_backgroundColor;
+    bool m_hasTransparentBackground;
 
     // If this is true, it is necessary to traverse the layer tree ticking the animators.
     bool m_needsAnimateLayers;
index 0e3afc0..a55feb8 100644 (file)
@@ -45,6 +45,7 @@ PassOwnPtr<CCRenderPass> CCRenderPass::create(CCRenderSurface* targetSurface)
 CCRenderPass::CCRenderPass(CCRenderSurface* targetSurface)
     : m_targetSurface(targetSurface)
     , m_framebufferOutputRect(targetSurface->contentRect())
+    , m_hasTransparentBackground(true)
 {
     ASSERT(m_targetSurface);
 }
index 649dbac..a451006 100644 (file)
@@ -64,6 +64,9 @@ public:
     // This denotes the bounds in physical pixels of the output generated by this RenderPass.
     const IntRect& framebufferOutputRect() const { return m_framebufferOutputRect; }
 
+    bool hasTransparentBackground() const { return m_hasTransparentBackground; }
+    void setHasTransparentBackground(bool transparent) { m_hasTransparentBackground = transparent; }
+
 private:
     explicit CCRenderPass(CCRenderSurface*);
 
@@ -71,6 +74,7 @@ private:
     CCQuadList m_quadList;
     IntRect m_framebufferOutputRect;
     Vector<OwnPtr<CCSharedQuadState> > m_sharedQuadStateList;
+    bool m_hasTransparentBackground;
 };
 
 typedef Vector<OwnPtr<CCRenderPass> > CCRenderPassList;
index 2d0bd94..3a6ea38 100644 (file)
@@ -1,3 +1,29 @@
+2012-06-08  David Reveman  <reveman@chromium.org>
+
+        [Chromium] Compositor doesn't support translucent root layers.
+        https://bugs.webkit.org/show_bug.cgi?id=87821
+
+        Reviewed by James Robinson.
+
+        * src/NonCompositedContentHost.cpp:
+        (WebKit::NonCompositedContentHost::setOpaque):
+        (WebKit):
+        * src/NonCompositedContentHost.h:
+        (NonCompositedContentHost):
+        * src/WebLayerTreeView.cpp:
+        (WebKit::WebLayerTreeView::setHasTransparentBackground):
+        (WebKit):
+        * src/WebViewImpl.cpp:
+        (WebKit::WebViewImpl::setIsTransparent):
+        (WebKit::WebViewImpl::setIsAcceleratedCompositingActive):
+        * tests/CCLayerTreeHostImplTest.cpp:
+        * tests/LayerRendererChromiumTest.cpp:
+        (ClearCountingContext):
+        (ClearCountingContext::ClearCountingContext):
+        (ClearCountingContext::clear):
+        (ClearCountingContext::clearCount):
+        (TEST):
+
 2012-06-08  Ian Vollick  <vollick@chromium.org>
 
         [chromium] Single thread proxy's animation timer should short circuit if the layer renderer has not been initialized
index 4cc1c11..9aa6f16 100644 (file)
@@ -62,6 +62,11 @@ void NonCompositedContentHost::setBackgroundColor(const WebCore::Color& color)
     m_graphicsLayer->platformLayer()->setBackgroundColor(color);
 }
 
+void NonCompositedContentHost::setOpaque(bool opaque)
+{
+    m_graphicsLayer->platformLayer()->setOpaque(opaque);
+}
+
 void NonCompositedContentHost::setScrollLayer(WebCore::GraphicsLayer* layer)
 {
     m_graphicsLayer->setNeedsDisplay();
index 320e7c1..c87bd8c 100644 (file)
@@ -56,6 +56,7 @@ public:
 
     void invalidateRect(const WebCore::IntRect&);
     void setBackgroundColor(const WebCore::Color&);
+    void setOpaque(bool);
     void setScrollLayer(WebCore::GraphicsLayer*);
     void setViewport(const WebCore::IntSize& viewportSize, const WebCore::IntSize& contentsSize, const WebCore::IntPoint& scrollPosition, float deviceScale, int layerAdjustX);
     WebCore::GraphicsLayer* topLevelRootLayer() const { return m_graphicsLayer.get(); }
index ae20aea..fed3db9 100644 (file)
@@ -107,6 +107,11 @@ void WebLayerTreeView::setBackgroundColor(WebColor color)
     m_private->layerTreeHost()->setBackgroundColor(color);
 }
 
+void WebLayerTreeView::setHasTransparentBackground(bool transparent)
+{
+    m_private->layerTreeHost()->setHasTransparentBackground(transparent);
+}
+
 void WebLayerTreeView::setVisible(bool visible)
 {
     m_private->layerTreeHost()->setVisible(visible);
index f90b1f8..a44097b 100644 (file)
@@ -3026,6 +3026,11 @@ void WebViewImpl::setIsTransparent(bool isTransparent)
 
     // Future frames check this to know whether to be transparent.
     m_isTransparent = isTransparent;
+
+    if (m_nonCompositedContentHost)
+        m_nonCompositedContentHost->setOpaque(!isTransparent);
+
+    m_layerTreeView.setHasTransparentBackground(isTransparent);
 }
 
 bool WebViewImpl::isTransparent() const
@@ -3475,6 +3480,7 @@ void WebViewImpl::setIsAcceleratedCompositingActive(bool active)
 
         m_nonCompositedContentHost = NonCompositedContentHost::create(WebViewImplContentPainter::create(this));
         m_nonCompositedContentHost->setShowDebugBorders(page()->settings()->showDebugBorders());
+        m_nonCompositedContentHost->setOpaque(!isTransparent());
 
         if (m_webSettings->applyDefaultDeviceScaleFactorInCompositor() && page()->deviceScaleFactor() != 1) {
             ASSERT(page()->deviceScaleFactor());
@@ -3489,6 +3495,7 @@ void WebViewImpl::setIsAcceleratedCompositingActive(bool active)
             m_layerTreeView.setPageScaleFactorAndLimits(pageScaleFactor(), m_minimumPageScaleFactor, m_maximumPageScaleFactor);
             if (m_compositorSurfaceReady)
                 m_layerTreeView.setSurfaceReady();
+            m_layerTreeView.setHasTransparentBackground(isTransparent());
             updateLayerTreeViewport();
             m_client->didActivateCompositor(m_layerTreeView.compositorIdentifier());
             m_isAcceleratedCompositingActive = true;
index 039e0cd..f26fdf8 100644 (file)
@@ -1775,4 +1775,39 @@ TEST_F(CCLayerTreeHostImplTest, dontUseOldResourcesAfterLostContext)
     m_hostImpl->swapBuffers();
 }
 
+class MockDrawQuadsToFillScreenContext : public FakeWebGraphicsContext3D {
+public:
+    MOCK_METHOD1(useProgram, void(WebGLId program));
+    MOCK_METHOD4(drawElements, void(WGC3Denum mode, WGC3Dsizei count, WGC3Denum type, WGC3Dintptr offset));
+};
+
+TEST_F(CCLayerTreeHostImplTest, hasTransparentBackground)
+{
+    MockDrawQuadsToFillScreenContext* mockContext = new MockDrawQuadsToFillScreenContext();
+    RefPtr<CCGraphicsContext> context = CCGraphicsContext::create3D(GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(mockContext), GraphicsContext3D::RenderDirectlyToHostWindow));
+
+    // Run test case
+    OwnPtr<CCLayerTreeHostImpl> myHostImpl = createLayerTreeHost(false, context, CCLayerImpl::create(1));
+    myHostImpl->setBackgroundColor(Color::white);
+
+    // Verify one quad is drawn when transparent background set is not set.
+    myHostImpl->setHasTransparentBackground(false);
+    EXPECT_CALL(*mockContext, useProgram(_))
+        .Times(1);
+    EXPECT_CALL(*mockContext, drawElements(_, _, _, _))
+        .Times(1);
+    CCLayerTreeHostImpl::FrameData frame;
+    EXPECT_TRUE(myHostImpl->prepareToDraw(frame));
+    myHostImpl->drawLayers(frame);
+    myHostImpl->didDrawAllLayers(frame);
+    Mock::VerifyAndClearExpectations(&mockContext);
+
+    // Verify no quads are drawn when transparent background is set.
+    myHostImpl->setHasTransparentBackground(true);
+    EXPECT_TRUE(myHostImpl->prepareToDraw(frame));
+    myHostImpl->drawLayers(frame);
+    myHostImpl->didDrawAllLayers(frame);
+    Mock::VerifyAndClearExpectations(&mockContext);
+}
+
 } // namespace
index 4017d38..76d5968 100644 (file)
@@ -357,3 +357,58 @@ TEST(LayerRendererChromiumTest2, initializationWithoutGpuMemoryManagerExtensionS
 
     EXPECT_GT(mockClient.memoryAllocationLimitBytes(), 0ul);
 }
+
+class ClearCountingContext : public FakeWebGraphicsContext3D {
+public:
+    ClearCountingContext() : m_clear(0) { }
+
+    virtual void clear(WGC3Dbitfield)
+    {
+        m_clear++;
+    }
+
+    int clearCount() const { return m_clear; }
+
+private:
+    int m_clear;
+};
+
+TEST(LayerRendererChromiumTest2, opaqueBackground)
+{
+    FakeCCRendererClient mockClient;
+    RefPtr<GraphicsContext3D> context = GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new ClearCountingContext), GraphicsContext3D::RenderDirectlyToHostWindow);
+    FakeLayerRendererChromium layerRendererChromium(&mockClient, context);
+
+    mockClient.rootRenderPass()->setHasTransparentBackground(false);
+
+    EXPECT_TRUE(layerRendererChromium.initialize());
+
+    layerRendererChromium.beginDrawingFrame(mockClient.rootRenderPass());
+    layerRendererChromium.drawRenderPass(mockClient.rootRenderPass(), FloatRect());
+    layerRendererChromium.finishDrawingFrame();
+
+    // On DEBUG builds, render passes with opaque background clear to blue to
+    // easily see regions that were not drawn on the screen.
+#if defined(NDEBUG)
+    EXPECT_EQ(0, static_cast<ClearCountingContext*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(context.get()))->clearCount());
+#else
+    EXPECT_EQ(1, static_cast<ClearCountingContext*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(context.get()))->clearCount());
+#endif
+}
+
+TEST(LayerRendererChromiumTest2, transparentBackground)
+{
+    FakeCCRendererClient mockClient;
+    RefPtr<GraphicsContext3D> context = GraphicsContext3DPrivate::createGraphicsContextFromWebContext(adoptPtr(new ClearCountingContext), GraphicsContext3D::RenderDirectlyToHostWindow);
+    FakeLayerRendererChromium layerRendererChromium(&mockClient, context);
+
+    mockClient.rootRenderPass()->setHasTransparentBackground(true);
+
+    EXPECT_TRUE(layerRendererChromium.initialize());
+
+    layerRendererChromium.beginDrawingFrame(mockClient.rootRenderPass());
+    layerRendererChromium.drawRenderPass(mockClient.rootRenderPass(), FloatRect());
+    layerRendererChromium.finishDrawingFrame();
+
+    EXPECT_EQ(1, static_cast<ClearCountingContext*>(GraphicsContext3DPrivate::extractWebGraphicsContext3D(context.get()))->clearCount());
+}