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

Side by Side Diff: cc/output/gl_renderer_unittest.cc

Issue 2677893003: cc: Add color conversion support to all DrawQuad types (Closed)
Patch Set: Update w/2681223002 Created 3 years, 10 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 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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <set> 9 #include <set>
10 #include <vector> 10 #include <vector>
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 void SetUp() override { 126 void SetUp() override {
127 GLRendererPixelTest::SetUp(); 127 GLRendererPixelTest::SetUp();
128 ASSERT_FALSE(renderer()->IsContextLost()); 128 ASSERT_FALSE(renderer()->IsContextLost());
129 } 129 }
130 130
131 void TearDown() override { 131 void TearDown() override {
132 GLRendererPixelTest::TearDown(); 132 GLRendererPixelTest::TearDown();
133 ASSERT_FALSE(renderer()->IsContextLost()); 133 ASSERT_FALSE(renderer()->IsContextLost());
134 } 134 }
135 135
136 void TestShader(const ProgramKey& program_key) {
137 renderer()->SetCurrentFrameForTesting(GLRenderer::DrawingFrame());
138 const size_t kNumSrcColorSpaces = 3;
139 gfx::ColorSpace src_color_spaces[kNumSrcColorSpaces] = {
140 gfx::ColorSpace(), gfx::ColorSpace::CreateSRGB(),
141 gfx::ColorSpace::CreateREC709(),
142 };
143 const size_t kNumDstColorSpaces = 3;
144 gfx::ColorSpace dst_color_spaces[kNumDstColorSpaces] = {
145 gfx::ColorSpace(), gfx::ColorSpace::CreateSRGB(),
146 gfx::ColorSpace::CreateSCRGBLinear(),
147 };
148 for (size_t i = 0; i < kNumDstColorSpaces; ++i) {
149 for (size_t j = 0; j < kNumSrcColorSpaces; ++j) {
150 renderer()->SetUseProgram(program_key, src_color_spaces[j],
151 dst_color_spaces[i]);
152 EXPECT_TRUE(renderer()->current_program_->initialized());
153 }
154 }
155 }
156
136 void TestBasicShaders() { 157 void TestBasicShaders() {
137 EXPECT_PROGRAM_VALID(renderer()->GetProgram(ProgramKey::DebugBorder())); 158 TestShader(ProgramKey::DebugBorder());
138 EXPECT_PROGRAM_VALID(renderer()->GetProgram(ProgramKey::SolidColor(NO_AA))); 159 TestShader(ProgramKey::SolidColor(NO_AA));
139 EXPECT_PROGRAM_VALID( 160 TestShader(ProgramKey::SolidColor(USE_AA));
140 renderer()->GetProgram(ProgramKey::SolidColor(USE_AA)));
141 } 161 }
142 162
143 void TestShadersWithPrecision(TexCoordPrecision precision) { 163 void TestShadersWithPrecision(TexCoordPrecision precision) {
144 // This program uses external textures and sampler, so it won't compile 164 // This program uses external textures and sampler, so it won't compile
145 // everywhere. 165 // everywhere.
146 if (context_provider()->ContextCapabilities().egl_image_external) 166 if (context_provider()->ContextCapabilities().egl_image_external) {
147 EXPECT_PROGRAM_VALID( 167 TestShader(ProgramKey::VideoStream(precision));
148 renderer()->GetProgram(ProgramKey::VideoStream(precision))); 168 }
149 } 169 }
150 170
151 void TestShadersWithPrecisionAndBlend(TexCoordPrecision precision, 171 void TestShadersWithPrecisionAndBlend(TexCoordPrecision precision,
152 BlendMode blend_mode) { 172 BlendMode blend_mode) {
153 EXPECT_PROGRAM_VALID(renderer()->GetProgram(ProgramKey::RenderPass( 173 TestShader(ProgramKey::RenderPass(precision, SAMPLER_TYPE_2D, blend_mode,
154 precision, SAMPLER_TYPE_2D, blend_mode, NO_AA, NO_MASK, false, false))); 174 NO_AA, NO_MASK, false, false));
155 EXPECT_PROGRAM_VALID(renderer()->GetProgram( 175 TestShader(ProgramKey::RenderPass(precision, SAMPLER_TYPE_2D, blend_mode,
156 ProgramKey::RenderPass(precision, SAMPLER_TYPE_2D, blend_mode, USE_AA, 176 USE_AA, NO_MASK, false, false));
157 NO_MASK, false, false)));
158 } 177 }
159 178
160 void TestShadersWithPrecisionAndSampler(TexCoordPrecision precision, 179 void TestShadersWithPrecisionAndSampler(TexCoordPrecision precision,
161 SamplerType sampler) { 180 SamplerType sampler) {
162 if (!context_provider()->ContextCapabilities().egl_image_external && 181 if (!context_provider()->ContextCapabilities().egl_image_external &&
163 sampler == SAMPLER_TYPE_EXTERNAL_OES) { 182 sampler == SAMPLER_TYPE_EXTERNAL_OES) {
164 // This will likely be hit in tests due to usage of osmesa. 183 // This will likely be hit in tests due to usage of osmesa.
165 return; 184 return;
166 } 185 }
167 186
168 EXPECT_PROGRAM_VALID(renderer()->GetProgram( 187 TestShader(
169 ProgramKey::Texture(precision, sampler, PREMULTIPLIED_ALPHA, false))); 188 ProgramKey::Texture(precision, sampler, PREMULTIPLIED_ALPHA, false));
170 EXPECT_PROGRAM_VALID(renderer()->GetProgram( 189 TestShader(
171 ProgramKey::Texture(precision, sampler, PREMULTIPLIED_ALPHA, true))); 190 ProgramKey::Texture(precision, sampler, PREMULTIPLIED_ALPHA, true));
172 EXPECT_PROGRAM_VALID(renderer()->GetProgram(ProgramKey::Texture( 191 TestShader(ProgramKey::Texture(precision, sampler, NON_PREMULTIPLIED_ALPHA,
173 precision, sampler, NON_PREMULTIPLIED_ALPHA, false))); 192 false));
174 EXPECT_PROGRAM_VALID(renderer()->GetProgram(ProgramKey::Texture( 193 TestShader(
175 precision, sampler, NON_PREMULTIPLIED_ALPHA, true))); 194 ProgramKey::Texture(precision, sampler, NON_PREMULTIPLIED_ALPHA, true));
176 195 TestShader(ProgramKey::Tile(precision, sampler, NO_AA, NO_SWIZZLE, false));
177 EXPECT_PROGRAM_VALID(renderer()->GetProgram( 196 TestShader(ProgramKey::Tile(precision, sampler, NO_AA, DO_SWIZZLE, false));
178 ProgramKey::Tile(precision, sampler, NO_AA, NO_SWIZZLE, false))); 197 TestShader(ProgramKey::Tile(precision, sampler, USE_AA, NO_SWIZZLE, false));
179 EXPECT_PROGRAM_VALID(renderer()->GetProgram( 198 TestShader(ProgramKey::Tile(precision, sampler, USE_AA, DO_SWIZZLE, false));
180 ProgramKey::Tile(precision, sampler, NO_AA, DO_SWIZZLE, false))); 199 TestShader(ProgramKey::Tile(precision, sampler, NO_AA, NO_SWIZZLE, true));
181 EXPECT_PROGRAM_VALID(renderer()->GetProgram( 200 TestShader(ProgramKey::Tile(precision, sampler, NO_AA, DO_SWIZZLE, true));
182 ProgramKey::Tile(precision, sampler, USE_AA, NO_SWIZZLE, false)));
183 EXPECT_PROGRAM_VALID(renderer()->GetProgram(
184 ProgramKey::Tile(precision, sampler, USE_AA, DO_SWIZZLE, false)));
185 EXPECT_PROGRAM_VALID(renderer()->GetProgram(
186 ProgramKey::Tile(precision, sampler, NO_AA, NO_SWIZZLE, true)));
187 EXPECT_PROGRAM_VALID(renderer()->GetProgram(
188 ProgramKey::Tile(precision, sampler, NO_AA, DO_SWIZZLE, true)));
189 201
190 // Iterate over alpha plane, nv12, and color_lut parameters. 202 // Iterate over alpha plane, nv12, and color_lut parameters.
191 UVTextureMode uv_modes[2] = {UV_TEXTURE_MODE_UV, UV_TEXTURE_MODE_U_V}; 203 UVTextureMode uv_modes[2] = {UV_TEXTURE_MODE_UV, UV_TEXTURE_MODE_U_V};
192 YUVAlphaTextureMode a_modes[2] = {YUV_NO_ALPHA_TEXTURE, 204 YUVAlphaTextureMode a_modes[2] = {YUV_NO_ALPHA_TEXTURE,
193 YUV_HAS_ALPHA_TEXTURE}; 205 YUV_HAS_ALPHA_TEXTURE};
194 ColorConversionMode c_modes[2] = {COLOR_CONVERSION_MODE_NONE,
195 COLOR_CONVERSION_MODE_LUT};
196 for (int j = 0; j < 2; j++) { 206 for (int j = 0; j < 2; j++) {
197 for (int k = 0; k < 2; k++) { 207 for (int k = 0; k < 2; k++) {
198 for (int l = 0; l < 2; l++) { 208 TestShader(
199 const Program* program = renderer()->GetProgram(ProgramKey::YUVVideo( 209 ProgramKey::YUVVideo(precision, sampler, a_modes[j], uv_modes[k]));
200 precision, sampler, a_modes[j], uv_modes[k], c_modes[l]));
201 EXPECT_PROGRAM_VALID(program);
202 }
203 } 210 }
204 } 211 }
205 } 212 }
206 213
207 void TestShadersWithMasks(TexCoordPrecision precision, 214 void TestShadersWithMasks(TexCoordPrecision precision,
208 SamplerType sampler, 215 SamplerType sampler,
209 BlendMode blend_mode, 216 BlendMode blend_mode,
210 bool mask_for_background) { 217 bool mask_for_background) {
211 if (!context_provider()->ContextCapabilities().egl_image_external && 218 if (!context_provider()->ContextCapabilities().egl_image_external &&
212 sampler == SAMPLER_TYPE_EXTERNAL_OES) { 219 sampler == SAMPLER_TYPE_EXTERNAL_OES) {
213 // This will likely be hit in tests due to usage of osmesa. 220 // This will likely be hit in tests due to usage of osmesa.
214 return; 221 return;
215 } 222 }
216 223
217 EXPECT_PROGRAM_VALID(renderer()->GetProgram( 224 TestShader(ProgramKey::RenderPass(precision, sampler, blend_mode, NO_AA,
218 ProgramKey::RenderPass(precision, sampler, blend_mode, NO_AA, HAS_MASK, 225 HAS_MASK, mask_for_background, false));
219 mask_for_background, false))); 226 TestShader(ProgramKey::RenderPass(precision, sampler, blend_mode, NO_AA,
220 EXPECT_PROGRAM_VALID(renderer()->GetProgram( 227 HAS_MASK, mask_for_background, true));
221 ProgramKey::RenderPass(precision, sampler, blend_mode, NO_AA, HAS_MASK, 228 TestShader(ProgramKey::RenderPass(precision, sampler, blend_mode, USE_AA,
222 mask_for_background, true))); 229 HAS_MASK, mask_for_background, false));
223 EXPECT_PROGRAM_VALID(renderer()->GetProgram( 230 TestShader(ProgramKey::RenderPass(precision, sampler, blend_mode, USE_AA,
224 ProgramKey::RenderPass(precision, sampler, blend_mode, USE_AA, HAS_MASK, 231 HAS_MASK, mask_for_background, true));
225 mask_for_background, false)));
226 EXPECT_PROGRAM_VALID(renderer()->GetProgram(
227 ProgramKey::RenderPass(precision, sampler, blend_mode, USE_AA, HAS_MASK,
228 mask_for_background, true)));
229 } 232 }
230 }; 233 };
231 234
232 namespace { 235 namespace {
233 236
234 #if !defined(OS_ANDROID) && !defined(OS_WIN) 237 #if !defined(OS_ANDROID) && !defined(OS_WIN)
235 static const TexCoordPrecision kPrecisionList[] = {TEX_COORD_PRECISION_MEDIUM, 238 static const TexCoordPrecision kPrecisionList[] = {TEX_COORD_PRECISION_MEDIUM,
236 TEX_COORD_PRECISION_HIGH}; 239 TEX_COORD_PRECISION_HIGH};
237 240
238 static const BlendMode kBlendModeList[LAST_BLEND_MODE + 1] = { 241 static const BlendMode kBlendModeList[LAST_BLEND_MODE + 1] = {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 renderer_->Initialize(); 406 renderer_->Initialize();
404 renderer_->SetVisible(true); 407 renderer_->SetVisible(true);
405 } 408 }
406 409
407 void TestRenderPassProgram(TexCoordPrecision precision, 410 void TestRenderPassProgram(TexCoordPrecision precision,
408 BlendMode blend_mode) { 411 BlendMode blend_mode) {
409 const Program* program = renderer_->GetProgramIfInitialized( 412 const Program* program = renderer_->GetProgramIfInitialized(
410 ProgramKey::RenderPass(precision, SAMPLER_TYPE_2D, blend_mode, NO_AA, 413 ProgramKey::RenderPass(precision, SAMPLER_TYPE_2D, blend_mode, NO_AA,
411 NO_MASK, false, false)); 414 NO_MASK, false, false));
412 EXPECT_PROGRAM_VALID(program); 415 EXPECT_PROGRAM_VALID(program);
413 EXPECT_EQ(program, renderer_->program_shadow_); 416 EXPECT_EQ(program, renderer_->current_program_);
414 } 417 }
415 418
416 void TestRenderPassColorMatrixProgram(TexCoordPrecision precision, 419 void TestRenderPassColorMatrixProgram(TexCoordPrecision precision,
417 BlendMode blend_mode) { 420 BlendMode blend_mode) {
418 const Program* program = renderer_->GetProgramIfInitialized( 421 const Program* program = renderer_->GetProgramIfInitialized(
419 ProgramKey::RenderPass(precision, SAMPLER_TYPE_2D, blend_mode, NO_AA, 422 ProgramKey::RenderPass(precision, SAMPLER_TYPE_2D, blend_mode, NO_AA,
420 NO_MASK, false, true)); 423 NO_MASK, false, true));
421 EXPECT_PROGRAM_VALID(program); 424 EXPECT_PROGRAM_VALID(program);
422 EXPECT_EQ(program, renderer_->program_shadow_); 425 EXPECT_EQ(program, renderer_->current_program_);
423 } 426 }
424 427
425 void TestRenderPassMaskProgram(TexCoordPrecision precision, 428 void TestRenderPassMaskProgram(TexCoordPrecision precision,
426 SamplerType sampler, 429 SamplerType sampler,
427 BlendMode blend_mode) { 430 BlendMode blend_mode) {
428 const Program* program = 431 const Program* program =
429 renderer_->GetProgramIfInitialized(ProgramKey::RenderPass( 432 renderer_->GetProgramIfInitialized(ProgramKey::RenderPass(
430 precision, sampler, blend_mode, NO_AA, HAS_MASK, false, false)); 433 precision, sampler, blend_mode, NO_AA, HAS_MASK, false, false));
431 EXPECT_PROGRAM_VALID(program); 434 EXPECT_PROGRAM_VALID(program);
432 EXPECT_EQ(program, renderer_->program_shadow_); 435 EXPECT_EQ(program, renderer_->current_program_);
433 } 436 }
434 437
435 void TestRenderPassMaskColorMatrixProgram(TexCoordPrecision precision, 438 void TestRenderPassMaskColorMatrixProgram(TexCoordPrecision precision,
436 SamplerType sampler, 439 SamplerType sampler,
437 BlendMode blend_mode) { 440 BlendMode blend_mode) {
438 const Program* program = 441 const Program* program =
439 renderer_->GetProgramIfInitialized(ProgramKey::RenderPass( 442 renderer_->GetProgramIfInitialized(ProgramKey::RenderPass(
440 precision, sampler, blend_mode, NO_AA, HAS_MASK, false, true)); 443 precision, sampler, blend_mode, NO_AA, HAS_MASK, false, true));
441 EXPECT_PROGRAM_VALID(program); 444 EXPECT_PROGRAM_VALID(program);
442 EXPECT_EQ(program, renderer_->program_shadow_); 445 EXPECT_EQ(program, renderer_->current_program_);
443 } 446 }
444 447
445 void TestRenderPassProgramAA(TexCoordPrecision precision, 448 void TestRenderPassProgramAA(TexCoordPrecision precision,
446 BlendMode blend_mode) { 449 BlendMode blend_mode) {
447 const Program* program = renderer_->GetProgramIfInitialized( 450 const Program* program = renderer_->GetProgramIfInitialized(
448 ProgramKey::RenderPass(precision, SAMPLER_TYPE_2D, blend_mode, USE_AA, 451 ProgramKey::RenderPass(precision, SAMPLER_TYPE_2D, blend_mode, USE_AA,
449 NO_MASK, false, false)); 452 NO_MASK, false, false));
450 EXPECT_PROGRAM_VALID(program); 453 EXPECT_PROGRAM_VALID(program);
451 EXPECT_EQ(program, renderer_->program_shadow_); 454 EXPECT_EQ(program, renderer_->current_program_);
452 } 455 }
453 456
454 void TestRenderPassColorMatrixProgramAA(TexCoordPrecision precision, 457 void TestRenderPassColorMatrixProgramAA(TexCoordPrecision precision,
455 BlendMode blend_mode) { 458 BlendMode blend_mode) {
456 const Program* program = renderer_->GetProgramIfInitialized( 459 const Program* program = renderer_->GetProgramIfInitialized(
457 ProgramKey::RenderPass(precision, SAMPLER_TYPE_2D, blend_mode, USE_AA, 460 ProgramKey::RenderPass(precision, SAMPLER_TYPE_2D, blend_mode, USE_AA,
458 NO_MASK, false, true)); 461 NO_MASK, false, true));
459 EXPECT_PROGRAM_VALID(program); 462 EXPECT_PROGRAM_VALID(program);
460 EXPECT_EQ(program, renderer_->program_shadow_); 463 EXPECT_EQ(program, renderer_->current_program_);
461 } 464 }
462 465
463 void TestRenderPassMaskProgramAA(TexCoordPrecision precision, 466 void TestRenderPassMaskProgramAA(TexCoordPrecision precision,
464 SamplerType sampler, 467 SamplerType sampler,
465 BlendMode blend_mode) { 468 BlendMode blend_mode) {
466 const Program* program = 469 const Program* program =
467 renderer_->GetProgramIfInitialized(ProgramKey::RenderPass( 470 renderer_->GetProgramIfInitialized(ProgramKey::RenderPass(
468 precision, sampler, blend_mode, USE_AA, HAS_MASK, false, false)); 471 precision, sampler, blend_mode, USE_AA, HAS_MASK, false, false));
469 EXPECT_PROGRAM_VALID(program); 472 EXPECT_PROGRAM_VALID(program);
470 EXPECT_EQ(program, renderer_->program_shadow_); 473 EXPECT_EQ(program, renderer_->current_program_);
471 } 474 }
472 475
473 void TestRenderPassMaskColorMatrixProgramAA(TexCoordPrecision precision, 476 void TestRenderPassMaskColorMatrixProgramAA(TexCoordPrecision precision,
474 SamplerType sampler, 477 SamplerType sampler,
475 BlendMode blend_mode) { 478 BlendMode blend_mode) {
476 const Program* program = 479 const Program* program =
477 renderer_->GetProgramIfInitialized(ProgramKey::RenderPass( 480 renderer_->GetProgramIfInitialized(ProgramKey::RenderPass(
478 precision, sampler, blend_mode, USE_AA, HAS_MASK, false, true)); 481 precision, sampler, blend_mode, USE_AA, HAS_MASK, false, true));
479 EXPECT_PROGRAM_VALID(program); 482 EXPECT_PROGRAM_VALID(program);
480 EXPECT_EQ(program, renderer_->program_shadow_); 483 EXPECT_EQ(program, renderer_->current_program_);
481 } 484 }
482 485
483 void TestSolidColorProgramAA() { 486 void TestSolidColorProgramAA() {
484 const Program* program = 487 const Program* program =
485 renderer_->GetProgramIfInitialized(ProgramKey::SolidColor(USE_AA)); 488 renderer_->GetProgramIfInitialized(ProgramKey::SolidColor(USE_AA));
486 EXPECT_PROGRAM_VALID(program); 489 EXPECT_PROGRAM_VALID(program);
487 EXPECT_EQ(program, renderer_->program_shadow_); 490 EXPECT_EQ(program, renderer_->current_program_);
488 } 491 }
489 492
490 RendererSettings settings_; 493 RendererSettings settings_;
491 FakeOutputSurfaceClient output_surface_client_; 494 FakeOutputSurfaceClient output_surface_client_;
492 std::unique_ptr<FakeOutputSurface> output_surface_; 495 std::unique_ptr<FakeOutputSurface> output_surface_;
493 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_; 496 std::unique_ptr<SharedBitmapManager> shared_bitmap_manager_;
494 std::unique_ptr<ResourceProvider> resource_provider_; 497 std::unique_ptr<ResourceProvider> resource_provider_;
495 std::unique_ptr<FakeRendererGL> renderer_; 498 std::unique_ptr<FakeRendererGL> renderer_;
496 }; 499 };
497 500
(...skipping 1486 matching lines...) Expand 10 before | Expand all | Expand 10 after
1984 renderer_->SetVisible(true); 1987 renderer_->SetVisible(true);
1985 Mock::VerifyAndClearExpectations(context_support_ptr_); 1988 Mock::VerifyAndClearExpectations(context_support_ptr_);
1986 1989
1987 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(true)); 1990 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(true));
1988 renderer_->SetVisible(false); 1991 renderer_->SetVisible(false);
1989 Mock::VerifyAndClearExpectations(context_support_ptr_); 1992 Mock::VerifyAndClearExpectations(context_support_ptr_);
1990 } 1993 }
1991 1994
1992 } // namespace 1995 } // namespace
1993 } // namespace cc 1996 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698