| 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 1302 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1313  |  1313  | 
|  1314 // TODO(sohanjg) : Remove it once impl-side painting ships everywhere. |  1314 // TODO(sohanjg) : Remove it once impl-side painting ships everywhere. | 
|  1315 // Verify atomicity of commits and reuse of textures. |  1315 // Verify atomicity of commits and reuse of textures. | 
|  1316 class LayerTreeHostTestDirectRendererAtomicCommit : public LayerTreeHostTest { |  1316 class LayerTreeHostTestDirectRendererAtomicCommit : public LayerTreeHostTest { | 
|  1317  public: |  1317  public: | 
|  1318   void InitializeSettings(LayerTreeSettings* settings) override { |  1318   void InitializeSettings(LayerTreeSettings* settings) override { | 
|  1319     settings->renderer_settings.texture_id_allocation_chunk_size = 1; |  1319     settings->renderer_settings.texture_id_allocation_chunk_size = 1; | 
|  1320     // Make sure partial texture updates are turned off. |  1320     // Make sure partial texture updates are turned off. | 
|  1321     settings->max_partial_texture_updates = 0; |  1321     settings->max_partial_texture_updates = 0; | 
|  1322     // Linear fade animator prevents scrollbars from drawing immediately. |  1322     // Linear fade animator prevents scrollbars from drawing immediately. | 
|  1323     settings->scrollbar_animator = LayerTreeSettings::NoAnimator; |  1323     settings->scrollbar_animator = LayerTreeSettings::NO_ANIMATOR; | 
|  1324   } |  1324   } | 
|  1325  |  1325  | 
|  1326   void SetupTree() override { |  1326   void SetupTree() override { | 
|  1327     layer_ = FakeContentLayer::Create(&client_); |  1327     layer_ = FakeContentLayer::Create(&client_); | 
|  1328     layer_->SetBounds(gfx::Size(10, 20)); |  1328     layer_->SetBounds(gfx::Size(10, 20)); | 
|  1329  |  1329  | 
|  1330     bool paint_scrollbar = true; |  1330     bool paint_scrollbar = true; | 
|  1331     bool has_thumb = false; |  1331     bool has_thumb = false; | 
|  1332     scrollbar_ = FakePaintedScrollbarLayer::Create( |  1332     scrollbar_ = FakePaintedScrollbarLayer::Create( | 
|  1333         paint_scrollbar, has_thumb, layer_->id()); |  1333         paint_scrollbar, has_thumb, layer_->id()); | 
| (...skipping 982 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  2316   scoped_refptr<FakeContentLayer> child_layer1_; |  2316   scoped_refptr<FakeContentLayer> child_layer1_; | 
|  2317   scoped_refptr<FakeContentLayer> child_layer2_; |  2317   scoped_refptr<FakeContentLayer> child_layer2_; | 
|  2318   int num_commits_; |  2318   int num_commits_; | 
|  2319 }; |  2319 }; | 
|  2320  |  2320  | 
|  2321 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( |  2321 SINGLE_AND_MULTI_THREAD_NOIMPL_TEST_F( | 
|  2322     LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); |  2322     LayerTreeHostTestShutdownWithOnlySomeResourcesEvicted); | 
|  2323  |  2323  | 
|  2324 class LayerTreeHostTestLCDChange : public LayerTreeHostTest { |  2324 class LayerTreeHostTestLCDChange : public LayerTreeHostTest { | 
|  2325  public: |  2325  public: | 
|  2326   class PaintClient : public FakeContentLayerClient { |  | 
|  2327    public: |  | 
|  2328     PaintClient() : paint_count_(0) {} |  | 
|  2329  |  | 
|  2330     int paint_count() const { return paint_count_; } |  | 
|  2331  |  | 
|  2332     void PaintContents(SkCanvas* canvas, |  | 
|  2333                        const gfx::Rect& clip, |  | 
|  2334                        PaintingControlSetting picture_control) override { |  | 
|  2335       FakeContentLayerClient::PaintContents(canvas, clip, picture_control); |  | 
|  2336       ++paint_count_; |  | 
|  2337     } |  | 
|  2338  |  | 
|  2339     scoped_refptr<DisplayItemList> PaintContentsToDisplayList( |  | 
|  2340         const gfx::Rect& clip, |  | 
|  2341         PaintingControlSetting picture_control) override { |  | 
|  2342       NOTIMPLEMENTED(); |  | 
|  2343       return DisplayItemList::Create(); |  | 
|  2344     } |  | 
|  2345  |  | 
|  2346     bool FillsBoundsCompletely() const override { return false; } |  | 
|  2347  |  | 
|  2348    private: |  | 
|  2349     int paint_count_; |  | 
|  2350   }; |  | 
|  2351  |  | 
|  2352   void SetupTree() override { |  2326   void SetupTree() override { | 
|  2353     num_tiles_rastered_ = 0; |  2327     num_tiles_rastered_ = 0; | 
|  2354  |  2328  | 
|  2355     scoped_refptr<Layer> root_layer; |  2329     scoped_refptr<Layer> root_layer = PictureLayer::Create(&client_); | 
|  2356     if (layer_tree_host()->settings().impl_side_painting) |  | 
|  2357       root_layer = PictureLayer::Create(&client_); |  | 
|  2358     else |  | 
|  2359       root_layer = ContentLayer::Create(&client_); |  | 
|  2360     client_.set_fill_with_nonsolid_color(true); |  2330     client_.set_fill_with_nonsolid_color(true); | 
|  2361     root_layer->SetIsDrawable(true); |  2331     root_layer->SetIsDrawable(true); | 
|  2362     root_layer->SetBounds(gfx::Size(10, 10)); |  2332     root_layer->SetBounds(gfx::Size(10, 10)); | 
|  2363     root_layer->SetContentsOpaque(true); |  2333     root_layer->SetContentsOpaque(true); | 
|  2364  |  2334  | 
|  2365     layer_tree_host()->SetRootLayer(root_layer); |  2335     layer_tree_host()->SetRootLayer(root_layer); | 
|  2366  |  2336  | 
|  2367     // The expecations are based on the assumption that the default |  2337     // The expectations are based on the assumption that the default | 
|  2368     // LCD settings are: |  2338     // LCD settings are: | 
|  2369     EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); |  2339     EXPECT_TRUE(layer_tree_host()->settings().can_use_lcd_text); | 
|  2370     EXPECT_FALSE(root_layer->can_use_lcd_text()); |  | 
|  2371  |  2340  | 
|  2372     LayerTreeHostTest::SetupTree(); |  2341     LayerTreeHostTest::SetupTree(); | 
|  2373   } |  2342   } | 
|  2374  |  2343  | 
|  2375   void BeginTest() override { PostSetNeedsCommitToMainThread(); } |  2344   void BeginTest() override { PostSetNeedsCommitToMainThread(); } | 
|  2376  |  2345  | 
|  2377   void DidCommitAndDrawFrame() override { |  2346   void DidCommitAndDrawFrame() override { | 
|  2378     switch (layer_tree_host()->source_frame_number()) { |  2347     switch (layer_tree_host()->source_frame_number()) { | 
|  2379       case 1: |  2348       case 1: | 
|  2380         // The first update consists of a paint of the whole layer. |  | 
|  2381         EXPECT_EQ(1, client_.paint_count()); |  | 
|  2382         // LCD text must have been enabled on the layer. |  | 
|  2383         EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); |  | 
|  2384         PostSetNeedsCommitToMainThread(); |  2349         PostSetNeedsCommitToMainThread(); | 
|  2385         break; |  2350         break; | 
|  2386       case 2: |  2351       case 2: | 
|  2387         // Since nothing changed on layer, there should be no paint. |  | 
|  2388         EXPECT_EQ(1, client_.paint_count()); |  | 
|  2389         // LCD text must not have changed. |  | 
|  2390         EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); |  | 
|  2391         // Change layer opacity that should trigger lcd change. |  2352         // Change layer opacity that should trigger lcd change. | 
|  2392         layer_tree_host()->root_layer()->SetOpacity(.5f); |  2353         layer_tree_host()->root_layer()->SetOpacity(.5f); | 
|  2393         break; |  2354         break; | 
|  2394       case 3: |  2355       case 3: | 
|  2395         // LCD text doesn't require re-recording, so no painting should occur. |  | 
|  2396         EXPECT_EQ(1, client_.paint_count()); |  | 
|  2397         // LCD text must have been disabled on the layer due to opacity. |  | 
|  2398         EXPECT_FALSE(layer_tree_host()->root_layer()->can_use_lcd_text()); |  | 
|  2399         // Change layer opacity that should not trigger lcd change. |  2356         // Change layer opacity that should not trigger lcd change. | 
|  2400         layer_tree_host()->root_layer()->SetOpacity(1.f); |  2357         layer_tree_host()->root_layer()->SetOpacity(1.f); | 
|  2401         break; |  2358         break; | 
|  2402       case 4: |  2359       case 4: | 
|  2403         // LCD text doesn't require re-recording, so no painting should occur. |  | 
|  2404         EXPECT_EQ(1, client_.paint_count()); |  | 
|  2405         // Even though LCD text could be allowed. |  | 
|  2406         EXPECT_TRUE(layer_tree_host()->root_layer()->can_use_lcd_text()); |  | 
|  2407         EndTest(); |  2360         EndTest(); | 
|  2408         break; |  2361         break; | 
|  2409     } |  2362     } | 
|  2410   } |  2363   } | 
|  2411  |  2364  | 
|  2412   void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl, |  2365   void NotifyTileStateChangedOnThread(LayerTreeHostImpl* host_impl, | 
|  2413                                       const Tile* tile) override { |  2366                                       const Tile* tile) override { | 
|  2414     ++num_tiles_rastered_; |  2367     ++num_tiles_rastered_; | 
|  2415   } |  2368   } | 
|  2416  |  2369  | 
|  2417   void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { |  2370   void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | 
 |  2371     PictureLayerImpl* root_layer = | 
 |  2372         static_cast<PictureLayerImpl*>(host_impl->active_tree()->root_layer()); | 
 |  2373     bool can_use_lcd_text = | 
 |  2374         host_impl->active_tree()->root_layer()->can_use_lcd_text(); | 
|  2418     switch (host_impl->active_tree()->source_frame_number()) { |  2375     switch (host_impl->active_tree()->source_frame_number()) { | 
|  2419       case 0: |  2376       case 0: | 
|  2420         // The first draw. |  2377         // The first draw. | 
|  2421         EXPECT_EQ(1, num_tiles_rastered_); |  2378         EXPECT_EQ(1, num_tiles_rastered_); | 
 |  2379         EXPECT_TRUE(can_use_lcd_text); | 
 |  2380         EXPECT_TRUE(root_layer->RasterSourceUsesLCDText()); | 
|  2422         break; |  2381         break; | 
|  2423       case 1: |  2382       case 1: | 
|  2424         // Nothing changed on the layer. |  2383         // Nothing changed on the layer. | 
|  2425         EXPECT_EQ(1, num_tiles_rastered_); |  2384         EXPECT_EQ(1, num_tiles_rastered_); | 
 |  2385         EXPECT_TRUE(can_use_lcd_text); | 
 |  2386         EXPECT_TRUE(root_layer->RasterSourceUsesLCDText()); | 
|  2426         break; |  2387         break; | 
|  2427       case 2: |  2388       case 2: | 
|  2428         // LCD text was disabled, it should be re-rastered with LCD text off. |  2389         // LCD text was disabled; it should be re-rastered with LCD text off. | 
|  2429         EXPECT_EQ(2, num_tiles_rastered_); |  2390         EXPECT_EQ(2, num_tiles_rastered_); | 
 |  2391         EXPECT_FALSE(can_use_lcd_text); | 
 |  2392         EXPECT_FALSE(root_layer->RasterSourceUsesLCDText()); | 
|  2430         break; |  2393         break; | 
|  2431       case 3: |  2394       case 3: | 
|  2432         // LCD text was enabled but it's sticky and stays off. |  2395         // LCD text was enabled, but it's sticky and stays off. | 
|  2433         EXPECT_EQ(2, num_tiles_rastered_); |  2396         EXPECT_EQ(2, num_tiles_rastered_); | 
 |  2397         EXPECT_TRUE(can_use_lcd_text); | 
 |  2398         EXPECT_FALSE(root_layer->RasterSourceUsesLCDText()); | 
|  2434         break; |  2399         break; | 
|  2435     } |  2400     } | 
|  2436   } |  2401   } | 
|  2437  |  2402  | 
|  2438   void AfterTest() override {} |  2403   void AfterTest() override {} | 
|  2439  |  2404  | 
|  2440  private: |  2405  private: | 
|  2441   PaintClient client_; |  2406   FakeContentLayerClient client_; | 
|  2442   int num_tiles_rastered_; |  2407   int num_tiles_rastered_; | 
|  2443 }; |  2408 }; | 
|  2444  |  2409  | 
|  2445 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestLCDChange); |  2410 SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostTestLCDChange); | 
|  2446  |  2411  | 
|  2447 // Verify that the BeginFrame notification is used to initiate rendering. |  2412 // Verify that the BeginFrame notification is used to initiate rendering. | 
|  2448 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { |  2413 class LayerTreeHostTestBeginFrameNotification : public LayerTreeHostTest { | 
|  2449  public: |  2414  public: | 
|  2450   void InitializeSettings(LayerTreeSettings* settings) override { |  2415   void InitializeSettings(LayerTreeSettings* settings) override { | 
|  2451     settings->use_external_begin_frame_source = true; |  2416     settings->use_external_begin_frame_source = true; | 
| (...skipping 3837 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  6289   } |  6254   } | 
|  6290  |  6255  | 
|  6291   void AfterTest() override { EXPECT_TRUE(did_commit_); } |  6256   void AfterTest() override { EXPECT_TRUE(did_commit_); } | 
|  6292  |  6257  | 
|  6293  private: |  6258  private: | 
|  6294   bool did_commit_; |  6259   bool did_commit_; | 
|  6295 }; |  6260 }; | 
|  6296  |  6261  | 
|  6297 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit); |  6262 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestNoTasksBetweenWillAndDidCommit); | 
|  6298  |  6263  | 
 |  6264 // Verify that if a LayerImpl holds onto a copy request for multiple | 
 |  6265 // frames that it will continue to have a render surface through | 
 |  6266 // multiple commits, even though the Layer itself has no reason | 
 |  6267 // to have a render surface. | 
 |  6268 class LayerPreserveRenderSurfaceFromOutputRequests : public LayerTreeHostTest { | 
 |  6269  protected: | 
 |  6270   void SetupTree() override { | 
 |  6271     scoped_refptr<Layer> root = Layer::Create(); | 
 |  6272     root->CreateRenderSurface(); | 
 |  6273     root->SetBounds(gfx::Size(10, 10)); | 
 |  6274     child_ = Layer::Create(); | 
 |  6275     child_->SetBounds(gfx::Size(20, 20)); | 
 |  6276     root->AddChild(child_); | 
 |  6277  | 
 |  6278     layer_tree_host()->SetRootLayer(root); | 
 |  6279     LayerTreeHostTest::SetupTree(); | 
 |  6280   } | 
 |  6281  | 
 |  6282   static void CopyOutputCallback(scoped_ptr<CopyOutputResult> result) {} | 
 |  6283  | 
 |  6284   void BeginTest() override { | 
 |  6285     child_->RequestCopyOfOutput( | 
 |  6286         CopyOutputRequest::CreateBitmapRequest(base::Bind(CopyOutputCallback))); | 
 |  6287     EXPECT_TRUE(child_->HasCopyRequest()); | 
 |  6288     PostSetNeedsCommitToMainThread(); | 
 |  6289   } | 
 |  6290  | 
 |  6291   void DidCommit() override { EXPECT_FALSE(child_->HasCopyRequest()); } | 
 |  6292  | 
 |  6293   void CommitCompleteOnThread(LayerTreeHostImpl* host_impl) override { | 
 |  6294     LayerImpl* child_impl = host_impl->sync_tree()->LayerById(child_->id()); | 
 |  6295  | 
 |  6296     switch (host_impl->sync_tree()->source_frame_number()) { | 
 |  6297       case 0: | 
 |  6298         EXPECT_TRUE(child_impl->HasCopyRequest()); | 
 |  6299         EXPECT_TRUE(child_impl->render_surface()); | 
 |  6300         break; | 
 |  6301       case 1: | 
 |  6302         if (host_impl->proxy()->CommitToActiveTree()) { | 
 |  6303           EXPECT_TRUE(child_impl->HasCopyRequest()); | 
 |  6304           EXPECT_TRUE(child_impl->render_surface()); | 
 |  6305         } else { | 
 |  6306           EXPECT_FALSE(child_impl->HasCopyRequest()); | 
 |  6307           EXPECT_FALSE(child_impl->render_surface()); | 
 |  6308         } | 
 |  6309         break; | 
 |  6310       default: | 
 |  6311         NOTREACHED(); | 
 |  6312         break; | 
 |  6313     } | 
 |  6314   } | 
 |  6315  | 
 |  6316   void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | 
 |  6317     LayerImpl* child_impl = host_impl->active_tree()->LayerById(child_->id()); | 
 |  6318     EXPECT_TRUE(child_impl->HasCopyRequest()); | 
 |  6319     EXPECT_TRUE(child_impl->render_surface()); | 
 |  6320  | 
 |  6321     switch (host_impl->active_tree()->source_frame_number()) { | 
 |  6322       case 0: | 
 |  6323         // Lose output surface to prevent drawing and cause another commit. | 
 |  6324         host_impl->DidLoseOutputSurface(); | 
 |  6325         break; | 
 |  6326       case 1: | 
 |  6327         EndTest(); | 
 |  6328         break; | 
 |  6329       default: | 
 |  6330         NOTREACHED(); | 
 |  6331         break; | 
 |  6332     } | 
 |  6333   } | 
 |  6334  | 
 |  6335   void AfterTest() override {} | 
 |  6336  | 
 |  6337  private: | 
 |  6338   scoped_refptr<Layer> child_; | 
 |  6339 }; | 
 |  6340  | 
 |  6341 SINGLE_AND_MULTI_THREAD_TEST_F(LayerPreserveRenderSurfaceFromOutputRequests); | 
 |  6342  | 
|  6299 }  // namespace cc |  6343 }  // namespace cc | 
| OLD | NEW |