Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(152)

Side by Side Diff: cc/surfaces/surface_aggregator_unittest.cc

Issue 368403003: Use RenderPass to create DrawQuad in unittests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@layerrawptrDQ
Patch Set: address review comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/output/compositor_frame.h" 5 #include "cc/output/compositor_frame.h"
6 #include "cc/output/delegated_frame_data.h" 6 #include "cc/output/delegated_frame_data.h"
7 #include "cc/quads/render_pass.h" 7 #include "cc/quads/render_pass.h"
8 #include "cc/quads/render_pass_draw_quad.h" 8 #include "cc/quads/render_pass_draw_quad.h"
9 #include "cc/quads/solid_color_draw_quad.h" 9 #include "cc/quads/solid_color_draw_quad.h"
10 #include "cc/quads/surface_draw_quad.h" 10 #include "cc/quads/surface_draw_quad.h"
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); 480 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
481 sqs->SetAll(content_to_target_transform, 481 sqs->SetAll(content_to_target_transform,
482 content_bounds, 482 content_bounds,
483 visible_content_rect, 483 visible_content_rect,
484 clip_rect, 484 clip_rect,
485 is_clipped, 485 is_clipped,
486 opacity, 486 opacity,
487 blend_mode, 487 blend_mode,
488 0); 488 0);
489 489
490 scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create(); 490 SolidColorDrawQuad* color_quad =
491 pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>();
491 color_quad->SetNew(pass->shared_quad_state_list.back(), 492 color_quad->SetNew(pass->shared_quad_state_list.back(),
492 visible_content_rect, 493 visible_content_rect,
493 visible_content_rect, 494 visible_content_rect,
494 SK_ColorGREEN, 495 SK_ColorGREEN,
495 force_anti_aliasing_off); 496 force_anti_aliasing_off);
496 pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
497 } 497 }
498 498
499 // This tests that we update shared quad state pointers correctly within 499 // This tests that we update shared quad state pointers correctly within
500 // aggregated passes. The shared quad state list on the aggregated pass will 500 // aggregated passes. The shared quad state list on the aggregated pass will
501 // include the shared quad states from each pass in one list so the quads will 501 // include the shared quad states from each pass in one list so the quads will
502 // end up pointed to shared quad state objects at different offsets. This test 502 // end up pointed to shared quad state objects at different offsets. This test
503 // uses the blend_mode value stored on the shared quad state to track the shared 503 // uses the blend_mode value stored on the shared quad state to track the shared
504 // quad state, but anything saved on the shared quad state would work. 504 // quad state, but anything saved on the shared quad state would work.
505 // 505 //
506 // This test has 4 surfaces in the following structure: 506 // This test has 4 surfaces in the following structure:
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 QueuePassAsFrame(grandchild_pass.Pass(), grandchild_surface_id); 547 QueuePassAsFrame(grandchild_pass.Pass(), grandchild_surface_id);
548 548
549 SurfaceId child_one_surface_id = allocator_.GenerateId(); 549 SurfaceId child_one_surface_id = allocator_.GenerateId();
550 factory_.Create(child_one_surface_id, SurfaceSize()); 550 factory_.Create(child_one_surface_id, SurfaceSize());
551 551
552 scoped_ptr<RenderPass> child_one_pass = RenderPass::Create(); 552 scoped_ptr<RenderPass> child_one_pass = RenderPass::Create();
553 child_one_pass->SetNew( 553 child_one_pass->SetNew(
554 pass_id, output_rect, damage_rect, transform_to_root_target); 554 pass_id, output_rect, damage_rect, transform_to_root_target);
555 AddSolidColorQuadWithBlendMode( 555 AddSolidColorQuadWithBlendMode(
556 SurfaceSize(), child_one_pass.get(), blend_modes[1]); 556 SurfaceSize(), child_one_pass.get(), blend_modes[1]);
557 scoped_ptr<SurfaceDrawQuad> grandchild_surface_quad = 557 SurfaceDrawQuad* grandchild_surface_quad =
558 SurfaceDrawQuad::Create(); 558 child_one_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
559 grandchild_surface_quad->SetNew(child_one_pass->shared_quad_state_list.back(), 559 grandchild_surface_quad->SetNew(child_one_pass->shared_quad_state_list.back(),
560 gfx::Rect(SurfaceSize()), 560 gfx::Rect(SurfaceSize()),
561 gfx::Rect(SurfaceSize()), 561 gfx::Rect(SurfaceSize()),
562 grandchild_surface_id); 562 grandchild_surface_id);
563 child_one_pass->quad_list.push_back(
564 grandchild_surface_quad.PassAs<DrawQuad>());
565 AddSolidColorQuadWithBlendMode( 563 AddSolidColorQuadWithBlendMode(
566 SurfaceSize(), child_one_pass.get(), blend_modes[3]); 564 SurfaceSize(), child_one_pass.get(), blend_modes[3]);
567 QueuePassAsFrame(child_one_pass.Pass(), child_one_surface_id); 565 QueuePassAsFrame(child_one_pass.Pass(), child_one_surface_id);
568 566
569 SurfaceId child_two_surface_id = allocator_.GenerateId(); 567 SurfaceId child_two_surface_id = allocator_.GenerateId();
570 factory_.Create(child_two_surface_id, SurfaceSize()); 568 factory_.Create(child_two_surface_id, SurfaceSize());
571 569
572 scoped_ptr<RenderPass> child_two_pass = RenderPass::Create(); 570 scoped_ptr<RenderPass> child_two_pass = RenderPass::Create();
573 child_two_pass->SetNew( 571 child_two_pass->SetNew(
574 pass_id, output_rect, damage_rect, transform_to_root_target); 572 pass_id, output_rect, damage_rect, transform_to_root_target);
575 AddSolidColorQuadWithBlendMode( 573 AddSolidColorQuadWithBlendMode(
576 SurfaceSize(), child_two_pass.get(), blend_modes[5]); 574 SurfaceSize(), child_two_pass.get(), blend_modes[5]);
577 QueuePassAsFrame(child_two_pass.Pass(), child_two_surface_id); 575 QueuePassAsFrame(child_two_pass.Pass(), child_two_surface_id);
578 576
579 scoped_ptr<RenderPass> root_pass = RenderPass::Create(); 577 scoped_ptr<RenderPass> root_pass = RenderPass::Create();
580 root_pass->SetNew( 578 root_pass->SetNew(
581 pass_id, output_rect, damage_rect, transform_to_root_target); 579 pass_id, output_rect, damage_rect, transform_to_root_target);
582 580
583 AddSolidColorQuadWithBlendMode( 581 AddSolidColorQuadWithBlendMode(
584 SurfaceSize(), root_pass.get(), blend_modes[0]); 582 SurfaceSize(), root_pass.get(), blend_modes[0]);
585 scoped_ptr<SurfaceDrawQuad> child_one_surface_quad = 583 SurfaceDrawQuad* child_one_surface_quad =
586 SurfaceDrawQuad::Create(); 584 root_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
587 child_one_surface_quad->SetNew(root_pass->shared_quad_state_list.back(), 585 child_one_surface_quad->SetNew(root_pass->shared_quad_state_list.back(),
588 gfx::Rect(SurfaceSize()), 586 gfx::Rect(SurfaceSize()),
589 gfx::Rect(SurfaceSize()), 587 gfx::Rect(SurfaceSize()),
590 child_one_surface_id); 588 child_one_surface_id);
591 root_pass->quad_list.push_back(child_one_surface_quad.PassAs<DrawQuad>());
592 AddSolidColorQuadWithBlendMode( 589 AddSolidColorQuadWithBlendMode(
593 SurfaceSize(), root_pass.get(), blend_modes[4]); 590 SurfaceSize(), root_pass.get(), blend_modes[4]);
594 scoped_ptr<SurfaceDrawQuad> child_two_surface_quad = 591 SurfaceDrawQuad* child_two_surface_quad =
595 SurfaceDrawQuad::Create(); 592 root_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>();
596 child_two_surface_quad->SetNew(root_pass->shared_quad_state_list.back(), 593 child_two_surface_quad->SetNew(root_pass->shared_quad_state_list.back(),
597 gfx::Rect(SurfaceSize()), 594 gfx::Rect(SurfaceSize()),
598 gfx::Rect(SurfaceSize()), 595 gfx::Rect(SurfaceSize()),
599 child_two_surface_id); 596 child_two_surface_id);
600 root_pass->quad_list.push_back(child_two_surface_quad.PassAs<DrawQuad>());
601 AddSolidColorQuadWithBlendMode( 597 AddSolidColorQuadWithBlendMode(
602 SurfaceSize(), root_pass.get(), blend_modes[6]); 598 SurfaceSize(), root_pass.get(), blend_modes[6]);
603 599
604 QueuePassAsFrame(root_pass.Pass(), root_surface_id_); 600 QueuePassAsFrame(root_pass.Pass(), root_surface_id_);
605 601
606 scoped_ptr<CompositorFrame> aggregated_frame = 602 scoped_ptr<CompositorFrame> aggregated_frame =
607 aggregator_.Aggregate(root_surface_id_); 603 aggregator_.Aggregate(root_surface_id_);
608 604
609 ASSERT_TRUE(aggregated_frame); 605 ASSERT_TRUE(aggregated_frame);
610 ASSERT_TRUE(aggregated_frame->delegated_frame_data); 606 ASSERT_TRUE(aggregated_frame->delegated_frame_data);
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 SurfaceFactory* factory, 812 SurfaceFactory* factory,
817 SurfaceId surface_id) { 813 SurfaceId surface_id) {
818 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData); 814 scoped_ptr<DelegatedFrameData> frame_data(new DelegatedFrameData);
819 scoped_ptr<RenderPass> pass = RenderPass::Create(); 815 scoped_ptr<RenderPass> pass = RenderPass::Create();
820 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); 816 SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
821 for (size_t i = 0u; i < num_resource_ids; ++i) { 817 for (size_t i = 0u; i < num_resource_ids; ++i) {
822 TransferableResource resource; 818 TransferableResource resource;
823 resource.id = resource_ids[i]; 819 resource.id = resource_ids[i];
824 resource.is_software = true; 820 resource.is_software = true;
825 frame_data->resource_list.push_back(resource); 821 frame_data->resource_list.push_back(resource);
826 scoped_ptr<TextureDrawQuad> quad(TextureDrawQuad::Create()); 822 TextureDrawQuad* quad = pass->CreateAndAppendDrawQuad<TextureDrawQuad>();
827 const gfx::Rect rect; 823 const gfx::Rect rect;
828 const gfx::Rect opaque_rect; 824 const gfx::Rect opaque_rect;
829 const gfx::Rect visible_rect; 825 const gfx::Rect visible_rect;
830 bool needs_blending = false; 826 bool needs_blending = false;
831 bool premultiplied_alpha = false; 827 bool premultiplied_alpha = false;
832 const gfx::PointF uv_top_left; 828 const gfx::PointF uv_top_left;
833 const gfx::PointF uv_bottom_right; 829 const gfx::PointF uv_bottom_right;
834 SkColor background_color = SK_ColorGREEN; 830 SkColor background_color = SK_ColorGREEN;
835 const float vertex_opacity[4] = {0.f, 0.f, 1.f, 1.f}; 831 const float vertex_opacity[4] = {0.f, 0.f, 1.f, 1.f};
836 bool flipped = false; 832 bool flipped = false;
837 quad->SetAll(sqs, 833 quad->SetAll(sqs,
838 rect, 834 rect,
839 opaque_rect, 835 opaque_rect,
840 visible_rect, 836 visible_rect,
841 needs_blending, 837 needs_blending,
842 resource_ids[i], 838 resource_ids[i],
843 premultiplied_alpha, 839 premultiplied_alpha,
844 uv_top_left, 840 uv_top_left,
845 uv_bottom_right, 841 uv_bottom_right,
846 background_color, 842 background_color,
847 vertex_opacity, 843 vertex_opacity,
848 flipped); 844 flipped);
849 845
850 quad->shared_quad_state = sqs; 846 quad->shared_quad_state = sqs;
851 pass->quad_list.push_back(quad.PassAs<DrawQuad>());
852 } 847 }
853 frame_data->render_pass_list.push_back(pass.Pass()); 848 frame_data->render_pass_list.push_back(pass.Pass());
854 scoped_ptr<CompositorFrame> frame(new CompositorFrame); 849 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
855 frame->delegated_frame_data = frame_data.Pass(); 850 frame->delegated_frame_data = frame_data.Pass();
856 factory->SubmitFrame(surface_id, frame.Pass()); 851 factory->SubmitFrame(surface_id, frame.Pass());
857 } 852 }
858 853
859 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) { 854 TEST_F(SurfaceAggregatorWithResourcesTest, TakeResourcesOneSurface) {
860 ResourceTrackingSurfaceFactoryClient client; 855 ResourceTrackingSurfaceFactoryClient client;
861 SurfaceFactory factory(&manager_, &client); 856 SurfaceFactory factory(&manager_, &client);
(...skipping 15 matching lines...) Expand all
877 ASSERT_EQ(3u, client.returned_resources().size()); 872 ASSERT_EQ(3u, client.returned_resources().size());
878 for (size_t i = 0; i < 3; ++i) { 873 for (size_t i = 0; i < 3; ++i) {
879 EXPECT_EQ(ids[i], client.returned_resources()[i].id); 874 EXPECT_EQ(ids[i], client.returned_resources()[i].id);
880 } 875 }
881 factory.Destroy(surface_id); 876 factory.Destroy(surface_id);
882 } 877 }
883 878
884 } // namespace 879 } // namespace
885 } // namespace cc 880 } // namespace cc
886 881
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698