| OLD | NEW | 
|---|
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 #include "cc/layer_tree_host.h" | 5 #include "cc/layer_tree_host.h" | 
| 6 | 6 | 
| 7 #include "base/synchronization/lock.h" | 7 #include "base/synchronization/lock.h" | 
| 8 #include "cc/content_layer.h" | 8 #include "cc/content_layer.h" | 
| 9 #include "cc/content_layer_client.h" | 9 #include "cc/content_layer_client.h" | 
| 10 #include "cc/layer_impl.h" | 10 #include "cc/layer_impl.h" | 
| (...skipping 1971 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 1982         endTest(); | 1982         endTest(); | 
| 1983     } | 1983     } | 
| 1984 | 1984 | 
| 1985     virtual void afterTest() OVERRIDE | 1985     virtual void afterTest() OVERRIDE | 
| 1986     { | 1986     { | 
| 1987     } | 1987     } | 
| 1988 }; | 1988 }; | 
| 1989 | 1989 | 
| 1990 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestManySurfaces) | 1990 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestManySurfaces) | 
| 1991 | 1991 | 
| 1992 // A loseOutputSurface(1) should lead to a didRecreateOutputSurface(true) | 1992 // Losing the context should lead to a didRecreateOutputSurface(true). | 
| 1993 class LayerTreeHostTestSetSingleLostContext : public LayerTreeHostTest { | 1993 class LayerTreeHostTestSetSingleLostContext : public LayerTreeHostTest { | 
| 1994 public: | 1994 public: | 
| 1995     LayerTreeHostTestSetSingleLostContext() | 1995     LayerTreeHostTestSetSingleLostContext() | 
|  | 1996         : m_context3d(NULL) | 
|  | 1997         , m_timesToLose(1) | 
|  | 1998         , m_timesToLoseDuringDraw(1) | 
| 1996     { | 1999     { | 
| 1997     } | 2000     } | 
| 1998 | 2001 | 
|  | 2002     virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE | 
|  | 2003     { | 
|  | 2004         scoped_ptr<CompositorFakeWebGraphicsContext3DWithTextureTracking> contex
      t3d = | 
|  | 2005                 CompositorFakeWebGraphicsContext3DWithTextureTracking::create(We
      bKit::WebGraphicsContext3D::Attributes()); | 
|  | 2006         m_context3d = context3d.get(); | 
|  | 2007         return FakeOutputSurface::Create3d(context3d.PassAs<WebKit::WebGraphicsC
      ontext3D>()).PassAs<OutputSurface>(); | 
|  | 2008     } | 
|  | 2009 | 
| 1999     virtual void beginTest() OVERRIDE | 2010     virtual void beginTest() OVERRIDE | 
| 2000     { | 2011     { | 
| 2001         postSetNeedsCommitToMainThread(); | 2012         postSetNeedsCommitToMainThread(); | 
| 2002     } | 2013     } | 
| 2003 | 2014 | 
| 2004     virtual void didCommitAndDrawFrame() OVERRIDE | 2015     virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE | 
| 2005     { | 2016     { | 
| 2006         m_layerTreeHost->loseOutputSurface(1); | 2017         if (!m_timesToLose) | 
|  | 2018             return; | 
|  | 2019         m_context3d->loseContext(); | 
|  | 2020         m_context3d = NULL; | 
|  | 2021         --m_timesToLose; | 
|  | 2022     } | 
|  | 2023 | 
|  | 2024     virtual void drawLayersOnThread(LayerTreeHostImpl* impl) OVERRIDE | 
|  | 2025     { | 
|  | 2026         // Lose during commit first, then during draw. | 
|  | 2027         if (m_timesToLose || !m_timesToLoseDuringDraw || !m_context3d) | 
|  | 2028             return; | 
|  | 2029         m_context3d->loseContext(); | 
|  | 2030         m_context3d = NULL; | 
|  | 2031         --m_timesToLoseDuringDraw; | 
| 2007     } | 2032     } | 
| 2008 | 2033 | 
| 2009     virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE | 2034     virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE | 
| 2010     { | 2035     { | 
| 2011         EXPECT_TRUE(succeeded); | 2036         EXPECT_TRUE(succeeded); | 
| 2012         endTest(); | 2037         if (!m_timesToLose && !m_timesToLoseDuringDraw) | 
|  | 2038             endTest(); | 
| 2013     } | 2039     } | 
| 2014 | 2040 | 
| 2015     virtual void afterTest() OVERRIDE | 2041     virtual void afterTest() OVERRIDE | 
| 2016     { | 2042     { | 
| 2017     } | 2043     } | 
|  | 2044 | 
|  | 2045 private: | 
|  | 2046     FakeWebGraphicsContext3D* m_context3d; | 
|  | 2047     int m_timesToLose; | 
|  | 2048     int m_timesToLoseDuringDraw; | 
| 2018 }; | 2049 }; | 
| 2019 | 2050 | 
| 2020 TEST_F(LayerTreeHostTestSetSingleLostContext, runMultiThread) | 2051 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetSingleLostContext) | 
| 2021 { |  | 
| 2022     runTest(true); |  | 
| 2023 } |  | 
| 2024 | 2052 | 
| 2025 // A loseOutputSurface(10) should lead to a didRecreateOutputSurface(false), and | 2053 // Failing to recreate the context should lead to a didRecreateOutputSurface(fal
      se) and | 
