}
void copyAndTakeOwnership(CachedData& other) {
- memcpy(this, &other, sizeof(this));
+ memcpy(this, &other, sizeof(*this));
other.fEffectUniLocationsExtended = NULL; // ownership transfer
GR_DEBUGCODE(other.fEffectUniCount = 0;)
}
class Entry : public ::GrNoncopyable {
public:
Entry() {}
- private:
void copyAndTakeOwnership(Entry& entry) {
fProgramData.copyAndTakeOwnership(entry.fProgramData);
fKey.copyAndTakeOwnership(entry.fKey); // ownership transfer
GrTHashTable<Entry, ProgramHashKey, 8> fHashCache;
+ // We may have kMaxEntries+1 shaders in the GL context because
+ // we create a new shader before evicting from the cache.
enum {
kMaxEntries = 32
};
}
GrGLProgram::CachedData* getProgramData(const GrGLProgram& desc) {
- ProgramHashKey key;
- while (key.doPass()) {
- desc.buildKey(key);
+ Entry newEntry;
+ while (newEntry.fKey.doPass()) {
+ desc.buildKey(newEntry.fKey);
}
- Entry* entry = fHashCache.find(key);
+ Entry* entry = fHashCache.find(newEntry.fKey);
if (NULL == entry) {
+ if (!desc.genProgram(&newEntry.fProgramData)) {
+ return NULL;
+ }
if (fCount < kMaxEntries) {
entry = fEntries + fCount;
++fCount;
fHashCache.remove(entry->fKey, entry);
GrGpuGLShaders::DeleteProgram(&entry->fProgramData);
}
- entry->fKey.copyAndTakeOwnership(key);
- if (!desc.genProgram(&entry->fProgramData)) {
- return NULL;
- }
+ entry->copyAndTakeOwnership(newEntry);
fHashCache.insert(entry->fKey, entry);
}