Changeset 117645 in webkit


Ignore:
Timestamp:
May 18, 2012 3:27:18 PM (12 years ago)
Author:
shawnsingh@chromium.org
Message:

[chromium] add back-face visibility check for renderSurfaces
https://bugs.webkit.org/show_bug.cgi?id=86870

Reviewed by Adrienne Walker.

Source/WebCore:

Test added CCLayerTreeHostCommonTest::verifyBackFaceCullingWithPreserves3dForFlatteningSurface

Chromium was not checking back-face visibility for renderSurfaces
that needed it. This patch adds that check and the appropriate
unit test.

  • platform/graphics/chromium/cc/CCLayerTreeHostCommon.cpp:

(WebCore::layerIsInExisting3DRenderingContext):
(WebCore):
(WebCore::subtreeShouldRenderToSeparateSurface):
(WebCore::calculateDrawTransformsAndVisibilityInternal):

Source/WebKit/chromium:

  • tests/CCLayerTreeHostCommonTest.cpp:

(WebKitTests::TEST):
(WebKitTests):

Location:
trunk/Source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r117640 r117645  
     12012-05-18  Shawn Singh  <shawnsingh@chromium.org>
     2
     3        [chromium] add back-face visibility check for renderSurfaces
     4        https://bugs.webkit.org/show_bug.cgi?id=86870
     5
     6        Reviewed by Adrienne Walker.
     7
     8        Test added CCLayerTreeHostCommonTest::verifyBackFaceCullingWithPreserves3dForFlatteningSurface
     9
     10        Chromium was not checking back-face visibility for renderSurfaces
     11        that needed it. This patch adds that check and the appropriate
     12        unit test.
     13
     14        * platform/graphics/chromium/cc/CCLayerTreeHostCommon.cpp:
     15        (WebCore::layerIsInExisting3DRenderingContext):
     16        (WebCore):
     17        (WebCore::subtreeShouldRenderToSeparateSurface):
     18        (WebCore::calculateDrawTransformsAndVisibilityInternal):
     19
    1202012-05-18  Levi Weintraub  <leviw@chromium.org>
    221
  • trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHostCommon.cpp

    r115386 r117645  
    6767
    6868template<typename LayerType>
     69static inline bool layerIsInExisting3DRenderingContext(LayerType* layer)
     70{
     71    // According to current W3C spec on CSS transforms, a layer is part of an established
     72    // 3d rendering context if its parent has transform-style of preserves-3d.
     73    return layer->parent() && layer->parent()->preserves3D();
     74}
     75
     76template<typename LayerType>
    6977static IntRect calculateVisibleLayerRect(LayerType* layer)
    7078{
     
    212220    // If the layer flattens its subtree (i.e. the layer doesn't preserve-3d), but it is
    213221    // treated as a 3D object by its parent (i.e. parent does preserve-3d).
    214     if (layer->parent() && layer->parent()->preserves3D() && !layer->preserves3D() && descendantDrawsContent)
     222    if (layerIsInExisting3DRenderingContext(layer) && !layer->preserves3D() && descendantDrawsContent)
    215223        return true;
    216224
     
    383391
    384392    if (subtreeShouldRenderToSeparateSurface(layer, isScaleOrTranslation(combinedTransform))) {
     393
     394        // We need to check back-face visibility before continuing with this surface.
     395        // We cannot early exit here, however, if the transform is animating and not known on the main thread.
     396        // FIXME: Also compute back-face visibility for surfaces that are not in existing 3D rendering context, using
     397        //        the layer's local transform. https://bugs.webkit.org/show_bug.cgi?id=84195
     398        if (layerIsInExisting3DRenderingContext(layer) && transformToParentIsKnown(layer) && !layer->doubleSided() && combinedTransform.isBackFaceVisible())
     399            return false;
     400
    385401        if (!layer->renderSurface())
    386402            layer->createRenderSurface();
  • trunk/Source/WebKit/chromium/ChangeLog

    r117615 r117645  
     12012-05-18  Shawn Singh  <shawnsingh@chromium.org>
     2
     3        [chromium] add back-face visibility check for renderSurfaces
     4        https://bugs.webkit.org/show_bug.cgi?id=86870
     5
     6        Reviewed by Adrienne Walker.
     7
     8        * tests/CCLayerTreeHostCommonTest.cpp:
     9        (WebKitTests::TEST):
     10        (WebKitTests):
     11
    1122012-05-18  Greg Billock  <gbillock@google.com>
    213
  • trunk/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp

    r116332 r117645  
    13261326}
    13271327
     1328TEST(CCLayerTreeHostCommonTest, verifyBackFaceCullingWithPreserves3dForFlatteningSurface)
     1329{
     1330    // Verify the behavior of back-face culling for a renderSurface that is created
     1331    // when it flattens its subtree, and its parent has preserves-3d.
     1332
     1333    const TransformationMatrix identityMatrix;
     1334    RefPtr<LayerChromium> parent = LayerChromium::create();
     1335    RefPtr<LayerChromiumWithForcedDrawsContent> frontFacingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1336    RefPtr<LayerChromiumWithForcedDrawsContent> backFacingSurface = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1337    RefPtr<LayerChromiumWithForcedDrawsContent> child1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1338    RefPtr<LayerChromiumWithForcedDrawsContent> child2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1339
     1340    parent->createRenderSurface();
     1341    parent->addChild(frontFacingSurface);
     1342    parent->addChild(backFacingSurface);
     1343    frontFacingSurface->addChild(child1);
     1344    backFacingSurface->addChild(child2);
     1345
     1346    // RenderSurfaces are not double-sided
     1347    frontFacingSurface->setDoubleSided(false);
     1348    backFacingSurface->setDoubleSided(false);
     1349
     1350    TransformationMatrix backfaceMatrix;
     1351    backfaceMatrix.translate(50, 50);
     1352    backfaceMatrix.rotate3d(0, 1, 0, 180);
     1353    backfaceMatrix.translate(-50, -50);
     1354
     1355    setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); // parent transform style is preserve3d.
     1356    setLayerPropertiesForTesting(frontFacingSurface.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); // surface transform style is flat.
     1357    setLayerPropertiesForTesting(backFacingSurface.get(),  backfaceMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); // surface transform style is flat.
     1358    setLayerPropertiesForTesting(child1.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
     1359    setLayerPropertiesForTesting(child2.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false);
     1360
     1361    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     1362    Vector<RefPtr<LayerChromium> > dummyLayerList;
     1363    int dummyMaxTextureSize = 512;
     1364    parent->renderSurface()->setContentRect(IntRect(IntPoint(), parent->bounds()));
     1365    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     1366    renderSurfaceLayerList.append(parent.get());
     1367
     1368    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     1369
     1370    // Verify which renderSurfaces were created.
     1371    EXPECT_TRUE(frontFacingSurface->renderSurface());
     1372    EXPECT_FALSE(backFacingSurface->renderSurface()); // because it should be culled
     1373    EXPECT_FALSE(child1->renderSurface());
     1374    EXPECT_FALSE(child2->renderSurface());
     1375
     1376    // Verify the renderSurfaceLayerList. The back-facing surface should be culled.
     1377    ASSERT_EQ(2u, renderSurfaceLayerList.size());
     1378    EXPECT_EQ(parent->id(), renderSurfaceLayerList[0]->id());
     1379    EXPECT_EQ(frontFacingSurface->id(), renderSurfaceLayerList[1]->id());
     1380
     1381    // Verify root surface's layerList.
     1382    ASSERT_EQ(1u, renderSurfaceLayerList[0]->renderSurface()->layerList().size());
     1383    EXPECT_EQ(frontFacingSurface->id(), renderSurfaceLayerList[0]->renderSurface()->layerList()[0]->id());
     1384
     1385    // Verify frontFacingSurface's layerList.
     1386    ASSERT_EQ(2u, renderSurfaceLayerList[1]->renderSurface()->layerList().size());
     1387    EXPECT_EQ(frontFacingSurface->id(), renderSurfaceLayerList[1]->renderSurface()->layerList()[0]->id());
     1388    EXPECT_EQ(child1->id(), renderSurfaceLayerList[1]->renderSurface()->layerList()[1]->id());
     1389}
     1390
    13281391// FIXME:
    13291392// continue working on https://bugs.webkit.org/show_bug.cgi?id=68942
Note: See TracChangeset for help on using the changeset viewer.