OLD | NEW |
(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 "gpu/command_buffer/service/gles2_cmd_decoder.h" |
| 6 |
| 7 #include "base/command_line.h" |
| 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 10 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 11 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
| 12 #include "gpu/command_buffer/service/context_group.h" |
| 13 #include "gpu/command_buffer/service/gl_surface_mock.h" |
| 14 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h" |
| 15 #include "gpu/command_buffer/service/gpu_switches.h" |
| 16 #include "gpu/command_buffer/service/mocks.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "ui/gl/gl_mock.h" |
| 19 |
| 20 using ::gfx::MockGLInterface; |
| 21 using ::testing::_; |
| 22 using ::testing::DoAll; |
| 23 using ::testing::InSequence; |
| 24 using ::testing::Invoke; |
| 25 using ::testing::MatcherCast; |
| 26 using ::testing::Mock; |
| 27 using ::testing::Pointee; |
| 28 using ::testing::Return; |
| 29 using ::testing::SaveArg; |
| 30 using ::testing::SetArrayArgument; |
| 31 using ::testing::SetArgumentPointee; |
| 32 using ::testing::SetArgPointee; |
| 33 using ::testing::StrEq; |
| 34 using ::testing::StrictMock; |
| 35 |
| 36 namespace gpu { |
| 37 namespace gles2 { |
| 38 |
| 39 using namespace cmds; |
| 40 |
| 41 class GLES2DecoderDrawOOMTest : public GLES2DecoderManualInitTest { |
| 42 protected: |
| 43 void Init(bool has_robustness) { |
| 44 InitState init; |
| 45 init.lose_context_when_out_of_memory = true; |
| 46 if (has_robustness) |
| 47 init.extensions = "GL_ARB_robustness"; |
| 48 InitDecoder(init); |
| 49 SetupDefaultProgram(); |
| 50 } |
| 51 |
| 52 void Draw(GLenum reset_status, |
| 53 error::ContextLostReason expected_other_reason) { |
| 54 const GLsizei kFakeLargeCount = 0x1234; |
| 55 SetupTexture(); |
| 56 if (context_->WasAllocatedUsingRobustnessExtension()) { |
| 57 EXPECT_CALL(*gl_, GetGraphicsResetStatusARB()) |
| 58 .WillOnce(Return(reset_status)); |
| 59 } |
| 60 AddExpectationsForSimulatedAttrib0WithError(kFakeLargeCount, 0, |
| 61 GL_OUT_OF_MEMORY); |
| 62 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0).RetiresOnSaturation(); |
| 63 // Other contexts in the group should be lost also. |
| 64 EXPECT_CALL(*mock_decoder_, MarkContextLost(expected_other_reason)) |
| 65 .Times(1) |
| 66 .RetiresOnSaturation(); |
| 67 DrawArrays cmd; |
| 68 cmd.Init(GL_TRIANGLES, 0, kFakeLargeCount); |
| 69 EXPECT_EQ(error::kLostContext, ExecuteCmd(cmd)); |
| 70 } |
| 71 }; |
| 72 |
| 73 // Test that we lose context. |
| 74 TEST_P(GLES2DecoderDrawOOMTest, ContextLostReasonOOM) { |
| 75 Init(false); // without robustness |
| 76 const error::ContextLostReason expected_reason_for_other_contexts = |
| 77 error::kOutOfMemory; |
| 78 Draw(GL_NO_ERROR, expected_reason_for_other_contexts); |
| 79 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); |
| 80 EXPECT_TRUE(decoder_->WasContextLost()); |
| 81 EXPECT_EQ(error::kOutOfMemory, decoder_->GetContextLostReason()); |
| 82 } |
| 83 |
| 84 TEST_P(GLES2DecoderDrawOOMTest, ContextLostReasonWhenStatusIsNoError) { |
| 85 Init(true); // with robustness |
| 86 // If the reset status is NO_ERROR, we should be signaling kOutOfMemory. |
| 87 const error::ContextLostReason expected_reason_for_other_contexts = |
| 88 error::kOutOfMemory; |
| 89 Draw(GL_NO_ERROR, expected_reason_for_other_contexts); |
| 90 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); |
| 91 EXPECT_TRUE(decoder_->WasContextLost()); |
| 92 EXPECT_EQ(error::kOutOfMemory, decoder_->GetContextLostReason()); |
| 93 } |
| 94 |
| 95 TEST_P(GLES2DecoderDrawOOMTest, ContextLostReasonWhenStatusIsGuilty) { |
| 96 Init(true); |
| 97 // If there was a reset, it should override kOutOfMemory. |
| 98 const error::ContextLostReason expected_reason_for_other_contexts = |
| 99 error::kUnknown; |
| 100 Draw(GL_GUILTY_CONTEXT_RESET_ARB, expected_reason_for_other_contexts); |
| 101 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); |
| 102 EXPECT_TRUE(decoder_->WasContextLost()); |
| 103 EXPECT_EQ(error::kGuilty, decoder_->GetContextLostReason()); |
| 104 } |
| 105 |
| 106 TEST_P(GLES2DecoderDrawOOMTest, ContextLostReasonWhenStatusIsUnknown) { |
| 107 Init(true); |
| 108 // If there was a reset, it should override kOutOfMemory. |
| 109 const error::ContextLostReason expected_reason_for_other_contexts = |
| 110 error::kUnknown; |
| 111 Draw(GL_UNKNOWN_CONTEXT_RESET_ARB, expected_reason_for_other_contexts); |
| 112 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); |
| 113 EXPECT_TRUE(decoder_->WasContextLost()); |
| 114 EXPECT_EQ(error::kUnknown, decoder_->GetContextLostReason()); |
| 115 } |
| 116 |
| 117 INSTANTIATE_TEST_CASE_P(Service, GLES2DecoderDrawOOMTest, ::testing::Bool()); |
| 118 |
| 119 class GLES2DecoderLostContextTest : public GLES2DecoderManualInitTest { |
| 120 protected: |
| 121 void Init(bool has_robustness) { |
| 122 InitState init; |
| 123 init.gl_version = "opengl es 2.0"; |
| 124 if (has_robustness) |
| 125 init.extensions = "GL_KHR_robustness"; |
| 126 InitDecoder(init); |
| 127 } |
| 128 |
| 129 void InitWithVirtualContextsAndRobustness() { |
| 130 base::CommandLine command_line(0, NULL); |
| 131 command_line.AppendSwitchASCII( |
| 132 switches::kGpuDriverBugWorkarounds, |
| 133 base::IntToString(USE_VIRTUALIZED_GL_CONTEXTS)); |
| 134 InitState init; |
| 135 init.gl_version = "opengl es 2.0"; |
| 136 init.extensions = "GL_KHR_robustness"; |
| 137 InitDecoderWithCommandLine(init, &command_line); |
| 138 } |
| 139 |
| 140 void DoGetErrorWithContextLost(GLenum reset_status) { |
| 141 DCHECK(context_->HasExtension("GL_KHR_robustness")); |
| 142 EXPECT_CALL(*gl_, GetError()) |
| 143 .WillOnce(Return(GL_CONTEXT_LOST_KHR)) |
| 144 .RetiresOnSaturation(); |
| 145 EXPECT_CALL(*gl_, GetGraphicsResetStatusARB()) |
| 146 .WillOnce(Return(reset_status)); |
| 147 cmds::GetError cmd; |
| 148 cmd.Init(shared_memory_id_, shared_memory_offset_); |
| 149 EXPECT_EQ(error::kLostContext, ExecuteCmd(cmd)); |
| 150 EXPECT_EQ(static_cast<GLuint>(GL_NO_ERROR), *GetSharedMemoryAs<GLenum*>()); |
| 151 } |
| 152 |
| 153 void ClearCurrentDecoderError() { |
| 154 DCHECK(decoder_->WasContextLost()); |
| 155 EXPECT_CALL(*gl_, GetError()) |
| 156 .WillOnce(Return(GL_CONTEXT_LOST_KHR)) |
| 157 .RetiresOnSaturation(); |
| 158 cmds::GetError cmd; |
| 159 cmd.Init(shared_memory_id_, shared_memory_offset_); |
| 160 EXPECT_EQ(error::kLostContext, ExecuteCmd(cmd)); |
| 161 } |
| 162 }; |
| 163 |
| 164 TEST_P(GLES2DecoderLostContextTest, LostFromMakeCurrent) { |
| 165 Init(false); // without robustness |
| 166 EXPECT_CALL(*context_, MakeCurrent(surface_.get())).WillOnce(Return(false)); |
| 167 // Expect the group to be lost. |
| 168 EXPECT_CALL(*mock_decoder_, MarkContextLost(error::kUnknown)).Times(1); |
| 169 decoder_->MakeCurrent(); |
| 170 EXPECT_TRUE(decoder_->WasContextLost()); |
| 171 EXPECT_EQ(error::kMakeCurrentFailed, decoder_->GetContextLostReason()); |
| 172 |
| 173 // We didn't process commands, so we need to clear the decoder error, |
| 174 // so that we can shut down cleanly. |
| 175 ClearCurrentDecoderError(); |
| 176 } |
| 177 |
| 178 TEST_P(GLES2DecoderLostContextTest, LostFromMakeCurrentWithRobustness) { |
| 179 Init(true); // with robustness |
| 180 // If we can't make the context current, we cannot query the robustness |
| 181 // extension. |
| 182 EXPECT_CALL(*gl_, GetGraphicsResetStatusARB()).Times(0); |
| 183 EXPECT_CALL(*context_, MakeCurrent(surface_.get())).WillOnce(Return(false)); |
| 184 // Expect the group to be lost. |
| 185 EXPECT_CALL(*mock_decoder_, MarkContextLost(error::kUnknown)).Times(1); |
| 186 decoder_->MakeCurrent(); |
| 187 EXPECT_TRUE(decoder_->WasContextLost()); |
| 188 EXPECT_FALSE(decoder_->WasContextLostByRobustnessExtension()); |
| 189 EXPECT_EQ(error::kMakeCurrentFailed, decoder_->GetContextLostReason()); |
| 190 |
| 191 // We didn't process commands, so we need to clear the decoder error, |
| 192 // so that we can shut down cleanly. |
| 193 ClearCurrentDecoderError(); |
| 194 } |
| 195 |
| 196 TEST_P(GLES2DecoderLostContextTest, LostFromResetAfterMakeCurrent) { |
| 197 Init(true); // with robustness |
| 198 InSequence seq; |
| 199 EXPECT_CALL(*context_, MakeCurrent(surface_.get())).WillOnce(Return(true)); |
| 200 EXPECT_CALL(*gl_, GetGraphicsResetStatusARB()) |
| 201 .WillOnce(Return(GL_GUILTY_CONTEXT_RESET_KHR)); |
| 202 // Expect the group to be lost. |
| 203 EXPECT_CALL(*mock_decoder_, MarkContextLost(error::kUnknown)).Times(1); |
| 204 decoder_->MakeCurrent(); |
| 205 EXPECT_TRUE(decoder_->WasContextLost()); |
| 206 EXPECT_TRUE(decoder_->WasContextLostByRobustnessExtension()); |
| 207 EXPECT_EQ(error::kGuilty, decoder_->GetContextLostReason()); |
| 208 |
| 209 // We didn't process commands, so we need to clear the decoder error, |
| 210 // so that we can shut down cleanly. |
| 211 ClearCurrentDecoderError(); |
| 212 } |
| 213 |
| 214 TEST_P(GLES2DecoderLostContextTest, LoseGuiltyFromGLError) { |
| 215 Init(true); |
| 216 // Always expect other contexts to be signaled as 'kUnknown' since we can't |
| 217 // query their status without making them current. |
| 218 EXPECT_CALL(*mock_decoder_, MarkContextLost(error::kUnknown)) |
| 219 .Times(1); |
| 220 DoGetErrorWithContextLost(GL_GUILTY_CONTEXT_RESET_KHR); |
| 221 EXPECT_TRUE(decoder_->WasContextLost()); |
| 222 EXPECT_TRUE(decoder_->WasContextLostByRobustnessExtension()); |
| 223 EXPECT_EQ(error::kGuilty, decoder_->GetContextLostReason()); |
| 224 } |
| 225 |
| 226 TEST_P(GLES2DecoderLostContextTest, LoseInnocentFromGLError) { |
| 227 Init(true); |
| 228 // Always expect other contexts to be signaled as 'kUnknown' since we can't |
| 229 // query their status without making them current. |
| 230 EXPECT_CALL(*mock_decoder_, MarkContextLost(error::kUnknown)) |
| 231 .Times(1); |
| 232 DoGetErrorWithContextLost(GL_INNOCENT_CONTEXT_RESET_KHR); |
| 233 EXPECT_TRUE(decoder_->WasContextLost()); |
| 234 EXPECT_TRUE(decoder_->WasContextLostByRobustnessExtension()); |
| 235 EXPECT_EQ(error::kInnocent, decoder_->GetContextLostReason()); |
| 236 } |
| 237 |
| 238 TEST_P(GLES2DecoderLostContextTest, LoseVirtualContextWithRobustness) { |
| 239 InitWithVirtualContextsAndRobustness(); |
| 240 EXPECT_CALL(*mock_decoder_, MarkContextLost(error::kUnknown)) |
| 241 .Times(1); |
| 242 // Signal guilty.... |
| 243 DoGetErrorWithContextLost(GL_GUILTY_CONTEXT_RESET_KHR); |
| 244 EXPECT_TRUE(decoder_->WasContextLost()); |
| 245 EXPECT_TRUE(decoder_->WasContextLostByRobustnessExtension()); |
| 246 // ...but make sure we don't pretend, since for virtual contexts we don't |
| 247 // know if this was really the guilty client. |
| 248 EXPECT_EQ(error::kUnknown, decoder_->GetContextLostReason()); |
| 249 } |
| 250 |
| 251 TEST_P(GLES2DecoderLostContextTest, LoseGroupFromRobustness) { |
| 252 // If one context in a group is lost through robustness, |
| 253 // the other ones should also get lost and query the reset status. |
| 254 Init(true); |
| 255 EXPECT_CALL(*mock_decoder_, MarkContextLost(error::kUnknown)) |
| 256 .Times(1); |
| 257 // There should be no GL calls, since we might not have a current context. |
| 258 EXPECT_CALL(*gl_, GetGraphicsResetStatusARB()).Times(0); |
| 259 LoseContexts(error::kUnknown); |
| 260 EXPECT_TRUE(decoder_->WasContextLost()); |
| 261 EXPECT_EQ(error::kUnknown, decoder_->GetContextLostReason()); |
| 262 |
| 263 // We didn't process commands, so we need to clear the decoder error, |
| 264 // so that we can shut down cleanly. |
| 265 ClearCurrentDecoderError(); |
| 266 } |
| 267 |
| 268 INSTANTIATE_TEST_CASE_P(Service, |
| 269 GLES2DecoderLostContextTest, |
| 270 ::testing::Bool()); |
| 271 |
| 272 } // namespace gles2 |
| 273 } // namespace gpu |
OLD | NEW |