Add and plumb abstraction layer over GrDirectContext
Also changed GaussianBlurFilter's surface origin from
kBottomLeft_GrSurfaceOrigin to kTopLeft_GrSurfaceOrigin. This doesn't
seem to have an effect in practice, but aligns it with KawaseBlurFilter.
Additionally, both blur filters now set the protected bit on the
surfaces they create to reflect the protection status of the active
context, as opposed to either the protection status of the input SkImage
that is being blurred (Kawase) or always false (Gaussian). This should
be equivalent behavior in the case of Kawase (and aligns with Graphite),
and is likely a bug fix for Gaussian.
Test: manual validation (GL+VK) & existing tests (refactor)
Bug: b/293371537
Change-Id: I19b0258035ea5f319d04207ceb266f2cd1e87674
diff --git a/libs/renderengine/skia/AutoBackendTexture.cpp b/libs/renderengine/skia/AutoBackendTexture.cpp
index 26b280d..02e7337 100644
--- a/libs/renderengine/skia/AutoBackendTexture.cpp
+++ b/libs/renderengine/skia/AutoBackendTexture.cpp
@@ -21,12 +21,12 @@
#define ATRACE_TAG ATRACE_TAG_GRAPHICS
#include <SkImage.h>
+#include <android/hardware_buffer.h>
#include <include/gpu/ganesh/SkImageGanesh.h>
#include <include/gpu/ganesh/SkSurfaceGanesh.h>
#include <include/gpu/ganesh/gl/GrGLBackendSurface.h>
#include <include/gpu/ganesh/vk/GrVkBackendSurface.h>
#include <include/gpu/vk/GrVkTypes.h>
-#include <android/hardware_buffer.h>
#include "ColorSpaces.h"
#include "log/log_main.h"
#include "utils/Trace.h"
@@ -35,47 +35,37 @@
namespace renderengine {
namespace skia {
-AutoBackendTexture::AutoBackendTexture(GrDirectContext* context, AHardwareBuffer* buffer,
+AutoBackendTexture::AutoBackendTexture(SkiaGpuContext* context, AHardwareBuffer* buffer,
bool isOutputBuffer, CleanupManager& cleanupMgr)
- : mGrContext(context), mCleanupMgr(cleanupMgr), mIsOutputBuffer(isOutputBuffer) {
+ : mGrContext(context->grDirectContext()),
+ mCleanupMgr(cleanupMgr),
+ mIsOutputBuffer(isOutputBuffer) {
ATRACE_CALL();
+
AHardwareBuffer_Desc desc;
AHardwareBuffer_describe(buffer, &desc);
bool createProtectedImage = 0 != (desc.usage & AHARDWAREBUFFER_USAGE_PROTECTED_CONTENT);
GrBackendFormat backendFormat;
- GrBackendApi backend = context->backend();
+ GrBackendApi backend = mGrContext->backend();
if (backend == GrBackendApi::kOpenGL) {
backendFormat =
- GrAHardwareBufferUtils::GetGLBackendFormat(context, desc.format, false);
+ GrAHardwareBufferUtils::GetGLBackendFormat(mGrContext.get(), desc.format, false);
mBackendTexture =
- GrAHardwareBufferUtils::MakeGLBackendTexture(context,
- buffer,
- desc.width,
- desc.height,
- &mDeleteProc,
- &mUpdateProc,
- &mImageCtx,
- createProtectedImage,
- backendFormat,
+ GrAHardwareBufferUtils::MakeGLBackendTexture(mGrContext.get(), buffer, desc.width,
+ desc.height, &mDeleteProc,
+ &mUpdateProc, &mImageCtx,
+ createProtectedImage, backendFormat,
isOutputBuffer);
} else if (backend == GrBackendApi::kVulkan) {
- backendFormat =
- GrAHardwareBufferUtils::GetVulkanBackendFormat(context,
- buffer,
- desc.format,
- false);
+ backendFormat = GrAHardwareBufferUtils::GetVulkanBackendFormat(mGrContext.get(), buffer,
+ desc.format, false);
mBackendTexture =
- GrAHardwareBufferUtils::MakeVulkanBackendTexture(context,
- buffer,
- desc.width,
- desc.height,
- &mDeleteProc,
- &mUpdateProc,
- &mImageCtx,
- createProtectedImage,
- backendFormat,
- isOutputBuffer);
+ GrAHardwareBufferUtils::MakeVulkanBackendTexture(mGrContext.get(), buffer,
+ desc.width, desc.height,
+ &mDeleteProc, &mUpdateProc,
+ &mImageCtx, createProtectedImage,
+ backendFormat, isOutputBuffer);
} else {
LOG_ALWAYS_FATAL("Unexpected backend %u", static_cast<unsigned>(backend));
}
@@ -162,7 +152,7 @@
ATRACE_CALL();
if (mBackendTexture.isValid()) {
- mUpdateProc(mImageCtx, mGrContext);
+ mUpdateProc(mImageCtx, mGrContext.get());
}
auto colorType = mColorType;
@@ -173,7 +163,7 @@
}
sk_sp<SkImage> image =
- SkImages::BorrowTextureFrom(mGrContext, mBackendTexture, kTopLeft_GrSurfaceOrigin,
+ SkImages::BorrowTextureFrom(mGrContext.get(), mBackendTexture, kTopLeft_GrSurfaceOrigin,
colorType, alphaType, toSkColorSpace(dataspace),
releaseImageProc, this);
if (image.get()) {
@@ -194,7 +184,7 @@
LOG_ALWAYS_FATAL_IF(!mIsOutputBuffer, "You can't generate a SkSurface for a read-only texture");
if (!mSurface.get() || mDataspace != dataspace) {
sk_sp<SkSurface> surface =
- SkSurfaces::WrapBackendTexture(mGrContext, mBackendTexture,
+ SkSurfaces::WrapBackendTexture(mGrContext.get(), mBackendTexture,
kTopLeft_GrSurfaceOrigin, 0, mColorType,
toSkColorSpace(dataspace), nullptr,
releaseSurfaceProc, this);