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

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

Issue 2145643004: Fix preserve backbuffer with native GMBs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « gpu/command_buffer/tests/gl_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 8
9 #include "gpu/command_buffer/client/gles2_lib.h" 9 #include "gpu/command_buffer/client/gles2_lib.h"
10 #include "gpu/command_buffer/service/image_factory.h" 10 #include "gpu/command_buffer/service/image_factory.h"
11 #include "gpu/command_buffer/tests/gl_manager.h" 11 #include "gpu/command_buffer/tests/gl_manager.h"
12 #include "gpu/command_buffer/tests/gl_test_utils.h" 12 #include "gpu/command_buffer/tests/gl_test_utils.h"
13 #include "gpu/command_buffer/tests/texture_image_factory.h" 13 #include "gpu/command_buffer/tests/texture_image_factory.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "ui/gl/gl_context.h" 15 #include "ui/gl/gl_context.h"
16 #include "ui/gl/gl_image.h" 16 #include "ui/gl/gl_image.h"
17 17
18 #if defined(OS_MACOSX)
19 #include "gpu/ipc/service/gpu_memory_buffer_factory_io_surface.h"
20 #endif
21
18 namespace gpu { 22 namespace gpu {
19 23
20 class GLNativeGMBTest : public testing::Test { 24 class GLNativeGMBTest : public testing::Test {
21 protected: 25 protected:
22 void SetUp() override { 26 void SetUp() override {
23 gl_.Initialize(GLManager::Options()); 27 gl_.Initialize(GLManager::Options());
24 image_factory_.SetRequiredTextureType(GL_TEXTURE_RECTANGLE_ARB);
25 } 28 }
26 29
27 void TearDown() override { 30 void TearDown() override {
28 gl_.Destroy(); 31 gl_.Destroy();
29 } 32 }
30 33
34 // Runs a simple battery of tests.
35 void RunBackbufferTestWithOptions(const GLManager::Options& options) {
36 GLManager gl;
37 gl.Initialize(options);
38 gl.MakeCurrent();
39
40 // Clear the back buffer and check that it has the right values.
41 glClearColor(0.0f, 0.25f, 0.5f, 0.7f);
42 glClear(GL_COLOR_BUFFER_BIT);
43 uint8_t pixel[4];
44 memset(pixel, 0, 4);
45 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
46 EXPECT_NEAR(0u, pixel[0], 2);
47 EXPECT_NEAR(64u, pixel[1], 2);
48 EXPECT_NEAR(127u, pixel[2], 2);
49 uint8_t alpha = options.backbuffer_alpha ? 178 : 255;
50 EXPECT_NEAR(alpha, pixel[3], 2);
51
52 // Resize, then clear the back buffer and check its contents.
53 glResizeCHROMIUM(10, 10, 1, true);
54 glClearColor(0.5f, 0.6f, 0.7f, 0.8f);
55 glClear(GL_COLOR_BUFFER_BIT);
56 memset(pixel, 0, 4);
57 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
58 EXPECT_NEAR(128u, pixel[0], 2);
59 EXPECT_NEAR(153u, pixel[1], 2);
60 EXPECT_NEAR(178u, pixel[2], 2);
61 uint8_t alpha2 = options.backbuffer_alpha ? 204 : 255;
62 EXPECT_NEAR(alpha2, pixel[3], 2);
63
64 // Swap buffers, then clear the back buffer and check its contents.
65 ::gles2::GetGLContext()->SwapBuffers();
66 glClearColor(0.1f, 0.2f, 0.3f, 0.4f);
67 glClear(GL_COLOR_BUFFER_BIT);
68 memset(pixel, 0, 4);
69 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
70 EXPECT_NEAR(25u, pixel[0], 2);
71 EXPECT_NEAR(51u, pixel[1], 2);
72 EXPECT_NEAR(76u, pixel[2], 2);
73 uint8_t alpha3 = options.backbuffer_alpha ? 102 : 255;
74 EXPECT_NEAR(alpha3, pixel[3], 2);
75
76 gl.Destroy();
77 }
78
31 GLManager gl_; 79 GLManager gl_;
32 TextureImageFactory image_factory_;
33 }; 80 };
34 81
35 TEST_F(GLNativeGMBTest, TestNativeGMBBackbufferWithDifferentConfigurations) { 82 TEST_F(GLNativeGMBTest, TestNativeGMBBackbufferWithDifferentConfigurations) {
36 if (!GLTestHelper::HasExtension("GL_ARB_texture_rectangle")) { 83 if (!GLTestHelper::HasExtension("GL_ARB_texture_rectangle")) {
37 LOG(INFO) << "GL_ARB_texture_rectangle not supported. Skipping test..."; 84 LOG(INFO) << "GL_ARB_texture_rectangle not supported. Skipping test...";
38 return; 85 return;
39 } 86 }
87 #if defined(OS_MACOSX)
88 GpuMemoryBufferFactoryIOSurface image_factory;
89 #else
90 TextureImageFactory image_factory;
91 image_factory.SetRequiredTextureType(GL_TEXTURE_RECTANGLE_ARB);
92 #endif
40 93
41 for (int has_alpha = 0; has_alpha <= 1; ++has_alpha) { 94 for (int has_alpha = 0; has_alpha <= 1; ++has_alpha) {
42 for (int msaa = 0; msaa <= 1; ++msaa) { 95 for (int msaa = 0; msaa <= 1; ++msaa) {
43 GLManager::Options options; 96 for (int preserve_backbuffer = 0; preserve_backbuffer <= 1;
44 options.image_factory = &image_factory_; 97 ++preserve_backbuffer) {
45 options.multisampled = msaa == 1; 98 GLManager::Options options;
46 options.backbuffer_alpha = has_alpha == 1; 99 options.image_factory = &image_factory;
100 options.multisampled = msaa == 1;
101 options.backbuffer_alpha = has_alpha == 1;
102 options.preserve_backbuffer = preserve_backbuffer;
47 103
48 GLManager gl; 104 RunBackbufferTestWithOptions(options);
49 gl.Initialize(options); 105 }
50 gl.MakeCurrent();
51
52 // Clear the back buffer and check that it has the right values.
53 glClearColor(0.0f, 0.25f, 0.5f, 0.7f);
54 glClear(GL_COLOR_BUFFER_BIT);
55 uint8_t pixel[4];
56 memset(pixel, 0, 4);
57 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
58 EXPECT_NEAR(0u, pixel[0], 2);
59 EXPECT_NEAR(64u, pixel[1], 2);
60 EXPECT_NEAR(127u, pixel[2], 2);
61 uint8_t alpha = has_alpha ? 178 : 255;
62 EXPECT_NEAR(alpha, pixel[3], 2);
63
64 // Resize, then clear the back buffer and check its contents.
65 glResizeCHROMIUM(10, 10, 1, true);
66 glClearColor(0.5f, 0.6f, 0.7f, 0.8f);
67 glClear(GL_COLOR_BUFFER_BIT);
68 memset(pixel, 0, 4);
69 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
70 EXPECT_NEAR(128u, pixel[0], 2);
71 EXPECT_NEAR(153u, pixel[1], 2);
72 EXPECT_NEAR(178u, pixel[2], 2);
73 uint8_t alpha2 = has_alpha ? 204 : 255;
74 EXPECT_NEAR(alpha2, pixel[3], 2);
75
76 // Swap buffers, then clear the back buffer and check its contents.
77 ::gles2::GetGLContext()->SwapBuffers();
78 glClearColor(0.1f, 0.2f, 0.3f, 0.4f);
79 glClear(GL_COLOR_BUFFER_BIT);
80 memset(pixel, 0, 4);
81 glReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &pixel);
82 EXPECT_NEAR(25u, pixel[0], 2);
83 EXPECT_NEAR(51u, pixel[1], 2);
84 EXPECT_NEAR(76u, pixel[2], 2);
85 uint8_t alpha3 = has_alpha ? 102 : 255;
86 EXPECT_NEAR(alpha3, pixel[3], 2);
87
88 gl.Destroy();
89 } 106 }
90 } 107 }
91 } 108 }
92 109
93 } // namespace gpu 110 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/tests/gl_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698