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/layer_tree_host_impl.h" | 5 #include "cc/layer_tree_host_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 1539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1550 { | 1550 { |
1551 m_quadsAppended = true; | 1551 m_quadsAppended = true; |
1552 | 1552 |
1553 gfx::Rect opaqueRect; | 1553 gfx::Rect opaqueRect; |
1554 if (contentsOpaque()) | 1554 if (contentsOpaque()) |
1555 opaqueRect = m_quadRect; | 1555 opaqueRect = m_quadRect; |
1556 else | 1556 else |
1557 opaqueRect = m_opaqueContentRect; | 1557 opaqueRect = m_opaqueContentRect; |
1558 | 1558 |
1559 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSha
redQuadState()); | 1559 SharedQuadState* sharedQuadState = quadSink.useSharedQuadState(createSha
redQuadState()); |
1560 scoped_ptr<TileDrawQuad> testBlendingDrawQuad = TileDrawQuad::create(sha
redQuadState, m_quadRect, opaqueRect, m_resourceId, gfx::Vector2d(), gfx::Size(1
, 1), 0, false, false, false, false, false); | 1560 scoped_ptr<TileDrawQuad> testBlendingDrawQuad = TileDrawQuad::create(sha
redQuadState, m_quadRect, opaqueRect, m_resourceId, gfx::Vector2d(), gfx::Size(1
, 1), false, false, false, false, false); |
1561 testBlendingDrawQuad->setQuadVisibleRect(m_quadVisibleRect); | 1561 testBlendingDrawQuad->setQuadVisibleRect(m_quadVisibleRect); |
1562 EXPECT_EQ(m_blend, testBlendingDrawQuad->needsBlending()); | 1562 EXPECT_EQ(m_blend, testBlendingDrawQuad->needsBlending()); |
1563 EXPECT_EQ(m_hasRenderSurface, !!renderSurface()); | 1563 EXPECT_EQ(m_hasRenderSurface, !!renderSurface()); |
1564 quadSink.append(testBlendingDrawQuad.PassAs<DrawQuad>(), appendQuadsData
); | 1564 quadSink.append(testBlendingDrawQuad.PassAs<DrawQuad>(), appendQuadsData
); |
1565 } | 1565 } |
1566 | 1566 |
1567 void setExpectation(bool blend, bool hasRenderSurface) | 1567 void setExpectation(bool blend, bool hasRenderSurface) |
1568 { | 1568 { |
1569 m_blend = blend; | 1569 m_blend = blend; |
1570 m_hasRenderSurface = hasRenderSurface; | 1570 m_hasRenderSurface = hasRenderSurface; |
(...skipping 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2450 } | 2450 } |
2451 | 2451 |
2452 // Fake WebGraphicsContext3D that will cause a failure if trying to use a | 2452 // Fake WebGraphicsContext3D that will cause a failure if trying to use a |
2453 // resource that wasn't created by it (resources created by | 2453 // resource that wasn't created by it (resources created by |
2454 // FakeWebGraphicsContext3D have an id of 1). | 2454 // FakeWebGraphicsContext3D have an id of 1). |
2455 class StrictWebGraphicsContext3D : public FakeWebGraphicsContext3D { | 2455 class StrictWebGraphicsContext3D : public FakeWebGraphicsContext3D { |
2456 public: | 2456 public: |
2457 StrictWebGraphicsContext3D() | 2457 StrictWebGraphicsContext3D() |
2458 : FakeWebGraphicsContext3D() | 2458 : FakeWebGraphicsContext3D() |
2459 { | 2459 { |
2460 m_nextTextureId = 7; // Start allocating texture ids larger than any oth
er resource IDs so we can tell if someone's mixing up their resource types. | 2460 m_nextTextureId = 8; // Start allocating texture ids larger than any oth
er resource IDs so we can tell if someone's mixing up their resource types. |
2461 } | 2461 } |
2462 | 2462 |
2463 virtual WebGLId createBuffer() { return 2; } | 2463 virtual WebGLId createBuffer() { return 2; } |
2464 virtual WebGLId createFramebuffer() { return 3; } | 2464 virtual WebGLId createFramebuffer() { return 3; } |
2465 virtual WebGLId createProgram() { return 4; } | 2465 virtual WebGLId createProgram() { return 4; } |
2466 virtual WebGLId createRenderbuffer() { return 5; } | 2466 virtual WebGLId createRenderbuffer() { return 5; } |
2467 virtual WebGLId createShader(WGC3Denum) { return 6; } | 2467 virtual WebGLId createShader(WGC3Denum) { return 6; } |
2468 | 2468 |
| 2469 static const WebGLId kExternalTextureId = 7; |
| 2470 |
2469 virtual void deleteBuffer(WebGLId id) | 2471 virtual void deleteBuffer(WebGLId id) |
2470 { | 2472 { |
2471 if (id != 2) | 2473 if (id != 2) |
2472 ADD_FAILURE() << "Trying to delete buffer id " << id; | 2474 ADD_FAILURE() << "Trying to delete buffer id " << id; |
2473 } | 2475 } |
2474 | 2476 |
2475 virtual void deleteFramebuffer(WebGLId id) | 2477 virtual void deleteFramebuffer(WebGLId id) |
2476 { | 2478 { |
2477 if (id != 3) | 2479 if (id != 3) |
2478 ADD_FAILURE() << "Trying to delete framebuffer id " << id; | 2480 ADD_FAILURE() << "Trying to delete framebuffer id " << id; |
(...skipping 18 matching lines...) Expand all Loading... |
2497 } | 2499 } |
2498 | 2500 |
2499 virtual WebGLId createTexture() | 2501 virtual WebGLId createTexture() |
2500 { | 2502 { |
2501 unsigned textureId = FakeWebGraphicsContext3D::createTexture(); | 2503 unsigned textureId = FakeWebGraphicsContext3D::createTexture(); |
2502 m_allocatedTextureIds.insert(textureId); | 2504 m_allocatedTextureIds.insert(textureId); |
2503 return textureId; | 2505 return textureId; |
2504 } | 2506 } |
2505 virtual void deleteTexture(WebGLId id) | 2507 virtual void deleteTexture(WebGLId id) |
2506 { | 2508 { |
| 2509 if (id == kExternalTextureId) |
| 2510 ADD_FAILURE() << "Trying to delete external texture"; |
2507 if (!ContainsKey(m_allocatedTextureIds, id)) | 2511 if (!ContainsKey(m_allocatedTextureIds, id)) |
2508 ADD_FAILURE() << "Trying to delete texture id " << id; | 2512 ADD_FAILURE() << "Trying to delete texture id " << id; |
2509 m_allocatedTextureIds.erase(id); | 2513 m_allocatedTextureIds.erase(id); |
2510 } | 2514 } |
2511 | 2515 |
2512 virtual void bindBuffer(WGC3Denum, WebGLId id) | 2516 virtual void bindBuffer(WGC3Denum, WebGLId id) |
2513 { | 2517 { |
2514 if (id != 2 && id) | 2518 if (id != 2 && id) |
2515 ADD_FAILURE() << "Trying to bind buffer id " << id; | 2519 ADD_FAILURE() << "Trying to bind buffer id " << id; |
2516 } | 2520 } |
(...skipping 17 matching lines...) Expand all Loading... |
2534 } | 2538 } |
2535 | 2539 |
2536 virtual void attachShader(WebGLId program, WebGLId shader) | 2540 virtual void attachShader(WebGLId program, WebGLId shader) |
2537 { | 2541 { |
2538 if ((program != 4) || (shader != 6)) | 2542 if ((program != 4) || (shader != 6)) |
2539 ADD_FAILURE() << "Trying to attach shader id " << shader << " to pro
gram id " << program; | 2543 ADD_FAILURE() << "Trying to attach shader id " << shader << " to pro
gram id " << program; |
2540 } | 2544 } |
2541 | 2545 |
2542 virtual void bindTexture(WGC3Denum, WebGLId id) | 2546 virtual void bindTexture(WGC3Denum, WebGLId id) |
2543 { | 2547 { |
2544 if (id && !ContainsKey(m_allocatedTextureIds, id)) | 2548 if (id && id != kExternalTextureId && !ContainsKey(m_allocatedTextureIds
, id)) |
2545 ADD_FAILURE() << "Trying to bind texture id " << id; | 2549 ADD_FAILURE() << "Trying to bind texture id " << id; |
2546 } | 2550 } |
2547 | 2551 |
2548 private: | 2552 private: |
2549 base::hash_set<unsigned> m_allocatedTextureIds; | 2553 base::hash_set<unsigned> m_allocatedTextureIds; |
2550 }; | 2554 }; |
2551 | 2555 |
2552 // Fake WebVideoFrame wrapper of media::VideoFrame. | 2556 // Fake WebVideoFrame wrapper of media::VideoFrame. |
2553 class FakeVideoFrame: public WebVideoFrame { | 2557 class FakeVideoFrame: public WebVideoFrame { |
2554 public: | 2558 public: |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2692 tilingData->setBounds(gfx::Size(10, 10)); | 2696 tilingData->setBounds(gfx::Size(10, 10)); |
2693 tileLayer->setTilingData(*tilingData); | 2697 tileLayer->setTilingData(*tilingData); |
2694 tileLayer->pushTileProperties(0, 0, 1, gfx::Rect(0, 0, 10, 10), false); | 2698 tileLayer->pushTileProperties(0, 0, 1, gfx::Rect(0, 0, 10, 10), false); |
2695 rootLayer->addChild(tileLayer.PassAs<LayerImpl>()); | 2699 rootLayer->addChild(tileLayer.PassAs<LayerImpl>()); |
2696 | 2700 |
2697 scoped_ptr<TextureLayerImpl> textureLayer = TextureLayerImpl::create(layerId
++); | 2701 scoped_ptr<TextureLayerImpl> textureLayer = TextureLayerImpl::create(layerId
++); |
2698 textureLayer->setBounds(gfx::Size(10, 10)); | 2702 textureLayer->setBounds(gfx::Size(10, 10)); |
2699 textureLayer->setAnchorPoint(gfx::PointF(0, 0)); | 2703 textureLayer->setAnchorPoint(gfx::PointF(0, 0)); |
2700 textureLayer->setContentBounds(gfx::Size(10, 10)); | 2704 textureLayer->setContentBounds(gfx::Size(10, 10)); |
2701 textureLayer->setDrawsContent(true); | 2705 textureLayer->setDrawsContent(true); |
2702 textureLayer->setTextureId(1); | 2706 textureLayer->setTextureId(StrictWebGraphicsContext3D::kExternalTextureId); |
2703 rootLayer->addChild(textureLayer.PassAs<LayerImpl>()); | 2707 rootLayer->addChild(textureLayer.PassAs<LayerImpl>()); |
2704 | 2708 |
2705 scoped_ptr<TiledLayerImpl> maskLayer = TiledLayerImpl::create(layerId++); | 2709 scoped_ptr<TiledLayerImpl> maskLayer = TiledLayerImpl::create(layerId++); |
2706 maskLayer->setBounds(gfx::Size(10, 10)); | 2710 maskLayer->setBounds(gfx::Size(10, 10)); |
2707 maskLayer->setAnchorPoint(gfx::PointF(0, 0)); | 2711 maskLayer->setAnchorPoint(gfx::PointF(0, 0)); |
2708 maskLayer->setContentBounds(gfx::Size(10, 10)); | 2712 maskLayer->setContentBounds(gfx::Size(10, 10)); |
2709 maskLayer->setDrawsContent(true); | 2713 maskLayer->setDrawsContent(true); |
2710 maskLayer->setSkipsDraw(false); | 2714 maskLayer->setSkipsDraw(false); |
2711 maskLayer->setTilingData(*tilingData); | 2715 maskLayer->setTilingData(*tilingData); |
2712 maskLayer->pushTileProperties(0, 0, 1, gfx::Rect(0, 0, 10, 10), false); | 2716 maskLayer->pushTileProperties(0, 0, 1, gfx::Rect(0, 0, 10, 10), false); |
2713 | 2717 |
2714 scoped_ptr<TextureLayerImpl> textureLayerWithMask = TextureLayerImpl::create
(layerId++); | 2718 scoped_ptr<TextureLayerImpl> textureLayerWithMask = TextureLayerImpl::create
(layerId++); |
2715 textureLayerWithMask->setBounds(gfx::Size(10, 10)); | 2719 textureLayerWithMask->setBounds(gfx::Size(10, 10)); |
2716 textureLayerWithMask->setAnchorPoint(gfx::PointF(0, 0)); | 2720 textureLayerWithMask->setAnchorPoint(gfx::PointF(0, 0)); |
2717 textureLayerWithMask->setContentBounds(gfx::Size(10, 10)); | 2721 textureLayerWithMask->setContentBounds(gfx::Size(10, 10)); |
2718 textureLayerWithMask->setDrawsContent(true); | 2722 textureLayerWithMask->setDrawsContent(true); |
2719 textureLayerWithMask->setTextureId(1); | 2723 textureLayerWithMask->setTextureId(StrictWebGraphicsContext3D::kExternalText
ureId); |
2720 textureLayerWithMask->setMaskLayer(maskLayer.PassAs<LayerImpl>()); | 2724 textureLayerWithMask->setMaskLayer(maskLayer.PassAs<LayerImpl>()); |
2721 rootLayer->addChild(textureLayerWithMask.PassAs<LayerImpl>()); | 2725 rootLayer->addChild(textureLayerWithMask.PassAs<LayerImpl>()); |
2722 | 2726 |
2723 FakeVideoFrame videoFrame(VideoFrame::CreateColorFrame(gfx::Size(4, 4), | 2727 FakeVideoFrame videoFrame(VideoFrame::CreateColorFrame(gfx::Size(4, 4), |
2724 0x80, 0x80, 0x80, | 2728 0x80, 0x80, 0x80, |
2725 base::TimeDelta())); | 2729 base::TimeDelta())); |
2726 VideoLayerImpl::FrameUnwrapper unwrapper = | 2730 VideoLayerImpl::FrameUnwrapper unwrapper = |
2727 base::Bind(FakeVideoFrame::toVideoFrame); | 2731 base::Bind(FakeVideoFrame::toVideoFrame); |
2728 FakeVideoFrameProvider provider; | 2732 FakeVideoFrameProvider provider; |
2729 provider.setFrame(&videoFrame); | 2733 provider.setFrame(&videoFrame); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2818 | 2822 |
2819 unsigned numResources = m_hostImpl->resourceProvider()->numResources(); | 2823 unsigned numResources = m_hostImpl->resourceProvider()->numResources(); |
2820 | 2824 |
2821 // Lose the context, replacing it with a StrictWebGraphicsContext3DWithIOSur
face, | 2825 // Lose the context, replacing it with a StrictWebGraphicsContext3DWithIOSur
face, |
2822 // that will warn if any resource from the previous context gets used. | 2826 // that will warn if any resource from the previous context gets used. |
2823 m_hostImpl->initializeRenderer(FakeWebCompositorOutputSurface::create(scoped
_ptr<WebKit::WebGraphicsContext3D>(new StrictWebGraphicsContext3DWithIOSurface))
.PassAs<GraphicsContext>()); | 2827 m_hostImpl->initializeRenderer(FakeWebCompositorOutputSurface::create(scoped
_ptr<WebKit::WebGraphicsContext3D>(new StrictWebGraphicsContext3DWithIOSurface))
.PassAs<GraphicsContext>()); |
2824 | 2828 |
2825 // Create dummy resources so that looking up an old resource will get an | 2829 // Create dummy resources so that looking up an old resource will get an |
2826 // invalid texture id mapping. | 2830 // invalid texture id mapping. |
2827 for (unsigned i = 0; i < numResources; ++i) | 2831 for (unsigned i = 0; i < numResources; ++i) |
2828 m_hostImpl->resourceProvider()->createResourceFromExternalTexture(1); | 2832 m_hostImpl->resourceProvider()->createResourceFromExternalTexture(Strict
WebGraphicsContext3D::kExternalTextureId); |
2829 | 2833 |
2830 // The WebVideoFrameProvider is expected to recreate its textures after a | 2834 // The WebVideoFrameProvider is expected to recreate its textures after a |
2831 // lost context (or not serve a frame). | 2835 // lost context (or not serve a frame). |
2832 hwProvider.setFrame(0); | 2836 hwProvider.setFrame(0); |
2833 providerScaled.setFrame(0); | 2837 providerScaled.setFrame(0); |
2834 | 2838 |
2835 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); | 2839 EXPECT_TRUE(m_hostImpl->prepareToDraw(frame)); |
2836 m_hostImpl->drawLayers(frame); | 2840 m_hostImpl->drawLayers(frame); |
2837 m_hostImpl->didDrawAllLayers(frame); | 2841 m_hostImpl->didDrawAllLayers(frame); |
2838 m_hostImpl->swapBuffers(); | 2842 m_hostImpl->swapBuffers(); |
(...skipping 1596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4435 testCaseIndex++; | 4439 testCaseIndex++; |
4436 } | 4440 } |
4437 } | 4441 } |
4438 | 4442 |
4439 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, | 4443 INSTANTIATE_TEST_CASE_P(LayerTreeHostImplTests, |
4440 LayerTreeHostImplTest, | 4444 LayerTreeHostImplTest, |
4441 ::testing::Values(false, true)); | 4445 ::testing::Values(false, true)); |
4442 | 4446 |
4443 } // namespace | 4447 } // namespace |
4444 } // namespace cc | 4448 } // namespace cc |
OLD | NEW |