Add checks for TextureSampler count in text GeoProcs.
Chrome is seeing unexplained segfaults when trying to access the n-1th textureSampler while creating textOp GeoProcs -- it's possible that's because n is 0. Also add checks to make sure n is not > kMaxTextures. Bug: chromium:1027314 Change-Id: I65a5472980bab37d580b3f237a132a8b23794abe Reviewed-on: https://skia-review.googlesource.com/c/skia/+/255985 Commit-Queue: Jim Van Verth <jvanverth@google.com> Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
db80f6936c
commit
9f2516f64d
@ -59,6 +59,13 @@ static void append_multitexture_lookup(GrGLSLPrimitiveProcessor::EmitArgs& args,
|
||||
const GrGLSLVarying &texIdx,
|
||||
const char* coordName,
|
||||
const char* colorName) {
|
||||
SkASSERT(numTextureSamplers > 0);
|
||||
// This shouldn't happen, but will avoid a crash if it does
|
||||
if (numTextureSamplers <= 0) {
|
||||
args.fFragBuilder->codeAppendf("%s = float4(1, 1, 1, 1);", colorName);
|
||||
return;
|
||||
}
|
||||
|
||||
// conditionally load from the indexed texture sampler
|
||||
for (int i = 0; i < numTextureSamplers-1; ++i) {
|
||||
args.fFragBuilder->codeAppendf("if (%s == %d) { %s = ", texIdx.fsIn(), i, colorName);
|
||||
|
@ -164,6 +164,8 @@ void GrBitmapTextGeoProc::addNewProxies(const sk_sp<GrTextureProxy>* proxies,
|
||||
int numActiveProxies,
|
||||
const GrSamplerState& params) {
|
||||
SkASSERT(numActiveProxies <= kMaxTextures);
|
||||
// Just to make sure we don't try to add too many proxies
|
||||
numActiveProxies = SkTMin(numActiveProxies, kMaxTextures);
|
||||
|
||||
if (!fTextureSamplers[0].isInitialized()) {
|
||||
fAtlasDimensions = proxies[0]->dimensions();
|
||||
|
@ -253,6 +253,8 @@ void GrDistanceFieldA8TextGeoProc::addNewProxies(const sk_sp<GrTextureProxy>* pr
|
||||
int numProxies,
|
||||
const GrSamplerState& params) {
|
||||
SkASSERT(numProxies <= kMaxTextures);
|
||||
// Just to make sure we don't try to add too many proxies
|
||||
numProxies = SkTMin(numProxies, kMaxTextures);
|
||||
|
||||
if (!fTextureSamplers[0].isInitialized()) {
|
||||
fAtlasDimensions = proxies[0]->dimensions();
|
||||
@ -548,6 +550,8 @@ void GrDistanceFieldPathGeoProc::addNewProxies(const sk_sp<GrTextureProxy>* prox
|
||||
int numProxies,
|
||||
const GrSamplerState& params) {
|
||||
SkASSERT(numProxies <= kMaxTextures);
|
||||
// Just to make sure we don't try to add too many proxies
|
||||
numProxies = SkTMin(numProxies, kMaxTextures);
|
||||
|
||||
if (!fTextureSamplers[0].isInitialized()) {
|
||||
fAtlasDimensions = proxies[0]->dimensions();
|
||||
@ -874,6 +878,8 @@ void GrDistanceFieldLCDTextGeoProc::addNewProxies(const sk_sp<GrTextureProxy>* p
|
||||
int numProxies,
|
||||
const GrSamplerState& params) {
|
||||
SkASSERT(numProxies <= kMaxTextures);
|
||||
// Just to make sure we don't try to add too many proxies
|
||||
numProxies = SkTMin(numProxies, kMaxTextures);
|
||||
|
||||
if (!fTextureSamplers[0].isInitialized()) {
|
||||
fAtlasDimensions = proxies[0]->dimensions();
|
||||
|
@ -411,6 +411,10 @@ void GrAtlasTextOp::flush(GrMeshDrawOp::Target* target, FlushInfo* flushInfo) co
|
||||
unsigned int numActiveProxies;
|
||||
const sk_sp<GrTextureProxy>* proxies = atlasManager->getProxies(maskFormat, &numActiveProxies);
|
||||
SkASSERT(proxies);
|
||||
// Something has gone terribly wrong, bail
|
||||
if (!proxies || 0 == numActiveProxies) {
|
||||
return;
|
||||
}
|
||||
if (gp->numTextureSamplers() != (int) numActiveProxies) {
|
||||
// During preparation the number of atlas pages has increased.
|
||||
// Update the proxies used in the GP to match.
|
||||
|
Loading…
Reference in New Issue
Block a user