}
#if SK_SUPPORT_GPU
+#include "GrGpu.h"
static void draw_pic_for_stats(SkCanvas* canvas, GrContext* context, const SkPicture* picture,
SkTArray<SkString>* keys, SkTArray<double>* values,
const char* tag) {
context->flush();
context->freeGpuResources();
context->resetContext();
+ context->getGpu()->resetShaderCacheForTesting();
draw_pic_for_stats(canvas, context, fPic, keys, values, "first_frame");
// draw second frame
// This is only to be used in GL-specific tests.
virtual const GrGLContext* glContextForTesting() const { return nullptr; }
+ // This is only to be used by testing code
+ virtual void resetShaderCacheForTesting() const {}
+
protected:
// Functions used to map clip-respecting stencil tests into normal
// stencil funcs supported by GPUs.
#endif
}
+void GrGLGpu::resetShaderCacheForTesting() const {
+ fProgramCache->abandon();
+}
+
///////////////////////////////////////////////////////////////////////////////
GrGLAttribArrayState* GrGLGpu::HWGeometryState::bindArrayAndBuffersToDraw(
GrGLGpu* gpu,
bool isTestingOnlyBackendTexture(GrBackendObject) const override;
void deleteTestingOnlyBackendTexture(GrBackendObject, bool abandonTexture) const override;
+ void resetShaderCacheForTesting() const override;
+
private:
GrGLGpu(GrGLContext* ctx, GrContext* context);
ProgramCache(GrGLGpu* gpu);
~ProgramCache();
+ void reset();
void abandon();
GrGLProgram* refProgram(const DrawArgs&);
#endif
}
-void GrGLGpu::ProgramCache::abandon() {
+void GrGLGpu::ProgramCache::reset() {
for (int i = 0; i < fCount; ++i) {
SkASSERT(fEntries[i]->fProgram.get());
fEntries[i]->fProgram->abandon();
delete fEntries[i];
+ fEntries[i] = nullptr;
}
fCount = 0;
+
+ // zero out hash table
+ for (int i = 0; i < 1 << kHashBits; i++) {
+ fHashTable[i] = nullptr;
+ }
+
+ fCurrLRUStamp = 0;
+#ifdef PROGRAM_CACHE_STATS
+ fTotalRequests = 0;
+ fCacheMisses = 0;
+ fHashMisses = 0;
+#endif
+}
+
+void GrGLGpu::ProgramCache::abandon() {
+ this->reset();
}
int GrGLGpu::ProgramCache::search(const GrProgramDesc& desc) const {