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 "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
10 #include "cc/output/compositor_frame_metadata.h" | 10 #include "cc/output/compositor_frame_metadata.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 return SkXfermode::kColor_Mode; | 90 return SkXfermode::kColor_Mode; |
91 case BLEND_MODE_LUMINOSITY: | 91 case BLEND_MODE_LUMINOSITY: |
92 return SkXfermode::kLuminosity_Mode; | 92 return SkXfermode::kLuminosity_Mode; |
93 } | 93 } |
94 return SkXfermode::kSrcOver_Mode; | 94 return SkXfermode::kSrcOver_Mode; |
95 } | 95 } |
96 | 96 |
97 // Explicitly named to be a friend in GLRenderer for shader access. | 97 // Explicitly named to be a friend in GLRenderer for shader access. |
98 class GLRendererShaderPixelTest : public GLRendererPixelTest { | 98 class GLRendererShaderPixelTest : public GLRendererPixelTest { |
99 public: | 99 public: |
100 void TestShaders() { | 100 void SetUp() override { |
| 101 GLRendererPixelTest::SetUp(); |
101 ASSERT_FALSE(renderer()->IsContextLost()); | 102 ASSERT_FALSE(renderer()->IsContextLost()); |
| 103 } |
| 104 |
| 105 void TearDown() override { |
| 106 GLRendererPixelTest::TearDown(); |
| 107 ASSERT_FALSE(renderer()->IsContextLost()); |
| 108 } |
| 109 |
| 110 void TestBasicShaders() { |
102 EXPECT_PROGRAM_VALID(renderer()->GetTileCheckerboardProgram()); | 111 EXPECT_PROGRAM_VALID(renderer()->GetTileCheckerboardProgram()); |
103 EXPECT_PROGRAM_VALID(renderer()->GetDebugBorderProgram()); | 112 EXPECT_PROGRAM_VALID(renderer()->GetDebugBorderProgram()); |
104 EXPECT_PROGRAM_VALID(renderer()->GetSolidColorProgram()); | 113 EXPECT_PROGRAM_VALID(renderer()->GetSolidColorProgram()); |
105 EXPECT_PROGRAM_VALID(renderer()->GetSolidColorProgramAA()); | 114 EXPECT_PROGRAM_VALID(renderer()->GetSolidColorProgramAA()); |
106 TestShadersWithTexCoordPrecision(TEX_COORD_PRECISION_MEDIUM); | |
107 TestShadersWithTexCoordPrecision(TEX_COORD_PRECISION_HIGH); | |
108 ASSERT_FALSE(renderer()->IsContextLost()); | |
109 } | 115 } |
110 | 116 |
111 void TestShadersWithTexCoordPrecision(TexCoordPrecision precision) { | 117 void TestShadersWithPrecision(TexCoordPrecision precision) { |
112 for (int i = 0; i <= LAST_BLEND_MODE; ++i) { | |
113 BlendMode blend_mode = static_cast<BlendMode>(i); | |
114 EXPECT_PROGRAM_VALID( | |
115 renderer()->GetRenderPassProgram(precision, blend_mode)); | |
116 EXPECT_PROGRAM_VALID( | |
117 renderer()->GetRenderPassProgramAA(precision, blend_mode)); | |
118 } | |
119 EXPECT_PROGRAM_VALID(renderer()->GetTextureProgram(precision)); | 118 EXPECT_PROGRAM_VALID(renderer()->GetTextureProgram(precision)); |
120 EXPECT_PROGRAM_VALID( | 119 EXPECT_PROGRAM_VALID( |
121 renderer()->GetNonPremultipliedTextureProgram(precision)); | 120 renderer()->GetNonPremultipliedTextureProgram(precision)); |
122 EXPECT_PROGRAM_VALID(renderer()->GetTextureBackgroundProgram(precision)); | 121 EXPECT_PROGRAM_VALID(renderer()->GetTextureBackgroundProgram(precision)); |
123 EXPECT_PROGRAM_VALID( | 122 EXPECT_PROGRAM_VALID( |
124 renderer()->GetNonPremultipliedTextureBackgroundProgram(precision)); | 123 renderer()->GetNonPremultipliedTextureBackgroundProgram(precision)); |
125 EXPECT_PROGRAM_VALID(renderer()->GetTextureIOSurfaceProgram(precision)); | 124 EXPECT_PROGRAM_VALID(renderer()->GetTextureIOSurfaceProgram(precision)); |
126 EXPECT_PROGRAM_VALID(renderer()->GetVideoYUVProgram(precision)); | 125 EXPECT_PROGRAM_VALID(renderer()->GetVideoYUVProgram(precision)); |
127 EXPECT_PROGRAM_VALID(renderer()->GetVideoYUVAProgram(precision)); | 126 EXPECT_PROGRAM_VALID(renderer()->GetVideoYUVAProgram(precision)); |
128 // This is unlikely to be ever true in tests due to usage of osmesa. | |
129 if (renderer()->Capabilities().using_egl_image) | 127 if (renderer()->Capabilities().using_egl_image) |
130 EXPECT_PROGRAM_VALID(renderer()->GetVideoStreamTextureProgram(precision)); | 128 EXPECT_PROGRAM_VALID(renderer()->GetVideoStreamTextureProgram(precision)); |
131 else | 129 else |
132 EXPECT_FALSE(renderer()->GetVideoStreamTextureProgram(precision)); | 130 EXPECT_FALSE(renderer()->GetVideoStreamTextureProgram(precision)); |
133 TestShadersWithSamplerType(precision, SAMPLER_TYPE_2D); | |
134 TestShadersWithSamplerType(precision, SAMPLER_TYPE_2D_RECT); | |
135 // This is unlikely to be ever true in tests due to usage of osmesa. | |
136 if (renderer()->Capabilities().using_egl_image) | |
137 TestShadersWithSamplerType(precision, SAMPLER_TYPE_EXTERNAL_OES); | |
138 } | 131 } |
139 | 132 |
140 void TestShadersWithSamplerType(TexCoordPrecision precision, | 133 void TestShadersWithPrecisionAndBlend(TexCoordPrecision precision, |
141 SamplerType sampler) { | 134 BlendMode blend_mode) { |
| 135 EXPECT_PROGRAM_VALID( |
| 136 renderer()->GetRenderPassProgram(precision, blend_mode)); |
| 137 EXPECT_PROGRAM_VALID( |
| 138 renderer()->GetRenderPassProgramAA(precision, blend_mode)); |
| 139 } |
| 140 |
| 141 void TestShadersWithPrecisionAndSampler(TexCoordPrecision precision, |
| 142 SamplerType sampler) { |
| 143 if (!renderer()->Capabilities().using_egl_image && |
| 144 sampler == SAMPLER_TYPE_EXTERNAL_OES) { |
| 145 // This will likely be hit in tests due to usage of osmesa. |
| 146 return; |
| 147 } |
| 148 |
142 EXPECT_PROGRAM_VALID(renderer()->GetTileProgram(precision, sampler)); | 149 EXPECT_PROGRAM_VALID(renderer()->GetTileProgram(precision, sampler)); |
143 EXPECT_PROGRAM_VALID(renderer()->GetTileProgramOpaque(precision, sampler)); | 150 EXPECT_PROGRAM_VALID(renderer()->GetTileProgramOpaque(precision, sampler)); |
144 EXPECT_PROGRAM_VALID(renderer()->GetTileProgramAA(precision, sampler)); | 151 EXPECT_PROGRAM_VALID(renderer()->GetTileProgramAA(precision, sampler)); |
145 EXPECT_PROGRAM_VALID(renderer()->GetTileProgramSwizzle(precision, sampler)); | 152 EXPECT_PROGRAM_VALID(renderer()->GetTileProgramSwizzle(precision, sampler)); |
146 EXPECT_PROGRAM_VALID( | 153 EXPECT_PROGRAM_VALID( |
147 renderer()->GetTileProgramSwizzleOpaque(precision, sampler)); | 154 renderer()->GetTileProgramSwizzleOpaque(precision, sampler)); |
148 EXPECT_PROGRAM_VALID( | 155 EXPECT_PROGRAM_VALID( |
149 renderer()->GetTileProgramSwizzleAA(precision, sampler)); | 156 renderer()->GetTileProgramSwizzleAA(precision, sampler)); |
150 for (int i = 0; i <= LAST_BLEND_MODE; ++i) { | 157 } |
151 BlendMode blend_mode = static_cast<BlendMode>(i); | 158 |
152 for (int l = 0; l <= 1; ++l) { | 159 void TestShadersWithMasks(TexCoordPrecision precision, |
153 bool mask_for_background = (l == 1); | 160 SamplerType sampler, |
154 EXPECT_PROGRAM_VALID( | 161 BlendMode blend_mode, |
155 renderer()->GetRenderPassMaskProgram(precision, | 162 bool mask_for_background) { |
156 sampler, | 163 if (!renderer()->Capabilities().using_egl_image && |
157 blend_mode, | 164 sampler == SAMPLER_TYPE_EXTERNAL_OES) { |
158 mask_for_background)); | 165 // This will likely be hit in tests due to usage of osmesa. |
159 EXPECT_PROGRAM_VALID(renderer()->GetRenderPassMaskProgramAA( | 166 return; |
160 precision, sampler, blend_mode, mask_for_background)); | |
161 EXPECT_PROGRAM_VALID(renderer()->GetRenderPassMaskColorMatrixProgramAA( | |
162 precision, sampler, blend_mode, mask_for_background)); | |
163 EXPECT_PROGRAM_VALID(renderer()->GetRenderPassMaskColorMatrixProgram( | |
164 precision, sampler, blend_mode, mask_for_background)); | |
165 } | |
166 } | 167 } |
| 168 |
| 169 EXPECT_PROGRAM_VALID(renderer()->GetRenderPassMaskProgram( |
| 170 precision, sampler, blend_mode, mask_for_background)); |
| 171 EXPECT_PROGRAM_VALID(renderer()->GetRenderPassMaskProgramAA( |
| 172 precision, sampler, blend_mode, mask_for_background)); |
| 173 EXPECT_PROGRAM_VALID(renderer()->GetRenderPassMaskColorMatrixProgramAA( |
| 174 precision, sampler, blend_mode, mask_for_background)); |
| 175 EXPECT_PROGRAM_VALID(renderer()->GetRenderPassMaskColorMatrixProgram( |
| 176 precision, sampler, blend_mode, mask_for_background)); |
167 } | 177 } |
168 }; | 178 }; |
169 | 179 |
170 namespace { | 180 namespace { |
171 | 181 |
172 #if !defined(OS_ANDROID) && !defined(OS_WIN) | 182 #if !defined(OS_ANDROID) && !defined(OS_WIN) |
173 TEST_F(GLRendererShaderPixelTest, AllShadersCompile) { TestShaders(); } | 183 static const TexCoordPrecision kPrecisionList[] = {TEX_COORD_PRECISION_MEDIUM, |
| 184 TEX_COORD_PRECISION_HIGH}; |
| 185 |
| 186 static const BlendMode kBlendModeList[LAST_BLEND_MODE + 1] = { |
| 187 BLEND_MODE_NONE, |
| 188 BLEND_MODE_NORMAL, |
| 189 BLEND_MODE_SCREEN, |
| 190 BLEND_MODE_OVERLAY, |
| 191 BLEND_MODE_DARKEN, |
| 192 BLEND_MODE_LIGHTEN, |
| 193 BLEND_MODE_COLOR_DODGE, |
| 194 BLEND_MODE_COLOR_BURN, |
| 195 BLEND_MODE_HARD_LIGHT, |
| 196 BLEND_MODE_SOFT_LIGHT, |
| 197 BLEND_MODE_DIFFERENCE, |
| 198 BLEND_MODE_EXCLUSION, |
| 199 BLEND_MODE_MULTIPLY, |
| 200 BLEND_MODE_HUE, |
| 201 BLEND_MODE_SATURATION, |
| 202 BLEND_MODE_COLOR, |
| 203 BLEND_MODE_LUMINOSITY, |
| 204 }; |
| 205 |
| 206 static const SamplerType kSamplerList[] = { |
| 207 SAMPLER_TYPE_2D, |
| 208 SAMPLER_TYPE_2D_RECT, |
| 209 SAMPLER_TYPE_EXTERNAL_OES, |
| 210 }; |
| 211 |
| 212 TEST_F(GLRendererShaderPixelTest, BasicShadersCompile) { |
| 213 TestBasicShaders(); |
| 214 } |
| 215 |
| 216 class PrecisionShaderPixelTest |
| 217 : public GLRendererShaderPixelTest, |
| 218 public ::testing::WithParamInterface<TexCoordPrecision> {}; |
| 219 |
| 220 TEST_P(PrecisionShaderPixelTest, ShadersCompile) { |
| 221 TestShadersWithPrecision(GetParam()); |
| 222 } |
| 223 |
| 224 INSTANTIATE_TEST_CASE_P(PrecisionShadersCompile, |
| 225 PrecisionShaderPixelTest, |
| 226 ::testing::ValuesIn(kPrecisionList)); |
| 227 |
| 228 class PrecisionBlendShaderPixelTest |
| 229 : public GLRendererShaderPixelTest, |
| 230 public ::testing::WithParamInterface< |
| 231 std::tr1::tuple<TexCoordPrecision, BlendMode>> {}; |
| 232 |
| 233 TEST_P(PrecisionBlendShaderPixelTest, ShadersCompile) { |
| 234 TestShadersWithPrecisionAndBlend(std::tr1::get<0>(GetParam()), |
| 235 std::tr1::get<1>(GetParam())); |
| 236 } |
| 237 |
| 238 INSTANTIATE_TEST_CASE_P( |
| 239 PrecisionBlendShadersCompile, |
| 240 PrecisionBlendShaderPixelTest, |
| 241 ::testing::Combine(::testing::ValuesIn(kPrecisionList), |
| 242 ::testing::ValuesIn(kBlendModeList))); |
| 243 |
| 244 class PrecisionSamplerShaderPixelTest |
| 245 : public GLRendererShaderPixelTest, |
| 246 public ::testing::WithParamInterface< |
| 247 std::tr1::tuple<TexCoordPrecision, SamplerType>> {}; |
| 248 |
| 249 TEST_P(PrecisionSamplerShaderPixelTest, ShadersCompile) { |
| 250 TestShadersWithPrecisionAndSampler(std::tr1::get<0>(GetParam()), |
| 251 std::tr1::get<1>(GetParam())); |
| 252 } |
| 253 |
| 254 INSTANTIATE_TEST_CASE_P(PrecisionSamplerShadersCompile, |
| 255 PrecisionSamplerShaderPixelTest, |
| 256 ::testing::Combine(::testing::ValuesIn(kPrecisionList), |
| 257 ::testing::ValuesIn(kSamplerList))); |
| 258 |
| 259 class MaskShaderPixelTest |
| 260 : public GLRendererShaderPixelTest, |
| 261 public ::testing::WithParamInterface< |
| 262 std::tr1::tuple<TexCoordPrecision, SamplerType, BlendMode, bool>> {}; |
| 263 |
| 264 TEST_P(MaskShaderPixelTest, ShadersCompile) { |
| 265 TestShadersWithMasks( |
| 266 std::tr1::get<0>(GetParam()), std::tr1::get<1>(GetParam()), |
| 267 std::tr1::get<2>(GetParam()), std::tr1::get<3>(GetParam())); |
| 268 } |
| 269 |
| 270 INSTANTIATE_TEST_CASE_P(MaskShadersCompile, |
| 271 MaskShaderPixelTest, |
| 272 ::testing::Combine(::testing::ValuesIn(kPrecisionList), |
| 273 ::testing::ValuesIn(kSamplerList), |
| 274 ::testing::ValuesIn(kBlendModeList), |
| 275 ::testing::Bool())); |
| 276 |
174 #endif | 277 #endif |
175 | 278 |
176 class FakeRendererGL : public GLRenderer { | 279 class FakeRendererGL : public GLRenderer { |
177 public: | 280 public: |
178 FakeRendererGL(RendererClient* client, | 281 FakeRendererGL(RendererClient* client, |
179 const RendererSettings* settings, | 282 const RendererSettings* settings, |
180 OutputSurface* output_surface, | 283 OutputSurface* output_surface, |
181 ResourceProvider* resource_provider) | 284 ResourceProvider* resource_provider) |
182 : GLRenderer(client, | 285 : GLRenderer(client, |
183 settings, | 286 settings, |
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1302 viewport_rect, | 1405 viewport_rect, |
1303 clip_rect, | 1406 clip_rect, |
1304 false); | 1407 false); |
1305 EXPECT_EQ(0, context->discarded()); | 1408 EXPECT_EQ(0, context->discarded()); |
1306 context->reset(); | 1409 context->reset(); |
1307 } | 1410 } |
1308 } | 1411 } |
1309 | 1412 |
1310 class FlippedScissorAndViewportContext : public TestWebGraphicsContext3D { | 1413 class FlippedScissorAndViewportContext : public TestWebGraphicsContext3D { |
1311 public: | 1414 public: |
1312 FlippedScissorAndViewportContext() | 1415 MOCK_METHOD4(viewport, void(GLint x, GLint y, GLsizei width, GLsizei height)); |
1313 : did_call_viewport_(false), did_call_scissor_(false) {} | 1416 MOCK_METHOD4(scissor, void(GLint x, GLint y, GLsizei width, GLsizei height)); |
1314 ~FlippedScissorAndViewportContext() override { | |
1315 EXPECT_TRUE(did_call_viewport_); | |
1316 EXPECT_TRUE(did_call_scissor_); | |
1317 } | |
1318 | |
1319 void viewport(GLint x, GLint y, GLsizei width, GLsizei height) override { | |
1320 EXPECT_EQ(10, x); | |
1321 EXPECT_EQ(390, y); | |
1322 EXPECT_EQ(100, width); | |
1323 EXPECT_EQ(100, height); | |
1324 did_call_viewport_ = true; | |
1325 } | |
1326 | |
1327 void scissor(GLint x, GLint y, GLsizei width, GLsizei height) override { | |
1328 EXPECT_EQ(30, x); | |
1329 EXPECT_EQ(450, y); | |
1330 EXPECT_EQ(20, width); | |
1331 EXPECT_EQ(20, height); | |
1332 did_call_scissor_ = true; | |
1333 } | |
1334 | |
1335 private: | |
1336 bool did_call_viewport_; | |
1337 bool did_call_scissor_; | |
1338 }; | 1417 }; |
1339 | 1418 |
1340 TEST_F(GLRendererTest, ScissorAndViewportWithinNonreshapableSurface) { | 1419 TEST_F(GLRendererTest, ScissorAndViewportWithinNonreshapableSurface) { |
1341 // In Android WebView, the OutputSurface is unable to respect reshape() calls | 1420 // In Android WebView, the OutputSurface is unable to respect reshape() calls |
1342 // and maintains a fixed size. This test verifies that glViewport and | 1421 // and maintains a fixed size. This test verifies that glViewport and |
1343 // glScissor's Y coordinate is flipped correctly in this environment, and that | 1422 // glScissor's Y coordinate is flipped correctly in this environment, and that |
1344 // the glViewport can be at a nonzero origin within the surface. | 1423 // the glViewport can be at a nonzero origin within the surface. |
1345 scoped_ptr<FlippedScissorAndViewportContext> context_owned( | 1424 scoped_ptr<FlippedScissorAndViewportContext> context_owned( |
1346 new FlippedScissorAndViewportContext); | 1425 new FlippedScissorAndViewportContext); |
1347 | 1426 |
| 1427 // We expect exactly one call to viewport on this context and exactly two |
| 1428 // to scissor (one to scissor the clear, one to scissor the quad draw). |
| 1429 EXPECT_CALL(*context_owned, viewport(10, 390, 100, 100)); |
| 1430 EXPECT_CALL(*context_owned, scissor(10, 390, 100, 100)); |
| 1431 EXPECT_CALL(*context_owned, scissor(30, 450, 20, 20)); |
| 1432 |
1348 FakeOutputSurfaceClient output_surface_client; | 1433 FakeOutputSurfaceClient output_surface_client; |
1349 scoped_ptr<OutputSurface> output_surface( | 1434 scoped_ptr<OutputSurface> output_surface( |
1350 new NonReshapableOutputSurface(context_owned.Pass())); | 1435 new NonReshapableOutputSurface(context_owned.Pass())); |
1351 CHECK(output_surface->BindToClient(&output_surface_client)); | 1436 CHECK(output_surface->BindToClient(&output_surface_client)); |
1352 | 1437 |
1353 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | 1438 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( |
1354 new TestSharedBitmapManager()); | 1439 new TestSharedBitmapManager()); |
1355 scoped_ptr<ResourceProvider> resource_provider( | 1440 scoped_ptr<ResourceProvider> resource_provider( |
1356 ResourceProvider::Create(output_surface.get(), | 1441 ResourceProvider::Create(output_surface.get(), |
1357 shared_bitmap_manager.get(), | 1442 shared_bitmap_manager.get(), |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1982 base::MessageLoop::current()->Run(); | 2067 base::MessageLoop::current()->Run(); |
1983 | 2068 |
1984 // The sync point should have happened. | 2069 // The sync point should have happened. |
1985 EXPECT_EQ(1, sync_point_callback_count); | 2070 EXPECT_EQ(1, sync_point_callback_count); |
1986 EXPECT_EQ(1, other_callback_count); | 2071 EXPECT_EQ(1, other_callback_count); |
1987 } | 2072 } |
1988 #endif // OS_ANDROID | 2073 #endif // OS_ANDROID |
1989 | 2074 |
1990 } // namespace | 2075 } // namespace |
1991 } // namespace cc | 2076 } // namespace cc |
OLD | NEW |