diff options
author | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-12 00:48:02 +0000 |
---|---|---|
committer | gman@chromium.org <gman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-12 00:48:02 +0000 |
commit | 38c0a9709bc84f85e6c3fb87db210dec1138204b (patch) | |
tree | ee4e7fa9c285b3f30134b0d7936d870c2f07c385 /gpu | |
parent | cd301f3cd66973509a21188947bb2ca006378ca9 (diff) | |
download | chromium_src-38c0a9709bc84f85e6c3fb87db210dec1138204b.zip chromium_src-38c0a9709bc84f85e6c3fb87db210dec1138204b.tar.gz chromium_src-38c0a9709bc84f85e6c3fb87db210dec1138204b.tar.bz2 |
Make glGenerateMipmap handle out of memory
TEST=unit tests
BUG=127590
Review URL: https://chromiumcodereview.appspot.com/10377116
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@136730 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gpu')
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder.cc | 8 | ||||
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc | 33 | ||||
-rw-r--r-- | gpu/command_buffer/service/gles2_cmd_decoder_unittest_1.cc | 4 |
3 files changed, 44 insertions, 1 deletions
diff --git a/gpu/command_buffer/service/gles2_cmd_decoder.cc b/gpu/command_buffer/service/gles2_cmd_decoder.cc index 81719d5..916d792 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder.cc @@ -3470,11 +3470,13 @@ void GLES2DecoderImpl::DoEnableVertexAttribArray(GLuint index) { void GLES2DecoderImpl::DoGenerateMipmap(GLenum target) { TextureManager::TextureInfo* info = GetTextureInfoForTarget(target); if (!info || - !texture_manager()->MarkMipmapsGenerated(info)) { + !texture_manager()->CanGenerateMipmaps(info)) { SetGLError(GL_INVALID_OPERATION, "glGenerateMipmaps: Can not generate mips"); return; } + + CopyRealGLErrorsToWrapper(); // Workaround for Mac driver bug. In the large scheme of things setting // glTexParamter twice for glGenerateMipmap is probably not a lage performance // hit so there's probably no need to make this conditional. The bug appears @@ -3488,6 +3490,10 @@ void GLES2DecoderImpl::DoGenerateMipmap(GLenum target) { if (!disable_workarounds_) { glTexParameteri(target, GL_TEXTURE_MIN_FILTER, info->min_filter()); } + GLenum error = PeekGLError(); + if (error == GL_NO_ERROR) { + texture_manager()->MarkMipmapsGenerated(info); + } } bool GLES2DecoderImpl::GetHelper( diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc index 3c20100..9627b31 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest.cc @@ -1799,6 +1799,39 @@ TEST_F(GLES2DecoderTest, GenerateMipmapWrongFormatsFails) { EXPECT_EQ(GL_INVALID_OPERATION, GetGLError()); } +TEST_F(GLES2DecoderTest, GenerateMipmapHandlesOutOfMemory) { + DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId); + TextureManager* manager = group().texture_manager(); + TextureManager::TextureInfo* info = + manager->GetTextureInfo(client_texture_id_); + ASSERT_TRUE(info != NULL); + GLint width = 0; + GLint height = 0; + EXPECT_FALSE(info->GetLevelSize(GL_TEXTURE_2D, 2, &width, &height)); + DoTexImage2D( + GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE, + 0, 0); + EXPECT_CALL(*gl_, TexParameteri( + GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST)) + .Times(1) + .RetiresOnSaturation(); + EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D)) + .Times(1); + EXPECT_CALL(*gl_, TexParameteri( + GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR)) + .Times(1) + .RetiresOnSaturation(); + EXPECT_CALL(*gl_, GetError()) + .WillOnce(Return(GL_NO_ERROR)) + .WillOnce(Return(GL_OUT_OF_MEMORY)) + .RetiresOnSaturation(); + GenerateMipmap cmd; + cmd.Init(GL_TEXTURE_2D); + EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); + EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError()); + EXPECT_FALSE(info->GetLevelSize(GL_TEXTURE_2D, 2, &width, &height)); +} + TEST_F(GLES2DecoderWithShaderTest, Uniform1iValidArgs) { EXPECT_CALL(*gl_, Uniform1i(kUniform1RealLocation, 2)); Uniform1i cmd; diff --git a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_1.cc b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_1.cc index 36cd8e2..1155bc7 100644 --- a/gpu/command_buffer/service/gles2_cmd_decoder_unittest_1.cc +++ b/gpu/command_buffer/service/gles2_cmd_decoder_unittest_1.cc @@ -48,6 +48,10 @@ void GLES2DecoderTestBase::SpecializedSetup<GenerateMipmap, 0>( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR)) .Times(1) .RetiresOnSaturation(); + EXPECT_CALL(*gl_, GetError()) + .WillOnce(Return(GL_NO_ERROR)) + .WillOnce(Return(GL_NO_ERROR)) + .RetiresOnSaturation(); } }; |