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):
def WriteGetDataSizeCode(self, func, f):
"""Overrriden from TypeHandler."""
code = """ uint32_t data_size;
if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
if (!%sSafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
return error::kOutOfBounds;
}
"""
""" % _Namespace()
f.write(code)
def WriteHandlerImplementation (self, func, f):
......@@ -2202,10 +2202,12 @@ class GENnHandler(TypeHandler):
f.write(" auto %(name)s_copy = std::make_unique<GLuint[]>(n);\n"
" GLuint* %(name)s_safe = %(name)s_copy.get();\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"
" 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):
"""Overrriden from TypeHandler."""
......@@ -2636,10 +2638,10 @@ class DELnHandler(TypeHandler):
def WriteGetDataSizeCode(self, func, f):
"""Overrriden from TypeHandler."""
code = """ uint32_t data_size;
if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
if (!%sSafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
return error::kOutOfBounds;
}
"""
""" % _Namespace()
f.write(code)
def WriteGLES2ImplementationUnitTest(self, func, f):
......@@ -3314,11 +3316,13 @@ TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
def WriteGetDataSizeCode(self, func, f):
"""Overrriden from TypeHandler."""
code = """ uint32_t data_size;
if (!GLES2Util::ComputeDataSize<%s, %d>(1, &data_size)) {
if (!%sGLES2Util::ComputeDataSize<%s, %d>(1, &data_size)) {
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():
f.write(" if (data_size > immediate_data_size) {\n")
f.write(" return error::kOutOfBounds;\n")
......@@ -3341,8 +3345,8 @@ TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
self.WriteClientGLCallLog(func, f)
if self.__NeedsToCalcDataCount(func):
f.write(" size_t count = GLES2Util::Calc%sDataCount(%s);\n" %
(func.name, func.GetOriginalArgs()[0].name))
f.write(" size_t count = %sGLES2Util::Calc%sDataCount(%s);\n" %
(_Namespace(), func.name, func.GetOriginalArgs()[0].name))
f.write(" DCHECK_LE(count, %du);\n" % self.GetArrayCount(func))
else:
f.write(" size_t count = %d;" % self.GetArrayCount(func))
......@@ -3408,8 +3412,8 @@ TEST_F(%(prefix)sImplementationTest, %(name)s) {
(func.GetOriginalArgs()[0].type,
func.GetOriginalArgs()[0].name))
f.write(" return static_cast<uint32_t>(\n")
f.write(" sizeof(%s) * GLES2Util::Calc%sDataCount(%s));\n" %
(self.GetArrayType(func), func.original_name,
f.write(" sizeof(%s) * %sGLES2Util::Calc%sDataCount(%s));\n" %
(self.GetArrayType(func), _Namespace(), func.original_name,
func.GetOriginalArgs()[0].name))
f.write(" }\n")
f.write("\n")
......@@ -3614,11 +3618,12 @@ TEST_P(%(test_name)s, %(name)sInvalidArgs%(arg_index)d_%(value_index)d) {
"""Overrriden from TypeHandler."""
code = """ uint32_t data_size = 0;
if (count >= 0 &&
!GLES2Util::ComputeDataSize<%s, %d>(count, &data_size)) {
!%sGLES2Util::ComputeDataSize<%s, %d>(count, &data_size)) {
return error::kOutOfBounds;
}
"""
f.write(code % (self.GetArrayType(func),
f.write(code % (_Namespace(),
self.GetArrayType(func),
self.GetArrayCount(func)))
if func.IsImmediate():
f.write(" if (data_size > immediate_data_size) {\n")
......@@ -4893,9 +4898,9 @@ class Argument(object):
def GetLogArg(self):
"""Get argument appropriate for LOG macro."""
if self.type == 'GLboolean':
return 'GLES2Util::GetStringBool(%s)' % self.name
return '%sGLES2Util::GetStringBool(%s)' % (_Namespace(), self.name)
if self.type == 'GLenum':
return 'GLES2Util::GetStringEnum(%s)' % self.name
return '%sGLES2Util::GetStringEnum(%s)' % (_Namespace(), self.name)
return self.name
def WriteGetCode(self, f):
......@@ -5250,8 +5255,8 @@ class ImmediatePointerArgument(Argument):
def WriteGetCode(self, f):
"""Overridden from Argument."""
f.write(" volatile %s %s = GetImmediateDataAs<volatile %s>(\n" %
(self.type, self.name, self.type))
f.write(" volatile %s %s = %sGetImmediateDataAs<volatile %s>(\n" %
(self.type, self.name, _Namespace(), self.type))
f.write(" c, data_size, immediate_data_size);\n")
def WriteValidationCode(self, f, func):
......
......@@ -20,11 +20,12 @@ error::Error RasterDecoderImpl::HandleDeleteTexturesImmediate(
cmd_data);
GLsizei n = static_cast<GLsizei>(c.n);
uint32_t data_size;
if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
if (!gles2::SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
return error::kOutOfBounds;
}
volatile const GLuint* textures = GetImmediateDataAs<volatile const GLuint*>(
c, data_size, immediate_data_size);
volatile const GLuint* textures =
gles2::GetImmediateDataAs<volatile const GLuint*>(c, data_size,
immediate_data_size);
if (textures == NULL) {
return error::kOutOfBounds;
}
......@@ -101,18 +102,18 @@ error::Error RasterDecoderImpl::HandleGenQueriesEXTImmediate(
cmd_data);
GLsizei n = static_cast<GLsizei>(c.n);
uint32_t data_size;
if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
if (!gles2::SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
return error::kOutOfBounds;
}
volatile GLuint* queries =
GetImmediateDataAs<volatile GLuint*>(c, data_size, immediate_data_size);
volatile GLuint* queries = gles2::GetImmediateDataAs<volatile GLuint*>(
c, data_size, immediate_data_size);
if (queries == NULL) {
return error::kOutOfBounds;
}
auto queries_copy = std::make_unique<GLuint[]>(n);
GLuint* queries_safe = queries_copy.get();
std::copy(queries, queries + n, queries_safe);
if (!CheckUniqueAndNonNullIds(n, queries_safe) ||
if (!gles2::CheckUniqueAndNonNullIds(n, queries_safe) ||
!GenQueriesEXTHelper(n, queries_safe)) {
return error::kInvalidArguments;
}
......@@ -127,11 +128,12 @@ error::Error RasterDecoderImpl::HandleDeleteQueriesEXTImmediate(
cmd_data);
GLsizei n = static_cast<GLsizei>(c.n);
uint32_t data_size;
if (!SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
if (!gles2::SafeMultiplyUint32(n, sizeof(GLuint), &data_size)) {
return error::kOutOfBounds;
}
volatile const GLuint* queries = GetImmediateDataAs<volatile const GLuint*>(
c, data_size, immediate_data_size);
volatile const GLuint* queries =
gles2::GetImmediateDataAs<volatile const GLuint*>(c, data_size,
immediate_data_size);
if (queries == NULL) {
return error::kOutOfBounds;
}
......@@ -335,14 +337,14 @@ error::Error RasterDecoderImpl::HandleProduceTextureDirectImmediate(
cmd_data);
GLuint texture = static_cast<GLuint>(c.texture);
uint32_t data_size;
if (!GLES2Util::ComputeDataSize<GLbyte, 16>(1, &data_size)) {
if (!gles2::GLES2Util::ComputeDataSize<GLbyte, 16>(1, &data_size)) {
return error::kOutOfBounds;
}
if (data_size > immediate_data_size) {
return error::kOutOfBounds;
}
volatile GLbyte* mailbox =
GetImmediateDataAs<volatile GLbyte*>(c, data_size, immediate_data_size);
volatile GLbyte* mailbox = gles2::GetImmediateDataAs<volatile GLbyte*>(
c, data_size, immediate_data_size);
if (mailbox == NULL) {
return error::kOutOfBounds;
}
......@@ -361,14 +363,15 @@ error::Error RasterDecoderImpl::HandleCreateAndConsumeTextureINTERNALImmediate(
gfx::BufferUsage buffer_usage = static_cast<gfx::BufferUsage>(c.buffer_usage);
viz::ResourceFormat format = static_cast<viz::ResourceFormat>(c.format);
uint32_t data_size;
if (!GLES2Util::ComputeDataSize<GLbyte, 16>(1, &data_size)) {
if (!gles2::GLES2Util::ComputeDataSize<GLbyte, 16>(1, &data_size)) {
return error::kOutOfBounds;
}
if (data_size > immediate_data_size) {
return error::kOutOfBounds;
}
volatile const GLbyte* mailbox = GetImmediateDataAs<volatile const GLbyte*>(
c, data_size, immediate_data_size);
volatile const GLbyte* mailbox =
gles2::GetImmediateDataAs<volatile const GLbyte*>(c, data_size,
immediate_data_size);
if (!validators_->gfx_buffer_usage.IsValid(buffer_usage)) {
LOCAL_SET_GL_ERROR_INVALID_ENUM("glCreateAndConsumeTextureINTERNAL",
buffer_usage, "buffer_usage");
......
......@@ -44,8 +44,6 @@ using ::testing::Return;
using ::testing::SetArgPointee;
using ::testing::StrictMock;
using namespace gpu::gles2;
namespace gpu {
namespace raster {
......@@ -185,10 +183,10 @@ void RasterDecoderTestBase::InitDecoder(const InitState& init) {
::gl::MockGLInterface::SetGLInterface(gl_.get());
GpuFeatureInfo gpu_feature_info;
scoped_refptr<FeatureInfo> feature_info =
new FeatureInfo(init.workarounds, gpu_feature_info);
scoped_refptr<gles2::FeatureInfo> 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_,
&shader_translator_cache_, &framebuffer_completeness_cache_, feature_info,
bind_generates_resource, &image_manager_, nullptr /* image_factory */,
......@@ -208,8 +206,8 @@ void RasterDecoderTestBase::InitDecoder(const InitState& init) {
context_->GLContextStub::MakeCurrent(surface_.get());
TestHelper::SetupContextGroupInitExpectations(
gl_.get(), DisallowedFeatures(), all_extensions.c_str(),
gles2::TestHelper::SetupContextGroupInitExpectations(
gl_.get(), gles2::DisallowedFeatures(), all_extensions.c_str(),
init.gl_version.c_str(), context_type, bind_generates_resource);
// We initialize the ContextGroup with a MockRasterDecoder so that
......@@ -219,7 +217,7 @@ void RasterDecoderTestBase::InitDecoder(const InitState& init) {
mock_decoder_.reset(new MockRasterDecoder(command_buffer_service_.get()));
EXPECT_EQ(group_->Initialize(mock_decoder_.get(), context_type,
DisallowedFeatures()),
gles2::DisallowedFeatures()),
gpu::ContextResult::kSuccess);
scoped_refptr<gpu::Buffer> buffer =
......@@ -249,14 +247,15 @@ void RasterDecoderTestBase::InitDecoder(const InitState& init) {
AddExpectationsForBindVertexArrayOES();
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))
.Times(1)
.RetiresOnSaturation();
EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D,
use_default_textures
? TestHelper::kServiceDefaultTexture2dId
: 0))
EXPECT_CALL(*gl_,
BindTexture(GL_TEXTURE_2D,
use_default_textures
? gles2::TestHelper::kServiceDefaultTexture2dId
: 0))
.Times(1)
.RetiresOnSaturation();
}
......@@ -275,11 +274,11 @@ void RasterDecoderTestBase::InitDecoder(const InitState& init) {
decoder_->SetIgnoreCachedStateForTest(ignore_cached_state_for_test_);
decoder_->GetLogger()->set_log_synthesized_gl_errors(false);
copy_texture_manager_ = new MockCopyTextureResourceManager();
copy_texture_manager_ = new gles2::MockCopyTextureResourceManager();
decoder_->SetCopyTextureResourceManagerForTest(copy_texture_manager_);
ASSERT_EQ(decoder_->Initialize(surface_, context_, true, DisallowedFeatures(),
attribs),
ASSERT_EQ(decoder_->Initialize(surface_, context_, true,
gles2::DisallowedFeatures(), attribs),
gpu::ContextResult::kSuccess);
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