Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit fc06f98

Browse files
bsalomonSkia Commit-Bot
authored andcommitted
Clamp GL_TEXTURE_MAX_LEVEL to 1 on Android.
This seems to avoid a bug when sampling from GL_TEXTURE_EXTERNAL_OES textures. Remove code to avoid sampler objects on when using GLSL ES2 on GL ES3. This was a speculative workaround that did not help. Bug: flutter/flutter#23900 Bug: flutter/flutter#24402 Bug: flutter/flutter#24391 Change-Id: Id14080131e49e632949a3bdc2b15f6e3ce97bf93 Reviewed-on: https://skia-review.googlesource.com/c/172978 Commit-Queue: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Osman <brianosman@google.com> Auto-Submit: Brian Salomon <bsalomon@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
1 parent df246b9 commit fc06f98

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

src/gpu/gl/GrGLCaps.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
6262
fUseDrawInsteadOfAllRenderTargetWrites = false;
6363
fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines = false;
6464
fDetachStencilFromMSAABuffersBeforeReadPixels = false;
65+
fClampMaxTextureLevelToOne = false;
6566
fProgramBinarySupport = false;
6667
fSamplerObjectSupport = false;
6768

@@ -2740,16 +2741,14 @@ void GrGLCaps::applyDriverCorrectnessWorkarounds(const GrGLContextInfo& ctxInfo,
27402741
}
27412742
#endif
27422743

2743-
// There are reports of both Mali and Adreno 3xx Flutter users having issues drawing
2744-
// videos and other embedded content on older Android versions (6 and earlier) after sampler
2745-
// objects were enabled. We suspect this may relate to using sampler objects on ES3 with the ES2
2746-
// shading language. (We may limit the shading language because of issues around
2747-
// GL_OES_EGL_image_external_essl3 on older Android versions). We suspect this may be an
2748-
// under tested combination (sampler object + EXTERNAL_OES texture + ES2 shading language).
2749-
if (kGLES_GrGLStandard == ctxInfo.standard() && ctxInfo.version() >= GR_GL_VER(3, 0) &&
2750-
ctxInfo.glslGeneration() <= k110_GrGLSLGeneration) {
2751-
fSamplerObjectSupport = false;
2752-
}
2744+
#ifdef SK_BUILD_FOR_ANDROID
2745+
// Older versions of Android have problems with setting GL_TEXTURE_MAX_LEVEL to 0 for
2746+
// EGL images (or possibly just GL_TEXTURE_EXTERNAL_OES).
2747+
// If the texture is not MIP mapped (only has level 0) then it should be harmless to use a
2748+
// GL_TEXTURE_MAX_LEVEL of 1. Such textures are never used with GL_*_MIPMAP_* set for
2749+
// GL_TEXTURE_MIN_FILTER.
2750+
fClampMaxTextureLevelToOne = true;
2751+
#endif
27532752
}
27542753

27552754
void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {

src/gpu/gl/GrGLCaps.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,10 @@ class GrGLCaps : public GrCaps {
390390
return fDetachStencilFromMSAABuffersBeforeReadPixels;
391391
}
392392

393+
// Older Android versions seem to have an issue with setting GL_TEXTURE_MAX_LEVEL to 0
394+
// on EGLImage/GL_TEXTURE_EXTERNAL_OES textures.
395+
bool clampMaxTextureLevelToOne() const { return fClampMaxTextureLevelToOne; }
396+
393397
// Returns the observed maximum number of instances the driver can handle in a single draw call
394398
// without crashing, or 'pendingInstanceCount' if this workaround is not necessary.
395399
// NOTE: the return value may be larger than pendingInstanceCount.
@@ -526,6 +530,7 @@ class GrGLCaps : public GrCaps {
526530
bool fUseDrawInsteadOfAllRenderTargetWrites : 1;
527531
bool fRequiresCullFaceEnableDisableWhenDrawingLinesAfterNonLines : 1;
528532
bool fDetachStencilFromMSAABuffersBeforeReadPixels : 1;
533+
bool fClampMaxTextureLevelToOne : 1;
529534
int fMaxInstancesPerDrawWithoutCrashing;
530535

531536
uint32_t fBlitFramebufferFlags;

src/gpu/gl/GrGLGpu.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2902,6 +2902,9 @@ void GrGLGpu::bindTexture(int unitIdx, GrSamplerState samplerState, GrGLTexture*
29022902
GrGLTexture::NonSamplerParams newNonSamplerParams;
29032903
newNonSamplerParams.fBaseMipMapLevel = 0;
29042904
newNonSamplerParams.fMaxMipMapLevel = texture->texturePriv().maxMipMapLevel();
2905+
if (this->glCaps().clampMaxTextureLevelToOne()) {
2906+
newNonSamplerParams.fMaxMipMapLevel = SkTMax(newNonSamplerParams.fMaxMipMapLevel, 1);
2907+
}
29052908

29062909
const GrGLTexture::NonSamplerParams& oldNonSamplerParams = texture->getCachedNonSamplerParams();
29072910
if (this->glCaps().textureSwizzleSupport()) {

0 commit comments

Comments
 (0)