OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/output/compositor_frame.h" |
| 6 #include "cc/output/delegated_frame_data.h" |
| 7 #include "cc/quads/render_pass.h" |
| 8 #include "cc/quads/render_pass_id.h" |
| 9 #include "cc/quads/surface_draw_quad.h" |
| 10 #include "cc/surfaces/surface.h" |
| 11 #include "cc/surfaces/surface_factory.h" |
| 12 #include "cc/surfaces/surface_factory_client.h" |
| 13 #include "cc/surfaces/surface_hittest.h" |
| 14 #include "cc/surfaces/surface_id_allocator.h" |
| 15 #include "cc/surfaces/surface_manager.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 #include "ui/gfx/geometry/size.h" |
| 18 |
| 19 namespace cc { |
| 20 |
| 21 class EmptySurfaceFactoryClient : public SurfaceFactoryClient { |
| 22 public: |
| 23 void ReturnResources(const ReturnedResourceArray& resources) override {} |
| 24 }; |
| 25 |
| 26 TEST(SurfaceHittestTest, Hittest_SingleSurface) { |
| 27 SurfaceManager manager; |
| 28 EmptySurfaceFactoryClient client; |
| 29 SurfaceFactory factory(&manager, &client); |
| 30 SurfaceIdAllocator root_allocator(2); |
| 31 |
| 32 // Creates a root surface. |
| 33 SurfaceId root_surface_id = root_allocator.GenerateId(); |
| 34 factory.Create(root_surface_id); |
| 35 gfx::Rect rect(300, 300); |
| 36 RenderPassId id(1, 1); |
| 37 scoped_ptr<RenderPass> pass = RenderPass::Create(); |
| 38 pass->SetNew(id, rect, rect, gfx::Transform()); |
| 39 scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData); |
| 40 delegated_frame_data->render_pass_list.push_back(pass.Pass()); |
| 41 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame); |
| 42 root_frame->delegated_frame_data = delegated_frame_data.Pass(); |
| 43 factory.SubmitFrame(root_surface_id, root_frame.Pass(), |
| 44 SurfaceFactory::DrawCallback()); |
| 45 |
| 46 { |
| 47 SurfaceHittest hittest(&manager); |
| 48 EXPECT_EQ(root_surface_id, |
| 49 hittest.Hittest(root_surface_id, gfx::Point(100, 100))); |
| 50 } |
| 51 |
| 52 factory.Destroy(root_surface_id); |
| 53 } |
| 54 |
| 55 TEST(SurfaceHittestTest, Hittest_ChildSurface) { |
| 56 SurfaceManager manager; |
| 57 EmptySurfaceFactoryClient client; |
| 58 SurfaceFactory factory(&manager, &client); |
| 59 SurfaceIdAllocator root_allocator(2); |
| 60 SurfaceIdAllocator child_allocator(3); |
| 61 |
| 62 SurfaceId root_surface_id = root_allocator.GenerateId(); |
| 63 SurfaceId child_surface_id = child_allocator.GenerateId(); |
| 64 gfx::Size root_size(300, 300); |
| 65 gfx::Rect root_rect(root_size); |
| 66 gfx::Size child_size(200, 200); |
| 67 gfx::Rect child_rect(child_size); |
| 68 |
| 69 // Creates a root surface. |
| 70 factory.Create(root_surface_id); |
| 71 RenderPassId root_id(1, 1); |
| 72 scoped_ptr<RenderPass> root_pass = RenderPass::Create(); |
| 73 root_pass->SetNew(root_id, root_rect, root_rect, gfx::Transform()); |
| 74 |
| 75 // Add a reference to the child surface on the root surface. |
| 76 SharedQuadState* shared_state = root_pass->CreateAndAppendSharedQuadState(); |
| 77 shared_state->SetAll(gfx::Transform(1.0f, 0.0f, 0.0f, 50.0f, |
| 78 0.0f, 1.0f, 0.0f, 50.0f, |
| 79 0.0f, 0.0f, 1.0f, 0.0f, |
| 80 0.0f, 0.0f, 0.0f, 1.0f), |
| 81 root_size, root_rect, root_rect, false, 1.0f, |
| 82 SkXfermode::kSrcOver_Mode, 0); |
| 83 SurfaceDrawQuad* surface_quad = |
| 84 root_pass->CreateAndAppendDrawQuad<SurfaceDrawQuad>(); |
| 85 surface_quad->SetNew(root_pass->shared_quad_state_list.back(), child_rect, |
| 86 child_rect, child_surface_id); |
| 87 |
| 88 // Submit the root frame. |
| 89 scoped_ptr<DelegatedFrameData> root_delegated_frame_data( |
| 90 new DelegatedFrameData); |
| 91 root_delegated_frame_data->render_pass_list.push_back(root_pass.Pass()); |
| 92 scoped_ptr<CompositorFrame> root_frame(new CompositorFrame); |
| 93 root_frame->delegated_frame_data = root_delegated_frame_data.Pass(); |
| 94 factory.SubmitFrame(root_surface_id, root_frame.Pass(), |
| 95 SurfaceFactory::DrawCallback()); |
| 96 |
| 97 // Creates a child surface. |
| 98 factory.Create(child_surface_id); |
| 99 RenderPassId child_id(1, 1); |
| 100 scoped_ptr<RenderPass> child_pass = RenderPass::Create(); |
| 101 child_pass->SetNew(child_id, child_rect, child_rect, gfx::Transform()); |
| 102 |
| 103 // Submit the frame. |
| 104 scoped_ptr<DelegatedFrameData> child_delegated_frame_data( |
| 105 new DelegatedFrameData); |
| 106 child_delegated_frame_data->render_pass_list.push_back(child_pass.Pass()); |
| 107 scoped_ptr<CompositorFrame> child_frame(new CompositorFrame); |
| 108 child_frame->delegated_frame_data = child_delegated_frame_data.Pass(); |
| 109 factory.SubmitFrame(child_surface_id, child_frame.Pass(), |
| 110 SurfaceFactory::DrawCallback()); |
| 111 |
| 112 { |
| 113 SurfaceHittest hittest(&manager); |
| 114 EXPECT_EQ(root_surface_id, |
| 115 hittest.Hittest(root_surface_id, gfx::Point(10, 10))); |
| 116 EXPECT_EQ(root_surface_id, |
| 117 hittest.Hittest(root_surface_id, gfx::Point(49, 49))); |
| 118 EXPECT_EQ(child_surface_id, |
| 119 hittest.Hittest(child_surface_id, gfx::Point(50, 50))); |
| 120 EXPECT_EQ(child_surface_id, |
| 121 hittest.Hittest(child_surface_id, gfx::Point(100, 100))); |
| 122 EXPECT_EQ(child_surface_id, |
| 123 hittest.Hittest(child_surface_id, gfx::Point(250, 250))); |
| 124 EXPECT_EQ(root_surface_id, |
| 125 hittest.Hittest(root_surface_id, gfx::Point(251, 251))); |
| 126 EXPECT_EQ(root_surface_id, |
| 127 hittest.Hittest(root_surface_id, gfx::Point(290, 290))); |
| 128 } |
| 129 |
| 130 factory.Destroy(root_surface_id); |
| 131 factory.Destroy(child_surface_id); |
| 132 } |
| 133 |
| 134 } // namespace cc |
OLD | NEW |