OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/location.h" | 9 #include "base/location.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 using testing::AtLeast; | 44 using testing::AtLeast; |
45 using testing::ElementsAre; | 45 using testing::ElementsAre; |
46 using testing::Expectation; | 46 using testing::Expectation; |
47 using testing::InSequence; | 47 using testing::InSequence; |
48 using testing::Mock; | 48 using testing::Mock; |
49 using testing::Return; | 49 using testing::Return; |
50 using testing::StrictMock; | 50 using testing::StrictMock; |
51 | 51 |
52 namespace cc { | 52 namespace cc { |
53 | 53 |
| 54 MATCHER_P(MatchesSyncToken, sync_token, "") { |
| 55 gpu::SyncToken other; |
| 56 memcpy(&other, arg, sizeof(other)); |
| 57 return other == sync_token; |
| 58 } |
| 59 |
54 class GLRendererTest : public testing::Test { | 60 class GLRendererTest : public testing::Test { |
55 protected: | 61 protected: |
56 RenderPass* root_render_pass() { return render_passes_in_draw_order_.back(); } | 62 RenderPass* root_render_pass() { return render_passes_in_draw_order_.back(); } |
57 | 63 |
58 RenderPassList render_passes_in_draw_order_; | 64 RenderPassList render_passes_in_draw_order_; |
59 }; | 65 }; |
60 | 66 |
61 #define EXPECT_PROGRAM_VALID(program_binding) \ | 67 #define EXPECT_PROGRAM_VALID(program_binding) \ |
62 do { \ | 68 do { \ |
63 EXPECT_TRUE((program_binding)->program()); \ | 69 EXPECT_TRUE((program_binding)->program()); \ |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
922 renderer.SetVisible(false); | 928 renderer.SetVisible(false); |
923 EXPECT_TRUE(context->last_call_was_set_visibility()); | 929 EXPECT_TRUE(context->last_call_was_set_visibility()); |
924 } | 930 } |
925 | 931 |
926 class TextureStateTrackingContext : public TestWebGraphicsContext3D { | 932 class TextureStateTrackingContext : public TestWebGraphicsContext3D { |
927 public: | 933 public: |
928 TextureStateTrackingContext() : active_texture_(GL_INVALID_ENUM) { | 934 TextureStateTrackingContext() : active_texture_(GL_INVALID_ENUM) { |
929 test_capabilities_.gpu.egl_image_external = true; | 935 test_capabilities_.gpu.egl_image_external = true; |
930 } | 936 } |
931 | 937 |
932 MOCK_METHOD1(waitSyncPoint, void(unsigned sync_point)); | 938 MOCK_METHOD1(waitSyncToken, void(const GLbyte* sync_token)); |
933 MOCK_METHOD3(texParameteri, void(GLenum target, GLenum pname, GLint param)); | 939 MOCK_METHOD3(texParameteri, void(GLenum target, GLenum pname, GLint param)); |
934 MOCK_METHOD4(drawElements, | 940 MOCK_METHOD4(drawElements, |
935 void(GLenum mode, GLsizei count, GLenum type, GLintptr offset)); | 941 void(GLenum mode, GLsizei count, GLenum type, GLintptr offset)); |
936 | 942 |
937 virtual void activeTexture(GLenum texture) { | 943 virtual void activeTexture(GLenum texture) { |
938 EXPECT_NE(texture, active_texture_); | 944 EXPECT_NE(texture, active_texture_); |
939 active_texture_ = texture; | 945 active_texture_ = texture; |
940 } | 946 } |
941 | 947 |
942 GLenum active_texture() const { return active_texture_; } | 948 GLenum active_texture() const { return active_texture_; } |
(...skipping 23 matching lines...) Expand all Loading... |
966 &settings, | 972 &settings, |
967 output_surface.get(), | 973 output_surface.get(), |
968 resource_provider.get()); | 974 resource_provider.get()); |
969 | 975 |
970 // During initialization we are allowed to set any texture parameters. | 976 // During initialization we are allowed to set any texture parameters. |
971 EXPECT_CALL(*context, texParameteri(_, _, _)).Times(AnyNumber()); | 977 EXPECT_CALL(*context, texParameteri(_, _, _)).Times(AnyNumber()); |
972 | 978 |
973 RenderPass* root_pass = | 979 RenderPass* root_pass = |
974 AddRenderPass(&render_passes_in_draw_order_, RenderPassId(1, 1), | 980 AddRenderPass(&render_passes_in_draw_order_, RenderPassId(1, 1), |
975 gfx::Rect(100, 100), gfx::Transform()); | 981 gfx::Rect(100, 100), gfx::Transform()); |
976 uint32_t mailbox_sync_point; | 982 unsigned mailbox_sync_point; |
977 AddOneOfEveryQuadType(root_pass, resource_provider.get(), RenderPassId(0, 0), | 983 AddOneOfEveryQuadType(root_pass, resource_provider.get(), RenderPassId(0, 0), |
978 &mailbox_sync_point); | 984 &mailbox_sync_point); |
979 | 985 |
980 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); | 986 renderer.DecideRenderPassAllocationsForFrame(render_passes_in_draw_order_); |
981 | 987 |
982 // Set up expected texture filter state transitions that match the quads | 988 // Set up expected texture filter state transitions that match the quads |
983 // created in AppendOneOfEveryQuadType(). | 989 // created in AppendOneOfEveryQuadType(). |
984 Mock::VerifyAndClearExpectations(context); | 990 Mock::VerifyAndClearExpectations(context); |
985 { | 991 { |
986 InSequence sequence; | 992 InSequence sequence; |
987 | 993 |
988 // The sync points for all quads are waited on first. This sync point is | 994 // The sync points for all quads are waited on first. This sync point is |
989 // for a texture quad drawn later in the frame. | 995 // for a texture quad drawn later in the frame. |
990 EXPECT_CALL(*context, waitSyncPoint(mailbox_sync_point)).Times(1); | 996 gpu::SyncToken mailbox_sync_token(mailbox_sync_point); |
| 997 EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(mailbox_sync_token))) |
| 998 .Times(1); |
991 | 999 |
992 // yuv_quad is drawn with the default linear filter. | 1000 // yuv_quad is drawn with the default linear filter. |
993 EXPECT_CALL(*context, drawElements(_, _, _, _)); | 1001 EXPECT_CALL(*context, drawElements(_, _, _, _)); |
994 | 1002 |
995 // tile_quad is drawn with GL_NEAREST because it is not transformed or | 1003 // tile_quad is drawn with GL_NEAREST because it is not transformed or |
996 // scaled. | 1004 // scaled. |
997 EXPECT_CALL( | 1005 EXPECT_CALL( |
998 *context, | 1006 *context, |
999 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); | 1007 texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)); |
1000 EXPECT_CALL( | 1008 EXPECT_CALL( |
(...skipping 1015 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2016 : OverlayProcessor(surface) {} | 2024 : OverlayProcessor(surface) {} |
2017 ~TestOverlayProcessor() override {} | 2025 ~TestOverlayProcessor() override {} |
2018 void Initialize() override { | 2026 void Initialize() override { |
2019 strategy_ = new Strategy(); | 2027 strategy_ = new Strategy(); |
2020 strategies_.push_back(make_scoped_ptr(strategy_)); | 2028 strategies_.push_back(make_scoped_ptr(strategy_)); |
2021 } | 2029 } |
2022 | 2030 |
2023 Strategy* strategy_; | 2031 Strategy* strategy_; |
2024 }; | 2032 }; |
2025 | 2033 |
2026 void MailboxReleased(unsigned sync_point, | 2034 void MailboxReleased(const gpu::SyncToken& sync_token, |
2027 bool lost_resource, | 2035 bool lost_resource, |
2028 BlockingTaskRunner* main_thread_task_runner) { | 2036 BlockingTaskRunner* main_thread_task_runner) {} |
2029 } | |
2030 | 2037 |
2031 void IgnoreCopyResult(scoped_ptr<CopyOutputResult> result) { | 2038 void IgnoreCopyResult(scoped_ptr<CopyOutputResult> result) { |
2032 } | 2039 } |
2033 | 2040 |
2034 TEST_F(GLRendererTest, DontOverlayWithCopyRequests) { | 2041 TEST_F(GLRendererTest, DontOverlayWithCopyRequests) { |
2035 scoped_ptr<DiscardCheckingContext> context_owned(new DiscardCheckingContext); | 2042 scoped_ptr<DiscardCheckingContext> context_owned(new DiscardCheckingContext); |
2036 FakeOutputSurfaceClient output_surface_client; | 2043 FakeOutputSurfaceClient output_surface_client; |
2037 scoped_ptr<OutputSurface> output_surface( | 2044 scoped_ptr<OutputSurface> output_surface( |
2038 FakeOutputSurface::Create3d(context_owned.Pass())); | 2045 FakeOutputSurface::Create3d(context_owned.Pass())); |
2039 CHECK(output_surface->BindToClient(&output_surface_client)); | 2046 CHECK(output_surface->BindToClient(&output_surface_client)); |
(...skipping 16 matching lines...) Expand all Loading... |
2056 renderer.SetOverlayProcessor(processor); | 2063 renderer.SetOverlayProcessor(processor); |
2057 | 2064 |
2058 gfx::Rect viewport_rect(1, 1); | 2065 gfx::Rect viewport_rect(1, 1); |
2059 RenderPass* root_pass = | 2066 RenderPass* root_pass = |
2060 AddRenderPass(&render_passes_in_draw_order_, RenderPassId(1, 0), | 2067 AddRenderPass(&render_passes_in_draw_order_, RenderPassId(1, 0), |
2061 viewport_rect, gfx::Transform()); | 2068 viewport_rect, gfx::Transform()); |
2062 root_pass->has_transparent_background = false; | 2069 root_pass->has_transparent_background = false; |
2063 root_pass->copy_requests.push_back( | 2070 root_pass->copy_requests.push_back( |
2064 CopyOutputRequest::CreateRequest(base::Bind(&IgnoreCopyResult))); | 2071 CopyOutputRequest::CreateRequest(base::Bind(&IgnoreCopyResult))); |
2065 | 2072 |
2066 unsigned sync_point = 0; | |
2067 TextureMailbox mailbox = | 2073 TextureMailbox mailbox = |
2068 TextureMailbox(gpu::Mailbox::Generate(), GL_TEXTURE_2D, sync_point, | 2074 TextureMailbox(gpu::Mailbox::Generate(), gpu::SyncToken(), GL_TEXTURE_2D, |
2069 gfx::Size(256, 256), true); | 2075 gfx::Size(256, 256), true); |
2070 scoped_ptr<SingleReleaseCallbackImpl> release_callback = | 2076 scoped_ptr<SingleReleaseCallbackImpl> release_callback = |
2071 SingleReleaseCallbackImpl::Create(base::Bind(&MailboxReleased)); | 2077 SingleReleaseCallbackImpl::Create(base::Bind(&MailboxReleased)); |
2072 ResourceId resource_id = resource_provider->CreateResourceFromTextureMailbox( | 2078 ResourceId resource_id = resource_provider->CreateResourceFromTextureMailbox( |
2073 mailbox, release_callback.Pass()); | 2079 mailbox, release_callback.Pass()); |
2074 bool premultiplied_alpha = false; | 2080 bool premultiplied_alpha = false; |
2075 bool flipped = false; | 2081 bool flipped = false; |
2076 bool nearest_neighbor = false; | 2082 bool nearest_neighbor = false; |
2077 float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f}; | 2083 float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f}; |
2078 | 2084 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2132 : OverlayProcessor(surface) {} | 2138 : OverlayProcessor(surface) {} |
2133 | 2139 |
2134 void Initialize() override { | 2140 void Initialize() override { |
2135 strategies_.push_back( | 2141 strategies_.push_back( |
2136 make_scoped_ptr(new OverlayStrategySingleOnTop(&validator_))); | 2142 make_scoped_ptr(new OverlayStrategySingleOnTop(&validator_))); |
2137 } | 2143 } |
2138 | 2144 |
2139 SingleOverlayValidator validator_; | 2145 SingleOverlayValidator validator_; |
2140 }; | 2146 }; |
2141 | 2147 |
2142 class WaitSyncPointCountingContext : public TestWebGraphicsContext3D { | 2148 class WaitSyncTokenCountingContext : public TestWebGraphicsContext3D { |
2143 public: | 2149 public: |
2144 MOCK_METHOD1(waitSyncPoint, void(unsigned sync_point)); | 2150 MOCK_METHOD1(waitSyncToken, void(const GLbyte* sync_token)); |
2145 }; | 2151 }; |
2146 | 2152 |
2147 class MockOverlayScheduler { | 2153 class MockOverlayScheduler { |
2148 public: | 2154 public: |
2149 MOCK_METHOD5(Schedule, | 2155 MOCK_METHOD5(Schedule, |
2150 void(int plane_z_order, | 2156 void(int plane_z_order, |
2151 gfx::OverlayTransform plane_transform, | 2157 gfx::OverlayTransform plane_transform, |
2152 unsigned overlay_texture_id, | 2158 unsigned overlay_texture_id, |
2153 const gfx::Rect& display_bounds, | 2159 const gfx::Rect& display_bounds, |
2154 const gfx::RectF& uv_rect)); | 2160 const gfx::RectF& uv_rect)); |
2155 }; | 2161 }; |
2156 | 2162 |
2157 TEST_F(GLRendererTest, OverlaySyncPointsAreProcessed) { | 2163 TEST_F(GLRendererTest, OverlaySyncTokensAreProcessed) { |
2158 scoped_ptr<WaitSyncPointCountingContext> context_owned( | 2164 scoped_ptr<WaitSyncTokenCountingContext> context_owned( |
2159 new WaitSyncPointCountingContext); | 2165 new WaitSyncTokenCountingContext); |
2160 WaitSyncPointCountingContext* context = context_owned.get(); | 2166 WaitSyncTokenCountingContext* context = context_owned.get(); |
2161 | 2167 |
2162 MockOverlayScheduler overlay_scheduler; | 2168 MockOverlayScheduler overlay_scheduler; |
2163 scoped_refptr<TestContextProvider> context_provider = | 2169 scoped_refptr<TestContextProvider> context_provider = |
2164 TestContextProvider::Create(context_owned.Pass()); | 2170 TestContextProvider::Create(context_owned.Pass()); |
2165 context_provider->support()->SetScheduleOverlayPlaneCallback(base::Bind( | 2171 context_provider->support()->SetScheduleOverlayPlaneCallback(base::Bind( |
2166 &MockOverlayScheduler::Schedule, base::Unretained(&overlay_scheduler))); | 2172 &MockOverlayScheduler::Schedule, base::Unretained(&overlay_scheduler))); |
2167 | 2173 |
2168 FakeOutputSurfaceClient output_surface_client; | 2174 FakeOutputSurfaceClient output_surface_client; |
2169 scoped_ptr<OutputSurface> output_surface( | 2175 scoped_ptr<OutputSurface> output_surface( |
2170 FakeOutputSurface::Create3d(context_provider)); | 2176 FakeOutputSurface::Create3d(context_provider)); |
(...skipping 15 matching lines...) Expand all Loading... |
2186 new SingleOverlayOnTopProcessor(output_surface.get()); | 2192 new SingleOverlayOnTopProcessor(output_surface.get()); |
2187 processor->Initialize(); | 2193 processor->Initialize(); |
2188 renderer.SetOverlayProcessor(processor); | 2194 renderer.SetOverlayProcessor(processor); |
2189 | 2195 |
2190 gfx::Rect viewport_rect(1, 1); | 2196 gfx::Rect viewport_rect(1, 1); |
2191 RenderPass* root_pass = | 2197 RenderPass* root_pass = |
2192 AddRenderPass(&render_passes_in_draw_order_, RenderPassId(1, 0), | 2198 AddRenderPass(&render_passes_in_draw_order_, RenderPassId(1, 0), |
2193 viewport_rect, gfx::Transform()); | 2199 viewport_rect, gfx::Transform()); |
2194 root_pass->has_transparent_background = false; | 2200 root_pass->has_transparent_background = false; |
2195 | 2201 |
2196 unsigned sync_point = 29; | 2202 gpu::SyncToken sync_token(29); |
2197 TextureMailbox mailbox = | 2203 TextureMailbox mailbox = |
2198 TextureMailbox(gpu::Mailbox::Generate(), GL_TEXTURE_2D, sync_point, | 2204 TextureMailbox(gpu::Mailbox::Generate(), sync_token, GL_TEXTURE_2D, |
2199 gfx::Size(256, 256), true); | 2205 gfx::Size(256, 256), true); |
2200 scoped_ptr<SingleReleaseCallbackImpl> release_callback = | 2206 scoped_ptr<SingleReleaseCallbackImpl> release_callback = |
2201 SingleReleaseCallbackImpl::Create(base::Bind(&MailboxReleased)); | 2207 SingleReleaseCallbackImpl::Create(base::Bind(&MailboxReleased)); |
2202 ResourceId resource_id = resource_provider->CreateResourceFromTextureMailbox( | 2208 ResourceId resource_id = resource_provider->CreateResourceFromTextureMailbox( |
2203 mailbox, release_callback.Pass()); | 2209 mailbox, release_callback.Pass()); |
2204 bool premultiplied_alpha = false; | 2210 bool premultiplied_alpha = false; |
2205 bool flipped = false; | 2211 bool flipped = false; |
2206 bool nearest_neighbor = false; | 2212 bool nearest_neighbor = false; |
2207 float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f}; | 2213 float vertex_opacity[4] = {1.0f, 1.0f, 1.0f, 1.0f}; |
2208 gfx::PointF uv_top_left(0, 0); | 2214 gfx::PointF uv_top_left(0, 0); |
2209 gfx::PointF uv_bottom_right(1, 1); | 2215 gfx::PointF uv_bottom_right(1, 1); |
2210 | 2216 |
2211 TextureDrawQuad* overlay_quad = | 2217 TextureDrawQuad* overlay_quad = |
2212 root_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); | 2218 root_pass->CreateAndAppendDrawQuad<TextureDrawQuad>(); |
2213 SharedQuadState* shared_state = root_pass->CreateAndAppendSharedQuadState(); | 2219 SharedQuadState* shared_state = root_pass->CreateAndAppendSharedQuadState(); |
2214 shared_state->SetAll(gfx::Transform(), viewport_rect.size(), viewport_rect, | 2220 shared_state->SetAll(gfx::Transform(), viewport_rect.size(), viewport_rect, |
2215 viewport_rect, false, 1, SkXfermode::kSrcOver_Mode, 0); | 2221 viewport_rect, false, 1, SkXfermode::kSrcOver_Mode, 0); |
2216 overlay_quad->SetNew(shared_state, viewport_rect, viewport_rect, | 2222 overlay_quad->SetNew(shared_state, viewport_rect, viewport_rect, |
2217 viewport_rect, resource_id, premultiplied_alpha, | 2223 viewport_rect, resource_id, premultiplied_alpha, |
2218 uv_top_left, uv_bottom_right, SK_ColorTRANSPARENT, | 2224 uv_top_left, uv_bottom_right, SK_ColorTRANSPARENT, |
2219 vertex_opacity, flipped, nearest_neighbor); | 2225 vertex_opacity, flipped, nearest_neighbor); |
2220 | 2226 |
2221 // Verify that overlay_quad actually gets turned into an overlay, and even | 2227 // Verify that overlay_quad actually gets turned into an overlay, and even |
2222 // though it's not drawn, that its sync point is waited on. | 2228 // though it's not drawn, that its sync point is waited on. |
2223 EXPECT_CALL(*context, waitSyncPoint(sync_point)).Times(1); | 2229 EXPECT_CALL(*context, waitSyncToken(MatchesSyncToken(sync_token))).Times(1); |
2224 EXPECT_CALL(overlay_scheduler, | 2230 EXPECT_CALL(overlay_scheduler, |
2225 Schedule(1, gfx::OVERLAY_TRANSFORM_NONE, _, viewport_rect, | 2231 Schedule(1, gfx::OVERLAY_TRANSFORM_NONE, _, viewport_rect, |
2226 BoundingRect(uv_top_left, uv_bottom_right))).Times(1); | 2232 BoundingRect(uv_top_left, uv_bottom_right))).Times(1); |
2227 | 2233 |
2228 renderer.DrawFrame(&render_passes_in_draw_order_, 1.f, viewport_rect, | 2234 renderer.DrawFrame(&render_passes_in_draw_order_, 1.f, viewport_rect, |
2229 viewport_rect, false); | 2235 viewport_rect, false); |
2230 } | 2236 } |
2231 | 2237 |
2232 } // namespace | 2238 } // namespace |
2233 } // namespace cc | 2239 } // namespace cc |
OLD | NEW |