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

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

Issue 1286193008: Reland of "gpu: workaround force_cube_map_positive_x_allocation fixes Android crash." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nvidia failure on mac and android Created 5 years, 4 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <GLES2/gl2.h>
6
7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "gpu/command_buffer/tests/gl_manager.h"
10 #include "gpu/command_buffer/tests/gl_test_utils.h"
11 #include "gpu/config/gpu_switches.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace gpu {
15
16 namespace {
17 const GLenum kCubeMapTextureTargets[] = {
18 GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
19 GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
20 GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
21 };
22 } // namespace
23
24 // A collection of tests that exercise the cube map texture.
25 class GLCubeMapTextureTest : public testing::TestWithParam<GLenum> {
26 protected:
27 void SetUp() override {
28 base::CommandLine command_line(base::CommandLine::NO_PROGRAM);
29 // ANGLE and NVidia fails ReadPixelsFromIncompleteCubeTexture without this
30 // workaround.
31 command_line.AppendSwitchASCII(switches::kGpuDriverBugWorkarounds,
32 base::IntToString(gpu::FORCE_CUBE_COMPLETE));
33 gl_.InitializeWithCommandLine(GLManager::Options(), &command_line);
34 DCHECK(gl_.workarounds().force_cube_complete);
35 for (int i = 0; i < 256; i++) {
36 pixels_[i * 4] = 255u;
37 pixels_[(i * 4) + 1] = 0;
38 pixels_[(i * 4) + 2] = 0;
39 pixels_[(i * 4) + 3] = 255u;
40 }
41
42 glGenTextures(1, &texture_);
43 glBindTexture(GL_TEXTURE_CUBE_MAP, texture_);
44 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
45
46 glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
47 glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
48 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
49 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
50 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
51
52 glGenFramebuffers(1, &framebuffer_id_);
53 }
54
55 void TearDown() override {
56 glDeleteTextures(1, &texture_);
57 glDeleteFramebuffers(1, &framebuffer_id_);
58 gl_.Destroy();
59 }
60
61 GLManager gl_;
62 uint8 pixels_[256 * 4];
63 const int width_ = 16;
64 GLuint texture_;
65 GLuint framebuffer_id_;
66 };
67
68 INSTANTIATE_TEST_CASE_P(GLCubeMapTextureTests,
69 GLCubeMapTextureTest,
70 ::testing::ValuesIn(kCubeMapTextureTargets));
71
72 TEST_P(GLCubeMapTextureTest, TexImage2DAfterFBOBinding) {
73 GLenum cube_map_target = GetParam();
74
75 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_);
76 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cube_map_target,
77 texture_, 0);
78 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
79
80 glBindTexture(GL_TEXTURE_CUBE_MAP, texture_);
81 // force_gl_finish_after_compositing workaround prevents Nexus 5 crash.
82 // TODO(dshwang): remove the workaround when it's fixed. crbug.com/518889
83 glTexImage2D(cube_map_target, 0, GL_RGBA, width_, width_, 0, GL_RGBA,
84 GL_UNSIGNED_BYTE, pixels_);
85 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
86 }
87
88 TEST_P(GLCubeMapTextureTest, ReadPixels) {
89 GLenum cube_map_target = GetParam();
90
91 glBindTexture(GL_TEXTURE_CUBE_MAP, texture_);
92 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
93
94 // Make a cube texture complete
95 for (unsigned i = 0; i < arraysize(kCubeMapTextureTargets); i++) {
96 glTexImage2D(kCubeMapTextureTargets[i], 0, GL_RGBA, width_, width_, 0,
97 GL_RGBA, GL_UNSIGNED_BYTE, pixels_);
98 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
99 }
100
101 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_);
102 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cube_map_target,
103 texture_, 0);
104 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
105
106 // Check that FB is complete.
107 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
108 glCheckFramebufferStatus(GL_FRAMEBUFFER));
109
110 GLTestHelper::CheckPixels(0, 0, width_, width_, 0, pixels_);
111 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
112 }
113
114 TEST_P(GLCubeMapTextureTest, ReadPixelsFromIncompleteCubeTexture) {
115 GLenum cube_map_target = GetParam();
116
117 glBindTexture(GL_TEXTURE_CUBE_MAP, texture_);
118 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
119
120 glTexImage2D(cube_map_target, 0, GL_RGBA, width_, width_, 0, GL_RGBA,
121 GL_UNSIGNED_BYTE, pixels_);
122 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
123
124 glBindFramebuffer(GL_FRAMEBUFFER, framebuffer_id_);
125 glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cube_map_target,
126 texture_, 0);
127
128 // force_gl_finish_after_compositing workaround prevents Nexus 5 crash.
129 // TODO(dshwang): remove the workaround when it's fixed. crbug.com/518889
130 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
131
132 // Check that FB is complete.
133 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE),
134 glCheckFramebufferStatus(GL_FRAMEBUFFER));
135 // Without force_cube_complete workaround,
136 // 1. ANGLE crashes on glReadPixels() from incomplete cube texture.
137 // 2. NVidia fails on glReadPixels() from incomplete cube texture.
138 GLTestHelper::CheckPixels(0, 0, width_, width_, 0, pixels_);
139 EXPECT_EQ(static_cast<GLenum>(GL_NO_ERROR), glGetError());
140 }
141
142 } // namespace gpu
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698