aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-05-11 16:52:59 +0000
committerGravatar bsalomon@google.com <bsalomon@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2011-05-11 16:52:59 +0000
commit2d9ddf9df12b900b7dbe9b9c627757595f8ed289 (patch)
treeadbaf4f341456a58fae86b38c5ffcb6d037facf7
parent97c88c255cff3dbb8343c5d090526fdbedad6dd6 (diff)
Keep program cache consistent when program creation fails.
Review URL: http://codereview.appspot.com/4523056/ git-svn-id: http://skia.googlecode.com/svn/trunk@1298 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--gpu/src/GrGLProgram.h2
-rw-r--r--gpu/src/GrGpuGLShaders.cpp19
2 files changed, 11 insertions, 10 deletions
diff --git a/gpu/src/GrGLProgram.h b/gpu/src/GrGLProgram.h
index 3b926a78c4..993fbe8239 100644
--- a/gpu/src/GrGLProgram.h
+++ b/gpu/src/GrGLProgram.h
@@ -188,7 +188,7 @@ public:
}
void copyAndTakeOwnership(CachedData& other) {
- memcpy(this, &other, sizeof(this));
+ memcpy(this, &other, sizeof(*this));
other.fEffectUniLocationsExtended = NULL; // ownership transfer
GR_DEBUGCODE(other.fEffectUniCount = 0;)
}
diff --git a/gpu/src/GrGpuGLShaders.cpp b/gpu/src/GrGpuGLShaders.cpp
index 2487563122..be030f1e6d 100644
--- a/gpu/src/GrGpuGLShaders.cpp
+++ b/gpu/src/GrGpuGLShaders.cpp
@@ -42,7 +42,6 @@ private:
class Entry : public ::GrNoncopyable {
public:
Entry() {}
- private:
void copyAndTakeOwnership(Entry& entry) {
fProgramData.copyAndTakeOwnership(entry.fProgramData);
fKey.copyAndTakeOwnership(entry.fKey); // ownership transfer
@@ -60,6 +59,8 @@ private:
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
};
@@ -91,12 +92,15 @@ public:
}
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;
@@ -111,10 +115,7 @@ public:
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);
}