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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 viewport_rect, | 355 viewport_rect, |
356 viewport_rect, | 356 viewport_rect, |
357 false); | 357 false); |
358 EXPECT_TRUE(renderer_->stencil_enabled()); | 358 EXPECT_TRUE(renderer_->stencil_enabled()); |
359 } | 359 } |
360 | 360 |
361 class ForbidSynchronousCallContext : public TestWebGraphicsContext3D { | 361 class ForbidSynchronousCallContext : public TestWebGraphicsContext3D { |
362 public: | 362 public: |
363 ForbidSynchronousCallContext() {} | 363 ForbidSynchronousCallContext() {} |
364 | 364 |
365 virtual void getAttachedShaders(GLuint program, | 365 void getAttachedShaders(GLuint program, |
366 GLsizei max_count, | 366 GLsizei max_count, |
367 GLsizei* count, | 367 GLsizei* count, |
368 GLuint* shaders) override { | 368 GLuint* shaders) override { |
369 ADD_FAILURE(); | 369 ADD_FAILURE(); |
370 } | 370 } |
371 virtual GLint getAttribLocation(GLuint program, const GLchar* name) override { | 371 GLint getAttribLocation(GLuint program, const GLchar* name) override { |
372 ADD_FAILURE(); | 372 ADD_FAILURE(); |
373 return 0; | 373 return 0; |
374 } | 374 } |
375 virtual void getBooleanv(GLenum pname, GLboolean* value) override { | 375 void getBooleanv(GLenum pname, GLboolean* value) override { ADD_FAILURE(); } |
| 376 void getBufferParameteriv(GLenum target, |
| 377 GLenum pname, |
| 378 GLint* value) override { |
376 ADD_FAILURE(); | 379 ADD_FAILURE(); |
377 } | 380 } |
378 virtual void getBufferParameteriv(GLenum target, | 381 GLenum getError() override { |
379 GLenum pname, | |
380 GLint* value) override { | |
381 ADD_FAILURE(); | |
382 } | |
383 virtual GLenum getError() override { | |
384 ADD_FAILURE(); | 382 ADD_FAILURE(); |
385 return GL_NO_ERROR; | 383 return GL_NO_ERROR; |
386 } | 384 } |
387 virtual void getFloatv(GLenum pname, GLfloat* value) override { | 385 void getFloatv(GLenum pname, GLfloat* value) override { ADD_FAILURE(); } |
| 386 void getFramebufferAttachmentParameteriv(GLenum target, |
| 387 GLenum attachment, |
| 388 GLenum pname, |
| 389 GLint* value) override { |
388 ADD_FAILURE(); | 390 ADD_FAILURE(); |
389 } | 391 } |
390 virtual void getFramebufferAttachmentParameteriv(GLenum target, | 392 void getIntegerv(GLenum pname, GLint* value) override { |
391 GLenum attachment, | |
392 GLenum pname, | |
393 GLint* value) override { | |
394 ADD_FAILURE(); | |
395 } | |
396 virtual void getIntegerv(GLenum pname, GLint* value) override { | |
397 if (pname == GL_MAX_TEXTURE_SIZE) { | 393 if (pname == GL_MAX_TEXTURE_SIZE) { |
398 // MAX_TEXTURE_SIZE is cached client side, so it's OK to query. | 394 // MAX_TEXTURE_SIZE is cached client side, so it's OK to query. |
399 *value = 1024; | 395 *value = 1024; |
400 } else { | 396 } else { |
401 ADD_FAILURE(); | 397 ADD_FAILURE(); |
402 } | 398 } |
403 } | 399 } |
404 | 400 |
405 // We allow querying the shader compilation and program link status in debug | 401 // We allow querying the shader compilation and program link status in debug |
406 // mode, but not release. | 402 // mode, but not release. |
407 virtual void getProgramiv(GLuint program, | 403 void getProgramiv(GLuint program, GLenum pname, GLint* value) override { |
408 GLenum pname, | |
409 GLint* value) override { | |
410 #ifndef NDEBUG | 404 #ifndef NDEBUG |
411 *value = 1; | 405 *value = 1; |
412 #else | 406 #else |
413 ADD_FAILURE(); | 407 ADD_FAILURE(); |
414 #endif | 408 #endif |
415 } | 409 } |
416 | 410 |
417 virtual void getShaderiv(GLuint shader, GLenum pname, GLint* value) override { | 411 void getShaderiv(GLuint shader, GLenum pname, GLint* value) override { |
418 #ifndef NDEBUG | 412 #ifndef NDEBUG |
419 *value = 1; | 413 *value = 1; |
420 #else | 414 #else |
421 ADD_FAILURE(); | 415 ADD_FAILURE(); |
422 #endif | 416 #endif |
423 } | 417 } |
424 | 418 |
425 virtual void getRenderbufferParameteriv(GLenum target, | 419 void getRenderbufferParameteriv(GLenum target, |
426 GLenum pname, | 420 GLenum pname, |
427 GLint* value) override { | 421 GLint* value) override { |
428 ADD_FAILURE(); | 422 ADD_FAILURE(); |
429 } | 423 } |
430 | 424 |
431 virtual void getShaderPrecisionFormat(GLenum shadertype, | 425 void getShaderPrecisionFormat(GLenum shadertype, |
432 GLenum precisiontype, | 426 GLenum precisiontype, |
433 GLint* range, | 427 GLint* range, |
434 GLint* precision) override { | 428 GLint* precision) override { |
435 ADD_FAILURE(); | 429 ADD_FAILURE(); |
436 } | 430 } |
437 virtual void getTexParameterfv(GLenum target, | 431 void getTexParameterfv(GLenum target, GLenum pname, GLfloat* value) override { |
438 GLenum pname, | |
439 GLfloat* value) override { | |
440 ADD_FAILURE(); | 432 ADD_FAILURE(); |
441 } | 433 } |
442 virtual void getTexParameteriv(GLenum target, | 434 void getTexParameteriv(GLenum target, GLenum pname, GLint* value) override { |
443 GLenum pname, | |
444 GLint* value) override { | |
445 ADD_FAILURE(); | 435 ADD_FAILURE(); |
446 } | 436 } |
447 virtual void getUniformfv(GLuint program, | 437 void getUniformfv(GLuint program, GLint location, GLfloat* value) override { |
448 GLint location, | |
449 GLfloat* value) override { | |
450 ADD_FAILURE(); | 438 ADD_FAILURE(); |
451 } | 439 } |
452 virtual void getUniformiv(GLuint program, | 440 void getUniformiv(GLuint program, GLint location, GLint* value) override { |
453 GLint location, | |
454 GLint* value) override { | |
455 ADD_FAILURE(); | 441 ADD_FAILURE(); |
456 } | 442 } |
457 virtual GLint getUniformLocation(GLuint program, | 443 GLint getUniformLocation(GLuint program, const GLchar* name) override { |
458 const GLchar* name) override { | |
459 ADD_FAILURE(); | 444 ADD_FAILURE(); |
460 return 0; | 445 return 0; |
461 } | 446 } |
462 virtual void getVertexAttribfv(GLuint index, | 447 void getVertexAttribfv(GLuint index, GLenum pname, GLfloat* value) override { |
463 GLenum pname, | |
464 GLfloat* value) override { | |
465 ADD_FAILURE(); | 448 ADD_FAILURE(); |
466 } | 449 } |
467 virtual void getVertexAttribiv(GLuint index, | 450 void getVertexAttribiv(GLuint index, GLenum pname, GLint* value) override { |
468 GLenum pname, | |
469 GLint* value) override { | |
470 ADD_FAILURE(); | 451 ADD_FAILURE(); |
471 } | 452 } |
472 virtual GLsizeiptr getVertexAttribOffset(GLuint index, | 453 GLsizeiptr getVertexAttribOffset(GLuint index, GLenum pname) override { |
473 GLenum pname) override { | |
474 ADD_FAILURE(); | 454 ADD_FAILURE(); |
475 return 0; | 455 return 0; |
476 } | 456 } |
477 }; | 457 }; |
478 TEST_F(GLRendererTest, InitializationDoesNotMakeSynchronousCalls) { | 458 TEST_F(GLRendererTest, InitializationDoesNotMakeSynchronousCalls) { |
479 FakeOutputSurfaceClient output_surface_client; | 459 FakeOutputSurfaceClient output_surface_client; |
480 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 460 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
481 scoped_ptr<TestWebGraphicsContext3D>(new ForbidSynchronousCallContext))); | 461 scoped_ptr<TestWebGraphicsContext3D>(new ForbidSynchronousCallContext))); |
482 CHECK(output_surface->BindToClient(&output_surface_client)); | 462 CHECK(output_surface->BindToClient(&output_surface_client)); |
483 | 463 |
(...skipping 14 matching lines...) Expand all Loading... |
498 FakeRendererGL renderer(&renderer_client, | 478 FakeRendererGL renderer(&renderer_client, |
499 &settings, | 479 &settings, |
500 output_surface.get(), | 480 output_surface.get(), |
501 resource_provider.get()); | 481 resource_provider.get()); |
502 } | 482 } |
503 | 483 |
504 class LoseContextOnFirstGetContext : public TestWebGraphicsContext3D { | 484 class LoseContextOnFirstGetContext : public TestWebGraphicsContext3D { |
505 public: | 485 public: |
506 LoseContextOnFirstGetContext() {} | 486 LoseContextOnFirstGetContext() {} |
507 | 487 |
508 virtual void getProgramiv(GLuint program, | 488 void getProgramiv(GLuint program, GLenum pname, GLint* value) override { |
509 GLenum pname, | |
510 GLint* value) override { | |
511 context_lost_ = true; | 489 context_lost_ = true; |
512 *value = 0; | 490 *value = 0; |
513 } | 491 } |
514 | 492 |
515 virtual void getShaderiv(GLuint shader, GLenum pname, GLint* value) override { | 493 void getShaderiv(GLuint shader, GLenum pname, GLint* value) override { |
516 context_lost_ = true; | 494 context_lost_ = true; |
517 *value = 0; | 495 *value = 0; |
518 } | 496 } |
519 }; | 497 }; |
520 | 498 |
521 TEST_F(GLRendererTest, InitializationWithQuicklyLostContextDoesNotAssert) { | 499 TEST_F(GLRendererTest, InitializationWithQuicklyLostContextDoesNotAssert) { |
522 FakeOutputSurfaceClient output_surface_client; | 500 FakeOutputSurfaceClient output_surface_client; |
523 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( | 501 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( |
524 scoped_ptr<TestWebGraphicsContext3D>(new LoseContextOnFirstGetContext))); | 502 scoped_ptr<TestWebGraphicsContext3D>(new LoseContextOnFirstGetContext))); |
525 CHECK(output_surface->BindToClient(&output_surface_client)); | 503 CHECK(output_surface->BindToClient(&output_surface_client)); |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 Mock::VerifyAndClearExpectations(context); | 678 Mock::VerifyAndClearExpectations(context); |
701 } | 679 } |
702 | 680 |
703 class VisibilityChangeIsLastCallTrackingContext | 681 class VisibilityChangeIsLastCallTrackingContext |
704 : public TestWebGraphicsContext3D { | 682 : public TestWebGraphicsContext3D { |
705 public: | 683 public: |
706 VisibilityChangeIsLastCallTrackingContext() | 684 VisibilityChangeIsLastCallTrackingContext() |
707 : last_call_was_set_visibility_(false) {} | 685 : last_call_was_set_visibility_(false) {} |
708 | 686 |
709 // TestWebGraphicsContext3D methods. | 687 // TestWebGraphicsContext3D methods. |
710 virtual void flush() override { last_call_was_set_visibility_ = false; } | 688 void flush() override { last_call_was_set_visibility_ = false; } |
711 virtual void deleteTexture(GLuint) override { | 689 void deleteTexture(GLuint) override { last_call_was_set_visibility_ = false; } |
| 690 void deleteFramebuffer(GLuint) override { |
712 last_call_was_set_visibility_ = false; | 691 last_call_was_set_visibility_ = false; |
713 } | 692 } |
714 virtual void deleteFramebuffer(GLuint) override { | 693 void deleteQueryEXT(GLuint) override { |
715 last_call_was_set_visibility_ = false; | 694 last_call_was_set_visibility_ = false; |
716 } | 695 } |
717 virtual void deleteQueryEXT(GLuint) override { | 696 void deleteRenderbuffer(GLuint) override { |
718 last_call_was_set_visibility_ = false; | |
719 } | |
720 virtual void deleteRenderbuffer(GLuint) override { | |
721 last_call_was_set_visibility_ = false; | 697 last_call_was_set_visibility_ = false; |
722 } | 698 } |
723 | 699 |
724 // Methods added for test. | 700 // Methods added for test. |
725 void set_last_call_was_visibility(bool visible) { | 701 void set_last_call_was_visibility(bool visible) { |
726 DCHECK(last_call_was_set_visibility_ == false); | 702 DCHECK(last_call_was_set_visibility_ == false); |
727 last_call_was_set_visibility_ = true; | 703 last_call_was_set_visibility_ = true; |
728 } | 704 } |
729 bool last_call_was_set_visibility() const { | 705 bool last_call_was_set_visibility() const { |
730 return last_call_was_set_visibility_; | 706 return last_call_was_set_visibility_; |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
982 | 958 |
983 // In multiple render passes all but the root pass should clear the | 959 // In multiple render passes all but the root pass should clear the |
984 // framebuffer. | 960 // framebuffer. |
985 Mock::VerifyAndClearExpectations(&mock_context); | 961 Mock::VerifyAndClearExpectations(&mock_context); |
986 } | 962 } |
987 | 963 |
988 class ScissorTestOnClearCheckingContext : public TestWebGraphicsContext3D { | 964 class ScissorTestOnClearCheckingContext : public TestWebGraphicsContext3D { |
989 public: | 965 public: |
990 ScissorTestOnClearCheckingContext() : scissor_enabled_(false) {} | 966 ScissorTestOnClearCheckingContext() : scissor_enabled_(false) {} |
991 | 967 |
992 virtual void clear(GLbitfield) override { EXPECT_FALSE(scissor_enabled_); } | 968 void clear(GLbitfield) override { EXPECT_FALSE(scissor_enabled_); } |
993 | 969 |
994 virtual void enable(GLenum cap) override { | 970 void enable(GLenum cap) override { |
995 if (cap == GL_SCISSOR_TEST) | 971 if (cap == GL_SCISSOR_TEST) |
996 scissor_enabled_ = true; | 972 scissor_enabled_ = true; |
997 } | 973 } |
998 | 974 |
999 virtual void disable(GLenum cap) override { | 975 void disable(GLenum cap) override { |
1000 if (cap == GL_SCISSOR_TEST) | 976 if (cap == GL_SCISSOR_TEST) |
1001 scissor_enabled_ = false; | 977 scissor_enabled_ = false; |
1002 } | 978 } |
1003 | 979 |
1004 private: | 980 private: |
1005 bool scissor_enabled_; | 981 bool scissor_enabled_; |
1006 }; | 982 }; |
1007 | 983 |
1008 TEST_F(GLRendererTest, ScissorTestWhenClearing) { | 984 TEST_F(GLRendererTest, ScissorTestWhenClearing) { |
1009 scoped_ptr<ScissorTestOnClearCheckingContext> context_owned( | 985 scoped_ptr<ScissorTestOnClearCheckingContext> context_owned( |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 false); | 1047 false); |
1072 } | 1048 } |
1073 | 1049 |
1074 class DiscardCheckingContext : public TestWebGraphicsContext3D { | 1050 class DiscardCheckingContext : public TestWebGraphicsContext3D { |
1075 public: | 1051 public: |
1076 DiscardCheckingContext() : discarded_(0) { | 1052 DiscardCheckingContext() : discarded_(0) { |
1077 set_have_post_sub_buffer(true); | 1053 set_have_post_sub_buffer(true); |
1078 set_have_discard_framebuffer(true); | 1054 set_have_discard_framebuffer(true); |
1079 } | 1055 } |
1080 | 1056 |
1081 virtual void discardFramebufferEXT(GLenum target, | 1057 void discardFramebufferEXT(GLenum target, |
1082 GLsizei numAttachments, | 1058 GLsizei numAttachments, |
1083 const GLenum* attachments) override { | 1059 const GLenum* attachments) override { |
1084 ++discarded_; | 1060 ++discarded_; |
1085 } | 1061 } |
1086 | 1062 |
1087 int discarded() const { return discarded_; } | 1063 int discarded() const { return discarded_; } |
1088 void reset() { discarded_ = 0; } | 1064 void reset() { discarded_ = 0; } |
1089 | 1065 |
1090 private: | 1066 private: |
1091 int discarded_; | 1067 int discarded_; |
1092 }; | 1068 }; |
1093 | 1069 |
1094 class NonReshapableOutputSurface : public FakeOutputSurface { | 1070 class NonReshapableOutputSurface : public FakeOutputSurface { |
1095 public: | 1071 public: |
1096 explicit NonReshapableOutputSurface( | 1072 explicit NonReshapableOutputSurface( |
1097 scoped_ptr<TestWebGraphicsContext3D> context3d) | 1073 scoped_ptr<TestWebGraphicsContext3D> context3d) |
1098 : FakeOutputSurface(TestContextProvider::Create(context3d.Pass()), | 1074 : FakeOutputSurface(TestContextProvider::Create(context3d.Pass()), |
1099 false) { | 1075 false) { |
1100 surface_size_ = gfx::Size(500, 500); | 1076 surface_size_ = gfx::Size(500, 500); |
1101 } | 1077 } |
1102 virtual void Reshape(const gfx::Size& size, float scale_factor) override {} | 1078 void Reshape(const gfx::Size& size, float scale_factor) override {} |
1103 void set_fixed_size(const gfx::Size& size) { surface_size_ = size; } | 1079 void set_fixed_size(const gfx::Size& size) { surface_size_ = size; } |
1104 }; | 1080 }; |
1105 | 1081 |
1106 TEST_F(GLRendererTest, NoDiscardOnPartialUpdates) { | 1082 TEST_F(GLRendererTest, NoDiscardOnPartialUpdates) { |
1107 scoped_ptr<DiscardCheckingContext> context_owned(new DiscardCheckingContext); | 1083 scoped_ptr<DiscardCheckingContext> context_owned(new DiscardCheckingContext); |
1108 DiscardCheckingContext* context = context_owned.get(); | 1084 DiscardCheckingContext* context = context_owned.get(); |
1109 | 1085 |
1110 FakeOutputSurfaceClient output_surface_client; | 1086 FakeOutputSurfaceClient output_surface_client; |
1111 scoped_ptr<NonReshapableOutputSurface> output_surface( | 1087 scoped_ptr<NonReshapableOutputSurface> output_surface( |
1112 new NonReshapableOutputSurface(context_owned.Pass())); | 1088 new NonReshapableOutputSurface(context_owned.Pass())); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1257 false); | 1233 false); |
1258 EXPECT_EQ(0, context->discarded()); | 1234 EXPECT_EQ(0, context->discarded()); |
1259 context->reset(); | 1235 context->reset(); |
1260 } | 1236 } |
1261 } | 1237 } |
1262 | 1238 |
1263 class FlippedScissorAndViewportContext : public TestWebGraphicsContext3D { | 1239 class FlippedScissorAndViewportContext : public TestWebGraphicsContext3D { |
1264 public: | 1240 public: |
1265 FlippedScissorAndViewportContext() | 1241 FlippedScissorAndViewportContext() |
1266 : did_call_viewport_(false), did_call_scissor_(false) {} | 1242 : did_call_viewport_(false), did_call_scissor_(false) {} |
1267 virtual ~FlippedScissorAndViewportContext() { | 1243 ~FlippedScissorAndViewportContext() override { |
1268 EXPECT_TRUE(did_call_viewport_); | 1244 EXPECT_TRUE(did_call_viewport_); |
1269 EXPECT_TRUE(did_call_scissor_); | 1245 EXPECT_TRUE(did_call_scissor_); |
1270 } | 1246 } |
1271 | 1247 |
1272 virtual void viewport(GLint x, GLint y, GLsizei width, GLsizei height) | 1248 void viewport(GLint x, GLint y, GLsizei width, GLsizei height) override { |
1273 override { | |
1274 EXPECT_EQ(10, x); | 1249 EXPECT_EQ(10, x); |
1275 EXPECT_EQ(390, y); | 1250 EXPECT_EQ(390, y); |
1276 EXPECT_EQ(100, width); | 1251 EXPECT_EQ(100, width); |
1277 EXPECT_EQ(100, height); | 1252 EXPECT_EQ(100, height); |
1278 did_call_viewport_ = true; | 1253 did_call_viewport_ = true; |
1279 } | 1254 } |
1280 | 1255 |
1281 virtual void scissor(GLint x, GLint y, GLsizei width, GLsizei height) | 1256 void scissor(GLint x, GLint y, GLsizei width, GLsizei height) override { |
1282 override { | |
1283 EXPECT_EQ(30, x); | 1257 EXPECT_EQ(30, x); |
1284 EXPECT_EQ(450, y); | 1258 EXPECT_EQ(450, y); |
1285 EXPECT_EQ(20, width); | 1259 EXPECT_EQ(20, width); |
1286 EXPECT_EQ(20, height); | 1260 EXPECT_EQ(20, height); |
1287 did_call_scissor_ = true; | 1261 did_call_scissor_ = true; |
1288 } | 1262 } |
1289 | 1263 |
1290 private: | 1264 private: |
1291 bool did_call_viewport_; | 1265 bool did_call_viewport_; |
1292 bool did_call_scissor_; | 1266 bool did_call_scissor_; |
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1850 base::MessageLoop::current()->Run(); | 1824 base::MessageLoop::current()->Run(); |
1851 | 1825 |
1852 // The sync point should have happened. | 1826 // The sync point should have happened. |
1853 EXPECT_EQ(1, sync_point_callback_count); | 1827 EXPECT_EQ(1, sync_point_callback_count); |
1854 EXPECT_EQ(1, other_callback_count); | 1828 EXPECT_EQ(1, other_callback_count); |
1855 } | 1829 } |
1856 #endif // OS_ANDROID | 1830 #endif // OS_ANDROID |
1857 | 1831 |
1858 } // namespace | 1832 } // namespace |
1859 } // namespace cc | 1833 } // namespace cc |
OLD | NEW |