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

Side by Side Diff: gpu/command_buffer/tests/gl_chromium_path_rendering_unittest.cc

Issue 477623004: command_buffer: Support instanced path rendering in gpu command buffer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@new-03-path-funcs
Patch Set: fix msvc signedness warning in an unittest Created 5 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 <GLES2/gl2.h> 5 #include <GLES2/gl2.h>
6 #include <GLES2/gl2ext.h> 6 #include <GLES2/gl2ext.h>
7 #include <GLES2/gl2extchromium.h> 7 #include <GLES2/gl2extchromium.h>
8 #include <cmath> 8 #include <cmath>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "gpu/command_buffer/service/gpu_switches.h" 11 #include "gpu/command_buffer/service/gpu_switches.h"
12 #include "gpu/command_buffer/tests/gl_manager.h" 12 #include "gpu/command_buffer/tests/gl_manager.h"
13 #include "gpu/command_buffer/tests/gl_test_utils.h" 13 #include "gpu/command_buffer/tests/gl_test_utils.h"
14 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
16 16
17 #define SHADER(Src) #Src 17 #define SHADER(Src) #Src
18 18
19 namespace gpu { 19 namespace gpu {
20 20
21 class CHROMIUMPathRenderingTest : public testing::Test { 21 class CHROMIUMPathRenderingTest : public testing::Test {
22 public: 22 public:
23 static const GLsizei kResolution = 100; 23 static const GLsizei kResolution = 300;
24 24
25 protected: 25 protected:
26 void SetUp() override { 26 void SetUp() override {
27 GLManager::Options options; 27 GLManager::Options options;
28 options.size = gfx::Size(kResolution, kResolution); 28 options.size = gfx::Size(kResolution, kResolution);
29 base::CommandLine command_line(*base::CommandLine::ForCurrentProcess()); 29 base::CommandLine command_line(*base::CommandLine::ForCurrentProcess());
30 command_line.AppendSwitch(switches::kEnableGLPathRendering); 30 command_line.AppendSwitch(switches::kEnableGLPathRendering);
31 gl_.InitializeWithCommandLine(options, &command_line); 31 gl_.InitializeWithCommandLine(options, &command_line);
32 } 32 }
33 33
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 glPathParameterfCHROMIUM(path, GL_PATH_STROKE_WIDTH_CHROMIUM, 5.0f); 116 glPathParameterfCHROMIUM(path, GL_PATH_STROKE_WIDTH_CHROMIUM, 5.0f);
117 glPathParameterfCHROMIUM(path, GL_PATH_MITER_LIMIT_CHROMIUM, 1.0f); 117 glPathParameterfCHROMIUM(path, GL_PATH_MITER_LIMIT_CHROMIUM, 1.0f);
118 glPathParameterfCHROMIUM(path, GL_PATH_STROKE_BOUND_CHROMIUM, .02f); 118 glPathParameterfCHROMIUM(path, GL_PATH_STROKE_BOUND_CHROMIUM, .02f);
119 glPathParameteriCHROMIUM(path, GL_PATH_JOIN_STYLE_CHROMIUM, 119 glPathParameteriCHROMIUM(path, GL_PATH_JOIN_STYLE_CHROMIUM,
120 GL_ROUND_CHROMIUM); 120 GL_ROUND_CHROMIUM);
121 glPathParameteriCHROMIUM(path, GL_PATH_END_CAPS_CHROMIUM, 121 glPathParameteriCHROMIUM(path, GL_PATH_END_CAPS_CHROMIUM,
122 GL_SQUARE_CHROMIUM); 122 GL_SQUARE_CHROMIUM);
123 } 123 }
124 124
125 void VerifyTestPatternFill(float x, float y) { 125 void VerifyTestPatternFill(float x, float y) {
126 static const float kFillCoords[] = { 126 SCOPED_TRACE(testing::Message() << "Verifying fill at " << x << "," << y);
127 55.0f, 55.0f, 50.0f, 28.0f, 66.0f, 63.0f}; 127 static const float kFillCoords[] = {55.0f, 54.0f, 50.0f,
128 28.0f, 66.0f, 63.0f};
128 static const uint8 kBlue[] = {0, 0, 255, 255}; 129 static const uint8 kBlue[] = {0, 0, 255, 255};
129 130
130 for (size_t i = 0; i < arraysize(kFillCoords); i += 2) { 131 for (size_t i = 0; i < arraysize(kFillCoords); i += 2) {
131 float fx = kFillCoords[i]; 132 float fx = kFillCoords[i];
132 float fy = kFillCoords[i + 1]; 133 float fy = kFillCoords[i + 1];
133 134
134 EXPECT_TRUE(GLTestHelper::CheckPixels(x + fx, y + fy, 1, 1, 0, kBlue)); 135 EXPECT_TRUE(GLTestHelper::CheckPixels(x + fx, y + fy, 1, 1, 0, kBlue));
135 } 136 }
136 } 137 }
137 138
138 void VerifyTestPatternBg(float x, float y) { 139 void VerifyTestPatternBg(float x, float y) {
140 SCOPED_TRACE(testing::Message() << "Verifying background at " << x << ","
141 << y);
139 const float kBackgroundCoords[] = {80.0f, 80.0f, 20.0f, 20.0f, 90.0f, 1.0f}; 142 const float kBackgroundCoords[] = {80.0f, 80.0f, 20.0f, 20.0f, 90.0f, 1.0f};
140 const uint8 kExpectedColor[] = {0, 0, 0, 0}; 143 const uint8 kExpectedColor[] = {0, 0, 0, 0};
141 144
142 for (size_t i = 0; i < arraysize(kBackgroundCoords); i += 2) { 145 for (size_t i = 0; i < arraysize(kBackgroundCoords); i += 2) {
143 float bx = kBackgroundCoords[i]; 146 float bx = kBackgroundCoords[i];
144 float by = kBackgroundCoords[i + 1]; 147 float by = kBackgroundCoords[i + 1];
145 148
146 EXPECT_TRUE( 149 EXPECT_TRUE(
147 GLTestHelper::CheckPixels(x + bx, y + by, 1, 1, 0, kExpectedColor)); 150 GLTestHelper::CheckPixels(x + bx, y + by, 1, 1, 0, kExpectedColor));
148 } 151 }
149 } 152 }
150 153
151 void VerifyTestPatternStroke(float x, float y) { 154 void VerifyTestPatternStroke(float x, float y) {
155 SCOPED_TRACE(testing::Message() << "Verifying stroke at " << x << "," << y);
152 // Inside the stroke we should have green. 156 // Inside the stroke we should have green.
153 const uint8 kGreen[] = {0, 255, 0, 255}; 157 const uint8 kGreen[] = {0, 255, 0, 255};
154 EXPECT_TRUE(GLTestHelper::CheckPixels(x + 50, y + 53, 1, 1, 0, kGreen)); 158 EXPECT_TRUE(GLTestHelper::CheckPixels(x + 50, y + 53, 1, 1, 0, kGreen));
155 EXPECT_TRUE(GLTestHelper::CheckPixels(x + 26, y + 76, 1, 1, 0, kGreen)); 159 EXPECT_TRUE(GLTestHelper::CheckPixels(x + 26, y + 76, 1, 1, 0, kGreen));
156 160
157 // Outside the path we should have black. 161 // Outside the path we should have black.
158 const uint8 black[] = {0, 0, 0, 0}; 162 const uint8 black[] = {0, 0, 0, 0};
159 EXPECT_TRUE(GLTestHelper::CheckPixels(x + 10, y + 10, 1, 1, 0, black)); 163 EXPECT_TRUE(GLTestHelper::CheckPixels(x + 10, y + 10, 1, 1, 0, black));
160 EXPECT_TRUE(GLTestHelper::CheckPixels(x + 80, y + 80, 1, 1, 0, black)); 164 EXPECT_TRUE(GLTestHelper::CheckPixels(x + 80, y + 80, 1, 1, 0, black));
161 } 165 }
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 glStencilThenCoverFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM - 1, 0x7F, 522 glStencilThenCoverFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM - 1, 0x7F,
519 GL_BOUNDING_BOX_CHROMIUM); 523 GL_BOUNDING_BOX_CHROMIUM);
520 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); 524 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
521 525
522 // Using invalid cover mode causes INVALID_ENUM. 526 // Using invalid cover mode causes INVALID_ENUM.
523 glCoverFillPathCHROMIUM(path, GL_CONVEX_HULL_CHROMIUM - 1); 527 glCoverFillPathCHROMIUM(path, GL_CONVEX_HULL_CHROMIUM - 1);
524 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); 528 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
525 glStencilThenCoverFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x7F, 529 glStencilThenCoverFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x7F,
526 GL_BOUNDING_BOX_CHROMIUM + 1); 530 GL_BOUNDING_BOX_CHROMIUM + 1);
527 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError()); 531 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
532 // For instanced variants, we need this to error the same way
533 // regardless of whether # of paths == 0 would cause an early return.
534 for (int path_count = 0; path_count <= 1; ++path_count) {
535 SCOPED_TRACE(testing::Message()
536 << "Invalid fillmode instanced test for path count "
537 << path_count);
538 glStencilFillPathInstancedCHROMIUM(path_count, GL_UNSIGNED_INT, &path, 0,
539 GL_COUNT_UP_CHROMIUM - 1, 0x7F, GL_NONE,
540 NULL);
541 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
542 glStencilThenCoverFillPathInstancedCHROMIUM(
543 path_count, GL_UNSIGNED_INT, &path, 0, GL_COUNT_UP_CHROMIUM - 1, 0x7F,
544 GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM, GL_NONE, NULL);
545 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_ENUM), glGetError());
546 }
528 547
529 // Using mask+1 not being power of two causes INVALID_VALUE with up/down fill 548 // Using mask+1 not being power of two causes INVALID_VALUE with up/down fill
530 // mode. 549 // mode.
531 glStencilFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x40); 550 glStencilFillPathCHROMIUM(path, GL_COUNT_UP_CHROMIUM, 0x40);
532 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError()); 551 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
533 glStencilThenCoverFillPathCHROMIUM(path, GL_COUNT_DOWN_CHROMIUM, 12, 552 glStencilThenCoverFillPathCHROMIUM(path, GL_COUNT_DOWN_CHROMIUM, 12,
534 GL_BOUNDING_BOX_CHROMIUM); 553 GL_BOUNDING_BOX_CHROMIUM);
535 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError()); 554 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
555 for (int path_count = 0; path_count <= 1; ++path_count) {
556 SCOPED_TRACE(testing::Message()
557 << "Invalid mask instanced test for path count "
558 << path_count);
559 glStencilFillPathInstancedCHROMIUM(path_count, GL_UNSIGNED_INT, &path, 0,
560 GL_COUNT_UP_CHROMIUM, 0x30, GL_NONE,
561 NULL);
562 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
563 glStencilThenCoverFillPathInstancedCHROMIUM(
564 path_count, GL_UNSIGNED_INT, &path, 0, GL_COUNT_DOWN_CHROMIUM, 0xFE,
565 GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM, GL_NONE, NULL);
566 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE), glGetError());
567 }
536 568
537 glDeletePathsCHROMIUM(path, 1); 569 glDeletePathsCHROMIUM(path, 1);
538 } 570 }
539 571
540 // Tests that drawing with CHROMIUM_path_rendering functions work. 572 // Tests that drawing with CHROMIUM_path_rendering functions work.
541 TEST_F(CHROMIUMPathRenderingTest, TestPathRendering) { 573 TEST_F(CHROMIUMPathRenderingTest, TestPathRendering) {
542 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) 574 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering"))
543 return; 575 return;
544 576
545 static const float kBlue[] = {0.0f, 0.0f, 1.0f, 1.0f}; 577 static const float kBlue[] = {0.0f, 0.0f, 1.0f, 1.0f};
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 GL_CONVEX_HULL_CHROMIUM); 644 GL_CONVEX_HULL_CHROMIUM);
613 645
614 glDeletePathsCHROMIUM(path, 1); 646 glDeletePathsCHROMIUM(path, 1);
615 647
616 // Verify the image. 648 // Verify the image.
617 VerifyTestPatternFill(0.0f, 0.0f); 649 VerifyTestPatternFill(0.0f, 0.0f);
618 VerifyTestPatternBg(0.0f, 0.0f); 650 VerifyTestPatternBg(0.0f, 0.0f);
619 VerifyTestPatternStroke(0.0f, 0.0f); 651 VerifyTestPatternStroke(0.0f, 0.0f);
620 } 652 }
621 653
654 // Tests that drawing with *Instanced functions work.
655 TEST_F(CHROMIUMPathRenderingTest, TestPathRenderingInstanced) {
656 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) {
657 return;
658 }
659 static const float kBlue[] = {0.0f, 0.0f, 1.0f, 1.0f};
660 static const float kGreen[] = {0.0f, 1.0f, 0.0f, 1.0f};
661
662 SetupStateForTestPattern();
663
664 GLuint path = glGenPathsCHROMIUM(1);
665 SetupPathStateForTestPattern(path);
666
667 const GLuint kPaths[] = {1, 1, 1, 1, 1};
668 const GLsizei kPathCount = arraysize(kPaths);
669 const GLfloat kShapeSize = 80.0f;
670 static const GLfloat kTransforms[kPathCount * 12] = {
671 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
672 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f,
673 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
674 0.0f, 0.0f, 1.0f, kShapeSize, 0.0f, 0.0f,
675 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
676 0.0f, 0.0f, 1.0f, kShapeSize * 2, 0.0f, 0.0f,
677 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
678 0.0f, 0.0f, 1.0f, 0.0f, kShapeSize, 0.0f,
679 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f,
680 0.0f, 0.0f, 1.0f, kShapeSize, kShapeSize, 0.0f};
681
682 // The test pattern is the same as in the simple draw case above,
683 // except that the path is drawn kPathCount times with different offsets.
684 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0xFF);
685 glStencilStrokePathInstancedCHROMIUM(kPathCount, GL_UNSIGNED_INT, kPaths,
686 path - 1, 0x80, 0x80,
687 GL_AFFINE_3D_CHROMIUM, kTransforms);
688
689 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0x7F);
690 glUniform4fv(color_loc_, 1, kBlue);
691 glStencilFillPathInstancedCHROMIUM(kPathCount, GL_UNSIGNED_INT, kPaths,
692 path - 1, GL_COUNT_UP_CHROMIUM, 0x7F,
693 GL_AFFINE_3D_CHROMIUM, kTransforms);
694 glStencilFunc(GL_LESS, 0, 0x7F);
695 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
696 glCoverFillPathInstancedCHROMIUM(kPathCount, GL_UNSIGNED_INT, kPaths,
697 path - 1,
698 GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM,
699 GL_AFFINE_3D_CHROMIUM, kTransforms);
700 glStencilFunc(GL_EQUAL, 0x80, 0x80);
701 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
702 glUniform4fv(color_loc_, 1, kGreen);
703 glCoverStrokePathInstancedCHROMIUM(kPathCount, GL_UNSIGNED_INT, kPaths,
704 path - 1,
705 GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM,
706 GL_AFFINE_3D_CHROMIUM, kTransforms);
707
708 glDeletePathsCHROMIUM(path, 1);
709
710 // Verify the image.
711 VerifyTestPatternFill(0.0f, 0.0f);
712 VerifyTestPatternBg(0.0f, 0.0f);
713 VerifyTestPatternStroke(0.0f, 0.0f);
714
715 VerifyTestPatternFill(kShapeSize, 0.0f);
716 VerifyTestPatternBg(kShapeSize, 0.0f);
717 VerifyTestPatternStroke(kShapeSize, 0.0f);
718
719 VerifyTestPatternFill(kShapeSize * 2, 0.0f);
720 VerifyTestPatternBg(kShapeSize * 2, 0.0f);
721 VerifyTestPatternStroke(kShapeSize * 2, 0.0f);
722
723 VerifyTestPatternFill(0.0f, kShapeSize);
724 VerifyTestPatternBg(0.0f, kShapeSize);
725 VerifyTestPatternStroke(0.0f, kShapeSize);
726
727 VerifyTestPatternFill(kShapeSize, kShapeSize);
728 VerifyTestPatternBg(kShapeSize, kShapeSize);
729 VerifyTestPatternStroke(kShapeSize, kShapeSize);
730 }
731
732 TEST_F(CHROMIUMPathRenderingTest, TestPathRenderingThenFunctionsInstanced) {
733 if (!GLTestHelper::HasExtension("GL_CHROMIUM_path_rendering")) {
734 return;
735 }
736 static const float kBlue[] = {0.0f, 0.0f, 1.0f, 1.0f};
737 static const float kGreen[] = {0.0f, 1.0f, 0.0f, 1.0f};
738
739 SetupStateForTestPattern();
740
741 GLuint path = glGenPathsCHROMIUM(1);
742 SetupPathStateForTestPattern(path);
743
744 const GLuint kPaths[] = {1, 1, 1, 1, 1};
745 const GLsizei kPathCount = arraysize(kPaths);
746 const GLfloat kShapeSize = 80.0f;
747 static const GLfloat kTransforms[] = {
748 0.0f, 0.0f, kShapeSize, 0.0f, kShapeSize * 2,
749 0.0f, 0.0f, kShapeSize, kShapeSize, kShapeSize,
750 };
751
752 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0xFF);
753 glStencilFunc(GL_EQUAL, 0x80, 0x80);
754 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
755 glUniform4fv(color_loc_, 1, kGreen);
756 glStencilThenCoverStrokePathInstancedCHROMIUM(
757 kPathCount, GL_UNSIGNED_INT, kPaths, path - 1, 0x80, 0x80,
758 GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM, GL_TRANSLATE_2D_CHROMIUM,
759 kTransforms);
760
761 glPathStencilFuncCHROMIUM(GL_ALWAYS, 0, 0x7F);
762 glStencilFunc(GL_LESS, 0, 0x7F);
763 glStencilOp(GL_KEEP, GL_KEEP, GL_ZERO);
764 glUniform4fv(color_loc_, 1, kBlue);
765 glStencilThenCoverFillPathInstancedCHROMIUM(
766 kPathCount, GL_UNSIGNED_INT, kPaths, path - 1, GL_COUNT_UP_CHROMIUM, 0x7F,
767 GL_BOUNDING_BOX_OF_BOUNDING_BOXES_CHROMIUM, GL_TRANSLATE_2D_CHROMIUM,
768 kTransforms);
769
770 glDeletePathsCHROMIUM(path, 1);
771
772 // Verify the image.
773 VerifyTestPatternFill(0.0f, 0.0f);
774 VerifyTestPatternBg(0.0f, 0.0f);
775 VerifyTestPatternStroke(0.0f, 0.0f);
776
777 VerifyTestPatternFill(kShapeSize, 0.0f);
778 VerifyTestPatternBg(kShapeSize, 0.0f);
779 VerifyTestPatternStroke(kShapeSize, 0.0f);
780
781 VerifyTestPatternFill(kShapeSize * 2, 0.0f);
782 VerifyTestPatternBg(kShapeSize * 2, 0.0f);
783 VerifyTestPatternStroke(kShapeSize * 2, 0.0f);
784
785 VerifyTestPatternFill(0.0f, kShapeSize);
786 VerifyTestPatternBg(0.0f, kShapeSize);
787 VerifyTestPatternStroke(0.0f, kShapeSize);
788
789 VerifyTestPatternFill(kShapeSize, kShapeSize);
790 VerifyTestPatternBg(kShapeSize, kShapeSize);
791 VerifyTestPatternStroke(kShapeSize, kShapeSize);
792 }
793
622 } // namespace gpu 794 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698