| 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 "config.h" | 5 #include "config.h" |
| 6 | 6 |
| 7 #include "CCLayerTreeHost.h" | 7 #include "CCLayerTreeHost.h" |
| 8 | 8 |
| 9 #include "CCGeometryTestUtils.h" | 9 #include "CCGeometryTestUtils.h" |
| 10 #include "CCGraphicsContext.h" | 10 #include "CCGraphicsContext.h" |
| (...skipping 2376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2387 RefPtr<ContentLayerChromiumWithUpdateTracking> m_rootLayer; | 2387 RefPtr<ContentLayerChromiumWithUpdateTracking> m_rootLayer; |
| 2388 RefPtr<ContentLayerChromiumWithUpdateTracking> m_surfaceLayer1; | 2388 RefPtr<ContentLayerChromiumWithUpdateTracking> m_surfaceLayer1; |
| 2389 RefPtr<ContentLayerChromiumWithUpdateTracking> m_replicaLayer1; | 2389 RefPtr<ContentLayerChromiumWithUpdateTracking> m_replicaLayer1; |
| 2390 RefPtr<ContentLayerChromiumWithUpdateTracking> m_surfaceLayer2; | 2390 RefPtr<ContentLayerChromiumWithUpdateTracking> m_surfaceLayer2; |
| 2391 RefPtr<ContentLayerChromiumWithUpdateTracking> m_replicaLayer2; | 2391 RefPtr<ContentLayerChromiumWithUpdateTracking> m_replicaLayer2; |
| 2392 }; | 2392 }; |
| 2393 | 2393 |
| 2394 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestSurfaceNotAllocatedForLayersOu
tsideMemoryLimit) | 2394 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestSurfaceNotAllocatedForLayersOu
tsideMemoryLimit) |
| 2395 | 2395 |
| 2396 | 2396 |
| 2397 class EvictionTrackingTexture : public LayerTextureUpdater::Texture { | |
| 2398 public: | |
| 2399 static PassOwnPtr<EvictionTrackingTexture> create(PassOwnPtr<CCPrioritizedTe
xture> texture) { return adoptPtr(new EvictionTrackingTexture(texture)); } | |
| 2400 virtual ~EvictionTrackingTexture() { } | |
| 2401 | |
| 2402 virtual void updateRect(CCResourceProvider* resourceProvider, const IntRect&
, const IntSize&) OVERRIDE | |
| 2403 { | |
| 2404 ASSERT_TRUE(!texture()->haveBackingTexture() || resourceProvider->numRes
ources() > 0); | |
| 2405 texture()->acquireBackingTexture(resourceProvider); | |
| 2406 m_updated = true; | |
| 2407 } | |
| 2408 void resetUpdated() { m_updated = false; } | |
| 2409 bool updated() const { return m_updated; } | |
| 2410 | |
| 2411 private: | |
| 2412 explicit EvictionTrackingTexture(PassOwnPtr<CCPrioritizedTexture> texture) | |
| 2413 : LayerTextureUpdater::Texture(texture) | |
| 2414 , m_updated(false) | |
| 2415 { } | |
| 2416 bool m_updated; | |
| 2417 }; | |
| 2418 | |
| 2419 class EvictionTestLayer : public LayerChromium { | 2397 class EvictionTestLayer : public LayerChromium { |
| 2420 public: | 2398 public: |
| 2421 static PassRefPtr<EvictionTestLayer> create() { return adoptRef(new Eviction
TestLayer()); } | 2399 static PassRefPtr<EvictionTestLayer> create() { return adoptRef(new Eviction
TestLayer()); } |
| 2422 | 2400 |
| 2423 virtual void update(CCTextureUpdateQueue&, const CCOcclusionTracker*, CCRend
eringStats&) OVERRIDE; | 2401 virtual void update(CCTextureUpdateQueue&, const CCOcclusionTracker*, CCRend
eringStats&) OVERRIDE; |
| 2424 virtual bool drawsContent() const OVERRIDE { return true; } | 2402 virtual bool drawsContent() const OVERRIDE { return true; } |
| 2425 | 2403 |
| 2426 virtual PassOwnPtr<CCLayerImpl> createCCLayerImpl() OVERRIDE; | 2404 virtual PassOwnPtr<CCLayerImpl> createCCLayerImpl() OVERRIDE; |
| 2427 virtual void pushPropertiesTo(CCLayerImpl*) OVERRIDE; | 2405 virtual void pushPropertiesTo(CCLayerImpl*) OVERRIDE; |
| 2428 virtual void setTexturePriorities(const CCPriorityCalculator&) OVERRIDE; | 2406 virtual void setTexturePriorities(const CCPriorityCalculator&) OVERRIDE; |
| 2429 | 2407 |
| 2430 void resetUpdated() | 2408 bool haveBackingTexture() const { return m_texture.get() ? m_texture->haveBa
ckingTexture() : false; } |
| 2431 { | |
| 2432 if (m_texture.get()) | |
| 2433 m_texture->resetUpdated(); | |
| 2434 } | |
| 2435 bool updated() const { return m_texture.get() ? m_texture->updated() : false
; } | |
| 2436 | 2409 |
| 2437 private: | 2410 private: |
| 2438 EvictionTestLayer() : LayerChromium() { } | 2411 EvictionTestLayer() : LayerChromium() { } |
| 2439 | 2412 |
| 2440 void createTextureIfNeeded() | 2413 void createTextureIfNeeded() |
| 2441 { | 2414 { |
| 2442 if (m_texture.get()) | 2415 if (m_texture.get()) |
| 2443 return; | 2416 return; |
| 2444 m_texture = EvictionTrackingTexture::create(CCPrioritizedTexture::create
(layerTreeHost()->contentsTextureManager())); | 2417 m_texture = CCPrioritizedTexture::create(layerTreeHost()->contentsTextur
eManager()); |
| 2445 m_texture->texture()->setDimensions(IntSize(10, 10), cc::GraphicsContext
3D::RGBA); | 2418 m_texture->setDimensions(IntSize(10, 10), cc::GraphicsContext3D::RGBA); |
| 2419 m_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 10, 10); |
| 2446 } | 2420 } |
| 2447 | 2421 |
| 2448 OwnPtr<EvictionTrackingTexture> m_texture; | 2422 OwnPtr<CCPrioritizedTexture> m_texture; |
| 2423 SkBitmap m_bitmap; |
| 2449 }; | 2424 }; |
| 2450 | 2425 |
| 2451 class EvictionTestLayerImpl : public CCLayerImpl { | 2426 class EvictionTestLayerImpl : public CCLayerImpl { |
| 2452 public: | 2427 public: |
| 2453 static PassOwnPtr<EvictionTestLayerImpl> create(int id) | 2428 static PassOwnPtr<EvictionTestLayerImpl> create(int id) |
| 2454 { | 2429 { |
| 2455 return adoptPtr(new EvictionTestLayerImpl(id)); | 2430 return adoptPtr(new EvictionTestLayerImpl(id)); |
| 2456 } | 2431 } |
| 2457 virtual ~EvictionTestLayerImpl() { } | 2432 virtual ~EvictionTestLayerImpl() { } |
| 2458 | 2433 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2470 , m_hasTexture(false) { } | 2445 , m_hasTexture(false) { } |
| 2471 | 2446 |
| 2472 bool m_hasTexture; | 2447 bool m_hasTexture; |
| 2473 }; | 2448 }; |
| 2474 | 2449 |
| 2475 void EvictionTestLayer::setTexturePriorities(const CCPriorityCalculator&) | 2450 void EvictionTestLayer::setTexturePriorities(const CCPriorityCalculator&) |
| 2476 { | 2451 { |
| 2477 createTextureIfNeeded(); | 2452 createTextureIfNeeded(); |
| 2478 if (!m_texture.get()) | 2453 if (!m_texture.get()) |
| 2479 return; | 2454 return; |
| 2480 m_texture->texture()->setRequestPriority(CCPriorityCalculator::uiPriority(tr
ue)); | 2455 m_texture->setRequestPriority(CCPriorityCalculator::uiPriority(true)); |
| 2481 } | 2456 } |
| 2482 | 2457 |
| 2483 void EvictionTestLayer::update(CCTextureUpdateQueue& queue, const CCOcclusionTra
cker*, CCRenderingStats&) | 2458 void EvictionTestLayer::update(CCTextureUpdateQueue& queue, const CCOcclusionTra
cker*, CCRenderingStats&) |
| 2484 { | 2459 { |
| 2485 createTextureIfNeeded(); | 2460 createTextureIfNeeded(); |
| 2486 if (!m_texture.get()) | 2461 if (!m_texture.get()) |
| 2487 return; | 2462 return; |
| 2488 IntRect fullRect(0, 0, 10, 10); | 2463 IntRect fullRect(0, 0, 10, 10); |
| 2489 TextureUploader::Parameters parameters = { m_texture.get(), fullRect, IntSiz
e() }; | 2464 TextureUploader::Parameters upload = { m_texture.get(), &m_bitmap, NULL, { f
ullRect, fullRect, IntSize() } }; |
| 2490 queue.appendFullUpload(parameters); | 2465 queue.appendFullUpload(upload); |
| 2491 } | 2466 } |
| 2492 | 2467 |
| 2493 PassOwnPtr<CCLayerImpl> EvictionTestLayer::createCCLayerImpl() | 2468 PassOwnPtr<CCLayerImpl> EvictionTestLayer::createCCLayerImpl() |
| 2494 { | 2469 { |
| 2495 return EvictionTestLayerImpl::create(m_layerId); | 2470 return EvictionTestLayerImpl::create(m_layerId); |
| 2496 } | 2471 } |
| 2497 | 2472 |
| 2498 void EvictionTestLayer::pushPropertiesTo(CCLayerImpl* layerImpl) | 2473 void EvictionTestLayer::pushPropertiesTo(CCLayerImpl* layerImpl) |
| 2499 { | 2474 { |
| 2500 LayerChromium::pushPropertiesTo(layerImpl); | 2475 LayerChromium::pushPropertiesTo(layerImpl); |
| 2501 | 2476 |
| 2502 EvictionTestLayerImpl* testLayerImpl = static_cast<EvictionTestLayerImpl*>(l
ayerImpl); | 2477 EvictionTestLayerImpl* testLayerImpl = static_cast<EvictionTestLayerImpl*>(l
ayerImpl); |
| 2503 testLayerImpl->setHasTexture(m_texture->texture()->haveBackingTexture()); | 2478 testLayerImpl->setHasTexture(m_texture->haveBackingTexture()); |
| 2504 } | 2479 } |
| 2505 | 2480 |
| 2506 class CCLayerTreeHostTestEvictTextures : public CCLayerTreeHostTest { | 2481 class CCLayerTreeHostTestEvictTextures : public CCLayerTreeHostTest { |
| 2507 public: | 2482 public: |
| 2508 CCLayerTreeHostTestEvictTextures() | 2483 CCLayerTreeHostTestEvictTextures() |
| 2509 : m_layer(EvictionTestLayer::create()) | 2484 : m_layer(EvictionTestLayer::create()) |
| 2510 , m_implForEvictTextures(0) | 2485 , m_implForEvictTextures(0) |
| 2511 , m_numCommits(0) | 2486 , m_numCommits(0) |
| 2512 { | 2487 { |
| 2513 } | 2488 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2560 // Commits 1+2 test the eviction recovery path where eviction happens outsid
e | 2535 // Commits 1+2 test the eviction recovery path where eviction happens outsid
e |
| 2561 // of the beginFrame/commit pair. | 2536 // of the beginFrame/commit pair. |
| 2562 // Commits 3+4 test the eviction recovery path where eviction happens inside | 2537 // Commits 3+4 test the eviction recovery path where eviction happens inside |
| 2563 // the beginFrame/commit pair. | 2538 // the beginFrame/commit pair. |
| 2564 // Commits 5+6 test the path where an eviction happens during the eviction | 2539 // Commits 5+6 test the path where an eviction happens during the eviction |
| 2565 // recovery path. | 2540 // recovery path. |
| 2566 virtual void didCommitAndDrawFrame() OVERRIDE | 2541 virtual void didCommitAndDrawFrame() OVERRIDE |
| 2567 { | 2542 { |
| 2568 switch (m_numCommits) { | 2543 switch (m_numCommits) { |
| 2569 case 1: | 2544 case 1: |
| 2570 EXPECT_TRUE(m_layer->updated()); | 2545 EXPECT_TRUE(m_layer->haveBackingTexture()); |
| 2571 postEvictTextures(); | 2546 postEvictTextures(); |
| 2572 break; | 2547 break; |
| 2573 case 2: | 2548 case 2: |
| 2574 EXPECT_TRUE(m_layer->updated()); | 2549 EXPECT_TRUE(m_layer->haveBackingTexture()); |
| 2575 m_layerTreeHost->setNeedsCommit(); | 2550 m_layerTreeHost->setNeedsCommit(); |
| 2576 break; | 2551 break; |
| 2577 case 3: | 2552 case 3: |
| 2578 break; | 2553 break; |
| 2579 case 4: | 2554 case 4: |
| 2580 EXPECT_TRUE(m_layer->updated()); | 2555 EXPECT_TRUE(m_layer->haveBackingTexture()); |
| 2581 m_layerTreeHost->setNeedsCommit(); | 2556 m_layerTreeHost->setNeedsCommit(); |
| 2582 break; | 2557 break; |
| 2583 case 5: | 2558 case 5: |
| 2584 break; | 2559 break; |
| 2585 case 6: | 2560 case 6: |
| 2586 EXPECT_TRUE(m_layer->updated()); | 2561 EXPECT_TRUE(m_layer->haveBackingTexture()); |
| 2587 endTest(); | 2562 endTest(); |
| 2588 break; | 2563 break; |
| 2589 default: | 2564 default: |
| 2590 ASSERT_NOT_REACHED(); | 2565 ASSERT_NOT_REACHED(); |
| 2591 break; | 2566 break; |
| 2592 } | 2567 } |
| 2593 } | 2568 } |
| 2594 | 2569 |
| 2595 virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl* impl) OVERRIDE | 2570 virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl* impl) OVERRIDE |
| 2596 { | 2571 { |
| 2597 m_implForEvictTextures = impl; | 2572 m_implForEvictTextures = impl; |
| 2598 } | 2573 } |
| 2599 | 2574 |
| 2600 virtual void layout() OVERRIDE | 2575 virtual void layout() OVERRIDE |
| 2601 { | 2576 { |
| 2602 ++m_numCommits; | 2577 ++m_numCommits; |
| 2603 switch (m_numCommits) { | 2578 switch (m_numCommits) { |
| 2604 case 1: | 2579 case 1: |
| 2605 case 2: | 2580 case 2: |
| 2606 break; | 2581 break; |
| 2607 case 3: | 2582 case 3: |
| 2608 postEvictTextures(); | 2583 postEvictTextures(); |
| 2609 break; | 2584 break; |
| 2610 case 4: | 2585 case 4: |
| 2611 // We couldn't check in didCommitAndDrawFrame on commit 3, so check
here. | 2586 // We couldn't check in didCommitAndDrawFrame on commit 3, so check
here. |
| 2612 EXPECT_FALSE(m_layer->updated()); | 2587 EXPECT_FALSE(m_layer->haveBackingTexture()); |
| 2613 break; | 2588 break; |
| 2614 case 5: | 2589 case 5: |
| 2615 postEvictTextures(); | 2590 postEvictTextures(); |
| 2616 break; | 2591 break; |
| 2617 case 6: | 2592 case 6: |
| 2618 // We couldn't check in didCommitAndDrawFrame on commit 5, so check
here. | 2593 // We couldn't check in didCommitAndDrawFrame on commit 5, so check
here. |
| 2619 EXPECT_FALSE(m_layer->updated()); | 2594 EXPECT_FALSE(m_layer->haveBackingTexture()); |
| 2620 postEvictTextures(); | 2595 postEvictTextures(); |
| 2621 break; | 2596 break; |
| 2622 default: | 2597 default: |
| 2623 ASSERT_NOT_REACHED(); | 2598 ASSERT_NOT_REACHED(); |
| 2624 break; | 2599 break; |
| 2625 } | 2600 } |
| 2626 m_layer->resetUpdated(); | |
| 2627 } | 2601 } |
| 2628 | 2602 |
| 2629 virtual void afterTest() OVERRIDE | 2603 virtual void afterTest() OVERRIDE |
| 2630 { | 2604 { |
| 2631 } | 2605 } |
| 2632 | 2606 |
| 2633 private: | 2607 private: |
| 2634 MockContentLayerChromiumClient m_client; | 2608 MockContentLayerChromiumClient m_client; |
| 2635 RefPtr<EvictionTestLayer> m_layer; | 2609 RefPtr<EvictionTestLayer> m_layer; |
| 2636 CCLayerTreeHostImpl* m_implForEvictTextures; | 2610 CCLayerTreeHostImpl* m_implForEvictTextures; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2693 // invisible (to prevent a commit that would recreate textures after | 2667 // invisible (to prevent a commit that would recreate textures after |
| 2694 // eviction, before the context recovery), and post a task that will evict | 2668 // eviction, before the context recovery), and post a task that will evict |
| 2695 // textures, then cause the context to be lost, and then set ourselves | 2669 // textures, then cause the context to be lost, and then set ourselves |
| 2696 // visible again (to allow commits, since that's what causes context | 2670 // visible again (to allow commits, since that's what causes context |
| 2697 // recovery in single thread). | 2671 // recovery in single thread). |
| 2698 virtual void didCommitAndDrawFrame() OVERRIDE | 2672 virtual void didCommitAndDrawFrame() OVERRIDE |
| 2699 { | 2673 { |
| 2700 ++m_numCommits; | 2674 ++m_numCommits; |
| 2701 switch (m_numCommits) { | 2675 switch (m_numCommits) { |
| 2702 case 1: | 2676 case 1: |
| 2703 EXPECT_TRUE(m_layer->updated()); | 2677 EXPECT_TRUE(m_layer->haveBackingTexture()); |
| 2704 m_layerTreeHost->setVisible(false); | 2678 m_layerTreeHost->setVisible(false); |
| 2705 postEvictTextures(); | 2679 postEvictTextures(); |
| 2706 m_layerTreeHost->loseContext(1); | 2680 m_layerTreeHost->loseContext(1); |
| 2707 m_layerTreeHost->setVisible(true); | 2681 m_layerTreeHost->setVisible(true); |
| 2708 break; | 2682 break; |
| 2709 default: | 2683 default: |
| 2710 break; | 2684 break; |
| 2711 } | 2685 } |
| 2712 } | 2686 } |
| 2713 | 2687 |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2988 int m_numCommitComplete; | 2962 int m_numCommitComplete; |
| 2989 int m_numDrawLayers; | 2963 int m_numDrawLayers; |
| 2990 }; | 2964 }; |
| 2991 | 2965 |
| 2992 TEST_F(CCLayerTreeHostTestContinuousAnimate, runMultiThread) | 2966 TEST_F(CCLayerTreeHostTestContinuousAnimate, runMultiThread) |
| 2993 { | 2967 { |
| 2994 runTest(true); | 2968 runTest(true); |
| 2995 } | 2969 } |
| 2996 | 2970 |
| 2997 } // namespace | 2971 } // namespace |
| OLD | NEW |