Add minimal GL support for protected backend textures
Bug: b/205516620 Internally, Skia does not have full GL support for protected backend textures. But there are some clients who know that they need to create one so that they can render a protected buffer into it. Plumb in support for clients calling GrDirectContext::createBackendTexture. GrGLDefines.h: - Add macros for querying whether a context is protected GrGLCaps: - Check whether the GL_EXT_protected_textures extension is present and the context supports protected. GrGLGpu: - Remove failure cases for GrProtected::kYes. Instead, pass the value down to createTexture where we then set the parameter in GL. Change-Id: I465442fc4b19ed32a65079a168124a067bcd66a6 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/472802 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Leon Scroggins <scroggo@google.com>
This commit is contained in:
parent
15ae48da5f
commit
63dee7ef06
@ -71,6 +71,7 @@ GrGLCaps::GrGLCaps(const GrContextOptions& contextOptions,
|
||||
fFBFetchRequiresEnablePerSample = false;
|
||||
fSRGBWriteControl = false;
|
||||
fSkipErrorChecks = false;
|
||||
fSupportsProtected = false;
|
||||
|
||||
fShaderCaps = std::make_unique<GrShaderCaps>();
|
||||
|
||||
@ -368,6 +369,17 @@ void GrGLCaps::init(const GrContextOptions& contextOptions,
|
||||
// When we are abandoning the context we cannot call into GL thus we should skip any sync work.
|
||||
fMustSyncGpuDuringAbandon = false;
|
||||
|
||||
fSupportsProtected = [&]() {
|
||||
if (!ctxInfo.hasExtension("GL_EXT_protected_textures")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GrGLint contextFlags;
|
||||
GR_GL_GetIntegerv(gli, GR_GL_CONTEXT_FLAGS, &contextFlags);
|
||||
return SkToBool(contextFlags & GR_GL_CONTEXT_FLAG_PROTECTED_CONTENT_BIT_EXT);
|
||||
}();
|
||||
|
||||
|
||||
/**************************************************************************
|
||||
* GrShaderCaps fields
|
||||
**************************************************************************/
|
||||
|
@ -470,6 +470,8 @@ public:
|
||||
/** Skip checks for GL errors, shader compilation success, program link success. */
|
||||
bool skipErrorChecks() const { return fSkipErrorChecks; }
|
||||
|
||||
bool supportsProtected() const { return fSupportsProtected; }
|
||||
|
||||
bool clientCanDisableMultisample() const { return fClientCanDisableMultisample; }
|
||||
|
||||
GrBackendFormat getBackendFormatFromCompressionType(SkImage::CompressionType) const override;
|
||||
@ -583,6 +585,7 @@ private:
|
||||
bool fSRGBWriteControl : 1;
|
||||
bool fSkipErrorChecks : 1;
|
||||
bool fClientCanDisableMultisample : 1;
|
||||
bool fSupportsProtected : 1;
|
||||
|
||||
// Driver workarounds
|
||||
bool fDoManualMipmapping : 1;
|
||||
|
@ -243,6 +243,10 @@
|
||||
#define GR_GL_MULTISAMPLE_COVERAGE_MODES 0x8E12
|
||||
#define GR_GL_MAX_TEXTURE_BUFFER_SIZE 0x8C2B
|
||||
|
||||
#define GR_GL_CONTEXT_FLAGS 0x821E
|
||||
#define GR_GL_CONTEXT_FLAG_PROTECTED_CONTENT_BIT_EXT 0x00000010
|
||||
#define GR_GL_TEXTURE_PROTECTED_EXT 0x8BFA
|
||||
|
||||
/* GetTextureParameter */
|
||||
/* GL_TEXTURE_MAG_FILTER */
|
||||
/* GL_TEXTURE_MIN_FILTER */
|
||||
|
@ -1387,7 +1387,7 @@ sk_sp<GrTexture> GrGLGpu::onCreateTexture(SkISize dimensions,
|
||||
SkASSERT(!GrGLFormatIsCompressed(texDesc.fFormat));
|
||||
|
||||
texDesc.fID = this->createTexture(dimensions, texDesc.fFormat, texDesc.fTarget, renderable,
|
||||
&initialState, mipLevelCount);
|
||||
&initialState, mipLevelCount, isProtected);
|
||||
|
||||
if (!texDesc.fID) {
|
||||
return return_null_texture();
|
||||
@ -1597,7 +1597,7 @@ int GrGLGpu::getCompatibleStencilIndex(GrGLFormat format) {
|
||||
int firstWorkingStencilFormatIndex = -1;
|
||||
|
||||
GrGLuint colorID = this->createTexture({kSize, kSize}, format, GR_GL_TEXTURE_2D,
|
||||
GrRenderable::kYes, nullptr, 1);
|
||||
GrRenderable::kYes, nullptr, 1, GrProtected::kNo);
|
||||
if (!colorID) {
|
||||
return -1;
|
||||
}
|
||||
@ -1700,7 +1700,8 @@ GrGLuint GrGLGpu::createTexture(SkISize dimensions,
|
||||
GrGLenum target,
|
||||
GrRenderable renderable,
|
||||
GrGLTextureParameters::SamplerOverriddenState* initialState,
|
||||
int mipLevelCount) {
|
||||
int mipLevelCount,
|
||||
GrProtected isProtected) {
|
||||
SkASSERT(format != GrGLFormat::kUnknown);
|
||||
SkASSERT(!GrGLFormatIsCompressed(format));
|
||||
|
||||
@ -1726,6 +1727,15 @@ GrGLuint GrGLGpu::createTexture(SkISize dimensions,
|
||||
set_initial_texture_params(this->glInterface(), target);
|
||||
}
|
||||
|
||||
if (GrProtected::kYes == isProtected) {
|
||||
if (this->glCaps().supportsProtected()) {
|
||||
GL_CALL(TexParameteri(target, GR_GL_TEXTURE_PROTECTED_EXT, GR_GL_TRUE));
|
||||
} else {
|
||||
GL_CALL(DeleteTextures(1, &id));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
GrGLenum internalFormat = this->glCaps().getTexImageOrStorageInternalFormat(format);
|
||||
|
||||
bool success = false;
|
||||
@ -3609,11 +3619,6 @@ GrBackendTexture GrGLGpu::onCreateBackendTexture(SkISize dimensions,
|
||||
GrRenderable renderable,
|
||||
GrMipmapped mipMapped,
|
||||
GrProtected isProtected) {
|
||||
// We don't support protected textures in GL.
|
||||
if (isProtected == GrProtected::kYes) {
|
||||
return {};
|
||||
}
|
||||
|
||||
this->handleDirtyContext();
|
||||
|
||||
GrGLFormat glFormat = format.asGLFormat();
|
||||
@ -3651,7 +3656,7 @@ GrBackendTexture GrGLGpu::onCreateBackendTexture(SkISize dimensions,
|
||||
}
|
||||
info.fFormat = GrGLFormatToEnum(glFormat);
|
||||
info.fID = this->createTexture(dimensions, glFormat, info.fTarget, renderable, &initialState,
|
||||
numMipLevels);
|
||||
numMipLevels, isProtected);
|
||||
if (!info.fID) {
|
||||
return {};
|
||||
}
|
||||
@ -3834,7 +3839,7 @@ GrBackendRenderTarget GrGLGpu::createTestingOnlyBackendRenderTarget(SkISize dime
|
||||
if (useTexture) {
|
||||
GrGLTextureParameters::SamplerOverriddenState initialState;
|
||||
colorID = this->createTexture(dimensions, format, GR_GL_TEXTURE_2D, GrRenderable::kYes,
|
||||
&initialState, 1);
|
||||
&initialState, 1, isProtected);
|
||||
if (!colorID) {
|
||||
deleteIDs();
|
||||
return {};
|
||||
|
@ -297,7 +297,8 @@ private:
|
||||
GrGLenum target,
|
||||
GrRenderable,
|
||||
GrGLTextureParameters::SamplerOverriddenState*,
|
||||
int mipLevelCount);
|
||||
int mipLevelCount,
|
||||
GrProtected isProtected);
|
||||
|
||||
GrGLuint createCompressedTexture2D(SkISize dimensions,
|
||||
SkImage::CompressionType compression,
|
||||
|
Loading…
Reference in New Issue
Block a user