| 2026 // a finishAllRendering() should not hang. | 2054 // a finishAllRendering() should not hang. | 
| 2027 class LayerTreeHostTestSetRepeatedLostContext : public LayerTreeHostTest { | 2055 class LayerTreeHostTestSetRepeatedLostContext : public LayerTreeHostTest { | 
| 2028 public: | 2056 public: | 
| 2029     LayerTreeHostTestSetRepeatedLostContext() | 2057     LayerTreeHostTestSetRepeatedLostContext() | 
|  | 2058         : m_context3d(NULL) | 
|  | 2059         , m_timesToLose(1) | 
|  | 2060         , m_timesToFailCreate(0) | 
| 2030     { | 2061     { | 
| 2031     } | 2062     } | 
| 2032 | 2063 | 
|  | 2064     virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE | 
|  | 2065     { | 
|  | 2066         if (m_timesToFailCreate) { | 
|  | 2067             --m_timesToFailCreate; | 
|  | 2068             return scoped_ptr<OutputSurface>(); | 
|  | 2069         } | 
|  | 2070 | 
|  | 2071         scoped_ptr<CompositorFakeWebGraphicsContext3DWithTextureTracking> contex
      t3d = | 
|  | 2072                 CompositorFakeWebGraphicsContext3DWithTextureTracking::create(We
      bKit::WebGraphicsContext3D::Attributes()); | 
|  | 2073         m_context3d = context3d.get(); | 
|  | 2074         return FakeOutputSurface::Create3d(context3d.PassAs<WebKit::WebGraphicsC
      ontext3D>()).PassAs<OutputSurface>(); | 
|  | 2075     } | 
|  | 2076 | 
| 2033     virtual void beginTest() OVERRIDE | 2077     virtual void beginTest() OVERRIDE | 
| 2034     { | 2078     { | 
| 2035         postSetNeedsCommitToMainThread(); | 2079         postSetNeedsCommitToMainThread(); | 
| 2036     } | 2080     } | 
| 2037 | 2081 | 
| 2038     virtual void didCommitAndDrawFrame() OVERRIDE | 2082     virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE | 
| 2039     { | 2083     { | 
| 2040         m_layerTreeHost->loseOutputSurface(10); | 2084         if (!m_timesToLose) | 
|  | 2085             return; | 
|  | 2086         m_context3d->loseContext(); | 
|  | 2087         m_context3d = NULL; | 
|  | 2088         --m_timesToLose; | 
|  | 2089 | 
|  | 2090         m_timesToFailCreate = 10; | 
| 2041     } | 2091     } | 
| 2042 | 2092 | 
| 2043     virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE | 2093     virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE | 
| 2044     { | 2094     { | 
| 2045         EXPECT_FALSE(succeeded); | 2095         EXPECT_FALSE(succeeded); | 
| 2046         m_layerTreeHost->finishAllRendering(); | 2096         m_layerTreeHost->finishAllRendering(); | 
| 2047         endTest(); | 2097         endTest(); | 
| 2048     } | 2098     } | 
| 2049 | 2099 | 
| 2050     virtual void afterTest() OVERRIDE | 2100     virtual void afterTest() OVERRIDE | 
| 2051     { | 2101     { | 
| 2052     } | 2102     } | 
|  | 2103 | 
|  | 2104 private: | 
|  | 2105     FakeWebGraphicsContext3D* m_context3d; | 
|  | 2106     int m_timesToLose; | 
|  | 2107     int m_timesToFailCreate; | 
| 2053 }; | 2108 }; | 
| 2054 | 2109 | 
| 2055 TEST_F(LayerTreeHostTestSetRepeatedLostContext, runMultiThread) | 2110 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestSetRepeatedLostContext) | 
| 2056 { |  | 
| 2057     runTest(true); |  | 
| 2058 } |  | 
| 2059 | 2111 | 
| 2060 class LayerTreeHostTestFractionalScroll : public LayerTreeHostTest { | 2112 class LayerTreeHostTestFractionalScroll : public LayerTreeHostTest { | 
| 2061 public: | 2113 public: | 
| 2062     LayerTreeHostTestFractionalScroll() | 2114     LayerTreeHostTestFractionalScroll() | 
| 2063         : m_scrollAmount(1.75, 0) | 2115         : m_scrollAmount(1.75, 0) | 
| 2064     { | 2116     { | 
| 2065     } | 2117     } | 
| 2066 | 2118 | 
| 2067     virtual void beginTest() OVERRIDE | 2119     virtual void beginTest() OVERRIDE | 
| 2068     { | 2120     { | 
| (...skipping 790 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 2859 { | 2911 { | 
| 2860     runTest(true); | 2912     runTest(true); | 
| 2861 } | 2913 } | 
| 2862 | 2914 | 
| 2863 class LayerTreeHostTestLostContextAfterEvictTextures : public LayerTreeHostTest 
      { | 2915 class LayerTreeHostTestLostContextAfterEvictTextures : public LayerTreeHostTest 
      { | 
| 2864 public: | 2916 public: | 
| 2865     LayerTreeHostTestLostContextAfterEvictTextures() | 2917     LayerTreeHostTestLostContextAfterEvictTextures() | 
| 2866         : m_layer(EvictionTestLayer::create()) | 2918         : m_layer(EvictionTestLayer::create()) | 
| 2867         , m_implForEvictTextures(0) | 2919         , m_implForEvictTextures(0) | 
| 2868         , m_numCommits(0) | 2920         , m_numCommits(0) | 
|  | 2921         , m_context3d(NULL) | 
| 2869     { | 2922     { | 
| 2870     } | 2923     } | 
| 2871 | 2924 | 
|  | 2925     virtual scoped_ptr<OutputSurface> createOutputSurface() OVERRIDE | 
|  | 2926     { | 
|  | 2927         scoped_ptr<CompositorFakeWebGraphicsContext3DWithTextureTracking> contex
      t3d = | 
|  | 2928                 CompositorFakeWebGraphicsContext3DWithTextureTracking::create(We
      bKit::WebGraphicsContext3D::Attributes()); | 
|  | 2929         m_context3d = context3d.get(); | 
|  | 2930         return FakeOutputSurface::Create3d(context3d.PassAs<WebKit::WebGraphicsC
      ontext3D>()).PassAs<OutputSurface>(); | 
|  | 2931     } | 
|  | 2932 | 
| 2872     virtual void beginTest() OVERRIDE | 2933     virtual void beginTest() OVERRIDE | 
| 2873     { | 2934     { | 
| 2874         m_layerTreeHost->setRootLayer(m_layer); | 2935         m_layerTreeHost->setRootLayer(m_layer); | 
| 2875         m_layerTreeHost->setViewportSize(gfx::Size(10, 20), gfx::Size(10, 20)); | 2936         m_layerTreeHost->setViewportSize(gfx::Size(10, 20), gfx::Size(10, 20)); | 
| 2876 | 2937 | 
| 2877         gfx::Transform identityMatrix; | 2938         gfx::Transform identityMatrix; | 
| 2878         setLayerPropertiesForTesting(m_layer.get(), 0, identityMatrix, gfx::Poin
      tF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 20), true); | 2939         setLayerPropertiesForTesting(m_layer.get(), 0, identityMatrix, gfx::Poin
      tF(0, 0), gfx::PointF(0, 0), gfx::Size(10, 20), true); | 
| 2879 | 2940 | 
| 2880         postSetNeedsCommitToMainThread(); | 2941         postSetNeedsCommitToMainThread(); | 
| 2881     } | 2942     } | 
| 2882 | 2943 | 
| 2883     void postEvictTextures() | 2944     void loseContextAndPostEvictTextures() | 
| 2884     { | 2945     { | 
| 2885         if (implThread()) { | 2946         if (implThread()) { | 
|  | 2947             implThread()->postTask(base::Bind(&FakeWebGraphicsContext3D::loseCon
      text, | 
|  | 2948                                               base::Unretained(m_context3d))); | 
| 2886             implThread()->postTask(base::Bind(&LayerTreeHostTestLostContextAfter
      EvictTextures::evictTexturesOnImplThread, | 2949             implThread()->postTask(base::Bind(&LayerTreeHostTestLostContextAfter
      EvictTextures::evictTexturesOnImplThread, | 
| 2887                                               base::Unretained(this))); | 2950                                               base::Unretained(this))); | 
| 2888         } else { | 2951         } else { | 
| 2889             DebugScopedSetImplThread impl(proxy()); | 2952             DebugScopedSetImplThread impl(proxy()); | 
|  | 2953             m_context3d->loseContext(); | 
| 2890             evictTexturesOnImplThread(); | 2954             evictTexturesOnImplThread(); | 
| 2891         } | 2955         } | 
| 2892     } | 2956     } | 
| 2893 | 2957 | 
| 2894     void evictTexturesOnImplThread() | 2958     void evictTexturesOnImplThread() | 
| 2895     { | 2959     { | 
| 2896         DCHECK(m_implForEvictTextures); | 2960         DCHECK(m_implForEvictTextures); | 
| 2897         m_implForEvictTextures->enforceManagedMemoryPolicy(ManagedMemoryPolicy(0
      )); | 2961         m_implForEvictTextures->enforceManagedMemoryPolicy(ManagedMemoryPolicy(0
      )); | 
| 2898     } | 2962     } | 
| 2899 | 2963 | 
| 2900     // Commit 1: Just commit and draw normally, then at the end, set ourselves | 2964     // Commit 1: Just commit and draw normally, then at the end, set ourselves | 
| 2901     // invisible (to prevent a commit that would recreate textures after | 2965     // invisible (to prevent a commit that would recreate textures after | 
| 2902     // eviction, before the context recovery), and post a task that will evict | 2966     // eviction, before the context recovery). Then lose the graphics context | 
| 2903     // textures, then cause the context to be lost, and then set ourselves | 2967     // and post a task that will evict textures. Finally, set ourselves | 
| 2904     // visible again (to allow commits, since that's what causes context | 2968     // visible again (to allow commits, since that's what causes context | 
| 2905     // recovery in single thread). | 2969     // recovery in single thread). | 
| 2906     virtual void didCommitAndDrawFrame() OVERRIDE | 2970     virtual void didCommitAndDrawFrame() OVERRIDE | 
| 2907     { | 2971     { | 
| 2908         ++m_numCommits; | 2972         ++m_numCommits; | 
| 2909         switch (m_numCommits) { | 2973         switch (m_numCommits) { | 
| 2910         case 1: | 2974         case 1: | 
| 2911             EXPECT_TRUE(m_layer->haveBackingTexture()); | 2975             EXPECT_TRUE(m_layer->haveBackingTexture()); | 
| 2912             m_layerTreeHost->setVisible(false); | 2976             m_layerTreeHost->setVisible(false); | 
| 2913             postEvictTextures(); | 2977             loseContextAndPostEvictTextures(); | 
| 2914             m_layerTreeHost->loseOutputSurface(1); |  | 
| 2915             m_layerTreeHost->setVisible(true); | 2978             m_layerTreeHost->setVisible(true); | 
| 2916             break; | 2979             break; | 
| 2917         default: | 2980         default: | 
| 2918             break; | 2981             break; | 
| 2919         } | 2982         } | 
| 2920     } | 2983     } | 
| 2921 | 2984 | 
| 2922     virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE | 2985     virtual void commitCompleteOnThread(LayerTreeHostImpl* impl) OVERRIDE | 
| 2923     { | 2986     { | 
| 2924         m_implForEvictTextures = impl; | 2987         m_implForEvictTextures = impl; | 
| 2925     } | 2988     } | 
| 2926 | 2989 | 
| 2927     virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE | 2990     virtual void didRecreateOutputSurface(bool succeeded) OVERRIDE | 
| 2928     { | 2991     { | 
| 2929         EXPECT_TRUE(succeeded); | 2992         EXPECT_TRUE(succeeded); | 
| 2930         endTest(); | 2993         endTest(); | 
| 2931     } | 2994     } | 
| 2932 | 2995 | 
| 2933     virtual void afterTest() OVERRIDE | 2996     virtual void afterTest() OVERRIDE | 
| 2934     { | 2997     { | 
| 2935     } | 2998     } | 
| 2936 | 2999 | 
| 2937 private: | 3000 private: | 
| 2938     FakeContentLayerClient m_client; | 3001     FakeContentLayerClient m_client; | 
| 2939     scoped_refptr<EvictionTestLayer> m_layer; | 3002     scoped_refptr<EvictionTestLayer> m_layer; | 
| 2940     LayerTreeHostImpl* m_implForEvictTextures; | 3003     LayerTreeHostImpl* m_implForEvictTextures; | 
| 2941     int m_numCommits; | 3004     int m_numCommits; | 
|  | 3005     FakeWebGraphicsContext3D* m_context3d; | 
| 2942 }; | 3006 }; | 
| 2943 | 3007 | 
| 2944 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLostContextAfterEvictTextures) | 3008 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestLostContextAfterEvictTextures) | 
| 2945 | 3009 | 
| 2946 class CompositorFakeWebGraphicsContext3DWithEndQueryCausingLostContext : public 
      CompositorFakeWebGraphicsContext3D { | 3010 class CompositorFakeWebGraphicsContext3DWithEndQueryCausingLostContext : public 
      CompositorFakeWebGraphicsContext3D { | 
| 2947 public: | 3011 public: | 
| 2948     static scoped_ptr<CompositorFakeWebGraphicsContext3DWithEndQueryCausingLostC
      ontext> create(Attributes attrs) | 3012     static scoped_ptr<CompositorFakeWebGraphicsContext3DWithEndQueryCausingLostC
      ontext> create(Attributes attrs) | 
| 2949     { | 3013     { | 
| 2950         return make_scoped_ptr(new CompositorFakeWebGraphicsContext3DWithEndQuer
      yCausingLostContext(attrs)); | 3014         return make_scoped_ptr(new CompositorFakeWebGraphicsContext3DWithEndQuer
      yCausingLostContext(attrs)); | 
| 2951     } | 3015     } | 
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3413     LayerTreeSettings settings; | 3477     LayerTreeSettings settings; | 
| 3414     settings.maxPartialTextureUpdates = 4; | 3478     settings.maxPartialTextureUpdates = 4; | 
| 3415 | 3479 | 
| 3416     scoped_ptr<LayerTreeHost> host = LayerTreeHost::create(&client, settings, sc
      oped_ptr<Thread>()); | 3480     scoped_ptr<LayerTreeHost> host = LayerTreeHost::create(&client, settings, sc
      oped_ptr<Thread>()); | 
| 3417     EXPECT_TRUE(host->initializeRendererIfNeeded()); | 3481     EXPECT_TRUE(host->initializeRendererIfNeeded()); | 
| 3418     EXPECT_EQ(0u, host->settings().maxPartialTextureUpdates); | 3482     EXPECT_EQ(0u, host->settings().maxPartialTextureUpdates); | 
| 3419 } | 3483 } | 
| 3420 | 3484 | 
| 3421 }  // namespace | 3485 }  // namespace | 
| 3422 }  // namespace cc | 3486 }  // namespace cc | 
| OLD | NEW | 
|---|