| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "cc/layers/content_layer.h" | 8 #include "cc/layers/content_layer.h" |
| 9 #include "cc/layers/delegated_frame_provider.h" | 9 #include "cc/layers/delegated_frame_provider.h" |
| 10 #include "cc/layers/delegated_frame_resource_collection.h" | 10 #include "cc/layers/delegated_frame_resource_collection.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "cc/test/render_pass_test_common.h" | 34 #include "cc/test/render_pass_test_common.h" |
| 35 #include "cc/test/test_context_provider.h" | 35 #include "cc/test/test_context_provider.h" |
| 36 #include "cc/test/test_web_graphics_context_3d.h" | 36 #include "cc/test/test_web_graphics_context_3d.h" |
| 37 #include "cc/trees/layer_tree_host_impl.h" | 37 #include "cc/trees/layer_tree_host_impl.h" |
| 38 #include "cc/trees/layer_tree_impl.h" | 38 #include "cc/trees/layer_tree_impl.h" |
| 39 #include "cc/trees/single_thread_proxy.h" | 39 #include "cc/trees/single_thread_proxy.h" |
| 40 #include "gpu/GLES2/gl2extchromium.h" | 40 #include "gpu/GLES2/gl2extchromium.h" |
| 41 #include "media/base/media.h" | 41 #include "media/base/media.h" |
| 42 | 42 |
| 43 using media::VideoFrame; | 43 using media::VideoFrame; |
| 44 using blink::WebGraphicsContext3D; | |
| 45 | 44 |
| 46 namespace cc { | 45 namespace cc { |
| 47 namespace { | 46 namespace { |
| 48 | 47 |
| 49 // These tests deal with losing the 3d graphics context. | 48 // These tests deal with losing the 3d graphics context. |
| 50 class LayerTreeHostContextTest : public LayerTreeTest { | 49 class LayerTreeHostContextTest : public LayerTreeTest { |
| 51 public: | 50 public: |
| 52 LayerTreeHostContextTest() | 51 LayerTreeHostContextTest() |
| 53 : LayerTreeTest(), | 52 : LayerTreeTest(), |
| 54 context3d_(NULL), | 53 context3d_(NULL), |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 419 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>( | 418 FakeContentLayerImpl* content_impl = static_cast<FakeContentLayerImpl*>( |
| 420 host_impl->active_tree()->root_layer()->children()[0]); | 419 host_impl->active_tree()->root_layer()->children()[0]); |
| 421 // Even though the context was lost, we should have a resource. The | 420 // Even though the context was lost, we should have a resource. The |
| 422 // TestWebGraphicsContext3D ensures that this resource is created with | 421 // TestWebGraphicsContext3D ensures that this resource is created with |
| 423 // the active context. | 422 // the active context. |
| 424 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); | 423 EXPECT_TRUE(content_impl->HaveResourceForTileAt(0, 0)); |
| 425 | 424 |
| 426 ContextProvider* contexts = host_impl->offscreen_context_provider(); | 425 ContextProvider* contexts = host_impl->offscreen_context_provider(); |
| 427 if (use_surface_) { | 426 if (use_surface_) { |
| 428 ASSERT_TRUE(contexts); | 427 ASSERT_TRUE(contexts); |
| 429 EXPECT_TRUE(contexts->Context3d()); | 428 EXPECT_TRUE(contexts->ContextGL()); |
| 430 // TODO(danakj): Make a fake GrContext. | 429 // TODO(danakj): Make a fake GrContext. |
| 431 // EXPECT_TRUE(contexts->GrContext()); | 430 // EXPECT_TRUE(contexts->GrContext()); |
| 432 } else { | 431 } else { |
| 433 EXPECT_FALSE(contexts); | 432 EXPECT_FALSE(contexts); |
| 434 } | 433 } |
| 435 } | 434 } |
| 436 | 435 |
| 437 virtual void AfterTest() OVERRIDE { | 436 virtual void AfterTest() OVERRIDE { |
| 438 LayerTreeHostContextTestLostContextSucceeds::AfterTest(); | 437 LayerTreeHostContextTestLostContextSucceeds::AfterTest(); |
| 439 if (use_surface_) { | 438 if (use_surface_) { |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 959 ResourceProvider::Create(child_output_surface_.get(), | 958 ResourceProvider::Create(child_output_surface_.get(), |
| 960 NULL, | 959 NULL, |
| 961 0, | 960 0, |
| 962 false, | 961 false, |
| 963 1); | 962 1); |
| 964 } | 963 } |
| 965 | 964 |
| 966 static void EmptyReleaseCallback(unsigned sync_point, bool lost) {} | 965 static void EmptyReleaseCallback(unsigned sync_point, bool lost) {} |
| 967 | 966 |
| 968 virtual void SetupTree() OVERRIDE { | 967 virtual void SetupTree() OVERRIDE { |
| 969 blink::WebGraphicsContext3D* context3d = | 968 gpu::gles2::GLES2Interface* gl = |
| 970 child_output_surface_->context_provider()->Context3d(); | 969 child_output_surface_->context_provider()->ContextGL(); |
| 971 | 970 |
| 972 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); | 971 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); |
| 973 | 972 |
| 974 scoped_ptr<TestRenderPass> pass_for_quad = TestRenderPass::Create(); | 973 scoped_ptr<TestRenderPass> pass_for_quad = TestRenderPass::Create(); |
| 975 pass_for_quad->SetNew( | 974 pass_for_quad->SetNew( |
| 976 // AppendOneOfEveryQuadType() makes a RenderPass quad with this id. | 975 // AppendOneOfEveryQuadType() makes a RenderPass quad with this id. |
| 977 RenderPass::Id(2, 1), | 976 RenderPass::Id(2, 1), |
| 978 gfx::Rect(0, 0, 10, 10), | 977 gfx::Rect(0, 0, 10, 10), |
| 979 gfx::Rect(0, 0, 10, 10), | 978 gfx::Rect(0, 0, 10, 10), |
| 980 gfx::Transform()); | 979 gfx::Transform()); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 997 ResourceProvider::ResourceId resource = | 996 ResourceProvider::ResourceId resource = |
| 998 child_resource_provider_->CreateResource( | 997 child_resource_provider_->CreateResource( |
| 999 gfx::Size(4, 4), | 998 gfx::Size(4, 4), |
| 1000 GL_CLAMP_TO_EDGE, | 999 GL_CLAMP_TO_EDGE, |
| 1001 ResourceProvider::TextureUsageAny, | 1000 ResourceProvider::TextureUsageAny, |
| 1002 RGBA_8888); | 1001 RGBA_8888); |
| 1003 ResourceProvider::ScopedWriteLockGL lock(child_resource_provider_.get(), | 1002 ResourceProvider::ScopedWriteLockGL lock(child_resource_provider_.get(), |
| 1004 resource); | 1003 resource); |
| 1005 | 1004 |
| 1006 gpu::Mailbox mailbox; | 1005 gpu::Mailbox mailbox; |
| 1007 context3d->genMailboxCHROMIUM(mailbox.name); | 1006 gl->GenMailboxCHROMIUM(mailbox.name); |
| 1008 unsigned sync_point = context3d->insertSyncPoint(); | 1007 GLuint sync_point = gl->InsertSyncPointCHROMIUM(); |
| 1009 | 1008 |
| 1010 scoped_refptr<Layer> root = Layer::Create(); | 1009 scoped_refptr<Layer> root = Layer::Create(); |
| 1011 root->SetBounds(gfx::Size(10, 10)); | 1010 root->SetBounds(gfx::Size(10, 10)); |
| 1012 root->SetAnchorPoint(gfx::PointF()); | 1011 root->SetAnchorPoint(gfx::PointF()); |
| 1013 root->SetIsDrawable(true); | 1012 root->SetIsDrawable(true); |
| 1014 | 1013 |
| 1015 scoped_refptr<FakeDelegatedRendererLayer> delegated = | 1014 scoped_refptr<FakeDelegatedRendererLayer> delegated = |
| 1016 FakeDelegatedRendererLayer::Create(delegated_frame_provider_.get()); | 1015 FakeDelegatedRendererLayer::Create(delegated_frame_provider_.get()); |
| 1017 delegated->SetBounds(gfx::Size(10, 10)); | 1016 delegated->SetBounds(gfx::Size(10, 10)); |
| 1018 delegated->SetAnchorPoint(gfx::PointF()); | 1017 delegated->SetAnchorPoint(gfx::PointF()); |
| (...skipping 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1892 ui_resource_.reset(); | 1891 ui_resource_.reset(); |
| 1893 EndTest(); | 1892 EndTest(); |
| 1894 break; | 1893 break; |
| 1895 case 4: | 1894 case 4: |
| 1896 NOTREACHED(); | 1895 NOTREACHED(); |
| 1897 } | 1896 } |
| 1898 } | 1897 } |
| 1899 | 1898 |
| 1900 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* impl, | 1899 virtual void DidSetVisibleOnImplTree(LayerTreeHostImpl* impl, |
| 1901 bool visible) OVERRIDE { | 1900 bool visible) OVERRIDE { |
| 1902 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( | 1901 TestWebGraphicsContext3D* context = static_cast<TestContextProvider*>( |
| 1903 impl->output_surface()->context_provider()->Context3d()); | 1902 impl->output_surface()->context_provider().get())->TestContext3d(); |
| 1904 if (!visible) { | 1903 if (!visible) { |
| 1905 // All resources should have been evicted. | 1904 // All resources should have been evicted. |
| 1906 ASSERT_EQ(0u, context->NumTextures()); | 1905 ASSERT_EQ(0u, context->NumTextures()); |
| 1907 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1906 EXPECT_EQ(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 1908 EXPECT_EQ(2, ui_resource_->resource_create_count); | 1907 EXPECT_EQ(2, ui_resource_->resource_create_count); |
| 1909 EXPECT_EQ(1, ui_resource_->lost_resource_count); | 1908 EXPECT_EQ(1, ui_resource_->lost_resource_count); |
| 1910 // Drawing is disabled both because of the evicted resources and | 1909 // Drawing is disabled both because of the evicted resources and |
| 1911 // because the renderer is not visible. | 1910 // because the renderer is not visible. |
| 1912 EXPECT_FALSE(impl->CanDraw()); | 1911 EXPECT_FALSE(impl->CanDraw()); |
| 1913 // Make the renderer visible again. | 1912 // Make the renderer visible again. |
| 1914 PostSetVisibleToMainThread(true); | 1913 PostSetVisibleToMainThread(true); |
| 1915 } | 1914 } |
| 1916 } | 1915 } |
| 1917 | 1916 |
| 1918 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { | 1917 virtual void StepCompleteOnImplThread(LayerTreeHostImpl* impl) OVERRIDE { |
| 1919 TestWebGraphicsContext3D* context = static_cast<TestWebGraphicsContext3D*>( | 1918 TestWebGraphicsContext3D* context = static_cast<TestContextProvider*>( |
| 1920 impl->output_surface()->context_provider()->Context3d()); | 1919 impl->output_surface()->context_provider().get())->TestContext3d(); |
| 1921 LayerTreeHostContextTest::CommitCompleteOnThread(impl); | 1920 LayerTreeHostContextTest::CommitCompleteOnThread(impl); |
| 1922 switch (time_step_) { | 1921 switch (time_step_) { |
| 1923 case 1: | 1922 case 1: |
| 1924 // The resource should have been created on LTHI after the commit. | 1923 // The resource should have been created on LTHI after the commit. |
| 1925 ASSERT_EQ(1u, context->NumTextures()); | 1924 ASSERT_EQ(1u, context->NumTextures()); |
| 1926 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); | 1925 EXPECT_NE(0u, impl->ResourceIdForUIResource(ui_resource_->id())); |
| 1927 EXPECT_EQ(1, ui_resource_->resource_create_count); | 1926 EXPECT_EQ(1, ui_resource_->resource_create_count); |
| 1928 EXPECT_EQ(0, ui_resource_->lost_resource_count); | 1927 EXPECT_EQ(0, ui_resource_->lost_resource_count); |
| 1929 EXPECT_TRUE(impl->CanDraw()); | 1928 EXPECT_TRUE(impl->CanDraw()); |
| 1930 // Evict all UI resources. This will trigger a commit. | 1929 // Evict all UI resources. This will trigger a commit. |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2022 protected: | 2021 protected: |
| 2023 FakeContentLayerClient client_; | 2022 FakeContentLayerClient client_; |
| 2024 scoped_refptr<FakeContentLayer> layer_; | 2023 scoped_refptr<FakeContentLayer> layer_; |
| 2025 int num_commits_; | 2024 int num_commits_; |
| 2026 }; | 2025 }; |
| 2027 | 2026 |
| 2028 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); | 2027 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostContextTestSurfaceCreateCallback); |
| 2029 | 2028 |
| 2030 } // namespace | 2029 } // namespace |
| 2031 } // namespace cc | 2030 } // namespace cc |
| OLD | NEW |