Changeset 110372 in webkit


Ignore:
Timestamp:
Mar 10, 2012 2:27:37 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Unreviewed, rolling out r110353.
http://trac.webkit.org/changeset/110353
https://bugs.webkit.org/show_bug.cgi?id=80752

copmile failed on Chromium (Requested by ukai_home on
#webkit).

Patch by Sheriff Bot <webkit.review.bot@gmail.com> on 2012-03-10

  • tests/CCOcclusionTrackerTest.cpp:

(WebCore::LayerChromiumWithForcedDrawsContent::LayerChromiumWithForcedDrawsContent):
(WebCore::LayerChromiumWithForcedDrawsContent::opaqueContentsRegion):
(WebCore::LayerChromiumWithForcedDrawsContent::setOpaquePaintRect):
(LayerChromiumWithForcedDrawsContent):
(WebCore::setLayerPropertiesForTesting):
(WebCore):
(WebCore::TestCCOcclusionTracker::TestCCOcclusionTracker):
(WebCore::TestCCOcclusionTracker::occlusionInScreenSpace):
(WebCore::TestCCOcclusionTracker::occlusionInTargetSurface):
(WebCore::TestCCOcclusionTracker::setOcclusionInScreenSpace):
(WebCore::TestCCOcclusionTracker::setOcclusionInTargetSurface):
(WebCore::TestCCOcclusionTracker::layerScissorRectInTargetSurface):
(WebCore::TestDamageClient::damageRect):
(WebCore::layerAddedToOccludedRegion):
(WebCore::layerAddedToOccludedRegionWithRotation):
(WebCore::layerAddedToOccludedRegionWithTranslation):
(WebCore::layerAddedToOccludedRegionWithRotatedSurface):
(WebCore::layerAddedToOccludedRegionWithSurfaceAlreadyOnStack):
(WebCore::layerAddedToOccludedRegionWithRotatedOffAxisSurface):
(WebCore::layerAddedToOccludedRegionWithMultipleOpaqueLayers):
(WebCore::surfaceOcclusionWithOverlappingSiblingSurfaces):
(WebCore::surfaceOcclusionInScreenSpace):
(WebCore::surfaceOcclusionInScreenSpaceDifferentTransforms):
(WebCore::occlusionInteractionWithFilters):
(WebCore::layerScissorRectOverTile):
(WebCore::screenScissorRectOverTile):
(WebCore::layerScissorRectOverCulledTile):
(WebCore::screenScissorRectOverCulledTile):
(WebCore::layerScissorRectOverPartialTiles):
(WebCore::screenScissorRectOverPartialTiles):
(WebCore::layerScissorRectOverNoTiles):
(WebCore::screenScissorRectOverNoTiles):
(WebCore::layerScissorRectForLayerOffOrigin):
(WebCore::damageRectOverTile):
(WebCore::damageRectOverCulledTile):
(WebCore::damageRectOverPartialTiles):
(WebCore::damageRectOverNoTiles):
(WebCore::TEST):

Location:
trunk/Source/WebKit/chromium
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/chromium/ChangeLog

    r110371 r110372  
     12012-03-10  Sheriff Bot  <webkit.review.bot@gmail.com>
     2
     3        Unreviewed, rolling out r110353.
     4        http://trac.webkit.org/changeset/110353
     5        https://bugs.webkit.org/show_bug.cgi?id=80752
     6
     7        copmile failed on Chromium (Requested by ukai_home on
     8        #webkit).
     9
     10        * tests/CCOcclusionTrackerTest.cpp:
     11        (WebCore::LayerChromiumWithForcedDrawsContent::LayerChromiumWithForcedDrawsContent):
     12        (WebCore::LayerChromiumWithForcedDrawsContent::opaqueContentsRegion):
     13        (WebCore::LayerChromiumWithForcedDrawsContent::setOpaquePaintRect):
     14        (LayerChromiumWithForcedDrawsContent):
     15        (WebCore::setLayerPropertiesForTesting):
     16        (WebCore):
     17        (WebCore::TestCCOcclusionTracker::TestCCOcclusionTracker):
     18        (WebCore::TestCCOcclusionTracker::occlusionInScreenSpace):
     19        (WebCore::TestCCOcclusionTracker::occlusionInTargetSurface):
     20        (WebCore::TestCCOcclusionTracker::setOcclusionInScreenSpace):
     21        (WebCore::TestCCOcclusionTracker::setOcclusionInTargetSurface):
     22        (WebCore::TestCCOcclusionTracker::layerScissorRectInTargetSurface):
     23        (WebCore::TestDamageClient::damageRect):
     24        (WebCore::layerAddedToOccludedRegion):
     25        (WebCore::layerAddedToOccludedRegionWithRotation):
     26        (WebCore::layerAddedToOccludedRegionWithTranslation):
     27        (WebCore::layerAddedToOccludedRegionWithRotatedSurface):
     28        (WebCore::layerAddedToOccludedRegionWithSurfaceAlreadyOnStack):
     29        (WebCore::layerAddedToOccludedRegionWithRotatedOffAxisSurface):
     30        (WebCore::layerAddedToOccludedRegionWithMultipleOpaqueLayers):
     31        (WebCore::surfaceOcclusionWithOverlappingSiblingSurfaces):
     32        (WebCore::surfaceOcclusionInScreenSpace):
     33        (WebCore::surfaceOcclusionInScreenSpaceDifferentTransforms):
     34        (WebCore::occlusionInteractionWithFilters):
     35        (WebCore::layerScissorRectOverTile):
     36        (WebCore::screenScissorRectOverTile):
     37        (WebCore::layerScissorRectOverCulledTile):
     38        (WebCore::screenScissorRectOverCulledTile):
     39        (WebCore::layerScissorRectOverPartialTiles):
     40        (WebCore::screenScissorRectOverPartialTiles):
     41        (WebCore::layerScissorRectOverNoTiles):
     42        (WebCore::screenScissorRectOverNoTiles):
     43        (WebCore::layerScissorRectForLayerOffOrigin):
     44        (WebCore::damageRectOverTile):
     45        (WebCore::damageRectOverCulledTile):
     46        (WebCore::damageRectOverPartialTiles):
     47        (WebCore::damageRectOverNoTiles):
     48        (WebCore::TEST):
     49
    1502012-03-09  Robert Kroeger  <rjkroege@chromium.org>
    251
  • trunk/Source/WebKit/chromium/tests/CCOcclusionTrackerTest.cpp

    r110353 r110372  
    3131#include "Region.h"
    3232#include "TransformationMatrix.h"
    33 #include "cc/CCLayerImpl.h"
    3433#include "cc/CCLayerTreeHostCommon.h"
    35 #include "cc/CCSingleThreadProxy.h"
    3634
    3735#include <gmock/gmock.h>
     
    4846namespace {
    4947
    50 class TestContentLayerChromium : public LayerChromium {
     48class LayerChromiumWithForcedDrawsContent : public LayerChromium {
    5149public:
    52     TestContentLayerChromium() : LayerChromium() { }
     50    LayerChromiumWithForcedDrawsContent()
     51        : LayerChromium()
     52    {
     53    }
    5354
    5455    virtual bool drawsContent() const { return true; }
    55     virtual Region opaqueContentsRegion() const { return intersection(m_opaqueContentsRect, visibleLayerRect()); }
    56     void setOpaqueContentsRect(const IntRect& opaqueContentsRect) { m_opaqueContentsRect = opaqueContentsRect; }
     56    virtual Region opaqueContentsRegion() const
     57    {
     58        return intersection(m_opaquePaintRect, visibleLayerRect());
     59    }
     60
     61    void setOpaquePaintRect(const IntRect& opaquePaintRect) { m_opaquePaintRect = opaquePaintRect; }
    5762
    5863private:
    59     IntRect m_opaqueContentsRect;
     64    IntRect m_opaquePaintRect;
    6065};
    6166
    62 class TestContentLayerImpl : public CCLayerImpl {
     67void setLayerPropertiesForTesting(LayerChromium* layer, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
     68{
     69    layer->setTransform(transform);
     70    layer->setSublayerTransform(TransformationMatrix());
     71    layer->setAnchorPoint(FloatPoint(0, 0));
     72    layer->setPosition(position);
     73    layer->setBounds(bounds);
     74}
     75
     76void setLayerPropertiesForTesting(LayerChromiumWithForcedDrawsContent* layer, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds, bool opaque, bool opaqueLayers)
     77{
     78    setLayerPropertiesForTesting(layer, transform, position, bounds);
     79    if (opaqueLayers)
     80        layer->setOpaque(opaque);
     81    else {
     82        layer->setOpaque(false);
     83        if (opaque)
     84            layer->setOpaquePaintRect(IntRect(IntPoint(), bounds));
     85        else
     86            layer->setOpaquePaintRect(IntRect());
     87    }
     88}
     89
     90// A subclass to expose the total current occlusion.
     91class TestCCOcclusionTracker : public CCOcclusionTracker {
    6392public:
    64     TestContentLayerImpl(int id) : CCLayerImpl(id) { setDrawsContent(true); }
    65 
    66     virtual Region opaqueContentsRegion() const { return intersection(m_opaqueContentsRect, visibleLayerRect()); }
    67     void setOpaqueContentsRect(const IntRect& opaqueContentsRect) { m_opaqueContentsRect = opaqueContentsRect; }
    68 private:
    69     IntRect m_opaqueContentsRect;
    70 };
    71 
    72 // A subclass to expose the total current occlusion.
    73 template<typename LayerType, typename RenderSurfaceType>
    74 class TestCCOcclusionTrackerBase : public CCOcclusionTrackerBase<LayerType, RenderSurfaceType> {
    75 public:
    76     TestCCOcclusionTrackerBase(IntRect screenScissorRect)
    77         : CCOcclusionTrackerBase<LayerType, RenderSurfaceType>(screenScissorRect)
     93    TestCCOcclusionTracker(IntRect screenScissorRect)
     94        : CCOcclusionTracker(screenScissorRect)
    7895        , m_overrideLayerScissorRect(false)
    7996    {
    8097    }
    8198
    82     TestCCOcclusionTrackerBase(IntRect screenScissorRect, const CCOcclusionTrackerDamageClientBase<RenderSurfaceType>* damageClient)
    83         : CCOcclusionTrackerBase<LayerType, RenderSurfaceType>(screenScissorRect, damageClient)
     99    TestCCOcclusionTracker(IntRect screenScissorRect, const CCOcclusionTrackerDamageClient* damageClient)
     100        : CCOcclusionTracker(screenScissorRect, damageClient)
    84101        , m_overrideLayerScissorRect(false)
    85102    {
    86103    }
    87104
    88     Region occlusionInScreenSpace() const { return CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::m_stack.last().occlusionInScreen; }
    89     Region occlusionInTargetSurface() const { return CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::m_stack.last().occlusionInTarget; }
    90 
    91     void setOcclusionInScreenSpace(const Region& region) { CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::m_stack.last().occlusionInScreen = region; }
    92     void setOcclusionInTargetSurface(const Region& region) { CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::m_stack.last().occlusionInTarget = region; }
     105    Region occlusionInScreenSpace() const { return CCOcclusionTracker::m_stack.last().occlusionInScreen; }
     106    Region occlusionInTargetSurface() const { return CCOcclusionTracker::m_stack.last().occlusionInTarget; }
     107
     108    void setOcclusionInScreenSpace(const Region& region) { CCOcclusionTracker::m_stack.last().occlusionInScreen = region; }
     109    void setOcclusionInTargetSurface(const Region& region) { CCOcclusionTracker::m_stack.last().occlusionInTarget = region; }
    93110
    94111    void setLayerScissorRect(const IntRect& rect) { m_overrideLayerScissorRect = true; m_layerScissorRect = rect;}
     
    96113
    97114protected:
    98     virtual IntRect layerScissorRectInTargetSurface(const LayerType* layer) const { return m_overrideLayerScissorRect ? m_layerScissorRect : CCOcclusionTrackerBase<LayerType, RenderSurfaceType>::layerScissorRectInTargetSurface(layer); }
     115    virtual IntRect layerScissorRectInTargetSurface(const LayerChromium* layer) const { return m_overrideLayerScissorRect ? m_layerScissorRect : CCOcclusionTracker::layerScissorRectInTargetSurface(layer); }
    99116
    100117private:
     
    103120};
    104121
    105 template<typename RenderSurfaceType>
    106 class TestDamageClient : public CCOcclusionTrackerDamageClientBase<RenderSurfaceType> {
     122class TestDamageClient : public CCOcclusionTrackerDamageClient {
    107123public:
    108124    // The interface
    109     virtual FloatRect damageRect(const RenderSurfaceType*) const { return m_damageRect; }
     125    virtual FloatRect damageRect(const RenderSurfaceChromium*) const { return m_damageRect; }
    110126
    111127    // Testing stuff
     
    117133};
    118134
    119 struct CCOcclusionTrackerTestMainThreadTypes {
    120     typedef LayerChromium LayerType;
    121     typedef RenderSurfaceChromium RenderSurfaceType;
    122     typedef TestContentLayerChromium ContentLayerType;
    123     typedef RefPtr<LayerChromium> LayerPtrType;
    124     typedef PassRefPtr<LayerChromium> PassLayerPtrType;
    125     typedef RefPtr<ContentLayerType> ContentLayerPtrType;
    126     typedef PassRefPtr<ContentLayerType> PassContentLayerPtrType;
    127 
    128     static PassLayerPtrType createLayer() { return LayerChromium::create(); }
    129     static PassContentLayerPtrType createContentLayer() { return adoptRef(new ContentLayerType()); }
    130 };
    131 
    132 struct CCOcclusionTrackerTestImplThreadTypes {
    133     typedef CCLayerImpl LayerType;
    134     typedef CCRenderSurface RenderSurfaceType;
    135     typedef TestContentLayerImpl ContentLayerType;
    136     typedef OwnPtr<CCLayerImpl> LayerPtrType;
    137     typedef PassOwnPtr<CCLayerImpl> PassLayerPtrType;
    138     typedef OwnPtr<ContentLayerType> ContentLayerPtrType;
    139     typedef PassOwnPtr<ContentLayerType> PassContentLayerPtrType;
    140 
    141     static PassLayerPtrType createLayer() { return CCLayerImpl::create(nextCCLayerImplId++); }
    142     static PassContentLayerPtrType createContentLayer() { return adoptPtr(new ContentLayerType(nextCCLayerImplId++)); }
    143     static int nextCCLayerImplId;
    144 };
    145 
    146 int CCOcclusionTrackerTestImplThreadTypes::nextCCLayerImplId = 0;
    147 
    148 template<typename Types, bool opaqueLayers>
    149 class CCOcclusionTrackerTest : public testing::Test {
    150 protected:
    151     virtual void runMyTest() = 0;
    152 
    153     virtual void TearDown()
     135#define TEST_OPAQUE_AND_PAINTED_OPAQUE(FULLTESTNAME, SHORTTESTNAME) \
     136    TEST(FULLTESTNAME, opaqueLayer)                                 \
     137    {                                                               \
     138        SHORTTESTNAME(true);                                        \
     139    }                                                               \
     140    TEST(FULLTESTNAME, opaquePaintRect)                             \
     141    {                                                               \
     142        SHORTTESTNAME(false);                                       \
     143    }
     144
     145void layerAddedToOccludedRegion(bool opaqueLayers)
     146{
     147    // This tests that the right transforms are being used.
     148    const TransformationMatrix identityMatrix;
     149    RefPtr<LayerChromium> parent = LayerChromium::create();
     150    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     151    parent->createRenderSurface();
     152    parent->addChild(layer);
     153
     154    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
     155    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(30, 30), IntSize(500, 500), true, opaqueLayers);
     156
     157    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     158    Vector<RefPtr<LayerChromium> > dummyLayerList;
     159    int dummyMaxTextureSize = 512;
     160
     161    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     162    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     163    renderSurfaceLayerList.append(parent);
     164
     165    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     166
     167    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     168    occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
     169
     170    occlusion.enterTargetRenderSurface(parent->renderSurface());
     171    occlusion.markOccludedBehindLayer(layer.get());
     172    EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
     173    EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
     174    EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
     175    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     176
     177    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(30, 30, 70, 70)));
     178    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(29, 30, 70, 70)));
     179    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(30, 29, 70, 70)));
     180    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(31, 30, 70, 70)));
     181    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(30, 31, 70, 70)));
     182
     183    occlusion.useDefaultLayerScissorRect();
     184    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(30, 30, 70, 70)));
     185    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(29, 30, 70, 70)));
     186    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(30, 29, 70, 70)));
     187    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(31, 30, 70, 70)));
     188    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(30, 31, 70, 70)));
     189    occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
     190
     191    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(30, 30, 70, 70)).isEmpty());
     192    EXPECT_EQ_RECT(IntRect(29, 30, 1, 70), occlusion.unoccludedContentRect(parent.get(), IntRect(29, 30, 70, 70)));
     193    EXPECT_EQ_RECT(IntRect(29, 29, 70, 70), occlusion.unoccludedContentRect(parent.get(), IntRect(29, 29, 70, 70)));
     194    EXPECT_EQ_RECT(IntRect(30, 29, 70, 1), occlusion.unoccludedContentRect(parent.get(), IntRect(30, 29, 70, 70)));
     195    EXPECT_EQ_RECT(IntRect(31, 29, 70, 70), occlusion.unoccludedContentRect(parent.get(), IntRect(31, 29, 70, 70)));
     196    EXPECT_EQ_RECT(IntRect(100, 30, 1, 70), occlusion.unoccludedContentRect(parent.get(), IntRect(31, 30, 70, 70)));
     197    EXPECT_EQ_RECT(IntRect(31, 31, 70, 70), occlusion.unoccludedContentRect(parent.get(), IntRect(31, 31, 70, 70)));
     198    EXPECT_EQ_RECT(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent.get(), IntRect(30, 31, 70, 70)));
     199    EXPECT_EQ_RECT(IntRect(29, 31, 70, 70), occlusion.unoccludedContentRect(parent.get(), IntRect(29, 31, 70, 70)));
     200}
     201
     202TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_layerAddedToOccludedRegion, layerAddedToOccludedRegion);
     203
     204void layerAddedToOccludedRegionWithRotation(bool opaqueLayers)
     205{
     206    // This tests that the right transforms are being used.
     207    const TransformationMatrix identityMatrix;
     208    RefPtr<LayerChromium> parent = LayerChromium::create();
     209    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     210    parent->createRenderSurface();
     211    parent->addChild(layer);
     212
     213    TransformationMatrix layerTransform;
     214    layerTransform.translate(250, 250);
     215    layerTransform.rotate(90);
     216    layerTransform.translate(-250, -250);
     217
     218    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
     219    setLayerPropertiesForTesting(layer.get(), layerTransform, FloatPoint(30, 30), IntSize(500, 500), true, opaqueLayers);
     220
     221    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     222    Vector<RefPtr<LayerChromium> > dummyLayerList;
     223    int dummyMaxTextureSize = 512;
     224
     225    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     226    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     227    renderSurfaceLayerList.append(parent);
     228
     229    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     230
     231    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     232    occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
     233
     234    occlusion.enterTargetRenderSurface(parent->renderSurface());
     235    occlusion.markOccludedBehindLayer(layer.get());
     236    EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
     237    EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
     238    EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
     239    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     240
     241    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(30, 30, 70, 70)));
     242    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(29, 30, 70, 70)));
     243    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(30, 29, 70, 70)));
     244    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(31, 30, 70, 70)));
     245    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(30, 31, 70, 70)));
     246
     247    occlusion.useDefaultLayerScissorRect();
     248    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(30, 30, 70, 70)));
     249    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(29, 30, 70, 70)));
     250    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(30, 29, 70, 70)));
     251    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(31, 30, 70, 70)));
     252    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(30, 31, 70, 70)));
     253    occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
     254
     255    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(30, 30, 70, 70)).isEmpty());
     256    EXPECT_EQ_RECT(IntRect(29, 30, 1, 70), occlusion.unoccludedContentRect(parent.get(), IntRect(29, 30, 70, 70)));
     257    EXPECT_EQ_RECT(IntRect(29, 29, 70, 70), occlusion.unoccludedContentRect(parent.get(), IntRect(29, 29, 70, 70)));
     258    EXPECT_EQ_RECT(IntRect(30, 29, 70, 1), occlusion.unoccludedContentRect(parent.get(), IntRect(30, 29, 70, 70)));
     259    EXPECT_EQ_RECT(IntRect(31, 29, 70, 70), occlusion.unoccludedContentRect(parent.get(), IntRect(31, 29, 70, 70)));
     260    EXPECT_EQ_RECT(IntRect(100, 30, 1, 70), occlusion.unoccludedContentRect(parent.get(), IntRect(31, 30, 70, 70)));
     261    EXPECT_EQ_RECT(IntRect(31, 31, 70, 70), occlusion.unoccludedContentRect(parent.get(), IntRect(31, 31, 70, 70)));
     262    EXPECT_EQ_RECT(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent.get(), IntRect(30, 31, 70, 70)));
     263    EXPECT_EQ_RECT(IntRect(29, 31, 70, 70), occlusion.unoccludedContentRect(parent.get(), IntRect(29, 31, 70, 70)));
     264}
     265
     266TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_layerAddedToOccludedRegionWithRotation, layerAddedToOccludedRegionWithRotation);
     267
     268void layerAddedToOccludedRegionWithTranslation(bool opaqueLayers)
     269{
     270    // This tests that the right transforms are being used.
     271    const TransformationMatrix identityMatrix;
     272    RefPtr<LayerChromium> parent = LayerChromium::create();
     273    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     274    parent->createRenderSurface();
     275    parent->addChild(layer);
     276
     277    TransformationMatrix layerTransform;
     278    layerTransform.translate(20, 20);
     279
     280    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
     281    setLayerPropertiesForTesting(layer.get(), layerTransform, FloatPoint(30, 30), IntSize(500, 500), true, opaqueLayers);
     282
     283    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     284    Vector<RefPtr<LayerChromium> > dummyLayerList;
     285    int dummyMaxTextureSize = 512;
     286
     287    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     288    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     289    renderSurfaceLayerList.append(parent);
     290
     291    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     292
     293    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     294    occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
     295
     296    occlusion.enterTargetRenderSurface(parent->renderSurface());
     297    occlusion.markOccludedBehindLayer(layer.get());
     298    EXPECT_EQ_RECT(IntRect(50, 50, 50, 50), occlusion.occlusionInScreenSpace().bounds());
     299    EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
     300    EXPECT_EQ_RECT(IntRect(50, 50, 50, 50), occlusion.occlusionInTargetSurface().bounds());
     301    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     302
     303    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(50, 50, 50, 50)));
     304    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(49, 50, 50, 50)));
     305    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(50, 49, 50, 50)));
     306    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(51, 50, 50, 50)));
     307    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(50, 51, 50, 50)));
     308
     309    occlusion.useDefaultLayerScissorRect();
     310    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(50, 50, 50, 50)));
     311    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(49, 50, 50, 50)));
     312    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(50, 49, 50, 50)));
     313    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(51, 50, 50, 50)));
     314    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(50, 51, 50, 50)));
     315    occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
     316
     317    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(50, 50, 50, 50)).isEmpty());
     318    EXPECT_EQ_RECT(IntRect(49, 50, 1, 50), occlusion.unoccludedContentRect(parent.get(), IntRect(49, 50, 50, 50)));
     319    EXPECT_EQ_RECT(IntRect(49, 49, 50, 50), occlusion.unoccludedContentRect(parent.get(), IntRect(49, 49, 50, 50)));
     320    EXPECT_EQ_RECT(IntRect(50, 49, 50, 1), occlusion.unoccludedContentRect(parent.get(), IntRect(50, 49, 50, 50)));
     321    EXPECT_EQ_RECT(IntRect(51, 49, 50, 50), occlusion.unoccludedContentRect(parent.get(), IntRect(51, 49, 50, 50)));
     322    EXPECT_EQ_RECT(IntRect(100, 50, 1, 50), occlusion.unoccludedContentRect(parent.get(), IntRect(51, 50, 50, 50)));
     323    EXPECT_EQ_RECT(IntRect(51, 51, 50, 50), occlusion.unoccludedContentRect(parent.get(), IntRect(51, 51, 50, 50)));
     324    EXPECT_EQ_RECT(IntRect(50, 100, 50, 1), occlusion.unoccludedContentRect(parent.get(), IntRect(50, 51, 50, 50)));
     325    EXPECT_EQ_RECT(IntRect(49, 51, 50, 50), occlusion.unoccludedContentRect(parent.get(), IntRect(49, 51, 50, 50)));
     326
     327    occlusion.useDefaultLayerScissorRect();
     328    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(50, 50, 50, 50)).isEmpty());
     329    EXPECT_EQ_RECT(IntRect(49, 50, 1, 50), occlusion.unoccludedContentRect(parent.get(), IntRect(49, 50, 50, 50)));
     330    EXPECT_EQ_RECT(IntRect(49, 49, 50, 50), occlusion.unoccludedContentRect(parent.get(), IntRect(49, 49, 50, 50)));
     331    EXPECT_EQ_RECT(IntRect(50, 49, 50, 1), occlusion.unoccludedContentRect(parent.get(), IntRect(50, 49, 50, 50)));
     332    EXPECT_EQ_RECT(IntRect(51, 49, 49, 1), occlusion.unoccludedContentRect(parent.get(), IntRect(51, 49, 50, 50)));
     333    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(51, 50, 50, 50)).isEmpty());
     334    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(51, 51, 50, 50)).isEmpty());
     335    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(50, 51, 50, 50)).isEmpty());
     336    EXPECT_EQ_RECT(IntRect(49, 51, 1, 49), occlusion.unoccludedContentRect(parent.get(), IntRect(49, 51, 50, 50)));
     337    occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
     338}
     339
     340TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_layerAddedToOccludedRegionWithTranslation, layerAddedToOccludedRegionWithTranslation);
     341
     342void layerAddedToOccludedRegionWithRotatedSurface(bool opaqueLayers)
     343{
     344    // This tests that the right transforms are being used.
     345    const TransformationMatrix identityMatrix;
     346    RefPtr<LayerChromium> parent = LayerChromium::create();
     347    RefPtr<LayerChromium> child = LayerChromium::create();
     348    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     349    parent->createRenderSurface();
     350    parent->addChild(child);
     351    child->addChild(layer);
     352
     353    TransformationMatrix childTransform;
     354    childTransform.translate(250, 250);
     355    childTransform.rotate(90);
     356    childTransform.translate(-250, -250);
     357
     358    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
     359    setLayerPropertiesForTesting(child.get(), childTransform, FloatPoint(30, 30), IntSize(500, 500));
     360    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(10, 10), IntSize(500, 500), true, opaqueLayers);
     361
     362    child->setMasksToBounds(true);
     363
     364    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     365    Vector<RefPtr<LayerChromium> > dummyLayerList;
     366    int dummyMaxTextureSize = 512;
     367
     368    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     369    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     370    renderSurfaceLayerList.append(parent);
     371
     372    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     373
     374    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     375    occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
     376
     377    occlusion.enterTargetRenderSurface(child->renderSurface());
     378    occlusion.markOccludedBehindLayer(layer.get());
     379
     380    EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
     381    EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
     382    EXPECT_EQ_RECT(IntRect(10, 430, 60, 70), occlusion.occlusionInTargetSurface().bounds());
     383    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     384
     385    EXPECT_TRUE(occlusion.occluded(child.get(), IntRect(10, 430, 60, 70)));
     386    EXPECT_FALSE(occlusion.occluded(child.get(), IntRect(9, 430, 60, 70)));
     387    EXPECT_FALSE(occlusion.occluded(child.get(), IntRect(10, 429, 60, 70)));
     388    EXPECT_FALSE(occlusion.occluded(child.get(), IntRect(10, 430, 61, 70)));
     389    EXPECT_FALSE(occlusion.occluded(child.get(), IntRect(10, 430, 60, 71)));
     390
     391    occlusion.useDefaultLayerScissorRect();
     392    EXPECT_TRUE(occlusion.occluded(child.get(), IntRect(10, 430, 60, 70)));
     393    EXPECT_TRUE(occlusion.occluded(child.get(), IntRect(9, 430, 60, 70)));
     394    EXPECT_TRUE(occlusion.occluded(child.get(), IntRect(10, 429, 60, 70)));
     395    EXPECT_TRUE(occlusion.occluded(child.get(), IntRect(10, 430, 61, 70)));
     396    EXPECT_TRUE(occlusion.occluded(child.get(), IntRect(10, 430, 60, 71)));
     397    occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
     398
     399    occlusion.markOccludedBehindLayer(child.get());
     400    occlusion.finishedTargetRenderSurface(child.get(), child->renderSurface());
     401    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     402
     403    EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
     404    EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
     405    EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInTargetSurface().bounds());
     406    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     407
     408    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(30, 40, 70, 60)));
     409    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(29, 40, 70, 60)));
     410    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(30, 39, 70, 60)));
     411    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(31, 40, 70, 60)));
     412    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(30, 41, 70, 60)));
     413
     414    occlusion.useDefaultLayerScissorRect();
     415    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(30, 40, 70, 60)));
     416    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(29, 40, 70, 60)));
     417    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(30, 39, 70, 60)));
     418    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(31, 40, 70, 60)));
     419    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(30, 41, 70, 60)));
     420    occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
     421
     422
     423    /* Justification for the above occlusion from |layer|:
     424               100
     425      +---------------------+                                      +---------------------+
     426      |                     |                                      |                     |30  Visible region of |layer|: /////
     427      |    30               |           rotate(90)                 |                     |
     428      | 30 + ---------------------------------+                    |     +---------------------------------+
     429  100 |    |  10            |                 |            ==>     |     |               |10               |
     430      |    |10+---------------------------------+                  |  +---------------------------------+  |
     431      |    |  |             |                 | |                  |  |  |///////////////|     420      |  |
     432      |    |  |             |                 | |                  |  |  |///////////////|60            |  |
     433      |    |  |             |                 | |                  |  |  |///////////////|              |  |
     434      +----|--|-------------+                 | |                  +--|--|---------------+              |  |
     435           |  |                               | |                   20|10|     70                       |  |
     436           |  |                               | |                     |  |                              |  |
     437           |  |                               | |500                  |  |                              |  |
     438           |  |                               | |                     |  |                              |  |
     439           |  |                               | |                     |  |                              |  |
     440           |  |                               | |                     |  |                              |  |
     441           |  |                               | |                     |  |                              |10|
     442           +--|-------------------------------+ |                     |  +------------------------------|--+
     443              |                                 |                     |                 490             |
     444              +---------------------------------+                     +---------------------------------+
     445                             500                                                     500
     446     */
     447}
     448
     449TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_layerAddedToOccludedRegionWithRotatedSurface, layerAddedToOccludedRegionWithRotatedSurface);
     450
     451void layerAddedToOccludedRegionWithSurfaceAlreadyOnStack(bool opaqueLayers)
     452{
     453    // This tests that the right transforms are being used.
     454    const TransformationMatrix identityMatrix;
     455    RefPtr<LayerChromium> parent = LayerChromium::create();
     456    RefPtr<LayerChromium> child = LayerChromium::create();
     457    RefPtr<LayerChromiumWithForcedDrawsContent> child2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
     458    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     459    parent->createRenderSurface();
     460    parent->addChild(child);
     461    child->addChild(layer);
     462    parent->addChild(child2);
     463
     464    TransformationMatrix childTransform;
     465    childTransform.translate(250, 250);
     466    childTransform.rotate(90);
     467    childTransform.translate(-250, -250);
     468
     469    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
     470    setLayerPropertiesForTesting(child.get(), childTransform, FloatPoint(30, 30), IntSize(500, 500));
     471    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(10, 10), IntSize(500, 500), true, opaqueLayers);
     472
     473    // |child2| makes |parent|'s surface get considered by CCOcclusionTracker first, instead of |child|'s. This exercises different code in
     474    // leaveToTargetRenderSurface, as the target surface has already been seen.
     475    setLayerPropertiesForTesting(child2.get(), identityMatrix, FloatPoint(30, 30), IntSize(60, 20), true, opaqueLayers);
     476
     477    child->setMasksToBounds(true);
     478
     479    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     480    Vector<RefPtr<LayerChromium> > dummyLayerList;
     481    int dummyMaxTextureSize = 512;
     482
     483    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     484    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     485    renderSurfaceLayerList.append(parent);
     486
     487    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     488
     489    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     490    occlusion.setLayerScissorRect(IntRect(-10, -10, 1000, 1000));
     491
     492    occlusion.enterTargetRenderSurface(parent->renderSurface());
     493    occlusion.markOccludedBehindLayer(child2.get());
     494
     495    EXPECT_EQ_RECT(IntRect(30, 30, 60, 20), occlusion.occlusionInScreenSpace().bounds());
     496    EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
     497    EXPECT_EQ_RECT(IntRect(30, 30, 60, 20), occlusion.occlusionInTargetSurface().bounds());
     498    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     499
     500    occlusion.enterTargetRenderSurface(child->renderSurface());
     501    occlusion.markOccludedBehindLayer(layer.get());
     502
     503    EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
     504    EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
     505    EXPECT_EQ_RECT(IntRect(10, 430, 60, 70), occlusion.occlusionInTargetSurface().bounds());
     506    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     507
     508    EXPECT_TRUE(occlusion.occluded(child.get(), IntRect(10, 430, 60, 70)));
     509    EXPECT_FALSE(occlusion.occluded(child.get(), IntRect(9, 430, 60, 70)));
     510    EXPECT_FALSE(occlusion.occluded(child.get(), IntRect(10, 429, 60, 70)));
     511    EXPECT_FALSE(occlusion.occluded(child.get(), IntRect(11, 430, 60, 70)));
     512    EXPECT_FALSE(occlusion.occluded(child.get(), IntRect(10, 431, 60, 70)));
     513
     514    occlusion.useDefaultLayerScissorRect();
     515    EXPECT_TRUE(occlusion.occluded(child.get(), IntRect(10, 430, 60, 70)));
     516    EXPECT_TRUE(occlusion.occluded(child.get(), IntRect(9, 430, 60, 70)));
     517    EXPECT_TRUE(occlusion.occluded(child.get(), IntRect(10, 429, 60, 70)));
     518    EXPECT_TRUE(occlusion.occluded(child.get(), IntRect(11, 430, 60, 70)));
     519    EXPECT_TRUE(occlusion.occluded(child.get(), IntRect(10, 431, 60, 70)));
     520    occlusion.setLayerScissorRect(IntRect(-10, -10, 1000, 1000));
     521
     522    EXPECT_TRUE(occlusion.unoccludedContentRect(child.get(), IntRect(10, 430, 60, 70)).isEmpty());
     523    // This is the little piece not occluded by child2
     524    EXPECT_EQ_RECT(IntRect(9, 430, 1, 10), occlusion.unoccludedContentRect(child.get(), IntRect(9, 430, 60, 70)));
     525    // This extends past both sides of child2, so it will be the original rect.
     526    EXPECT_EQ_RECT(IntRect(9, 430, 60, 80), occlusion.unoccludedContentRect(child.get(), IntRect(9, 430, 60, 80)));
     527    // This extends past two adjacent sides of child2, and should included the unoccluded parts of each side.
     528    // This also demonstrates that the rect can be arbitrary and does not get clipped to the layer's visibleLayerRect().
     529    EXPECT_EQ_RECT(IntRect(-10, 430, 20, 70), occlusion.unoccludedContentRect(child.get(), IntRect(-10, 430, 60, 70)));
     530    // This extends past three adjacent sides of child2, so it should contain the unoccluded parts of each side. The left
     531    // and bottom edges are completely unoccluded for some row/column so we get back the original query rect.
     532    EXPECT_EQ_RECT(IntRect(-10, 430, 60, 80), occlusion.unoccludedContentRect(child.get(), IntRect(-10, 430, 60, 80)));
     533    EXPECT_EQ_RECT(IntRect(10, 429, 60, 1), occlusion.unoccludedContentRect(child.get(), IntRect(10, 429, 60, 70)));
     534    EXPECT_EQ_RECT(IntRect(70, 430, 1, 70), occlusion.unoccludedContentRect(child.get(), IntRect(11, 430, 60, 70)));
     535    EXPECT_EQ_RECT(IntRect(10, 500, 60, 1), occlusion.unoccludedContentRect(child.get(), IntRect(10, 431, 60, 70)));
     536
     537    occlusion.useDefaultLayerScissorRect();
     538    EXPECT_TRUE(occlusion.unoccludedContentRect(child.get(), IntRect(10, 430, 60, 70)).isEmpty());
     539    EXPECT_TRUE(occlusion.unoccludedContentRect(child.get(), IntRect(9, 430, 60, 70)).isEmpty());
     540    EXPECT_TRUE(occlusion.unoccludedContentRect(child.get(), IntRect(9, 430, 60, 80)).isEmpty());
     541    EXPECT_TRUE(occlusion.unoccludedContentRect(child.get(), IntRect(-10, 430, 60, 70)).isEmpty());
     542    EXPECT_TRUE(occlusion.unoccludedContentRect(child.get(), IntRect(-10, 430, 60, 80)).isEmpty());
     543    EXPECT_TRUE(occlusion.unoccludedContentRect(child.get(), IntRect(10, 429, 60, 70)).isEmpty());
     544    EXPECT_TRUE(occlusion.unoccludedContentRect(child.get(), IntRect(11, 430, 60, 70)).isEmpty());
     545    EXPECT_TRUE(occlusion.unoccludedContentRect(child.get(), IntRect(10, 431, 60, 70)).isEmpty());
     546    occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
     547
     548    occlusion.markOccludedBehindLayer(child.get());
     549    // |child2| should get merged with the surface we are leaving now
     550    occlusion.finishedTargetRenderSurface(child.get(), child->renderSurface());
     551    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     552
     553    EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
     554    EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
     555    EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
     556    EXPECT_EQ(2u, occlusion.occlusionInTargetSurface().rects().size());
     557
     558    Vector<IntRect> screen = occlusion.occlusionInScreenSpace().rects();
     559    Vector<IntRect> target = occlusion.occlusionInTargetSurface().rects();
     560
     561    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(30, 30, 70, 70)));
     562    EXPECT_EQ_RECT(IntRect(90, 30, 10, 10), occlusion.unoccludedContentRect(parent.get(), IntRect(30, 30, 70, 70)));
     563
     564    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(30, 30, 60, 10)));
     565    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(29, 30, 60, 10)));
     566    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(30, 29, 60, 10)));
     567    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(31, 30, 60, 10)));
     568    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(30, 31, 60, 10)));
     569
     570    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(30, 40, 70, 60)));
     571    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(29, 40, 70, 60)));
     572    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(30, 39, 70, 60)));
     573
     574    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(30, 30, 60, 10)).isEmpty());
     575    EXPECT_EQ_RECT(IntRect(29, 30, 1, 10), occlusion.unoccludedContentRect(parent.get(), IntRect(29, 30, 60, 10)));
     576    EXPECT_EQ_RECT(IntRect(30, 29, 60, 1), occlusion.unoccludedContentRect(parent.get(), IntRect(30, 29, 60, 10)));
     577    EXPECT_EQ_RECT(IntRect(90, 30, 1, 10), occlusion.unoccludedContentRect(parent.get(), IntRect(31, 30, 60, 10)));
     578    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(30, 31, 60, 10)).isEmpty());
     579
     580    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(30, 40, 70, 60)).isEmpty());
     581    EXPECT_EQ_RECT(IntRect(29, 40, 1, 60), occlusion.unoccludedContentRect(parent.get(), IntRect(29, 40, 70, 60)));
     582    // This rect is mostly occluded by |child2|.
     583    EXPECT_EQ_RECT(IntRect(90, 39, 10, 1), occlusion.unoccludedContentRect(parent.get(), IntRect(30, 39, 70, 60)));
     584    // This rect extends past top/right ends of |child2|.
     585    EXPECT_EQ_RECT(IntRect(30, 29, 70, 11), occlusion.unoccludedContentRect(parent.get(), IntRect(30, 29, 70, 70)));
     586    // This rect extends past left/right ends of |child2|.
     587    EXPECT_EQ_RECT(IntRect(20, 39, 80, 60), occlusion.unoccludedContentRect(parent.get(), IntRect(20, 39, 80, 60)));
     588    EXPECT_EQ_RECT(IntRect(100, 40, 1, 60), occlusion.unoccludedContentRect(parent.get(), IntRect(31, 40, 70, 60)));
     589    EXPECT_EQ_RECT(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent.get(), IntRect(30, 41, 70, 60)));
     590
     591    /* Justification for the above occlusion from |layer|:
     592               100
     593      +---------------------+                                      +---------------------+
     594      |                     |                                      |                     |30  Visible region of |layer|: /////
     595      |    30               |           rotate(90)                 |     30   60         |    |child2|: \\\\\
     596      | 30 + ------------+--------------------+                    |  30 +------------+--------------------+
     597  100 |    |  10         |  |                 |            ==>     |     |\\\\\\\\\\\\|  |10               |
     598      |    |10+----------|----------------------+                  |  +--|\\\\\\\\\\\\|-----------------+  |
     599      |    + ------------+  |                 | |                  |  |  +------------+//|     420      |  |
     600      |    |  |             |                 | |                  |  |  |///////////////|60            |  |
     601      |    |  |             |                 | |                  |  |  |///////////////|              |  |
     602      +----|--|-------------+                 | |                  +--|--|---------------+              |  |
     603           |  |                               | |                   20|10|     70                       |  |
     604           |  |                               | |                     |  |                              |  |
     605           |  |                               | |500                  |  |                              |  |
     606           |  |                               | |                     |  |                              |  |
     607           |  |                               | |                     |  |                              |  |
     608           |  |                               | |                     |  |                              |  |
     609           |  |                               | |                     |  |                              |10|
     610           +--|-------------------------------+ |                     |  +------------------------------|--+
     611              |                                 |                     |                 490             |
     612              +---------------------------------+                     +---------------------------------+
     613                             500                                                     500
     614     */
     615}
     616
     617TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_layerAddedToOccludedRegionWithSurfaceAlreadyOnStack, layerAddedToOccludedRegionWithSurfaceAlreadyOnStack);
     618
     619void layerAddedToOccludedRegionWithRotatedOffAxisSurface(bool opaqueLayers)
     620{
     621    const TransformationMatrix identityMatrix;
     622    RefPtr<LayerChromium> parent = LayerChromium::create();
     623    RefPtr<LayerChromium> child = LayerChromium::create();
     624    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     625    parent->createRenderSurface();
     626    parent->addChild(child);
     627    child->addChild(layer);
     628
     629    // Now rotate the child a little more so it is not axis-aligned. The parent will no longer be occluded by |layer|, but
     630    // the child's occlusion should be unchanged.
     631
     632    TransformationMatrix childTransform;
     633    childTransform.translate(250, 250);
     634    childTransform.rotate(95);
     635    childTransform.translate(-250, -250);
     636
     637    TransformationMatrix layerTransform;
     638    layerTransform.translate(10, 10);
     639
     640    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
     641    setLayerPropertiesForTesting(child.get(), childTransform, FloatPoint(30, 30), IntSize(500, 500));
     642    setLayerPropertiesForTesting(layer.get(), layerTransform, FloatPoint(0, 0), IntSize(500, 500), true, opaqueLayers);
     643
     644    child->setMasksToBounds(true);
     645
     646    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     647    Vector<RefPtr<LayerChromium> > dummyLayerList;
     648    int dummyMaxTextureSize = 512;
     649
     650    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     651    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     652    renderSurfaceLayerList.append(parent);
     653
     654    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     655
     656    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     657    occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
     658
     659    IntRect clippedLayerInChild = layerTransform.mapRect(layer->visibleLayerRect());
     660
     661    occlusion.enterTargetRenderSurface(child->renderSurface());
     662    occlusion.markOccludedBehindLayer(layer.get());
     663
     664    EXPECT_EQ_RECT(IntRect(), occlusion.occlusionInScreenSpace().bounds());
     665    EXPECT_EQ(0u, occlusion.occlusionInScreenSpace().rects().size());
     666    EXPECT_EQ_RECT(clippedLayerInChild, occlusion.occlusionInTargetSurface().bounds());
     667    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     668
     669    EXPECT_TRUE(occlusion.occluded(child.get(), clippedLayerInChild));
     670    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), clippedLayerInChild).isEmpty());
     671    clippedLayerInChild.move(-1, 0);
     672    EXPECT_FALSE(occlusion.occluded(child.get(), clippedLayerInChild));
     673    EXPECT_FALSE(occlusion.unoccludedContentRect(parent.get(), clippedLayerInChild).isEmpty());
     674    clippedLayerInChild.move(1, 0);
     675    clippedLayerInChild.move(1, 0);
     676    EXPECT_FALSE(occlusion.occluded(child.get(), clippedLayerInChild));
     677    EXPECT_FALSE(occlusion.unoccludedContentRect(parent.get(), clippedLayerInChild).isEmpty());
     678    clippedLayerInChild.move(-1, 0);
     679    clippedLayerInChild.move(0, -1);
     680    EXPECT_FALSE(occlusion.occluded(child.get(), clippedLayerInChild));
     681    EXPECT_FALSE(occlusion.unoccludedContentRect(parent.get(), clippedLayerInChild).isEmpty());
     682    clippedLayerInChild.move(0, 1);
     683    clippedLayerInChild.move(0, 1);
     684    EXPECT_FALSE(occlusion.occluded(child.get(), clippedLayerInChild));
     685    EXPECT_FALSE(occlusion.unoccludedContentRect(parent.get(), clippedLayerInChild).isEmpty());
     686    clippedLayerInChild.move(0, -1);
     687
     688    occlusion.markOccludedBehindLayer(child.get());
     689    occlusion.finishedTargetRenderSurface(child.get(), child->renderSurface());
     690    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     691
     692    EXPECT_EQ_RECT(IntRect(), occlusion.occlusionInScreenSpace().bounds());
     693    EXPECT_EQ(0u, occlusion.occlusionInScreenSpace().rects().size());
     694    EXPECT_EQ_RECT(IntRect(), occlusion.occlusionInTargetSurface().bounds());
     695    EXPECT_EQ(0u, occlusion.occlusionInTargetSurface().rects().size());
     696
     697    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(75, 55, 1, 1)));
     698    EXPECT_EQ_RECT(IntRect(75, 55, 1, 1), occlusion.unoccludedContentRect(parent.get(), IntRect(75, 55, 1, 1)));
     699}
     700
     701TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_layerAddedToOccludedRegionWithRotatedOffAxisSurface, layerAddedToOccludedRegionWithRotatedOffAxisSurface);
     702
     703void layerAddedToOccludedRegionWithMultipleOpaqueLayers(bool opaqueLayers)
     704{
     705    // This is similar to the previous test but now we make a few opaque layers inside of |child| so that the occluded parts of child are not a simple rect.
     706    const TransformationMatrix identityMatrix;
     707    RefPtr<LayerChromium> parent = LayerChromium::create();
     708    RefPtr<LayerChromium> child = LayerChromium::create();
     709    RefPtr<LayerChromiumWithForcedDrawsContent> layer1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
     710    RefPtr<LayerChromiumWithForcedDrawsContent> layer2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
     711    parent->createRenderSurface();
     712    parent->addChild(child);
     713    child->addChild(layer1);
     714    child->addChild(layer2);
     715
     716    TransformationMatrix childTransform;
     717    childTransform.translate(250, 250);
     718    childTransform.rotate(90);
     719    childTransform.translate(-250, -250);
     720
     721    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
     722    setLayerPropertiesForTesting(child.get(), childTransform, FloatPoint(30, 30), IntSize(500, 500));
     723    setLayerPropertiesForTesting(layer1.get(), identityMatrix, FloatPoint(10, 10), IntSize(500, 440), true, opaqueLayers);
     724    setLayerPropertiesForTesting(layer2.get(), identityMatrix, FloatPoint(10, 450), IntSize(500, 60), true, opaqueLayers);
     725
     726    child->setMasksToBounds(true);
     727
     728    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     729    Vector<RefPtr<LayerChromium> > dummyLayerList;
     730    int dummyMaxTextureSize = 512;
     731
     732    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     733    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     734    renderSurfaceLayerList.append(parent);
     735
     736    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     737
     738    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     739    occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
     740
     741    occlusion.enterTargetRenderSurface(child->renderSurface());
     742    occlusion.markOccludedBehindLayer(layer2.get());
     743    occlusion.markOccludedBehindLayer(layer1.get());
     744
     745    EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
     746    EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
     747    EXPECT_EQ_RECT(IntRect(10, 430, 60, 70), occlusion.occlusionInTargetSurface().bounds());
     748    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     749
     750    EXPECT_TRUE(occlusion.occluded(child.get(), IntRect(10, 430, 60, 70)));
     751    EXPECT_FALSE(occlusion.occluded(child.get(), IntRect(9, 430, 60, 70)));
     752    EXPECT_FALSE(occlusion.occluded(child.get(), IntRect(10, 429, 60, 70)));
     753    EXPECT_FALSE(occlusion.occluded(child.get(), IntRect(11, 430, 60, 70)));
     754    EXPECT_FALSE(occlusion.occluded(child.get(), IntRect(10, 431, 60, 70)));
     755
     756    EXPECT_TRUE(occlusion.unoccludedContentRect(child.get(), IntRect(10, 430, 60, 70)).isEmpty());
     757    EXPECT_EQ_RECT(IntRect(9, 430, 1, 70), occlusion.unoccludedContentRect(child.get(), IntRect(9, 430, 60, 70)));
     758    EXPECT_EQ_RECT(IntRect(10, 429, 60, 1), occlusion.unoccludedContentRect(child.get(), IntRect(10, 429, 60, 70)));
     759    EXPECT_EQ_RECT(IntRect(70, 430, 1, 70), occlusion.unoccludedContentRect(child.get(), IntRect(11, 430, 60, 70)));
     760    EXPECT_EQ_RECT(IntRect(10, 500, 60, 1), occlusion.unoccludedContentRect(child.get(), IntRect(10, 431, 60, 70)));
     761
     762    occlusion.markOccludedBehindLayer(child.get());
     763    occlusion.finishedTargetRenderSurface(child.get(), child->renderSurface());
     764    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     765
     766    EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
     767    EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
     768    EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInTargetSurface().bounds());
     769    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     770
     771    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(30, 40, 70, 60)));
     772    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(29, 40, 70, 60)));
     773    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(30, 39, 70, 60)));
     774
     775    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(30, 40, 70, 60)).isEmpty());
     776    EXPECT_EQ_RECT(IntRect(29, 40, 1, 60), occlusion.unoccludedContentRect(parent.get(), IntRect(29, 40, 70, 60)));
     777    EXPECT_EQ_RECT(IntRect(30, 39, 70, 1), occlusion.unoccludedContentRect(parent.get(), IntRect(30, 39, 70, 60)));
     778    EXPECT_EQ_RECT(IntRect(100, 40, 1, 60), occlusion.unoccludedContentRect(parent.get(), IntRect(31, 40, 70, 60)));
     779    EXPECT_EQ_RECT(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent.get(), IntRect(30, 41, 70, 60)));
     780
     781    /* Justification for the above occlusion from |layer1| and |layer2|:
     782
     783       +---------------------+
     784       |                     |30  Visible region of |layer1|: /////
     785       |                     |    Visible region of |layer2|: \\\\\
     786       |     +---------------------------------+
     787       |     |               |10               |
     788       |  +---------------+-----------------+  |
     789       |  |  |\\\\\\\\\\\\|//|     420      |  |
     790       |  |  |\\\\\\\\\\\\|//|60            |  |
     791       |  |  |\\\\\\\\\\\\|//|              |  |
     792       +--|--|------------|--+              |  |
     793        20|10|     70     |                 |  |
     794          |  |            |                 |  |
     795          |  |            |                 |  |
     796          |  |            |                 |  |
     797          |  |            |                 |  |
     798          |  |            |                 |  |
     799          |  |            |                 |10|
     800          |  +------------|-----------------|--+
     801          |               | 490             |
     802          +---------------+-----------------+
     803                60               440
     804     */
     805}
     806
     807TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_layerAddedToOccludedRegionWithMultipleOpaqueLayers, layerAddedToOccludedRegionWithMultipleOpaqueLayers);
     808
     809void surfaceOcclusionWithOverlappingSiblingSurfaces(bool opaqueLayers)
     810{
     811    // This tests that the right transforms are being used.
     812    const TransformationMatrix identityMatrix;
     813    RefPtr<LayerChromium> parent = LayerChromium::create();
     814    RefPtr<LayerChromium> child1 = LayerChromium::create();
     815    RefPtr<LayerChromium> child2 = LayerChromium::create();
     816    RefPtr<LayerChromiumWithForcedDrawsContent> layer1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
     817    RefPtr<LayerChromiumWithForcedDrawsContent> layer2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
     818    parent->createRenderSurface();
     819    parent->addChild(child1);
     820    parent->addChild(child2);
     821    child1->addChild(layer1);
     822    child2->addChild(layer2);
     823
     824    TransformationMatrix childTransform;
     825    childTransform.translate(250, 250);
     826    childTransform.rotate(90);
     827    childTransform.translate(-250, -250);
     828
     829    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
     830    setLayerPropertiesForTesting(child1.get(), childTransform, FloatPoint(30, 30), IntSize(500, 500));
     831    setLayerPropertiesForTesting(layer1.get(), identityMatrix, FloatPoint(0, 0), IntSize(500, 500), true, opaqueLayers);
     832    setLayerPropertiesForTesting(child2.get(), childTransform, FloatPoint(20, 40), IntSize(500, 500));
     833    setLayerPropertiesForTesting(layer2.get(), identityMatrix, FloatPoint(0, 0), IntSize(500, 500), true, opaqueLayers);
     834
     835    child1->setMasksToBounds(true);
     836    child2->setMasksToBounds(true);
     837
     838    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     839    Vector<RefPtr<LayerChromium> > dummyLayerList;
     840    int dummyMaxTextureSize = 512;
     841
     842    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     843    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     844    renderSurfaceLayerList.append(parent);
     845
     846    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     847
     848    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     849    occlusion.setLayerScissorRect(IntRect(-10, -10, 1000, 1000));
     850
     851    occlusion.enterTargetRenderSurface(child2->renderSurface());
     852    occlusion.markOccludedBehindLayer(layer2.get());
     853
     854    EXPECT_EQ_RECT(IntRect(20, 40, 80, 60), occlusion.occlusionInScreenSpace().bounds());
     855    EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
     856    EXPECT_EQ_RECT(IntRect(0, 420, 60, 80), occlusion.occlusionInTargetSurface().bounds());
     857    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     858
     859    EXPECT_TRUE(occlusion.occluded(child2.get(), IntRect(0, 420, 60, 80)));
     860    EXPECT_FALSE(occlusion.occluded(child2.get(), IntRect(-1, 420, 60, 80)));
     861    EXPECT_FALSE(occlusion.occluded(child2.get(), IntRect(0, 419, 60, 80)));
     862    EXPECT_FALSE(occlusion.occluded(child2.get(), IntRect(0, 420, 61, 80)));
     863    EXPECT_FALSE(occlusion.occluded(child2.get(), IntRect(0, 420, 60, 81)));
     864
     865    occlusion.markOccludedBehindLayer(child2.get());
     866    occlusion.finishedTargetRenderSurface(child2.get(), child2->renderSurface());
     867    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     868    occlusion.enterTargetRenderSurface(child1->renderSurface());
     869    occlusion.markOccludedBehindLayer(layer1.get());
     870
     871    EXPECT_EQ_RECT(IntRect(20, 30, 80, 70), occlusion.occlusionInScreenSpace().bounds());
     872    EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
     873    EXPECT_EQ_RECT(IntRect(0, 430, 70, 70), occlusion.occlusionInTargetSurface().bounds());
     874    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     875
     876    EXPECT_TRUE(occlusion.occluded(child1.get(), IntRect(0, 430, 70, 70)));
     877    EXPECT_FALSE(occlusion.occluded(child1.get(), IntRect(-1, 430, 70, 70)));
     878    EXPECT_FALSE(occlusion.occluded(child1.get(), IntRect(0, 429, 70, 70)));
     879    EXPECT_FALSE(occlusion.occluded(child1.get(), IntRect(0, 430, 71, 70)));
     880    EXPECT_FALSE(occlusion.occluded(child1.get(), IntRect(0, 430, 70, 71)));
     881
     882    occlusion.markOccludedBehindLayer(child1.get());
     883    occlusion.finishedTargetRenderSurface(child1.get(), child1->renderSurface());
     884    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     885
     886    EXPECT_EQ_RECT(IntRect(20, 30, 80, 70), occlusion.occlusionInScreenSpace().bounds());
     887    EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
     888    EXPECT_EQ_RECT(IntRect(20, 30, 80, 70), occlusion.occlusionInTargetSurface().bounds());
     889    EXPECT_EQ(2u, occlusion.occlusionInTargetSurface().rects().size());
     890
     891    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(20, 30, 80, 70)));
     892
     893    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(30, 30, 70, 70)));
     894    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(29, 30, 70, 70)));
     895    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(30, 29, 70, 70)));
     896
     897    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(20, 40, 80, 60)));
     898    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(19, 40, 80, 60)));
     899    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(20, 39, 80, 60)));
     900
     901    /* Justification for the above occlusion:
     902               100
     903      +---------------------+
     904      |                     |
     905      |    30               |       child1
     906      |  30+ ---------------------------------+
     907  100 |  40|                |     child2      |
     908      |20+----------------------------------+ |
     909      |  | |                |               | |
     910      |  | |                |               | |
     911      |  | |                |               | |
     912      +--|-|----------------+               | |
     913         | |                                | | 500
     914         | |                                | |
     915         | |                                | |
     916         | |                                | |
     917         | |                                | |
     918         | |                                | |
     919         | |                                | |
     920         | +--------------------------------|-+
     921         |                                  |
     922         +----------------------------------+
     923                         500
     924     */
     925}
     926
     927TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_surfaceOcclusionWithOverlappingSiblingSurfaces, surfaceOcclusionWithOverlappingSiblingSurfaces);
     928
     929void surfaceOcclusionInScreenSpace(bool opaqueLayers)
     930{
     931    // This tests that the right transforms are being used.
     932    const TransformationMatrix identityMatrix;
     933    RefPtr<LayerChromium> parent = LayerChromium::create();
     934    RefPtr<LayerChromium> child1 = LayerChromium::create();
     935    RefPtr<LayerChromium> child2 = LayerChromium::create();
     936    RefPtr<LayerChromiumWithForcedDrawsContent> layer1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
     937    RefPtr<LayerChromiumWithForcedDrawsContent> layer2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
     938    parent->createRenderSurface();
     939    parent->addChild(child1);
     940    parent->addChild(child2);
     941    child1->addChild(layer1);
     942    child2->addChild(layer2);
     943
     944    TransformationMatrix childTransform;
     945    childTransform.translate(250, 250);
     946    childTransform.rotate(90);
     947    childTransform.translate(-250, -250);
     948
     949    // The owning layers have very different bounds from the surfaces that they own.
     950    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
     951    setLayerPropertiesForTesting(child1.get(), childTransform, FloatPoint(30, 30), IntSize(10, 10));
     952    setLayerPropertiesForTesting(layer1.get(), identityMatrix, FloatPoint(-10, -10), IntSize(510, 510), true, opaqueLayers);
     953    setLayerPropertiesForTesting(child2.get(), childTransform, FloatPoint(20, 40), IntSize(10, 10));
     954    setLayerPropertiesForTesting(layer2.get(), identityMatrix, FloatPoint(-10, -10), IntSize(510, 510), true, opaqueLayers);
     955
     956    // Make them both render surfaces
     957    FilterOperations filters;
     958    filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
     959    child1->setFilters(filters);
     960    child2->setFilters(filters);
     961
     962    child1->setMasksToBounds(false);
     963    child2->setMasksToBounds(false);
     964
     965    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     966    Vector<RefPtr<LayerChromium> > dummyLayerList;
     967    int dummyMaxTextureSize = 512;
     968
     969    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     970    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     971    renderSurfaceLayerList.append(parent);
     972
     973    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     974
     975    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     976    occlusion.setLayerScissorRect(IntRect(-20, -20, 1000, 1000));
     977
     978    occlusion.enterTargetRenderSurface(child2->renderSurface());
     979    occlusion.markOccludedBehindLayer(layer2.get());
     980
     981    EXPECT_EQ_RECT(IntRect(20, 30, 80, 70), occlusion.occlusionInScreenSpace().bounds());
     982    EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
     983    EXPECT_EQ_RECT(IntRect(-10, 420, 70, 80), occlusion.occlusionInTargetSurface().bounds());
     984    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     985
     986    EXPECT_TRUE(occlusion.occluded(child2.get(), IntRect(-10, 420, 70, 80)));
     987    EXPECT_FALSE(occlusion.occluded(child2.get(), IntRect(-11, 420, 70, 80)));
     988    EXPECT_FALSE(occlusion.occluded(child2.get(), IntRect(-10, 419, 70, 80)));
     989    EXPECT_FALSE(occlusion.occluded(child2.get(), IntRect(-10, 420, 71, 80)));
     990    EXPECT_FALSE(occlusion.occluded(child2.get(), IntRect(-10, 420, 70, 81)));
     991
     992    occlusion.useDefaultLayerScissorRect();
     993    EXPECT_TRUE(occlusion.occluded(child2.get(), IntRect(-10, 420, 70, 80)));
     994    EXPECT_TRUE(occlusion.occluded(child2.get(), IntRect(-11, 420, 70, 80)));
     995    EXPECT_TRUE(occlusion.occluded(child2.get(), IntRect(-10, 419, 70, 80)));
     996    EXPECT_TRUE(occlusion.occluded(child2.get(), IntRect(-10, 420, 71, 80)));
     997    EXPECT_TRUE(occlusion.occluded(child2.get(), IntRect(-10, 420, 70, 81)));
     998    occlusion.setLayerScissorRect(IntRect(-20, -20, 1000, 1000));
     999
     1000    occlusion.markOccludedBehindLayer(child2.get());
     1001    occlusion.finishedTargetRenderSurface(child2.get(), child2->renderSurface());
     1002    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1003    occlusion.enterTargetRenderSurface(child1->renderSurface());
     1004    occlusion.markOccludedBehindLayer(layer1.get());
     1005
     1006    EXPECT_EQ_RECT(IntRect(20, 20, 80, 80), occlusion.occlusionInScreenSpace().bounds());
     1007    EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
     1008    EXPECT_EQ_RECT(IntRect(-10, 430, 80, 70), occlusion.occlusionInTargetSurface().bounds());
     1009    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     1010
     1011    EXPECT_TRUE(occlusion.occluded(child1.get(), IntRect(-10, 430, 80, 70)));
     1012    EXPECT_FALSE(occlusion.occluded(child1.get(), IntRect(-11, 430, 80, 70)));
     1013    EXPECT_FALSE(occlusion.occluded(child1.get(), IntRect(-10, 429, 80, 70)));
     1014    EXPECT_FALSE(occlusion.occluded(child1.get(), IntRect(-10, 430, 81, 70)));
     1015    EXPECT_FALSE(occlusion.occluded(child1.get(), IntRect(-10, 430, 80, 71)));
     1016
     1017    occlusion.markOccludedBehindLayer(child1.get());
     1018    occlusion.finishedTargetRenderSurface(child1.get(), child1->renderSurface());
     1019    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1020
     1021    EXPECT_EQ_RECT(IntRect(20, 20, 80, 80), occlusion.occlusionInScreenSpace().bounds());
     1022    EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
     1023    EXPECT_EQ_RECT(IntRect(20, 20, 80, 80), occlusion.occlusionInTargetSurface().bounds());
     1024    EXPECT_EQ(2u, occlusion.occlusionInTargetSurface().rects().size());
     1025
     1026    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(20, 20, 80, 80)));
     1027
     1028    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(30, 20, 70, 80)));
     1029    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(29, 20, 70, 80)));
     1030    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(30, 19, 70, 80)));
     1031
     1032    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(20, 30, 80, 70)));
     1033    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(19, 30, 80, 70)));
     1034    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(20, 29, 80, 70)));
     1035
     1036    /* Justification for the above occlusion:
     1037               100
     1038      +---------------------+
     1039      |    20               |       layer1
     1040      |  30+ ---------------------------------+
     1041  100 |  30|                |     layer2      |
     1042      |20+----------------------------------+ |
     1043      |  | |                |               | |
     1044      |  | |                |               | |
     1045      |  | |                |               | |
     1046      +--|-|----------------+               | |
     1047         | |                                | | 510
     1048         | |                                | |
     1049         | |                                | |
     1050         | |                                | |
     1051         | |                                | |
     1052         | |                                | |
     1053         | |                                | |
     1054         | +--------------------------------|-+
     1055         |                                  |
     1056         +----------------------------------+
     1057                         510
     1058     */
     1059}
     1060
     1061TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_surfaceOcclusionInScreenSpace, surfaceOcclusionInScreenSpace);
     1062
     1063void surfaceOcclusionInScreenSpaceDifferentTransforms(bool opaqueLayers)
     1064{
     1065    // This tests that the right transforms are being used.
     1066    const TransformationMatrix identityMatrix;
     1067    RefPtr<LayerChromium> parent = LayerChromium::create();
     1068    RefPtr<LayerChromium> child1 = LayerChromium::create();
     1069    RefPtr<LayerChromium> child2 = LayerChromium::create();
     1070    RefPtr<LayerChromiumWithForcedDrawsContent> layer1 = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1071    RefPtr<LayerChromiumWithForcedDrawsContent> layer2 = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1072    parent->createRenderSurface();
     1073    parent->addChild(child1);
     1074    parent->addChild(child2);
     1075    child1->addChild(layer1);
     1076    child2->addChild(layer2);
     1077
     1078    TransformationMatrix child1Transform;
     1079    child1Transform.translate(250, 250);
     1080    child1Transform.rotate(-90);
     1081    child1Transform.translate(-250, -250);
     1082
     1083    TransformationMatrix child2Transform;
     1084    child2Transform.translate(250, 250);
     1085    child2Transform.rotate(90);
     1086    child2Transform.translate(-250, -250);
     1087
     1088    // The owning layers have very different bounds from the surfaces that they own.
     1089    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
     1090    setLayerPropertiesForTesting(child1.get(), child1Transform, FloatPoint(30, 20), IntSize(10, 10));
     1091    setLayerPropertiesForTesting(layer1.get(), identityMatrix, FloatPoint(-10, -20), IntSize(510, 520), true, opaqueLayers);
     1092    setLayerPropertiesForTesting(child2.get(), child2Transform, FloatPoint(20, 40), IntSize(10, 10));
     1093    setLayerPropertiesForTesting(layer2.get(), identityMatrix, FloatPoint(-10, -10), IntSize(510, 510), true, opaqueLayers);
     1094
     1095    // Make them both render surfaces
     1096    FilterOperations filters;
     1097    filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
     1098    child1->setFilters(filters);
     1099    child2->setFilters(filters);
     1100
     1101    child1->setMasksToBounds(false);
     1102    child2->setMasksToBounds(false);
     1103
     1104    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     1105    Vector<RefPtr<LayerChromium> > dummyLayerList;
     1106    int dummyMaxTextureSize = 512;
     1107
     1108    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     1109    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     1110    renderSurfaceLayerList.append(parent);
     1111
     1112    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     1113
     1114    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     1115    occlusion.setLayerScissorRect(IntRect(-30, -30, 1000, 1000));
     1116
     1117    occlusion.enterTargetRenderSurface(child2->renderSurface());
     1118    occlusion.markOccludedBehindLayer(layer2.get());
     1119
     1120    EXPECT_EQ_RECT(IntRect(20, 30, 80, 70), occlusion.occlusionInScreenSpace().bounds());
     1121    EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
     1122    EXPECT_EQ_RECT(IntRect(-10, 420, 70, 80), occlusion.occlusionInTargetSurface().bounds());
     1123    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     1124
     1125    EXPECT_TRUE(occlusion.occluded(child2.get(), IntRect(-10, 420, 70, 80)));
     1126    EXPECT_FALSE(occlusion.occluded(child2.get(), IntRect(-11, 420, 70, 80)));
     1127    EXPECT_FALSE(occlusion.occluded(child2.get(), IntRect(-10, 419, 70, 80)));
     1128    EXPECT_FALSE(occlusion.occluded(child2.get(), IntRect(-10, 420, 71, 80)));
     1129    EXPECT_FALSE(occlusion.occluded(child2.get(), IntRect(-10, 420, 70, 81)));
     1130
     1131    occlusion.markOccludedBehindLayer(child2.get());
     1132    occlusion.finishedTargetRenderSurface(child2.get(), child2->renderSurface());
     1133    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1134    occlusion.enterTargetRenderSurface(child1->renderSurface());
     1135    occlusion.markOccludedBehindLayer(layer1.get());
     1136
     1137    EXPECT_EQ_RECT(IntRect(10, 20, 90, 80), occlusion.occlusionInScreenSpace().bounds());
     1138    EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
     1139    EXPECT_EQ_RECT(IntRect(420, -20, 80, 90), occlusion.occlusionInTargetSurface().bounds());
     1140    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     1141
     1142    EXPECT_TRUE(occlusion.occluded(child1.get(), IntRect(420, -20, 80, 90)));
     1143    EXPECT_FALSE(occlusion.occluded(child1.get(), IntRect(419, -20, 80, 90)));
     1144    EXPECT_FALSE(occlusion.occluded(child1.get(), IntRect(420, -21, 80, 90)));
     1145    EXPECT_FALSE(occlusion.occluded(child1.get(), IntRect(420, -19, 80, 90)));
     1146    EXPECT_FALSE(occlusion.occluded(child1.get(), IntRect(421, -20, 80, 90)));
     1147
     1148    occlusion.markOccludedBehindLayer(child1.get());
     1149    occlusion.finishedTargetRenderSurface(child1.get(), child1->renderSurface());
     1150    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1151
     1152    EXPECT_EQ_RECT(IntRect(10, 20, 90, 80), occlusion.occlusionInScreenSpace().bounds());
     1153    EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
     1154    EXPECT_EQ_RECT(IntRect(10, 20, 90, 80), occlusion.occlusionInTargetSurface().bounds());
     1155    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     1156
     1157    EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(10, 20, 90, 80)));
     1158    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(9, 20, 90, 80)));
     1159    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(10, 19, 90, 80)));
     1160    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(11, 20, 90, 80)));
     1161    EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(10, 21, 90, 80)));
     1162
     1163    /* Justification for the above occlusion:
     1164               100
     1165      +---------------------+
     1166      |20                   |       layer1
     1167     10+----------------------------------+
     1168  100 || 30                 |     layer2  |
     1169      |20+----------------------------------+
     1170      || |                  |             | |
     1171      || |                  |             | |
     1172      || |                  |             | |
     1173      +|-|------------------+             | |
     1174       | |                                | | 510
     1175       | |                            510 | |
     1176       | |                                | |
     1177       | |                                | |
     1178       | |                                | |
     1179       | |                                | |
     1180       | |                520             | |
     1181       +----------------------------------+ |
     1182         |                                  |
     1183         +----------------------------------+
     1184                         510
     1185     */
     1186}
     1187
     1188TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_surfaceOcclusionInScreenSpaceDifferentTransforms, surfaceOcclusionInScreenSpaceDifferentTransforms);
     1189
     1190void occlusionInteractionWithFilters(bool opaqueLayers)
     1191{
     1192    // This tests that the right transforms are being used.
     1193    const TransformationMatrix identityMatrix;
     1194    RefPtr<LayerChromium> parent = LayerChromium::create();
     1195    RefPtr<LayerChromiumWithForcedDrawsContent> blurLayer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1196    RefPtr<LayerChromiumWithForcedDrawsContent> opacityLayer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1197    RefPtr<LayerChromiumWithForcedDrawsContent> opaqueLayer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1198    parent->createRenderSurface();
     1199    parent->addChild(blurLayer);
     1200    parent->addChild(opacityLayer);
     1201    parent->addChild(opaqueLayer);
     1202
     1203    TransformationMatrix layerTransform;
     1204    layerTransform.translate(250, 250);
     1205    layerTransform.rotate(90);
     1206    layerTransform.translate(-250, -250);
     1207
     1208    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
     1209    setLayerPropertiesForTesting(blurLayer.get(), layerTransform, FloatPoint(30, 30), IntSize(500, 500), true, opaqueLayers);
     1210    setLayerPropertiesForTesting(opaqueLayer.get(), layerTransform, FloatPoint(30, 30), IntSize(500, 500), true, opaqueLayers);
     1211    setLayerPropertiesForTesting(opacityLayer.get(), layerTransform, FloatPoint(30, 30), IntSize(500, 500), true, opaqueLayers);
     1212
    1541213    {
    155         m_root.clear();
    156         m_renderSurfaceLayerListChromium.clear();
    157         m_renderSurfaceLayerListImpl.clear();
    158     }
    159 
    160     typename Types::ContentLayerType* createRoot(const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
    161     {
    162         typename Types::ContentLayerPtrType layer = Types::createContentLayer();
    163         typename Types::ContentLayerType* layerPtr = layer.get();
    164         setProperties(layerPtr, transform, position, bounds);
    165 
    166         ASSERT(!m_root);
    167         m_root = layer.release();
    168         return layerPtr;
    169     }
    170 
    171     typename Types::LayerType* createLayer(typename Types::LayerType* parent, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
    172     {
    173         typename Types::LayerPtrType layer = Types::createLayer();
    174         typename Types::LayerType* layerPtr = layer.get();
    175         setProperties(layerPtr, transform, position, bounds);
    176         parent->addChild(layer.release());
    177         return layerPtr;
    178     }
    179 
    180     typename Types::LayerType* createSurface(typename Types::LayerType* parent, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
    181     {
    182         typename Types::LayerType* layer = createLayer(parent, transform, position, bounds);
    183         FilterOperations filters;
    184         filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
    185         layer->setFilters(filters);
    186         return layer;
    187     }
    188 
    189     typename Types::ContentLayerType* createDrawingLayer(typename Types::LayerType* parent, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds, bool opaque)
    190     {
    191         typename Types::ContentLayerPtrType layer = Types::createContentLayer();
    192         typename Types::ContentLayerType* layerPtr = layer.get();
    193         setProperties(layerPtr, transform, position, bounds);
    194 
    195         if (opaqueLayers)
    196             layerPtr->setOpaque(opaque);
    197         else {
    198             layerPtr->setOpaque(false);
    199             if (opaque)
    200                 layerPtr->setOpaqueContentsRect(IntRect(IntPoint(), bounds));
    201             else
    202                 layerPtr->setOpaqueContentsRect(IntRect());
    203         }
    204 
    205         parent->addChild(layer.release());
    206         return layerPtr;
    207     }
    208 
    209     typename Types::ContentLayerType* createDrawingSurface(typename Types::LayerType* parent, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds, bool opaque)
    210     {
    211         typename Types::ContentLayerType* layer = createDrawingLayer(parent, transform, position, bounds, opaque);
    212         FilterOperations filters;
    213         filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
    214         layer->setFilters(filters);
    215         return layer;
    216     }
    217 
    218 
    219     TestContentLayerImpl* calcDrawEtc(TestContentLayerImpl* root)
    220     {
    221         ASSERT(root == m_root.get());
    222         Vector<CCLayerImpl*> dummyLayerList;
    223         int dummyMaxTextureSize = 512;
    224 
    225         ASSERT(!root->renderSurface());
    226         root->createRenderSurface();
    227         root->renderSurface()->setContentRect(IntRect(IntPoint::zero(), root->bounds()));
    228         root->setClipRect(IntRect(IntPoint::zero(), root->bounds()));
    229         m_renderSurfaceLayerListImpl.append(m_root.get());
    230 
    231         CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(root, root, identityMatrix, identityMatrix, m_renderSurfaceLayerListImpl, dummyLayerList, 0, dummyMaxTextureSize);
    232         return root;
    233     }
    234 
    235     TestContentLayerChromium* calcDrawEtc(TestContentLayerChromium* root)
    236     {
    237         ASSERT(root == m_root.get());
    238         Vector<RefPtr<LayerChromium> > dummyLayerList;
    239         int dummyMaxTextureSize = 512;
    240 
    241         ASSERT(!root->renderSurface());
    242         root->createRenderSurface();
    243         root->renderSurface()->setContentRect(IntRect(IntPoint::zero(), root->bounds()));
    244         root->setClipRect(IntRect(IntPoint::zero(), root->bounds()));
    245         m_renderSurfaceLayerListChromium.append(m_root);
    246 
    247         CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(root, root, identityMatrix, identityMatrix, m_renderSurfaceLayerListChromium, dummyLayerList, dummyMaxTextureSize);
    248         return root;
    249     }
    250 
    251     const TransformationMatrix identityMatrix;
    252 
    253 private:
    254     void setBaseProperties(typename Types::LayerType* layer, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
    255     {
    256         layer->setTransform(transform);
    257         layer->setSublayerTransform(TransformationMatrix());
    258         layer->setAnchorPoint(FloatPoint(0, 0));
    259         layer->setPosition(position);
    260         layer->setBounds(bounds);
    261     }
    262 
    263     void setProperties(LayerChromium* layer, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
    264     {
    265         setBaseProperties(layer, transform, position, bounds);
    266     }
    267 
    268     void setProperties(CCLayerImpl* layer, const TransformationMatrix& transform, const FloatPoint& position, const IntSize& bounds)
    269     {
    270         setBaseProperties(layer, transform, position, bounds);
    271 
    272         layer->setContentBounds(layer->bounds());
    273     }
    274 
    275     // These hold ownership of the layers for the duration of the test.
    276     typename Types::LayerPtrType m_root;
    277     Vector<RefPtr<LayerChromium> > m_renderSurfaceLayerListChromium;
    278     Vector<CCLayerImpl*> m_renderSurfaceLayerListImpl;
    279 };
    280 
    281 #define RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
    282     class ClassName##MainThreadOpaqueLayers : public ClassName<CCOcclusionTrackerTestMainThreadTypes, true> { }; \
    283     TEST_F(ClassName##MainThreadOpaqueLayers, runTest) { runMyTest(); }
    284 #define RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
    285     class ClassName##MainThreadOpaquePaints : public ClassName<CCOcclusionTrackerTestMainThreadTypes, false> { }; \
    286     TEST_F(ClassName##MainThreadOpaquePaints, runTest) { runMyTest(); }
    287 
    288 #define RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
    289     class ClassName##ImplThreadOpaqueLayers : public ClassName<CCOcclusionTrackerTestImplThreadTypes, true> { \
    290         DebugScopedSetImplThread impl; \
    291     }; \
    292     TEST_F(ClassName##ImplThreadOpaqueLayers, runTest) { runMyTest(); }
    293 #define RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName) \
    294     class ClassName##ImplThreadOpaquePaints : public ClassName<CCOcclusionTrackerTestImplThreadTypes, false> { \
    295         DebugScopedSetImplThread impl; \
    296     }; \
    297     TEST_F(ClassName##ImplThreadOpaquePaints, runTest) { runMyTest(); }
    298 
    299 #define ALL_CCOCCLUSIONTRACKER_TEST(ClassName) \
    300     RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
    301     RUN_TEST_MAIN_THREAD_OPAQUE_PAINTS(ClassName) \
    302     RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName) \
    303     RUN_TEST_IMPL_THREAD_OPAQUE_PAINTS(ClassName)
    304 
    305 #define MAIN_AND_IMPL_THREAD_TEST(ClassName) \
    306     RUN_TEST_MAIN_THREAD_OPAQUE_LAYERS(ClassName) \
    307     RUN_TEST_IMPL_THREAD_OPAQUE_LAYERS(ClassName)
    308 
    309 template<class Types, bool opaqueLayers>
    310 class CCOcclusionTrackerTestIdentityTransforms : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    311 protected:
    312     void runMyTest()
    313     {
    314         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
    315         typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(30, 30), IntSize(500, 500), true);
    316         calcDrawEtc(parent);
    317 
    318         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    319         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    320 
    321         occlusion.enterTargetRenderSurface(parent->renderSurface());
    322         occlusion.markOccludedBehindLayer(layer);
    323         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
    324         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    325         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
    326         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
    327 
    328         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
    329         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 70, 70)));
    330         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 70, 70)));
    331         EXPECT_FALSE(occlusion.occluded(parent, IntRect(31, 30, 70, 70)));
    332         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 31, 70, 70)));
    333 
    334         occlusion.useDefaultLayerScissorRect();
    335         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
    336         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 70, 70)));
    337         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 70, 70)));
    338         EXPECT_TRUE(occlusion.occluded(parent, IntRect(31, 30, 70, 70)));
    339         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 31, 70, 70)));
    340         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    341 
    342         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 30, 70, 70)).isEmpty());
    343         EXPECT_EQ_RECT(IntRect(29, 30, 1, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 30, 70, 70)));
    344         EXPECT_EQ_RECT(IntRect(29, 29, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 29, 70, 70)));
    345         EXPECT_EQ_RECT(IntRect(30, 29, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 29, 70, 70)));
    346         EXPECT_EQ_RECT(IntRect(31, 29, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 29, 70, 70)));
    347         EXPECT_EQ_RECT(IntRect(100, 30, 1, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 30, 70, 70)));
    348         EXPECT_EQ_RECT(IntRect(31, 31, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 31, 70, 70)));
    349         EXPECT_EQ_RECT(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 31, 70, 70)));
    350         EXPECT_EQ_RECT(IntRect(29, 31, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 31, 70, 70)));
    351     }
    352 };
    353 
    354 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestIdentityTransforms);
    355 
    356 template<class Types, bool opaqueLayers>
    357 class CCOcclusionTrackerTestRotatedChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    358 protected:
    359     void runMyTest()
    360     {
    361         TransformationMatrix layerTransform;
    362         layerTransform.translate(250, 250);
    363         layerTransform.rotate(90);
    364         layerTransform.translate(-250, -250);
    365 
    366         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
    367         typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
    368         calcDrawEtc(parent);
    369 
    370         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    371         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    372 
    373         occlusion.enterTargetRenderSurface(parent->renderSurface());
    374         occlusion.markOccludedBehindLayer(layer);
    375         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
    376         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    377         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
    378         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
    379 
    380         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
    381         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 70, 70)));
    382         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 70, 70)));
    383         EXPECT_FALSE(occlusion.occluded(parent, IntRect(31, 30, 70, 70)));
    384         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 31, 70, 70)));
    385 
    386         occlusion.useDefaultLayerScissorRect();
    387         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
    388         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 70, 70)));
    389         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 70, 70)));
    390         EXPECT_TRUE(occlusion.occluded(parent, IntRect(31, 30, 70, 70)));
    391         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 31, 70, 70)));
    392         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    393 
    394         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 30, 70, 70)).isEmpty());
    395         EXPECT_EQ_RECT(IntRect(29, 30, 1, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 30, 70, 70)));
    396         EXPECT_EQ_RECT(IntRect(29, 29, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 29, 70, 70)));
    397         EXPECT_EQ_RECT(IntRect(30, 29, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 29, 70, 70)));
    398         EXPECT_EQ_RECT(IntRect(31, 29, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 29, 70, 70)));
    399         EXPECT_EQ_RECT(IntRect(100, 30, 1, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 30, 70, 70)));
    400         EXPECT_EQ_RECT(IntRect(31, 31, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(31, 31, 70, 70)));
    401         EXPECT_EQ_RECT(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 31, 70, 70)));
    402         EXPECT_EQ_RECT(IntRect(29, 31, 70, 70), occlusion.unoccludedContentRect(parent, IntRect(29, 31, 70, 70)));
    403     }
    404 };
    405 
    406 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestRotatedChild);
    407 
    408 template<class Types, bool opaqueLayers>
    409 class CCOcclusionTrackerTestTranslatedChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    410 protected:
    411     void runMyTest()
    412     {
    413         TransformationMatrix layerTransform;
    414         layerTransform.translate(20, 20);
    415 
    416         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
    417         typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
    418         calcDrawEtc(parent);
    419 
    420         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    421         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    422 
    423         occlusion.enterTargetRenderSurface(parent->renderSurface());
    424         occlusion.markOccludedBehindLayer(layer);
    425         EXPECT_EQ_RECT(IntRect(50, 50, 50, 50), occlusion.occlusionInScreenSpace().bounds());
    426         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    427         EXPECT_EQ_RECT(IntRect(50, 50, 50, 50), occlusion.occlusionInTargetSurface().bounds());
    428         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
    429 
    430         EXPECT_TRUE(occlusion.occluded(parent, IntRect(50, 50, 50, 50)));
    431         EXPECT_FALSE(occlusion.occluded(parent, IntRect(49, 50, 50, 50)));
    432         EXPECT_FALSE(occlusion.occluded(parent, IntRect(50, 49, 50, 50)));
    433         EXPECT_FALSE(occlusion.occluded(parent, IntRect(51, 50, 50, 50)));
    434         EXPECT_FALSE(occlusion.occluded(parent, IntRect(50, 51, 50, 50)));
    435 
    436         occlusion.useDefaultLayerScissorRect();
    437         EXPECT_TRUE(occlusion.occluded(parent, IntRect(50, 50, 50, 50)));
    438         EXPECT_FALSE(occlusion.occluded(parent, IntRect(49, 50, 50, 50)));
    439         EXPECT_FALSE(occlusion.occluded(parent, IntRect(50, 49, 50, 50)));
    440         EXPECT_TRUE(occlusion.occluded(parent, IntRect(51, 50, 50, 50)));
    441         EXPECT_TRUE(occlusion.occluded(parent, IntRect(50, 51, 50, 50)));
    442         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    443 
    444         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(50, 50, 50, 50)).isEmpty());
    445         EXPECT_EQ_RECT(IntRect(49, 50, 1, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 50, 50, 50)));
    446         EXPECT_EQ_RECT(IntRect(49, 49, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 49, 50, 50)));
    447         EXPECT_EQ_RECT(IntRect(50, 49, 50, 1), occlusion.unoccludedContentRect(parent, IntRect(50, 49, 50, 50)));
    448         EXPECT_EQ_RECT(IntRect(51, 49, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(51, 49, 50, 50)));
    449         EXPECT_EQ_RECT(IntRect(100, 50, 1, 50), occlusion.unoccludedContentRect(parent, IntRect(51, 50, 50, 50)));
    450         EXPECT_EQ_RECT(IntRect(51, 51, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(51, 51, 50, 50)));
    451         EXPECT_EQ_RECT(IntRect(50, 100, 50, 1), occlusion.unoccludedContentRect(parent, IntRect(50, 51, 50, 50)));
    452         EXPECT_EQ_RECT(IntRect(49, 51, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 51, 50, 50)));
    453 
    454         occlusion.useDefaultLayerScissorRect();
    455         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(50, 50, 50, 50)).isEmpty());
    456         EXPECT_EQ_RECT(IntRect(49, 50, 1, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 50, 50, 50)));
    457         EXPECT_EQ_RECT(IntRect(49, 49, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(49, 49, 50, 50)));
    458         EXPECT_EQ_RECT(IntRect(50, 49, 50, 1), occlusion.unoccludedContentRect(parent, IntRect(50, 49, 50, 50)));
    459         EXPECT_EQ_RECT(IntRect(51, 49, 49, 1), occlusion.unoccludedContentRect(parent, IntRect(51, 49, 50, 50)));
    460         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(51, 50, 50, 50)).isEmpty());
    461         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(51, 51, 50, 50)).isEmpty());
    462         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(50, 51, 50, 50)).isEmpty());
    463         EXPECT_EQ_RECT(IntRect(49, 51, 1, 49), occlusion.unoccludedContentRect(parent, IntRect(49, 51, 50, 50)));
    464         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    465     }
    466 };
    467 
    468 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestTranslatedChild);
    469 
    470 template<class Types, bool opaqueLayers>
    471 class CCOcclusionTrackerTestChildInRotatedChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    472 protected:
    473     void runMyTest()
    474     {
    475         TransformationMatrix childTransform;
    476         childTransform.translate(250, 250);
    477         childTransform.rotate(90);
    478         childTransform.translate(-250, -250);
    479 
    480         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
    481         typename Types::LayerType* child = this->createLayer(parent, childTransform, FloatPoint(30, 30), IntSize(500, 500));
    482         child->setMasksToBounds(true);
    483         typename Types::ContentLayerType* layer = this->createDrawingLayer(child, this->identityMatrix, FloatPoint(10, 10), IntSize(500, 500), true);
    484         calcDrawEtc(parent);
    485 
    486         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    487         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    488 
    489         occlusion.enterTargetRenderSurface(child->renderSurface());
    490         occlusion.markOccludedBehindLayer(layer);
    491 
    492         EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
    493         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    494         EXPECT_EQ_RECT(IntRect(10, 430, 60, 70), occlusion.occlusionInTargetSurface().bounds());
    495         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
    496 
    497         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 70)));
    498         EXPECT_FALSE(occlusion.occluded(child, IntRect(9, 430, 60, 70)));
    499         EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 429, 60, 70)));
    500         EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 430, 61, 70)));
    501         EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 430, 60, 71)));
    502 
    503         occlusion.useDefaultLayerScissorRect();
    504         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 70)));
    505         EXPECT_TRUE(occlusion.occluded(child, IntRect(9, 430, 60, 70)));
    506         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 429, 60, 70)));
    507         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 61, 70)));
    508         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 71)));
    509         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    510 
    511         occlusion.markOccludedBehindLayer(child);
    512         occlusion.finishedTargetRenderSurface(child, child->renderSurface());
    513         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    514 
    515         EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
    516         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    517         EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInTargetSurface().bounds());
    518         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
    519 
    520         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 40, 70, 60)));
    521         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 40, 70, 60)));
    522         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 39, 70, 60)));
    523         EXPECT_FALSE(occlusion.occluded(parent, IntRect(31, 40, 70, 60)));
    524         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 41, 70, 60)));
    525 
    526         occlusion.useDefaultLayerScissorRect();
    527         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 40, 70, 60)));
    528         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 40, 70, 60)));
    529         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 39, 70, 60)));
    530         EXPECT_TRUE(occlusion.occluded(parent, IntRect(31, 40, 70, 60)));
    531         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 41, 70, 60)));
    532         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    533 
    534 
    535         /* Justification for the above occlusion from |layer|:
    536                    100
    537           +---------------------+                                      +---------------------+
    538           |                     |                                      |                     |30  Visible region of |layer|: /////
    539           |    30               |           rotate(90)                 |                     |
    540           | 30 + ---------------------------------+                    |     +---------------------------------+
    541       100 |    |  10            |                 |            ==>     |     |               |10               |
    542           |    |10+---------------------------------+                  |  +---------------------------------+  |
    543           |    |  |             |                 | |                  |  |  |///////////////|     420      |  |
    544           |    |  |             |                 | |                  |  |  |///////////////|60            |  |
    545           |    |  |             |                 | |                  |  |  |///////////////|              |  |
    546           +----|--|-------------+                 | |                  +--|--|---------------+              |  |
    547                |  |                               | |                   20|10|     70                       |  |
    548                |  |                               | |                     |  |                              |  |
    549                |  |                               | |500                  |  |                              |  |
    550                |  |                               | |                     |  |                              |  |
    551                |  |                               | |                     |  |                              |  |
    552                |  |                               | |                     |  |                              |  |
    553                |  |                               | |                     |  |                              |10|
    554                +--|-------------------------------+ |                     |  +------------------------------|--+
    555                   |                                 |                     |                 490             |
    556                   +---------------------------------+                     +---------------------------------+
    557                                  500                                                     500
    558          */
    559     }
    560 };
    561 
    562 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestChildInRotatedChild);
    563 
    564 template<class Types, bool opaqueLayers>
    565 class CCOcclusionTrackerTestVisitTargetTwoTimes : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    566 protected:
    567     void runMyTest()
    568     {
    569         TransformationMatrix childTransform;
    570         childTransform.translate(250, 250);
    571         childTransform.rotate(90);
    572         childTransform.translate(-250, -250);
    573 
    574         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
    575         typename Types::LayerType* child = this->createLayer(parent, childTransform, FloatPoint(30, 30), IntSize(500, 500));
    576         child->setMasksToBounds(true);
    577         typename Types::ContentLayerType* layer = this->createDrawingLayer(child, this->identityMatrix, FloatPoint(10, 10), IntSize(500, 500), true);
    578         // |child2| makes |parent|'s surface get considered by CCOcclusionTracker first, instead of |child|'s. This exercises different code in
    579         // leaveToTargetRenderSurface, as the target surface has already been seen.
    580         typename Types::ContentLayerType* child2 = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(30, 30), IntSize(60, 20), true);
    581         calcDrawEtc(parent);
    582 
    583         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    584         occlusion.setLayerScissorRect(IntRect(-10, -10, 1000, 1000));
    585 
    586         occlusion.enterTargetRenderSurface(parent->renderSurface());
    587         occlusion.markOccludedBehindLayer(child2);
    588 
    589         EXPECT_EQ_RECT(IntRect(30, 30, 60, 20), occlusion.occlusionInScreenSpace().bounds());
    590         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    591         EXPECT_EQ_RECT(IntRect(30, 30, 60, 20), occlusion.occlusionInTargetSurface().bounds());
    592         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
    593 
    594         occlusion.enterTargetRenderSurface(child->renderSurface());
    595         occlusion.markOccludedBehindLayer(layer);
    596 
    597         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
    598         EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
    599         EXPECT_EQ_RECT(IntRect(10, 430, 60, 70), occlusion.occlusionInTargetSurface().bounds());
    600         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
    601 
    602         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 70)));
    603         EXPECT_FALSE(occlusion.occluded(child, IntRect(9, 430, 60, 70)));
    604         EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 429, 60, 70)));
    605         EXPECT_FALSE(occlusion.occluded(child, IntRect(11, 430, 60, 70)));
    606         EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 431, 60, 70)));
    607 
    608         occlusion.useDefaultLayerScissorRect();
    609         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 70)));
    610         EXPECT_TRUE(occlusion.occluded(child, IntRect(9, 430, 60, 70)));
    611         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 429, 60, 70)));
    612         EXPECT_TRUE(occlusion.occluded(child, IntRect(11, 430, 60, 70)));
    613         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 431, 60, 70)));
    614         occlusion.setLayerScissorRect(IntRect(-10, -10, 1000, 1000));
    615 
    616         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(10, 430, 60, 70)).isEmpty());
    617         // This is the little piece not occluded by child2
    618         EXPECT_EQ_RECT(IntRect(9, 430, 1, 10), occlusion.unoccludedContentRect(child, IntRect(9, 430, 60, 70)));
    619         // This extends past both sides of child2, so it will be the original rect.
    620         EXPECT_EQ_RECT(IntRect(9, 430, 60, 80), occlusion.unoccludedContentRect(child, IntRect(9, 430, 60, 80)));
    621         // This extends past two adjacent sides of child2, and should included the unoccluded parts of each side.
    622         // This also demonstrates that the rect can be arbitrary and does not get clipped to the layer's visibleLayerRect().
    623         EXPECT_EQ_RECT(IntRect(-10, 430, 20, 70), occlusion.unoccludedContentRect(child, IntRect(-10, 430, 60, 70)));
    624         // This extends past three adjacent sides of child2, so it should contain the unoccluded parts of each side. The left
    625         // and bottom edges are completely unoccluded for some row/column so we get back the original query rect.
    626         EXPECT_EQ_RECT(IntRect(-10, 430, 60, 80), occlusion.unoccludedContentRect(child, IntRect(-10, 430, 60, 80)));
    627         EXPECT_EQ_RECT(IntRect(10, 429, 60, 1), occlusion.unoccludedContentRect(child, IntRect(10, 429, 60, 70)));
    628         EXPECT_EQ_RECT(IntRect(70, 430, 1, 70), occlusion.unoccludedContentRect(child, IntRect(11, 430, 60, 70)));
    629         EXPECT_EQ_RECT(IntRect(10, 500, 60, 1), occlusion.unoccludedContentRect(child, IntRect(10, 431, 60, 70)));
    630 
    631         occlusion.useDefaultLayerScissorRect();
    632         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(10, 430, 60, 70)).isEmpty());
    633         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(9, 430, 60, 70)).isEmpty());
    634         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(9, 430, 60, 80)).isEmpty());
    635         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(-10, 430, 60, 70)).isEmpty());
    636         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(-10, 430, 60, 80)).isEmpty());
    637         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(10, 429, 60, 70)).isEmpty());
    638         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(11, 430, 60, 70)).isEmpty());
    639         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(10, 431, 60, 70)).isEmpty());
    640         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    641 
    642         occlusion.markOccludedBehindLayer(child);
    643         // |child2| should get merged with the surface we are leaving now
    644         occlusion.finishedTargetRenderSurface(child, child->renderSurface());
    645         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    646 
    647         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
    648         EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
    649         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
    650         EXPECT_EQ(2u, occlusion.occlusionInTargetSurface().rects().size());
    651 
    652         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 30, 70, 70)));
    653         EXPECT_EQ_RECT(IntRect(90, 30, 10, 10), occlusion.unoccludedContentRect(parent, IntRect(30, 30, 70, 70)));
    654 
    655         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 30, 60, 10)));
    656         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 30, 60, 10)));
    657         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 29, 60, 10)));
    658         EXPECT_FALSE(occlusion.occluded(parent, IntRect(31, 30, 60, 10)));
    659         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 31, 60, 10)));
    660 
    661         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 40, 70, 60)));
    662         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 40, 70, 60)));
    663         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 39, 70, 60)));
    664 
    665         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 30, 60, 10)).isEmpty());
    666         EXPECT_EQ_RECT(IntRect(29, 30, 1, 10), occlusion.unoccludedContentRect(parent, IntRect(29, 30, 60, 10)));
    667         EXPECT_EQ_RECT(IntRect(30, 29, 60, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 29, 60, 10)));
    668         EXPECT_EQ_RECT(IntRect(90, 30, 1, 10), occlusion.unoccludedContentRect(parent, IntRect(31, 30, 60, 10)));
    669         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 31, 60, 10)).isEmpty());
    670 
    671         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 40, 70, 60)).isEmpty());
    672         EXPECT_EQ_RECT(IntRect(29, 40, 1, 60), occlusion.unoccludedContentRect(parent, IntRect(29, 40, 70, 60)));
    673         // This rect is mostly occluded by |child2|.
    674         EXPECT_EQ_RECT(IntRect(90, 39, 10, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 39, 70, 60)));
    675         // This rect extends past top/right ends of |child2|.
    676         EXPECT_EQ_RECT(IntRect(30, 29, 70, 11), occlusion.unoccludedContentRect(parent, IntRect(30, 29, 70, 70)));
    677         // This rect extends past left/right ends of |child2|.
    678         EXPECT_EQ_RECT(IntRect(20, 39, 80, 60), occlusion.unoccludedContentRect(parent, IntRect(20, 39, 80, 60)));
    679         EXPECT_EQ_RECT(IntRect(100, 40, 1, 60), occlusion.unoccludedContentRect(parent, IntRect(31, 40, 70, 60)));
    680         EXPECT_EQ_RECT(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 41, 70, 60)));
    681 
    682         /* Justification for the above occlusion from |layer|:
    683                    100
    684           +---------------------+                                      +---------------------+
    685           |                     |                                      |                     |30  Visible region of |layer|: /////
    686           |    30               |           rotate(90)                 |     30   60         |    |child2|: \\\\\
    687           | 30 + ------------+--------------------+                    |  30 +------------+--------------------+
    688       100 |    |  10         |  |                 |            ==>     |     |\\\\\\\\\\\\|  |10               |
    689           |    |10+----------|----------------------+                  |  +--|\\\\\\\\\\\\|-----------------+  |
    690           |    + ------------+  |                 | |                  |  |  +------------+//|     420      |  |
    691           |    |  |             |                 | |                  |  |  |///////////////|60            |  |
    692           |    |  |             |                 | |                  |  |  |///////////////|              |  |
    693           +----|--|-------------+                 | |                  +--|--|---------------+              |  |
    694                |  |                               | |                   20|10|     70                       |  |
    695                |  |                               | |                     |  |                              |  |
    696                |  |                               | |500                  |  |                              |  |
    697                |  |                               | |                     |  |                              |  |
    698                |  |                               | |                     |  |                              |  |
    699                |  |                               | |                     |  |                              |  |
    700                |  |                               | |                     |  |                              |10|
    701                +--|-------------------------------+ |                     |  +------------------------------|--+
    702                   |                                 |                     |                 490             |
    703                   +---------------------------------+                     +---------------------------------+
    704                                  500                                                     500
    705          */
    706     }
    707 };
    708 
    709 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestVisitTargetTwoTimes);
    710 
    711 template<class Types, bool opaqueLayers>
    712 class CCOcclusionTrackerTestSurfaceRotatedOffAxis : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    713 protected:
    714     void runMyTest()
    715     {
    716         TransformationMatrix childTransform;
    717         childTransform.translate(250, 250);
    718         childTransform.rotate(95);
    719         childTransform.translate(-250, -250);
    720 
    721         TransformationMatrix layerTransform;
    722         layerTransform.translate(10, 10);
    723 
    724         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
    725         typename Types::LayerType* child = this->createLayer(parent, childTransform, FloatPoint(30, 30), IntSize(500, 500));
    726         child->setMasksToBounds(true);
    727         typename Types::ContentLayerType* layer = this->createDrawingLayer(child, layerTransform, FloatPoint(0, 0), IntSize(500, 500), true);
    728         calcDrawEtc(parent);
    729 
    730         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    731         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    732 
    733         IntRect clippedLayerInChild = layerTransform.mapRect(layer->visibleLayerRect());
    734 
    735         occlusion.enterTargetRenderSurface(child->renderSurface());
    736         occlusion.markOccludedBehindLayer(layer);
    737 
    738         EXPECT_EQ_RECT(IntRect(), occlusion.occlusionInScreenSpace().bounds());
    739         EXPECT_EQ(0u, occlusion.occlusionInScreenSpace().rects().size());
    740         EXPECT_EQ_RECT(clippedLayerInChild, occlusion.occlusionInTargetSurface().bounds());
    741         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
    742 
    743         EXPECT_TRUE(occlusion.occluded(child, clippedLayerInChild));
    744         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, clippedLayerInChild).isEmpty());
    745         clippedLayerInChild.move(-1, 0);
    746         EXPECT_FALSE(occlusion.occluded(child, clippedLayerInChild));
    747         EXPECT_FALSE(occlusion.unoccludedContentRect(parent, clippedLayerInChild).isEmpty());
    748         clippedLayerInChild.move(1, 0);
    749         clippedLayerInChild.move(1, 0);
    750         EXPECT_FALSE(occlusion.occluded(child, clippedLayerInChild));
    751         EXPECT_FALSE(occlusion.unoccludedContentRect(parent, clippedLayerInChild).isEmpty());
    752         clippedLayerInChild.move(-1, 0);
    753         clippedLayerInChild.move(0, -1);
    754         EXPECT_FALSE(occlusion.occluded(child, clippedLayerInChild));
    755         EXPECT_FALSE(occlusion.unoccludedContentRect(parent, clippedLayerInChild).isEmpty());
    756         clippedLayerInChild.move(0, 1);
    757         clippedLayerInChild.move(0, 1);
    758         EXPECT_FALSE(occlusion.occluded(child, clippedLayerInChild));
    759         EXPECT_FALSE(occlusion.unoccludedContentRect(parent, clippedLayerInChild).isEmpty());
    760         clippedLayerInChild.move(0, -1);
    761 
    762         occlusion.markOccludedBehindLayer(child);
    763         occlusion.finishedTargetRenderSurface(child, child->renderSurface());
    764         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    765 
    766         EXPECT_EQ_RECT(IntRect(), occlusion.occlusionInScreenSpace().bounds());
    767         EXPECT_EQ(0u, occlusion.occlusionInScreenSpace().rects().size());
    768         EXPECT_EQ_RECT(IntRect(), occlusion.occlusionInTargetSurface().bounds());
    769         EXPECT_EQ(0u, occlusion.occlusionInTargetSurface().rects().size());
    770 
    771         EXPECT_FALSE(occlusion.occluded(parent, IntRect(75, 55, 1, 1)));
    772         EXPECT_EQ_RECT(IntRect(75, 55, 1, 1), occlusion.unoccludedContentRect(parent, IntRect(75, 55, 1, 1)));
    773     }
    774 };
    775 
    776 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestSurfaceRotatedOffAxis);
    777 
    778 template<class Types, bool opaqueLayers>
    779 class CCOcclusionTrackerTestSurfaceWithTwoOpaqueChildren : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    780 protected:
    781     void runMyTest()
    782     {
    783         TransformationMatrix childTransform;
    784         childTransform.translate(250, 250);
    785         childTransform.rotate(90);
    786         childTransform.translate(-250, -250);
    787 
    788         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
    789         typename Types::LayerType* child = this->createLayer(parent, childTransform, FloatPoint(30, 30), IntSize(500, 500));
    790         child->setMasksToBounds(true);
    791         typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child, this->identityMatrix, FloatPoint(10, 10), IntSize(500, 500), true);
    792         typename Types::ContentLayerType* layer2 = this->createDrawingLayer(child, this->identityMatrix, FloatPoint(10, 450), IntSize(500, 60), true);
    793         calcDrawEtc(parent);
    794 
    795         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    796         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    797 
    798         occlusion.enterTargetRenderSurface(child->renderSurface());
    799         occlusion.markOccludedBehindLayer(layer2);
    800         occlusion.markOccludedBehindLayer(layer1);
    801 
    802         EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
    803         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    804         EXPECT_EQ_RECT(IntRect(10, 430, 60, 70), occlusion.occlusionInTargetSurface().bounds());
    805         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
    806 
    807         EXPECT_TRUE(occlusion.occluded(child, IntRect(10, 430, 60, 70)));
    808         EXPECT_FALSE(occlusion.occluded(child, IntRect(9, 430, 60, 70)));
    809         EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 429, 60, 70)));
    810         EXPECT_FALSE(occlusion.occluded(child, IntRect(11, 430, 60, 70)));
    811         EXPECT_FALSE(occlusion.occluded(child, IntRect(10, 431, 60, 70)));
    812 
    813         EXPECT_TRUE(occlusion.unoccludedContentRect(child, IntRect(10, 430, 60, 70)).isEmpty());
    814         EXPECT_EQ_RECT(IntRect(9, 430, 1, 70), occlusion.unoccludedContentRect(child, IntRect(9, 430, 60, 70)));
    815         EXPECT_EQ_RECT(IntRect(10, 429, 60, 1), occlusion.unoccludedContentRect(child, IntRect(10, 429, 60, 70)));
    816         EXPECT_EQ_RECT(IntRect(70, 430, 1, 70), occlusion.unoccludedContentRect(child, IntRect(11, 430, 60, 70)));
    817         EXPECT_EQ_RECT(IntRect(10, 500, 60, 1), occlusion.unoccludedContentRect(child, IntRect(10, 431, 60, 70)));
    818 
    819         occlusion.markOccludedBehindLayer(child);
    820         occlusion.finishedTargetRenderSurface(child, child->renderSurface());
    821         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    822 
    823         EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInScreenSpace().bounds());
    824         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    825         EXPECT_EQ_RECT(IntRect(30, 40, 70, 60), occlusion.occlusionInTargetSurface().bounds());
    826         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
    827 
    828         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 40, 70, 60)));
    829         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 40, 70, 60)));
    830         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 39, 70, 60)));
    831 
    832         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(30, 40, 70, 60)).isEmpty());
    833         EXPECT_EQ_RECT(IntRect(29, 40, 1, 60), occlusion.unoccludedContentRect(parent, IntRect(29, 40, 70, 60)));
    834         EXPECT_EQ_RECT(IntRect(30, 39, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 39, 70, 60)));
    835         EXPECT_EQ_RECT(IntRect(100, 40, 1, 60), occlusion.unoccludedContentRect(parent, IntRect(31, 40, 70, 60)));
    836         EXPECT_EQ_RECT(IntRect(30, 100, 70, 1), occlusion.unoccludedContentRect(parent, IntRect(30, 41, 70, 60)));
    837 
    838         /* Justification for the above occlusion from |layer1| and |layer2|:
    839 
    840            +---------------------+
    841            |                     |30  Visible region of |layer1|: /////
    842            |                     |    Visible region of |layer2|: \\\\\
    843            |     +---------------------------------+
    844            |     |               |10               |
    845            |  +---------------+-----------------+  |
    846            |  |  |\\\\\\\\\\\\|//|     420      |  |
    847            |  |  |\\\\\\\\\\\\|//|60            |  |
    848            |  |  |\\\\\\\\\\\\|//|              |  |
    849            +--|--|------------|--+              |  |
    850             20|10|     70     |                 |  |
    851               |  |            |                 |  |
    852               |  |            |                 |  |
    853               |  |            |                 |  |
    854               |  |            |                 |  |
    855               |  |            |                 |  |
    856               |  |            |                 |10|
    857               |  +------------|-----------------|--+
    858               |               | 490             |
    859               +---------------+-----------------+
    860                      60               440
    861          */
    862     }
    863 };
    864 
    865 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestSurfaceWithTwoOpaqueChildren);
    866 
    867 template<class Types, bool opaqueLayers>
    868 class CCOcclusionTrackerTestOverlappingSurfaceSiblings : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    869 protected:
    870     void runMyTest()
    871     {
    872         TransformationMatrix childTransform;
    873         childTransform.translate(250, 250);
    874         childTransform.rotate(90);
    875         childTransform.translate(-250, -250);
    876 
    877         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
    878         typename Types::LayerType* child1 = this->createSurface(parent, childTransform, FloatPoint(30, 30), IntSize(10, 10));
    879         typename Types::LayerType* child2 = this->createSurface(parent, childTransform, FloatPoint(20, 40), IntSize(10, 10));
    880         typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child1, this->identityMatrix, FloatPoint(-10, -10), IntSize(510, 510), true);
    881         typename Types::ContentLayerType* layer2 = this->createDrawingLayer(child2, this->identityMatrix, FloatPoint(-10, -10), IntSize(510, 510), true);
    882         calcDrawEtc(parent);
    883 
    884         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    885         occlusion.setLayerScissorRect(IntRect(-20, -20, 1000, 1000));
    886 
    887         occlusion.enterTargetRenderSurface(child2->renderSurface());
    888         occlusion.markOccludedBehindLayer(layer2);
    889 
    890         EXPECT_EQ_RECT(IntRect(20, 30, 80, 70), occlusion.occlusionInScreenSpace().bounds());
    891         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    892         EXPECT_EQ_RECT(IntRect(-10, 420, 70, 80), occlusion.occlusionInTargetSurface().bounds());
    893         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
    894 
    895         EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 70, 80)));
    896         EXPECT_FALSE(occlusion.occluded(child2, IntRect(-11, 420, 70, 80)));
    897         EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 419, 70, 80)));
    898         EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 420, 71, 80)));
    899         EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 420, 70, 81)));
    900 
    901         occlusion.useDefaultLayerScissorRect();
    902         EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 70, 80)));
    903         EXPECT_TRUE(occlusion.occluded(child2, IntRect(-11, 420, 70, 80)));
    904         EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 419, 70, 80)));
    905         EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 71, 80)));
    906         EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 70, 81)));
    907         occlusion.setLayerScissorRect(IntRect(-20, -20, 1000, 1000));
    908 
    909         occlusion.markOccludedBehindLayer(child2);
    910         occlusion.finishedTargetRenderSurface(child2, child2->renderSurface());
    911         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    912         occlusion.enterTargetRenderSurface(child1->renderSurface());
    913         occlusion.markOccludedBehindLayer(layer1);
    914 
    915         EXPECT_EQ_RECT(IntRect(20, 20, 80, 80), occlusion.occlusionInScreenSpace().bounds());
    916         EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
    917         EXPECT_EQ_RECT(IntRect(-10, 430, 80, 70), occlusion.occlusionInTargetSurface().bounds());
    918         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
    919 
    920         EXPECT_TRUE(occlusion.occluded(child1, IntRect(-10, 430, 80, 70)));
    921         EXPECT_FALSE(occlusion.occluded(child1, IntRect(-11, 430, 80, 70)));
    922         EXPECT_FALSE(occlusion.occluded(child1, IntRect(-10, 429, 80, 70)));
    923         EXPECT_FALSE(occlusion.occluded(child1, IntRect(-10, 430, 81, 70)));
    924         EXPECT_FALSE(occlusion.occluded(child1, IntRect(-10, 430, 80, 71)));
    925 
    926         occlusion.markOccludedBehindLayer(child1);
    927         occlusion.finishedTargetRenderSurface(child1, child1->renderSurface());
    928         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    929 
    930         EXPECT_EQ_RECT(IntRect(20, 20, 80, 80), occlusion.occlusionInScreenSpace().bounds());
    931         EXPECT_EQ(2u, occlusion.occlusionInScreenSpace().rects().size());
    932         EXPECT_EQ_RECT(IntRect(20, 20, 80, 80), occlusion.occlusionInTargetSurface().bounds());
    933         EXPECT_EQ(2u, occlusion.occlusionInTargetSurface().rects().size());
    934 
    935         EXPECT_FALSE(occlusion.occluded(parent, IntRect(20, 20, 80, 80)));
    936 
    937         EXPECT_TRUE(occlusion.occluded(parent, IntRect(30, 20, 70, 80)));
    938         EXPECT_FALSE(occlusion.occluded(parent, IntRect(29, 20, 70, 80)));
    939         EXPECT_FALSE(occlusion.occluded(parent, IntRect(30, 19, 70, 80)));
    940 
    941         EXPECT_TRUE(occlusion.occluded(parent, IntRect(20, 30, 80, 70)));
    942         EXPECT_FALSE(occlusion.occluded(parent, IntRect(19, 30, 80, 70)));
    943         EXPECT_FALSE(occlusion.occluded(parent, IntRect(20, 29, 80, 70)));
    944 
    945         /* Justification for the above occlusion:
    946                    100
    947           +---------------------+
    948           |    20               |       layer1
    949           |  30+ ---------------------------------+
    950       100 |  30|                |     layer2      |
    951           |20+----------------------------------+ |
    952           |  | |                |               | |
    953           |  | |                |               | |
    954           |  | |                |               | |
    955           +--|-|----------------+               | |
    956              | |                                | | 510
    957              | |                                | |
    958              | |                                | |
    959              | |                                | |
    960              | |                                | |
    961              | |                                | |
    962              | |                                | |
    963              | +--------------------------------|-+
    964              |                                  |
    965              +----------------------------------+
    966                              510
    967          */
    968     }
    969 };
    970 
    971 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestOverlappingSurfaceSiblings);
    972 
    973 template<class Types, bool opaqueLayers>
    974 class CCOcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    975 protected:
    976     void runMyTest()
    977     {
    978         TransformationMatrix child1Transform;
    979         child1Transform.translate(250, 250);
    980         child1Transform.rotate(-90);
    981         child1Transform.translate(-250, -250);
    982 
    983         TransformationMatrix child2Transform;
    984         child2Transform.translate(250, 250);
    985         child2Transform.rotate(90);
    986         child2Transform.translate(-250, -250);
    987 
    988         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
    989         typename Types::LayerType* child1 = this->createSurface(parent, child1Transform, FloatPoint(30, 20), IntSize(10, 10));
    990         typename Types::LayerType* child2 = this->createSurface(parent, child2Transform, FloatPoint(20, 40), IntSize(10, 10));
    991         typename Types::ContentLayerType* layer1 = this->createDrawingLayer(child1, this->identityMatrix, FloatPoint(-10, -20), IntSize(510, 510), true);
    992         typename Types::ContentLayerType* layer2 = this->createDrawingLayer(child2, this->identityMatrix, FloatPoint(-10, -10), IntSize(510, 510), true);
    993         calcDrawEtc(parent);
    994 
    995         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    996         occlusion.setLayerScissorRect(IntRect(-30, -30, 1000, 1000));
    997 
    998         occlusion.enterTargetRenderSurface(child2->renderSurface());
    999         occlusion.markOccludedBehindLayer(layer2);
    1000 
    1001         EXPECT_EQ_RECT(IntRect(20, 30, 80, 70), occlusion.occlusionInScreenSpace().bounds());
    1002         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    1003         EXPECT_EQ_RECT(IntRect(-10, 420, 70, 80), occlusion.occlusionInTargetSurface().bounds());
    1004         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
    1005 
    1006         EXPECT_TRUE(occlusion.occluded(child2, IntRect(-10, 420, 70, 80)));
    1007         EXPECT_FALSE(occlusion.occluded(child2, IntRect(-11, 420, 70, 80)));
    1008         EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 419, 70, 80)));
    1009         EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 420, 71, 80)));
    1010         EXPECT_FALSE(occlusion.occluded(child2, IntRect(-10, 420, 70, 81)));
    1011 
    1012         occlusion.markOccludedBehindLayer(child2);
    1013         occlusion.finishedTargetRenderSurface(child2, child2->renderSurface());
    1014         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1015         occlusion.enterTargetRenderSurface(child1->renderSurface());
    1016         occlusion.markOccludedBehindLayer(layer1);
    1017 
    1018         EXPECT_EQ_RECT(IntRect(10, 20, 90, 80), occlusion.occlusionInScreenSpace().bounds());
    1019         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    1020         EXPECT_EQ_RECT(IntRect(420, -20, 80, 90), occlusion.occlusionInTargetSurface().bounds());
    1021         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
    1022 
    1023         EXPECT_TRUE(occlusion.occluded(child1, IntRect(420, -20, 80, 90)));
    1024         EXPECT_FALSE(occlusion.occluded(child1, IntRect(419, -20, 80, 90)));
    1025         EXPECT_FALSE(occlusion.occluded(child1, IntRect(420, -21, 80, 90)));
    1026         EXPECT_FALSE(occlusion.occluded(child1, IntRect(420, -19, 80, 90)));
    1027         EXPECT_FALSE(occlusion.occluded(child1, IntRect(421, -20, 80, 90)));
    1028 
    1029         occlusion.markOccludedBehindLayer(child1);
    1030         occlusion.finishedTargetRenderSurface(child1, child1->renderSurface());
    1031         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1032 
    1033         EXPECT_EQ_RECT(IntRect(10, 20, 90, 80), occlusion.occlusionInScreenSpace().bounds());
    1034         EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    1035         EXPECT_EQ_RECT(IntRect(10, 20, 90, 80), occlusion.occlusionInTargetSurface().bounds());
    1036         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
    1037 
    1038         EXPECT_TRUE(occlusion.occluded(parent, IntRect(10, 20, 90, 80)));
    1039         EXPECT_FALSE(occlusion.occluded(parent, IntRect(9, 20, 90, 80)));
    1040         EXPECT_FALSE(occlusion.occluded(parent, IntRect(10, 19, 90, 80)));
    1041         EXPECT_FALSE(occlusion.occluded(parent, IntRect(11, 20, 90, 80)));
    1042         EXPECT_FALSE(occlusion.occluded(parent, IntRect(10, 21, 90, 80)));
    1043 
    1044         /* Justification for the above occlusion:
    1045                       100
    1046             +---------------------+
    1047             |20                   |       layer1
    1048            10+----------------------------------+
    1049         100 || 30                 |     layer2  |
    1050             |20+----------------------------------+
    1051             || |                  |             | |
    1052             || |                  |             | |
    1053             || |                  |             | |
    1054             +|-|------------------+             | |
    1055              | |                                | | 510
    1056              | |                            510 | |
    1057              | |                                | |
    1058              | |                                | |
    1059              | |                                | |
    1060              | |                                | |
    1061              | |                520             | |
    1062              +----------------------------------+ |
    1063                |                                  |
    1064                +----------------------------------+
    1065                                510
    1066          */
    1067     }
    1068 };
    1069 
    1070 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestOverlappingSurfaceSiblingsWithTwoTransforms);
    1071 
    1072 template<class Types, bool opaqueLayers>
    1073 class CCOcclusionTrackerTestFilters : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    1074 protected:
    1075     void runMyTest()
    1076     {
    1077         TransformationMatrix layerTransform;
    1078         layerTransform.translate(250, 250);
    1079         layerTransform.rotate(90);
    1080         layerTransform.translate(-250, -250);
    1081 
    1082         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(100, 100));
    1083         typename Types::ContentLayerType* blurLayer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
    1084         typename Types::ContentLayerType* opacityLayer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
    1085         typename Types::ContentLayerType* opaqueLayer = this->createDrawingLayer(parent, layerTransform, FloatPoint(30, 30), IntSize(500, 500), true);
    1086 
    10871214        FilterOperations filters;
    10881215        filters.operations().append(BlurFilterOperation::create(Length(10, WebCore::Percent), FilterOperation::BLUR));
    10891216        blurLayer->setFilters(filters);
    1090 
    1091         filters.operations().clear();
     1217    }
     1218
     1219    {
     1220        FilterOperations filters;
    10921221        filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
    10931222        opaqueLayer->setFilters(filters);
    1094 
    1095         filters.operations().clear();
     1223    }
     1224
     1225    {
     1226        FilterOperations filters;
    10961227        filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::OPACITY));
    10971228        opacityLayer->setFilters(filters);
    1098 
    1099         calcDrawEtc(parent);
    1100 
    1101         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    1102         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    1103 
    1104         // Opacity layer won't contribute to occlusion.
    1105         occlusion.enterTargetRenderSurface(opacityLayer->renderSurface());
    1106         occlusion.markOccludedBehindLayer(opacityLayer);
    1107         occlusion.finishedTargetRenderSurface(opacityLayer, opacityLayer->renderSurface());
    1108 
    1109         EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
    1110         EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
    1111 
    1112         // And has nothing to contribute to its parent surface.
    1113         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1114         EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
    1115         EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
    1116 
    1117         // Opaque layer will contribute to occlusion.
    1118         occlusion.enterTargetRenderSurface(opaqueLayer->renderSurface());
    1119         occlusion.markOccludedBehindLayer(opaqueLayer);
    1120         occlusion.finishedTargetRenderSurface(opaqueLayer, opaqueLayer->renderSurface());
    1121 
    1122         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
     1229    }
     1230
     1231
     1232    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     1233    Vector<RefPtr<LayerChromium> > dummyLayerList;
     1234    int dummyMaxTextureSize = 512;
     1235
     1236    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     1237    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     1238    renderSurfaceLayerList.append(parent);
     1239
     1240    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     1241
     1242    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     1243    occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
     1244
     1245    // Opacity layer won't contribute to occlusion.
     1246    occlusion.enterTargetRenderSurface(opacityLayer->renderSurface());
     1247    occlusion.markOccludedBehindLayer(opacityLayer.get());
     1248    occlusion.finishedTargetRenderSurface(opacityLayer.get(), opacityLayer->renderSurface());
     1249
     1250    EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
     1251    EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
     1252
     1253    // And has nothing to contribute to its parent surface.
     1254    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1255    EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
     1256    EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
     1257
     1258    // Opaque layer will contribute to occlusion.
     1259    occlusion.enterTargetRenderSurface(opaqueLayer->renderSurface());
     1260    occlusion.markOccludedBehindLayer(opaqueLayer.get());
     1261    occlusion.finishedTargetRenderSurface(opaqueLayer.get(), opaqueLayer->renderSurface());
     1262
     1263    EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
     1264    EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
     1265    EXPECT_EQ_RECT(IntRect(0, 430, 70, 70), occlusion.occlusionInTargetSurface().bounds());
     1266    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     1267
     1268    // And it gets translated to the parent surface.
     1269    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1270    EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
     1271    EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
     1272    EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
     1273    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     1274
     1275    // The blur layer needs to throw away any occlusion from outside its subtree.
     1276    occlusion.enterTargetRenderSurface(blurLayer->renderSurface());
     1277    EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
     1278    EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
     1279
     1280    // And it won't contribute to occlusion.
     1281    occlusion.markOccludedBehindLayer(blurLayer.get());
     1282    occlusion.finishedTargetRenderSurface(blurLayer.get(), blurLayer->renderSurface());
     1283    EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
     1284    EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
     1285
     1286    // But the opaque layer's occlusion is preserved on the parent.
     1287    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1288    EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
     1289    EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
     1290    EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
     1291    EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     1292}
     1293
     1294TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_occlusionInteractionWithFilters, occlusionInteractionWithFilters);
     1295
     1296void layerScissorRectOverTile(bool opaqueLayers)
     1297{
     1298    const TransformationMatrix identityMatrix;
     1299    RefPtr<LayerChromium> parent = LayerChromium::create();
     1300    RefPtr<LayerChromiumWithForcedDrawsContent> parentLayer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1301    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1302    parent->createRenderSurface();
     1303    parent->addChild(parentLayer);
     1304    parent->addChild(layer);
     1305
     1306    FilterOperations filters;
     1307    filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
     1308    parentLayer->setFilters(filters);
     1309    layer->setFilters(filters);
     1310
     1311    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
     1312    setLayerPropertiesForTesting(parentLayer.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300), false, opaqueLayers);
     1313    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true, opaqueLayers);
     1314
     1315    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     1316    Vector<RefPtr<LayerChromium> > dummyLayerList;
     1317    int dummyMaxTextureSize = 512;
     1318
     1319    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     1320    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     1321    renderSurfaceLayerList.append(parent);
     1322
     1323    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     1324
     1325    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     1326    occlusion.setLayerScissorRect(IntRect(200, 100, 100, 100));
     1327
     1328    occlusion.enterTargetRenderSurface(layer->renderSurface());
     1329
     1330    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 0, 100, 100)));
     1331    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(100, 0, 100, 100)));
     1332    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 100, 100, 100)));
     1333    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(100, 100, 100, 100)));
     1334    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(200, 100, 100, 100)));
     1335
     1336    occlusion.useDefaultLayerScissorRect();
     1337    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(200, 100, 100, 100)));
     1338    occlusion.setLayerScissorRect(IntRect(200, 100, 100, 100));
     1339
     1340    occlusion.markOccludedBehindLayer(layer.get());
     1341    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1342    occlusion.enterTargetRenderSurface(parentLayer->renderSurface());
     1343
     1344    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 0, 100, 100)));
     1345    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 100, 100, 100)));
     1346    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 0, 100, 100)));
     1347    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 100, 100, 100)));
     1348    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(200, 100, 100, 100)));
     1349    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 0, 100, 100)));
     1350    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 200, 100, 100)));
     1351    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 200, 100, 100)));
     1352    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 200, 100, 100)));
     1353
     1354    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1355
     1356    EXPECT_EQ_RECT(IntRect(200, 100, 100, 100), occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 300)));
     1357}
     1358
     1359TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_layerScissorRectOverTile, layerScissorRectOverTile);
     1360
     1361void screenScissorRectOverTile(bool opaqueLayers)
     1362{
     1363    const TransformationMatrix identityMatrix;
     1364    RefPtr<LayerChromium> parent = LayerChromium::create();
     1365    RefPtr<LayerChromiumWithForcedDrawsContent> parentLayer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1366    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1367    parent->createRenderSurface();
     1368    parent->addChild(parentLayer);
     1369    parent->addChild(layer);
     1370
     1371    FilterOperations filters;
     1372    filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
     1373    parentLayer->setFilters(filters);
     1374    layer->setFilters(filters);
     1375
     1376    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
     1377    setLayerPropertiesForTesting(parentLayer.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300), false, opaqueLayers);
     1378    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true, opaqueLayers);
     1379
     1380    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     1381    Vector<RefPtr<LayerChromium> > dummyLayerList;
     1382    int dummyMaxTextureSize = 512;
     1383
     1384    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     1385    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     1386    renderSurfaceLayerList.append(parent);
     1387
     1388    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     1389
     1390    TestCCOcclusionTracker occlusion(IntRect(200, 100, 100, 100));
     1391
     1392    occlusion.enterTargetRenderSurface(layer->renderSurface());
     1393
     1394    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 0, 100, 100)));
     1395    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(100, 0, 100, 100)));
     1396    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 100, 100, 100)));
     1397    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(100, 100, 100, 100)));
     1398
     1399    // Occluded since its outside the surface bounds.
     1400    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(200, 100, 100, 100)));
     1401
     1402    // Test without any scissors.
     1403    occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
     1404    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(200, 100, 100, 100)));
     1405    occlusion.useDefaultLayerScissorRect();
     1406
     1407    occlusion.markOccludedBehindLayer(layer.get());
     1408    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1409    occlusion.enterTargetRenderSurface(parentLayer->renderSurface());
     1410
     1411    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 0, 100, 100)));
     1412    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 100, 100, 100)));
     1413    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 0, 100, 100)));
     1414    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 100, 100, 100)));
     1415    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(200, 100, 100, 100)));
     1416    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 0, 100, 100)));
     1417    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 200, 100, 100)));
     1418    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 200, 100, 100)));
     1419    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 200, 100, 100)));
     1420
     1421    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1422
     1423    EXPECT_EQ_RECT(IntRect(200, 100, 100, 100), occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 300)));
     1424}
     1425
     1426TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_screenScissorRectOverTile, screenScissorRectOverTile);
     1427
     1428void layerScissorRectOverCulledTile(bool opaqueLayers)
     1429{
     1430    const TransformationMatrix identityMatrix;
     1431    RefPtr<LayerChromium> parent = LayerChromium::create();
     1432    RefPtr<LayerChromiumWithForcedDrawsContent> parentLayer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1433    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1434    parent->createRenderSurface();
     1435    parent->addChild(parentLayer);
     1436    parent->addChild(layer);
     1437
     1438    FilterOperations filters;
     1439    filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
     1440    parentLayer->setFilters(filters);
     1441    layer->setFilters(filters);
     1442
     1443    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
     1444    setLayerPropertiesForTesting(parentLayer.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300), false, opaqueLayers);
     1445    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true, opaqueLayers);
     1446
     1447    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     1448    Vector<RefPtr<LayerChromium> > dummyLayerList;
     1449    int dummyMaxTextureSize = 512;
     1450
     1451    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     1452    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     1453    renderSurfaceLayerList.append(parent);
     1454
     1455    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     1456
     1457    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     1458    occlusion.setLayerScissorRect(IntRect(100, 100, 100, 100));
     1459
     1460    occlusion.enterTargetRenderSurface(layer->renderSurface());
     1461
     1462    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 0, 100, 100)));
     1463    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 100, 100, 100)));
     1464    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(100, 0, 100, 100)));
     1465    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(100, 100, 100, 100)));
     1466
     1467    occlusion.markOccludedBehindLayer(layer.get());
     1468    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1469    occlusion.enterTargetRenderSurface(parentLayer->renderSurface());
     1470
     1471    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 0, 100, 100)));
     1472    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 100, 100, 100)));
     1473    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 0, 100, 100)));
     1474    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 100, 100, 100)));
     1475    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 100, 100, 100)));
     1476    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 0, 100, 100)));
     1477    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 200, 100, 100)));
     1478    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 200, 100, 100)));
     1479    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 200, 100, 100)));
     1480
     1481    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1482
     1483    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 300)).isEmpty());
     1484}
     1485
     1486TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_layerScissorRectOverCulledTile, layerScissorRectOverCulledTile);
     1487
     1488void screenScissorRectOverCulledTile(bool opaqueLayers)
     1489{
     1490    const TransformationMatrix identityMatrix;
     1491    RefPtr<LayerChromium> parent = LayerChromium::create();
     1492    RefPtr<LayerChromiumWithForcedDrawsContent> parentLayer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1493    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1494    parent->createRenderSurface();
     1495    parent->addChild(parentLayer);
     1496    parent->addChild(layer);
     1497
     1498    FilterOperations filters;
     1499    filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
     1500    parentLayer->setFilters(filters);
     1501    layer->setFilters(filters);
     1502
     1503    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
     1504    setLayerPropertiesForTesting(parentLayer.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300), false, opaqueLayers);
     1505    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true, opaqueLayers);
     1506
     1507    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     1508    Vector<RefPtr<LayerChromium> > dummyLayerList;
     1509    int dummyMaxTextureSize = 512;
     1510
     1511    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     1512    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     1513    renderSurfaceLayerList.append(parent);
     1514
     1515    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     1516
     1517    TestCCOcclusionTracker occlusion(IntRect(100, 100, 100, 100));
     1518
     1519    occlusion.enterTargetRenderSurface(layer->renderSurface());
     1520
     1521    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 0, 100, 100)));
     1522    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 100, 100, 100)));
     1523    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(100, 0, 100, 100)));
     1524    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(100, 100, 100, 100)));
     1525
     1526    occlusion.markOccludedBehindLayer(layer.get());
     1527    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1528    occlusion.enterTargetRenderSurface(parentLayer->renderSurface());
     1529
     1530    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 0, 100, 100)));
     1531    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 100, 100, 100)));
     1532    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 0, 100, 100)));
     1533    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 100, 100, 100)));
     1534    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 100, 100, 100)));
     1535    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 0, 100, 100)));
     1536    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 200, 100, 100)));
     1537    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 200, 100, 100)));
     1538    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 200, 100, 100)));
     1539
     1540    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1541
     1542    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 300)).isEmpty());
     1543}
     1544
     1545TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_screenScissorRectOverCulledTile, screenScissorRectOverCulledTile);
     1546
     1547void layerScissorRectOverPartialTiles(bool opaqueLayers)
     1548{
     1549    const TransformationMatrix identityMatrix;
     1550    RefPtr<LayerChromium> parent = LayerChromium::create();
     1551    RefPtr<LayerChromiumWithForcedDrawsContent> parentLayer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1552    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1553    parent->createRenderSurface();
     1554    parent->addChild(parentLayer);
     1555    parent->addChild(layer);
     1556
     1557    FilterOperations filters;
     1558    filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
     1559    parentLayer->setFilters(filters);
     1560    layer->setFilters(filters);
     1561
     1562    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
     1563    setLayerPropertiesForTesting(parentLayer.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300), false, opaqueLayers);
     1564    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true, opaqueLayers);
     1565
     1566    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     1567    Vector<RefPtr<LayerChromium> > dummyLayerList;
     1568    int dummyMaxTextureSize = 512;
     1569
     1570    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     1571    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     1572    renderSurfaceLayerList.append(parent);
     1573
     1574    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     1575
     1576    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     1577    occlusion.setLayerScissorRect(IntRect(50, 50, 200, 200));
     1578
     1579    occlusion.enterTargetRenderSurface(layer->renderSurface());
     1580
     1581    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(0, 0, 100, 100)));
     1582    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(0, 100, 100, 100)));
     1583    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(100, 0, 100, 100)));
     1584    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(100, 100, 100, 100)));
     1585
     1586    occlusion.markOccludedBehindLayer(layer.get());
     1587    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1588    occlusion.enterTargetRenderSurface(parentLayer->renderSurface());
     1589
     1590    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 0, 100, 100)));
     1591    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 100, 100, 100)));
     1592    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 0, 100, 100)));
     1593    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 100, 100, 100)));
     1594    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(200, 100, 100, 100)));
     1595    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(200, 0, 100, 100)));
     1596    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(0, 200, 100, 100)));
     1597    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(100, 200, 100, 100)));
     1598    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(200, 200, 100, 100)));
     1599
     1600    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1601
     1602    EXPECT_EQ_RECT(IntRect(50, 50, 200, 200), occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 300)));
     1603    EXPECT_EQ_RECT(IntRect(200, 50, 50, 50), occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 100)));
     1604    EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent.get(), IntRect(0, 100, 300, 100)));
     1605    EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent.get(), IntRect(200, 100, 100, 100)));
     1606    EXPECT_EQ_RECT(IntRect(100, 200, 100, 50), occlusion.unoccludedContentRect(parent.get(), IntRect(100, 200, 100, 100)));
     1607}
     1608
     1609TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_layerScissorRectOverPartialTiles, layerScissorRectOverPartialTiles);
     1610
     1611void screenScissorRectOverPartialTiles(bool opaqueLayers)
     1612{
     1613    const TransformationMatrix identityMatrix;
     1614    RefPtr<LayerChromium> parent = LayerChromium::create();
     1615    RefPtr<LayerChromiumWithForcedDrawsContent> parentLayer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1616    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1617    parent->createRenderSurface();
     1618    parent->addChild(parentLayer);
     1619    parent->addChild(layer);
     1620
     1621    FilterOperations filters;
     1622    filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
     1623    parentLayer->setFilters(filters);
     1624    layer->setFilters(filters);
     1625
     1626    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
     1627    setLayerPropertiesForTesting(parentLayer.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300), false, opaqueLayers);
     1628    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true, opaqueLayers);
     1629
     1630    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     1631    Vector<RefPtr<LayerChromium> > dummyLayerList;
     1632    int dummyMaxTextureSize = 512;
     1633
     1634    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     1635    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     1636    renderSurfaceLayerList.append(parent);
     1637
     1638    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     1639
     1640    TestCCOcclusionTracker occlusion(IntRect(50, 50, 200, 200));
     1641
     1642    occlusion.enterTargetRenderSurface(layer->renderSurface());
     1643
     1644    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(0, 0, 100, 100)));
     1645    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(0, 100, 100, 100)));
     1646    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(100, 0, 100, 100)));
     1647    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(100, 100, 100, 100)));
     1648
     1649    occlusion.markOccludedBehindLayer(layer.get());
     1650    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1651    occlusion.enterTargetRenderSurface(parentLayer->renderSurface());
     1652
     1653    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 0, 100, 100)));
     1654    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 100, 100, 100)));
     1655    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 0, 100, 100)));
     1656    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 100, 100, 100)));
     1657    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(200, 100, 100, 100)));
     1658    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(200, 0, 100, 100)));
     1659    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(0, 200, 100, 100)));
     1660    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(100, 200, 100, 100)));
     1661    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(200, 200, 100, 100)));
     1662
     1663    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1664
     1665    EXPECT_EQ_RECT(IntRect(50, 50, 200, 200), occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 300)));
     1666    EXPECT_EQ_RECT(IntRect(200, 50, 50, 50), occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 100)));
     1667    EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent.get(), IntRect(0, 100, 300, 100)));
     1668    EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent.get(), IntRect(200, 100, 100, 100)));
     1669    EXPECT_EQ_RECT(IntRect(100, 200, 100, 50), occlusion.unoccludedContentRect(parent.get(), IntRect(100, 200, 100, 100)));
     1670}
     1671
     1672TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_screenScissorRectOverPartialTiles, screenScissorRectOverPartialTiles);
     1673
     1674void layerScissorRectOverNoTiles(bool opaqueLayers)
     1675{
     1676    const TransformationMatrix identityMatrix;
     1677    RefPtr<LayerChromium> parent = LayerChromium::create();
     1678    RefPtr<LayerChromiumWithForcedDrawsContent> parentLayer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1679    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1680    parent->createRenderSurface();
     1681    parent->addChild(parentLayer);
     1682    parent->addChild(layer);
     1683
     1684    FilterOperations filters;
     1685    filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
     1686    parentLayer->setFilters(filters);
     1687    layer->setFilters(filters);
     1688
     1689    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
     1690    setLayerPropertiesForTesting(parentLayer.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300), false, opaqueLayers);
     1691    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true, opaqueLayers);
     1692
     1693    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     1694    Vector<RefPtr<LayerChromium> > dummyLayerList;
     1695    int dummyMaxTextureSize = 512;
     1696
     1697    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     1698    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     1699    renderSurfaceLayerList.append(parent);
     1700
     1701    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     1702
     1703    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     1704    occlusion.setLayerScissorRect(IntRect(500, 500, 100, 100));
     1705
     1706    occlusion.enterTargetRenderSurface(layer->renderSurface());
     1707
     1708    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 0, 100, 100)));
     1709    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 100, 100, 100)));
     1710    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(100, 0, 100, 100)));
     1711    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(100, 100, 100, 100)));
     1712
     1713    occlusion.markOccludedBehindLayer(layer.get());
     1714    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1715    occlusion.enterTargetRenderSurface(parentLayer->renderSurface());
     1716
     1717    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 0, 100, 100)));
     1718    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 100, 100, 100)));
     1719    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 0, 100, 100)));
     1720    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 100, 100, 100)));
     1721    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 100, 100, 100)));
     1722    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 0, 100, 100)));
     1723    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 200, 100, 100)));
     1724    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 200, 100, 100)));
     1725    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 200, 100, 100)));
     1726
     1727    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1728
     1729    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 300)).isEmpty());
     1730    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 100)).isEmpty());
     1731    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(0, 100, 300, 100)).isEmpty());
     1732    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(200, 100, 100, 100)).isEmpty());
     1733    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(100, 200, 100, 100)).isEmpty());
     1734}
     1735
     1736TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_layerScissorRectOverNoTiles, layerScissorRectOverNoTiles);
     1737
     1738void screenScissorRectOverNoTiles(bool opaqueLayers)
     1739{
     1740    const TransformationMatrix identityMatrix;
     1741    RefPtr<LayerChromium> parent = LayerChromium::create();
     1742    RefPtr<LayerChromiumWithForcedDrawsContent> parentLayer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1743    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1744    parent->createRenderSurface();
     1745    parent->addChild(parentLayer);
     1746    parent->addChild(layer);
     1747
     1748    FilterOperations filters;
     1749    filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
     1750    parentLayer->setFilters(filters);
     1751    layer->setFilters(filters);
     1752
     1753    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
     1754    setLayerPropertiesForTesting(parentLayer.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300), false, opaqueLayers);
     1755    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true, opaqueLayers);
     1756
     1757    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     1758    Vector<RefPtr<LayerChromium> > dummyLayerList;
     1759    int dummyMaxTextureSize = 512;
     1760
     1761    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     1762    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     1763    renderSurfaceLayerList.append(parent);
     1764
     1765    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     1766
     1767    TestCCOcclusionTracker occlusion(IntRect(500, 500, 100, 100));
     1768
     1769    occlusion.enterTargetRenderSurface(layer->renderSurface());
     1770
     1771    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 0, 100, 100)));
     1772    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 100, 100, 100)));
     1773    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(100, 0, 100, 100)));
     1774    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(100, 100, 100, 100)));
     1775
     1776    occlusion.markOccludedBehindLayer(layer.get());
     1777    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1778    occlusion.enterTargetRenderSurface(parentLayer->renderSurface());
     1779
     1780    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 0, 100, 100)));
     1781    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 100, 100, 100)));
     1782    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 0, 100, 100)));
     1783    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 100, 100, 100)));
     1784    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 100, 100, 100)));
     1785    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 0, 100, 100)));
     1786    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 200, 100, 100)));
     1787    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 200, 100, 100)));
     1788    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 200, 100, 100)));
     1789
     1790    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1791
     1792    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 300)).isEmpty());
     1793    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 100)).isEmpty());
     1794    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(0, 100, 300, 100)).isEmpty());
     1795    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(200, 100, 100, 100)).isEmpty());
     1796    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(100, 200, 100, 100)).isEmpty());
     1797}
     1798
     1799TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_screenScissorRectOverNoTiles, screenScissorRectOverNoTiles);
     1800
     1801void layerScissorRectForLayerOffOrigin(bool opaqueLayers)
     1802{
     1803    const TransformationMatrix identityMatrix;
     1804    RefPtr<LayerChromium> parent = LayerChromium::create();
     1805    RefPtr<LayerChromiumWithForcedDrawsContent> parentLayer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1806    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1807    parent->createRenderSurface();
     1808    parent->addChild(parentLayer);
     1809    parent->addChild(layer);
     1810
     1811    FilterOperations filters;
     1812    filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
     1813    parentLayer->setFilters(filters);
     1814    layer->setFilters(filters);
     1815
     1816    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
     1817    setLayerPropertiesForTesting(parentLayer.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300), false, opaqueLayers);
     1818    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(100, 100), IntSize(200, 200), true, opaqueLayers);
     1819
     1820    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     1821    Vector<RefPtr<LayerChromium> > dummyLayerList;
     1822    int dummyMaxTextureSize = 512;
     1823
     1824    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     1825    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     1826    renderSurfaceLayerList.append(parent);
     1827
     1828    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     1829
     1830    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     1831
     1832    occlusion.enterTargetRenderSurface(layer->renderSurface());
     1833
     1834    // This layer is translated when drawn into its target. So if the scissor rect given from the target surface
     1835    // is not in that target space, then after translating these query rects into the target, they will fall outside
     1836    // the scissor and be considered occluded.
     1837    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(0, 0, 100, 100)));
     1838    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(0, 100, 100, 100)));
     1839    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(100, 0, 100, 100)));
     1840    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(100, 100, 100, 100)));
     1841}
     1842
     1843TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_layerScissorRectForLayerOffOrigin, layerScissorRectForLayerOffOrigin);
     1844
     1845void damageRectOverTile(bool opaqueLayers)
     1846{
     1847    const TransformationMatrix identityMatrix;
     1848    RefPtr<LayerChromium> parent = LayerChromium::create();
     1849    RefPtr<LayerChromiumWithForcedDrawsContent> parentLayer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1850    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1851    parent->createRenderSurface();
     1852    parent->addChild(parentLayer);
     1853    parent->addChild(layer);
     1854
     1855    FilterOperations filters;
     1856    filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
     1857    parentLayer->setFilters(filters);
     1858    layer->setFilters(filters);
     1859
     1860    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
     1861    setLayerPropertiesForTesting(parentLayer.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300), false, opaqueLayers);
     1862    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true, opaqueLayers);
     1863
     1864    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     1865    Vector<RefPtr<LayerChromium> > dummyLayerList;
     1866    int dummyMaxTextureSize = 512;
     1867
     1868    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     1869    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     1870    renderSurfaceLayerList.append(parent);
     1871
     1872    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     1873
     1874    TestDamageClient damage(FloatRect(200, 100, 100, 100));
     1875    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000), &damage);
     1876
     1877    occlusion.enterTargetRenderSurface(layer->renderSurface());
     1878
     1879    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 0, 100, 100)));
     1880    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(100, 0, 100, 100)));
     1881    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 100, 100, 100)));
     1882    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(100, 100, 100, 100)));
     1883
     1884    // Outside the layer's clip rect.
     1885    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(200, 100, 100, 100)));
     1886
     1887    occlusion.markOccludedBehindLayer(layer.get());
     1888    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1889    occlusion.enterTargetRenderSurface(parentLayer->renderSurface());
     1890
     1891    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 0, 100, 100)));
     1892    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 100, 100, 100)));
     1893    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 0, 100, 100)));
     1894    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 100, 100, 100)));
     1895    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(200, 100, 100, 100)));
     1896    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 0, 100, 100)));
     1897    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 200, 100, 100)));
     1898    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 200, 100, 100)));
     1899    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 200, 100, 100)));
     1900
     1901    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1902
     1903    EXPECT_EQ_RECT(IntRect(200, 100, 100, 100), occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 300)));
     1904}
     1905
     1906TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_damageRectOverTile, damageRectOverTile);
     1907
     1908void damageRectOverCulledTile(bool opaqueLayers)
     1909{
     1910    const TransformationMatrix identityMatrix;
     1911    RefPtr<LayerChromium> parent = LayerChromium::create();
     1912    RefPtr<LayerChromiumWithForcedDrawsContent> parentLayer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1913    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1914    parent->createRenderSurface();
     1915    parent->addChild(parentLayer);
     1916    parent->addChild(layer);
     1917
     1918    FilterOperations filters;
     1919    filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
     1920    parentLayer->setFilters(filters);
     1921    layer->setFilters(filters);
     1922
     1923    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
     1924    setLayerPropertiesForTesting(parentLayer.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300), false, opaqueLayers);
     1925    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true, opaqueLayers);
     1926
     1927    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     1928    Vector<RefPtr<LayerChromium> > dummyLayerList;
     1929    int dummyMaxTextureSize = 512;
     1930
     1931    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     1932    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     1933    renderSurfaceLayerList.append(parent);
     1934
     1935    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     1936
     1937    TestDamageClient damage(FloatRect(100, 100, 100, 100));
     1938    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000), &damage);
     1939
     1940    occlusion.enterTargetRenderSurface(layer->renderSurface());
     1941
     1942    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 0, 100, 100)));
     1943    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 100, 100, 100)));
     1944    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(100, 0, 100, 100)));
     1945    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(100, 100, 100, 100)));
     1946
     1947    occlusion.markOccludedBehindLayer(layer.get());
     1948    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1949    occlusion.enterTargetRenderSurface(parentLayer->renderSurface());
     1950
     1951    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 0, 100, 100)));
     1952    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 100, 100, 100)));
     1953    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 0, 100, 100)));
     1954    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 100, 100, 100)));
     1955    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 100, 100, 100)));
     1956    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 0, 100, 100)));
     1957    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 200, 100, 100)));
     1958    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 200, 100, 100)));
     1959    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 200, 100, 100)));
     1960
     1961    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     1962
     1963    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 300)).isEmpty());
     1964}
     1965
     1966TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_damageRectOverCulledTile, damageRectOverCulledTile);
     1967
     1968void damageRectOverPartialTiles(bool opaqueLayers)
     1969{
     1970    const TransformationMatrix identityMatrix;
     1971    RefPtr<LayerChromium> parent = LayerChromium::create();
     1972    RefPtr<LayerChromiumWithForcedDrawsContent> parentLayer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1973    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     1974    parent->createRenderSurface();
     1975    parent->addChild(parentLayer);
     1976    parent->addChild(layer);
     1977
     1978    FilterOperations filters;
     1979    filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
     1980    parentLayer->setFilters(filters);
     1981    layer->setFilters(filters);
     1982
     1983    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
     1984    setLayerPropertiesForTesting(parentLayer.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300), false, opaqueLayers);
     1985    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true, opaqueLayers);
     1986
     1987    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     1988    Vector<RefPtr<LayerChromium> > dummyLayerList;
     1989    int dummyMaxTextureSize = 512;
     1990
     1991    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     1992    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     1993    renderSurfaceLayerList.append(parent);
     1994
     1995    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     1996
     1997    TestDamageClient damage(FloatRect(50, 50, 200, 200));
     1998    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000), &damage);
     1999
     2000    occlusion.enterTargetRenderSurface(layer->renderSurface());
     2001
     2002    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(0, 0, 100, 100)));
     2003    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(0, 100, 100, 100)));
     2004    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(100, 0, 100, 100)));
     2005    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(100, 100, 100, 100)));
     2006
     2007    occlusion.markOccludedBehindLayer(layer.get());
     2008    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     2009    occlusion.enterTargetRenderSurface(parentLayer->renderSurface());
     2010
     2011    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 0, 100, 100)));
     2012    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 100, 100, 100)));
     2013    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 0, 100, 100)));
     2014    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 100, 100, 100)));
     2015    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(200, 100, 100, 100)));
     2016    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(200, 0, 100, 100)));
     2017    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(0, 200, 100, 100)));
     2018    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(100, 200, 100, 100)));
     2019    EXPECT_FALSE(occlusion.occluded(parentLayer.get(), IntRect(200, 200, 100, 100)));
     2020
     2021    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     2022
     2023    EXPECT_EQ_RECT(IntRect(50, 50, 200, 200), occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 300)));
     2024    EXPECT_EQ_RECT(IntRect(200, 50, 50, 50), occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 100)));
     2025    EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent.get(), IntRect(0, 100, 300, 100)));
     2026    EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent.get(), IntRect(200, 100, 100, 100)));
     2027    EXPECT_EQ_RECT(IntRect(100, 200, 100, 50), occlusion.unoccludedContentRect(parent.get(), IntRect(100, 200, 100, 100)));
     2028}
     2029
     2030TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_damageRectOverPartialTiles, damageRectOverPartialTiles);
     2031
     2032void damageRectOverNoTiles(bool opaqueLayers)
     2033{
     2034    const TransformationMatrix identityMatrix;
     2035    RefPtr<LayerChromium> parent = LayerChromium::create();
     2036    RefPtr<LayerChromiumWithForcedDrawsContent> parentLayer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     2037    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     2038    parent->createRenderSurface();
     2039    parent->addChild(parentLayer);
     2040    parent->addChild(layer);
     2041
     2042    FilterOperations filters;
     2043    filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
     2044    parentLayer->setFilters(filters);
     2045    layer->setFilters(filters);
     2046
     2047    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
     2048    setLayerPropertiesForTesting(parentLayer.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300), false, opaqueLayers);
     2049    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true, opaqueLayers);
     2050
     2051    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     2052    Vector<RefPtr<LayerChromium> > dummyLayerList;
     2053    int dummyMaxTextureSize = 512;
     2054
     2055    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     2056    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     2057    renderSurfaceLayerList.append(parent);
     2058
     2059    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     2060
     2061    TestDamageClient damage(FloatRect(500, 500, 100, 100));
     2062    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000), &damage);
     2063
     2064    occlusion.enterTargetRenderSurface(layer->renderSurface());
     2065
     2066    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 0, 100, 100)));
     2067    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(0, 100, 100, 100)));
     2068    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(100, 0, 100, 100)));
     2069    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(100, 100, 100, 100)));
     2070
     2071    occlusion.markOccludedBehindLayer(layer.get());
     2072    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     2073    occlusion.enterTargetRenderSurface(parentLayer->renderSurface());
     2074
     2075    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 0, 100, 100)));
     2076    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 100, 100, 100)));
     2077    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 0, 100, 100)));
     2078    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 100, 100, 100)));
     2079    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 100, 100, 100)));
     2080    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 0, 100, 100)));
     2081    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(0, 200, 100, 100)));
     2082    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(100, 200, 100, 100)));
     2083    EXPECT_TRUE(occlusion.occluded(parentLayer.get(), IntRect(200, 200, 100, 100)));
     2084
     2085    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     2086
     2087    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 300)).isEmpty());
     2088    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(0, 0, 300, 100)).isEmpty());
     2089    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(0, 100, 300, 100)).isEmpty());
     2090    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(200, 100, 100, 100)).isEmpty());
     2091    EXPECT_TRUE(occlusion.unoccludedContentRect(parent.get(), IntRect(100, 200, 100, 100)).isEmpty());
     2092}
     2093
     2094TEST_OPAQUE_AND_PAINTED_OPAQUE(CCOcclusionTrackerTest_damageRectOverNoTiles, damageRectOverNoTiles);
     2095
     2096TEST(CCOcclusionTrackerTest, opaqueContentsRegionEmpty)
     2097{
     2098    const TransformationMatrix identityMatrix;
     2099    RefPtr<LayerChromium> parent = LayerChromium::create();
     2100    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     2101    parent->createRenderSurface();
     2102    parent->addChild(layer);
     2103
     2104    FilterOperations filters;
     2105    filters.operations().append(BasicComponentTransferFilterOperation::create(0.5, FilterOperation::GRAYSCALE));
     2106    layer->setFilters(filters);
     2107
     2108    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
     2109    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(0, 0), IntSize(200, 200), false, false);
     2110
     2111    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     2112    Vector<RefPtr<LayerChromium> > dummyLayerList;
     2113    int dummyMaxTextureSize = 512;
     2114
     2115    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     2116    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     2117    renderSurfaceLayerList.append(parent);
     2118
     2119    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     2120
     2121    TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     2122
     2123    occlusion.enterTargetRenderSurface(layer->renderSurface());
     2124
     2125    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(0, 0, 100, 100)));
     2126    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(100, 0, 100, 100)));
     2127    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(0, 100, 100, 100)));
     2128    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(100, 100, 100, 100)));
     2129
     2130    // Occluded since its outside the surface bounds.
     2131    EXPECT_TRUE(occlusion.occluded(layer.get(), IntRect(200, 100, 100, 100)));
     2132
     2133    // Test without any scissors.
     2134    occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
     2135    EXPECT_FALSE(occlusion.occluded(layer.get(), IntRect(200, 100, 100, 100)));
     2136    occlusion.useDefaultLayerScissorRect();
     2137
     2138    occlusion.markOccludedBehindLayer(layer.get());
     2139    occlusion.leaveToTargetRenderSurface(parent->renderSurface());
     2140
     2141    EXPECT_TRUE(occlusion.occlusionInScreenSpace().bounds().isEmpty());
     2142    EXPECT_EQ(0u, occlusion.occlusionInScreenSpace().rects().size());
     2143}
     2144
     2145TEST(CCOcclusionTrackerTest, opaqueContentsRegionNonEmpty)
     2146{
     2147    const TransformationMatrix identityMatrix;
     2148    RefPtr<LayerChromium> parent = LayerChromium::create();
     2149    RefPtr<LayerChromiumWithForcedDrawsContent> layer = adoptRef(new LayerChromiumWithForcedDrawsContent());
     2150    parent->createRenderSurface();
     2151    parent->addChild(layer);
     2152
     2153    setLayerPropertiesForTesting(parent.get(), identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
     2154    setLayerPropertiesForTesting(layer.get(), identityMatrix, FloatPoint(100, 100), IntSize(200, 200), false, false);
     2155
     2156    Vector<RefPtr<LayerChromium> > renderSurfaceLayerList;
     2157    Vector<RefPtr<LayerChromium> > dummyLayerList;
     2158    int dummyMaxTextureSize = 512;
     2159
     2160    parent->renderSurface()->setContentRect(IntRect(IntPoint::zero(), parent->bounds()));
     2161    parent->setClipRect(IntRect(IntPoint::zero(), parent->bounds()));
     2162    renderSurfaceLayerList.append(parent);
     2163
     2164    CCLayerTreeHostCommon::calculateDrawTransformsAndVisibility(parent.get(), parent.get(), identityMatrix, identityMatrix, renderSurfaceLayerList, dummyLayerList, dummyMaxTextureSize);
     2165
     2166    {
     2167        TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     2168        layer->setOpaquePaintRect(IntRect(0, 0, 100, 100));
     2169
     2170        occlusion.enterTargetRenderSurface(parent->renderSurface());
     2171        occlusion.markOccludedBehindLayer(layer.get());
     2172
     2173        EXPECT_EQ_RECT(IntRect(100, 100, 100, 100), occlusion.occlusionInScreenSpace().bounds());
    11232174        EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    1124         EXPECT_EQ_RECT(IntRect(0, 430, 70, 70), occlusion.occlusionInTargetSurface().bounds());
    1125         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
    1126 
    1127         // And it gets translated to the parent surface.
    1128         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1129         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
     2175
     2176        EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(0, 100, 100, 100)));
     2177        EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(100, 100, 100, 100)));
     2178        EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(200, 200, 100, 100)));
     2179    }
     2180
     2181    {
     2182        TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     2183        layer->setOpaquePaintRect(IntRect(20, 20, 180, 180));
     2184
     2185        occlusion.enterTargetRenderSurface(parent->renderSurface());
     2186        occlusion.markOccludedBehindLayer(layer.get());
     2187
     2188        EXPECT_EQ_RECT(IntRect(120, 120, 180, 180), occlusion.occlusionInScreenSpace().bounds());
    11302189        EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    1131         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
    1132         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
    1133 
    1134         // The blur layer needs to throw away any occlusion from outside its subtree.
    1135         occlusion.enterTargetRenderSurface(blurLayer->renderSurface());
    1136         EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
    1137         EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
    1138 
    1139         // And it won't contribute to occlusion.
    1140         occlusion.markOccludedBehindLayer(blurLayer);
    1141         occlusion.finishedTargetRenderSurface(blurLayer, blurLayer->renderSurface());
    1142         EXPECT_TRUE(occlusion.occlusionInScreenSpace().isEmpty());
    1143         EXPECT_TRUE(occlusion.occlusionInTargetSurface().isEmpty());
    1144 
    1145         // But the opaque layer's occlusion is preserved on the parent.
    1146         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1147         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInScreenSpace().bounds());
     2190
     2191        EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(0, 100, 100, 100)));
     2192        EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(100, 100, 100, 100)));
     2193        EXPECT_TRUE(occlusion.occluded(parent.get(), IntRect(200, 200, 100, 100)));
     2194    }
     2195
     2196    {
     2197        TestCCOcclusionTracker occlusion(IntRect(0, 0, 1000, 1000));
     2198        layer->setOpaquePaintRect(IntRect(150, 150, 100, 100));
     2199
     2200        occlusion.enterTargetRenderSurface(parent->renderSurface());
     2201        occlusion.markOccludedBehindLayer(layer.get());
     2202
     2203        EXPECT_EQ_RECT(IntRect(250, 250, 50, 50), occlusion.occlusionInScreenSpace().bounds());
    11482204        EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    1149         EXPECT_EQ_RECT(IntRect(30, 30, 70, 70), occlusion.occlusionInTargetSurface().bounds());
    1150         EXPECT_EQ(1u, occlusion.occlusionInTargetSurface().rects().size());
     2205
     2206        EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(0, 100, 100, 100)));
     2207        EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(100, 100, 100, 100)));
     2208        EXPECT_FALSE(occlusion.occluded(parent.get(), IntRect(200, 200, 100, 100)));
    11512209    }
    1152 };
    1153 
    1154 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestFilters);
    1155 
    1156 template<class Types, bool opaqueLayers>
    1157 class CCOcclusionTrackerTestLayerScissorRectOutsideChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    1158 protected:
    1159     void runMyTest()
    1160     {
    1161         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
    1162         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
    1163         calcDrawEtc(parent);
    1164 
    1165         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    1166         occlusion.setLayerScissorRect(IntRect(200, 100, 100, 100));
    1167 
    1168         occlusion.enterTargetRenderSurface(layer->renderSurface());
    1169 
    1170         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
    1171         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
    1172         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
    1173         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
    1174         EXPECT_FALSE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
    1175 
    1176         occlusion.useDefaultLayerScissorRect();
    1177         EXPECT_TRUE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
    1178         occlusion.setLayerScissorRect(IntRect(200, 100, 100, 100));
    1179 
    1180         occlusion.markOccludedBehindLayer(layer);
    1181         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1182 
    1183         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
    1184         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
    1185         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
    1186         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
    1187         EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
    1188         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
    1189         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
    1190         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
    1191         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
    1192 
    1193         EXPECT_EQ_RECT(IntRect(200, 100, 100, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
    1194     }
    1195 };
    1196 
    1197 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestLayerScissorRectOutsideChild);
    1198 
    1199 template<class Types, bool opaqueLayers>
    1200 class CCOcclusionTrackerTestScreenScissorRectOutsideChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    1201 protected:
    1202     void runMyTest()
    1203     {
    1204         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
    1205         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
    1206         calcDrawEtc(parent);
    1207 
    1208         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(200, 100, 100, 100));
    1209         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    1210 
    1211         occlusion.enterTargetRenderSurface(layer->renderSurface());
    1212 
    1213         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
    1214         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
    1215         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
    1216         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
    1217         EXPECT_FALSE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
    1218 
    1219         occlusion.useDefaultLayerScissorRect();
    1220         EXPECT_TRUE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
    1221         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    1222 
    1223         occlusion.markOccludedBehindLayer(layer);
    1224         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1225 
    1226         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
    1227         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
    1228         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
    1229         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
    1230         EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
    1231         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
    1232         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
    1233         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
    1234         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
    1235 
    1236         EXPECT_EQ_RECT(IntRect(200, 100, 100, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
    1237     }
    1238 };
    1239 
    1240 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestScreenScissorRectOutsideChild);
    1241 
    1242 template<class Types, bool opaqueLayers>
    1243 class CCOcclusionTrackerTestDamageRectOutsideChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    1244 protected:
    1245     void runMyTest()
    1246     {
    1247         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
    1248         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
    1249         calcDrawEtc(parent);
    1250 
    1251         TestDamageClient<typename Types::RenderSurfaceType> damage(FloatRect(200, 100, 100, 100));
    1252         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000), &damage);
    1253 
    1254         occlusion.enterTargetRenderSurface(layer->renderSurface());
    1255 
    1256         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 200, 200)).isEmpty());
    1257 
    1258         occlusion.markOccludedBehindLayer(layer);
    1259         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1260 
    1261         EXPECT_EQ_RECT(IntRect(200, 100, 100, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
    1262     }
    1263 };
    1264 
    1265 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestDamageRectOutsideChild);
    1266 
    1267 template<class Types, bool opaqueLayers>
    1268 class CCOcclusionTrackerTestLayerScissorRectOverChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    1269 protected:
    1270     void runMyTest()
    1271     {
    1272         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
    1273         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
    1274         calcDrawEtc(parent);
    1275 
    1276         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    1277         occlusion.setLayerScissorRect(IntRect(100, 100, 100, 100));
    1278 
    1279         occlusion.enterTargetRenderSurface(layer->renderSurface());
    1280 
    1281         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
    1282         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
    1283         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
    1284         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
    1285 
    1286         occlusion.markOccludedBehindLayer(layer);
    1287         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1288 
    1289         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
    1290         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
    1291         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
    1292         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
    1293         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
    1294         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
    1295         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
    1296         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
    1297         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
    1298 
    1299         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
    1300     }
    1301 };
    1302 
    1303 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestLayerScissorRectOverChild);
    1304 
    1305 template<class Types, bool opaqueLayers>
    1306 class CCOcclusionTrackerTestScreenScissorRectOverChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    1307 protected:
    1308     void runMyTest()
    1309     {
    1310         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
    1311         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
    1312         calcDrawEtc(parent);
    1313 
    1314         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(100, 100, 100, 100));
    1315         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    1316 
    1317         occlusion.enterTargetRenderSurface(layer->renderSurface());
    1318 
    1319         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
    1320         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
    1321         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
    1322         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
    1323 
    1324         occlusion.markOccludedBehindLayer(layer);
    1325         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1326 
    1327         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
    1328         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
    1329         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
    1330         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
    1331         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
    1332         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
    1333         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
    1334         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
    1335         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
    1336 
    1337         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
    1338     }
    1339 };
    1340 
    1341 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestScreenScissorRectOverChild);
    1342 
    1343 template<class Types, bool opaqueLayers>
    1344 class CCOcclusionTrackerTestDamageRectOverChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    1345 protected:
    1346     void runMyTest()
    1347     {
    1348         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
    1349         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
    1350         calcDrawEtc(parent);
    1351 
    1352         TestDamageClient<typename Types::RenderSurfaceType> damage(FloatRect(100, 100, 100, 100));
    1353         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000), &damage);
    1354 
    1355         occlusion.enterTargetRenderSurface(layer->renderSurface());
    1356 
    1357         EXPECT_EQ_RECT(IntRect(100, 100, 100, 100), occlusion.unoccludedContentRect(layer, IntRect(0, 0, 200, 200)));
    1358 
    1359         occlusion.markOccludedBehindLayer(layer);
    1360         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1361 
    1362         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
    1363     }
    1364 };
    1365 
    1366 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestDamageRectOverChild);
    1367 
    1368 template<class Types, bool opaqueLayers>
    1369 class CCOcclusionTrackerTestLayerScissorRectPartlyOverChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    1370 protected:
    1371     void runMyTest()
    1372     {
    1373         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
    1374         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
    1375         calcDrawEtc(parent);
    1376 
    1377         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    1378         occlusion.setLayerScissorRect(IntRect(50, 50, 200, 200));
    1379 
    1380         occlusion.enterTargetRenderSurface(layer->renderSurface());
    1381 
    1382         EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
    1383         EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
    1384         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
    1385         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
    1386 
    1387         occlusion.markOccludedBehindLayer(layer);
    1388         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1389 
    1390         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
    1391         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
    1392         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
    1393         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
    1394         EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
    1395         EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
    1396         EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
    1397         EXPECT_FALSE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
    1398         EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
    1399 
    1400         EXPECT_EQ_RECT(IntRect(50, 50, 200, 200), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
    1401         EXPECT_EQ_RECT(IntRect(200, 50, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 100)));
    1402         EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 100, 300, 100)));
    1403         EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent, IntRect(200, 100, 100, 100)));
    1404         EXPECT_EQ_RECT(IntRect(100, 200, 100, 50), occlusion.unoccludedContentRect(parent, IntRect(100, 200, 100, 100)));
    1405     }
    1406 };
    1407 
    1408 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestLayerScissorRectPartlyOverChild);
    1409 
    1410 template<class Types, bool opaqueLayers>
    1411 class CCOcclusionTrackerTestScreenScissorRectPartlyOverChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    1412 protected:
    1413     void runMyTest()
    1414     {
    1415         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
    1416         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
    1417         calcDrawEtc(parent);
    1418 
    1419         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(50, 50, 200, 200));
    1420         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    1421 
    1422         occlusion.enterTargetRenderSurface(layer->renderSurface());
    1423 
    1424         EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
    1425         EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
    1426         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
    1427         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
    1428 
    1429         occlusion.markOccludedBehindLayer(layer);
    1430         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1431 
    1432         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
    1433         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
    1434         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
    1435         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
    1436         EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
    1437         EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
    1438         EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
    1439         EXPECT_FALSE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
    1440         EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
    1441 
    1442         EXPECT_EQ_RECT(IntRect(50, 50, 200, 200), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
    1443         EXPECT_EQ_RECT(IntRect(200, 50, 50, 50), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 100)));
    1444         EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent, IntRect(0, 100, 300, 100)));
    1445         EXPECT_EQ_RECT(IntRect(200, 100, 50, 100), occlusion.unoccludedContentRect(parent, IntRect(200, 100, 100, 100)));
    1446         EXPECT_EQ_RECT(IntRect(100, 200, 100, 50), occlusion.unoccludedContentRect(parent, IntRect(100, 200, 100, 100)));
    1447     }
    1448 };
    1449 
    1450 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestScreenScissorRectPartlyOverChild);
    1451 
    1452 template<class Types, bool opaqueLayers>
    1453 class CCOcclusionTrackerTestDamageRectPartlyOverChild : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    1454 protected:
    1455     void runMyTest()
    1456     {
    1457         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
    1458         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
    1459         calcDrawEtc(parent);
    1460 
    1461         TestDamageClient<typename Types::RenderSurfaceType> damage(FloatRect(50, 50, 200, 200));
    1462         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000), &damage);
    1463 
    1464         occlusion.enterTargetRenderSurface(layer->renderSurface());
    1465 
    1466         EXPECT_EQ_RECT(IntRect(50, 50, 150, 150), occlusion.unoccludedContentRect(layer, IntRect(0, 0, 200, 200)));
    1467 
    1468         occlusion.markOccludedBehindLayer(layer);
    1469         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1470 
    1471         EXPECT_EQ_RECT(IntRect(50, 50, 200, 200), occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)));
    1472     }
    1473 };
    1474 
    1475 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestDamageRectPartlyOverChild);
    1476 
    1477 template<class Types, bool opaqueLayers>
    1478 class CCOcclusionTrackerTestLayerScissorRectOverNothing : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    1479 protected:
    1480     void runMyTest()
    1481     {
    1482         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
    1483         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
    1484         calcDrawEtc(parent);
    1485 
    1486         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    1487         occlusion.setLayerScissorRect(IntRect(500, 500, 100, 100));
    1488 
    1489         occlusion.enterTargetRenderSurface(layer->renderSurface());
    1490 
    1491         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
    1492         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
    1493         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
    1494         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
    1495 
    1496         occlusion.markOccludedBehindLayer(layer);
    1497         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1498 
    1499         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
    1500         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
    1501         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
    1502         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
    1503         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
    1504         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
    1505         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
    1506         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
    1507         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
    1508 
    1509         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
    1510         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 100)).isEmpty());
    1511         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 100, 300, 100)).isEmpty());
    1512         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(200, 100, 100, 100)).isEmpty());
    1513         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(100, 200, 100, 100)).isEmpty());
    1514     }
    1515 };
    1516 
    1517 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestLayerScissorRectOverNothing);
    1518 
    1519 template<class Types, bool opaqueLayers>
    1520 class CCOcclusionTrackerTestScreenScissorRectOverNothing : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    1521 protected:
    1522     void runMyTest()
    1523     {
    1524         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
    1525         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
    1526         calcDrawEtc(parent);
    1527 
    1528         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(500, 500, 100, 100));
    1529         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    1530 
    1531         occlusion.enterTargetRenderSurface(layer->renderSurface());
    1532 
    1533         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
    1534         EXPECT_TRUE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
    1535         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
    1536         EXPECT_TRUE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
    1537 
    1538         occlusion.markOccludedBehindLayer(layer);
    1539         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1540 
    1541         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 0, 100, 100)));
    1542         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
    1543         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 0, 100, 100)));
    1544         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
    1545         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 100, 100, 100)));
    1546         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 0, 100, 100)));
    1547         EXPECT_TRUE(occlusion.occluded(parent, IntRect(0, 200, 100, 100)));
    1548         EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 200, 100, 100)));
    1549         EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
    1550 
    1551         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
    1552         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 100)).isEmpty());
    1553         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 100, 300, 100)).isEmpty());
    1554         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(200, 100, 100, 100)).isEmpty());
    1555         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(100, 200, 100, 100)).isEmpty());
    1556     }
    1557 };
    1558 
    1559 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestScreenScissorRectOverNothing);
    1560 
    1561 template<class Types, bool opaqueLayers>
    1562 class CCOcclusionTrackerTestDamageRectOverNothing : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    1563 protected:
    1564     void runMyTest()
    1565     {
    1566         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
    1567         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
    1568         calcDrawEtc(parent);
    1569 
    1570         TestDamageClient<typename Types::RenderSurfaceType> damage(FloatRect(500, 500, 100, 100));
    1571         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000), &damage);
    1572 
    1573         occlusion.enterTargetRenderSurface(layer->renderSurface());
    1574 
    1575         EXPECT_TRUE(occlusion.unoccludedContentRect(layer, IntRect(0, 0, 200, 200)).isEmpty());
    1576 
    1577         occlusion.markOccludedBehindLayer(layer);
    1578         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1579 
    1580         EXPECT_TRUE(occlusion.unoccludedContentRect(parent, IntRect(0, 0, 300, 300)).isEmpty());
    1581     }
    1582 };
    1583 
    1584 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestDamageRectOverNothing);
    1585 
    1586 template<class Types, bool opaqueLayers>
    1587 class CCOcclusionTrackerTestLayerScissorRectForLayerOffOrigin : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    1588 protected:
    1589     void runMyTest()
    1590     {
    1591         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
    1592         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), true);
    1593         calcDrawEtc(parent);
    1594 
    1595         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    1596         occlusion.enterTargetRenderSurface(layer->renderSurface());
    1597 
    1598         // This layer is translated when drawn into its target. So if the scissor rect given from the target surface
    1599         // is not in that target space, then after translating these query rects into the target, they will fall outside
    1600         // the scissor and be considered occluded.
    1601         EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
    1602         EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
    1603         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
    1604         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
    1605     }
    1606 };
    1607 
    1608 ALL_CCOCCLUSIONTRACKER_TEST(CCOcclusionTrackerTestLayerScissorRectForLayerOffOrigin);
    1609 
    1610 template<class Types, bool opaqueLayers>
    1611 class CCOcclusionTrackerTestOpaqueContentsRegionEmpty : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    1612 protected:
    1613     void runMyTest()
    1614     {
    1615         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
    1616         typename Types::ContentLayerType* layer = this->createDrawingSurface(parent, this->identityMatrix, FloatPoint(0, 0), IntSize(200, 200), false);
    1617         calcDrawEtc(parent);
    1618 
    1619         TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    1620         occlusion.enterTargetRenderSurface(layer->renderSurface());
    1621 
    1622         EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 0, 100, 100)));
    1623         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 0, 100, 100)));
    1624         EXPECT_FALSE(occlusion.occluded(layer, IntRect(0, 100, 100, 100)));
    1625         EXPECT_FALSE(occlusion.occluded(layer, IntRect(100, 100, 100, 100)));
    1626 
    1627         // Occluded since its outside the surface bounds.
    1628         EXPECT_TRUE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
    1629 
    1630         // Test without any scissors.
    1631         occlusion.setLayerScissorRect(IntRect(0, 0, 1000, 1000));
    1632         EXPECT_FALSE(occlusion.occluded(layer, IntRect(200, 100, 100, 100)));
    1633         occlusion.useDefaultLayerScissorRect();
    1634 
    1635         occlusion.markOccludedBehindLayer(layer);
    1636         occlusion.leaveToTargetRenderSurface(parent->renderSurface());
    1637 
    1638         EXPECT_TRUE(occlusion.occlusionInScreenSpace().bounds().isEmpty());
    1639         EXPECT_EQ(0u, occlusion.occlusionInScreenSpace().rects().size());
    1640     }
    1641 };
    1642 
    1643 MAIN_AND_IMPL_THREAD_TEST(CCOcclusionTrackerTestOpaqueContentsRegionEmpty);
    1644 
    1645 template<class Types, bool opaqueLayers>
    1646 class CCOcclusionTrackerTestOpaqueContentsRegionNonEmpty : public CCOcclusionTrackerTest<Types, opaqueLayers> {
    1647 protected:
    1648     void runMyTest()
    1649     {
    1650         typename Types::ContentLayerType* parent = this->createRoot(this->identityMatrix, FloatPoint(0, 0), IntSize(300, 300));
    1651         typename Types::ContentLayerType* layer = this->createDrawingLayer(parent, this->identityMatrix, FloatPoint(100, 100), IntSize(200, 200), false);
    1652         calcDrawEtc(parent);
    1653 
    1654         {
    1655             TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    1656             layer->setOpaqueContentsRect(IntRect(0, 0, 100, 100));
    1657 
    1658             occlusion.enterTargetRenderSurface(parent->renderSurface());
    1659             occlusion.markOccludedBehindLayer(layer);
    1660 
    1661             EXPECT_EQ_RECT(IntRect(100, 100, 100, 100), occlusion.occlusionInScreenSpace().bounds());
    1662             EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    1663 
    1664             EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
    1665             EXPECT_TRUE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
    1666             EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
    1667         }
    1668 
    1669         {
    1670             TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    1671             layer->setOpaqueContentsRect(IntRect(20, 20, 180, 180));
    1672 
    1673             occlusion.enterTargetRenderSurface(parent->renderSurface());
    1674             occlusion.markOccludedBehindLayer(layer);
    1675 
    1676             EXPECT_EQ_RECT(IntRect(120, 120, 180, 180), occlusion.occlusionInScreenSpace().bounds());
    1677             EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    1678 
    1679             EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
    1680             EXPECT_FALSE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
    1681             EXPECT_TRUE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
    1682         }
    1683 
    1684         {
    1685             TestCCOcclusionTrackerBase<typename Types::LayerType, typename Types::RenderSurfaceType> occlusion(IntRect(0, 0, 1000, 1000));
    1686             layer->setOpaqueContentsRect(IntRect(150, 150, 100, 100));
    1687 
    1688             occlusion.enterTargetRenderSurface(parent->renderSurface());
    1689             occlusion.markOccludedBehindLayer(layer);
    1690 
    1691             EXPECT_EQ_RECT(IntRect(250, 250, 50, 50), occlusion.occlusionInScreenSpace().bounds());
    1692             EXPECT_EQ(1u, occlusion.occlusionInScreenSpace().rects().size());
    1693 
    1694             EXPECT_FALSE(occlusion.occluded(parent, IntRect(0, 100, 100, 100)));
    1695             EXPECT_FALSE(occlusion.occluded(parent, IntRect(100, 100, 100, 100)));
    1696             EXPECT_FALSE(occlusion.occluded(parent, IntRect(200, 200, 100, 100)));
    1697         }
    1698     }
    1699 };
    1700 
    1701 MAIN_AND_IMPL_THREAD_TEST(CCOcclusionTrackerTestOpaqueContentsRegionNonEmpty);
     2210}
    17022211
    17032212} // namespace
Note: See TracChangeset for help on using the changeset viewer.