Minor modifications to GrProgramDesc.h.

BUG=skia:

Review URL: https://codereview.chromium.org/1100483003
This commit is contained in:
jvanverth 2015-04-20 12:29:37 -07:00 committed by Commit bot
parent 9ef1bb1375
commit d1e72875d1
4 changed files with 22 additions and 14 deletions

View File

@ -12,8 +12,6 @@
#include "GrTypesPriv.h"
#include "SkChecksum.h"
class GrGLGpu;
/** This class describes a program to generate. It also serves as a program cache key. Very little
of this is GL-specific. The GL-specific parts could be factored out into a subclass. */
class GrProgramDesc {
@ -76,7 +74,7 @@ public:
// This should really only be used internally, base classes should return their own headers
const KeyHeader& header() const { return *this->atOffset<KeyHeader, kHeaderOffset>(); }
private:
protected:
template<typename T, size_t OFFSET> T* atOffset() {
return reinterpret_cast<T*>(reinterpret_cast<intptr_t>(fKey.begin()) + OFFSET);
}
@ -117,9 +115,11 @@ private:
kMaxPreallocProcessors * sizeof(uint32_t) * kIntsPerProcessor,
};
SkSTArray<kPreAllocSize, uint8_t, true> fKey;
SkSTArray<kPreAllocSize, uint8_t, true>& key() { return fKey; }
const SkSTArray<kPreAllocSize, uint8_t, true>& key() const { return fKey; }
friend class GrGLProgramDescBuilder;
private:
SkSTArray<kPreAllocSize, uint8_t, true> fKey;
};
#endif

View File

@ -96,16 +96,18 @@ bool GrGLProgramDescBuilder::Build(GrProgramDesc* desc,
// bindings in use or other descriptor field settings) it should be set
// to a canonical value to avoid duplicate programs with different keys.
GrGLProgramDesc* glDesc = (GrGLProgramDesc*) desc;
GR_STATIC_ASSERT(0 == kProcessorKeysOffset % sizeof(uint32_t));
// Make room for everything up to the effect keys.
desc->fKey.reset();
desc->fKey.push_back_n(kProcessorKeysOffset);
glDesc->key().reset();
glDesc->key().push_back_n(kProcessorKeysOffset);
GrProcessorKeyBuilder b(&desc->fKey);
GrProcessorKeyBuilder b(&glDesc->key());
primProc.getGLProcessorKey(batchTracker, gpu->glCaps(), &b);
if (!get_meta_key(primProc, gpu->glCaps(), 0, &b)) {
desc->fKey.reset();
glDesc->key().reset();
return false;
}
@ -114,7 +116,7 @@ bool GrGLProgramDescBuilder::Build(GrProgramDesc* desc,
const GrFragmentProcessor& fp = *fps.processor();
fp.getGLProcessorKey(gpu->glCaps(), &b);
if (!get_meta_key(fp, gpu->glCaps(), primProc.getTransformKey(fp.coordTransforms()), &b)) {
desc->fKey.reset();
glDesc->key().reset();
return false;
}
}
@ -122,14 +124,14 @@ bool GrGLProgramDescBuilder::Build(GrProgramDesc* desc,
const GrXferProcessor& xp = *pipeline.getXferProcessor();
xp.getGLProcessorKey(gpu->glCaps(), &b);
if (!get_meta_key(xp, gpu->glCaps(), 0, &b)) {
desc->fKey.reset();
glDesc->key().reset();
return false;
}
// --------DO NOT MOVE HEADER ABOVE THIS LINE--------------------------------------------------
// Because header is a pointer into the dynamic array, we can't push any new data into the key
// below here.
KeyHeader* header = desc->atOffset<KeyHeader, kHeaderOffset>();
KeyHeader* header = glDesc->atOffset<KeyHeader, kHeaderOffset>();
// make sure any padding in the header is zeroed.
memset(header, 0, kHeaderSize);
@ -144,6 +146,6 @@ bool GrGLProgramDescBuilder::Build(GrProgramDesc* desc,
header->fColorEffectCnt = pipeline.numColorFragmentStages();
header->fCoverageEffectCnt = pipeline.numCoverageFragmentStages();
desc->finalize();
glDesc->finalize();
return true;
}

View File

@ -14,6 +14,11 @@
#include "GrTypesPriv.h"
class GrGLGpu;
class GrGLProgramDescBuilder;
class GrGLProgramDesc : public GrProgramDesc {
friend class GrGLProgramDescBuilder;
};
/**
* This class can be used to build a GrProgramDesc. It also provides helpers for accessing
@ -30,7 +35,7 @@ public:
// Each processor's key is a variable length array of uint32_t.
enum {
// Part 3.
kHeaderOffset = GrProgramDesc::kHeaderOffset,
kHeaderOffset = GrGLProgramDesc::kHeaderOffset,
kHeaderSize = SkAlign4(sizeof(KeyHeader)),
// Part 4.
// This is the offset into the backenend specific part of the key, which includes

View File

@ -13,6 +13,7 @@
#include "GrTexture.h"
#include "GrGLUtil.h"
class GrGLGpu;
class GrGLTexture : public GrTexture {