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