Chromium Code Reviews| 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 } | |
| 3098 } | |
| 3099 | |
| 3100 virtual void SwapBuffersOnThread(LayerTreeHostImpl *impl, bool result) | |
| 3101 OVERRIDE { | |
| 3102 switch (impl->active_tree()->source_frame_number()) { | |
| 3103 case 0: | |
| 3104 // The layers have been drawn, so their textures have been allocated. | |
| 3105 EXPECT_FALSE(result_); | |
| 3106 num_textures_without_readback_ = | |
| 3107 first_context_provider_->TestContext3d()->NumTextures(); | |
| 3108 break; | |
| 3109 case 1: | |
| 3110 // We did a readback, so there will be a readback texture around now. | |
| 3111 EXPECT_LT(num_textures_without_readback_, | |
| 3112 first_context_provider_->TestContext3d()->NumTextures()); | |
| 3113 break; | |
| 3114 case 2: | |
| 3115 // The readback texture is collected. | |
| 3116 EXPECT_TRUE(result_); | |
|
piman
2013/08/16 03:32:27
result_ is set on the main thread, don't we have a
danakj
2013/08/16 18:18:38
I think it's fine, because we get here because of
| |
| 3117 | |
| 3118 // Lose the output surface. | |
| 3119 first_context_provider_->TestContext3d()->loseContextCHROMIUM( | |
| 3120 GL_GUILTY_CONTEXT_RESET_ARB, | |
| 3121 GL_INNOCENT_CONTEXT_RESET_ARB); | |
| 3122 break; | |
| 3123 case 3: | |
| 3124 // With SingleThreadProxy it takes two commits to finally swap after a | |
| 3125 // context loss. | |
| 3126 case 4: | |
| 3127 // The output surface has been recreated. | |
| 3128 EXPECT_TRUE(second_context_provider_.get()); | |
| 3129 | |
| 3130 num_textures_after_loss_ = | |
| 3131 first_context_provider_->TestContext3d()->NumTextures(); | |
| 3132 | |
| 3133 // Now destroy the CopyOutputResult, releasing the texture inside back | |
| 3134 // to the compositor. | |
| 3135 EXPECT_TRUE(result_); | |
| 3136 result_.reset(); | |
|
piman
2013/08/16 03:32:27
Is it ok to run the mailbox callback on the compos
danakj
2013/08/16 18:18:38
oh, darn. I had done this better earlier. it can a
| |
| 3137 | |
| 3138 // Check that it is released. | |
| 3139 base::MessageLoopProxy::current()->PostTask( | |
| 3140 FROM_HERE, | |
| 3141 base::Bind(&LayerTreeHostTestAsyncReadbackLostOutputSurface:: | |
| 3142 CheckNumTextures, | |
| 3143 base::Unretained(this), | |
| 3144 num_textures_after_loss_ - 1)); | |
| 3145 break; | |
| 3146 } | |
| 3147 } | |
| 3148 | |
| 3149 void CheckNumTextures(size_t expected_num_textures) { | |
| 3150 EXPECT_EQ(expected_num_textures, | |
| 3151 first_context_provider_->TestContext3d()->NumTextures()); | |
| 3152 EndTest(); | |
| 3153 } | |
| 3154 | |
| 3155 virtual void AfterTest() OVERRIDE {} | |
| 3156 | |
| 3157 scoped_refptr<TestContextProvider> first_context_provider_; | |
| 3158 scoped_refptr<TestContextProvider> second_context_provider_; | |
| 3159 size_t num_textures_without_readback_; | |
| 3160 size_t num_textures_after_loss_; | |
| 3161 FakeContentLayerClient client_; | |
| 3162 scoped_refptr<FakeContentLayer> root_; | |
| 3163 scoped_refptr<FakeContentLayer> copy_layer_; | |
| 3164 scoped_ptr<CopyOutputResult> result_; | |
| 3165 }; | |
| 3166 | |
| 3167 // No output to copy for delegated renderers. | |
| 3168 SINGLE_AND_MULTI_THREAD_DIRECT_RENDERER_TEST_F( | |
| 3169 LayerTreeHostTestAsyncReadbackLostOutputSurface); | |
| 3170 | |
| 3040 class LayerTreeHostTestNumFramesPending : public LayerTreeHostTest { | 3171 class LayerTreeHostTestNumFramesPending : public LayerTreeHostTest { |
| 3041 public: | 3172 public: |
| 3042 virtual void BeginTest() OVERRIDE { | 3173 virtual void BeginTest() OVERRIDE { |
| 3043 frame_ = 0; | 3174 frame_ = 0; |
| 3044 PostSetNeedsCommitToMainThread(); | 3175 PostSetNeedsCommitToMainThread(); |
| 3045 } | 3176 } |
| 3046 | 3177 |
| 3047 // Round 1: commit + draw | 3178 // Round 1: commit + draw |
| 3048 // Round 2: commit only (no draw/swap) | 3179 // Round 2: commit only (no draw/swap) |
| 3049 // Round 3: draw only (no commit) | 3180 // 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_; | 4477 int num_will_begin_frames_; |
| 4347 int num_impl_commits_; | 4478 int num_impl_commits_; |
| 4348 }; | 4479 }; |
| 4349 | 4480 |
| 4350 // Commits can only be aborted when using the thread proxy. | 4481 // Commits can only be aborted when using the thread proxy. |
| 4351 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortEvictedTextures); | 4482 MULTI_THREAD_TEST_F(LayerTreeHostTestAbortEvictedTextures); |
| 4352 | 4483 |
| 4353 } // namespace | 4484 } // namespace |
| 4354 | 4485 |
| 4355 } // namespace cc | 4486 } // namespace cc |
| OLD | NEW |