| 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_impl.h" | 5 #include "cc/trees/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 2746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2757 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); | 2757 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); |
| 2758 | 2758 |
| 2759 // Even though the layer can't scroll the overscroll still happens. | 2759 // Even though the layer can't scroll the overscroll still happens. |
| 2760 EXPECT_EQ(InputHandler::ScrollStarted, | 2760 EXPECT_EQ(InputHandler::ScrollStarted, |
| 2761 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); | 2761 host_impl_->ScrollBegin(gfx::Point(), InputHandler::Wheel)); |
| 2762 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); | 2762 host_impl_->ScrollBy(gfx::Point(), gfx::Vector2d(0, 10)); |
| 2763 EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll()); | 2763 EXPECT_EQ(gfx::Vector2dF(0, 10), host_impl_->accumulated_root_overscroll()); |
| 2764 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); | 2764 EXPECT_EQ(gfx::Vector2dF(), host_impl_->current_fling_velocity()); |
| 2765 } | 2765 } |
| 2766 | 2766 |
| 2767 class BlendStateTrackerContext: public TestWebGraphicsContext3D { | |
| 2768 public: | |
| 2769 BlendStateTrackerContext() : blend_(false) {} | |
| 2770 | |
| 2771 virtual void enable(WebKit::WGC3Denum cap) OVERRIDE { | |
| 2772 if (cap == GL_BLEND) | |
| 2773 blend_ = true; | |
| 2774 } | |
| 2775 | |
| 2776 virtual void disable(WebKit::WGC3Denum cap) OVERRIDE { | |
| 2777 if (cap == GL_BLEND) | |
| 2778 blend_ = false; | |
| 2779 } | |
| 2780 | |
| 2781 bool blend() const { return blend_; } | |
| 2782 | |
| 2783 private: | |
| 2784 bool blend_; | |
| 2785 }; | |
| 2786 | |
| 2787 class BlendStateCheckLayer : public LayerImpl { | 2767 class BlendStateCheckLayer : public LayerImpl { |
| 2788 public: | 2768 public: |
| 2789 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, | 2769 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, |
| 2790 int id, | 2770 int id, |
| 2791 ResourceProvider* resource_provider) { | 2771 ResourceProvider* resource_provider) { |
| 2792 return scoped_ptr<LayerImpl>(new BlendStateCheckLayer(tree_impl, | 2772 return scoped_ptr<LayerImpl>(new BlendStateCheckLayer(tree_impl, |
| 2793 id, | 2773 id, |
| 2794 resource_provider)); | 2774 resource_provider)); |
| 2795 } | 2775 } |
| 2796 | 2776 |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3370 host_impl_->CreatePendingTree(); | 3350 host_impl_->CreatePendingTree(); |
| 3371 host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); | 3351 host_impl_->SetViewportSize(DipSizeToPixelSize(viewport_size_)); |
| 3372 EXPECT_TRUE(host_impl_->active_tree()->ViewportSizeInvalid()); | 3352 EXPECT_TRUE(host_impl_->active_tree()->ViewportSizeInvalid()); |
| 3373 | 3353 |
| 3374 SetupActiveTreeLayers(); | 3354 SetupActiveTreeLayers(); |
| 3375 TestEmptyLayer(); | 3355 TestEmptyLayer(); |
| 3376 TestLayerInMiddleOfViewport(); | 3356 TestLayerInMiddleOfViewport(); |
| 3377 TestLayerIsLargerThanViewport(); | 3357 TestLayerIsLargerThanViewport(); |
| 3378 } | 3358 } |
| 3379 | 3359 |
| 3380 class ReshapeTrackerContext: public TestWebGraphicsContext3D { | |
| 3381 public: | |
| 3382 ReshapeTrackerContext() | |
| 3383 : reshape_called_(false), | |
| 3384 last_reshape_width_(-1), | |
| 3385 last_reshape_height_(-1), | |
| 3386 last_reshape_scale_factor_(-1.f) { | |
| 3387 } | |
| 3388 | |
| 3389 virtual void reshapeWithScaleFactor( | |
| 3390 int width, int height, float scale_factor) OVERRIDE { | |
| 3391 reshape_called_ = true; | |
| 3392 last_reshape_width_ = width; | |
| 3393 last_reshape_height_ = height; | |
| 3394 last_reshape_scale_factor_ = scale_factor; | |
| 3395 } | |
| 3396 | |
| 3397 bool reshape_called() const { return reshape_called_; } | |
| 3398 void clear_reshape_called() { reshape_called_ = false; } | |
| 3399 int last_reshape_width() { return last_reshape_width_; } | |
| 3400 int last_reshape_height() { return last_reshape_height_; } | |
| 3401 int last_reshape_scale_factor() { return last_reshape_scale_factor_; } | |
| 3402 | |
| 3403 private: | |
| 3404 bool reshape_called_; | |
| 3405 int last_reshape_width_; | |
| 3406 int last_reshape_height_; | |
| 3407 float last_reshape_scale_factor_; | |
| 3408 }; | |
| 3409 | |
| 3410 class FakeDrawableLayerImpl: public LayerImpl { | 3360 class FakeDrawableLayerImpl: public LayerImpl { |
| 3411 public: | 3361 public: |
| 3412 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) { | 3362 static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) { |
| 3413 return scoped_ptr<LayerImpl>(new FakeDrawableLayerImpl(tree_impl, id)); | 3363 return scoped_ptr<LayerImpl>(new FakeDrawableLayerImpl(tree_impl, id)); |
| 3414 } | 3364 } |
| 3415 protected: | 3365 protected: |
| 3416 FakeDrawableLayerImpl(LayerTreeImpl* tree_impl, int id) | 3366 FakeDrawableLayerImpl(LayerTreeImpl* tree_impl, int id) |
| 3417 : LayerImpl(tree_impl, id) {} | 3367 : LayerImpl(tree_impl, id) {} |
| 3418 }; | 3368 }; |
| 3419 | 3369 |
| 3420 // Only reshape when we know we are going to draw. Otherwise, the reshape | 3370 // Only reshape when we know we are going to draw. Otherwise, the reshape |
| 3421 // can leave the window at the wrong size if we never draw and the proper | 3371 // can leave the window at the wrong size if we never draw and the proper |
| 3422 // viewport size is never set. | 3372 // viewport size is never set. |
| 3423 TEST_F(LayerTreeHostImplTest, ReshapeNotCalledUntilDraw) { | 3373 TEST_F(LayerTreeHostImplTest, ReshapeNotCalledUntilDraw) { |
| 3424 scoped_ptr<ReshapeTrackerContext> owned_reshape_tracker( | 3374 scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); |
| 3425 new ReshapeTrackerContext); | 3375 scoped_ptr<OutputSurface> output_surface( |
| 3426 ReshapeTrackerContext* reshape_tracker = owned_reshape_tracker.get(); | 3376 FakeOutputSurface::Create3d(provider)); |
| 3427 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | |
| 3428 owned_reshape_tracker.PassAs<TestWebGraphicsContext3D>())); | |
| 3429 host_impl_->InitializeRenderer(output_surface.Pass()); | 3377 host_impl_->InitializeRenderer(output_surface.Pass()); |
| 3430 | 3378 |
| 3431 scoped_ptr<LayerImpl> root = | 3379 scoped_ptr<LayerImpl> root = |
| 3432 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 1); | 3380 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 1); |
| 3433 root->SetAnchorPoint(gfx::PointF()); | 3381 root->SetAnchorPoint(gfx::PointF()); |
| 3434 root->SetBounds(gfx::Size(10, 10)); | 3382 root->SetBounds(gfx::Size(10, 10)); |
| 3435 root->SetContentBounds(gfx::Size(10, 10)); | 3383 root->SetContentBounds(gfx::Size(10, 10)); |
| 3436 root->SetDrawsContent(true); | 3384 root->SetDrawsContent(true); |
| 3437 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 3385 host_impl_->active_tree()->SetRootLayer(root.Pass()); |
| 3438 EXPECT_FALSE(reshape_tracker->reshape_called()); | 3386 EXPECT_FALSE(provider->TestContext3d()->reshape_called()); |
| 3439 reshape_tracker->clear_reshape_called(); | 3387 provider->TestContext3d()->clear_reshape_called(); |
| 3440 | 3388 |
| 3441 LayerTreeHostImpl::FrameData frame; | 3389 LayerTreeHostImpl::FrameData frame; |
| 3442 host_impl_->SetViewportSize(gfx::Size(10, 10)); | 3390 host_impl_->SetViewportSize(gfx::Size(10, 10)); |
| 3443 host_impl_->SetDeviceScaleFactor(1.f); | 3391 host_impl_->SetDeviceScaleFactor(1.f); |
| 3444 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); | 3392 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); |
| 3445 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); | 3393 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); |
| 3446 EXPECT_TRUE(reshape_tracker->reshape_called()); | 3394 EXPECT_TRUE(provider->TestContext3d()->reshape_called()); |
| 3447 EXPECT_EQ(reshape_tracker->last_reshape_width(), 10); | 3395 EXPECT_EQ(provider->TestContext3d()->width(), 10); |
| 3448 EXPECT_EQ(reshape_tracker->last_reshape_height(), 10); | 3396 EXPECT_EQ(provider->TestContext3d()->height(), 10); |
| 3449 EXPECT_EQ(reshape_tracker->last_reshape_scale_factor(), 1.f); | 3397 EXPECT_EQ(provider->TestContext3d()->scale_factor(), 1.f); |
| 3450 host_impl_->DidDrawAllLayers(frame); | 3398 host_impl_->DidDrawAllLayers(frame); |
| 3451 reshape_tracker->clear_reshape_called(); | 3399 provider->TestContext3d()->clear_reshape_called(); |
| 3452 | 3400 |
| 3453 host_impl_->SetViewportSize(gfx::Size(20, 30)); | 3401 host_impl_->SetViewportSize(gfx::Size(20, 30)); |
| 3454 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); | 3402 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); |
| 3455 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); | 3403 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); |
| 3456 EXPECT_TRUE(reshape_tracker->reshape_called()); | 3404 EXPECT_TRUE(provider->TestContext3d()->reshape_called()); |
| 3457 EXPECT_EQ(reshape_tracker->last_reshape_width(), 20); | 3405 EXPECT_EQ(provider->TestContext3d()->width(), 20); |
| 3458 EXPECT_EQ(reshape_tracker->last_reshape_height(), 30); | 3406 EXPECT_EQ(provider->TestContext3d()->height(), 30); |
| 3459 EXPECT_EQ(reshape_tracker->last_reshape_scale_factor(), 1.f); | 3407 EXPECT_EQ(provider->TestContext3d()->scale_factor(), 1.f); |
| 3460 host_impl_->DidDrawAllLayers(frame); | 3408 host_impl_->DidDrawAllLayers(frame); |
| 3461 reshape_tracker->clear_reshape_called(); | 3409 provider->TestContext3d()->clear_reshape_called(); |
| 3462 | 3410 |
| 3463 host_impl_->SetDeviceScaleFactor(2.f); | 3411 host_impl_->SetDeviceScaleFactor(2.f); |
| 3464 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); | 3412 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); |
| 3465 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); | 3413 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); |
| 3466 EXPECT_TRUE(reshape_tracker->reshape_called()); | 3414 EXPECT_TRUE(provider->TestContext3d()->reshape_called()); |
| 3467 EXPECT_EQ(reshape_tracker->last_reshape_width(), 20); | 3415 EXPECT_EQ(provider->TestContext3d()->width(), 20); |
| 3468 EXPECT_EQ(reshape_tracker->last_reshape_height(), 30); | 3416 EXPECT_EQ(provider->TestContext3d()->height(), 30); |
| 3469 EXPECT_EQ(reshape_tracker->last_reshape_scale_factor(), 2.f); | 3417 EXPECT_EQ(provider->TestContext3d()->scale_factor(), 2.f); |
| 3470 host_impl_->DidDrawAllLayers(frame); | 3418 host_impl_->DidDrawAllLayers(frame); |
| 3471 reshape_tracker->clear_reshape_called(); | 3419 provider->TestContext3d()->clear_reshape_called(); |
| 3472 } | 3420 } |
| 3473 | 3421 |
| 3474 class SwapTrackerContext : public TestWebGraphicsContext3D { | |
| 3475 public: | |
| 3476 SwapTrackerContext() | |
| 3477 : last_update_type_(NoUpdate) { | |
| 3478 test_capabilities_.post_sub_buffer = true; | |
| 3479 test_capabilities_.set_visibility = true; | |
| 3480 } | |
| 3481 | |
| 3482 virtual void prepareTexture() OVERRIDE { | |
| 3483 update_rect_ = gfx::Rect(width_, height_); | |
| 3484 last_update_type_ = PrepareTexture; | |
| 3485 } | |
| 3486 | |
| 3487 virtual void postSubBufferCHROMIUM(int x, int y, int width, int height) | |
| 3488 OVERRIDE { | |
| 3489 update_rect_ = gfx::Rect(x, y, width, height); | |
| 3490 last_update_type_ = PostSubBuffer; | |
| 3491 } | |
| 3492 | |
| 3493 gfx::Rect update_rect() const { return update_rect_; } | |
| 3494 | |
| 3495 enum UpdateType { | |
| 3496 NoUpdate = 0, | |
| 3497 PrepareTexture, | |
| 3498 PostSubBuffer | |
| 3499 }; | |
| 3500 | |
| 3501 UpdateType last_update_type() { | |
| 3502 return last_update_type_; | |
| 3503 } | |
| 3504 | |
| 3505 private: | |
| 3506 gfx::Rect update_rect_; | |
| 3507 UpdateType last_update_type_; | |
| 3508 }; | |
| 3509 | |
| 3510 // Make sure damage tracking propagates all the way to the graphics context, | 3422 // Make sure damage tracking propagates all the way to the graphics context, |
| 3511 // where it should request to swap only the sub-buffer that is damaged. | 3423 // where it should request to swap only the sub-buffer that is damaged. |
| 3512 TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) { | 3424 TEST_F(LayerTreeHostImplTest, PartialSwapReceivesDamageRect) { |
| 3513 scoped_ptr<SwapTrackerContext> context(new SwapTrackerContext); | 3425 scoped_refptr<TestContextProvider> provider( |
| 3514 SwapTrackerContext* swap_tracker = context.get(); | 3426 TestContextProvider::Create()); |
| 3427 scoped_ptr<OutputSurface> output_surface( |
| 3428 FakeOutputSurface::Create3d(provider)); |
| 3515 | 3429 |
| 3516 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 3430 provider->BindToCurrentThread(); |
| 3517 context.PassAs<TestWebGraphicsContext3D>())); | 3431 TestWebGraphicsContext3D* context = provider->TestContext3d(); |
| 3432 context->set_have_post_sub_buffer(true); |
| 3518 | 3433 |
| 3519 // This test creates its own LayerTreeHostImpl, so | 3434 // This test creates its own LayerTreeHostImpl, so |
| 3520 // that we can force partial swap enabled. | 3435 // that we can force partial swap enabled. |
| 3521 LayerTreeSettings settings; | 3436 LayerTreeSettings settings; |
| 3522 settings.partial_swap_enabled = true; | 3437 settings.partial_swap_enabled = true; |
| 3523 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl = | 3438 scoped_ptr<LayerTreeHostImpl> layer_tree_host_impl = |
| 3524 LayerTreeHostImpl::Create( | 3439 LayerTreeHostImpl::Create( |
| 3525 settings, this, &proxy_, &stats_instrumentation_, NULL); | 3440 settings, this, &proxy_, &stats_instrumentation_, NULL); |
| 3526 layer_tree_host_impl->InitializeRenderer(output_surface.Pass()); | 3441 layer_tree_host_impl->InitializeRenderer(output_surface.Pass()); |
| 3527 layer_tree_host_impl->SetViewportSize(gfx::Size(500, 500)); | 3442 layer_tree_host_impl->SetViewportSize(gfx::Size(500, 500)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3542 root->AddChild(child.Pass()); | 3457 root->AddChild(child.Pass()); |
| 3543 layer_tree_host_impl->active_tree()->SetRootLayer(root.Pass()); | 3458 layer_tree_host_impl->active_tree()->SetRootLayer(root.Pass()); |
| 3544 | 3459 |
| 3545 LayerTreeHostImpl::FrameData frame; | 3460 LayerTreeHostImpl::FrameData frame; |
| 3546 | 3461 |
| 3547 // First frame, the entire screen should get swapped. | 3462 // First frame, the entire screen should get swapped. |
| 3548 EXPECT_TRUE(layer_tree_host_impl->PrepareToDraw(&frame, gfx::Rect())); | 3463 EXPECT_TRUE(layer_tree_host_impl->PrepareToDraw(&frame, gfx::Rect())); |
| 3549 layer_tree_host_impl->DrawLayers(&frame, gfx::FrameTime::Now()); | 3464 layer_tree_host_impl->DrawLayers(&frame, gfx::FrameTime::Now()); |
| 3550 layer_tree_host_impl->DidDrawAllLayers(frame); | 3465 layer_tree_host_impl->DidDrawAllLayers(frame); |
| 3551 layer_tree_host_impl->SwapBuffers(frame); | 3466 layer_tree_host_impl->SwapBuffers(frame); |
| 3552 gfx::Rect actual_swap_rect = swap_tracker->update_rect(); | 3467 gfx::Rect actual_swap_rect = context->update_rect(); |
| 3553 gfx::Rect expected_swap_rect = gfx::Rect(0, 0, 500, 500); | 3468 gfx::Rect expected_swap_rect = gfx::Rect(0, 0, 500, 500); |
| 3554 EXPECT_EQ(expected_swap_rect.x(), actual_swap_rect.x()); | 3469 EXPECT_EQ(expected_swap_rect.x(), actual_swap_rect.x()); |
| 3555 EXPECT_EQ(expected_swap_rect.y(), actual_swap_rect.y()); | 3470 EXPECT_EQ(expected_swap_rect.y(), actual_swap_rect.y()); |
| 3556 EXPECT_EQ(expected_swap_rect.width(), actual_swap_rect.width()); | 3471 EXPECT_EQ(expected_swap_rect.width(), actual_swap_rect.width()); |
| 3557 EXPECT_EQ(expected_swap_rect.height(), actual_swap_rect.height()); | 3472 EXPECT_EQ(expected_swap_rect.height(), actual_swap_rect.height()); |
| 3558 EXPECT_EQ(swap_tracker->last_update_type(), | 3473 EXPECT_EQ(context->last_update_type(), |
| 3559 SwapTrackerContext::PrepareTexture); | 3474 TestWebGraphicsContext3D::PrepareTexture); |
| 3560 // Second frame, only the damaged area should get swapped. Damage should be | 3475 // Second frame, only the damaged area should get swapped. Damage should be |
| 3561 // the union of old and new child rects. | 3476 // the union of old and new child rects. |
| 3562 // expected damage rect: gfx::Rect(26, 28); | 3477 // expected damage rect: gfx::Rect(26, 28); |
| 3563 // expected swap rect: vertically flipped, with origin at bottom left corner. | 3478 // expected swap rect: vertically flipped, with origin at bottom left corner. |
| 3564 layer_tree_host_impl->active_tree()->root_layer()->children()[0]->SetPosition( | 3479 layer_tree_host_impl->active_tree()->root_layer()->children()[0]->SetPosition( |
| 3565 gfx::PointF()); | 3480 gfx::PointF()); |
| 3566 EXPECT_TRUE(layer_tree_host_impl->PrepareToDraw(&frame, gfx::Rect())); | 3481 EXPECT_TRUE(layer_tree_host_impl->PrepareToDraw(&frame, gfx::Rect())); |
| 3567 layer_tree_host_impl->DrawLayers(&frame, gfx::FrameTime::Now()); | 3482 layer_tree_host_impl->DrawLayers(&frame, gfx::FrameTime::Now()); |
| 3568 host_impl_->DidDrawAllLayers(frame); | 3483 host_impl_->DidDrawAllLayers(frame); |
| 3569 layer_tree_host_impl->SwapBuffers(frame); | 3484 layer_tree_host_impl->SwapBuffers(frame); |
| 3570 actual_swap_rect = swap_tracker->update_rect(); | 3485 actual_swap_rect = context->update_rect(); |
| 3571 expected_swap_rect = gfx::Rect(0, 500-28, 26, 28); | 3486 expected_swap_rect = gfx::Rect(0, 500-28, 26, 28); |
| 3572 EXPECT_EQ(expected_swap_rect.x(), actual_swap_rect.x()); | 3487 EXPECT_EQ(expected_swap_rect.x(), actual_swap_rect.x()); |
| 3573 EXPECT_EQ(expected_swap_rect.y(), actual_swap_rect.y()); | 3488 EXPECT_EQ(expected_swap_rect.y(), actual_swap_rect.y()); |
| 3574 EXPECT_EQ(expected_swap_rect.width(), actual_swap_rect.width()); | 3489 EXPECT_EQ(expected_swap_rect.width(), actual_swap_rect.width()); |
| 3575 EXPECT_EQ(expected_swap_rect.height(), actual_swap_rect.height()); | 3490 EXPECT_EQ(expected_swap_rect.height(), actual_swap_rect.height()); |
| 3576 EXPECT_EQ(swap_tracker->last_update_type(), | 3491 EXPECT_EQ(context->last_update_type(), |
| 3577 SwapTrackerContext::PostSubBuffer); | 3492 TestWebGraphicsContext3D::PostSubBuffer); |
| 3578 | 3493 |
| 3579 // Make sure that partial swap is constrained to the viewport dimensions | 3494 // Make sure that partial swap is constrained to the viewport dimensions |
| 3580 // expected damage rect: gfx::Rect(500, 500); | 3495 // expected damage rect: gfx::Rect(500, 500); |
| 3581 // expected swap rect: flipped damage rect, but also clamped to viewport | 3496 // expected swap rect: flipped damage rect, but also clamped to viewport |
| 3582 layer_tree_host_impl->SetViewportSize(gfx::Size(10, 10)); | 3497 layer_tree_host_impl->SetViewportSize(gfx::Size(10, 10)); |
| 3583 // This will damage everything. | 3498 // This will damage everything. |
| 3584 layer_tree_host_impl->active_tree()->root_layer()->SetBackgroundColor( | 3499 layer_tree_host_impl->active_tree()->root_layer()->SetBackgroundColor( |
| 3585 SK_ColorBLACK); | 3500 SK_ColorBLACK); |
| 3586 EXPECT_TRUE(layer_tree_host_impl->PrepareToDraw(&frame, gfx::Rect())); | 3501 EXPECT_TRUE(layer_tree_host_impl->PrepareToDraw(&frame, gfx::Rect())); |
| 3587 layer_tree_host_impl->DrawLayers(&frame, gfx::FrameTime::Now()); | 3502 layer_tree_host_impl->DrawLayers(&frame, gfx::FrameTime::Now()); |
| 3588 host_impl_->DidDrawAllLayers(frame); | 3503 host_impl_->DidDrawAllLayers(frame); |
| 3589 layer_tree_host_impl->SwapBuffers(frame); | 3504 layer_tree_host_impl->SwapBuffers(frame); |
| 3590 actual_swap_rect = swap_tracker->update_rect(); | 3505 actual_swap_rect = context->update_rect(); |
| 3591 expected_swap_rect = gfx::Rect(10, 10); | 3506 expected_swap_rect = gfx::Rect(10, 10); |
| 3592 EXPECT_EQ(expected_swap_rect.x(), actual_swap_rect.x()); | 3507 EXPECT_EQ(expected_swap_rect.x(), actual_swap_rect.x()); |
| 3593 EXPECT_EQ(expected_swap_rect.y(), actual_swap_rect.y()); | 3508 EXPECT_EQ(expected_swap_rect.y(), actual_swap_rect.y()); |
| 3594 EXPECT_EQ(expected_swap_rect.width(), actual_swap_rect.width()); | 3509 EXPECT_EQ(expected_swap_rect.width(), actual_swap_rect.width()); |
| 3595 EXPECT_EQ(expected_swap_rect.height(), actual_swap_rect.height()); | 3510 EXPECT_EQ(expected_swap_rect.height(), actual_swap_rect.height()); |
| 3596 EXPECT_EQ(swap_tracker->last_update_type(), | 3511 EXPECT_EQ(context->last_update_type(), |
| 3597 SwapTrackerContext::PrepareTexture); | 3512 TestWebGraphicsContext3D::PrepareTexture); |
| 3598 } | 3513 } |
| 3599 | 3514 |
| 3600 TEST_F(LayerTreeHostImplTest, RootLayerDoesntCreateExtraSurface) { | 3515 TEST_F(LayerTreeHostImplTest, RootLayerDoesntCreateExtraSurface) { |
| 3601 scoped_ptr<LayerImpl> root = | 3516 scoped_ptr<LayerImpl> root = |
| 3602 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 1); | 3517 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 1); |
| 3603 scoped_ptr<LayerImpl> child = | 3518 scoped_ptr<LayerImpl> child = |
| 3604 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 2); | 3519 FakeDrawableLayerImpl::Create(host_impl_->active_tree(), 2); |
| 3605 child->SetAnchorPoint(gfx::PointF()); | 3520 child->SetAnchorPoint(gfx::PointF()); |
| 3606 child->SetBounds(gfx::Size(10, 10)); | 3521 child->SetBounds(gfx::Size(10, 10)); |
| 3607 child->SetContentBounds(gfx::Size(10, 10)); | 3522 child->SetContentBounds(gfx::Size(10, 10)); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3801 harness.MustDrawSolidQuad(); | 3716 harness.MustDrawSolidQuad(); |
| 3802 { | 3717 { |
| 3803 LayerTreeHostImpl::FrameData frame; | 3718 LayerTreeHostImpl::FrameData frame; |
| 3804 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); | 3719 EXPECT_TRUE(host_impl_->PrepareToDraw(&frame, gfx::Rect())); |
| 3805 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); | 3720 host_impl_->DrawLayers(&frame, gfx::FrameTime::Now()); |
| 3806 host_impl_->DidDrawAllLayers(frame); | 3721 host_impl_->DidDrawAllLayers(frame); |
| 3807 } | 3722 } |
| 3808 Mock::VerifyAndClearExpectations(&mock_context); | 3723 Mock::VerifyAndClearExpectations(&mock_context); |
| 3809 } | 3724 } |
| 3810 | 3725 |
| 3811 class PartialSwapContext : public TestWebGraphicsContext3D { | |
| 3812 public: | |
| 3813 PartialSwapContext() { | |
| 3814 test_capabilities_.post_sub_buffer = true; | |
| 3815 } | |
| 3816 | |
| 3817 // Unlimited texture size. | |
| 3818 virtual void getIntegerv(WebKit::WGC3Denum pname, WebKit::WGC3Dint* value) | |
| 3819 OVERRIDE { | |
| 3820 if (pname == GL_MAX_TEXTURE_SIZE) | |
| 3821 *value = 8192; | |
| 3822 else if (pname == GL_ACTIVE_TEXTURE) | |
| 3823 *value = GL_TEXTURE0; | |
| 3824 } | |
| 3825 }; | |
| 3826 | |
| 3827 static scoped_ptr<LayerTreeHostImpl> SetupLayersForOpacity( | 3726 static scoped_ptr<LayerTreeHostImpl> SetupLayersForOpacity( |
| 3828 bool partial_swap, | 3727 bool partial_swap, |
| 3829 LayerTreeHostImplClient* client, | 3728 LayerTreeHostImplClient* client, |
| 3830 Proxy* proxy, | 3729 Proxy* proxy, |
| 3831 RenderingStatsInstrumentation* stats_instrumentation) { | 3730 RenderingStatsInstrumentation* stats_instrumentation) { |
| 3832 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 3731 scoped_refptr<TestContextProvider> provider(TestContextProvider::Create()); |
| 3833 scoped_ptr<TestWebGraphicsContext3D>(new PartialSwapContext))); | 3732 scoped_ptr<OutputSurface> output_surface( |
| 3733 FakeOutputSurface::Create3d(provider)); |
| 3734 provider->BindToCurrentThread(); |
| 3735 provider->TestContext3d()->set_have_post_sub_buffer(true); |
| 3834 | 3736 |
| 3835 LayerTreeSettings settings; | 3737 LayerTreeSettings settings; |
| 3836 settings.partial_swap_enabled = partial_swap; | 3738 settings.partial_swap_enabled = partial_swap; |
| 3837 scoped_ptr<LayerTreeHostImpl> my_host_impl = LayerTreeHostImpl::Create( | 3739 scoped_ptr<LayerTreeHostImpl> my_host_impl = LayerTreeHostImpl::Create( |
| 3838 settings, client, proxy, stats_instrumentation, NULL); | 3740 settings, client, proxy, stats_instrumentation, NULL); |
| 3839 my_host_impl->InitializeRenderer(output_surface.Pass()); | 3741 my_host_impl->InitializeRenderer(output_surface.Pass()); |
| 3840 my_host_impl->SetViewportSize(gfx::Size(100, 100)); | 3742 my_host_impl->SetViewportSize(gfx::Size(100, 100)); |
| 3841 | 3743 |
| 3842 /* | 3744 /* |
| 3843 Layers are created as follows: | 3745 Layers are created as follows: |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3935 EXPECT_EQ(DrawQuad::SOLID_COLOR, | 3837 EXPECT_EQ(DrawQuad::SOLID_COLOR, |
| 3936 frame.render_passes[0]->quad_list[0]->material); | 3838 frame.render_passes[0]->quad_list[0]->material); |
| 3937 EXPECT_EQ(DrawQuad::RENDER_PASS, | 3839 EXPECT_EQ(DrawQuad::RENDER_PASS, |
| 3938 frame.render_passes[1]->quad_list[0]->material); | 3840 frame.render_passes[1]->quad_list[0]->material); |
| 3939 | 3841 |
| 3940 my_host_impl->DrawLayers(&frame, gfx::FrameTime::Now()); | 3842 my_host_impl->DrawLayers(&frame, gfx::FrameTime::Now()); |
| 3941 my_host_impl->DidDrawAllLayers(frame); | 3843 my_host_impl->DidDrawAllLayers(frame); |
| 3942 } | 3844 } |
| 3943 } | 3845 } |
| 3944 | 3846 |
| 3945 // Fake WebKit::WebGraphicsContext3D that tracks the number of textures in use. | |
| 3946 class TrackingWebGraphicsContext3D : public TestWebGraphicsContext3D { | |
| 3947 public: | |
| 3948 TrackingWebGraphicsContext3D() | |
| 3949 : TestWebGraphicsContext3D(), | |
| 3950 num_textures_(0) { | |
| 3951 test_capabilities_.iosurface = true; | |
| 3952 test_capabilities_.texture_rectangle = true; | |
| 3953 } | |
| 3954 | |
| 3955 virtual WebKit::WebGLId createTexture() OVERRIDE { | |
| 3956 WebKit::WebGLId id = TestWebGraphicsContext3D::createTexture(); | |
| 3957 | |
| 3958 textures_[id] = true; | |
| 3959 ++num_textures_; | |
| 3960 return id; | |
| 3961 } | |
| 3962 | |
| 3963 virtual void deleteTexture(WebKit::WebGLId id) OVERRIDE { | |
| 3964 if (textures_.find(id) == textures_.end()) | |
| 3965 return; | |
| 3966 | |
| 3967 textures_[id] = false; | |
| 3968 --num_textures_; | |
| 3969 } | |
| 3970 | |
| 3971 unsigned num_textures() const { return num_textures_; } | |
| 3972 | |
| 3973 private: | |
| 3974 base::hash_map<WebKit::WebGLId, bool> textures_; | |
| 3975 unsigned num_textures_; | |
| 3976 }; | |
| 3977 | |
| 3978 TEST_F(LayerTreeHostImplTest, LayersFreeTextures) { | 3847 TEST_F(LayerTreeHostImplTest, LayersFreeTextures) { |
| 3979 scoped_ptr<TestWebGraphicsContext3D> context = | 3848 scoped_ptr<TestWebGraphicsContext3D> context = |
| 3980 TestWebGraphicsContext3D::Create(); | 3849 TestWebGraphicsContext3D::Create(); |
| 3981 TestWebGraphicsContext3D* context3d = context.get(); | 3850 TestWebGraphicsContext3D* context3d = context.get(); |
| 3982 scoped_ptr<OutputSurface> output_surface( | 3851 scoped_ptr<OutputSurface> output_surface( |
| 3983 FakeOutputSurface::Create3d(context.Pass())); | 3852 FakeOutputSurface::Create3d(context.Pass())); |
| 3984 host_impl_->InitializeRenderer(output_surface.Pass()); | 3853 host_impl_->InitializeRenderer(output_surface.Pass()); |
| 3985 | 3854 |
| 3986 scoped_ptr<LayerImpl> root_layer = | 3855 scoped_ptr<LayerImpl> root_layer = |
| 3987 LayerImpl::Create(host_impl_->active_tree(), 1); | 3856 LayerImpl::Create(host_impl_->active_tree(), 1); |
| (...skipping 1477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5465 // The root should have scrolled. | 5334 // The root should have scrolled. |
| 5466 ASSERT_EQ(2u, scroll_info->scrolls.size()); | 5335 ASSERT_EQ(2u, scroll_info->scrolls.size()); |
| 5467 ExpectContains(*scroll_info.get(), | 5336 ExpectContains(*scroll_info.get(), |
| 5468 host_impl_->active_tree()->root_layer()->id(), | 5337 host_impl_->active_tree()->root_layer()->id(), |
| 5469 gfx::Vector2d(0, 10)); | 5338 gfx::Vector2d(0, 10)); |
| 5470 } | 5339 } |
| 5471 } | 5340 } |
| 5472 | 5341 |
| 5473 } // namespace | 5342 } // namespace |
| 5474 } // namespace cc | 5343 } // namespace cc |
| OLD | NEW |