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. 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 pixmap SkPixmap that contains data to be uploaded to the AHardwareBuffer
@param hardwareBuffer AHardwareBuffer Android hardware buffer @param hardwareBuffer AHardwareBuffer Android hardware buffer
@param surfaceOrigin surface origin for resulting image
@return created SkImage, or nullptr @return created SkImage, or nullptr
*/ */
static sk_sp<SkImage> MakeFromAHardwareBufferWithData( static sk_sp<SkImage> MakeFromAHardwareBufferWithData(
GrContext* context, GrDirectContext* context,
const SkPixmap& pixmap, const SkPixmap& pixmap,
AHardwareBuffer* hardwareBuffer, AHardwareBuffer* hardwareBuffer,
GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin); GrSurfaceOrigin surfaceOrigin = kTopLeft_GrSurfaceOrigin);

View File

@ -206,7 +206,7 @@ public:
@param releaseContext state passed to textureReleaseProc @param releaseContext state passed to textureReleaseProc
@return SkSurface if all parameters are valid; otherwise, nullptr @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, const GrBackendTexture& backendTexture,
GrSurfaceOrigin origin, int sampleCnt, GrSurfaceOrigin origin, int sampleCnt,
SkColorType colorType, SkColorType colorType,
@ -240,7 +240,7 @@ public:
@param releaseContext state passed to releaseProc @param releaseContext state passed to releaseProc
@return SkSurface if all parameters are valid; otherwise, nullptr @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, const GrBackendRenderTarget& backendRenderTarget,
GrSurfaceOrigin origin, GrSurfaceOrigin origin,
SkColorType colorType, SkColorType colorType,
@ -251,7 +251,7 @@ public:
#if GR_TEST_UTILS #if GR_TEST_UTILS
// TODO: Remove this. // TODO: Remove this.
static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrContext* context, static sk_sp<SkSurface> MakeFromBackendTextureAsRenderTarget(GrRecordingContext* context,
const GrBackendTexture& backendTexture, const GrBackendTexture& backendTexture,
GrSurfaceOrigin origin, GrSurfaceOrigin origin,
int sampleCnt, int sampleCnt,
@ -280,7 +280,7 @@ public:
fonts; may be nullptr fonts; may be nullptr
@return created SkSurface, or nullptr @return created SkSurface, or nullptr
*/ */
static sk_sp<SkSurface> MakeFromAHardwareBuffer(GrContext* context, static sk_sp<SkSurface> MakeFromAHardwareBuffer(GrDirectContext* context,
AHardwareBuffer* hardwareBuffer, AHardwareBuffer* hardwareBuffer,
GrSurfaceOrigin origin, GrSurfaceOrigin origin,
sk_sp<SkColorSpace> colorSpace, sk_sp<SkColorSpace> colorSpace,
@ -376,14 +376,6 @@ public:
const SkSurfaceProps* surfaceProps, const SkSurfaceProps* surfaceProps,
bool shouldCreateWithMips = false); 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 /** Returns SkSurface on GPU indicated by context. Allocates memory for
pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
selects whether allocation for pixels is tracked by context. imageInfo selects whether allocation for pixels is tracked by context. imageInfo
@ -412,12 +404,6 @@ public:
kBottomLeft_GrSurfaceOrigin, surfaceProps); 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 /** Returns SkSurface on GPU indicated by context. Allocates memory for
pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted pixels, based on the width, height, and SkColorType in SkImageInfo. budgeted
selects whether allocation for pixels is tracked by context. imageInfo selects whether allocation for pixels is tracked by context. imageInfo
@ -440,11 +426,6 @@ public:
nullptr); 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 /** Returns SkSurface on GPU indicated by context that is compatible with the provided
characterization. budgeted selects whether allocation for pixels is tracked by context. 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) { 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(); GrBackendApi backend = dContext->backend();
if (backend == GrBackendApi::kOpenGL) { if (backend == GrBackendApi::kOpenGL) {
@ -205,13 +199,7 @@ void delete_gl_texture(void* context) {
delete cleanupHelper; delete cleanupHelper;
} }
void update_gl_texture(void* context, GrContext* grContext) { void update_gl_texture(void* context, GrDirectContext* dContext) {
// CONTEXT TODO: Elevate direct context requirement to Android API.
auto dContext = GrAsDirectContext(grContext);
if (!dContext) {
SkDEBUGFAIL("Direct context required.");
return;
}
GLTextureHelper* cleanupHelper = static_cast<GLTextureHelper*>(context); GLTextureHelper* cleanupHelper = static_cast<GLTextureHelper*>(context);
cleanupHelper->rebind(dContext); cleanupHelper->rebind(dContext);
} }
@ -306,9 +294,7 @@ void delete_vk_image(void* context) {
delete cleanupHelper; delete cleanupHelper;
} }
void update_vk_image(void* context, GrContext* grContext) { void update_vk_image(void* context, GrDirectContext* dContext) {
// CONTEXT TODO: Elevate direct context requirement to Android API.
SkASSERT(GrAsDirectContext(grContext));
// no op // no op
} }
@ -539,7 +525,7 @@ static bool can_import_protected_content(GrDirectContext* dContext) {
return false; return false;
} }
GrBackendTexture MakeBackendTexture(GrContext* context, AHardwareBuffer* hardwareBuffer, GrBackendTexture MakeBackendTexture(GrDirectContext* dContext, AHardwareBuffer* hardwareBuffer,
int width, int height, int width, int height,
DeleteImageProc* deleteProc, DeleteImageProc* deleteProc,
UpdateImageProc* updateProc, UpdateImageProc* updateProc,
@ -547,8 +533,6 @@ GrBackendTexture MakeBackendTexture(GrContext* context, AHardwareBuffer* hardwar
bool isProtectedContent, bool isProtectedContent,
const GrBackendFormat& backendFormat, const GrBackendFormat& backendFormat,
bool isRenderable) { bool isRenderable) {
// CONTEXT TODO: Elevate direct context requirement to Android API.
auto dContext = GrAsDirectContext(context);
SkASSERT(dContext); SkASSERT(dContext);
if (!dContext || dContext->abandoned()) { if (!dContext || dContext->abandoned()) {
return GrBackendTexture(); return GrBackendTexture();

View File

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

View File

@ -626,7 +626,7 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBuffer(AHardwareBuffer* graphicBuffer,
return SkImage::MakeFromGenerator(std::move(gen)); return SkImage::MakeFromGenerator(std::move(gen));
} }
sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context, sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrDirectContext* dContext,
const SkPixmap& pixmap, const SkPixmap& pixmap,
AHardwareBuffer* hardwareBuffer, AHardwareBuffer* hardwareBuffer,
GrSurfaceOrigin surfaceOrigin) { GrSurfaceOrigin surfaceOrigin) {
@ -637,12 +637,6 @@ sk_sp<SkImage> SkImage::MakeFromAHardwareBufferWithData(GrContext* context,
return nullptr; return nullptr;
} }
auto dContext = GrAsDirectContext(context);
if (!dContext) {
SkDebugf("Direct context required\n");
return nullptr;
}
GrBackendFormat backendFormat = GrAHardwareBufferUtils::GetBackendFormat(dContext, GrBackendFormat backendFormat = GrAHardwareBufferUtils::GetBackendFormat(dContext,
hardwareBuffer, hardwareBuffer,
bufferDesc.format, 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 // 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 // let the cache know it is waiting on an unref message. We will send that message from
// our destructor. // our destructor.
GrContext* context = fTexture->getContext(); auto dContext = fTexture->getContext();
context->priv().getResourceCache()->insertDelayedTextureUnref(fTexture); dContext->priv().getResourceCache()->insertDelayedTextureUnref(fTexture);
fTextureContextID = context->priv().contextID(); fTextureContextID = dContext->priv().contextID();
return {std::move(tex), kReleaseCallbackOnInstantiation, kKeySyncMode}; return {std::move(tex), kReleaseCallbackOnInstantiation, kKeySyncMode};
} }

View File

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

View File

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

View File

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