Initial version of external_oes texture support and unit test
Committed: https://skia.googlesource.com/skia/+/27a048700778d4cebfc23301d1780649791b0e03
Review URL: https://codereview.chromium.org/1451683002
diff --git a/src/gpu/gl/GrGLProgramDesc.cpp b/src/gpu/gl/GrGLProgramDesc.cpp
index 172aca7..e3ee913 100644
--- a/src/gpu/gl/GrGLProgramDesc.cpp
+++ b/src/gpu/gl/GrGLProgramDesc.cpp
@@ -31,11 +31,16 @@
static uint32_t gen_texture_key(const GrProcessor& proc, const GrGLCaps& caps) {
uint32_t key = 0;
int numTextures = proc.numTextures();
+ int shift = 0;
for (int t = 0; t < numTextures; ++t) {
const GrTextureAccess& access = proc.textureAccess(t);
if (swizzle_requires_alpha_remapping(*caps.glslCaps(), access.getTexture()->config())) {
- key |= 1 << t;
+ key |= 1 << shift;
}
+ if (GR_GL_TEXTURE_EXTERNAL == static_cast<GrGLTexture*>(access.getTexture())->target()) {
+ key |= 2 << shift;
+ }
+ shift += 2;
}
return key;
}
@@ -48,10 +53,8 @@
* which must be different for every GrProcessor subclass. It can fail if an effect uses too many
* textures, transforms, etc, for the space allotted in the meta-key. NOTE, both FPs and GPs share
* this function because it is hairy, though FPs do not have attribs, and GPs do not have transforms
- *
- * TODO: A better name for this function would be "compute" instead of "get".
*/
-static bool get_meta_key(const GrProcessor& proc,
+static bool gen_meta_key(const GrProcessor& proc,
const GrGLCaps& caps,
uint32_t transformKey,
GrProcessorKeyBuilder* b) {
@@ -59,31 +62,25 @@
uint32_t textureKey = gen_texture_key(proc, caps);
uint32_t classID = proc.classID();
- // Currently we allow 16 bits for each of the above portions of the meta-key. Fail if they
- // don't fit.
+ // Currently we allow 16 bits for the class id and the overall processor key size.
static const uint32_t kMetaKeyInvalidMask = ~((uint32_t) SK_MaxU16);
- if ((textureKey | transformKey | classID) & kMetaKeyInvalidMask) {
- return false;
- }
- if (processorKeySize > SK_MaxU16) {
+ if ((processorKeySize | classID) & kMetaKeyInvalidMask) {
return false;
}
- uint32_t* key = b->add32n(2);
- key[0] = (textureKey << 16 | transformKey);
- key[1] = (classID << 16 | SkToU16(processorKeySize));
+ uint32_t* key = b->add32n(3);
+ key[0] = (classID << 16) | SkToU32(processorKeySize);
+ key[1] = textureKey;
+ key[2] = transformKey;
return true;
}
-/*
- * TODO: A better name for this function would be "compute" instead of "get".
- */
-static bool get_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc,
+static bool gen_frag_proc_and_meta_keys(const GrPrimitiveProcessor& primProc,
const GrFragmentProcessor& fp,
const GrGLCaps& caps,
GrProcessorKeyBuilder* b) {
for (int i = 0; i < fp.numChildProcessors(); ++i) {
- if (!get_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), caps, b)) {
+ if (!gen_frag_proc_and_meta_keys(primProc, fp.childProcessor(i), caps, b)) {
return false;
}
}
@@ -91,7 +88,7 @@
fp.getGLSLProcessorKey(*caps.glslCaps(), b);
//**** use glslCaps here?
- return get_meta_key(fp, caps, primProc.getTransformKey(fp.coordTransforms(),
+ return gen_meta_key(fp, caps, primProc.getTransformKey(fp.coordTransforms(),
fp.numTransformsExclChildren()), b);
}
@@ -115,14 +112,14 @@
primProc.getGLSLProcessorKey(*gpu->glCaps().glslCaps(), &b);
//**** use glslCaps here?
- if (!get_meta_key(primProc, gpu->glCaps(), 0, &b)) {
+ if (!gen_meta_key(primProc, gpu->glCaps(), 0, &b)) {
glDesc->key().reset();
return false;
}
for (int i = 0; i < pipeline.numFragmentProcessors(); ++i) {
const GrFragmentProcessor& fp = pipeline.getFragmentProcessor(i);
- if (!get_frag_proc_and_meta_keys(primProc, fp, gpu->glCaps(), &b)) {
+ if (!gen_frag_proc_and_meta_keys(primProc, fp, gpu->glCaps(), &b)) {
glDesc->key().reset();
return false;
}
@@ -131,7 +128,7 @@
const GrXferProcessor& xp = *pipeline.getXferProcessor();
xp.getGLSLProcessorKey(*gpu->glCaps().glslCaps(), &b);
//**** use glslCaps here?
- if (!get_meta_key(xp, gpu->glCaps(), 0, &b)) {
+ if (!gen_meta_key(xp, gpu->glCaps(), 0, &b)) {
glDesc->key().reset();
return false;
}