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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 | 11 |
12 #include "base/auto_reset.h" | 12 #include "base/auto_reset.h" |
13 #include "base/location.h" | 13 #include "base/location.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
18 #include "cc/animation/timing_function.h" | 18 #include "cc/animation/timing_function.h" |
19 #include "cc/debug/frame_rate_counter.h" | 19 #include "cc/debug/frame_rate_counter.h" |
20 #include "cc/input/scroll_elasticity_helper.h" | 20 #include "cc/input/scroll_elasticity_helper.h" |
21 #include "cc/layers/content_layer_client.h" | 21 #include "cc/layers/content_layer_client.h" |
22 #include "cc/layers/io_surface_layer.h" | |
23 #include "cc/layers/layer_impl.h" | 22 #include "cc/layers/layer_impl.h" |
24 #include "cc/layers/painted_scrollbar_layer.h" | 23 #include "cc/layers/painted_scrollbar_layer.h" |
25 #include "cc/layers/picture_layer.h" | 24 #include "cc/layers/picture_layer.h" |
26 #include "cc/layers/solid_color_layer.h" | 25 #include "cc/layers/solid_color_layer.h" |
27 #include "cc/layers/video_layer.h" | 26 #include "cc/layers/video_layer.h" |
28 #include "cc/output/begin_frame_args.h" | 27 #include "cc/output/begin_frame_args.h" |
29 #include "cc/output/compositor_frame_ack.h" | 28 #include "cc/output/compositor_frame_ack.h" |
30 #include "cc/output/copy_output_request.h" | 29 #include "cc/output/copy_output_request.h" |
31 #include "cc/output/copy_output_result.h" | 30 #include "cc/output/copy_output_result.h" |
32 #include "cc/output/output_surface.h" | 31 #include "cc/output/output_surface.h" |
(...skipping 2240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2273 } | 2272 } |
2274 | 2273 |
2275 void AfterTest() override {} | 2274 void AfterTest() override {} |
2276 | 2275 |
2277 FakeContentLayerClient client_; | 2276 FakeContentLayerClient client_; |
2278 }; | 2277 }; |
2279 | 2278 |
2280 SINGLE_AND_MULTI_THREAD_TEST_F( | 2279 SINGLE_AND_MULTI_THREAD_TEST_F( |
2281 LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation); | 2280 LayerTreeHostTestUninvertibleTransformDoesNotBlockActivation); |
2282 | 2281 |
2283 class MockIOSurfaceWebGraphicsContext3D : public TestWebGraphicsContext3D { | |
2284 public: | |
2285 MockIOSurfaceWebGraphicsContext3D() { | |
2286 test_capabilities_.gpu.iosurface = true; | |
2287 test_capabilities_.gpu.texture_rectangle = true; | |
2288 } | |
2289 | |
2290 GLuint createTexture() override { return 1; } | |
2291 MOCK_METHOD1(activeTexture, void(GLenum texture)); | |
2292 MOCK_METHOD2(bindTexture, void(GLenum target, | |
2293 GLuint texture_id)); | |
2294 MOCK_METHOD3(texParameteri, void(GLenum target, | |
2295 GLenum pname, | |
2296 GLint param)); | |
2297 MOCK_METHOD5(texImageIOSurface2DCHROMIUM, void(GLenum target, | |
2298 GLint width, | |
2299 GLint height, | |
2300 GLuint ioSurfaceId, | |
2301 GLuint plane)); | |
2302 MOCK_METHOD4(drawElements, void(GLenum mode, | |
2303 GLsizei count, | |
2304 GLenum type, | |
2305 GLintptr offset)); | |
2306 MOCK_METHOD1(deleteTexture, void(GLenum texture)); | |
2307 MOCK_METHOD3(produceTextureDirectCHROMIUM, | |
2308 void(GLuint texture, GLenum target, const GLbyte* mailbox)); | |
2309 }; | |
2310 | |
2311 class LayerTreeHostTestIOSurfaceDrawing : public LayerTreeHostTest { | |
2312 protected: | |
2313 std::unique_ptr<FakeOutputSurface> CreateFakeOutputSurface() override { | |
2314 std::unique_ptr<MockIOSurfaceWebGraphicsContext3D> mock_context_owned( | |
2315 new MockIOSurfaceWebGraphicsContext3D); | |
2316 mock_context_ = mock_context_owned.get(); | |
2317 | |
2318 if (delegating_renderer()) | |
2319 return FakeOutputSurface::CreateDelegating3d( | |
2320 std::move(mock_context_owned)); | |
2321 else | |
2322 return FakeOutputSurface::Create3d(std::move(mock_context_owned)); | |
2323 } | |
2324 | |
2325 void SetupTree() override { | |
2326 LayerTreeHostTest::SetupTree(); | |
2327 | |
2328 layer_tree_host()->root_layer()->SetIsDrawable(false); | |
2329 | |
2330 io_surface_id_ = 9; | |
2331 io_surface_size_ = gfx::Size(6, 7); | |
2332 | |
2333 scoped_refptr<IOSurfaceLayer> io_surface_layer = IOSurfaceLayer::Create(); | |
2334 io_surface_layer->SetBounds(gfx::Size(10, 10)); | |
2335 io_surface_layer->SetIsDrawable(true); | |
2336 io_surface_layer->SetContentsOpaque(true); | |
2337 io_surface_layer->SetIOSurfaceProperties(io_surface_id_, io_surface_size_); | |
2338 layer_tree_host()->root_layer()->AddChild(io_surface_layer); | |
2339 } | |
2340 | |
2341 void BeginTest() override { PostSetNeedsCommitToMainThread(); } | |
2342 | |
2343 void DidActivateTreeOnThread(LayerTreeHostImpl* host_impl) override { | |
2344 EXPECT_EQ(0u, host_impl->resource_provider()->num_resources()); | |
2345 // In WillDraw, the IOSurfaceLayer sets up the io surface texture. | |
2346 | |
2347 EXPECT_CALL(*mock_context_, activeTexture(_)).Times(0); | |
2348 EXPECT_CALL(*mock_context_, bindTexture(GL_TEXTURE_RECTANGLE_ARB, 1)) | |
2349 .Times(AtLeast(1)); | |
2350 EXPECT_CALL(*mock_context_, | |
2351 texParameteri( | |
2352 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR)) | |
2353 .Times(1); | |
2354 EXPECT_CALL(*mock_context_, | |
2355 texParameteri( | |
2356 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR)) | |
2357 .Times(1); | |
2358 EXPECT_CALL(*mock_context_, | |
2359 texParameteri(GL_TEXTURE_RECTANGLE_ARB, | |
2360 GL_TEXTURE_WRAP_S, | |
2361 GL_CLAMP_TO_EDGE)).Times(1); | |
2362 EXPECT_CALL(*mock_context_, | |
2363 texParameteri(GL_TEXTURE_RECTANGLE_ARB, | |
2364 GL_TEXTURE_WRAP_T, | |
2365 GL_CLAMP_TO_EDGE)).Times(1); | |
2366 | |
2367 EXPECT_CALL(*mock_context_, | |
2368 texImageIOSurface2DCHROMIUM(GL_TEXTURE_RECTANGLE_ARB, | |
2369 io_surface_size_.width(), | |
2370 io_surface_size_.height(), | |
2371 io_surface_id_, | |
2372 0)).Times(1); | |
2373 | |
2374 EXPECT_CALL(*mock_context_, bindTexture(_, 0)).Times(AnyNumber()); | |
2375 } | |
2376 | |
2377 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl, | |
2378 LayerTreeHostImpl::FrameData* frame, | |
2379 DrawResult draw_result) override { | |
2380 Mock::VerifyAndClearExpectations(&mock_context_); | |
2381 ResourceProvider* resource_provider = host_impl->resource_provider(); | |
2382 EXPECT_EQ(1u, resource_provider->num_resources()); | |
2383 CHECK_EQ(1u, frame->render_passes.size()); | |
2384 CHECK_LE(1u, frame->render_passes[0]->quad_list.size()); | |
2385 const DrawQuad* quad = frame->render_passes[0]->quad_list.front(); | |
2386 CHECK_EQ(DrawQuad::IO_SURFACE_CONTENT, quad->material); | |
2387 const IOSurfaceDrawQuad* io_surface_draw_quad = | |
2388 IOSurfaceDrawQuad::MaterialCast(quad); | |
2389 EXPECT_EQ(io_surface_size_, io_surface_draw_quad->io_surface_size); | |
2390 EXPECT_NE(0u, io_surface_draw_quad->io_surface_resource_id()); | |
2391 EXPECT_EQ(static_cast<GLenum>(GL_TEXTURE_RECTANGLE_ARB), | |
2392 resource_provider->GetResourceTextureTarget( | |
2393 io_surface_draw_quad->io_surface_resource_id())); | |
2394 | |
2395 if (delegating_renderer()) { | |
2396 // The io surface layer's resource should be sent to the parent. | |
2397 EXPECT_CALL(*mock_context_, produceTextureDirectCHROMIUM( | |
2398 _, GL_TEXTURE_RECTANGLE_ARB, _)).Times(1); | |
2399 } else { | |
2400 // The io surface layer's texture is drawn. | |
2401 EXPECT_CALL(*mock_context_, activeTexture(GL_TEXTURE0)).Times(AtLeast(1)); | |
2402 EXPECT_CALL(*mock_context_, drawElements(GL_TRIANGLES, 6, _, _)) | |
2403 .Times(AtLeast(1)); | |
2404 } | |
2405 | |
2406 return draw_result; | |
2407 } | |
2408 | |
2409 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override { | |
2410 Mock::VerifyAndClearExpectations(&mock_context_); | |
2411 | |
2412 EXPECT_CALL(*mock_context_, deleteTexture(1)).Times(AtLeast(1)); | |
2413 EndTest(); | |
2414 } | |
2415 | |
2416 void AfterTest() override {} | |
2417 | |
2418 int io_surface_id_; | |
2419 MockIOSurfaceWebGraphicsContext3D* mock_context_; | |
2420 gfx::Size io_surface_size_; | |
2421 }; | |
2422 | |
2423 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestIOSurfaceDrawing); | |
2424 | |
2425 class LayerTreeHostTestNumFramesPending : public LayerTreeHostTest { | 2282 class LayerTreeHostTestNumFramesPending : public LayerTreeHostTest { |
2426 public: | 2283 public: |
2427 void BeginTest() override { | 2284 void BeginTest() override { |
2428 frame_ = 0; | 2285 frame_ = 0; |
2429 PostSetNeedsCommitToMainThread(); | 2286 PostSetNeedsCommitToMainThread(); |
2430 } | 2287 } |
2431 | 2288 |
2432 // Round 1: commit + draw | 2289 // Round 1: commit + draw |
2433 // Round 2: commit only (no draw/swap) | 2290 // Round 2: commit only (no draw/swap) |
2434 // Round 3: draw only (no commit) | 2291 // Round 3: draw only (no commit) |
(...skipping 1348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3783 | 3640 |
3784 invalidate_layer_ = video_layer; | 3641 invalidate_layer_ = video_layer; |
3785 } | 3642 } |
3786 | 3643 |
3787 private: | 3644 private: |
3788 FakeVideoFrameProvider provider_; | 3645 FakeVideoFrameProvider provider_; |
3789 }; | 3646 }; |
3790 | 3647 |
3791 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestVideoLayerInvalidate); | 3648 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestVideoLayerInvalidate); |
3792 | 3649 |
3793 // IOSurfaceLayer must support being invalidated and then passing that along | |
3794 // to the compositor thread, even though no resources are updated in | |
3795 // response to that invalidation. | |
3796 class LayerTreeHostTestIOSurfaceLayerInvalidate | |
3797 : public LayerInvalidateCausesDraw { | |
3798 public: | |
3799 void SetupTree() override { | |
3800 LayerTreeHostTest::SetupTree(); | |
3801 scoped_refptr<IOSurfaceLayer> layer = IOSurfaceLayer::Create(); | |
3802 layer->SetBounds(gfx::Size(10, 10)); | |
3803 uint32_t fake_io_surface_id = 7; | |
3804 layer->SetIOSurfaceProperties(fake_io_surface_id, layer->bounds()); | |
3805 layer->SetIsDrawable(true); | |
3806 layer_tree_host()->root_layer()->AddChild(layer); | |
3807 | |
3808 invalidate_layer_ = layer; | |
3809 } | |
3810 }; | |
3811 | |
3812 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestIOSurfaceLayerInvalidate); | |
3813 | |
3814 class LayerTreeHostTestPushHiddenLayer : public LayerTreeHostTest { | 3650 class LayerTreeHostTestPushHiddenLayer : public LayerTreeHostTest { |
3815 protected: | 3651 protected: |
3816 void SetupTree() override { | 3652 void SetupTree() override { |
3817 root_layer_ = Layer::Create(); | 3653 root_layer_ = Layer::Create(); |
3818 root_layer_->SetPosition(gfx::PointF()); | 3654 root_layer_->SetPosition(gfx::PointF()); |
3819 root_layer_->SetBounds(gfx::Size(10, 10)); | 3655 root_layer_->SetBounds(gfx::Size(10, 10)); |
3820 | 3656 |
3821 parent_layer_ = SolidColorLayer::Create(); | 3657 parent_layer_ = SolidColorLayer::Create(); |
3822 parent_layer_->SetPosition(gfx::PointF()); | 3658 parent_layer_->SetPosition(gfx::PointF()); |
3823 parent_layer_->SetBounds(gfx::Size(10, 10)); | 3659 parent_layer_->SetBounds(gfx::Size(10, 10)); |
(...skipping 2800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6624 EndTest(); | 6460 EndTest(); |
6625 } | 6461 } |
6626 | 6462 |
6627 void AfterTest() override {} | 6463 void AfterTest() override {} |
6628 }; | 6464 }; |
6629 | 6465 |
6630 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPaintedDeviceScaleFactor); | 6466 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostTestPaintedDeviceScaleFactor); |
6631 | 6467 |
6632 } // namespace | 6468 } // namespace |
6633 } // namespace cc | 6469 } // namespace cc |
OLD | NEW |