blob: 29aa110ad790cd3c17128d0165e42bf8b1c21a8a [file] [log] [blame]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gpu/command_buffer/service/gles2_cmd_decoder.h"
#include <stddef.h>
#include <stdint.h>
#include "base/command_line.h"
#include "base/strings/string_number_conversions.h"
#include "gpu/command_buffer/common/gles2_cmd_format.h"
#include "gpu/command_buffer/common/gles2_cmd_utils.h"
#include "gpu/command_buffer/common/id_allocator.h"
#include "gpu/command_buffer/service/context_group.h"
#include "gpu/command_buffer/service/context_state.h"
#include "gpu/command_buffer/service/gl_surface_mock.h"
#include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
#include "gpu/command_buffer/service/image_manager.h"
#include "gpu/command_buffer/service/mailbox_manager.h"
#include "gpu/command_buffer/service/mocks.h"
#include "gpu/command_buffer/service/program_manager.h"
#include "gpu/command_buffer/service/service_discardable_manager.h"
#include "gpu/command_buffer/service/shared_image_representation.h"
#include "gpu/command_buffer/service/test_helper.h"
#include "gpu/config/gpu_switches.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gl/gl_image_stub.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/gl_mock.h"
#include "ui/gl/gl_surface_stub.h"
#if !defined(GL_DEPTH24_STENCIL8)
#define GL_DEPTH24_STENCIL8 0x88F0
#endif
using ::gl::MockGLInterface;
using ::testing::_;
using ::testing::AnyNumber;
using ::testing::DoAll;
using ::testing::InSequence;
using ::testing::Invoke;
using ::testing::MatcherCast;
using ::testing::Mock;
using ::testing::Pointee;
using ::testing::Return;
using ::testing::SaveArg;
using ::testing::SetArrayArgument;
using ::testing::SetArgPointee;
using ::testing::SetArgPointee;
using ::testing::StrEq;
using ::testing::StrictMock;
namespace {
class EmulatingRGBImageStub : public gl::GLImageStub {
protected:
~EmulatingRGBImageStub() override = default;
bool EmulatingRGB() const override {
return true;
}
};
} // namespace
namespace gpu {
namespace gles2 {
using namespace cmds;
TEST_P(GLES2DecoderTest, GenerateMipmapWrongFormatsFails) {
EXPECT_CALL(*gl_, GenerateMipmapEXT(_)).Times(0);
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
DoTexImage2D(
GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
GenerateMipmap cmd;
cmd.Init(GL_TEXTURE_2D);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
}
TEST_P(GLES2DecoderTest, GenerateMipmapHandlesOutOfMemory) {
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
TextureManager* manager = group().texture_manager();
TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
ASSERT_TRUE(texture_ref != nullptr);
Texture* texture = texture_ref->texture();
GLint width = 0;
GLint height = 0;
EXPECT_FALSE(
texture->GetLevelSize(GL_TEXTURE_2D, 2, &width, &height, nullptr));
DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
shared_memory_id_, kSharedMemoryOffset);
EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D)).Times(1);
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(
texture->GetLevelSize(GL_TEXTURE_2D, 2, &width, &height, nullptr));
}
TEST_P(GLES2DecoderTest, GenerateMipmapClearsUnclearedTexture) {
EXPECT_CALL(*gl_, GenerateMipmapEXT(_)).Times(0);
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
DoTexImage2D(
GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
SetupClearTextureExpectations(kServiceTextureId, kServiceTextureId,
GL_TEXTURE_2D, GL_TEXTURE_2D, 0, GL_RGBA,
GL_UNSIGNED_BYTE, 0, 0, 2, 2, 0);
EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D));
EXPECT_CALL(*gl_, GetError())
.WillOnce(Return(GL_NO_ERROR))
.WillOnce(Return(GL_NO_ERROR))
.RetiresOnSaturation();
GenerateMipmap cmd;
cmd.Init(GL_TEXTURE_2D);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
TEST_P(GLES3DecoderTest, GenerateMipmapBaseLevel) {
EXPECT_CALL(*gl_, GenerateMipmapEXT(_)).Times(0);
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
DoTexImage2D(
GL_TEXTURE_2D, 2, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
{
EXPECT_CALL(*gl_, TexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2));
TexParameteri cmd;
cmd.Init(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 2);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
SetupClearTextureExpectations(kServiceTextureId, kServiceTextureId,
GL_TEXTURE_2D, GL_TEXTURE_2D, 2, GL_RGBA,
GL_UNSIGNED_BYTE, 0, 0, 2, 2, 0);
EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D));
EXPECT_CALL(*gl_, GetError())
.WillOnce(Return(GL_NO_ERROR))
.WillOnce(Return(GL_NO_ERROR))
.RetiresOnSaturation();
GenerateMipmap cmd;
cmd.Init(GL_TEXTURE_2D);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
TEST_P(GLES2DecoderTest, ActiveTextureValidArgs) {
EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
SpecializedSetup<ActiveTexture, 0>(true);
ActiveTexture cmd;
cmd.Init(GL_TEXTURE1);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
TEST_P(GLES2DecoderTest, ActiveTextureInvalidArgs) {
EXPECT_CALL(*gl_, ActiveTexture(_)).Times(0);
SpecializedSetup<ActiveTexture, 0>(false);
ActiveTexture cmd;
cmd.Init(GL_TEXTURE0 - 1);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
cmd.Init(kNumTextureUnits);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
}
TEST_P(GLES2DecoderTest, TexSubImage2DValidArgs) {
const int kWidth = 16;
const int kHeight = 8;
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
DoTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, kWidth, kHeight, 0, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset);
EXPECT_CALL(*gl_,
TexSubImage2D(GL_TEXTURE_2D,
1,
1,
0,
kWidth - 1,
kHeight,
GL_RGBA,
GL_UNSIGNED_BYTE,
shared_memory_address_))
.Times(1)
.RetiresOnSaturation();
TexSubImage2D cmd;
cmd.Init(GL_TEXTURE_2D, 1, 1, 0, kWidth - 1, kHeight, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// 0 size with null SHM
EXPECT_CALL(*gl_, TexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, GL_RGBA,
GL_UNSIGNED_BYTE, nullptr))
.Times(1)
.RetiresOnSaturation();
cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0,
GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
TEST_P(GLES2DecoderTest, TexSubImage2DBadArgs) {
const int kWidth = 8;
const int kHeight = 4;
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
DoTexImage2D(GL_TEXTURE_2D,
1,
GL_RGBA,
kWidth,
kHeight,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
0,
0);
TexSubImage2D cmd;
// Invalid target.
cmd.Init(GL_TEXTURE0, 1, 0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
// Invalid format / type.
cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth, kHeight, GL_TRUE, GL_UNSIGNED_BYTE,
shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_INT,
shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
// Invalid offsets/sizes.
cmd.Init(GL_TEXTURE_2D, 1, -1, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_2D, 1, 1, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_2D, 1, 0, -1, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_2D, 1, 0, 1, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth + 1, kHeight, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth, kHeight + 1, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
// Incompatible format / type.
cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth, kHeight, GL_RGB, GL_UNSIGNED_BYTE,
shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth, kHeight, GL_RGBA,
GL_UNSIGNED_SHORT_4_4_4_4, shared_memory_id_, kSharedMemoryOffset,
GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// Above errors should still happen with NULL data.
cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_INT, 0,
0, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
cmd.Init(GL_TEXTURE_2D, 1, 0, -1, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
0, 0, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth + 1, kHeight, GL_RGBA,
GL_UNSIGNED_BYTE, 0, 0, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
// Invalid SHM / offset.
cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
kInvalidSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
shared_memory_id_, kInvalidSharedMemoryOffset, GL_FALSE);
EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
0, 0, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
}
TEST_P(GLES3DecoderTest, TexSubImage3DValidArgs) {
const int kWidth = 8;
const int kHeight = 4;
const int kDepth = 2;
DoBindTexture(GL_TEXTURE_3D, client_texture_id_, kServiceTextureId);
DoTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA, kWidth, kHeight, kDepth, 0, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset);
EXPECT_CALL(*gl_,
TexSubImage3DWithData(GL_TEXTURE_3D, 1, 1, 0, 0, kWidth - 1,
kHeight, kDepth, GL_RGBA, GL_UNSIGNED_BYTE))
.Times(1)
.RetiresOnSaturation();
TexSubImage3D cmd;
cmd.Init(GL_TEXTURE_3D, 1, 1, 0, 0, kWidth - 1, kHeight, kDepth, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// 0 size with null SHM
EXPECT_CALL(*gl_, TexSubImage3DNoData(GL_TEXTURE_3D, 1, 1, 0, 0, 0, 0, 0,
GL_RGBA, GL_UNSIGNED_BYTE))
.Times(1)
.RetiresOnSaturation();
cmd.Init(GL_TEXTURE_3D, 1, 1, 0, 0, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0,
GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
TEST_P(GLES3DecoderTest, TexSubImage3DBadArgs) {
const int kWidth = 4;
const int kHeight = 4;
const int kDepth = 2;
DoBindTexture(GL_TEXTURE_3D, client_texture_id_, kServiceTextureId);
DoTexImage3D(GL_TEXTURE_3D, 1, GL_RGBA, kWidth, kHeight, kDepth, 0, GL_RGBA,
GL_UNSIGNED_BYTE, 0, 0);
TexSubImage3D cmd;
// Invalid target.
cmd.Init(GL_TEXTURE0, 1, 0, 0, 0, kWidth, kHeight, kDepth, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
// Invalid format.
cmd.Init(GL_TEXTURE_3D, 1, 0, 0, 0, kWidth, kHeight, kDepth, GL_TRUE,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
// Invalid offsets/sizes.
cmd.Init(GL_TEXTURE_3D, 1, -1, 0, 0, kWidth, kHeight, kDepth, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_3D, 1, 1, 0, 0, kWidth, kHeight, kDepth, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_3D, 1, 0, -1, 0, kWidth, kHeight, kDepth, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_3D, 1, 0, 1, 0, kWidth, kHeight, kDepth, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_3D, 1, 0, 0, -1, kWidth, kHeight, kDepth, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_3D, 1, 0, 0, 1, kWidth, kHeight, kDepth, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_3D, 1, 0, 0, 0, kWidth + 1, kHeight, kDepth, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_3D, 1, 0, 0, 0, kWidth, kHeight + 1, kDepth, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_3D, 1, 0, 0, 0, kWidth, kHeight, kDepth + 1, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
// Incompatible format.
cmd.Init(GL_TEXTURE_3D, 1, 0, 0, 0, kWidth, kHeight, kDepth, GL_RGB,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// Above errors should still happen with NULL data.
cmd.Init(GL_TEXTURE_3D, 1, 0, 0, 0, kWidth, kHeight, kDepth, GL_TRUE,
GL_UNSIGNED_BYTE, 0, 0, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
cmd.Init(GL_TEXTURE_3D, 1, 0, 0, 0, kWidth, kHeight, kDepth + 1, GL_RGBA,
GL_UNSIGNED_BYTE, 0, 0, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_3D, 1, 0, 0, 0, kWidth, kHeight, kDepth, GL_RGB,
GL_UNSIGNED_BYTE, 0, 0, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// Invalid SHM / offset.
cmd.Init(GL_TEXTURE_3D, 1, 0, 0, 0, kWidth, kHeight, kDepth, GL_RGBA,
GL_UNSIGNED_BYTE, kInvalidSharedMemoryId, kSharedMemoryOffset,
GL_FALSE);
EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
cmd.Init(GL_TEXTURE_3D, 1, 0, 0, 0, kWidth, kHeight, kDepth, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kInvalidSharedMemoryOffset,
GL_FALSE);
EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
cmd.Init(GL_TEXTURE_3D, 1, 0, 0, 0, kWidth, kHeight, kDepth, GL_RGBA,
GL_UNSIGNED_BYTE, 0, 0, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
}
TEST_P(GLES3DecoderTest, TexSubImage2DTypesDoNotMatchUnsizedFormat) {
const int kWidth = 16;
const int kHeight = 8;
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
DoTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, kWidth, kHeight, 0, GL_RGBA,
GL_UNSIGNED_SHORT_4_4_4_4, shared_memory_id_,
kSharedMemoryOffset);
EXPECT_CALL(*gl_,
TexSubImage2D(GL_TEXTURE_2D,
1,
1,
0,
kWidth - 1,
kHeight,
GL_RGBA,
GL_UNSIGNED_BYTE,
shared_memory_address_))
.Times(1)
.RetiresOnSaturation();
TexSubImage2D cmd;
cmd.Init(GL_TEXTURE_2D, 1, 1, 0, kWidth - 1, kHeight, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
TEST_P(GLES3DecoderTest, TexSubImage2DTypesDoNotMatchSizedFormat) {
const int kWidth = 16;
const int kHeight = 8;
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
DoTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA4, kWidth, kHeight, 0, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset);
EXPECT_CALL(*gl_,
TexSubImage2D(GL_TEXTURE_2D,
1,
1,
0,
kWidth - 1,
kHeight,
GL_RGBA,
GL_UNSIGNED_SHORT_4_4_4_4,
shared_memory_address_))
.Times(1)
.RetiresOnSaturation();
TexSubImage2D cmd;
cmd.Init(GL_TEXTURE_2D, 1, 1, 0, kWidth - 1, kHeight, GL_RGBA,
GL_UNSIGNED_SHORT_4_4_4_4, shared_memory_id_, kSharedMemoryOffset,
GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
TEST_P(GLES2DecoderTest, CopyTexSubImage2DValidArgs) {
const int kWidth = 16;
const int kHeight = 8;
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
DoTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, kWidth, kHeight, 0, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset);
EXPECT_CALL(*gl_,
CopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight))
.Times(1)
.RetiresOnSaturation();
CopyTexSubImage2D cmd;
cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
TEST_P(GLES2DecoderTest, CopyTexSubImage2DBadArgs) {
const int kWidth = 16;
const int kHeight = 8;
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
DoTexImage2D(GL_TEXTURE_2D,
1,
GL_RGBA,
kWidth,
kHeight,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
0,
0);
CopyTexSubImage2D cmd;
cmd.Init(GL_TEXTURE0, 1, 0, 0, 0, 0, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
cmd.Init(GL_TEXTURE_2D, 1, -1, 0, 0, 0, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_2D, 1, 1, 0, 0, 0, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_2D, 1, 0, -1, 0, 0, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_2D, 1, 0, 1, 0, 0, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth + 1, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight + 1);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
}
TEST_P(GLES2DecoderTest, TexImage2DRedefinitionSucceeds) {
const int kWidth = 16;
const int kHeight = 8;
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
EXPECT_CALL(*gl_, GetError()).WillRepeatedly(Return(GL_NO_ERROR));
for (int ii = 0; ii < 2; ++ii) {
TexImage2D cmd;
if (ii == 0) {
EXPECT_CALL(*gl_,
TexImage2D(GL_TEXTURE_2D,
0,
GL_RGBA,
kWidth,
kHeight,
0,
GL_RGBA,
GL_UNSIGNED_BYTE,
_))
.Times(1)
.RetiresOnSaturation();
cmd.Init(GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset);
} else {
cmd.Init(GL_TEXTURE_2D,
0,
GL_RGBA,
kWidth,
kHeight,
GL_RGBA,
GL_UNSIGNED_BYTE,
0,
0);
}
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_CALL(*gl_,
TexSubImage2D(GL_TEXTURE_2D,
0,
0,
0,
kWidth,
kHeight - 1,
GL_RGBA,
GL_UNSIGNED_BYTE,
shared_memory_address_))
.Times(1)
.RetiresOnSaturation();
// Consider this TexSubImage2D command part of the previous TexImage2D
// (last GL_TRUE argument). It will be skipped if there are bugs in the
// redefinition case.
TexSubImage2D cmd2;
cmd2.Init(GL_TEXTURE_2D, 0, 0, 0, kWidth, kHeight - 1, GL_RGBA,
GL_UNSIGNED_BYTE, shared_memory_id_, kSharedMemoryOffset,
GL_TRUE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
}
}
TEST_P(GLES2DecoderTest, TexImage2DGLError) {
GLenum target = GL_TEXTURE_2D;
GLint level = 0;
GLenum internal_format = GL_RGBA;
GLsizei width = 2;
GLsizei height = 4;
GLint border = 0;
GLenum format = GL_RGBA;
GLenum type = GL_UNSIGNED_BYTE;
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
TextureManager* manager = group().texture_manager();
TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
ASSERT_TRUE(texture_ref != nullptr);
Texture* texture = texture_ref->texture();
EXPECT_FALSE(
texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height, nullptr));
EXPECT_CALL(*gl_, GetError())
.WillOnce(Return(GL_NO_ERROR))
.WillOnce(Return(GL_OUT_OF_MEMORY))
.RetiresOnSaturation();
EXPECT_CALL(*gl_,
TexImage2D(target,
level,
internal_format,
width,
height,
border,
format,
type,
_))
.Times(1)
.RetiresOnSaturation();
TexImage2D cmd;
cmd.Init(target, level, internal_format, width, height, format, type,
shared_memory_id_, kSharedMemoryOffset);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
EXPECT_FALSE(
texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height, nullptr));
}
TEST_P(GLES2DecoderTest, CopyTexImage2DGLError) {
GLenum target = GL_TEXTURE_2D;
GLint level = 0;
GLenum internal_format = GL_RGBA;
GLsizei width = 2;
GLsizei height = 4;
GLint border = 0;
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
TextureManager* manager = group().texture_manager();
TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
ASSERT_TRUE(texture_ref != nullptr);
Texture* texture = texture_ref->texture();
EXPECT_FALSE(
texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height, nullptr));
EXPECT_CALL(*gl_, GetError())
.WillOnce(Return(GL_NO_ERROR))
.WillOnce(Return(GL_OUT_OF_MEMORY))
.RetiresOnSaturation();
EXPECT_CALL(*gl_,
CopyTexImage2D(
target, level, internal_format, 0, 0, width, height, border))
.Times(1)
.RetiresOnSaturation();
CopyTexImage2D cmd;
cmd.Init(target, level, internal_format, 0, 0, width, height);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
EXPECT_FALSE(
texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height, nullptr));
}
TEST_P(GLES2DecoderManualInitTest, CopyTexImage2DUnsizedInternalFormat) {
InitState init;
init.gl_version = "OpenGL ES 3.0";
init.extensions = "GL_APPLE_texture_format_BGRA8888 GL_EXT_sRGB";
init.has_alpha = true;
init.request_alpha = true;
init.bind_generates_resource = true;
init.context_type = CONTEXT_TYPE_OPENGLES2;
InitDecoder(init);
GLenum kUnsizedInternalFormats[] = {
GL_RED,
GL_RG,
GL_RGB,
GL_RGBA,
GL_BGRA_EXT,
GL_LUMINANCE,
GL_LUMINANCE_ALPHA,
GL_SRGB,
GL_SRGB_ALPHA,
};
GLenum target = GL_TEXTURE_2D;
GLint level = 0;
GLsizei width = 2;
GLsizei height = 4;
GLint border = 0;
EXPECT_CALL(*gl_, GenTextures(_, _))
.WillOnce(SetArgPointee<1>(kNewServiceId))
.RetiresOnSaturation();
GenHelper<GenTexturesImmediate>(kNewClientId);
TextureManager* manager = group().texture_manager();
EXPECT_CALL(*gl_, GetError()).WillRepeatedly(Return(GL_NO_ERROR));
EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(_))
.WillRepeatedly(Return(GL_FRAMEBUFFER_COMPLETE));
for (size_t i = 0; i < arraysize(kUnsizedInternalFormats); ++i) {
// Copy from main framebuffer to texture, using the unsized internal format.
DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0);
GLenum internal_format = kUnsizedInternalFormats[i];
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
DoCopyTexImage2D(target, level, internal_format, 0, 0, width, height, border);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
TextureRef* ref = manager->GetTexture(client_texture_id_);
ASSERT_TRUE(ref != nullptr);
Texture* texture = ref->texture();
GLenum chosen_type = 0;
GLenum chosen_internal_format = 0;
texture->GetLevelType(target, level, &chosen_type, &chosen_internal_format);
EXPECT_NE(0u, chosen_type);
EXPECT_NE(0u, chosen_internal_format);
// Attach texture to FBO, and copy into second texture.
DoBindFramebuffer(
GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
DoFramebufferTexture2D(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D,
client_texture_id_,
kServiceTextureId,
0,
GL_NO_ERROR);
DoBindTexture(GL_TEXTURE_2D, kNewClientId, kNewServiceId);
bool complete =
(DoCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
if (complete) {
DoCopyTexImage2D(target, level, internal_format,
0, 0, width, height, border);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
} else {
CopyTexImage2D cmd;
cmd.Init(target, level, internal_format, 0, 0, width, height);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION, GetGLError());
}
}
}
TEST_P(GLES2DecoderManualInitTest, CopyTexImage2DUnsizedInternalFormatES3) {
InitState init;
init.gl_version = "OpenGL ES 3.0";
init.extensions = "GL_APPLE_texture_format_BGRA8888";
init.has_alpha = true;
init.request_alpha = true;
init.bind_generates_resource = true;
init.context_type = CONTEXT_TYPE_OPENGLES3;
InitDecoder(init);
struct UnsizedSizedInternalFormat {
GLenum unsized;
GLenum sized;
};
UnsizedSizedInternalFormat kUnsizedInternalFormats[] = {
// GL_RED and GL_RG should not work.
{GL_RGB, GL_RGB8},
{GL_RGBA, GL_RGBA8},
{GL_BGRA_EXT, GL_RGBA8},
{GL_LUMINANCE, GL_RGB8},
{GL_LUMINANCE_ALPHA, GL_RGBA8},
};
GLenum target = GL_TEXTURE_2D;
GLint level = 0;
GLsizei width = 2;
GLsizei height = 4;
GLint border = 0;
EXPECT_CALL(*gl_, GenTextures(_, _))
.WillOnce(SetArgPointee<1>(kNewServiceId))
.RetiresOnSaturation();
GenHelper<GenTexturesImmediate>(kNewClientId);
TextureManager* manager = group().texture_manager();
EXPECT_CALL(*gl_, GetError()).WillRepeatedly(Return(GL_NO_ERROR));
EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(_))
.WillRepeatedly(Return(GL_FRAMEBUFFER_COMPLETE));
for (size_t i = 0; i < arraysize(kUnsizedInternalFormats); ++i) {
// Copy from main framebuffer to texture, using the unsized internal format.
DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0);
GLenum internal_format = kUnsizedInternalFormats[i].unsized;
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
DoCopyTexImage2D(target, level, internal_format,
0, 0, width, height, border);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
TextureRef* ref = manager->GetTexture(client_texture_id_);
ASSERT_TRUE(ref != nullptr);
Texture* texture = ref->texture();
GLenum chosen_type = 0;
GLenum chosen_internal_format = 0;
texture->GetLevelType(target, level, &chosen_type, &chosen_internal_format);
EXPECT_NE(0u, chosen_type);
EXPECT_NE(0u, chosen_internal_format);
// Attach texture to FBO, and copy into second texture using the sized
// internal format.
DoBindFramebuffer(
GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
DoFramebufferTexture2D(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
GL_TEXTURE_2D,
client_texture_id_,
kServiceTextureId,
0,
GL_NO_ERROR);
if (DoCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
continue;
internal_format = kUnsizedInternalFormats[i].sized;
DoBindTexture(GL_TEXTURE_2D, kNewClientId, kNewServiceId);
bool complete =
(DoCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
if (complete) {
DoCopyTexImage2D(target, level, internal_format,
0, 0, width, height, border);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
} else {
CopyTexImage2D cmd;
cmd.Init(target, level, internal_format, 0, 0, width, height);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION, GetGLError());
}
}
}
TEST_P(GLES3DecoderTest, CompressedTexImage3DBucket) {
const uint32_t kBucketId = 123;
const uint32_t kBadBucketId = 99;
const GLenum kTarget = GL_TEXTURE_2D_ARRAY;
const GLint kLevel = 0;
const GLenum kInternalFormat = GL_COMPRESSED_R11_EAC;
const GLsizei kWidth = 4;
const GLsizei kHeight = 4;
const GLsizei kDepth = 4;
const GLint kBorder = 0;
CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
ASSERT_TRUE(bucket != nullptr);
const GLsizei kImageSize = 32;
bucket->SetSize(kImageSize);
DoBindTexture(kTarget, client_texture_id_, kServiceTextureId);
CompressedTexImage3DBucket cmd;
cmd.Init(kTarget,
kLevel,
kInternalFormat,
kWidth,
kHeight,
kDepth,
kBadBucketId);
EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
cmd.Init(kTarget,
kLevel,
kInternalFormat,
kWidth,
kHeight,
kDepth,
kBucketId);
EXPECT_CALL(*gl_,
CompressedTexImage3D(kTarget, kLevel, kInternalFormat, kWidth,
kHeight, kDepth, kBorder, kImageSize, _))
.Times(1)
.RetiresOnSaturation();
EXPECT_CALL(*gl_, GetError())
.WillOnce(Return(GL_NO_ERROR))
.WillOnce(Return(GL_NO_ERROR))
.RetiresOnSaturation();
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
TEST_P(GLES3DecoderTest, CompressedTexImage3DBucketBucketSizeIsZero) {
const uint32_t kBucketId = 123;
const uint32_t kBadBucketId = 99;
const GLenum kTarget = GL_TEXTURE_2D_ARRAY;
const GLint kLevel = 0;
const GLenum kInternalFormat = GL_COMPRESSED_R11_EAC;
const GLsizei kWidth = 4;
const GLsizei kHeight = 4;
const GLsizei kDepth = 4;
const GLint kBorder = 0;
CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
ASSERT_TRUE(bucket != nullptr);
const GLsizei kImageSize = 0;
bucket->SetSize(kImageSize);
DoBindTexture(kTarget, client_texture_id_, kServiceTextureId);
// Bad bucket
CompressedTexImage3DBucket cmd;
cmd.Init(kTarget,
kLevel,
kInternalFormat,
0,
kHeight,
kDepth,
kBadBucketId);
EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
// Bucket size is zero. Height or width or depth is zero too.
cmd.Init(kTarget,
kLevel,
kInternalFormat,
0,
kHeight,
kDepth,
kBucketId);
EXPECT_CALL(*gl_,
CompressedTexImage3D(kTarget, kLevel, kInternalFormat, 0,
kHeight, kDepth, kBorder, kImageSize, _))
.Times(1)
.RetiresOnSaturation();
EXPECT_CALL(*gl_, GetError())
.WillOnce(Return(GL_NO_ERROR))
.WillOnce(Return(GL_NO_ERROR))
.RetiresOnSaturation();
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// Bucket size is zero. But height, width and depth are not zero.
cmd.Init(kTarget,
kLevel,
kInternalFormat,
kWidth,
kHeight,
kDepth,
kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
}
TEST_P(GLES2DecoderTest, CompressedTexImage3DFailsOnES2) {
const uint32_t kBucketId = 123;
const GLenum kTarget = GL_TEXTURE_2D_ARRAY;
const GLint kLevel = 0;
const GLenum kInternalFormat = GL_COMPRESSED_R11_EAC;
const GLsizei kWidth = 4;
const GLsizei kHeight = 4;
const GLsizei kDepth = 4;
CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
ASSERT_TRUE(bucket != nullptr);
const GLsizei kImageSize = 32;
bucket->SetSize(kImageSize);
{
CompressedTexImage3DBucket cmd;
cmd.Init(kTarget,
kLevel,
kInternalFormat,
kWidth,
kHeight,
kDepth,
kBucketId);
EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
}
{
CompressedTexSubImage3DBucket cmd;
cmd.Init(kTarget,
kLevel,
0, 0, 0,
kWidth,
kHeight,
kDepth,
kInternalFormat,
kBucketId);
EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
}
}
TEST_P(GLES2DecoderTest, CopyTexSubImage3DFailsOnES2) {
const GLenum kTarget = GL_TEXTURE_2D_ARRAY;
const GLint kLevel = 0;
const GLsizei kWidth = 4;
const GLsizei kHeight = 4;
CopyTexSubImage3D cmd;
cmd.Init(kTarget,
kLevel,
0, 0, 0,
0, 0,
kWidth,
kHeight);
EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
}
TEST_P(GLES3DecoderTest, CopyTexSubImage3DFaiures) {
const GLenum kTarget = GL_TEXTURE_3D;
const GLint kLevel = 1;
const GLint kXoffset = 0;
const GLint kYoffset = 0;
const GLint kZoffset = 0;
const GLint kX = 0;
const GLint kY = 0;
const GLsizei kWidth = 2;
const GLsizei kHeight = 2;
const GLsizei kDepth = 2;
CopyTexSubImage3D cmd;
// No texture bound
cmd.Init(kTarget, kLevel, kXoffset, kYoffset, kZoffset,
kX, kY, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// Incompatible format / type
// The default format/type of default read buffer is RGB/UNSIGNED_BYTE
const GLint kInternalFormat = GL_RGBA8;
const GLenum kFormat = GL_RGBA;
const GLenum kType = GL_UNSIGNED_BYTE;
DoBindTexture(kTarget, client_texture_id_, kServiceTextureId);
DoTexImage3D(kTarget, kLevel, kInternalFormat, kWidth, kHeight, kDepth, 0,
kFormat, kType, shared_memory_id_, kSharedMemoryOffset);
cmd.Init(kTarget, kLevel, kXoffset, kYoffset, kZoffset,
kX, kY, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
}
TEST_P(GLES3DecoderTest, CopyTexSubImage3DCheckArgs) {
const GLenum kTarget = GL_TEXTURE_3D;
const GLint kLevel = 1;
const GLint kInternalFormat = GL_RGB8;
const GLint kXoffset = 0;
const GLint kYoffset = 0;
const GLint kZoffset = 0;
const GLint kX = 0;
const GLint kY = 0;
const GLsizei kWidth = 2;
const GLsizei kHeight = 2;
const GLsizei kDepth = 2;
const GLsizei kBorder = 0;
const GLenum kFormat = GL_RGB;
const GLenum kType = GL_UNSIGNED_BYTE;
DoBindTexture(kTarget, client_texture_id_, kServiceTextureId);
DoTexImage3D(kTarget, kLevel, kInternalFormat, kWidth, kHeight, kDepth,
kBorder, kFormat, kType, shared_memory_id_, kSharedMemoryOffset);
// Valid args
EXPECT_CALL(*gl_,
CopyTexSubImage3D(kTarget, kLevel, kXoffset, kYoffset, kZoffset,
kX, kY, kWidth, kHeight))
.Times(1)
.RetiresOnSaturation();
CopyTexSubImage3D cmd;
cmd.Init(kTarget, kLevel, kXoffset, kYoffset, kZoffset,
kX, kY, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// Bad target
cmd.Init(GL_TEXTURE_2D, kLevel, kXoffset, kYoffset, kZoffset,
kX, kY, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
// Bad Level
cmd.Init(kTarget, -1, kXoffset, kYoffset, kZoffset,
kX, kY, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(kTarget, 0, kXoffset, kYoffset, kZoffset,
kX, kY, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
// Bad xoffest / yoffset of 3D texture
cmd.Init(kTarget, kLevel, -1, kYoffset, kZoffset,
kX, kY, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(kTarget, kLevel, 1, kYoffset, kZoffset,
kX, kY, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(kTarget, kLevel, kXoffset, -1, kZoffset,
kX, kY, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(kTarget, kLevel, kXoffset, 1, kZoffset,
kX, kY, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
// Bad zoffset: zoffset specifies the layer of the 3D texture to be replaced
cmd.Init(kTarget, kLevel, kXoffset, kYoffset, -1,
kX, kY, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(kTarget, kLevel, kXoffset, kYoffset, kDepth,
kX, kY, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
// Bad width / height
cmd.Init(kTarget, kLevel, kXoffset, kYoffset, kZoffset,
kX, kY, kWidth + 1, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
cmd.Init(kTarget, kLevel, kXoffset, kYoffset, kZoffset,
kX, kY, kWidth, kHeight + 1);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
}
TEST_P(GLES3DecoderTest, CopyTexSubImage3DFeedbackLoopSucceeds0) {
const GLenum kTarget = GL_TEXTURE_3D;
const GLint kInternalFormat = GL_RGB8;
const GLint kXoffset = 0;
const GLint kYoffset = 0;
const GLint kZoffset = 0;
const GLint kX = 0;
const GLint kY = 0;
const GLsizei kWidth = 2;
const GLsizei kHeight = 2;
const GLsizei kDepth = 2;
const GLsizei kBorder = 0;
const GLenum kFormat = GL_RGB;
const GLenum kType = GL_UNSIGNED_BYTE;
DoBindTexture(kTarget, client_texture_id_, kServiceTextureId);
DoBindFramebuffer(
GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
FramebufferTextureLayer tex_layer;
CopyTexSubImage3D cmd;
// The source and the target for CopyTexSubImage3D are the same 3d texture.
// But level of 3D texture != level of read attachment in fbo.
GLint kLevel = 0;
GLint kLayer = 0; // kZoffset is 0
EXPECT_CALL(*gl_, FramebufferTextureLayer(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
kServiceTextureId, kLevel, kLayer))
.Times(1)
.RetiresOnSaturation();
DoTexImage3D(kTarget, kLevel, kInternalFormat, kWidth, kHeight, kDepth,
kBorder, kFormat, kType, shared_memory_id_, kSharedMemoryOffset);
tex_layer.Init(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, client_texture_id_,
kLevel, kLayer);
EXPECT_EQ(error::kNoError, ExecuteCmd(tex_layer));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
kLevel = 1;
EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(_))
.WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
.RetiresOnSaturation();
EXPECT_CALL(*gl_,
CopyTexSubImage3D(kTarget, kLevel, kXoffset, kYoffset, kZoffset,
kX, kY, kWidth, kHeight))
.Times(1)
.RetiresOnSaturation();
DoTexImage3D(kTarget, kLevel, kInternalFormat, kWidth, kHeight, kDepth,
kBorder, kFormat, kType, shared_memory_id_, kSharedMemoryOffset);
cmd.Init(kTarget, kLevel, kXoffset, kYoffset, kZoffset,
kX, kY, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
TEST_P(GLES3DecoderTest, CopyTexSubImage3DFeedbackLoopSucceeds1) {
const GLenum kTarget = GL_TEXTURE_3D;
const GLint kInternalFormat = GL_RGB8;
const GLint kXoffset = 0;
const GLint kYoffset = 0;
const GLint kZoffset = 0;
const GLint kX = 0;
const GLint kY = 0;
const GLsizei kWidth = 2;
const GLsizei kHeight = 2;
const GLsizei kDepth = 2;
const GLsizei kBorder = 0;
const GLenum kFormat = GL_RGB;
const GLenum kType = GL_UNSIGNED_BYTE;
DoBindTexture(kTarget, client_texture_id_, kServiceTextureId);
DoBindFramebuffer(
GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
FramebufferTextureLayer tex_layer;
CopyTexSubImage3D cmd;
// The source and the target for CopyTexSubImage3D are the same 3d texture.
// But zoffset of 3D texture != layer of read attachment in fbo.
GLint kLevel = 0;
GLint kLayer = 1; // kZoffset is 0
EXPECT_CALL(*gl_, FramebufferTextureLayer(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
kServiceTextureId, kLevel, kLayer))
.Times(1)
.RetiresOnSaturation();
DoTexImage3D(kTarget, kLevel, kInternalFormat, kWidth, kHeight, kDepth,
kBorder, kFormat, kType, shared_memory_id_, kSharedMemoryOffset);
tex_layer.Init(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, client_texture_id_,
kLevel, kLayer);
EXPECT_EQ(error::kNoError, ExecuteCmd(tex_layer));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(_))
.WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
.RetiresOnSaturation();
EXPECT_CALL(*gl_,
CopyTexSubImage3D(kTarget, kLevel, kXoffset, kYoffset, kZoffset,
kX, kY, kWidth, kHeight))
.Times(1)
.RetiresOnSaturation();
cmd.Init(kTarget, kLevel, kXoffset, kYoffset, kZoffset,
kX, kY, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
TEST_P(GLES3DecoderTest, CopyTexSubImage3DFeedbackLoopFails) {
const GLenum kTarget = GL_TEXTURE_3D;
const GLint kInternalFormat = GL_RGB8;
const GLint kXoffset = 0;
const GLint kYoffset = 0;
const GLint kZoffset = 0;
const GLint kX = 0;
const GLint kY = 0;
const GLsizei kWidth = 2;
const GLsizei kHeight = 2;
const GLsizei kDepth = 2;
const GLsizei kBorder = 0;
const GLenum kFormat = GL_RGB;
const GLenum kType = GL_UNSIGNED_BYTE;
DoBindTexture(kTarget, client_texture_id_, kServiceTextureId);
DoBindFramebuffer(
GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
FramebufferTextureLayer tex_layer;
CopyTexSubImage3D cmd;
// The source and the target for CopyTexSubImage3D are the same 3d texture.
// And level / zoffset of 3D texture equal to level / layer of read attachment
// in fbo.
GLint kLevel = 0; // This has to be base level, or fbo is incomplete.
GLint kLayer = 0; // kZoffset is 0
EXPECT_CALL(*gl_, FramebufferTextureLayer(GL_FRAMEBUFFER,
GL_COLOR_ATTACHMENT0,
kServiceTextureId, kLevel, kLayer))
.Times(1)
.RetiresOnSaturation();
DoTexImage3D(kTarget, kLevel, kInternalFormat, kWidth, kHeight, kDepth,
kBorder, kFormat, kType, shared_memory_id_, kSharedMemoryOffset);
tex_layer.Init(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, client_texture_id_,
kLevel, kLayer);
EXPECT_EQ(error::kNoError, ExecuteCmd(tex_layer));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(_))
.WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
.RetiresOnSaturation();
cmd.Init(kTarget, kLevel, kXoffset, kYoffset, kZoffset,
kX, kY, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
}
TEST_P(GLES3DecoderTest, CopyTexSubImage3DClearTheUncleared3DTexture) {
const GLenum kTarget = GL_TEXTURE_3D;
const GLint kLevel = 0;
const GLint kXoffset = 0;
const GLint kYoffset = 0;
const GLint kZoffset = 0;
const GLint kX = 0;
const GLint kY = 0;
const GLint kInternalFormat = GL_RGB8;
const GLsizei kWidth = 2;
const GLsizei kHeight = 2;
const GLsizei kDepth = 2;
const GLenum kFormat = GL_RGB;
const GLenum kType = GL_UNSIGNED_BYTE;
const uint32_t kBufferSize = kWidth * kHeight * kDepth * 4;
DoBindTexture(kTarget, client_texture_id_, kServiceTextureId);
DoTexImage3D(kTarget, kLevel, kInternalFormat, kWidth, kHeight, kDepth, 0,
kFormat, kType, 0, 0);
TextureRef* texture_ref =
group().texture_manager()->GetTexture(client_texture_id_);
ASSERT_TRUE(texture_ref != nullptr);
Texture* texture = texture_ref->texture();
EXPECT_FALSE(texture->SafeToRenderFrom());
EXPECT_FALSE(texture->IsLevelCleared(kTarget, kLevel));
// CopyTexSubImage3D will clear the uncleared texture
GLint xoffset[] = {kXoffset};
GLint yoffset[] = {kYoffset};
GLint zoffset[] = {kZoffset};
GLsizei width[] = {kWidth};
GLsizei height[] = {kHeight};
GLsizei depth[] = {kDepth};
SetupClearTexture3DExpectations(kBufferSize, kTarget, kServiceTextureId,
kLevel, kFormat, kType, 1, xoffset, yoffset,
zoffset, width, height, depth, 0);
EXPECT_CALL(*gl_,
CopyTexSubImage3D(kTarget, kLevel, kXoffset, kYoffset, kZoffset,
kX, kY, kWidth, kHeight))
.Times(1)
.RetiresOnSaturation();
CopyTexSubImage3D cmd;
cmd.Init(kTarget, kLevel, kXoffset, kYoffset, kZoffset,
kX, kY, kWidth, kHeight);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
EXPECT_TRUE(texture->SafeToRenderFrom());
EXPECT_TRUE(texture->IsLevelCleared(kTarget, kLevel));
}
TEST_P(GLES3DecoderTest, CompressedTexImage3DFailsWithBadImageSize) {
const uint32_t kBucketId = 123;
const GLenum kTarget = GL_TEXTURE_2D_ARRAY;
const GLint kLevel = 0;
const GLenum kInternalFormat = GL_COMPRESSED_RGBA8_ETC2_EAC;
const GLsizei kWidth = 4;
const GLsizei kHeight = 8;
const GLsizei kDepth = 4;
CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
ASSERT_TRUE(bucket != nullptr);
const GLsizei kBadImageSize = 64;
bucket->SetSize(kBadImageSize);
DoBindTexture(kTarget, client_texture_id_, kServiceTextureId);
CompressedTexImage3DBucket cmd;
cmd.Init(kTarget,
kLevel,
kInternalFormat,
kWidth,
kHeight,
kDepth,
kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
}
TEST_P(GLES3DecoderTest, CompressedTexSubImage3DFails) {
const uint32_t kBucketId = 123;
const GLenum kTarget = GL_TEXTURE_2D_ARRAY;
const GLint kLevel = 0;
const GLenum kInternalFormat = GL_COMPRESSED_RGBA8_ETC2_EAC;
const GLsizei kWidth = 4;
const GLsizei kHeight = 8;
const GLsizei kDepth = 4;
const GLint kBorder = 0;
CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
ASSERT_TRUE(bucket != nullptr);
const GLsizei kImageSize = 128;
bucket->SetSize(kImageSize);
DoBindTexture(kTarget, client_texture_id_, kServiceTextureId);
CompressedTexImage3DBucket tex_cmd;
tex_cmd.Init(kTarget,
kLevel,
kInternalFormat,
kWidth,
kHeight,
kDepth,
kBucketId);
EXPECT_CALL(*gl_,
CompressedTexImage3D(kTarget, kLevel, kInternalFormat, kWidth,
kHeight, kDepth, kBorder, kImageSize, _))
.Times(1)
.RetiresOnSaturation();
EXPECT_CALL(*gl_, GetError())
.WillOnce(Return(GL_NO_ERROR))
.WillOnce(Return(GL_NO_ERROR))
.RetiresOnSaturation();
EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
const GLint kXOffset = 0;
const GLint kYOffset = 0;
const GLint kZOffset = 0;
const GLint kSubWidth = 4;
const GLint kSubHeight = 4;
const GLint kSubDepth = 4;
const GLenum kFormat = kInternalFormat;
CompressedTexSubImage3DBucket cmd;
// Incorrect image size.
cmd.Init(kTarget,
kLevel,
kXOffset,
kYOffset,
kZOffset,
kSubWidth,
kSubHeight,
kSubDepth,
kFormat,
kBucketId);
const GLsizei kBadSubImageSize = 32;
const GLsizei kSubImageSize = 64;
bucket->SetSize(kBadSubImageSize);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
// Incorrect format.
const GLenum kBadFormat = GL_COMPRESSED_R11_EAC;
cmd.Init(kTarget,
kLevel,
kXOffset,
kYOffset,
kZOffset,
kSubWidth,
kSubHeight,
kSubDepth,
kBadFormat,
kBucketId);
bucket->SetSize(kSubImageSize);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// Negative offset.
cmd.Init(kTarget,
kLevel,
kXOffset,
-4,
kZOffset,
kSubWidth,
kSubHeight,
kSubDepth,
kFormat,
kBucketId);
bucket->SetSize(kSubImageSize);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
// offset + size > texture size
cmd.Init(kTarget,
kLevel,
kXOffset,
kYOffset + 8,
kZOffset,
kSubWidth,
kSubHeight,
kSubDepth,
kFormat,
kBucketId);
bucket->SetSize(kSubImageSize);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
// offset not a multiple of 4.
cmd.Init(kTarget,
kLevel,
kXOffset,
kYOffset + 1,
kZOffset,
kSubWidth,
kSubHeight,
kSubDepth,
kFormat,
kBucketId);
bucket->SetSize(kSubImageSize);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// offset + width not a multlple of 4 .
cmd.Init(kTarget,
kLevel,
kXOffset,
kYOffset,
kZOffset,
kSubWidth,
kSubHeight + 3,
kSubDepth,
kFormat,
kBucketId);
const GLsizei kSubImageSize2 = 128;
bucket->SetSize(kSubImageSize2);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// Bad bucket id.
const uint32_t kBadBucketId = 444;
cmd.Init(kTarget,
kLevel,
kXOffset,
kYOffset,
kZOffset,
kSubWidth,
kSubHeight,
kSubDepth,
kFormat,
kBadBucketId);
bucket->SetSize(kSubImageSize);
EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
// Bad target
cmd.Init(GL_RGBA,
kLevel,
kXOffset,
kYOffset,
kZOffset,
kSubWidth,
kSubHeight,
kSubDepth,
kFormat,
kBucketId);
bucket->SetSize(kSubImageSize);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
// Bad format
cmd.Init(kTarget,
kLevel,
kXOffset,
kYOffset,
kZOffset,
kSubWidth,
kSubHeight,
kSubDepth,
GL_ONE,
kBucketId);
bucket->SetSize(kSubImageSize);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
}
TEST_P(GLES3DecoderTest, CompressedTexSubImage3DBadSHM) {
const uint32_t kBucketId = 123;
const GLenum kTarget = GL_TEXTURE_2D_ARRAY;
const GLint kLevel = 0;
const GLenum kInternalFormat = GL_COMPRESSED_RGBA8_ETC2_EAC;
const GLsizei kWidth = 4;
const GLsizei kHeight = 8;
const GLsizei kDepth = 4;
const GLint kBorder = 0;
CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
ASSERT_TRUE(bucket != nullptr);
const GLsizei kImageSize = 128;
bucket->SetSize(kImageSize);
DoBindTexture(kTarget, client_texture_id_, kServiceTextureId);
CompressedTexImage3DBucket tex_cmd;
tex_cmd.Init(kTarget, kLevel, kInternalFormat, kWidth, kHeight, kDepth,
kBucketId);
EXPECT_CALL(*gl_,
CompressedTexImage3D(kTarget, kLevel, kInternalFormat, kWidth,
kHeight, kDepth, kBorder, kImageSize, _))
.Times(1)
.RetiresOnSaturation();
EXPECT_CALL(*gl_, GetError())
.WillOnce(Return(GL_NO_ERROR))
.WillOnce(Return(GL_NO_ERROR))
.RetiresOnSaturation();
EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
const GLint kXOffset = 0;
const GLint kYOffset = 0;
const GLint kZOffset = 0;
const GLint kSubWidth = 4;
const GLint kSubHeight = 4;
const GLint kSubDepth = 4;
const GLenum kFormat = kInternalFormat;
const GLsizei kSubImageSize = 64;
const GLsizei kBadSubImageSize = 65;
CompressedTexSubImage3D cmd;
// Invalid args + NULL SHM -> GL error
cmd.Init(kTarget, kLevel, kXOffset, kYOffset, kZOffset, kSubWidth, kSubHeight,
kSubDepth, kFormat, kBadSubImageSize, 0, 0);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
// Valid args + non-empty size + NULL SHM -> command buffer error
cmd.Init(kTarget, kLevel, kXOffset, kYOffset, kZOffset, kSubWidth, kSubHeight,
kSubDepth, kFormat, kSubImageSize, 0, 0);
EXPECT_EQ(error::kInvalidArguments, ExecuteCmd(cmd));
// Valid args + non-empty size + invalid SHM -> command buffer error
cmd.Init(kTarget, kLevel, kXOffset, kYOffset, kZOffset, kSubWidth, kSubHeight,
kSubDepth, kFormat, kSubImageSize, 0, kSharedMemoryOffset);
EXPECT_EQ(error::kInvalidArguments, ExecuteCmd(cmd));
// Valid args + empty size + NULL SHM -> no error (NOOP).
EXPECT_CALL(*gl_,
CompressedTexSubImage3DNoData(kTarget, kLevel, kXOffset, kYOffset,
kZOffset, 0, 0, 0, kFormat, 0))
.Times(1)
.RetiresOnSaturation();
cmd.Init(kTarget, kLevel, kXOffset, kYOffset, kZOffset, 0, 0, 0, kFormat, 0,
0, 0);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
TEST_P(GLES3DecoderTest, CompressedTexImage2DBucketBucketSizeIsZero) {
const uint32_t kBucketId = 123;
const uint32_t kBadBucketId = 99;
const GLenum kTarget = GL_TEXTURE_2D;
const GLint kLevel = 0;
const GLenum kInternalFormat = GL_COMPRESSED_R11_EAC;
const GLsizei kWidth = 4;
const GLsizei kHeight = 4;
const GLint kBorder = 0;
CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
ASSERT_TRUE(bucket != nullptr);
const GLsizei kImageSize = 0;
bucket->SetSize(kImageSize);
DoBindTexture(kTarget, client_texture_id_, kServiceTextureId);
// Bad bucket
CompressedTexImage2DBucket cmd;
cmd.Init(kTarget,
kLevel,
kInternalFormat,
0,
kHeight,
kBadBucketId);
EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
// Bucket size is zero. Height or width is zero too.
cmd.Init(kTarget,
kLevel,
kInternalFormat,
0,
kHeight,
kBucketId);
EXPECT_CALL(*gl_,
CompressedTexImage2D(kTarget, kLevel, kInternalFormat, 0,
kHeight, kBorder, kImageSize, _))
.Times(1)
.RetiresOnSaturation();
EXPECT_CALL(*gl_, GetError())
.WillOnce(Return(GL_NO_ERROR))
.WillOnce(Return(GL_NO_ERROR))
.RetiresOnSaturation();
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// Bucket size is zero. But height and width are not zero.
cmd.Init(kTarget,
kLevel,
kInternalFormat,
kWidth,
kHeight,
kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
}
TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DBucketBadBucket) {
InitState init;
init.extensions = "GL_EXT_texture_compression_s3tc";
init.bind_generates_resource = true;
InitDecoder(init);
const uint32_t kBadBucketId = 123;
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
CompressedTexImage2DBucket cmd;
cmd.Init(GL_TEXTURE_2D,
0,
GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
4,
4,
kBadBucketId);
EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
CompressedTexSubImage2DBucket cmd2;
cmd2.Init(GL_TEXTURE_2D,
0,
0,
0,
4,
4,
GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
kBadBucketId);
EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
}
namespace {
struct S3TCTestData {
GLenum format;
size_t block_size;
};
} // anonymous namespace.
TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DS3TCWebGL) {
InitState init;
init.extensions = "GL_EXT_texture_compression_s3tc";
init.bind_generates_resource = true;
init.context_type = CONTEXT_TYPE_WEBGL1;
InitDecoder(init);
const uint32_t kBucketId = 123;
CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
ASSERT_TRUE(bucket != nullptr);
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
static const S3TCTestData test_data[] = {
{
GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 8,
},
{
GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 8,
},
{
GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, 16,
},
{
GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 16,
},
};
for (size_t ii = 0; ii < arraysize(test_data); ++ii) {
const S3TCTestData& test = test_data[ii];
CompressedTexImage2DBucket cmd;
// test small width.
DoCompressedTexImage2D(
GL_TEXTURE_2D, 1, test.format, 2, 4, 0, test.block_size, kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// test bad width.
cmd.Init(GL_TEXTURE_2D, 0, test.format, 5, 4, kBucketId);
bucket->SetSize(test.block_size * 2);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// test small height.
DoCompressedTexImage2D(
GL_TEXTURE_2D, 1, test.format, 4, 2, 0, test.block_size, kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// test too bad height.
cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 5, kBucketId);
bucket->SetSize(test.block_size * 2);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// test small for level 0.
DoCompressedTexImage2D(
GL_TEXTURE_2D, 1, test.format, 1, 1, 0, test.block_size, kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// test small for level 0.
DoCompressedTexImage2D(
GL_TEXTURE_2D, 1, test.format, 2, 2, 0, test.block_size, kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// test size too large.
cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 4, kBucketId);
bucket->SetSize(test.block_size * 2);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
// test size too small.
cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 4, kBucketId);
bucket->SetSize(test.block_size / 2);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
// test with 3 mips.
DoCompressedTexImage2D(
GL_TEXTURE_2D, 0, test.format, 4, 4, 0, test.block_size, kBucketId);
DoCompressedTexImage2D(
GL_TEXTURE_2D, 1, test.format, 2, 2, 0, test.block_size, kBucketId);
DoCompressedTexImage2D(
GL_TEXTURE_2D, 2, test.format, 1, 1, 0, test.block_size, kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// Test a 16x16
DoCompressedTexImage2D(GL_TEXTURE_2D,
0,
test.format,
16,
16,
0,
test.block_size * 4 * 4,
kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
CompressedTexSubImage2DBucket sub_cmd;
bucket->SetSize(test.block_size);
// Test sub image bad xoffset
sub_cmd.Init(GL_TEXTURE_2D, 0, 1, 0, 4, 4, test.format, kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// Test sub image bad yoffset
sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 2, 4, 4, test.format, kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// Test sub image bad width
bucket->SetSize(test.block_size * 2);
sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 5, 4, test.format, kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// Test sub image bad height
sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 5, test.format, kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// Test sub image bad size
bucket->SetSize(test.block_size + 1);
sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 4, test.format, kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
for (GLint yoffset = 0; yoffset <= 8; yoffset += 4) {
for (GLint xoffset = 0; xoffset <= 8; xoffset += 4) {
for (GLsizei height = 4; height <= 8; height += 4) {
for (GLsizei width = 4; width <= 8; width += 4) {
GLsizei size = test.block_size * (width / 4) * (height / 4);
bucket->SetSize(size);
EXPECT_CALL(*gl_,
CompressedTexSubImage2D(GL_TEXTURE_2D,
0,
xoffset,
yoffset,
width,
height,
test.format,
size,
_))
.Times(1)
.RetiresOnSaturation();
sub_cmd.Init(GL_TEXTURE_2D,
0,
xoffset,
yoffset,
width,
height,
test.format,
kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
}
}
}
}
}
TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DS3TC) {
InitState init;
init.extensions = "GL_EXT_texture_compression_s3tc";
init.bind_generates_resource = true;
InitDecoder(init);
const uint32_t kBucketId = 123;
CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
ASSERT_TRUE(bucket != nullptr);
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
static const S3TCTestData test_data[] = {
{
GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 8,
},
{
GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 8,
},
{
GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, 16,
},
{
GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 16,
},
};
for (size_t ii = 0; ii < arraysize(test_data); ++ii) {
const S3TCTestData& test = test_data[ii];
CompressedTexImage2DBucket cmd;
// test small width.
DoCompressedTexImage2D(
GL_TEXTURE_2D, 1, test.format, 2, 4, 0, test.block_size, kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// test non-block-size width.
bucket->SetSize(test.block_size * 2);
DoCompressedTexImage2D(
GL_TEXTURE_2D, 0, test.format, 5, 4, 0, test.block_size * 2, kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// test small height.
DoCompressedTexImage2D(
GL_TEXTURE_2D, 1, test.format, 4, 2, 0, test.block_size, kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// test non-block-size height.
bucket->SetSize(test.block_size * 2);
DoCompressedTexImage2D(
GL_TEXTURE_2D, 0, test.format, 4, 5, 0, test.block_size * 2, kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// test small for level 0.
DoCompressedTexImage2D(
GL_TEXTURE_2D, 1, test.format, 1, 1, 0, test.block_size, kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// test small for level 0.
DoCompressedTexImage2D(
GL_TEXTURE_2D, 1, test.format, 2, 2, 0, test.block_size, kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// test size too large.
cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 4, kBucketId);
bucket->SetSize(test.block_size * 2);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
// test size too small.
cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 4, kBucketId);
bucket->SetSize(test.block_size / 2);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
// test with 3 mips.
DoCompressedTexImage2D(
GL_TEXTURE_2D, 0, test.format, 4, 4, 0, test.block_size, kBucketId);
DoCompressedTexImage2D(
GL_TEXTURE_2D, 1, test.format, 2, 2, 0, test.block_size, kBucketId);
DoCompressedTexImage2D(
GL_TEXTURE_2D, 2, test.format, 1, 1, 0, test.block_size, kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// Test a 16x16
DoCompressedTexImage2D(GL_TEXTURE_2D,
0,
test.format,
16,
16,
0,
test.block_size * 4 * 4,
kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
CompressedTexSubImage2DBucket sub_cmd;
bucket->SetSize(test.block_size);
// Test sub image bad xoffset
sub_cmd.Init(GL_TEXTURE_2D, 0, 1, 0, 4, 4, test.format, kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// Test sub image bad yoffset
sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 2, 4, 4, test.format, kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// Test sub image bad width
bucket->SetSize(test.block_size * 2);
sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 5, 4, test.format, kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// Test sub image bad height
sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 5, test.format, kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// Test sub image bad size
bucket->SetSize(test.block_size + 1);
sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 4, test.format, kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
for (GLint yoffset = 0; yoffset <= 8; yoffset += 4) {
for (GLint xoffset = 0; xoffset <= 8; xoffset += 4) {
for (GLsizei height = 4; height <= 8; height += 4) {
for (GLsizei width = 4; width <= 8; width += 4) {
GLsizei size = test.block_size * (width / 4) * (height / 4);
bucket->SetSize(size);
EXPECT_CALL(*gl_,
CompressedTexSubImage2D(GL_TEXTURE_2D,
0,
xoffset,
yoffset,
width,
height,
test.format,
size,
_))
.Times(1)
.RetiresOnSaturation();
sub_cmd.Init(GL_TEXTURE_2D,
0,
xoffset,
yoffset,
width,
height,
test.format,
kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
}
}
}
// Test a 13x13
DoCompressedTexImage2D(GL_TEXTURE_2D,
0,
test.format,
13,
13,
0,
test.block_size * 4 * 4,
kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
{
// Accept non-multiple-of-4 width sub image if it aligns to the right
GLint xoffset = 12;
GLint width = 1;
GLint yoffset = 0;
GLint height = 4;
bucket->SetSize(test.block_size);
EXPECT_CALL(*gl_,
CompressedTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset,
width, height, test.format, _, _))
.Times(1)
.RetiresOnSaturation();
sub_cmd.Init(GL_TEXTURE_2D, 0, xoffset, yoffset, width, height,
test.format, kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
{
// Accept non-multiple-of-4 height sub image if it aligns to the bottom
GLint xoffset = 0;
GLint width = 4;
GLint yoffset = 12;
GLint height = 1;
bucket->SetSize(test.block_size);
EXPECT_CALL(*gl_,
CompressedTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset,
width, height, test.format, _, _))
.Times(1)
.RetiresOnSaturation();
sub_cmd.Init(GL_TEXTURE_2D, 0, xoffset, yoffset, width, height,
test.format, kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
{
// Check that partial blocks are still fully counted.
// Those 25 pixels still need to use 4 blocks.
GLint xoffset = 8;
GLint width = 5;
GLint yoffset = 8;
GLint height = 5;
bucket->SetSize(test.block_size * 3);
sub_cmd.Init(GL_TEXTURE_2D, 0, xoffset, yoffset, width, height,
test.format, kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
bucket->SetSize(test.block_size * 4);
EXPECT_CALL(*gl_,
CompressedTexSubImage2D(GL_TEXTURE_2D, 0, xoffset, yoffset,
width, height, test.format, _, _))
.Times(1)
.RetiresOnSaturation();
EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
}
}
TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DETC1) {
InitState init;
init.extensions = "GL_OES_compressed_ETC1_RGB8_texture";
init.gl_version = "OpenGL ES 2.0";
init.bind_generates_resource = true;
InitDecoder(init);
const uint32_t kBucketId = 123;
CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
ASSERT_TRUE(bucket != nullptr);
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
const GLenum kFormat = GL_ETC1_RGB8_OES;
const size_t kBlockSize = 8;
CompressedTexImage2DBucket cmd;
// test small width.
DoCompressedTexImage2D(GL_TEXTURE_2D, 0, kFormat, 4, 8, 0, 16, kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// test small height.
DoCompressedTexImage2D(GL_TEXTURE_2D, 0, kFormat, 8, 4, 0, 16, kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// test size too large.
cmd.Init(GL_TEXTURE_2D, 0, kFormat, 4, 4, kBucketId);
bucket->SetSize(kBlockSize * 2);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
// test size too small.
cmd.Init(GL_TEXTURE_2D, 0, kFormat, 4, 4, kBucketId);
bucket->SetSize(kBlockSize / 2);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
// Test a 16x16
DoCompressedTexImage2D(
GL_TEXTURE_2D, 0, kFormat, 16, 16, 0, kBlockSize * 16, kBucketId);
EXPECT_EQ(GL_NO_ERROR, GetGLError());
// Test CompressedTexSubImage not allowed
CompressedTexSubImage2DBucket sub_cmd;
bucket->SetSize(kBlockSize);
sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 4, kFormat, kBucketId);
EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// Test TexSubImage not allowed for ETC1 compressed texture
TextureRef* texture_ref = GetTexture(client_texture_id_);
ASSERT_TRUE(texture_ref != nullptr);
Texture* texture = texture_ref->texture();
GLenum type, internal_format;
EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
EXPECT_EQ(kFormat, internal_format);
TexSubImage2D texsub_cmd;
texsub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_RGBA, GL_UNSIGNED_BYTE,
shared_memory_id_, kSharedMemoryOffset, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(texsub_cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
// Test CopyTexSubImage not allowed for ETC1 compressed texture
CopyTexSubImage2D copy_cmd;
copy_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 4, 4);
EXPECT_EQ(error::kNoError, ExecuteCmd(copy_cmd));
EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
}
TEST_P(GLES2DecoderTest, CopyTextureCHROMIUMBadTarget) {
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_UNSIGNED_BYTE,
0, 0);
EXPECT_CALL(*gl_, GenTextures(_, _))
.WillOnce(SetArgPointee<1>(kNewServiceId))
.RetiresOnSaturation();
GenHelper<GenTexturesImmediate>(kNewClientId);
const GLenum kBadTarget = GL_RGB;
CopyTextureCHROMIUM cmd;
cmd.Init(client_texture_id_, 0, kBadTarget, kNewClientId, 0, GL_RGBA,
GL_UNSIGNED_BYTE, GL_FALSE, GL_FALSE, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
}
TEST_P(GLES2DecoderTest, CopySubTextureCHROMIUMBadTarget) {
DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_UNSIGNED_BYTE,
0, 0);
EXPECT_CALL(*gl_, GenTextures(_, _))
.WillOnce(SetArgPointee<1>(kNewServiceId))
.RetiresOnSaturation();
DoBindTexture(GL_TEXTURE_2D, kNewClientId, kNewServiceId);
DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_UNSIGNED_BYTE,
0, 0);
const GLenum kBadTarget = GL_RGB;
CopySubTextureCHROMIUM cmd;
cmd.Init(client_texture_id_, 0, kBadTarget, kNewClientId, 0, 1, 1, 2, 2, 3, 3,
GL_FALSE, GL_FALSE, GL_FALSE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
}
TEST_P(GLES2DecoderManualInitTest, EGLImageExternalBindTexture) {
InitState init;
init.extensions = "GL_OES_EGL_image_external";
init.gl_version = "OpenGL ES 2.0";
init.bind_generates_resource = true;
InitDecoder(init);
EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_EXTERNAL_OES, kNewServiceId));
EXPECT_CALL(*gl_, GenTextures(1, _))
.WillOnce(SetArgPointee<1>(kNewServiceId));
BindTexture cmd;
cmd.Init(GL_TEXTURE_EXTERNAL_OES, kNewClientId);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
TextureRef* texture_ref = GetTexture(kNewClientId);
EXPECT_TRUE(texture_ref != nullptr);
EXPECT_TRUE(texture_ref->texture()->target() == GL_TEXTURE_EXTERNAL_OES);
}
TEST_P(GLES2DecoderManualInitTest, EGLImageExternalGetBinding) {
InitState init;
init.extensions = "GL_OES_EGL_image_external";
init.gl_version = "OpenGL ES 2.0";
init.bind_generates_resource = true;
InitDecoder(init);
DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
EXPECT_CALL(*gl_, GetError())
.WillOnce(Return(GL_NO_ERROR))
.WillOnce(Return(GL_NO_ERROR))
.RetiresOnSaturation();
typedef GetIntegerv::Result Result;
Result* result = static_cast<Result*>(shared_memory_address_);
EXPECT_CALL(*gl_,
GetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, result->GetData()))
.Times(0);
result->size = 0;
GetIntegerv cmd;
cmd.Init(GL_TEXTURE_BINDING_EXTERNAL_OES,
shared_memory_id_,
shared_memory_offset_);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(
GL_TEXTURE_BINDING_EXTERNAL_OES),
result->GetNumResults());
EXPECT_EQ(GL_NO_ERROR, GetGLError());
EXPECT_EQ(client_texture_id_, (uint32_t)result->GetData()[0]);
}
TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureDefaults) {
InitState init;
init.extensions = "GL_OES_EGL_image_external";
init.gl_version = "OpenGL ES 2.0";
init.bind_generates_resource = true;
InitDecoder(init);
DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
TextureRef* texture_ref = GetTexture(client_texture_id_);
EXPECT_TRUE(texture_ref != nullptr);
Texture* texture = texture_ref->texture();
EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
}
TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureParam) {
InitState init;
init.extensions = "GL_OES_EGL_image_external";
init.gl_version = "OpenGL ES 2.0";
init.bind_generates_resource = true;
InitDecoder(init);
DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
EXPECT_CALL(*gl_,
TexParameteri(
GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
EXPECT_CALL(
*gl_,
TexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
EXPECT_CALL(
*gl_,
TexParameteri(
GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
EXPECT_CALL(
*gl_,
TexParameteri(
GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
TexParameteri cmd;
cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
TextureRef* texture_ref = GetTexture(client_texture_id_);
EXPECT_TRUE(texture_ref != nullptr);
Texture* texture = texture_ref->texture();
EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
}
TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureParamInvalid) {
InitState init;
init.extensions = "GL_OES_EGL_image_external";
init.gl_version = "OpenGL ES 2.0";
init.bind_generates_resource = true;
InitDecoder(init);
DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
TexParameteri cmd;
cmd.Init(GL_TEXTURE_EXTERNAL_OES,
GL_TEXTURE_MIN_FILTER,
GL_NEAREST_MIPMAP_NEAREST);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_REPEAT);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_REPEAT);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
TextureRef* texture_ref = GetTexture(client_texture_id_);
EXPECT_TRUE(texture_ref != nullptr);
Texture* texture = texture_ref->texture();
EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
}
TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTexImage2DError) {
InitState init;
init.extensions = "GL_OES_EGL_image_external";
init.gl_version = "OpenGL ES 2.0";
init.bind_generates_resource = true;
InitDecoder(init);
GLenum target = GL_TEXTURE_EXTERNAL_OES;
GLint level = 0;
GLenum internal_format = GL_RGBA;
GLsizei width = 2;
GLsizei height = 4;
GLenum format = GL_RGBA;
GLenum type = GL_UNSIGNED_BYTE;
DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
ASSERT_TRUE(GetTexture(client_texture_id_) != nullptr);
TexImage2D cmd;
cmd.Init(target, level, internal_format, width, height, format, type,
shared_memory_id_, kSharedMemoryOffset);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
// TexImage2D is not allowed with GL_TEXTURE_EXTERNAL_OES targets.
EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
}
TEST_P(GLES2DecoderManualInitTest, DefaultTextureZero) {
InitState init;
InitDecoder(init);
BindTexture cmd1;
cmd1.Init(GL_TEXTURE_2D, 0);
EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
BindTexture cmd2;
cmd2.Init(GL_TEXTURE_CUBE_MAP, 0);
EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
TEST_P(GLES2DecoderManualInitTest, DefaultTextureBGR) {
InitState init;
init.bind_generates_resource = true;
InitDecoder(init);
BindTexture cmd1;
cmd1.Init(GL_TEXTURE_2D, 0);
EXPECT_CALL(
*gl_, BindTexture(GL_TEXTURE_2D, TestHelper::kServiceDefaultTexture2dId));
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
BindTexture cmd2;
cmd2.Init(GL_TEXTURE_CUBE_MAP, 0);
EXPECT_CALL(*gl_,
BindTexture(GL_TEXTURE_CUBE_MAP,
TestHelper::kServiceDefaultTextureCubemapId));
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
}
// Test that default texture 0 is immutable.
TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameterf) {
InitState init;
InitDecoder(init);
{
BindTexture cmd1;
cmd1.Init(GL_TEXTURE_2D, 0);
EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
TexParameterf cmd2;
cmd2.Init(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
}
{
BindTexture cmd1;
cmd1.Init(GL_TEXTURE_CUBE_MAP, 0);
EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
EXPECT_EQ(GL_NO_ERROR, GetGLError());
TexParameterf cmd2;
cmd2.Init(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
}
}
TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameteri) {
InitState init;
InitDecoder(init);
{