| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "cc/test/test_web_graphics_context_3d.h" | 6 #include "cc/test/test_web_graphics_context_3d.h" |
| 7 #include "gpu/GLES2/gl2extchromium.h" | 7 #include "gpu/GLES2/gl2extchromium.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" | 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/khronos/GLES2/gl2ext.h" | 10 #include "third_party/khronos/GLES2/gl2ext.h" |
| 11 | 11 |
| 12 namespace cc { | 12 namespace cc { |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 static bool check_parameter_value(TestWebGraphicsContext3D* context, | 15 static bool check_parameter_value(TestWebGraphicsContext3D* context, |
| 16 blink::WGC3Denum pname, | 16 GLenum pname, |
| 17 blink::WGC3Dint expected_value) { | 17 GLint expected_value) { |
| 18 blink::WGC3Dint actual_value = 0; | 18 GLint actual_value = 0; |
| 19 context->getTexParameteriv(GL_TEXTURE_2D, pname, &actual_value); | 19 context->getTexParameteriv(GL_TEXTURE_2D, pname, &actual_value); |
| 20 return expected_value == actual_value; | 20 return expected_value == actual_value; |
| 21 } | 21 } |
| 22 | 22 |
| 23 static void expect_default_parameter_values(TestWebGraphicsContext3D* context) { | 23 static void expect_default_parameter_values(TestWebGraphicsContext3D* context) { |
| 24 EXPECT_TRUE(check_parameter_value(context, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); | 24 EXPECT_TRUE(check_parameter_value(context, GL_TEXTURE_MAG_FILTER, GL_LINEAR)); |
| 25 EXPECT_TRUE(check_parameter_value( | 25 EXPECT_TRUE(check_parameter_value( |
| 26 context, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR)); | 26 context, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR)); |
| 27 EXPECT_TRUE(check_parameter_value(context, GL_TEXTURE_WRAP_S, GL_REPEAT)); | 27 EXPECT_TRUE(check_parameter_value(context, GL_TEXTURE_WRAP_S, GL_REPEAT)); |
| 28 EXPECT_TRUE(check_parameter_value(context, GL_TEXTURE_WRAP_T, GL_REPEAT)); | 28 EXPECT_TRUE(check_parameter_value(context, GL_TEXTURE_WRAP_T, GL_REPEAT)); |
| 29 EXPECT_TRUE(check_parameter_value( | 29 EXPECT_TRUE(check_parameter_value( |
| 30 context, GL_TEXTURE_POOL_CHROMIUM, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM)); | 30 context, GL_TEXTURE_POOL_CHROMIUM, GL_TEXTURE_POOL_UNMANAGED_CHROMIUM)); |
| 31 EXPECT_TRUE(check_parameter_value(context, GL_TEXTURE_USAGE_ANGLE, GL_NONE)); | 31 EXPECT_TRUE(check_parameter_value(context, GL_TEXTURE_USAGE_ANGLE, GL_NONE)); |
| 32 } | 32 } |
| 33 | 33 |
| 34 TEST(TestWebGraphicsContext3DTest, GetDefaultTextureParameterValues) { | 34 TEST(TestWebGraphicsContext3DTest, GetDefaultTextureParameterValues) { |
| 35 scoped_ptr<TestWebGraphicsContext3D> context( | 35 scoped_ptr<TestWebGraphicsContext3D> context( |
| 36 TestWebGraphicsContext3D::Create()); | 36 TestWebGraphicsContext3D::Create()); |
| 37 | 37 |
| 38 blink::WebGLId texture = context->createTexture(); | 38 GLuint texture = context->createTexture(); |
| 39 context->bindTexture(GL_TEXTURE_2D, texture); | 39 context->bindTexture(GL_TEXTURE_2D, texture); |
| 40 | 40 |
| 41 expect_default_parameter_values(context.get()); | 41 expect_default_parameter_values(context.get()); |
| 42 } | 42 } |
| 43 | 43 |
| 44 TEST(TestWebGraphicsContext3DTest, SetAndGetTextureParameter) { | 44 TEST(TestWebGraphicsContext3DTest, SetAndGetTextureParameter) { |
| 45 scoped_ptr<TestWebGraphicsContext3D> context( | 45 scoped_ptr<TestWebGraphicsContext3D> context( |
| 46 TestWebGraphicsContext3D::Create()); | 46 TestWebGraphicsContext3D::Create()); |
| 47 | 47 |
| 48 blink::WebGLId texture = context->createTexture(); | 48 GLuint texture = context->createTexture(); |
| 49 context->bindTexture(GL_TEXTURE_2D, texture); | 49 context->bindTexture(GL_TEXTURE_2D, texture); |
| 50 context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 50 context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 51 | 51 |
| 52 EXPECT_TRUE( | 52 EXPECT_TRUE( |
| 53 check_parameter_value(context.get(), GL_TEXTURE_MIN_FILTER, GL_NEAREST)); | 53 check_parameter_value(context.get(), GL_TEXTURE_MIN_FILTER, GL_NEAREST)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 TEST(TestWebGraphicsContext3DTest, | 56 TEST(TestWebGraphicsContext3DTest, |
| 57 SetAndGetMultipleTextureParametersOnMultipleTextures) { | 57 SetAndGetMultipleTextureParametersOnMultipleTextures) { |
| 58 scoped_ptr<TestWebGraphicsContext3D> context( | 58 scoped_ptr<TestWebGraphicsContext3D> context( |
| 59 TestWebGraphicsContext3D::Create()); | 59 TestWebGraphicsContext3D::Create()); |
| 60 | 60 |
| 61 // Set and get non-default texture parameters on the first texture. | 61 // Set and get non-default texture parameters on the first texture. |
| 62 blink::WebGLId first_texture = context->createTexture(); | 62 GLuint first_texture = context->createTexture(); |
| 63 context->bindTexture(GL_TEXTURE_2D, first_texture); | 63 context->bindTexture(GL_TEXTURE_2D, first_texture); |
| 64 context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); | 64 context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 65 context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 65 context->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 66 | 66 |
| 67 EXPECT_TRUE( | 67 EXPECT_TRUE( |
| 68 check_parameter_value(context.get(), GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 68 check_parameter_value(context.get(), GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 69 EXPECT_TRUE( | 69 EXPECT_TRUE( |
| 70 check_parameter_value(context.get(), GL_TEXTURE_MAG_FILTER, GL_NEAREST)); | 70 check_parameter_value(context.get(), GL_TEXTURE_MAG_FILTER, GL_NEAREST)); |
| 71 | 71 |
| 72 // Set and get different, non-default texture parameters on the second | 72 // Set and get different, non-default texture parameters on the second |
| 73 // texture. | 73 // texture. |
| 74 blink::WebGLId second_texture = context->createTexture(); | 74 GLuint second_texture = context->createTexture(); |
| 75 context->bindTexture(GL_TEXTURE_2D, second_texture); | 75 context->bindTexture(GL_TEXTURE_2D, second_texture); |
| 76 context->texParameteri( | 76 context->texParameteri( |
| 77 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); | 77 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST); |
| 78 context->texParameteri( | 78 context->texParameteri( |
| 79 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); | 79 GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); |
| 80 | 80 |
| 81 EXPECT_TRUE(check_parameter_value( | 81 EXPECT_TRUE(check_parameter_value( |
| 82 context.get(), GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST)); | 82 context.get(), GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST)); |
| 83 EXPECT_TRUE(check_parameter_value( | 83 EXPECT_TRUE(check_parameter_value( |
| 84 context.get(), GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR)); | 84 context.get(), GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR)); |
| 85 | 85 |
| 86 // Get texture parameters on the first texture and verify they are still | 86 // Get texture parameters on the first texture and verify they are still |
| 87 // intact. | 87 // intact. |
| 88 context->bindTexture(GL_TEXTURE_2D, first_texture); | 88 context->bindTexture(GL_TEXTURE_2D, first_texture); |
| 89 | 89 |
| 90 EXPECT_TRUE( | 90 EXPECT_TRUE( |
| 91 check_parameter_value(context.get(), GL_TEXTURE_MIN_FILTER, GL_LINEAR)); | 91 check_parameter_value(context.get(), GL_TEXTURE_MIN_FILTER, GL_LINEAR)); |
| 92 EXPECT_TRUE( | 92 EXPECT_TRUE( |
| 93 check_parameter_value(context.get(), GL_TEXTURE_MAG_FILTER, GL_NEAREST)); | 93 check_parameter_value(context.get(), GL_TEXTURE_MAG_FILTER, GL_NEAREST)); |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace | 96 } // namespace |
| 97 } // namespace cc | 97 } // namespace cc |
| OLD | NEW |