| 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/trees/layer_tree_host.h" | 5 #include "cc/trees/layer_tree_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 3019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3030 int callback_count_; | 3030 int callback_count_; |
| 3031 FakeContentLayerClient client_; | 3031 FakeContentLayerClient client_; |
| 3032 scoped_refptr<FakeContentLayer> root_; | 3032 scoped_refptr<FakeContentLayer> root_; |
| 3033 scoped_refptr<FakeContentLayer> copy_layer_; | 3033 scoped_refptr<FakeContentLayer> copy_layer_; |
| 3034 }; | 3034 }; |
| 3035 | 3035 |
| 3036 // No output to copy for delegated renderers. | 3036 // No output to copy for delegated renderers. |
| 3037 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | 3037 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 3038 LayerTreeHostTestAsyncTwoReadbacksWithoutDraw); | 3038 LayerTreeHostTestAsyncTwoReadbacksWithoutDraw); |
| 3039 | 3039 |
| 3040 class LayerTreeHostTestAsyncReadbackLostOutputSurface |
| 3041 : public LayerTreeHostTest { |
| 3042 protected: |
| 3043 virtual scoped_ptr<OutputSurface> CreateOutputSurface(bool fallback) |
| 3044 OVERRIDE { |
| 3045 if (!first_context_provider_.get()) { |
| 3046 first_context_provider_ = TestContextProvider::Create(); |
| 3047 return FakeOutputSurface::Create3d(first_context_provider_) |
| 3048 .PassAs<OutputSurface>(); |
| 3049 } |
| 3050 |
| 3051 EXPECT_FALSE(second_context_provider_.get()); |
| 3052 second_context_provider_ = TestContextProvider::Create(); |
| 3053 return FakeOutputSurface::Create3d(second_context_provider_) |
| 3054 .PassAs<OutputSurface>(); |
| 3055 } |
| 3056 |
| 3057 virtual void SetupTree() OVERRIDE { |
| 3058 root_ = FakeContentLayer::Create(&client_); |
| 3059 root_->SetBounds(gfx::Size(20, 20)); |
| 3060 |
| 3061 copy_layer_ = FakeContentLayer::Create(&client_); |
| 3062 copy_layer_->SetBounds(gfx::Size(10, 10)); |
| 3063 root_->AddChild(copy_layer_); |
| 3064 |
| 3065 layer_tree_host()->SetRootLayer(root_); |
| 3066 LayerTreeHostTest::SetupTree(); |
| 3067 } |
| 3068 |
| 3069 virtual void BeginTest() OVERRIDE { PostSetNeedsCommitToMainThread(); } |
| 3070 |
| 3071 void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) { |
| 3072 EXPECT_TRUE(layer_tree_host()->proxy()->IsMainThread()); |
| 3073 EXPECT_EQ(gfx::Size(10, 10).ToString(), result->size().ToString()); |
| 3074 EXPECT_TRUE(result->HasTexture()); |
| 3075 |
| 3076 // Save the result for later. |
| 3077 EXPECT_FALSE(result_); |
| 3078 result_ = result.Pass(); |
| 3079 |
| 3080 // Post a commit to lose the output surface. |
| 3081 layer_tree_host()->SetNeedsCommit(); |
| 3082 } |
| 3083 |
| 3084 virtual void DidCommitAndDrawFrame() OVERRIDE { |
| 3085 switch (layer_tree_host()->source_frame_number()) { |
| 3086 case 1: |
| 3087 // The layers have been pushed to the impl side. The layer textures have |
| 3088 // been allocated. |
| 3089 |
| 3090 // Request a copy of the layer. This will use another texture. |
| 3091 copy_layer_->RequestCopyOfOutput( |
| 3092 CopyOutputRequest::CreateRequest(base::Bind( |
| 3093 &LayerTreeHostTestAsyncReadbackLostOutputSurface:: |
| 3094 CopyOutputCallback, |
| 3095 base::Unretained(this)))); |
| 3096 break; |
| 3097 case 4: |
| 3098 // With SingleThreadProxy it takes two commits to finally swap after a |
| 3099 // context loss. |
| 3100 case 5: |
| 3101 // Now destroy the CopyOutputResult, releasing the texture inside back |
| 3102 // to the compositor. |
| 3103 EXPECT_TRUE(result_); |
| 3104 result_.reset(); |
| 3105 |
| 3106 // Check that it is released. |
| 3107 base::SingleThreadTaskRunner* task_runner = |
| 3108 HasImplThread() ? ImplThreadTaskRunner() |
| 3109 : base::MessageLoopProxy::current(); |
| 3110 task_runner->PostTask( |
| 3111 FROM_HERE, |
| 3112 base::Bind(&LayerTreeHostTestAsyncReadbackLostOutputSurface:: |
| 3113 CheckNumTextures, |
| 3114 base::Unretained(this), |
| 3115 num_textures_after_loss_ - 1)); |
| 3116 break; |
| 3117 } |
| 3118 } |
| 3119 |
| 3120 virtual void SwapBuffersOnThread(LayerTreeHostImpl *impl, bool result) |
| 3121 OVERRIDE { |
| 3122 switch (impl->active_tree()->source_frame_number()) { |
| 3123 case 0: |
| 3124 // The layers have been drawn, so their textures have been allocated. |
| 3125 EXPECT_FALSE(result_); |
| 3126 num_textures_without_readback_ = |
| 3127 first_context_provider_->TestContext3d()->NumTextures(); |
| 3128 break; |
| 3129 case 1: |
| 3130 // We did a readback, so there will be a readback texture around now. |
| 3131 EXPECT_LT(num_textures_without_readback_, |
| 3132 first_context_provider_->TestContext3d()->NumTextures()); |
| 3133 break; |
| 3134 case 2: |
| 3135 // The readback texture is collected. |
| 3136 EXPECT_TRUE(result_); |
| 3137 |
| 3138 // Lose the output surface. |
| 3139 first_context_provider_->TestContext3d()->loseContextCHROMIUM( |
| 3140 GL_GUILTY_CONTEXT_RESET_ARB, |
| 3141 GL_INNOCENT_CONTEXT_RESET_ARB); |
| 3142 break; |
| 3143 case 3: |
| 3144 // With SingleThreadProxy it takes two commits to finally swap after a |
| 3145 // context loss. |
| 3146 case 4: |
| 3147 // The output surface has been recreated. |
| 3148 EXPECT_TRUE(second_context_provider_.get()); |
| 3149 |
| 3150 num_textures_after_loss_ = |
| 3151 first_context_provider_->TestContext3d()->NumTextures(); |
| 3152 break; |
| 3153 } |
| 3154 } |
| 3155 |
| 3156 void CheckNumTextures(size_t expected_num_textures) { |
| 3157 EXPECT_EQ(expected_num_textures, |
| 3158 first_context_provider_->TestContext3d()->NumTextures()); |
| 3159 EndTest(); |
| 3160 } |
| 3161 |
| 3162 virtual void AfterTest() OVERRIDE {} |
| 3163 |
| 3164 scoped_refptr<TestContextProvider> first_context_provider_; |
| 3165 scoped_refptr<TestContextProvider> second_context_provider_; |
| 3166 size_t num_textures_without_readback_; |
| 3167 size_t num_textures_after_loss_; |
| 3168 FakeContentLayerClient client_; |
| 3169 scoped_refptr<FakeContentLayer> root_; |
| 3170 scoped_refptr<FakeContentLayer> copy_layer_; |
| 3171 scoped_ptr<CopyOutputResult> result_; |
| 3172 }; |
| 3173 |
| 3174 // No output to copy for delegated renderers. |
| 3175 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( |
| 3176 LayerTreeHostTestAsyncReadbackLostOutputSurface); |
| 3177 |
| 3040 class LayerTreeHostTestNumFramesPending : public LayerTreeHostTest { | 3178 class LayerTreeHostTestNumFramesPending : public LayerTreeHostTest { |
| 3041 public: | 3179 public: |
| 3042 virtual void BeginTest() OVERRIDE { | 3180 virtual void BeginTest() OVERRIDE { |
| 3043 frame_ = 0; | 3181 frame_ = 0; |
| 3044 PostSetNeedsCommitToMainThread(); | 3182 PostSetNeedsCommitToMainThread(); |
| 3045 } | 3183 } |
| 3046 | 3184 |
| 3047 // Round 1: commit + draw | 3185 // Round 1: commit + draw |
| 3048 // Round 2: commit only (no draw/swap) | 3186 // Round 2: commit only (no draw/swap) |
| 3049 // Round 3: draw only (no commit) | 3187 // Round 3: draw only (no commit) |
| (...skipping 1296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4346 int num_will_begin_frames_; | 4484 int num_will_begin_frames_; |
| 4347 int num_impl_commits_; | 4485 int num_impl_commits_; |
| 4348 }; | 4486 }; |
| 4349 | 4487 |
| 4350 // Commits can only be aborted when using the thread proxy. | 4488 // Commits can only be aborted when using the thread proxy. |
| 4351 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortEvictedTextures); | 4489 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortEvictedTextures); |
| 4352 | 4490 |
| 4353 } // namespace | 4491 } // namespace |
| 4354 | 4492 |
| 4355 } // namespace cc | 4493 } // namespace cc |
| OLD | NEW |