Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(112)

Side by Side Diff: Source/WebKit/chromium/tests/CCLayerTreeHostTest.cpp

Issue 10836250: Merge 125577 - [chromium] race between CCLayerTreeHostImpl::releaseContentsTextures and CCThreadPro… (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1229/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 2331 matching lines...) Expand 10 before | Expand all | Expand 10 after
2342 MockContentLayerDelegate m_mockDelegate; 2342 MockContentLayerDelegate m_mockDelegate;
2343 RefPtr<ContentLayerChromiumWithUpdateTracking> m_rootLayer; 2343 RefPtr<ContentLayerChromiumWithUpdateTracking> m_rootLayer;
2344 RefPtr<ContentLayerChromiumWithUpdateTracking> m_surfaceLayer1; 2344 RefPtr<ContentLayerChromiumWithUpdateTracking> m_surfaceLayer1;
2345 RefPtr<ContentLayerChromiumWithUpdateTracking> m_replicaLayer1; 2345 RefPtr<ContentLayerChromiumWithUpdateTracking> m_replicaLayer1;
2346 RefPtr<ContentLayerChromiumWithUpdateTracking> m_surfaceLayer2; 2346 RefPtr<ContentLayerChromiumWithUpdateTracking> m_surfaceLayer2;
2347 RefPtr<ContentLayerChromiumWithUpdateTracking> m_replicaLayer2; 2347 RefPtr<ContentLayerChromiumWithUpdateTracking> m_replicaLayer2;
2348 }; 2348 };
2349 2349
2350 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestSurfaceNotAllocatedForLayersOu tsideMemoryLimit) 2350 SINGLE_AND_MULTI_THREAD_TEST_F(CCLayerTreeHostTestSurfaceNotAllocatedForLayersOu tsideMemoryLimit)
2351 2351
2352
2353 class EvictionTrackingTexture : public LayerTextureUpdater::Texture {
2354 public:
2355 static PassOwnPtr<EvictionTrackingTexture> create(PassOwnPtr<CCPrioritizedTe xture> texture) { return adoptPtr(new EvictionTrackingTexture(texture)); }
2356 virtual ~EvictionTrackingTexture() { }
2357
2358 virtual void updateRect(CCResourceProvider* resourceProvider, const IntRect& , const IntRect&) OVERRIDE
2359 {
2360 ASSERT_TRUE(!texture()->haveBackingTexture() || resourceProvider->numRes ources() > 0);
2361 texture()->acquireBackingTexture(resourceProvider);
2362 m_updated = true;
2363 }
2364 void resetUpdated() { m_updated = false; }
2365 bool updated() const { return m_updated; }
2366
2367 private:
2368 explicit EvictionTrackingTexture(PassOwnPtr<CCPrioritizedTexture> texture)
2369 : LayerTextureUpdater::Texture(texture)
2370 , m_updated(false)
2371 { }
2372 bool m_updated;
2373 };
2374
2375 class EvictionTestLayer : public LayerChromium {
2376 public:
2377 static PassRefPtr<EvictionTestLayer> create() { return adoptRef(new Eviction TestLayer()); }
2378
2379 virtual void update(CCTextureUpdateQueue&, const CCOcclusionTracker*, CCRend eringStats&) OVERRIDE;
2380 virtual bool drawsContent() const OVERRIDE { return true; }
2381
2382 virtual PassOwnPtr<CCLayerImpl> createCCLayerImpl() OVERRIDE;
2383 virtual void pushPropertiesTo(CCLayerImpl*) OVERRIDE;
2384 virtual void setTexturePriorities(const CCPriorityCalculator&) OVERRIDE;
2385
2386 void resetUpdated()
2387 {
2388 if (m_texture.get())
2389 m_texture->resetUpdated();
2390 }
2391 bool updated() const { return m_texture.get() ? m_texture->updated() : false ; }
2392
2393 private:
2394 EvictionTestLayer() : LayerChromium() { }
2395
2396 void createTextureIfNeeded()
2397 {
2398 if (m_texture.get())
2399 return;
2400 m_texture = EvictionTrackingTexture::create(CCPrioritizedTexture::create (layerTreeHost()->contentsTextureManager()));
2401 m_texture->texture()->setDimensions(WebCore::IntSize(10, 10), WebCore::G raphicsContext3D::RGBA);
2402 }
2403
2404 OwnPtr<EvictionTrackingTexture> m_texture;
2405 };
2406
2407 class EvictionTestLayerImpl : public CCLayerImpl {
2408 public:
2409 static PassOwnPtr<EvictionTestLayerImpl> create(int id)
2410 {
2411 return adoptPtr(new EvictionTestLayerImpl(id));
2412 }
2413 virtual ~EvictionTestLayerImpl() { }
2414 virtual void appendQuads(CCQuadSink&, const CCSharedQuadState*, bool& hadMis singTiles)
2415 {
2416 ASSERT_TRUE(m_hasTexture);
2417 ASSERT_NE(0u, layerTreeHostImpl()->resourceProvider()->numResources());
2418 }
2419 void setHasTexture(bool hasTexture) { m_hasTexture = hasTexture; }
2420
2421 private:
2422 explicit EvictionTestLayerImpl(int id)
2423 : CCLayerImpl(id)
2424 , m_hasTexture(false) { }
2425
2426 bool m_hasTexture;
2427 };
2428
2429 void EvictionTestLayer::setTexturePriorities(const CCPriorityCalculator&)
2430 {
2431 createTextureIfNeeded();
2432 if (!m_texture.get())
2433 return;
2434 m_texture->texture()->setRequestPriority(CCPriorityCalculator::uiPriority(tr ue));
2435 }
2436
2437 void EvictionTestLayer::update(CCTextureUpdateQueue& queue, const CCOcclusionTra cker*, CCRenderingStats&)
2438 {
2439 createTextureIfNeeded();
2440 if (!m_texture.get())
2441 return;
2442 IntRect fullRect(0, 0, 10, 10);
2443 TextureUploader::Parameters parameters = { m_texture.get(), fullRect, fullRe ct };
2444 queue.appendFullUpload(parameters);
2445 }
2446
2447 PassOwnPtr<CCLayerImpl> EvictionTestLayer::createCCLayerImpl()
2448 {
2449 return EvictionTestLayerImpl::create(m_layerId);
2450 }
2451
2452 void EvictionTestLayer::pushPropertiesTo(CCLayerImpl* layerImpl)
2453 {
2454 LayerChromium::pushPropertiesTo(layerImpl);
2455
2456 EvictionTestLayerImpl* testLayerImpl = static_cast<EvictionTestLayerImpl*>(l ayerImpl);
2457 testLayerImpl->setHasTexture(m_texture->texture()->haveBackingTexture());
2458 }
2459
2460 class CCLayerTreeHostTestEvictTextures : public CCLayerTreeHostTest {
2461 public:
2462 CCLayerTreeHostTestEvictTextures()
2463 : m_layer(EvictionTestLayer::create())
2464 , m_implForEvictTextures(0)
2465 , m_numCommits(0)
2466 {
2467 }
2468
2469 virtual void beginTest()
2470 {
2471 m_layerTreeHost->setRootLayer(m_layer);
2472 m_layerTreeHost->setViewportSize(IntSize(10, 20), IntSize(10, 20));
2473
2474 WebTransformationMatrix identityMatrix;
2475 setLayerPropertiesForTesting(m_layer.get(), 0, identityMatrix, FloatPoin t(0, 0), FloatPoint(0, 0), IntSize(10, 20), true);
2476 }
2477
2478 class EvictTexturesTask : public WebKit::WebThread::Task {
2479 public:
2480 EvictTexturesTask(CCLayerTreeHostTestEvictTextures* test) : m_test(test) { }
2481 virtual ~EvictTexturesTask() { }
2482 virtual void run()
2483 {
2484 ASSERT(m_test->m_implForEvictTextures);
2485 m_test->m_implForEvictTextures->releaseContentsTextures();
2486 }
2487
2488 private:
2489 CCLayerTreeHostTestEvictTextures* m_test;
2490 };
2491
2492 void postEvictTextures()
2493 {
2494 ASSERT(webThread());
2495 webThread()->postTask(new EvictTexturesTask(this));
2496 }
2497
2498 // Commit 1: Just commit and draw normally, then post an eviction at the end
2499 // that will trigger a commit.
2500 // Commit 2: Triggered by the eviction, let it go through and then set
2501 // needsCommit.
2502 // Commit 3: Triggered by the setNeedsCommit. In layout(), post an eviction
2503 // task, which will be handled before the commit. Don't set needsCommit, it
2504 // should have been posted. A frame should not be drawn (note,
2505 // didCommitAndDrawFrame may be called anyway).
2506 // Commit 4: Triggered by the eviction, let it go through and then set
2507 // needsCommit.
2508 // Commit 5: Triggered by the setNeedsCommit, post an eviction task in
2509 // layout(), a frame should not be drawn but a commit will be posted.
2510 // Commit 6: Triggered by the eviction, post an eviction task in
2511 // layout(), which will be a noop, letting the commit (which recreates the
2512 // textures) go through and draw a frame, then end the test.
2513 //
2514 // Commits 1+2 test the eviction recovery path where eviction happens outsid e
2515 // of the beginFrame/commit pair.
2516 // Commits 3+4 test the eviction recovery path where eviction happens inside
2517 // the beginFrame/commit pair.
2518 // Commits 5+6 test the path where an eviction happens during the eviction
2519 // recovery path.
2520 virtual void didCommitAndDrawFrame()
2521 {
2522 switch (m_numCommits) {
2523 case 1:
2524 EXPECT_TRUE(m_layer->updated());
2525 postEvictTextures();
2526 break;
2527 case 2:
2528 EXPECT_TRUE(m_layer->updated());
2529 m_layerTreeHost->setNeedsCommit();
2530 break;
2531 case 3:
2532 break;
2533 case 4:
2534 EXPECT_TRUE(m_layer->updated());
2535 m_layerTreeHost->setNeedsCommit();
2536 break;
2537 case 5:
2538 break;
2539 case 6:
2540 EXPECT_TRUE(m_layer->updated());
2541 endTest();
2542 break;
2543 default:
2544 ASSERT_NOT_REACHED();
2545 break;
2546 }
2547 }
2548
2549 virtual void commitCompleteOnCCThread(CCLayerTreeHostImpl* impl)
2550 {
2551 m_implForEvictTextures = impl;
2552 }
2553
2554 virtual void layout()
2555 {
2556 ++m_numCommits;
2557 switch (m_numCommits) {
2558 case 1:
2559 case 2:
2560 break;
2561 case 3:
2562 postEvictTextures();
2563 break;
2564 case 4:
2565 // We couldn't check in didCommitAndDrawFrame on commit 3, so check here.
2566 EXPECT_FALSE(m_layer->updated());
2567 break;
2568 case 5:
2569 postEvictTextures();
2570 break;
2571 case 6:
2572 // We couldn't check in didCommitAndDrawFrame on commit 5, so check here.
2573 EXPECT_FALSE(m_layer->updated());
2574 postEvictTextures();
2575 break;
2576 default:
2577 ASSERT_NOT_REACHED();
2578 break;
2579 }
2580 m_layer->resetUpdated();
2581 }
2582
2583 virtual void afterTest()
2584 {
2585 }
2586
2587 private:
2588 MockContentLayerDelegate m_delegate;
2589 RefPtr<EvictionTestLayer> m_layer;
2590 CCLayerTreeHostImpl* m_implForEvictTextures;
2591 int m_numCommits;
2592 };
2593
2594 TEST_F(CCLayerTreeHostTestEvictTextures, runMultiThread)
2595 {
2596 runTest(true);
2597 }
2598
2352 } // namespace 2599 } // namespace
OLDNEW
« no previous file with comments | « Source/WebCore/platform/graphics/chromium/cc/CCThreadProxy.cpp ('k') | Source/WebKit/chromium/tests/CCThreadedTest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698