Changeset 106324 in webkit
- Timestamp:
- Jan 30, 2012 8:03:00 PM (12 years ago)
- Location:
- trunk/Source
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r106323 r106324 1 2012-01-30 Dana Jansens <danakj@chromium.org> 2 3 [chromium] Compute occlusion during paint loop 4 https://bugs.webkit.org/show_bug.cgi?id=76858 5 6 Reviewed by James Robinson. 7 8 New unit tests in TiledLayerChromiumTest.cpp, CCLayerTreeHostCommonTest.cpp, CCLayerTreeHostTest.cpp 9 10 * platform/graphics/FloatRect.cpp: 11 (WebCore::enclosedIntRect): 12 (WebCore): 13 * platform/graphics/FloatRect.h: 14 (WebCore): 15 * platform/graphics/chromium/Canvas2DLayerChromium.cpp: 16 (WebCore::Canvas2DLayerChromium::paintContentsIfDirty): 17 * platform/graphics/chromium/Canvas2DLayerChromium.h: 18 (Canvas2DLayerChromium): 19 * platform/graphics/chromium/ContentLayerChromium.cpp: 20 (WebCore::ContentLayerChromium::paintContentsIfDirty): 21 * platform/graphics/chromium/ContentLayerChromium.h: 22 (ContentLayerChromium): 23 * platform/graphics/chromium/ImageLayerChromium.cpp: 24 (WebCore::ImageLayerChromium::paintContentsIfDirty): 25 * platform/graphics/chromium/ImageLayerChromium.h: 26 (ImageLayerChromium): 27 * platform/graphics/chromium/LayerChromium.cpp: 28 (WebCore::LayerChromium::contentToScreenSpaceTransform): 29 (WebCore): 30 (WebCore::LayerChromium::addSelfToOccludedScreenSpace): 31 (WebCore::LayerChromium::isPaintedAxisAlignedInScreen): 32 * platform/graphics/chromium/LayerChromium.h: 33 (WebCore): 34 (WebCore::LayerChromium::paintContentsIfDirty): 35 (LayerChromium): 36 * platform/graphics/chromium/RenderSurfaceChromium.h: 37 (RenderSurfaceChromium): 38 * platform/graphics/chromium/TiledLayerChromium.cpp: 39 (WebCore::TiledLayerChromium::addSelfToOccludedScreenSpace): 40 * platform/graphics/chromium/TiledLayerChromium.h: 41 (WebCore): 42 (): 43 * platform/graphics/chromium/cc/CCLayerTreeHost.cpp: 44 (WebCore::CCLayerTreeHost::paintContentsIfDirty): 45 (WebCore::CCLayerTreeHost::paintMaskAndReplicaForRenderSurface): 46 (RenderSurfaceRegion): 47 (WebCore): 48 (WebCore::pushTargetRenderSurfaceRegion): 49 (WebCore::popAndPushTargetRenderSurfaceRegion): 50 (WebCore::CCLayerTreeHost::paintLayerContents): 51 * platform/graphics/chromium/cc/CCLayerTreeHost.h: 52 (WebCore): 53 (): 54 * platform/graphics/chromium/cc/CCQuadCuller.cpp: 55 1 56 2012-01-30 Caio Marcelo de Oliveira Filho <caio.oliveira@openbossa.org> 2 57 -
trunk/Source/WebCore/platform/graphics/FloatRect.cpp
r105643 r106324 219 219 } 220 220 221 IntRect enclosedIntRect(const FloatRect& rect) 222 { 223 int x = clampToInteger(ceilf(rect.x())); 224 int y = clampToInteger(ceilf(rect.y())); 225 float maxX = clampToInteger(floorf(rect.maxX())); 226 float maxY = clampToInteger(floorf(rect.maxY())); 227 // A rect of width 0 should not become a rect of width -1 due to ceil/floor. 228 int width = max(clampToInteger(maxX - x), 0); 229 int height = max(clampToInteger(maxY - y), 0); 230 231 return IntRect(x, y, width, height); 232 } 233 221 234 FloatRect mapRect(const FloatRect& r, const FloatRect& srcRect, const FloatRect& destRect) 222 235 { -
trunk/Source/WebCore/platform/graphics/FloatRect.h
r105231 r106324 271 271 IntRect enclosingIntRect(const FloatRect&); 272 272 273 // Returns a valid IntRect contained within the given FloatRect. 274 IntRect enclosedIntRect(const FloatRect&); 275 273 276 // Map rect r from srcRect to an equivalent rect in destRect. 274 277 FloatRect mapRect(const FloatRect& r, const FloatRect& srcRect, const FloatRect& destRect); -
trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.cpp
r105544 r106324 92 92 } 93 93 94 void Canvas2DLayerChromium::paintContentsIfDirty( )94 void Canvas2DLayerChromium::paintContentsIfDirty(const Region& /* occludedScreenSpace */) 95 95 { 96 96 if (!drawsContent()) -
trunk/Source/WebCore/platform/graphics/chromium/Canvas2DLayerChromium.h
r104044 r106324 41 41 42 42 class GraphicsContext3D; 43 class Region; 43 44 44 45 // A layer containing an accelerated 2d canvas … … 53 54 54 55 virtual bool drawsContent() const; 55 virtual void paintContentsIfDirty( );56 virtual void paintContentsIfDirty(const Region& occludedScreenSpace); 56 57 57 58 virtual void setLayerTreeHost(CCLayerTreeHost*); -
trunk/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.cpp
r105783 r106324 94 94 } 95 95 96 void ContentLayerChromium::paintContentsIfDirty( )96 void ContentLayerChromium::paintContentsIfDirty(const Region& /* occludedScreenSpace */) 97 97 { 98 98 updateTileSizeAndTilingOption(); -
trunk/Source/WebCore/platform/graphics/chromium/ContentLayerChromium.h
r105783 r106324 42 42 class LayerTilerChromium; 43 43 class LayerTextureUpdater; 44 class Region; 44 45 45 46 class ContentLayerDelegate { … … 59 60 60 61 virtual bool drawsContent() const; 61 virtual void paintContentsIfDirty( );62 virtual void paintContentsIfDirty(const Region& occludedScreenSpace); 62 63 virtual void idlePaintContentsIfDirty(); 63 64 -
trunk/Source/WebCore/platform/graphics/chromium/ImageLayerChromium.cpp
r105460 r106324 159 159 } 160 160 161 void ImageLayerChromium::paintContentsIfDirty( )161 void ImageLayerChromium::paintContentsIfDirty(const Region& /* occludedScreenSpace */) 162 162 { 163 163 if (m_needsDisplay) { -
trunk/Source/WebCore/platform/graphics/chromium/ImageLayerChromium.h
r105460 r106324 46 46 class Image; 47 47 class ImageLayerTextureUpdater; 48 class Region; 48 49 49 50 // A Layer that contains only an Image element. … … 54 55 55 56 virtual bool drawsContent() const; 56 virtual void paintContentsIfDirty( );57 virtual void paintContentsIfDirty(const Region& occludedScreenSpace); 57 58 virtual bool needsContentsScale() const; 58 59 -
trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.cpp
r106300 r106324 40 40 #include "PlatformContextSkia.h" 41 41 #endif 42 #include "Region.h" 42 43 #include "RenderLayerBacking.h" 43 44 #include "TextStream.h" … … 470 471 } 471 472 473 TransformationMatrix LayerChromium::contentToScreenSpaceTransform() const 474 { 475 IntSize boundsInLayerSpace = bounds(); 476 IntSize boundsInContentSpace = contentBounds(); 477 478 TransformationMatrix transform = screenSpaceTransform(); 479 480 // Scale from content space to layer space 481 transform.scaleNonUniform(boundsInLayerSpace.width() / static_cast<double>(boundsInContentSpace.width()), 482 boundsInLayerSpace.height() / static_cast<double>(boundsInContentSpace.height())); 483 484 return transform; 485 } 486 487 void LayerChromium::addSelfToOccludedScreenSpace(Region& occludedScreenSpace) 488 { 489 if (!opaque() || drawOpacity() != 1 || !isPaintedAxisAlignedInScreen()) 490 return; 491 492 FloatRect targetRect = contentToScreenSpaceTransform().mapRect(FloatRect(visibleLayerRect())); 493 occludedScreenSpace.unite(enclosedIntRect(targetRect)); 494 } 495 496 bool LayerChromium::isPaintedAxisAlignedInScreen() const 497 { 498 FloatQuad quad = contentToScreenSpaceTransform().mapQuad(FloatQuad(visibleLayerRect())); 499 return quad.isRectilinear(); 500 } 501 472 502 void LayerChromium::createRenderSurface() 473 503 { -
trunk/Source/WebCore/platform/graphics/chromium/LayerChromium.h
r106289 r106324 56 56 class CCTextureUpdater; 57 57 class GraphicsContext3D; 58 class Region; 58 59 59 60 // Base class for composited layers. Special layer types are derived from … … 154 155 // These methods typically need to be overwritten by derived classes. 155 156 virtual bool drawsContent() const { return m_isDrawable; } 156 virtual void paintContentsIfDirty( ) { }157 virtual void paintContentsIfDirty(const Region& /* occludedScreenSpace */) { } 157 158 virtual void idlePaintContentsIfDirty() { } 158 159 virtual void updateCompositorResources(GraphicsContext3D*, CCTextureUpdater&) { } … … 183 184 RenderSurfaceChromium* targetRenderSurface() const { return m_targetRenderSurface; } 184 185 void setTargetRenderSurface(RenderSurfaceChromium* surface) { m_targetRenderSurface = surface; } 186 // This moves from layer space, with origin in the center to target space with origin in the top left 185 187 const TransformationMatrix& drawTransform() const { return m_drawTransform; } 186 188 void setDrawTransform(const TransformationMatrix& matrix) { m_drawTransform = matrix; } 189 // This moves from layer space, with origin the top left to screen space with origin in the top left 187 190 const TransformationMatrix& screenSpaceTransform() const { return m_screenSpaceTransform; } 188 191 void setScreenSpaceTransform(const TransformationMatrix& matrix) { m_screenSpaceTransform = matrix; } … … 192 195 void setContentsScale(float); 193 196 197 TransformationMatrix contentToScreenSpaceTransform() const; 198 199 // Adds any opaque visible pixels to the occluded region. 200 virtual void addSelfToOccludedScreenSpace(Region& occludedScreenSpace); 201 194 202 // Returns true if any of the layer's descendants has content to draw. 195 203 bool descendantDrawsContent(); … … 211 219 // hold context-dependent resources such as textures. 212 220 virtual void cleanupResources(); 221 222 bool isPaintedAxisAlignedInScreen() const; 213 223 214 224 void setNeedsCommit(); -
trunk/Source/WebCore/platform/graphics/chromium/RenderSurfaceChromium.h
r104626 r106324 64 64 void setDrawOpacity(float drawOpacity) { m_drawOpacity = drawOpacity; } 65 65 66 // This goes from content space with the origin in the center of the rect being transformed to the target space with the origin in the top left of the 67 // rect being transformed. Position the rect so that the origin is in the center of it before applying this transform. 66 68 const TransformationMatrix& drawTransform() const { return m_drawTransform; } 67 69 void setDrawTransform(const TransformationMatrix& drawTransform) { m_drawTransform = drawTransform; } -
trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.cpp
r106300 r106324 489 489 } 490 490 491 void TiledLayerChromium::addSelfToOccludedScreenSpace(Region& occludedScreenSpace) 492 { 493 if (m_skipsDraw || drawOpacity() != 1 || !isPaintedAxisAlignedInScreen()) 494 return; 495 496 if (opaque()) { 497 LayerChromium::addSelfToOccludedScreenSpace(occludedScreenSpace); 498 return; 499 } 500 501 IntRect visibleRect = visibleLayerRect(); 502 TransformationMatrix contentTransform = contentToScreenSpaceTransform(); 503 504 // FIXME: Create/Use a FloatRegion for the occludedScreenSpace, instead of a Region based on ints, to avoid this step and get better accuracy between layers in target space. 505 Region tileRegion; 506 int left, top, right, bottom; 507 m_tiler->layerRectToTileIndices(visibleLayerRect(), left, top, right, bottom); 508 for (int j = top; j <= bottom; ++j) { 509 for (int i = left; i <= right; ++i) { 510 UpdatableTile* tile = tileAt(i, j); 511 if (tile) { 512 IntRect visibleTileOpaqueRect = intersection(visibleRect, tile->m_opaqueRect); 513 FloatRect screenRect = contentTransform.mapRect(FloatRect(visibleTileOpaqueRect)); 514 occludedScreenSpace.unite(enclosedIntRect(screenRect)); 515 } 516 } 517 } 518 } 519 491 520 void TiledLayerChromium::prepareToUpdate(const IntRect& layerRect) 492 521 { -
trunk/Source/WebCore/platform/graphics/chromium/TiledLayerChromium.h
r106289 r106324 36 36 37 37 class LayerTextureUpdater; 38 class Region; 38 39 class UpdatableTile; 39 40 … … 63 64 64 65 virtual void reserveTextures(); 66 67 virtual void addSelfToOccludedScreenSpace(Region& occludedScreenSpace); 65 68 66 69 protected: -
trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.cpp
r106289 r106324 30 30 #include "LayerPainterChromium.h" 31 31 #include "LayerRendererChromium.h" 32 #include "Region.h" 32 33 #include "TraceEvent.h" 33 34 #include "TreeSynchronizer.h" … … 414 415 415 416 // static 416 void CCLayerTreeHost::paintContentsIfDirty(LayerChromium* layer, PaintType paintType )417 void CCLayerTreeHost::paintContentsIfDirty(LayerChromium* layer, PaintType paintType, const Region& occludedScreenSpace) 417 418 { 418 419 ASSERT(layer); 419 420 ASSERT(PaintVisible == paintType || PaintIdle == paintType); 420 421 if (PaintVisible == paintType) 421 layer->paintContentsIfDirty( );422 layer->paintContentsIfDirty(occludedScreenSpace); 422 423 else 423 424 layer->idlePaintContentsIfDirty(); … … 430 431 // mask and replica should be painted. 431 432 433 // FIXME: If the surface has a replica, it should be painted with occlusion that excludes the current target surface subtree. 434 Region noOcclusion; 435 432 436 if (renderSurfaceLayer->maskLayer()) { 433 437 renderSurfaceLayer->maskLayer()->setVisibleLayerRect(IntRect(IntPoint(), renderSurfaceLayer->contentBounds())); 434 paintContentsIfDirty(renderSurfaceLayer->maskLayer(), paintType );438 paintContentsIfDirty(renderSurfaceLayer->maskLayer(), paintType, noOcclusion); 435 439 } 436 440 437 441 LayerChromium* replicaLayer = renderSurfaceLayer->replicaLayer(); 438 442 if (replicaLayer) { 439 paintContentsIfDirty(replicaLayer, paintType );443 paintContentsIfDirty(replicaLayer, paintType, noOcclusion); 440 444 441 445 if (replicaLayer->maskLayer()) { 442 446 replicaLayer->maskLayer()->setVisibleLayerRect(IntRect(IntPoint(), replicaLayer->maskLayer()->contentBounds())); 443 paintContentsIfDirty(replicaLayer->maskLayer(), paintType );447 paintContentsIfDirty(replicaLayer->maskLayer(), paintType, noOcclusion); 444 448 } 449 } 450 } 451 452 struct RenderSurfaceRegion { 453 RenderSurfaceChromium* surface; 454 Region occludedInScreen; 455 }; 456 457 // Add the surface to the top of the stack and copy the occlusion from the old top of the stack to the new. 458 static void enterTargetRenderSurface(Vector<RenderSurfaceRegion>& stack, RenderSurfaceChromium* newTarget) 459 { 460 if (stack.isEmpty()) { 461 stack.append(RenderSurfaceRegion()); 462 stack.last().surface = newTarget; 463 } else if (stack.last().surface != newTarget) { 464 const RenderSurfaceRegion& previous = stack.last(); 465 stack.append(RenderSurfaceRegion()); 466 stack.last().surface = newTarget; 467 stack.last().occludedInScreen = previous.occludedInScreen; 468 } 469 } 470 471 // Pop the top of the stack off, push on the new surface, and merge the old top's occlusion into the new top surface. 472 static void leaveTargetRenderSurface(Vector<RenderSurfaceRegion>& stack, RenderSurfaceChromium* newTarget) 473 { 474 int lastIndex = stack.size() - 1; 475 bool surfaceWillBeAtTopAfterPop = stack.size() > 1 && stack[lastIndex - 1].surface == newTarget; 476 477 if (surfaceWillBeAtTopAfterPop) { 478 // Merge the top of the stack down. 479 stack[lastIndex - 1].occludedInScreen.unite(stack[lastIndex].occludedInScreen); 480 stack.removeLast(); 481 } else { 482 // Replace the top of the stack with the new pushed surface. Copy the occluded region to the top. 483 stack.last().surface = newTarget; 445 484 } 446 485 } … … 450 489 // Use FrontToBack to allow for testing occlusion and performing culling during the tree walk. 451 490 typedef CCLayerIterator<LayerChromium, RenderSurfaceChromium, CCLayerIteratorActions::FrontToBack> CCLayerIteratorType; 491 492 // The stack holds occluded regions for subtrees in the RenderSurface-Layer tree, so that when we leave a subtree we may 493 // apply a mask to it, but not to the parts outside the subtree. 494 // - The first time we see a new subtree under a target, we add that target to the top of the stack. This can happen as a layer representing itself, or as a target surface. 495 // - When we visit a target surface, we apply its mask to its subtree, which is at the top of the stack. 496 // - When we visit a layer representing itself, we add its occlusion to the current subtree, which is at the top of the stack. 497 // - When we visit a layer representing a contributing surface, the current target will never be the top of the stack since we just came from the contributing surface. 498 // We merge the occlusion at the top of the stack with the new current subtree. This new target is pushed onto the stack if not already there. 499 Vector<RenderSurfaceRegion> targetSurfaceStack; 452 500 453 501 CCLayerIteratorType end = CCLayerIteratorType::end(&renderSurfaceLayerList); … … 455 503 if (it.representsTargetRenderSurface()) { 456 504 ASSERT(it->renderSurface()->drawOpacity()); 505 506 enterTargetRenderSurface(targetSurfaceStack, it->renderSurface()); 457 507 paintMaskAndReplicaForRenderSurface(*it, paintType); 508 // FIXME: add the replica layer to the current occlusion 509 510 if (it->maskLayer() || it->renderSurface()->drawOpacity() < 1) 511 targetSurfaceStack.last().occludedInScreen = Region(); 458 512 } else if (it.representsItself()) { 459 513 ASSERT(!it->bounds().isEmpty()); 460 paintContentsIfDirty(*it, paintType); 514 515 enterTargetRenderSurface(targetSurfaceStack, it->targetRenderSurface()); 516 paintContentsIfDirty(*it, paintType, targetSurfaceStack.last().occludedInScreen); 517 it->addSelfToOccludedScreenSpace(targetSurfaceStack.last().occludedInScreen); 518 } else { 519 leaveTargetRenderSurface(targetSurfaceStack, it.targetRenderSurfaceLayer()->renderSurface()); 461 520 } 462 521 } -
trunk/Source/WebCore/platform/graphics/chromium/cc/CCLayerTreeHost.h
r106289 r106324 49 49 class GraphicsContext3D; 50 50 class LayerPainterChromium; 51 class Region; 51 52 class TextureAllocator; 52 53 class TextureManager; … … 206 207 207 208 enum PaintType { PaintVisible, PaintIdle }; 208 static void paintContentsIfDirty(LayerChromium*, PaintType );209 static void paintContentsIfDirty(LayerChromium*, PaintType, const Region& occludedScreenSpace); 209 210 void paintLayerContents(const LayerList&, PaintType); 210 211 void paintMaskAndReplicaForRenderSurface(LayerChromium*, PaintType); -
trunk/Source/WebCore/platform/graphics/chromium/cc/CCQuadCuller.cpp
r106300 r106324 76 76 } 77 77 78 static IntRect enclosedIntRect(const FloatRect& rect)79 {80 float x = ceilf(rect.x());81 float y = ceilf(rect.y());82 // A rect of width 0 should not become a rect of width -1.83 float width = max<float>(floorf(rect.maxX()) - x, 0);84 float height = max<float>(floorf(rect.maxY()) - y, 0);85 86 return IntRect(clampToInteger(x), clampToInteger(y),87 clampToInteger(width), clampToInteger(height));88 }89 90 78 void CCQuadCuller::cullOccludedQuads(CCQuadList& quadList) 91 79 { -
trunk/Source/WebKit/chromium/ChangeLog
r106320 r106324 1 2012-01-30 Dana Jansens <danakj@chromium.org> 2 3 [chromium] Compute occlusion during paint loop 4 https://bugs.webkit.org/show_bug.cgi?id=76858 5 6 Reviewed by James Robinson. 7 8 * tests/CCLayerTreeHostCommonTest.cpp: 9 (WebCore::TEST): 10 (WebCore): 11 * tests/CCLayerTreeHostTest.cpp: 12 (WTF::ContentLayerChromiumWithUpdateTracking::paintContentsIfDirty): 13 (WTF): 14 (TestLayerChromium): 15 (WTF::TestLayerChromium::create): 16 (WTF::TestLayerChromium::paintContentsIfDirty): 17 (WTF::TestLayerChromium::drawsContent): 18 (WTF::TestLayerChromium::occludedScreenSpace): 19 (WTF::TestLayerChromium::clearOccludedScreenSpace): 20 (WTF::TestLayerChromium::TestLayerChromium): 21 (WTF::setLayerPropertiesForTesting): 22 (CCLayerTreeHostTestLayerOcclusion): 23 (WTF::CCLayerTreeHostTestLayerOcclusion::CCLayerTreeHostTestLayerOcclusion): 24 (WTF::CCLayerTreeHostTestLayerOcclusion::beginTest): 25 (WTF::CCLayerTreeHostTestLayerOcclusion::afterTest): 26 * tests/Canvas2DLayerChromiumTest.cpp: 27 (WebCore::Canvas2DLayerChromiumTest::fullLifecycleTest): 28 * tests/TiledLayerChromiumTest.cpp: 29 (WTF::FakeLayerTextureUpdater::setOpaquePaintRect): 30 (FakeLayerTextureUpdater): 31 (WTF::FakeTiledLayerChromium::paintContentsIfDirty): 32 (WTF::FakeLayerTextureUpdater::prepareToUpdate): 33 (WTF::TEST): 34 (WTF): 35 1 36 2012-01-30 Gregg Tavares <gman@google.com> 2 37 -
trunk/Source/WebKit/chromium/tests/CCLayerTreeHostCommonTest.cpp
r105460 r106324 29 29 #include "CCLayerTreeTestCommon.h" 30 30 #include "LayerChromium.h" 31 #include "Region.h" 31 32 #include "TransformationMatrix.h" 32 33 … … 35 36 36 37 using namespace WebCore; 38 39 #define EXPECT_EQ_RECT(a, b) \ 40 EXPECT_EQ(a.x(), b.x()); \ 41 EXPECT_EQ(a.y(), b.y()); \ 42 EXPECT_EQ(a.width(), b.width()); \ 43 EXPECT_EQ(a.height(), b.height()); 37 44 38 45 namespace { … … 596 603 // 597 604 605 TEST(CCLayerTreeHostCommonTest, layerAddsSelfToOccludedRegion) 606 { 607 // This tests that the right transforms are being used. 608 Region occluded; 609 const TransformationMatrix identityMatrix; 610 RefPtr<LayerChromium> parent = LayerChromium::create(); 611 RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent()); 612 parent->createRenderSurface(); 613 parent->addChild(layer); 614 615 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 616 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), false); 617 618 layer->setOpaque(true); 619 620 Vector<RefPtr<LayerChromium> > renderSurfaceLayerList; 621 Vector<RefPtr<LayerChromium> > dummyLayerList; 622 int dummyMaxTextureSize = 512; 623 624 // FIXME: when we fix this "root-layer special case" behavior in CCLayerTreeHost, we will have to fix it here, too. 625 parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds())); 626 parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds())); 627 renderSurfaceLayerList.append(parent); 628 629 CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize); 630 631 occluded = Region(); 632 layer->addSelfToOccludedScreenSpace(occluded); 633 EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occluded.bounds()); 634 EXPECT_EQ(1u, occluded.rects().size()); 635 } 636 637 TEST(CCLayerTreeHostCommonTest, layerAddsSelfToOccludedRegionWithRotation) 638 { 639 // This tests that the right transforms are being used. 640 Region occluded; 641 const TransformationMatrix identityMatrix; 642 RefPtr<LayerChromium> parent = LayerChromium::create(); 643 RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent()); 644 parent->createRenderSurface(); 645 parent->addChild(layer); 646 647 TransformationMatrix layerTransform; 648 layerTransform.translate(250, 250); 649 layerTransform.rotate(90); 650 layerTransform.translate(-250, -250); 651 652 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 653 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), false); 654 655 layer->setOpaque(true); 656 657 Vector<RefPtr<LayerChromium> > renderSurfaceLayerList; 658 Vector<RefPtr<LayerChromium> > dummyLayerList; 659 int dummyMaxTextureSize = 512; 660 661 // FIXME: when we fix this "root-layer special case" behavior in CCLayerTreeHost, we will have to fix it here, too. 662 parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds())); 663 parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds())); 664 renderSurfaceLayerList.append(parent); 665 666 CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize); 667 668 occluded = Region(); 669 layer->addSelfToOccludedScreenSpace(occluded); 670 EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occluded.bounds()); 671 EXPECT_EQ(1u, occluded.rects().size()); 672 } 673 674 TEST(CCLayerTreeHostCommonTest, layerAddsSelfToOccludedRegionWithTranslation) 675 { 676 // This tests that the right transforms are being used. 677 Region occluded; 678 const TransformationMatrix identityMatrix; 679 RefPtr<LayerChromium> parent = LayerChromium::create(); 680 RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent()); 681 parent->createRenderSurface(); 682 parent->addChild(layer); 683 684 TransformationMatrix layerTransform; 685 layerTransform.translate(20, 20); 686 687 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 688 setLayerPropertiesForTesting(layer.get(), layerTransform, identityMatrix, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), false); 689 690 layer->setOpaque(true); 691 692 Vector<RefPtr<LayerChromium> > renderSurfaceLayerList; 693 Vector<RefPtr<LayerChromium> > dummyLayerList; 694 int dummyMaxTextureSize = 512; 695 696 // FIXME: when we fix this "root-layer special case" behavior in CCLayerTreeHost, we will have to fix it here, too. 697 parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds())); 698 parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds())); 699 renderSurfaceLayerList.append(parent); 700 701 CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize); 702 703 occluded = Region(); 704 layer->addSelfToOccludedScreenSpace(occluded); 705 EXPECT_EQ_RECT(IntRect(50, 50, 50, 50), occluded.bounds()); 706 EXPECT_EQ(1u, occluded.rects().size()); 707 } 708 709 TEST(CCLayerTreeHostCommonTest, layerAddsSelfToOccludedRegionWithRotatedSurface) 710 { 711 // This tests that the right transforms are being used. 712 Region occluded; 713 const TransformationMatrix identityMatrix; 714 RefPtr<LayerChromium> parent = LayerChromium::create(); 715 RefPtr<LayerChromium> child = LayerChromium::create(); 716 RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent()); 717 parent->createRenderSurface(); 718 parent->addChild(child); 719 child->addChild(layer); 720 721 TransformationMatrix childTransform; 722 childTransform.translate(250, 250); 723 childTransform.rotate(90); 724 childTransform.translate(-250, -250); 725 726 setLayerPropertiesForTesting(parent.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), false); 727 setLayerPropertiesForTesting(child.get(), childTransform, identityMatrix, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), false); 728 setLayerPropertiesForTesting(layer.get(), identityMatrix, identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), false); 729 730 child->setMasksToBounds(true); 731 layer->setOpaque(true); 732 733 Vector<RefPtr<LayerChromium> > renderSurfaceLayerList; 734 Vector<RefPtr<LayerChromium> > dummyLayerList; 735 int dummyMaxTextureSize = 512; 736 737 // FIXME: when we fix this "root-layer special case" behavior in CCLayerTreeHost, we will have to fix it here, too. 738 parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds())); 739 parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds())); 740 renderSurfaceLayerList.append(parent); 741 742 CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize); 743 744 occluded = Region(); 745 layer->addSelfToOccludedScreenSpace(occluded); 746 EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occluded.bounds()); 747 EXPECT_EQ(1u, occluded.rects().size()); 748 749 /* Justification for the above opaque rect from |layer|: 750 100 751 +---------------------+ +---------------------+ 752 | | | |30 Visible region of |layer|: ///// 753 | 30 | rotate(90) | | 754 | 30 + ---------------------------------+ | +---------------------------------+ 755 100 | | 10 | | ==> | | |10 | 756 | |10+---------------------------------+ | +---------------------------------+ | 757 | | | | | | | | |///////////////| 420 | | 758 | | | | | | | | |///////////////|60 | | 759 | | | | | | | | |///////////////| | | 760 +----|--|-------------+ | | +--|--|---------------+ | | 761 | | | | 20|10| 70 | | 762 | | | | | | | | 763 | | | |500 | | | | 764 | | | | | | | | 765 | | | | | | | | 766 | | | | | | | | 767 | | | | | | |10| 768 +--|-------------------------------+ | | +------------------------------|--+ 769 | | | 490 | 770 +---------------------------------+ +---------------------------------+ 771 500 500 772 */ 773 } 774 598 775 } // namespace -
trunk/Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp
r106044 r106324 31 31 #include "GraphicsContext3DPrivate.h" 32 32 #include "LayerChromium.h" 33 #include "Region.h" 33 34 #include "TextureManager.h" 34 35 #include "WebCompositor.h" … … 1006 1007 void resetUpdateCount() { m_updateCount = 0; } 1007 1008 1008 virtual void paintContentsIfDirty( )1009 { 1010 ContentLayerChromium::paintContentsIfDirty( );1009 virtual void paintContentsIfDirty(const Region& occludedScreenSpace) 1010 { 1011 ContentLayerChromium::paintContentsIfDirty(occludedScreenSpace); 1011 1012 m_paintContentsCount++; 1012 1013 } … … 1229 1230 } 1230 1231 1232 #define EXPECT_EQ_RECT(a, b) \ 1233 EXPECT_EQ(a.x(), b.x()); \ 1234 EXPECT_EQ(a.y(), b.y()); \ 1235 EXPECT_EQ(a.width(), b.width()); \ 1236 EXPECT_EQ(a.height(), b.height()); 1237 1238 class TestLayerChromium : public LayerChromium { 1239 public: 1240 static PassRefPtr<TestLayerChromium> create() { return adoptRef(new TestLayerChromium()); } 1241 1242 virtual void paintContentsIfDirty(const Region& occludedScreenSpace) 1243 { 1244 m_occludedScreenSpace = occludedScreenSpace; 1245 } 1246 1247 virtual bool drawsContent() const { return true; } 1248 1249 const Region& occludedScreenSpace() const { return m_occludedScreenSpace; } 1250 void clearOccludedScreenSpace() { m_occludedScreenSpace = Region(); } 1251 1252 private: 1253 TestLayerChromium() : LayerChromium() { } 1254 1255 Region m_occludedScreenSpace; 1256 }; 1257 1258 static void setLayerPropertiesForTesting(TestLayerChromium* layer, LayerChromium* parent, const TransformationMatrix& transform, const FloatPoint& anchor, const FloatPoint& position, const IntSize& bounds, bool opaque) 1259 { 1260 layer->removeAllChildren(); 1261 if (parent) 1262 parent->addChild(layer); 1263 layer->setTransform(transform); 1264 layer->setAnchorPoint(anchor); 1265 layer->setPosition(position); 1266 layer->setBounds(bounds); 1267 layer->setOpaque(opaque); 1268 layer->clearOccludedScreenSpace(); 1269 } 1270 1271 class CCLayerTreeHostTestLayerOcclusion : public CCLayerTreeHostTest { 1272 public: 1273 CCLayerTreeHostTestLayerOcclusion() { } 1274 1275 virtual void beginTest() 1276 { 1277 RefPtr<TestLayerChromium> rootLayer = TestLayerChromium::create(); 1278 RefPtr<TestLayerChromium> child = TestLayerChromium::create(); 1279 RefPtr<TestLayerChromium> child2 = TestLayerChromium::create(); 1280 RefPtr<TestLayerChromium> grandChild = TestLayerChromium::create(); 1281 RefPtr<TestLayerChromium> mask = TestLayerChromium::create(); 1282 1283 TransformationMatrix identityMatrix; 1284 TransformationMatrix childTransform; 1285 childTransform.translate(250, 250); 1286 childTransform.rotate(90); 1287 childTransform.translate(-250, -250); 1288 1289 child->setMasksToBounds(true); 1290 1291 // See CCLayerTreeHostCommonTest.layerAddsSelfToOccludedRegionWithRotatedSurface for a nice visual of these layers and how they end up 1292 // positioned on the screen. 1293 1294 // The child layer is rotated and the grandChild is opaque, but clipped to the child and rootLayer 1295 setLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); 1296 setLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), false); 1297 setLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true); 1298 1299 m_layerTreeHost->setRootLayer(rootLayer); 1300 m_layerTreeHost->setViewportSize(rootLayer->bounds()); 1301 m_layerTreeHost->updateLayers(); 1302 m_layerTreeHost->commitComplete(); 1303 1304 EXPECT_EQ_RECT(IntRect(), grandChild->occludedScreenSpace().bounds()); 1305 EXPECT_EQ(0u, grandChild->occludedScreenSpace().rects().size()); 1306 EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), child->occludedScreenSpace().bounds()); 1307 EXPECT_EQ(1u, child->occludedScreenSpace().rects().size()); 1308 EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), rootLayer->occludedScreenSpace().bounds()); 1309 EXPECT_EQ(1u, rootLayer->occludedScreenSpace().rects().size()); 1310 1311 // If the child layer is opaque, then it adds to the occlusion seen by the rootLayer. 1312 setLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); 1313 setLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), true); 1314 setLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true); 1315 1316 m_layerTreeHost->setRootLayer(rootLayer); 1317 m_layerTreeHost->setViewportSize(rootLayer->bounds()); 1318 m_layerTreeHost->updateLayers(); 1319 m_layerTreeHost->commitComplete(); 1320 1321 EXPECT_EQ_RECT(IntRect(), grandChild->occludedScreenSpace().bounds()); 1322 EXPECT_EQ(0u, grandChild->occludedScreenSpace().rects().size()); 1323 EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), child->occludedScreenSpace().bounds()); 1324 EXPECT_EQ(1u, child->occludedScreenSpace().rects().size()); 1325 EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), rootLayer->occludedScreenSpace().bounds()); 1326 EXPECT_EQ(1u, rootLayer->occludedScreenSpace().rects().size()); 1327 1328 // Add a second child to the root layer and the regions should merge 1329 setLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); 1330 setLayerPropertiesForTesting(child2.get(), rootLayer.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(70, 20), IntSize(500, 500), true); 1331 setLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), true); 1332 setLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true); 1333 1334 m_layerTreeHost->setRootLayer(rootLayer); 1335 m_layerTreeHost->setViewportSize(rootLayer->bounds()); 1336 m_layerTreeHost->updateLayers(); 1337 m_layerTreeHost->commitComplete(); 1338 1339 EXPECT_EQ_RECT(IntRect(), grandChild->occludedScreenSpace().bounds()); 1340 EXPECT_EQ(0u, grandChild->occludedScreenSpace().rects().size()); 1341 EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), child->occludedScreenSpace().bounds()); 1342 EXPECT_EQ(1u, child->occludedScreenSpace().rects().size()); 1343 EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), child2->occludedScreenSpace().bounds()); 1344 EXPECT_EQ(1u, child2->occludedScreenSpace().rects().size()); 1345 EXPECT_EQ_RECT(IntRect(30, 20, 70, 80), rootLayer->occludedScreenSpace().bounds()); 1346 EXPECT_EQ(2u, rootLayer->occludedScreenSpace().rects().size()); 1347 1348 // Move the second child to be sure. 1349 setLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); 1350 setLayerPropertiesForTesting(child2.get(), rootLayer.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 70), IntSize(500, 500), true); 1351 setLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), true); 1352 setLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true); 1353 1354 m_layerTreeHost->setRootLayer(rootLayer); 1355 m_layerTreeHost->setViewportSize(rootLayer->bounds()); 1356 m_layerTreeHost->updateLayers(); 1357 m_layerTreeHost->commitComplete(); 1358 1359 EXPECT_EQ_RECT(IntRect(), grandChild->occludedScreenSpace().bounds()); 1360 EXPECT_EQ(0u, grandChild->occludedScreenSpace().rects().size()); 1361 EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), child->occludedScreenSpace().bounds()); 1362 EXPECT_EQ(1u, child->occludedScreenSpace().rects().size()); 1363 EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), child2->occludedScreenSpace().bounds()); 1364 EXPECT_EQ(1u, child2->occludedScreenSpace().rects().size()); 1365 EXPECT_EQ_RECT(IntRect(10, 30, 90, 70), rootLayer->occludedScreenSpace().bounds()); 1366 EXPECT_EQ(2u, rootLayer->occludedScreenSpace().rects().size()); 1367 1368 // If the child layer has a mask on it, then it shouldn't contribute to occlusion on stuff below it 1369 setLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); 1370 setLayerPropertiesForTesting(child2.get(), rootLayer.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 70), IntSize(500, 500), true); 1371 setLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), true); 1372 setLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true); 1373 1374 child->setMaskLayer(mask.get()); 1375 1376 m_layerTreeHost->setRootLayer(rootLayer); 1377 m_layerTreeHost->setViewportSize(rootLayer->bounds()); 1378 m_layerTreeHost->updateLayers(); 1379 m_layerTreeHost->commitComplete(); 1380 1381 EXPECT_EQ_RECT(IntRect(), grandChild->occludedScreenSpace().bounds()); 1382 EXPECT_EQ(0u, grandChild->occludedScreenSpace().rects().size()); 1383 EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), child->occludedScreenSpace().bounds()); 1384 EXPECT_EQ(1u, child->occludedScreenSpace().rects().size()); 1385 EXPECT_EQ_RECT(IntRect(), child2->occludedScreenSpace().bounds()); 1386 EXPECT_EQ(0u, child2->occludedScreenSpace().rects().size()); 1387 EXPECT_EQ_RECT(IntRect(10, 70, 90, 30), rootLayer->occludedScreenSpace().bounds()); 1388 EXPECT_EQ(1u, rootLayer->occludedScreenSpace().rects().size()); 1389 1390 // If the child layer with a mask is below child2, then child2 should contribute to occlusion on everything, and child shouldn't contribute to the rootLayer 1391 setLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); 1392 setLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), true); 1393 setLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true); 1394 setLayerPropertiesForTesting(child2.get(), rootLayer.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 70), IntSize(500, 500), true); 1395 1396 child->setMaskLayer(mask.get()); 1397 1398 m_layerTreeHost->setRootLayer(rootLayer); 1399 m_layerTreeHost->setViewportSize(rootLayer->bounds()); 1400 m_layerTreeHost->updateLayers(); 1401 m_layerTreeHost->commitComplete(); 1402 1403 EXPECT_EQ_RECT(IntRect(), child2->occludedScreenSpace().bounds()); 1404 EXPECT_EQ(0u, child2->occludedScreenSpace().rects().size()); 1405 EXPECT_EQ_RECT(IntRect(10, 70, 90, 30), grandChild->occludedScreenSpace().bounds()); 1406 EXPECT_EQ(1u, grandChild->occludedScreenSpace().rects().size()); 1407 EXPECT_EQ_RECT(IntRect(10, 40, 90, 60), child->occludedScreenSpace().bounds()); 1408 EXPECT_EQ(2u, child->occludedScreenSpace().rects().size()); 1409 EXPECT_EQ_RECT(IntRect(10, 70, 90, 30), rootLayer->occludedScreenSpace().bounds()); 1410 EXPECT_EQ(1u, rootLayer->occludedScreenSpace().rects().size()); 1411 1412 // If the child layer has a non-opaque drawOpacity, then it shouldn't contribute to occlusion on stuff below it 1413 setLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); 1414 setLayerPropertiesForTesting(child2.get(), rootLayer.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 70), IntSize(500, 500), true); 1415 setLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), true); 1416 setLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true); 1417 1418 child->setMaskLayer(0); 1419 child->setDrawOpacity(0.5); 1420 1421 m_layerTreeHost->setRootLayer(rootLayer); 1422 m_layerTreeHost->setViewportSize(rootLayer->bounds()); 1423 m_layerTreeHost->updateLayers(); 1424 m_layerTreeHost->commitComplete(); 1425 1426 EXPECT_EQ_RECT(IntRect(), grandChild->occludedScreenSpace().bounds()); 1427 EXPECT_EQ(0u, grandChild->occludedScreenSpace().rects().size()); 1428 EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), child->occludedScreenSpace().bounds()); 1429 EXPECT_EQ(1u, child->occludedScreenSpace().rects().size()); 1430 EXPECT_EQ_RECT(IntRect(), child2->occludedScreenSpace().bounds()); 1431 EXPECT_EQ(0u, child2->occludedScreenSpace().rects().size()); 1432 EXPECT_EQ_RECT(IntRect(10, 70, 90, 30), rootLayer->occludedScreenSpace().bounds()); 1433 EXPECT_EQ(1u, rootLayer->occludedScreenSpace().rects().size()); 1434 1435 // If the child layer with non-opaque drawOpacity is below child2, then child2 should contribute to occlusion on everything, and child shouldn't contribute to the rootLayer 1436 setLayerPropertiesForTesting(rootLayer.get(), 0, identityMatrix, FloatPoint(0, 0), FloatPoint(0, 0), IntSize(100, 100), true); 1437 setLayerPropertiesForTesting(child.get(), rootLayer.get(), childTransform, FloatPoint(0, 0), FloatPoint(30, 30), IntSize(500, 500), true); 1438 setLayerPropertiesForTesting(grandChild.get(), child.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 10), IntSize(500, 500), true); 1439 setLayerPropertiesForTesting(child2.get(), rootLayer.get(), identityMatrix, FloatPoint(0, 0), FloatPoint(10, 70), IntSize(500, 500), true); 1440 1441 child->setMaskLayer(0); 1442 child->setDrawOpacity(0.5); 1443 1444 m_layerTreeHost->setRootLayer(rootLayer); 1445 m_layerTreeHost->setViewportSize(rootLayer->bounds()); 1446 m_layerTreeHost->updateLayers(); 1447 m_layerTreeHost->commitComplete(); 1448 1449 EXPECT_EQ_RECT(IntRect(), child2->occludedScreenSpace().bounds()); 1450 EXPECT_EQ(0u, child2->occludedScreenSpace().rects().size()); 1451 EXPECT_EQ_RECT(IntRect(10, 70, 90, 30), grandChild->occludedScreenSpace().bounds()); 1452 EXPECT_EQ(1u, grandChild->occludedScreenSpace().rects().size()); 1453 EXPECT_EQ_RECT(IntRect(10, 40, 90, 60), child->occludedScreenSpace().bounds()); 1454 EXPECT_EQ(2u, child->occludedScreenSpace().rects().size()); 1455 EXPECT_EQ_RECT(IntRect(10, 70, 90, 30), rootLayer->occludedScreenSpace().bounds()); 1456 EXPECT_EQ(1u, rootLayer->occludedScreenSpace().rects().size()); 1457 1458 // Kill the layerTreeHost immediately. 1459 m_layerTreeHost->setRootLayer(0); 1460 m_layerTreeHost.clear(); 1461 1462 endTest(); 1463 } 1464 1465 virtual void afterTest() 1466 { 1467 } 1468 }; 1469 1470 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestLayerOcclusion) 1471 1231 1472 } // namespace -
trunk/Source/WebKit/chromium/tests/Canvas2DLayerChromiumTest.cpp
r104044 r106324 30 30 #include "FakeWebGraphicsContext3D.h" 31 31 #include "GraphicsContext3DPrivate.h" 32 #include "Region.h" 32 33 #include "TextureManager.h" 33 34 #include "cc/CCCanvasLayerImpl.h" … … 139 140 canvas->contentChanged(); 140 141 EXPECT_TRUE(canvas->needsDisplay()); 141 canvas->paintContentsIfDirty(); 142 Region occludedScreenSpace; 143 canvas->paintContentsIfDirty(occludedScreenSpace); 142 144 EXPECT_FALSE(canvas->needsDisplay()); 143 145 { -
trunk/Source/WebKit/chromium/tests/TiledLayerChromiumTest.cpp
r105845 r106324 30 30 #include "FakeCCLayerTreeHostClient.h" 31 31 #include "LayerTextureUpdater.h" 32 #include "Region.h" 32 33 #include "TextureManager.h" 33 34 #include "WebCompositor.h" … … 40 41 using namespace WTF; 41 42 43 #define EXPECT_EQ_RECT(a, b) \ 44 EXPECT_EQ(a.x(), b.x()); \ 45 EXPECT_EQ(a.y(), b.y()); \ 46 EXPECT_EQ(a.width(), b.width()); \ 47 EXPECT_EQ(a.height(), b.height()); 48 42 49 namespace { 43 50 … … 71 78 void clearPrepareCount() { m_prepareCount = 0; } 72 79 80 void setOpaquePaintRect(const IntRect& opaquePaintRect) { m_opaquePaintRect = opaquePaintRect; } 81 73 82 // Last rect passed to prepareToUpdate(). 74 83 const IntRect& lastUpdateRect() const { return m_lastUpdateRect; } … … 76 85 virtual PassOwnPtr<LayerTextureUpdater::Texture> createTexture(TextureManager* manager) { return adoptPtr(new Texture(ManagedTexture::create(manager))); } 77 86 virtual SampledTexelFormat sampledTexelFormat(GC3Denum) { return SampledTexelFormatRGBA; } 78 virtual void prepareToUpdate(const IntRect& contentRect, const IntSize&, int, float, IntRect* );87 virtual void prepareToUpdate(const IntRect& contentRect, const IntSize&, int, float, IntRect* resultingOpaqueRect); 79 88 80 89 private: … … 82 91 IntRect m_rectToInvalidate; 83 92 IntRect m_lastUpdateRect; 93 IntRect m_opaquePaintRect; 84 94 RefPtr<FakeTiledLayerChromium> m_layer; 85 95 }; … … 140 150 virtual TextureManager* textureManager() const { return m_textureManager; } 141 151 142 virtual void paintContentsIfDirty( )152 virtual void paintContentsIfDirty(const Region& /* occludedScreenSpace */) 143 153 { 144 154 prepareToUpdate(visibleLayerRect()); … … 188 198 m_layer = 0; 189 199 } 190 *resultingOpaqueRect = IntRect();200 *resultingOpaqueRect = m_opaquePaintRect; 191 201 } 192 202 … … 461 471 } 462 472 473 TEST(TiledLayerChromiumTest, layerAddsSelfToOccludedRegion) 474 { 475 OwnPtr<TextureManager> textureManager = TextureManager::create(4*1024*1024, 2*1024*1024, 1024); 476 RefPtr<FakeTiledLayerChromium> layer = adoptRef(new FakeTiledLayerChromium(textureManager.get())); 477 478 // The tile size is 100x100, so this invalidates and then paints two tiles in various ways. 479 480 Region occluded; 481 IntRect contentBounds = IntRect(0, 0, 100, 200); 482 IntRect visibleBounds = IntRect(0, 0, 100, 150); 483 484 layer->setBounds(contentBounds.size()); 485 layer->setVisibleLayerRect(visibleBounds); 486 layer->setDrawOpacity(1); 487 488 // The screenSpaceTransform is verified in CCLayerTreeHostCommonTests 489 TransformationMatrix screenSpaceTransform; 490 layer->setScreenSpaceTransform(screenSpaceTransform); 491 492 // If the layer is opaque then the occluded region should be the whole layer's visible region. 493 layer->setOpaque(true); 494 layer->invalidateRect(contentBounds); 495 layer->prepareToUpdate(contentBounds); 496 497 occluded = Region(); 498 layer->addSelfToOccludedScreenSpace(occluded); 499 EXPECT_EQ_RECT(visibleBounds, occluded.bounds()); 500 EXPECT_EQ(1u, occluded.rects().size()); 501 502 // If the layer is not opaque then the occluded region should be empty. 503 layer->setOpaque(false); 504 layer->invalidateRect(contentBounds); 505 layer->prepareToUpdate(contentBounds); 506 507 occluded = Region(); 508 layer->addSelfToOccludedScreenSpace(occluded); 509 EXPECT_EQ_RECT(IntRect(), occluded.bounds()); 510 EXPECT_EQ(1u, occluded.rects().size()); 511 512 // If the layer paints opaque content, then the occluded region should match the visible opaque content. 513 IntRect opaquePaintRect = IntRect(10, 10, 90, 190); 514 layer->fakeLayerTextureUpdater()->setOpaquePaintRect(opaquePaintRect); 515 layer->invalidateRect(contentBounds); 516 layer->prepareToUpdate(contentBounds); 517 518 occluded = Region(); 519 layer->addSelfToOccludedScreenSpace(occluded); 520 EXPECT_EQ_RECT(intersection(opaquePaintRect, visibleBounds), occluded.bounds()); 521 EXPECT_EQ(1u, occluded.rects().size()); 522 523 // If we paint again without invalidating, the same stuff should be occluded. 524 layer->fakeLayerTextureUpdater()->setOpaquePaintRect(IntRect()); 525 layer->prepareToUpdate(contentBounds); 526 527 occluded = Region(); 528 layer->addSelfToOccludedScreenSpace(occluded); 529 EXPECT_EQ_RECT(intersection(opaquePaintRect, visibleBounds), occluded.bounds()); 530 EXPECT_EQ(1u, occluded.rects().size()); 531 532 // If the layer is transformed then the resulting occluded area needs to be transformed to its target space. 533 TransformationMatrix transform; 534 transform.translate(contentBounds.width() / 2.0, contentBounds.height() / 2.0); 535 transform.rotate(90); 536 transform.translate(-contentBounds.width() / 2.0, -contentBounds.height() / 2.0); 537 transform.translate(10, 10); 538 screenSpaceTransform.translate(contentBounds.width() / 2.0, contentBounds.height() / 2.0); 539 screenSpaceTransform *= transform; 540 screenSpaceTransform.translate(-contentBounds.width() / 2.0, -contentBounds.height() / 2.0); 541 layer->setScreenSpaceTransform(screenSpaceTransform); 542 layer->prepareToUpdate(contentBounds); 543 544 occluded = Region(); 545 layer->addSelfToOccludedScreenSpace(occluded); 546 EXPECT_EQ_RECT(screenSpaceTransform.mapRect(intersection(opaquePaintRect, visibleBounds)), occluded.bounds()); 547 EXPECT_EQ(1u, occluded.rects().size()); 548 549 // But a non-axis-aligned transform does not get considered for occlusion. 550 transform.translate(contentBounds.width() / 2.0, contentBounds.height() / 2.0); 551 transform.rotate(5); 552 transform.translate(-contentBounds.width() / 2.0, -contentBounds.height() / 2.0); 553 screenSpaceTransform.translate(contentBounds.width() / 2.0, contentBounds.height() / 2.0); 554 screenSpaceTransform *= transform; 555 screenSpaceTransform.translate(-contentBounds.width() / 2.0, -contentBounds.height() / 2.0); 556 layer->setScreenSpaceTransform(screenSpaceTransform); 557 layer->prepareToUpdate(contentBounds); 558 559 occluded = Region(); 560 layer->addSelfToOccludedScreenSpace(occluded); 561 // FIXME: If we find an opaque rect contained in the rotated non-axis-aligned rect, then 562 // this won't be an empty result. 563 EXPECT_EQ_RECT(IntRect(), occluded.bounds()); 564 EXPECT_EQ(0u, occluded.rects().size()); 565 } 566 463 567 } // namespace
Note: See TracChangeset
for help on using the changeset viewer.