Rollback r942.
MapLongVariableNames inherits from TIntermTraverser, and TIntermTraverser uses ANGLE's memory allocator, thus the memory is released per compilation. Our design is for MapLongVariableNames to be a singleton across all compilations, thus, this is not working.
BUG=
TEST=
TBR=kbr
Review URL: https://codereview.appspot.com/5556053
git-svn-id: https://angleproject.googlecode.com/svn/trunk@949 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/Compiler.cpp b/src/compiler/Compiler.cpp
index 3a50319..22764bd 100644
--- a/src/compiler/Compiler.cpp
+++ b/src/compiler/Compiler.cpp
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
@@ -89,15 +89,12 @@
TCompiler::TCompiler(ShShaderType type, ShShaderSpec spec)
: shaderType(type),
shaderSpec(spec),
- builtInFunctionEmulator(type),
- longNameMapper(NULL)
+ builtInFunctionEmulator(type)
{
}
TCompiler::~TCompiler()
{
- if (longNameMapper)
- longNameMapper->Release();
}
bool TCompiler::Init(const ShBuiltInResources& resources)
@@ -249,9 +246,8 @@
void TCompiler::mapLongVariableNames(TIntermNode* root)
{
- if (longNameMapper == NULL)
- longNameMapper = MapLongVariableNames::GetInstance();
- root->traverse(longNameMapper);
+ MapLongVariableNames map(varyingLongNameMap);
+ root->traverse(&map);
}
int TCompiler::getMappedNameMaxLength() const
diff --git a/src/compiler/MapLongVariableNames.cpp b/src/compiler/MapLongVariableNames.cpp
index 678f674..3c5d356 100644
--- a/src/compiler/MapLongVariableNames.cpp
+++ b/src/compiler/MapLongVariableNames.cpp
@@ -8,51 +8,26 @@
namespace {
-TString mapLongName(int id, const TString& name, bool global)
+TString mapLongName(int id, const TString& name, bool isVarying)
{
ASSERT(name.size() > MAX_SHORTENED_IDENTIFIER_SIZE);
TStringStream stream;
stream << "webgl_";
- if (global)
- stream << "g";
+ if (isVarying)
+ stream << "v";
stream << id << "_";
stream << name.substr(0, MAX_SHORTENED_IDENTIFIER_SIZE - stream.str().size());
return stream.str();
}
-MapLongVariableNames* gMapLongVariableNamesInstance = NULL;
-
} // anonymous namespace
-MapLongVariableNames::MapLongVariableNames()
- : refCount(0)
+MapLongVariableNames::MapLongVariableNames(
+ std::map<std::string, std::string>& varyingLongNameMap)
+ : mVaryingLongNameMap(varyingLongNameMap)
{
}
-MapLongVariableNames::~MapLongVariableNames()
-{
-}
-
-// static
-MapLongVariableNames* MapLongVariableNames::GetInstance()
-{
- if (gMapLongVariableNamesInstance == NULL)
- gMapLongVariableNamesInstance = new MapLongVariableNames;
- gMapLongVariableNamesInstance->refCount++;
- return gMapLongVariableNamesInstance;
-}
-
-void MapLongVariableNames::Release()
-{
- ASSERT(gMapLongVariableNamesInstance == this);
- ASSERT(refCount > 0);
- refCount--;
- if (refCount == 0) {
- delete gMapLongVariableNamesInstance;
- gMapLongVariableNamesInstance = NULL;
- }
-}
-
void MapLongVariableNames::visitSymbol(TIntermSymbol* symbol)
{
ASSERT(symbol != NULL);
@@ -64,7 +39,7 @@
case EvqInvariantVaryingOut:
case EvqUniform:
symbol->setSymbol(
- mapLongGlobalName(symbol->getSymbol()));
+ mapVaryingLongName(symbol->getSymbol()));
break;
default:
symbol->setSymbol(
@@ -81,15 +56,15 @@
return true;
}
-TString MapLongVariableNames::mapLongGlobalName(const TString& name)
+TString MapLongVariableNames::mapVaryingLongName(const TString& name)
{
- std::map<std::string, std::string>::const_iterator it = longGlobalNameMap.find(name.c_str());
- if (it != longGlobalNameMap.end())
+ std::map<std::string, std::string>::const_iterator it = mVaryingLongNameMap.find(name.c_str());
+ if (it != mVaryingLongNameMap.end())
return (*it).second.c_str();
- int id = longGlobalNameMap.size();
+ int id = mVaryingLongNameMap.size();
TString mappedName = mapLongName(id, name, true);
- longGlobalNameMap.insert(
+ mVaryingLongNameMap.insert(
std::map<std::string, std::string>::value_type(name.c_str(), mappedName.c_str()));
return mappedName;
}
diff --git a/src/compiler/MapLongVariableNames.h b/src/compiler/MapLongVariableNames.h
index 0a5d609..086f2b9 100644
--- a/src/compiler/MapLongVariableNames.h
+++ b/src/compiler/MapLongVariableNames.h
@@ -1,5 +1,5 @@
//
-// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved.
+// Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
@@ -15,30 +15,19 @@
// This size does not include '\0' in the end.
#define MAX_SHORTENED_IDENTIFIER_SIZE 32
-// MapLongVariableNames is implemented as a ref-counted singleton. The first
-// call of GetInstance() will create an instance and return it; latter calls
-// will return the same instance, with ref-count increased. Release() will
-// reduce the ref-count, and when no more reference, release the instance.
-
// Traverses intermediate tree to map attributes and uniforms names that are
// longer than MAX_SHORTENED_IDENTIFIER_SIZE to MAX_SHORTENED_IDENTIFIER_SIZE.
class MapLongVariableNames : public TIntermTraverser {
public:
- static MapLongVariableNames* GetInstance();
- void Release();
+ MapLongVariableNames(std::map<std::string, std::string>& varyingLongNameMap);
virtual void visitSymbol(TIntermSymbol*);
virtual bool visitLoop(Visit, TIntermLoop*);
private:
- MapLongVariableNames();
- virtual ~MapLongVariableNames();
+ TString mapVaryingLongName(const TString& name);
- TString mapLongGlobalName(const TString& name);
-
- // Pair of long global varibale name <originalName, mappedName>.
- std::map<std::string, std::string> longGlobalNameMap;
- size_t refCount;
+ std::map<std::string, std::string>& mVaryingLongNameMap;
};
#endif // COMPILER_MAP_LONG_VARIABLE_NAMES_H_
diff --git a/src/compiler/ShHandle.h b/src/compiler/ShHandle.h
index a775460..8ddf0f1 100644
--- a/src/compiler/ShHandle.h
+++ b/src/compiler/ShHandle.h
@@ -22,7 +22,6 @@
#include "compiler/SymbolTable.h"
#include "compiler/VariableInfo.h"
-class MapLongVariableNames;
class TCompiler;
//
@@ -101,8 +100,8 @@
TVariableInfoList attribs; // Active attributes in the compiled shader.
TVariableInfoList uniforms; // Active uniforms in the compiled shader.
- // Local instance of the ref-counted singleton.
- MapLongVariableNames* longNameMapper;
+ // Pair of long varying varibale name <originalName, mappedName>.
+ std::map<std::string, std::string> varyingLongNameMap;
};
//