aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/gpu/gl/GrGpuGL.cpp7
-rw-r--r--src/gpu/gl/GrGpuGL.h48
-rw-r--r--src/gpu/gl/GrGpuGL_program.cpp157
3 files changed, 104 insertions, 108 deletions
diff --git a/src/gpu/gl/GrGpuGL.cpp b/src/gpu/gl/GrGpuGL.cpp
index 29c7900c45..8817068207 100644
--- a/src/gpu/gl/GrGpuGL.cpp
+++ b/src/gpu/gl/GrGpuGL.cpp
@@ -207,7 +207,8 @@ GrGpuGL::GrGpuGL(const GrGLContextInfo& ctxInfo) : fGLContextInfo(ctxInfo) {
this->initCaps();
- this->createProgramCache();
+ fProgramData = NULL;
+ fProgramCache = new ProgramCache(this->glContextInfo());
#if 0
this->programUnitTest();
@@ -225,7 +226,9 @@ GrGpuGL::~GrGpuGL() {
GL_CALL(UseProgram(0));
}
- this->deleteProgramCache();
+ delete fProgramCache;
+ fProgramCache = NULL;
+ fProgramData = NULL;
// This must be called by before the GrDrawTarget destructor
this->releaseGeometry();
diff --git a/src/gpu/gl/GrGpuGL.h b/src/gpu/gl/GrGpuGL.h
index 24d491d63f..7cbd23058c 100644
--- a/src/gpu/gl/GrGpuGL.h
+++ b/src/gpu/gl/GrGpuGL.h
@@ -10,6 +10,7 @@
#ifndef GrGpuGL_DEFINED
#define GrGpuGL_DEFINED
+#include "GrBinHashKey.h"
#include "GrDrawState.h"
#include "GrGpu.h"
#include "GrGLContextInfo.h"
@@ -19,6 +20,7 @@
#include "GrGLStencilBuffer.h"
#include "GrGLTexture.h"
#include "GrGLVertexBuffer.h"
+#include "../GrTHashCache.h"
class GrGpuGL : public GrGpu {
public:
@@ -211,16 +213,52 @@ protected:
static bool BlendCoeffReferencesConstant(GrBlendCoeff coeff);
private:
-
// for readability of function impls
typedef GrGLProgram::ProgramDesc ProgramDesc;
typedef ProgramDesc::StageDesc StageDesc;
typedef GrGLProgram::CachedData CachedData;
- class ProgramCache;
-
- void createProgramCache();
- void deleteProgramCache();
+ class ProgramCache : public ::GrNoncopyable {
+ public:
+ ProgramCache(const GrGLContextInfo& gl);
+ ~ProgramCache();
+
+ void abandon();
+ void invalidateViewMatrices();
+ CachedData* getProgramData(const GrGLProgram& desc,
+ GrCustomStage** stages);
+ private:
+ enum {
+ kKeySize = GrGLProgram::kProgramKeySize,
+ // We may actually have kMaxEntries+1 shaders in the GL context
+ // because we create a new shader before evicting from the cache.
+ kMaxEntries = 32
+ };
+
+ class Entry;
+ typedef GrBinHashKey<Entry, kKeySize> ProgramHashKey;
+
+ class Entry : public ::GrNoncopyable {
+ public:
+ Entry() {}
+ void copyAndTakeOwnership(Entry& entry);
+ int compare(const ProgramHashKey& key) const {
+ return fKey.compare(key);
+ }
+
+ public:
+ CachedData fProgramData;
+ ProgramHashKey fKey;
+ unsigned int fLRUStamp;
+ };
+
+ GrTHashTable<Entry, ProgramHashKey, 8> fHashCache;
+
+ Entry fEntries[kMaxEntries];
+ int fCount;
+ unsigned int fCurrLRUStamp;
+ const GrGLContextInfo& fGL;
+ };
// sets the texture matrix uniform for currently bound program
void flushTextureMatrix(int stage);
diff --git a/src/gpu/gl/GrGpuGL_program.cpp b/src/gpu/gl/GrGpuGL_program.cpp
index 2448fa46ec..b8fcb1b03e 100644
--- a/src/gpu/gl/GrGpuGL_program.cpp
+++ b/src/gpu/gl/GrGpuGL_program.cpp
@@ -10,7 +10,6 @@
#include "effects/GrConvolutionEffect.h"
#include "effects/GrMorphologyEffect.h"
-#include "GrBinHashKey.h"
#include "GrCustomStage.h"
#include "GrGLProgramStage.h"
#include "GrGLSL.h"
@@ -23,109 +22,76 @@
#define SKIP_CACHE_CHECK true
#define GR_UINT32_MAX static_cast<uint32_t>(-1)
-#include "../GrTHashCache.h"
-
-class GrGpuGL::ProgramCache : public ::GrNoncopyable {
-private:
- class Entry;
-
- typedef GrBinHashKey<Entry, GrGLProgram::kProgramKeySize> ProgramHashKey;
-
- class Entry : public ::GrNoncopyable {
- public:
- Entry() {}
- void copyAndTakeOwnership(Entry& entry) {
- fProgramData.copyAndTakeOwnership(entry.fProgramData);
- fKey = entry.fKey; // ownership transfer
- fLRUStamp = entry.fLRUStamp;
- }
-
- public:
- int compare(const ProgramHashKey& key) const { return fKey.compare(key); }
-
- public:
- GrGLProgram::CachedData fProgramData;
- ProgramHashKey fKey;
- unsigned int fLRUStamp;
- };
+void GrGpuGL::ProgramCache::Entry::copyAndTakeOwnership(Entry& entry) {
+ fProgramData.copyAndTakeOwnership(entry.fProgramData);
+ fKey = entry.fKey; // ownership transfer
+ fLRUStamp = entry.fLRUStamp;
+}
- GrTHashTable<Entry, ProgramHashKey, 8> fHashCache;
+GrGpuGL::ProgramCache::ProgramCache(const GrGLContextInfo& gl)
+ : fCount(0)
+ , fCurrLRUStamp(0)
+ , fGL(gl) {
+}
- // We may have kMaxEntries+1 shaders in the GL context because
- // we create a new shader before evicting from the cache.
- enum {
- kMaxEntries = 32
- };
- Entry fEntries[kMaxEntries];
- int fCount;
- unsigned int fCurrLRUStamp;
- const GrGLContextInfo& fGL;
-
-public:
- ProgramCache(const GrGLContextInfo& gl)
- : fCount(0)
- , fCurrLRUStamp(0)
- , fGL(gl) {
+GrGpuGL::ProgramCache::~ProgramCache() {
+ for (int i = 0; i < fCount; ++i) {
+ GrGpuGL::DeleteProgram(fGL.interface(),
+ &fEntries[i].fProgramData);
}
+}
- ~ProgramCache() {
- for (int i = 0; i < fCount; ++i) {
- GrGpuGL::DeleteProgram(fGL.interface(),
- &fEntries[i].fProgramData);
- }
- }
+void GrGpuGL::ProgramCache::abandon() {
+ fCount = 0;
+}
- void abandon() {
- fCount = 0;
- }
-
- void invalidateViewMatrices() {
- for (int i = 0; i < fCount; ++i) {
- // set to illegal matrix
- fEntries[i].fProgramData.fViewMatrix = GrMatrix::InvalidMatrix();
- }
+void GrGpuGL::ProgramCache::invalidateViewMatrices() {
+ for (int i = 0; i < fCount; ++i) {
+ // set to illegal matrix
+ fEntries[i].fProgramData.fViewMatrix = GrMatrix::InvalidMatrix();
}
+}
- GrGLProgram::CachedData* getProgramData(const GrGLProgram& desc,
- GrCustomStage** stages) {
- Entry newEntry;
- newEntry.fKey.setKeyData(desc.keyData());
+GrGLProgram::CachedData* GrGpuGL::ProgramCache::getProgramData(
+ const GrGLProgram& desc,
+ GrCustomStage** stages) {
+ Entry newEntry;
+ newEntry.fKey.setKeyData(desc.keyData());
- Entry* entry = fHashCache.find(newEntry.fKey);
- if (NULL == entry) {
- if (!desc.genProgram(fGL, stages, &newEntry.fProgramData)) {
- return NULL;
- }
- if (fCount < kMaxEntries) {
- entry = fEntries + fCount;
- ++fCount;
- } else {
- GrAssert(kMaxEntries == fCount);
- entry = fEntries;
- for (int i = 1; i < kMaxEntries; ++i) {
- if (fEntries[i].fLRUStamp < entry->fLRUStamp) {
- entry = fEntries + i;
- }
+ Entry* entry = fHashCache.find(newEntry.fKey);
+ if (NULL == entry) {
+ if (!desc.genProgram(fGL, stages, &newEntry.fProgramData)) {
+ return NULL;
+ }
+ if (fCount < kMaxEntries) {
+ entry = fEntries + fCount;
+ ++fCount;
+ } else {
+ GrAssert(kMaxEntries == fCount);
+ entry = fEntries;
+ for (int i = 1; i < kMaxEntries; ++i) {
+ if (fEntries[i].fLRUStamp < entry->fLRUStamp) {
+ entry = fEntries + i;
}
- fHashCache.remove(entry->fKey, entry);
- GrGpuGL::DeleteProgram(fGL.interface(),
- &entry->fProgramData);
}
- entry->copyAndTakeOwnership(newEntry);
- fHashCache.insert(entry->fKey, entry);
+ fHashCache.remove(entry->fKey, entry);
+ GrGpuGL::DeleteProgram(fGL.interface(),
+ &entry->fProgramData);
}
+ entry->copyAndTakeOwnership(newEntry);
+ fHashCache.insert(entry->fKey, entry);
+ }
- entry->fLRUStamp = fCurrLRUStamp;
- if (GR_UINT32_MAX == fCurrLRUStamp) {
- // wrap around! just trash our LRU, one time hit.
- for (int i = 0; i < fCount; ++i) {
- fEntries[i].fLRUStamp = 0;
- }
+ entry->fLRUStamp = fCurrLRUStamp;
+ if (GR_UINT32_MAX == fCurrLRUStamp) {
+ // wrap around! just trash our LRU, one time hit.
+ for (int i = 0; i < fCount; ++i) {
+ fEntries[i].fLRUStamp = 0;
}
- ++fCurrLRUStamp;
- return &entry->fProgramData;
}
-};
+ ++fCurrLRUStamp;
+ return &entry->fProgramData;
+}
void GrGpuGL::DeleteProgram(const GrGLInterface* gl,
CachedData* programData) {
@@ -140,17 +106,6 @@ void GrGpuGL::DeleteProgram(const GrGLInterface* gl,
////////////////////////////////////////////////////////////////////////////////
-void GrGpuGL::createProgramCache() {
- fProgramData = NULL;
- fProgramCache = new ProgramCache(this->glContextInfo());
-}
-
-void GrGpuGL::deleteProgramCache() {
- delete fProgramCache;
- fProgramCache = NULL;
- fProgramData = NULL;
-}
-
void GrGpuGL::abandonResources(){
INHERITED::abandonResources();
fProgramCache->abandon();