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