Commit aabc8d68 authored by Daniel Bratell's avatar Daniel Bratell Committed by Commit Bot

Avoid "using namespace gles2" in the gpu code

Jumbo isn't compatible with "using namespace" since those cause
compiler warnings unless in the top level file, but "using namespace"
is also prohibited by the code style guide (see:
https://google.github.io/styleguide/cppguide.html#Namespaces )

This makes the code a bit more verbose, but it also makes it
more self consistent since the gles2:: prefix was already
occasionally used.

Bug: 864986
Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I7c2111e70407a7ddf65473cb83e7f63b70b18747
Reviewed-on: https://chromium-review.googlesource.com/1141882Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Commit-Queue: Daniel Bratell <bratell@opera.com>
Cr-Commit-Position: refs/heads/master@{#576159}
parent 548db201
...@@ -2186,10 +2186,10 @@ class GENnHandler(TypeHandler): ...@@ -2186,10 +2186,10 @@ class GENnHandler(TypeHandler):
def WriteGetDataSizeCode(self, func, f): def WriteGetDataSizeCode(self, func, f):
"""Overrriden from TypeHandler.""" """Overrriden from TypeHandler."""
code = """ uint32_t data_size; code = """ uint32_t data_size;
if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { if (!%sSafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
return error::kOutOfBounds; return error::kOutOfBounds;
} }
""" """ % _Namespace()
f.write(code) f.write(code)
def WriteHandlerImplementation (self, func, f): def WriteHandlerImplementation (self, func, f):
...@@ -2202,10 +2202,12 @@ class GENnHandler(TypeHandler): ...@@ -2202,10 +2202,12 @@ class GENnHandler(TypeHandler):
f.write(" auto %(name)s_copy = std::make_unique<GLuint[]>(n);\n" f.write(" auto %(name)s_copy = std::make_unique<GLuint[]>(n);\n"
" GLuint* %(name)s_safe = %(name)s_copy.get();\n" " GLuint* %(name)s_safe = %(name)s_copy.get();\n"
" std::copy(%(name)s, %(name)s + n, %(name)s_safe);\n" " std::copy(%(name)s, %(name)s + n, %(name)s_safe);\n"
" if (!CheckUniqueAndNonNullIds(n, %(name)s_safe) ||\n" " if (!%(ns)sCheckUniqueAndNonNullIds(n, %(name)s_safe) ||\n"
" !%(func)sHelper(n, %(name)s_safe)) {\n" " !%(func)sHelper(n, %(name)s_safe)) {\n"
" return error::kInvalidArguments;\n" " return error::kInvalidArguments;\n"
" }\n" % {'name': param_name, 'func': func.original_name}) " }\n" % {'name': param_name,
'func': func.original_name,
'ns': _Namespace()})
def WriteGLES2Implementation(self, func, f): def WriteGLES2Implementation(self, func, f):
"""Overrriden from TypeHandler.""" """Overrriden from TypeHandler."""
...@@ -2636,10 +2638,10 @@ class DELnHandler(TypeHandler): ...@@ -2636,10 +2638,10 @@ class DELnHandler(TypeHandler):
def WriteGetDataSizeCode(self, func, f): def WriteGetDataSizeCode(self, func, f):
"""Overrriden from TypeHandler.""" """Overrriden from TypeHandler."""
code = """ uint32_t data_size; code = """ uint32_t data_size;
if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { if (!%sSafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
return error::kOutOfBounds; return error::kOutOfBounds;
} }
""" """ % _Namespace()
f.write(code) f.write(code)
def WriteGLES2ImplementationUnitTest(self, func, f): def WriteGLES2ImplementationUnitTest(self, func, f):
...@@ -3314,11 +3316,13 @@ TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { ...@@ -3314,11 +3316,13 @@ TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
def WriteGetDataSizeCode(self, func, f): def WriteGetDataSizeCode(self, func, f):
"""Overrriden from TypeHandler.""" """Overrriden from TypeHandler."""
code = """ uint32_t data_size; code = """ uint32_t data_size;
if (!GLES2Util::ComputeDataSize<%s, %d>(1, &data_size)) { if (!%sGLES2Util::ComputeDataSize<%s, %d>(1, &data_size)) {
return error::kOutOfBounds; return error::kOutOfBounds;
} }
""" """
f.write(code % (self.GetArrayType(func), self.GetArrayCount(func))) f.write(code % (_Namespace(),
self.GetArrayType(func),
self.GetArrayCount(func)))
if func.IsImmediate(): if func.IsImmediate():
f.write(" if (data_size > immediate_data_size) {\n") f.write(" if (data_size > immediate_data_size) {\n")
f.write(" return error::kOutOfBounds;\n") f.write(" return error::kOutOfBounds;\n")
...@@ -3341,8 +3345,8 @@ TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { ...@@ -3341,8 +3345,8 @@ TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
self.WriteClientGLCallLog(func, f) self.WriteClientGLCallLog(func, f)
if self.__NeedsToCalcDataCount(func): if self.__NeedsToCalcDataCount(func):
f.write(" size_t count = GLES2Util::Calc%sDataCount(%s);\n" % f.write(" size_t count = %sGLES2Util::Calc%sDataCount(%s);\n" %
(func.name, func.GetOriginalArgs()[0].name)) (_Namespace(), func.name, func.GetOriginalArgs()[0].name))
f.write(" DCHECK_LE(count, %du);\n" % self.GetArrayCount(func)) f.write(" DCHECK_LE(count, %du);\n" % self.GetArrayCount(func))
else: else:
f.write(" size_t count = %d;" % self.GetArrayCount(func)) f.write(" size_t count = %d;" % self.GetArrayCount(func))
...@@ -3408,8 +3412,8 @@ TEST_F(%(prefix)sImplementationTest, %(name)s) { ...@@ -3408,8 +3412,8 @@ TEST_F(%(prefix)sImplementationTest, %(name)s) {
(func.GetOriginalArgs()[0].type, (func.GetOriginalArgs()[0].type,
func.GetOriginalArgs()[0].name)) func.GetOriginalArgs()[0].name))
f.write(" return static_cast<uint32_t>(\n") f.write(" return static_cast<uint32_t>(\n")
f.write(" sizeof(%s) * GLES2Util::Calc%sDataCount(%s));\n" % f.write(" sizeof(%s) * %sGLES2Util::Calc%sDataCount(%s));\n" %
(self.GetArrayType(func), func.original_name, (self.GetArrayType(func), _Namespace(), func.original_name,
func.GetOriginalArgs()[0].name)) func.GetOriginalArgs()[0].name))
f.write(" }\n") f.write(" }\n")
f.write("\n") f.write("\n")
...@@ -3614,11 +3618,12 @@ TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) { ...@@ -3614,11 +3618,12 @@ TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
"""Overrriden from TypeHandler.""" """Overrriden from TypeHandler."""
code = """ uint32_t data_size = 0; code = """ uint32_t data_size = 0;
if (count >= 0 && if (count >= 0 &&
!GLES2Util::ComputeDataSize<%s, %d>(count, &data_size)) { !%sGLES2Util::ComputeDataSize<%s, %d>(count, &data_size)) {
return error::kOutOfBounds; return error::kOutOfBounds;
} }
""" """
f.write(code % (self.GetArrayType(func), f.write(code % (_Namespace(),
self.GetArrayType(func),
self.GetArrayCount(func))) self.GetArrayCount(func)))
if func.IsImmediate(): if func.IsImmediate():
f.write(" if (data_size > immediate_data_size) {\n") f.write(" if (data_size > immediate_data_size) {\n")
...@@ -4893,9 +4898,9 @@ class Argument(object): ...@@ -4893,9 +4898,9 @@ class Argument(object):
def GetLogArg(self): def GetLogArg(self):
"""Get argument appropriate for LOG macro.""" """Get argument appropriate for LOG macro."""
if self.type == 'GLboolean': if self.type == 'GLboolean':
return 'GLES2Util::GetStringBool(%s)' % self.name return '%sGLES2Util::GetStringBool(%s)' % (_Namespace(), self.name)
if self.type == 'GLenum': if self.type == 'GLenum':
return 'GLES2Util::GetStringEnum(%s)' % self.name return '%sGLES2Util::GetStringEnum(%s)' % (_Namespace(), self.name)
return self.name return self.name
def WriteGetCode(self, f): def WriteGetCode(self, f):
...@@ -5250,8 +5255,8 @@ class ImmediatePointerArgument(Argument): ...@@ -5250,8 +5255,8 @@ class ImmediatePointerArgument(Argument):
def WriteGetCode(self, f): def WriteGetCode(self, f):
"""Overridden from Argument.""" """Overridden from Argument."""
f.write(" volatile %s %s = GetImmediateDataAs<volatile %s>(\n" % f.write(" volatile %s %s = %sGetImmediateDataAs<volatile %s>(\n" %
(self.type, self.name, self.type)) (self.type, self.name, _Namespace(), self.type))
f.write(" c, data_size, immediate_data_size);\n") f.write(" c, data_size, immediate_data_size);\n")
def WriteValidationCode(self, f, func): def WriteValidationCode(self, f, func):
......
...@@ -20,11 +20,12 @@ error::Error RasterDecoderImpl::HandleDeleteTexturesImmediate( ...@@ -20,11 +20,12 @@ error::Error RasterDecoderImpl::HandleDeleteTexturesImmediate(
cmd_data); cmd_data);
GLsizei n = static_cast<GLsizei>(c.n); GLsizei n = static_cast<GLsizei>(c.n);
uint32_t data_size; uint32_t data_size;
if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { if (!gles2::SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
return error::kOutOfBounds; return error::kOutOfBounds;
} }
volatile const GLuint* textures = GetImmediateDataAs<volatile const GLuint*>( volatile const GLuint* textures =
c, data_size, immediate_data_size); gles2::GetImmediateDataAs<volatile const GLuint*>(c, data_size,
immediate_data_size);
if (textures == NULL) { if (textures == NULL) {
return error::kOutOfBounds; return error::kOutOfBounds;
} }
...@@ -101,18 +102,18 @@ error::Error RasterDecoderImpl::HandleGenQueriesEXTImmediate( ...@@ -101,18 +102,18 @@ error::Error RasterDecoderImpl::HandleGenQueriesEXTImmediate(
cmd_data); cmd_data);
GLsizei n = static_cast<GLsizei>(c.n); GLsizei n = static_cast<GLsizei>(c.n);
uint32_t data_size; uint32_t data_size;
if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { if (!gles2::SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
return error::kOutOfBounds; return error::kOutOfBounds;
} }
volatile GLuint* queries = volatile GLuint* queries = gles2::GetImmediateDataAs<volatile GLuint*>(
GetImmediateDataAs<volatile GLuint*>(c, data_size, immediate_data_size); c, data_size, immediate_data_size);
if (queries == NULL) { if (queries == NULL) {
return error::kOutOfBounds; return error::kOutOfBounds;
} }
auto queries_copy = std::make_unique<GLuint[]>(n); auto queries_copy = std::make_unique<GLuint[]>(n);
GLuint* queries_safe = queries_copy.get(); GLuint* queries_safe = queries_copy.get();
std::copy(queries, queries + n, queries_safe); std::copy(queries, queries + n, queries_safe);
if (!CheckUniqueAndNonNullIds(n, queries_safe) || if (!gles2::CheckUniqueAndNonNullIds(n, queries_safe) ||
!GenQueriesEXTHelper(n, queries_safe)) { !GenQueriesEXTHelper(n, queries_safe)) {
return error::kInvalidArguments; return error::kInvalidArguments;
} }
...@@ -127,11 +128,12 @@ error::Error RasterDecoderImpl::HandleDeleteQueriesEXTImmediate( ...@@ -127,11 +128,12 @@ error::Error RasterDecoderImpl::HandleDeleteQueriesEXTImmediate(
cmd_data); cmd_data);
GLsizei n = static_cast<GLsizei>(c.n); GLsizei n = static_cast<GLsizei>(c.n);
uint32_t data_size; uint32_t data_size;
if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) { if (!gles2::SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
return error::kOutOfBounds; return error::kOutOfBounds;
} }
volatile const GLuint* queries = GetImmediateDataAs<volatile const GLuint*>( volatile const GLuint* queries =
c, data_size, immediate_data_size); gles2::GetImmediateDataAs<volatile const GLuint*>(c, data_size,
immediate_data_size);
if (queries == NULL) { if (queries == NULL) {
return error::kOutOfBounds; return error::kOutOfBounds;
} }
...@@ -335,14 +337,14 @@ error::Error RasterDecoderImpl::HandleProduceTextureDirectImmediate( ...@@ -335,14 +337,14 @@ error::Error RasterDecoderImpl::HandleProduceTextureDirectImmediate(
cmd_data); cmd_data);
GLuint texture = static_cast<GLuint>(c.texture); GLuint texture = static_cast<GLuint>(c.texture);
uint32_t data_size; uint32_t data_size;
if (!GLES2Util::ComputeDataSize<GLbyte, 16>(1, &data_size)) { if (!gles2::GLES2Util::ComputeDataSize<GLbyte, 16>(1, &data_size)) {
return error::kOutOfBounds; return error::kOutOfBounds;
} }
if (data_size > immediate_data_size) { if (data_size > immediate_data_size) {
return error::kOutOfBounds; return error::kOutOfBounds;
} }
volatile GLbyte* mailbox = volatile GLbyte* mailbox = gles2::GetImmediateDataAs<volatile GLbyte*>(
GetImmediateDataAs<volatile GLbyte*>(c, data_size, immediate_data_size); c, data_size, immediate_data_size);
if (mailbox == NULL) { if (mailbox == NULL) {
return error::kOutOfBounds; return error::kOutOfBounds;
} }
...@@ -361,14 +363,15 @@ error::Error RasterDecoderImpl::HandleCreateAndConsumeTextureINTERNALImmediate( ...@@ -361,14 +363,15 @@ error::Error RasterDecoderImpl::HandleCreateAndConsumeTextureINTERNALImmediate(
gfx::BufferUsage buffer_usage = static_cast<gfx::BufferUsage>(c.buffer_usage); gfx::BufferUsage buffer_usage = static_cast<gfx::BufferUsage>(c.buffer_usage);
viz::ResourceFormat format = static_cast<viz::ResourceFormat>(c.format); viz::ResourceFormat format = static_cast<viz::ResourceFormat>(c.format);
uint32_t data_size; uint32_t data_size;
if (!GLES2Util::ComputeDataSize<GLbyte, 16>(1, &data_size)) { if (!gles2::GLES2Util::ComputeDataSize<GLbyte, 16>(1, &data_size)) {
return error::kOutOfBounds; return error::kOutOfBounds;
} }
if (data_size > immediate_data_size) { if (data_size > immediate_data_size) {
return error::kOutOfBounds; return error::kOutOfBounds;
} }
volatile const GLbyte* mailbox = GetImmediateDataAs<volatile const GLbyte*>( volatile const GLbyte* mailbox =
c, data_size, immediate_data_size); gles2::GetImmediateDataAs<volatile const GLbyte*>(c, data_size,
immediate_data_size);
if (!validators_->gfx_buffer_usage.IsValid(buffer_usage)) { if (!validators_->gfx_buffer_usage.IsValid(buffer_usage)) {
LOCAL_SET_GL_ERROR_INVALID_ENUM("glCreateAndConsumeTextureINTERNAL", LOCAL_SET_GL_ERROR_INVALID_ENUM("glCreateAndConsumeTextureINTERNAL",
buffer_usage, "buffer_usage"); buffer_usage, "buffer_usage");
......
...@@ -44,8 +44,6 @@ using ::testing::Return; ...@@ -44,8 +44,6 @@ using ::testing::Return;
using ::testing::SetArgPointee; using ::testing::SetArgPointee;
using ::testing::StrictMock; using ::testing::StrictMock;
using namespace gpu::gles2;
namespace gpu { namespace gpu {
namespace raster { namespace raster {
...@@ -185,10 +183,10 @@ void RasterDecoderTestBase::InitDecoder(const InitState& init) { ...@@ -185,10 +183,10 @@ void RasterDecoderTestBase::InitDecoder(const InitState& init) {
::gl::MockGLInterface::SetGLInterface(gl_.get()); ::gl::MockGLInterface::SetGLInterface(gl_.get());
GpuFeatureInfo gpu_feature_info; GpuFeatureInfo gpu_feature_info;
scoped_refptr<FeatureInfo> feature_info = scoped_refptr<gles2::FeatureInfo> feature_info =
new FeatureInfo(init.workarounds, gpu_feature_info); new gles2::FeatureInfo(init.workarounds, gpu_feature_info);
group_ = scoped_refptr<ContextGroup>(new ContextGroup( group_ = scoped_refptr<gles2::ContextGroup>(new gles2::ContextGroup(
gpu_preferences_, false, &mailbox_manager_, memory_tracker_, gpu_preferences_, false, &mailbox_manager_, memory_tracker_,
&shader_translator_cache_, &framebuffer_completeness_cache_, feature_info, &shader_translator_cache_, &framebuffer_completeness_cache_, feature_info,
bind_generates_resource, &image_manager_, nullptr /* image_factory */, bind_generates_resource, &image_manager_, nullptr /* image_factory */,
...@@ -208,8 +206,8 @@ void RasterDecoderTestBase::InitDecoder(const InitState& init) { ...@@ -208,8 +206,8 @@ void RasterDecoderTestBase::InitDecoder(const InitState& init) {
context_->GLContextStub::MakeCurrent(surface_.get()); context_->GLContextStub::MakeCurrent(surface_.get());
TestHelper::SetupContextGroupInitExpectations( gles2::TestHelper::SetupContextGroupInitExpectations(
gl_.get(), DisallowedFeatures(), all_extensions.c_str(), gl_.get(), gles2::DisallowedFeatures(), all_extensions.c_str(),
init.gl_version.c_str(), context_type, bind_generates_resource); init.gl_version.c_str(), context_type, bind_generates_resource);
// We initialize the ContextGroup with a MockRasterDecoder so that // We initialize the ContextGroup with a MockRasterDecoder so that
...@@ -219,7 +217,7 @@ void RasterDecoderTestBase::InitDecoder(const InitState& init) { ...@@ -219,7 +217,7 @@ void RasterDecoderTestBase::InitDecoder(const InitState& init) {
mock_decoder_.reset(new MockRasterDecoder(command_buffer_service_.get())); mock_decoder_.reset(new MockRasterDecoder(command_buffer_service_.get()));
EXPECT_EQ(group_->Initialize(mock_decoder_.get(), context_type, EXPECT_EQ(group_->Initialize(mock_decoder_.get(), context_type,
DisallowedFeatures()), gles2::DisallowedFeatures()),
gpu::ContextResult::kSuccess); gpu::ContextResult::kSuccess);
scoped_refptr<gpu::Buffer> buffer = scoped_refptr<gpu::Buffer> buffer =
...@@ -249,14 +247,15 @@ void RasterDecoderTestBase::InitDecoder(const InitState& init) { ...@@ -249,14 +247,15 @@ void RasterDecoderTestBase::InitDecoder(const InitState& init) {
AddExpectationsForBindVertexArrayOES(); AddExpectationsForBindVertexArrayOES();
bool use_default_textures = bind_generates_resource; bool use_default_textures = bind_generates_resource;
for (GLint tt = 0; tt < TestHelper::kNumTextureUnits; ++tt) { for (GLint tt = 0; tt < gles2::TestHelper::kNumTextureUnits; ++tt) {
EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0 + tt)) EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0 + tt))
.Times(1) .Times(1)
.RetiresOnSaturation(); .RetiresOnSaturation();
EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, EXPECT_CALL(*gl_,
use_default_textures BindTexture(GL_TEXTURE_2D,
? TestHelper::kServiceDefaultTexture2dId use_default_textures
: 0)) ? gles2::TestHelper::kServiceDefaultTexture2dId
: 0))
.Times(1) .Times(1)
.RetiresOnSaturation(); .RetiresOnSaturation();
} }
...@@ -275,11 +274,11 @@ void RasterDecoderTestBase::InitDecoder(const InitState& init) { ...@@ -275,11 +274,11 @@ void RasterDecoderTestBase::InitDecoder(const InitState& init) {
decoder_->SetIgnoreCachedStateForTest(ignore_cached_state_for_test_); decoder_->SetIgnoreCachedStateForTest(ignore_cached_state_for_test_);
decoder_->GetLogger()->set_log_synthesized_gl_errors(false); decoder_->GetLogger()->set_log_synthesized_gl_errors(false);
copy_texture_manager_ = new MockCopyTextureResourceManager(); copy_texture_manager_ = new gles2::MockCopyTextureResourceManager();
decoder_->SetCopyTextureResourceManagerForTest(copy_texture_manager_); decoder_->SetCopyTextureResourceManagerForTest(copy_texture_manager_);
ASSERT_EQ(decoder_->Initialize(surface_, context_, true, DisallowedFeatures(), ASSERT_EQ(decoder_->Initialize(surface_, context_, true,
attribs), gles2::DisallowedFeatures(), attribs),
gpu::ContextResult::kSuccess); gpu::ContextResult::kSuccess);
EXPECT_CALL(*context_, MakeCurrent(surface_.get())).WillOnce(Return(true)); EXPECT_CALL(*context_, MakeCurrent(surface_.get())).WillOnce(Return(true));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment