Migrate more Android & SkSurface API off GrContext

Migration should be free because (1) the non-Android API is
only loosening up to GrRecordingContext and (2) the Android API
can only see GrContext through including GrDirectContext.h

Change-Id: I97aa75baba0b0969361db6eaef9f83ea94183700
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/323557
Commit-Queue: Adlai Holler <adlai@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Adlai Holler 2020-10-07 11:36:49 -04:00 committed by Skia Commit-Bot
parent adbd312a46
commit 1fc76ce6ff
9 changed files with 29 additions and 94 deletions

View File

@ -549,12 +549,14 @@ public:
Only available on Android, when __ANDROID_API__ is defined to be 26 or greater.
@param context GPU context
@param pixmap SkPixmap that contains data to be uploaded to the AHardwareBuffer
@param hardwareBuffer AHardwareBuffer Android hardware buffer
@param surfaceOrigin surface origin for resulting image
@return created SkImage, or nullptr
*/
static sk_sp<SkImage> MakeFromAHardwareBufferWithData(
GrContext* context,
GrDirectContext* context,
const SkPixmap& pixmap,
AHardwareBuffer* hardwareBuffer,
GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin);

View File

@ -206,7 +206,7 @@ public:
@param releaseContext state passed to textureReleaseProc
@return SkSurface if all parameters are valid; otherwise, nullptr
*/
static sk_sp<SkSurface> MakeFromBackendTexture(GrContext* context,
static sk_sp<SkSurface> MakeFromBackendTexture(GrRecordingContext* context,
const GrBackendTexture& backendTexture,
GrSurfaceOrigin origin, int sampleCnt,
SkColorType colorType,
@ -240,7 +240,7 @@ public:
@param releaseContext state passed to releaseProc
@return SkSurface if all parameters are valid; otherwise, nullptr
*/
static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrContext* context,
static sk_sp<SkSurface> MakeFromBackendRenderTarget(GrRecordingContext* context,
const GrBackendRenderTarget& backendRenderTarget,
GrSurfaceOrigin origin,
SkColorType colorType,
@ -251,7 +251,7 @@ public:
#if GR_TEST_UTILS
// TODO: Remove this.
static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrContext* context,
static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrRecordingContext* context,
const GrBackendTexture& backendTexture,
GrSurfaceOrigin origin,
int sampleCnt,
@ -280,7 +280,7 @@ public:
fonts; may be nullptr
@return created SkSurface, or nullptr
*/
static sk_sp<SkSurface> MakeFromAHardwareBuffer(GrContext* context,
static sk_sp<SkSurface> MakeFromAHardwareBuffer(GrDirectContext* context,
AHardwareBuffer* hardwareBuffer,
GrSurfaceOrigin origin,
sk_sp<SkColorSpace> colorSpace,
@ -376,14 +376,6 @@ public:
const SkSurfaceProps* surfaceProps,
bool shouldCreateWithMips = false);
/** Deprecated.
*/
static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
const SkImageInfo& imageInfo,
int sampleCount, GrSurfaceOrigin surfaceOrigin,
const SkSurfaceProps* surfaceProps,
bool shouldCreateWithMips = false);
/** Returns SkSurface on GPU indicated by context. Allocates memory for
pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
selects whether allocation for pixels is tracked by context. imageInfo
@ -412,12 +404,6 @@ public:
kBottomLeft_GrSurfaceOrigin, surfaceProps);
}
/** Deprecated.
*/
static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
const SkImageInfo& imageInfo, int sampleCount,
const SkSurfaceProps* surfaceProps);
/** Returns SkSurface on GPU indicated by context. Allocates memory for
pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
selects whether allocation for pixels is tracked by context. imageInfo
@ -440,11 +426,6 @@ public:
nullptr);
}
/** Deprecated.
*/
static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
const SkImageInfo& imageInfo);
/** Returns SkSurface on GPU indicated by context that is compatible with the provided
characterization. budgeted selects whether allocation for pixels is tracked by context.

View File

@ -60,14 +60,8 @@ SkColorType GetSkColorTypeFromBufferFormat(uint32_t bufferFormat) {
}
}
GrBackendFormat GetBackendFormat(GrContext* context, AHardwareBuffer* hardwareBuffer,
GrBackendFormat GetBackendFormat(GrDirectContext* dContext, AHardwareBuffer* hardwareBuffer,
uint32_t bufferFormat, bool requireKnownFormat) {
// CONTEXT TODO: Elevate direct context requirement to Android API.
auto dContext = GrAsDirectContext(context);
if (!dContext) {
SkDEBUGFAIL("Requires direct context.");
return GrBackendFormat();
}
GrBackendApi backend = dContext->backend();
if (backend == GrBackendApi::kOpenGL) {
@ -205,13 +199,7 @@ void delete_gl_texture(void* context) {
delete cleanupHelper;
}
void update_gl_texture(void* context, GrContext* grContext) {
// CONTEXT TODO: Elevate direct context requirement to Android API.
auto dContext = GrAsDirectContext(grContext);
if (!dContext) {
SkDEBUGFAIL("Direct context required.");
return;
}
void update_gl_texture(void* context, GrDirectContext* dContext) {
GLTextureHelper* cleanupHelper = static_cast<GLTextureHelper*>(context);
cleanupHelper->rebind(dContext);
}
@ -306,9 +294,7 @@ void delete_vk_image(void* context) {
delete cleanupHelper;
}
void update_vk_image(void* context, GrContext* grContext) {
// CONTEXT TODO: Elevate direct context requirement to Android API.
SkASSERT(GrAsDirectContext(grContext));
void update_vk_image(void* context, GrDirectContext* dContext) {
// no op
}
@ -539,7 +525,7 @@ static bool can_import_protected_content(GrDirectContext* dContext) {
return false;
}
GrBackendTexture MakeBackendTexture(GrContext* context, AHardwareBuffer* hardwareBuffer,
GrBackendTexture MakeBackendTexture(GrDirectContext* dContext, AHardwareBuffer* hardwareBuffer,
int width, int height,
DeleteImageProc* deleteProc,
UpdateImageProc* updateProc,
@ -547,8 +533,6 @@ GrBackendTexture MakeBackendTexture(GrContext* context, AHardwareBuffer* hardwar
bool isProtectedContent,
const GrBackendFormat& backendFormat,
bool isRenderable) {
// CONTEXT TODO: Elevate direct context requirement to Android API.
auto dContext = GrAsDirectContext(context);
SkASSERT(dContext);
if (!dContext || dContext->abandoned()) {
return GrBackendTexture();

View File

@ -24,12 +24,12 @@ namespace GrAHardwareBufferUtils {
SkColorType GetSkColorTypeFromBufferFormat(uint32_t bufferFormat);
GrBackendFormat GetBackendFormat(GrContext* context, AHardwareBuffer* hardwareBuffer,
GrBackendFormat GetBackendFormat(GrDirectContext* context, AHardwareBuffer* hardwareBuffer,
uint32_t bufferFormat, bool requireKnownFormat);
typedef void* TexImageCtx;
typedef void (*DeleteImageProc)(TexImageCtx);
typedef void (*UpdateImageProc)(TexImageCtx, GrContext*);
typedef void (*UpdateImageProc)(TexImageCtx, GrDirectContext*);
/**
* Create a GrBackendTexture from AHardwareBuffer
@ -53,7 +53,7 @@ typedef void (*UpdateImageProc)(TexImageCtx, GrContext*);
* attachment
* @return valid GrBackendTexture object on success
*/
GrBackendTexture MakeBackendTexture(GrContext* context, AHardwareBuffer* hardwareBuffer,
GrBackendTexture MakeBackendTexture(GrDirectContext* context, AHardwareBuffer* hardwareBuffer,
int width, int height,
DeleteImageProc* deleteProc,
UpdateImageProc* updateProc,

View File

@ -626,7 +626,7 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBuffer(AHardwareBuffer* graphicBuffer,
return SkImage::MakeFromGenerator(std::move(gen));
}
sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrDirectContext* dContext,
const SkPixmap& pixmap,
AHardwareBuffer* hardwareBuffer,
GrSurfaceOrigin surfaceOrigin) {
@ -637,12 +637,6 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
return nullptr;
}
auto dContext = GrAsDirectContext(context);
if (!dContext) {
SkDebugf("Direct context required\n");
return nullptr;
}
GrBackendFormat backendFormat = GrAHardwareBufferUtils::GetBackendFormat(dContext,
hardwareBuffer,
bufferDesc.format,

View File

@ -477,9 +477,9 @@ sk_sp<GrTextureProxy> SkImage_GpuBase::MakePromiseImageLazyProxy(
// we can't unref in our destructor because we may be on another thread then. So we
// let the cache know it is waiting on an unref message. We will send that message from
// our destructor.
GrContext* context = fTexture->getContext();
context->priv().getResourceCache()->insertDelayedTextureUnref(fTexture);
fTextureContextID = context->priv().contextID();
auto dContext = fTexture->getContext();
dContext->priv().getResourceCache()->insertDelayedTextureUnref(fTexture);
fTextureContextID = dContext->priv().contextID();
return {std::move(tex), kReleaseCallbackOnInstantiation, kKeySyncMode};
}

View File

@ -417,7 +417,7 @@ sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrRecordingContext*, const SkSurfac
return nullptr;
}
sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext*, const GrBackendTexture&,
sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrRecordingContext*, const GrBackendTexture&,
GrSurfaceOrigin origin, int sampleCnt,
SkColorType, sk_sp<SkColorSpace>,
const SkSurfaceProps*,
@ -425,7 +425,7 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext*, const GrBackendTe
return nullptr;
}
sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext*,
sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrRecordingContext*,
const GrBackendRenderTarget&,
GrSurfaceOrigin origin,
SkColorType,

View File

@ -465,27 +465,6 @@ sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrRecordingContext* ctx, SkBudgeted
return sk_make_sp<SkSurface_Gpu>(std::move(device));
}
sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
const SkImageInfo& imageInfo,
int sampleCount, GrSurfaceOrigin surfaceOrigin,
const SkSurfaceProps* surfaceProps,
bool shouldCreateWithMips) {
return MakeRenderTarget(static_cast<GrRecordingContext*>(context), budgeted, imageInfo,
sampleCount, surfaceOrigin, surfaceProps, shouldCreateWithMips);
}
sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
const SkImageInfo& imageInfo, int sampleCount,
const SkSurfaceProps* surfaceProps) {
return MakeRenderTarget(static_cast<GrRecordingContext*>(context), budgeted, imageInfo,
sampleCount, surfaceProps);
}
sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext* context, SkBudgeted budgeted,
const SkImageInfo& imageInfo) {
return MakeRenderTarget(static_cast<GrRecordingContext*>(context), budgeted, imageInfo);
}
sk_sp<SkSurface> SkSurface_Gpu::MakeWrappedRenderTarget(
GrRecordingContext* context, std::unique_ptr<GrRenderTargetContext> rtc) {
if (!context) {
@ -500,7 +479,8 @@ sk_sp<SkSurface> SkSurface_Gpu::MakeWrappedRenderTarget(
return sk_make_sp<SkSurface_Gpu>(std::move(device));
}
sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrContext* context, const GrBackendTexture& tex,
sk_sp<SkSurface> SkSurface::MakeFromBackendTexture(GrRecordingContext* context,
const GrBackendTexture& tex,
GrSurfaceOrigin origin, int sampleCnt,
SkColorType colorType,
sk_sp<SkColorSpace> colorSpace,
@ -616,7 +596,7 @@ bool validate_backend_render_target(const GrCaps* caps, const GrBackendRenderTar
return true;
}
sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context,
sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrRecordingContext* context,
const GrBackendRenderTarget& rt,
GrSurfaceOrigin origin,
SkColorType colorType,
@ -662,7 +642,7 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendRenderTarget(GrContext* context,
}
#if GR_TEST_UTILS
sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* context,
sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrRecordingContext* context,
const GrBackendTexture& tex,
GrSurfaceOrigin origin,
int sampleCnt,
@ -698,7 +678,7 @@ sk_sp<SkSurface> SkSurface::MakeFromBackendTextureAsRenderTarget(GrContext* cont
#endif
#if defined(SK_BUILD_FOR_ANDROID) && __ANDROID_API__ >= 26
sk_sp<SkSurface> SkSurface::MakeFromAHardwareBuffer(GrContext* context,
sk_sp<SkSurface> SkSurface::MakeFromAHardwareBuffer(GrDirectContext* dContext,
AHardwareBuffer* hardwareBuffer,
GrSurfaceOrigin origin,
sk_sp<SkColorSpace> colorSpace,
@ -719,13 +699,7 @@ sk_sp<SkSurface> SkSurface::MakeFromAHardwareBuffer(GrContext* context,
return nullptr;
}
auto direct = GrAsDirectContext(context);
if (!direct) {
SkDebugf("Direct context required\n");
return nullptr;
}
GrBackendFormat backendFormat = GrAHardwareBufferUtils::GetBackendFormat(direct,
GrBackendFormat backendFormat = GrAHardwareBufferUtils::GetBackendFormat(dContext,
hardwareBuffer,
bufferDesc.format,
true);
@ -739,7 +713,7 @@ sk_sp<SkSurface> SkSurface::MakeFromAHardwareBuffer(GrContext* context,
GrAHardwareBufferUtils::TexImageCtx deleteImageCtx = nullptr;
GrBackendTexture backendTexture =
GrAHardwareBufferUtils::MakeBackendTexture(direct, hardwareBuffer,
GrAHardwareBufferUtils::MakeBackendTexture(dContext, hardwareBuffer,
bufferDesc.width, bufferDesc.height,
&deleteImageProc, &updateImageProc,
&deleteImageCtx, isProtectedContent,
@ -751,7 +725,7 @@ sk_sp<SkSurface> SkSurface::MakeFromAHardwareBuffer(GrContext* context,
SkColorType colorType =
GrAHardwareBufferUtils::GetSkColorTypeFromBufferFormat(bufferDesc.format);
sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture(direct, backendTexture,
sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture(dContext, backendTexture,
origin, 0, colorType, std::move(colorSpace), surfaceProps, deleteImageProc,
deleteImageCtx);

View File

@ -22,7 +22,7 @@ sk_sp<SkSurface> MakeBackendRenderTargetSurface(GrDirectContext* context,
auto ct = SkColorTypeToGrColorType(colorType);
struct ReleaseContext {
GrContext* fContext;
GrDirectContext* fContext;
GrBackendRenderTarget fRenderTarget;
};