diff options
| author | 2021-03-24 20:44:29 +0000 | |
|---|---|---|
| committer | 2021-03-24 20:44:29 +0000 | |
| commit | a8f89293fe6e2622d4e4882c4377fbd64aacb01d (patch) | |
| tree | 44860aa81f2f52a6fd91c0033246458f726436b0 | |
| parent | de5779f8f9082f58fb7d7d6ba09a3282ab33ed56 (diff) | |
| parent | eb904d4aa48cc44292e50c8659b142b1c40826d5 (diff) | |
Merge "RE was not using the protected cache when in protected mode" into sc-dev
| -rw-r--r-- | libs/renderengine/skia/SkiaGLRenderEngine.cpp | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/libs/renderengine/skia/SkiaGLRenderEngine.cpp b/libs/renderengine/skia/SkiaGLRenderEngine.cpp index 7d711c19c6..c5ee15df29 100644 --- a/libs/renderengine/skia/SkiaGLRenderEngine.cpp +++ b/libs/renderengine/skia/SkiaGLRenderEngine.cpp @@ -479,18 +479,31 @@ void SkiaGLRenderEngine::cacheExternalTextureBuffer(const sp<GraphicBuffer>& buf } ATRACE_CALL(); + // We need to switch the currently bound context if the buffer is protected but the current + // context is not. The current state must then be restored after the buffer is cached. + const bool protectedContextState = mInProtectedContext; + if (!useProtectedContext(protectedContextState || + (buffer->getUsage() & GRALLOC_USAGE_PROTECTED))) { + ALOGE("Attempting to cache a buffer into a different context than what is currently bound"); + return; + } + + auto grContext = mInProtectedContext ? mProtectedGrContext : mGrContext; + auto& cache = mInProtectedContext ? mProtectedTextureCache : mTextureCache; + std::lock_guard<std::mutex> lock(mRenderingMutex); - auto iter = mTextureCache.find(buffer->getId()); - if (iter != mTextureCache.end()) { + auto iter = cache.find(buffer->getId()); + if (iter != cache.end()) { ALOGV("Texture already exists in cache."); - return; } else { std::shared_ptr<AutoBackendTexture::LocalRef> imageTextureRef = std::make_shared<AutoBackendTexture::LocalRef>(); imageTextureRef->setTexture( - new AutoBackendTexture(mGrContext.get(), buffer->toAHardwareBuffer(), false)); - mTextureCache.insert({buffer->getId(), imageTextureRef}); + new AutoBackendTexture(grContext.get(), buffer->toAHardwareBuffer(), false)); + cache.insert({buffer->getId(), imageTextureRef}); } + // restore the original state of the protected context if necessary + useProtectedContext(protectedContextState); } void SkiaGLRenderEngine::unbindExternalTextureBuffer(uint64_t bufferId) { @@ -842,15 +855,15 @@ status_t SkiaGLRenderEngine::drawLayers(const DisplaySettings& display, validateInputBufferUsage(layer->source.buffer.buffer); const auto& item = layer->source.buffer; std::shared_ptr<AutoBackendTexture::LocalRef> imageTextureRef = nullptr; - auto iter = mTextureCache.find(item.buffer->getId()); - if (iter != mTextureCache.end()) { + auto iter = cache.find(item.buffer->getId()); + if (iter != cache.end()) { imageTextureRef = iter->second; } else { imageTextureRef = std::make_shared<AutoBackendTexture::LocalRef>(); imageTextureRef->setTexture(new AutoBackendTexture(grContext.get(), item.buffer->toAHardwareBuffer(), false)); - mTextureCache.insert({item.buffer->getId(), imageTextureRef}); + cache.insert({item.buffer->getId(), imageTextureRef}); } sk_sp<SkImage> image = |