Migrate SkImage::MakeFromTexture to GrRecordingContext

Android migration landed in Android CL 12234077
Chrome migration is landing in Chrome CL 2335812

Note: makeFromCompressedTexture is not used by Chrome.

Bug: skia:104662
Change-Id: Ibbe6d412cf22e87188926383d10b21f780208e48
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305102
Commit-Queue: Adlai Holler <adlai@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
This commit is contained in:
Adlai Holler 2020-08-03 12:50:40 -04:00 committed by Skia Commit-Bot
parent 066f7d6b1a
commit daa9e7455d
21 changed files with 239 additions and 261 deletions

View File

@ -3,9 +3,9 @@
#include "tools/fiddle/examples.h"
// HASH=06aeb3cf63ffccf7b49fe556e5def351
REG_FIDDLE(Image_MakeBackendTextureFromSkImage, 256, 64, false, 0) {
static sk_sp<SkImage> create_gpu_image(GrContext* grContext) {
static sk_sp<SkImage> create_gpu_image(GrRecordingContext* rContext) {
const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType);
auto surface(SkSurface::MakeRenderTarget(grContext, SkBudgeted::kNo, info));
auto surface(SkSurface::MakeRenderTarget(rContext, SkBudgeted::kNo, info));
SkCanvas* canvas = surface->getCanvas();
canvas->clear(SK_ColorWHITE);
SkPaint paint;
@ -15,19 +15,19 @@ static sk_sp<SkImage> create_gpu_image(GrContext* grContext) {
}
void draw(SkCanvas* canvas) {
GrContext* grContext = canvas->getGrContext();
if (!grContext) {
auto dContext = GrAsDirectContext(canvas->recordingContext());
if (!dContext) {
return;
}
sk_sp<SkImage> backEndImage = create_gpu_image(grContext);
sk_sp<SkImage> backEndImage = create_gpu_image(dContext);
canvas->drawImage(backEndImage, 0, 0);
GrBackendTexture texture;
SkImage::BackendTextureReleaseProc proc;
if (!SkImage::MakeBackendTextureFromSkImage(grContext, std::move(backEndImage),
if (!SkImage::MakeBackendTextureFromSkImage(dContext, std::move(backEndImage),
&texture, &proc)) {
return;
}
sk_sp<SkImage> i2 = SkImage::MakeFromTexture(grContext, texture, kTopLeft_GrSurfaceOrigin,
sk_sp<SkImage> i2 = SkImage::MakeFromTexture(dContext, texture, kTopLeft_GrSurfaceOrigin,
kN32_SkColorType, kOpaque_SkAlphaType, nullptr);
canvas->drawImage(i2, 30, 30);
}

View File

@ -4,14 +4,14 @@
// HASH=94e9296c53bad074bf2a48ff885dac13
REG_FIDDLE(Image_MakeFromTexture, 256, 128, false, 3) {
void draw(SkCanvas* canvas) {
GrContext* context = canvas->getGrContext();
if (!context) {
auto dContext = GrAsDirectContext(canvas->recordingContext());
if (!dContext) {
return;
}
canvas->scale(.25f, .25f);
int x = 0;
for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) {
sk_sp<SkImage> image = SkImage::MakeFromTexture(context, backEndTexture,
sk_sp<SkImage> image = SkImage::MakeFromTexture(dContext, backEndTexture,
origin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType, nullptr);
canvas->drawImage(image, x, 0);
x += 512;

View File

@ -4,8 +4,8 @@
// HASH=2b1e46354d823dbb53fa6af570135329
REG_FIDDLE(Image_MakeFromTexture_2, 256, 256, false, 4) {
void draw(SkCanvas* canvas) {
GrContext* context = canvas->getGrContext();
if (!context) {
auto dContext = GrAsDirectContext(canvas->recordingContext());
if (!dContext) {
return;
}
auto debugster = [](SkImage::ReleaseContext releaseContext) -> void {
@ -13,7 +13,7 @@ void draw(SkCanvas* canvas) {
};
int x = 0, y = 0;
for (auto origin : { kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin } ) {
sk_sp<SkImage> image = SkImage::MakeFromTexture(context, backEndTexture,
sk_sp<SkImage> image = SkImage::MakeFromTexture(dContext, backEndTexture,
origin, kRGBA_8888_SkColorType, kOpaque_SkAlphaType, nullptr, debugster, &x);
canvas->drawImage(image, x, y);
y += 128;

View File

@ -4,6 +4,10 @@
// HASH=afc62f38aebc56af8e425297ec67dd37
REG_FIDDLE(Image_isValid, 256, 256, false, 5) {
void draw(SkCanvas* canvas) {
auto dContext = GrAsDirectContext(canvas->recordingContext());
if (!dContext) {
return;
}
auto drawImage = [=](sk_sp<SkImage> image, const char* label) -> void {
if (nullptr == image) {
return;
@ -13,20 +17,19 @@ void draw(SkCanvas* canvas) {
paint.setAntiAlias(true);
canvas->drawImage(image, 0, 0);
canvas->drawString(label, image->width() / 2, image->height() / 4, font, paint);
if (canvas->recordingContext()) {
const char* msg = image->isValid(canvas->recordingContext()) ? "is valid on GPU"
: "not valid on GPU";
if (dContext) {
const char* msg = image->isValid(dContext) ? "is valid on GPU"
: "not valid on GPU";
canvas->drawString(msg, 20, image->height() * 5 / 8, font, paint);
}
// CONTEXT TODO: Once GrContext is gone, remove this cast
const char* msg = image->isValid((GrRecordingContext*) nullptr) ? "is valid on CPU"
: "not valid on CPU";
const char* msg = image->isValid(nullptr) ? "is valid on CPU"
: "not valid on CPU";
canvas->drawString(msg, 20, image->height() * 7 / 8, font, paint);
};
sk_sp<SkImage> bitmapImage(SkImage::MakeFromBitmap(source));
sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(canvas->getGrContext(), backEndTexture,
sk_sp<SkImage> textureImage(SkImage::MakeFromTexture(dContext, backEndTexture,
kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType,
kOpaque_SkAlphaType, nullptr));
drawImage(image, "image");

View File

@ -1191,7 +1191,9 @@ protected:
kTopLeft_GrSurfaceOrigin,
ct,
kPremul_SkAlphaType,
nullptr);
nullptr /* colorSpace */,
nullptr /* releaseProc */,
nullptr /* releaseContext */);
GrBackendTexture tmp = dContext->createBackendTexture(shrunkPlaneSize.width(),
shrunkPlaneSize.height(),

View File

@ -278,27 +278,6 @@ public:
*/
typedef void (*TextureReleaseProc)(ReleaseContext releaseContext);
/** Creates SkImage from GPU texture associated with context. Caller is responsible for
managing the lifetime of GPU texture.
SkImage is returned if format of backendTexture is recognized and supported.
Recognized formats vary by GPU back-end.
@param context GPU context
@param backendTexture texture residing on GPU
@param colorSpace range of colors; may be nullptr
@return created SkImage, or nullptr
*/
static sk_sp<SkImage> MakeFromTexture(GrContext* context,
const GrBackendTexture& backendTexture,
GrSurfaceOrigin origin,
SkColorType colorType,
SkAlphaType alphaType,
sk_sp<SkColorSpace> colorSpace) {
return MakeFromTexture(context, backendTexture, origin, colorType, alphaType, colorSpace,
nullptr, nullptr);
}
/** Creates SkImage from GPU texture associated with context. GPU texture must stay
valid and unchanged until textureReleaseProc is called. textureReleaseProc is
passed releaseContext when SkImage is deleted or no longer refers to texture.
@ -306,6 +285,9 @@ public:
SkImage is returned if format of backendTexture is recognized and supported.
Recognized formats vary by GPU back-end.
@note When using a DDL recording context, textureReleaseProc will be called on the
GPU thread after the DDL is played back on the direct context.
@param context GPU context
@param backendTexture texture residing on GPU
@param colorSpace This describes the color space of this image's contents, as
@ -319,14 +301,14 @@ public:
@param releaseContext state passed to textureReleaseProc
@return created SkImage, or nullptr
*/
static sk_sp<SkImage> MakeFromTexture(GrContext* context,
static sk_sp<SkImage> MakeFromTexture(GrRecordingContext* context,
const GrBackendTexture& backendTexture,
GrSurfaceOrigin origin,
SkColorType colorType,
SkAlphaType alphaType,
sk_sp<SkColorSpace> colorSpace,
TextureReleaseProc textureReleaseProc,
ReleaseContext releaseContext);
TextureReleaseProc textureReleaseProc = nullptr,
ReleaseContext releaseContext = nullptr);
/** Creates an SkImage from a GPU backend texture. The backend texture must stay
valid and unchanged until textureReleaseProc is called. The textureReleaseProc is
@ -336,6 +318,9 @@ public:
An SkImage is returned if the format of backendTexture is recognized and supported.
Recognized formats vary by GPU back-end.
@note When using a DDL recording context, textureReleaseProc will be called on the
GPU thread after the DDL is played back on the direct context.
@param context the GPU context
@param backendTexture a texture already allocated by the GPU
@param alphaType This characterizes the nature of the alpha values in the
@ -352,7 +337,7 @@ public:
@param releaseContext state passed to textureReleaseProc
@return created SkImage, or nullptr
*/
static sk_sp<SkImage> MakeFromCompressedTexture(GrContext* context,
static sk_sp<SkImage> MakeFromCompressedTexture(GrRecordingContext* context,
const GrBackendTexture& backendTexture,
GrSurfaceOrigin origin,
SkAlphaType alphaType,

View File

@ -505,20 +505,20 @@ sk_sp<SkImage> SkImage::makeRasterImage(CachingHint chint) const {
#if !SK_SUPPORT_GPU
sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx,
const GrBackendTexture& tex, GrSurfaceOrigin origin,
SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs,
TextureReleaseProc releaseP, ReleaseContext releaseC) {
sk_sp<SkImage> SkImage::MakeFromTexture(GrRecordingContext*,
const GrBackendTexture&, GrSurfaceOrigin,
SkColorType, SkAlphaType, sk_sp<SkColorSpace>,
TextureReleaseProc, ReleaseContext) {
return nullptr;
}
sk_sp<SkImage> SkImage::MakeFromCompressedTexture(GrContext* ctx,
const GrBackendTexture& tex,
GrSurfaceOrigin origin,
SkAlphaType at,
sk_sp<SkColorSpace> cs,
TextureReleaseProc releaseP,
ReleaseContext releaseC) {
sk_sp<SkImage> SkImage::MakeFromCompressedTexture(GrRecordingContext*,
const GrBackendTexture&,
GrSurfaceOrigin,
SkAlphaType,
sk_sp<SkColorSpace>,
TextureReleaseProc,
ReleaseContext) {
return nullptr;
}
@ -561,16 +561,14 @@ sk_sp<SkImage> SkImage::MakeFromYUVATexturesCopyWithExternalBackend(
}
sk_sp<SkImage> SkImage::MakeFromYUVTexturesCopyWithExternalBackend(
GrContext* context, SkYUVColorSpace yuvColorSpace, const GrBackendTexture yuvTextures[3],
GrSurfaceOrigin surfaceOrigin, const GrBackendTexture& backendTexture,
sk_sp<SkColorSpace> colorSpace) {
GrContext*, SkYUVColorSpace, const GrBackendTexture[3], GrSurfaceOrigin,
const GrBackendTexture&, sk_sp<SkColorSpace>) {
return nullptr;
}
sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace space,
const GrBackendTexture[2],
GrSurfaceOrigin origin,
sk_sp<SkColorSpace> imageColorSpace) {
sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext*, SkYUVColorSpace,
const GrBackendTexture[2],
GrSurfaceOrigin, sk_sp<SkColorSpace>) {
return nullptr;
}
@ -580,14 +578,8 @@ sk_sp<SkImage> SkImage::makeTextureImage(GrDirectContext*, GrMipmapped, SkBudget
}
sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopyWithExternalBackend(
GrContext* context,
SkYUVColorSpace yuvColorSpace,
const GrBackendTexture nv12Textures[2],
GrSurfaceOrigin imageOrigin,
const GrBackendTexture& backendTexture,
sk_sp<SkColorSpace> imageColorSpace,
TextureReleaseProc textureReleaseProc,
ReleaseContext releaseContext) {
GrContext*, SkYUVColorSpace, const GrBackendTexture[2], GrSurfaceOrigin,
const GrBackendTexture&, sk_sp<SkColorSpace>, TextureReleaseProc, ReleaseContext) {
return nullptr;
}

View File

@ -163,7 +163,7 @@ void SkImage_Gpu::onAsyncRescaleAndReadPixelsYUV420(SkYUVColorSpace yuvColorSpac
///////////////////////////////////////////////////////////////////////////////////////////////////
static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx,
static sk_sp<SkImage> new_wrapped_texture_common(GrRecordingContext* rContext,
const GrBackendTexture& backendTex,
GrColorType colorType, GrSurfaceOrigin origin,
SkAlphaType at, sk_sp<SkColorSpace> colorSpace,
@ -173,20 +173,21 @@ static sk_sp<SkImage> new_wrapped_texture_common(GrContext* ctx,
return nullptr;
}
GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
sk_sp<GrTextureProxy> proxy = proxyProvider->wrapBackendTexture(
backendTex, ownership, GrWrapCacheable::kNo, kRead_GrIOType, std::move(releaseHelper));
if (!proxy) {
return nullptr;
}
GrSwizzle swizzle = ctx->priv().caps()->getReadSwizzle(proxy->backendFormat(), colorType);
GrSwizzle swizzle = rContext->priv().caps()->getReadSwizzle(proxy->backendFormat(), colorType);
GrSurfaceProxyView view(std::move(proxy), origin, swizzle);
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, std::move(view),
auto grContext = rContext->priv().backdoor();
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(grContext), kNeedNewImageUniqueID, std::move(view),
GrColorTypeToSkColorType(colorType), at, std::move(colorSpace));
}
sk_sp<SkImage> SkImage::MakeFromCompressedTexture(GrContext* ctx,
sk_sp<SkImage> SkImage::MakeFromCompressedTexture(GrRecordingContext* rContext,
const GrBackendTexture& tex,
GrSurfaceOrigin origin,
SkAlphaType at,
@ -198,17 +199,17 @@ sk_sp<SkImage> SkImage::MakeFromCompressedTexture(GrContext* ctx,
releaseHelper.reset(new GrRefCntedCallback(releaseP, releaseC));
}
if (!ctx) {
if (!rContext) {
return nullptr;
}
const GrCaps* caps = ctx->priv().caps();
const GrCaps* caps = rContext->priv().caps();
if (!SkImage_GpuBase::ValidateCompressedBackendTexture(caps, tex, at)) {
return nullptr;
}
GrProxyProvider* proxyProvider = ctx->priv().proxyProvider();
GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
sk_sp<GrTextureProxy> proxy = proxyProvider->wrapCompressedBackendTexture(
tex, kBorrow_GrWrapOwnership, GrWrapCacheable::kNo, std::move(releaseHelper));
if (!proxy) {
@ -219,11 +220,12 @@ sk_sp<SkImage> SkImage::MakeFromCompressedTexture(GrContext* ctx,
SkColorType ct = GrCompressionTypeToSkColorType(type);
GrSurfaceProxyView view(std::move(proxy), origin, GrSwizzle::RGBA());
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(ctx), kNeedNewImageUniqueID, std::move(view), ct, at,
std::move(cs));
auto grContext = rContext->priv().backdoor();
return sk_make_sp<SkImage_Gpu>(sk_ref_sp(grContext), kNeedNewImageUniqueID, std::move(view),
ct, at, std::move(cs));
}
sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx,
sk_sp<SkImage> SkImage::MakeFromTexture(GrRecordingContext* rContext,
const GrBackendTexture& tex, GrSurfaceOrigin origin,
SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs,
TextureReleaseProc releaseP, ReleaseContext releaseC) {
@ -232,11 +234,11 @@ sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx,
releaseHelper.reset(new GrRefCntedCallback(releaseP, releaseC));
}
if (!ctx) {
if (!rContext) {
return nullptr;
}
const GrCaps* caps = ctx->priv().caps();
const GrCaps* caps = rContext->priv().caps();
GrColorType grColorType = SkColorTypeAndFormatToGrColorType(caps, ct, tex.getBackendFormat());
if (GrColorType::kUnknown == grColorType) {
@ -247,7 +249,7 @@ sk_sp<SkImage> SkImage::MakeFromTexture(GrContext* ctx,
return nullptr;
}
return new_wrapped_texture_common(ctx, tex, grColorType, origin, at, std::move(cs),
return new_wrapped_texture_common(rContext, tex, grColorType, origin, at, std::move(cs),
kBorrow_GrWrapOwnership, std::move(releaseHelper));
}

View File

@ -20,10 +20,10 @@
#include "src/gpu/vk/GrVkTexture.h"
DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkBackendSurfaceMutableStateTest, reporter, ctxInfo) {
auto context = ctxInfo.directContext();
auto dContext = ctxInfo.directContext();
GrBackendFormat format = GrBackendFormat::MakeVk(VK_FORMAT_R8G8B8A8_UNORM);
GrBackendTexture backendTex = context->createBackendTexture(
GrBackendTexture backendTex = dContext->createBackendTexture(
32, 32, format, GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo);
REPORTER_ASSERT(reporter, backendTex.isValid());
@ -56,12 +56,12 @@ DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkBackendSurfaceMutableStateTest, reporter, ctxIn
// Setting back to the init state since we didn't actually change it
backendTex.setMutableState(initState);
sk_sp<SkImage> wrappedImage = SkImage::MakeFromTexture(context, backendTex,
sk_sp<SkImage> wrappedImage = SkImage::MakeFromTexture(dContext, backendTex,
kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,
kPremul_SkAlphaType, nullptr);
const GrSurfaceProxyView* view = as_IB(wrappedImage)->view(context);
const GrSurfaceProxyView* view = as_IB(wrappedImage)->view(dContext);
REPORTER_ASSERT(reporter, view);
REPORTER_ASSERT(reporter, view->proxy()->isInstantiated());
GrTexture* texture = view->proxy()->peekTexture();
@ -105,9 +105,9 @@ DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkBackendSurfaceMutableStateTest, reporter, ctxIn
// Test using the setBackendTextureStateAPI. Unlike the previous test this will actually add
// real transitions to the image so we need to be careful about doing actual valid transitions.
GrVkGpu* gpu = static_cast<GrVkGpu*>(context->priv().getGpu());
GrVkGpu* gpu = static_cast<GrVkGpu*>(dContext->priv().getGpu());
context->setBackendTextureState(backendTex, newState);
dContext->setBackendTextureState(backendTex, newState);
REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL == info.fImageLayout);
@ -119,16 +119,16 @@ DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkBackendSurfaceMutableStateTest, reporter, ctxIn
GrBackendSurfaceMutableState externalState(VK_IMAGE_LAYOUT_GENERAL,
VK_QUEUE_FAMILY_EXTERNAL);
context->setBackendTextureState(backendTex, externalState);
dContext->setBackendTextureState(backendTex, externalState);
REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_GENERAL == info.fImageLayout);
REPORTER_ASSERT(reporter, VK_QUEUE_FAMILY_EXTERNAL == info.fCurrentQueueFamily);
context->submit();
dContext->submit();
GrBackendSurfaceMutableState externalState2(VK_IMAGE_LAYOUT_GENERAL, initQueue);
context->setBackendTextureState(backendTex, externalState2);
dContext->setBackendTextureState(backendTex, externalState2);
REPORTER_ASSERT(reporter, backendTex.getVkImageInfo(&info));
REPORTER_ASSERT(reporter, VK_IMAGE_LAYOUT_GENERAL == info.fImageLayout);
@ -136,9 +136,9 @@ DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkBackendSurfaceMutableStateTest, reporter, ctxIn
}
// We must submit this work before we try to delete the backend texture.
context->submit(true);
dContext->submit(true);
context->deleteBackendTexture(backendTex);
dContext->deleteBackendTexture(backendTex);
}
#endif

View File

@ -36,14 +36,14 @@ static void check_solid_pixmap(skiatest::Reporter* reporter,
}
// Create an SkImage to wrap 'backendTex'
sk_sp<SkImage> create_image(GrContext* context, const GrBackendTexture& backendTex) {
sk_sp<SkImage> create_image(GrDirectContext* dContext, const GrBackendTexture& backendTex) {
SkImage::CompressionType compression =
GrBackendFormatToCompressionType(backendTex.getBackendFormat());
SkAlphaType at = SkCompressionTypeIsOpaque(compression) ? kOpaque_SkAlphaType
: kPremul_SkAlphaType;
return SkImage::MakeFromCompressedTexture(context,
return SkImage::MakeFromCompressedTexture(dContext,
backendTex,
kTopLeft_GrSurfaceOrigin,
at,

View File

@ -877,57 +877,52 @@ enum class DDLStage { kMakeImage, kDrawImage, kDetach, kDrawDDL };
// This tests the ability to create and use wrapped textures in a DDL world
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLWrapBackendTest, reporter, ctxInfo) {
auto context = ctxInfo.directContext();
auto dContext = ctxInfo.directContext();
GrBackendTexture backendTex;
CreateBackendTexture(context, &backendTex, kSize, kSize, kRGBA_8888_SkColorType,
CreateBackendTexture(dContext, &backendTex, kSize, kSize, kRGBA_8888_SkColorType,
SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo);
if (!backendTex.isValid()) {
return;
}
SurfaceParameters params(context);
SurfaceParameters params(dContext);
GrBackendTexture backend;
sk_sp<SkSurface> s = params.make(context, &backend);
sk_sp<SkSurface> s = params.make(dContext, &backend);
if (!s) {
context->deleteBackendTexture(backendTex);
dContext->deleteBackendTexture(backendTex);
return;
}
SkSurfaceCharacterization c;
SkAssertResult(s->characterize(&c));
std::unique_ptr<SkDeferredDisplayListRecorder> recorder(new SkDeferredDisplayListRecorder(c));
SkDeferredDisplayListRecorder recorder(c);
SkCanvas* canvas = recorder->getCanvas();
if (!canvas) {
s = nullptr;
params.cleanUpBackEnd(context, backend);
context->deleteBackendTexture(backendTex);
return;
}
SkCanvas* canvas = recorder.getCanvas();
SkASSERT(canvas);
GrContext* deferredContext = canvas->getGrContext();
if (!deferredContext) {
auto rContext = canvas->recordingContext();
if (!rContext) {
s = nullptr;
params.cleanUpBackEnd(context, backend);
context->deleteBackendTexture(backendTex);
params.cleanUpBackEnd(dContext, backend);
dContext->deleteBackendTexture(backendTex);
return;
}
// Wrapped Backend Textures are not supported in DDL
TextureReleaseChecker releaseChecker;
sk_sp<SkImage> image =
SkImage::MakeFromTexture(deferredContext, backendTex, kTopLeft_GrSurfaceOrigin,
SkImage::MakeFromTexture(rContext, backendTex, kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr,
TextureReleaseChecker::Release, &releaseChecker);
REPORTER_ASSERT(reporter, !image);
context->deleteBackendTexture(backendTex);
dContext->deleteBackendTexture(backendTex);
s = nullptr;
params.cleanUpBackEnd(context, backend);
params.cleanUpBackEnd(dContext, backend);
}
static sk_sp<SkPromiseImageTexture> dummy_fulfill_proc(void*) {

View File

@ -47,9 +47,9 @@ static bool params_valid(const GrGLTextureParameters& parameters, const GrGLCaps
}
DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(GLTextureParameters, reporter, ctxInfo) {
auto context = ctxInfo.directContext();
auto dContext = ctxInfo.directContext();
GrBackendTexture backendTex = context->createBackendTexture(
GrBackendTexture backendTex = dContext->createBackendTexture(
1, 1, kRGBA_8888_SkColorType, GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo);
REPORTER_ASSERT(reporter, backendTex.isValid());
@ -60,11 +60,11 @@ DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(GLTextureParameters, reporter, ctxInfo) {
REPORTER_ASSERT(reporter, backendTexCopy.isSameTexture(backendTex));
sk_sp<SkImage> wrappedImage =
SkImage::MakeFromTexture(context, backendTex, kTopLeft_GrSurfaceOrigin,
SkImage::MakeFromTexture(dContext, backendTex, kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);
REPORTER_ASSERT(reporter, wrappedImage);
const GrSurfaceProxyView* view = as_IB(wrappedImage)->view(context);
const GrSurfaceProxyView* view = as_IB(wrappedImage)->view(dContext);
REPORTER_ASSERT(reporter, view);
REPORTER_ASSERT(reporter, view->proxy()->isInstantiated());
auto texture = static_cast<GrGLTexture*>(view->proxy()->peekTexture());
@ -80,13 +80,13 @@ DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(GLTextureParameters, reporter, ctxInfo) {
REPORTER_ASSERT(reporter, params_invalid(*parameters));
auto surf = SkSurface::MakeRenderTarget(
context, SkBudgeted::kYes,
dContext, SkBudgeted::kYes,
SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kPremul_SkAlphaType), 1, nullptr);
REPORTER_ASSERT(reporter, surf);
surf->getCanvas()->drawImage(wrappedImage, 0, 0);
surf->flushAndSubmit();
auto caps = static_cast<const GrGLCaps*>(context->priv().caps());
auto caps = static_cast<const GrGLCaps*>(dContext->priv().caps());
// Now the texture should be in a known state.
REPORTER_ASSERT(reporter, params_valid(*parameters, caps));
@ -127,8 +127,8 @@ DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(GLTextureParameters, reporter, ctxInfo) {
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, invalidTexture));
wrappedImage.reset();
context->flush();
context->submit(true);
context->deleteBackendTexture(backendTex);
dContext->flush();
dContext->submit(true);
dContext->deleteBackendTexture(backendTex);
}
#endif

View File

@ -14,8 +14,8 @@ DEF_GPUTEST(GrDDLImage_MakeSubset, reporter, options) {
sk_gpu_test::GrContextFactory factory(options);
for (int ct = 0; ct < sk_gpu_test::GrContextFactory::kContextTypeCnt; ++ct) {
auto contextType = static_cast<sk_gpu_test::GrContextFactory::ContextType>(ct);
auto direct = factory.get(contextType);
if (!direct) {
auto dContext = factory.get(contextType);
if (!dContext) {
continue;
}
SkIRect subsetBounds = SkIRect::MakeLTRB(4,4,8,8);
@ -31,32 +31,32 @@ DEF_GPUTEST(GrDDLImage_MakeSubset, reporter, options) {
REPORTER_ASSERT(reporter, rasterImg->isValid(static_cast<GrRecordingContext*>(nullptr)));
// raster + context:
auto subImg1 = rasterImg->makeSubset(subsetBounds, direct);
REPORTER_ASSERT(reporter, subImg1->isValid(direct));
auto subImg1 = rasterImg->makeSubset(subsetBounds, dContext);
REPORTER_ASSERT(reporter, subImg1->isValid(dContext));
// raster + no context:
auto subImg2 = rasterImg->makeSubset(subsetBounds, nullptr);
REPORTER_ASSERT(reporter, subImg2->isValid(static_cast<GrRecordingContext*>(nullptr)));
// Texture image:
auto surf = SkSurface::MakeRenderTarget(direct, SkBudgeted::kNo, ii);
auto surf = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, ii);
SkSurfaceCharacterization sc;
REPORTER_ASSERT(reporter, surf->characterize(&sc));
GrBackendTexture tex = direct->createBackendTexture(sc);
auto gpuImage = SkImage::MakeFromTexture(direct, tex, kTopLeft_GrSurfaceOrigin,
GrBackendTexture tex = dContext->createBackendTexture(sc);
auto gpuImage = SkImage::MakeFromTexture(dContext, tex, kTopLeft_GrSurfaceOrigin,
ii.colorType(), ii.alphaType(),
ii.refColorSpace());
REPORTER_ASSERT(reporter, gpuImage->isValid(direct));
REPORTER_ASSERT(reporter, gpuImage->isValid(dContext));
// gpu image + context:
auto subImg5 = gpuImage->makeSubset(subsetBounds, direct);
REPORTER_ASSERT(reporter, subImg5->isValid(direct));
auto subImg5 = gpuImage->makeSubset(subsetBounds, dContext);
REPORTER_ASSERT(reporter, subImg5->isValid(dContext));
// gpu image + nullptr:
REPORTER_ASSERT(reporter, !gpuImage->makeSubset(subsetBounds, nullptr));
direct->flush();
direct->submit(true);
direct->deleteBackendTexture(tex);
dContext->flush();
dContext->submit(true);
dContext->deleteBackendTexture(tex);
}
}

View File

@ -34,8 +34,8 @@ static constexpr int kSize = 8;
// Test that the correct mip map states are on the GrTextures when wrapping GrBackendTextures in
// SkImages and SkSurfaces
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) {
auto context = ctxInfo.directContext();
if (!context->priv().caps()->mipmapSupport()) {
auto dContext = ctxInfo.directContext();
if (!dContext->priv().caps()->mipmapSupport()) {
return;
}
@ -45,14 +45,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) {
// so we don't send any. However, we pretend there is data for the checks below which is
// fine since we are never actually using these textures for any work on the gpu.
GrBackendTexture backendTex;
CreateBackendTexture(context, &backendTex, kSize, kSize, kRGBA_8888_SkColorType,
CreateBackendTexture(dContext, &backendTex, kSize, kSize, kRGBA_8888_SkColorType,
SkColors::kTransparent, mipMapped, renderable);
sk_sp<GrTextureProxy> proxy;
sk_sp<SkImage> image;
if (GrRenderable::kYes == renderable) {
sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture(
context,
dContext,
backendTex,
kTopLeft_GrSurfaceOrigin,
0,
@ -63,22 +63,22 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) {
SkGpuDevice* device = ((SkSurface_Gpu*)surface.get())->getDevice();
proxy = device->accessRenderTargetContext()->asTextureProxyRef();
} else {
image = SkImage::MakeFromTexture(context, backendTex,
image = SkImage::MakeFromTexture(dContext, backendTex,
kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,
kPremul_SkAlphaType, nullptr,
nullptr, nullptr);
const GrSurfaceProxyView* view = as_IB(image)->view(context);
const GrSurfaceProxyView* view = as_IB(image)->view(dContext);
REPORTER_ASSERT(reporter, view);
if (!view) {
context->deleteBackendTexture(backendTex);
dContext->deleteBackendTexture(backendTex);
return;
}
proxy = view->asTextureProxyRef();
}
REPORTER_ASSERT(reporter, proxy);
if (!proxy) {
context->deleteBackendTexture(backendTex);
dContext->deleteBackendTexture(backendTex);
return;
}
@ -87,7 +87,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) {
GrTexture* texture = proxy->peekTexture();
REPORTER_ASSERT(reporter, texture);
if (!texture) {
context->deleteBackendTexture(backendTex);
dContext->deleteBackendTexture(backendTex);
return;
}
@ -101,7 +101,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) {
} else {
REPORTER_ASSERT(reporter, GrMipmapped::kNo == texture->mipmapped());
}
context->deleteBackendTexture(backendTex);
dContext->deleteBackendTexture(backendTex);
}
}
}
@ -109,18 +109,18 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrWrappedMipMappedTest, reporter, ctxInfo) {
// Test that we correctly copy or don't copy GrBackendTextures in the GrBackendTextureImageGenerator
// based on if we will use mips in the draw and the mip status of the GrBackendTexture.
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter, ctxInfo) {
auto context = ctxInfo.directContext();
if (!context->priv().caps()->mipmapSupport()) {
auto dContext = ctxInfo.directContext();
if (!dContext->priv().caps()->mipmapSupport()) {
return;
}
for (auto betMipMapped : {GrMipmapped::kNo, GrMipmapped::kYes}) {
for (auto requestMipMapped : {GrMipmapped::kNo, GrMipmapped::kYes}) {
GrBackendTexture backendTex;
CreateBackendTexture(context, &backendTex, kSize, kSize, kRGBA_8888_SkColorType,
CreateBackendTexture(dContext, &backendTex, kSize, kSize, kRGBA_8888_SkColorType,
SkColors::kTransparent, betMipMapped, GrRenderable::kNo);
sk_sp<SkImage> image = SkImage::MakeFromTexture(context, backendTex,
sk_sp<SkImage> image = SkImage::MakeFromTexture(dContext, backendTex,
kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,
kPremul_SkAlphaType, nullptr,
@ -129,7 +129,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter,
GrTextureProxy* proxy = as_IB(image)->peekProxy();
REPORTER_ASSERT(reporter, proxy);
if (!proxy) {
context->deleteBackendTexture(backendTex);
dContext->deleteBackendTexture(backendTex);
return;
}
@ -138,7 +138,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter,
sk_sp<GrTexture> texture = sk_ref_sp(proxy->peekTexture());
REPORTER_ASSERT(reporter, texture);
if (!texture) {
context->deleteBackendTexture(backendTex);
dContext->deleteBackendTexture(backendTex);
return;
}
@ -147,7 +147,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter,
kPremul_SkAlphaType, nullptr);
REPORTER_ASSERT(reporter, imageGen);
if (!imageGen) {
context->deleteBackendTexture(backendTex);
dContext->deleteBackendTexture(backendTex);
return;
}
@ -155,31 +155,31 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter,
SkImageInfo imageInfo = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType,
kPremul_SkAlphaType);
GrSurfaceProxyView genView = imageGen->generateTexture(
context, imageInfo, origin, requestMipMapped, GrImageTexGenPolicy::kDraw);
dContext, imageInfo, origin, requestMipMapped, GrImageTexGenPolicy::kDraw);
GrSurfaceProxy* genProxy = genView.proxy();
REPORTER_ASSERT(reporter, genProxy);
if (!genProxy) {
context->deleteBackendTexture(backendTex);
dContext->deleteBackendTexture(backendTex);
return;
}
if (genProxy->isLazy()) {
genProxy->priv().doLazyInstantiation(context->priv().resourceProvider());
genProxy->priv().doLazyInstantiation(dContext->priv().resourceProvider());
} else if (!genProxy->isInstantiated()) {
genProxy->instantiate(context->priv().resourceProvider());
genProxy->instantiate(dContext->priv().resourceProvider());
}
REPORTER_ASSERT(reporter, genProxy->isInstantiated());
if (!genProxy->isInstantiated()) {
context->deleteBackendTexture(backendTex);
dContext->deleteBackendTexture(backendTex);
return;
}
GrTexture* genTexture = genProxy->peekTexture();
REPORTER_ASSERT(reporter, genTexture);
if (!genTexture) {
context->deleteBackendTexture(backendTex);
dContext->deleteBackendTexture(backendTex);
return;
}
@ -237,11 +237,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter,
// Must make sure the uses of the backend texture have finished (we possibly have a
// queued up copy) before we delete the backend texture.
context->flushAndSubmit();
dContext->flushAndSubmit();
context->priv().getGpu()->testingOnly_flushGpuAndSync();
dContext->priv().getGpu()->testingOnly_flushGpuAndSync();
context->deleteBackendTexture(backendTex);
dContext->deleteBackendTexture(backendTex);
}
}
}
@ -249,22 +249,22 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrBackendTextureImageMipMappedTest, reporter,
// Test that when we call makeImageSnapshot on an SkSurface we retains the same mip status as the
// resource we took the snapshot of.
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxInfo) {
auto context = ctxInfo.directContext();
if (!context->priv().caps()->mipmapSupport()) {
auto dContext = ctxInfo.directContext();
if (!dContext->priv().caps()->mipmapSupport()) {
return;
}
auto resourceProvider = context->priv().resourceProvider();
auto resourceProvider = dContext->priv().resourceProvider();
for (auto willUseMips : {false, true}) {
for (auto isWrapped : {false, true}) {
GrMipmapped mipMapped = willUseMips ? GrMipmapped::kYes : GrMipmapped::kNo;
sk_sp<SkSurface> surface;
GrBackendTexture backendTex;
CreateBackendTexture(context, &backendTex, kSize, kSize, kRGBA_8888_SkColorType,
CreateBackendTexture(dContext, &backendTex, kSize, kSize, kRGBA_8888_SkColorType,
SkColors::kTransparent, mipMapped, GrRenderable::kYes);
if (isWrapped) {
surface = SkSurface::MakeFromBackendTexture(context,
surface = SkSurface::MakeFromBackendTexture(dContext,
backendTex,
kTopLeft_GrSurfaceOrigin,
0,
@ -274,13 +274,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxIn
} else {
SkImageInfo info = SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType,
kPremul_SkAlphaType);
surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info, 0,
surface = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kYes, info, 0,
kTopLeft_GrSurfaceOrigin, nullptr,
willUseMips);
}
REPORTER_ASSERT(reporter, surface);
if (!surface) {
context->deleteBackendTexture(backendTex);
dContext->deleteBackendTexture(backendTex);
}
SkGpuDevice* device = ((SkSurface_Gpu*)surface.get())->getDevice();
GrTextureProxy* texProxy = device->accessRenderTargetContext()->asTextureProxy();
@ -293,7 +293,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxIn
sk_sp<SkImage> image = surface->makeImageSnapshot();
REPORTER_ASSERT(reporter, image);
if (!image) {
context->deleteBackendTexture(backendTex);
dContext->deleteBackendTexture(backendTex);
}
texProxy = as_IB(image)->peekProxy();
REPORTER_ASSERT(reporter, mipMapped == texProxy->mipmapped());
@ -302,11 +302,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxIn
texture = texProxy->peekTexture();
REPORTER_ASSERT(reporter, mipMapped == texture->mipmapped());
// Must flush the context to make sure all the cmds (copies, etc.) from above are sent
// Must flush the dContext to make sure all the cmds (copies, etc.) from above are sent
// to the gpu before we delete the backendHandle.
context->flushAndSubmit();
context->priv().getGpu()->testingOnly_flushGpuAndSync();
context->deleteBackendTexture(backendTex);
dContext->flushAndSubmit();
dContext->priv().getGpu()->testingOnly_flushGpuAndSync();
dContext->deleteBackendTexture(backendTex);
}
}
}
@ -314,14 +314,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrImageSnapshotMipMappedTest, reporter, ctxIn
// Test that we don't create a mip mapped texture if the size is 1x1 even if the filter mode is set
// to use mips. This test passes by not crashing or hitting asserts in code.
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(Gr1x1TextureMipMappedTest, reporter, ctxInfo) {
auto context = ctxInfo.directContext();
if (!context->priv().caps()->mipmapSupport()) {
auto dContext = ctxInfo.directContext();
if (!dContext->priv().caps()->mipmapSupport()) {
return;
}
// Make surface to draw into
SkImageInfo info = SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType);
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info);
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, info);
// Make 1x1 raster bitmap
SkBitmap bmp;
@ -349,12 +349,12 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(Gr1x1TextureMipMappedTest, reporter, ctxInfo)
// Create a new render target and draw 'mipmapView' into it using the provided 'filter'.
static std::unique_ptr<GrRenderTargetContext> draw_mipmap_into_new_render_target(
GrRecordingContext* context,
GrProxyProvider* proxyProvider,
GrRecordingContext* rContext,
GrColorType colorType,
SkAlphaType alphaType,
GrSurfaceProxyView mipmapView,
GrSamplerState::MipmapMode mm) {
auto proxyProvider = rContext->priv().proxyProvider();
sk_sp<GrSurfaceProxy> renderTarget =
proxyProvider->createProxy(mipmapView.proxy()->backendFormat(),
{1, 1},
@ -365,7 +365,7 @@ static std::unique_ptr<GrRenderTargetContext> draw_mipmap_into_new_render_target
SkBudgeted::kYes,
GrProtected::kNo);
auto rtc = GrRenderTargetContext::Make(context,
auto rtc = GrRenderTargetContext::Make(rContext,
colorType,
nullptr,
std::move(renderTarget),
@ -399,22 +399,22 @@ DEF_GPUTEST(GrManyDependentsMipMappedTest, reporter, /* options */) {
mockOptions.fMipmapSupport = true;
GrContextOptions ctxOptions;
ctxOptions.fReduceOpsTaskSplitting = enableSortingAndReduction;
sk_sp<GrDirectContext> context = GrDirectContext::MakeMock(&mockOptions, ctxOptions);
GrDrawingManager* drawingManager = context->priv().drawingManager();
if (!context) {
ERRORF(reporter, "could not create mock context with fReduceOpsTaskSplitting %s.",
sk_sp<GrDirectContext> dContext = GrDirectContext::MakeMock(&mockOptions, ctxOptions);
GrDrawingManager* drawingManager = dContext->priv().drawingManager();
if (!dContext) {
ERRORF(reporter, "could not create mock dContext with fReduceOpsTaskSplitting %s.",
(Enable::kYes == enableSortingAndReduction) ? "enabled" : "disabled");
continue;
}
SkASSERT(context->priv().caps()->mipmapSupport());
SkASSERT(dContext->priv().caps()->mipmapSupport());
GrBackendFormat format = context->defaultBackendFormat(
GrBackendFormat format = dContext->defaultBackendFormat(
kRGBA_8888_SkColorType, GrRenderable::kYes);
GrColorType colorType = GrColorType::kRGBA_8888;
SkAlphaType alphaType = kPremul_SkAlphaType;
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
// Create a mipmapped render target.
@ -427,7 +427,7 @@ DEF_GPUTEST(GrManyDependentsMipMappedTest, reporter, /* options */) {
mipmapProxy->markMipmapsClean();
auto mipmapRTC = GrRenderTargetContext::Make(
context.get(), colorType, nullptr, mipmapProxy, kTopLeft_GrSurfaceOrigin, nullptr);
dContext.get(), colorType, nullptr, mipmapProxy, kTopLeft_GrSurfaceOrigin, nullptr);
mipmapRTC->clear({.1f,.2f,.3f,.4f});
REPORTER_ASSERT(reporter, drawingManager->getLastRenderTask(mipmapProxy.get()));
@ -439,12 +439,12 @@ DEF_GPUTEST(GrManyDependentsMipMappedTest, reporter, /* options */) {
// Mipmaps don't get marked dirty until makeClosed().
REPORTER_ASSERT(reporter, !mipmapProxy->mipmapsAreDirty());
GrSwizzle swizzle = context->priv().caps()->getReadSwizzle(format, colorType);
GrSwizzle swizzle = dContext->priv().caps()->getReadSwizzle(format, colorType);
GrSurfaceProxyView mipmapView(mipmapProxy, kTopLeft_GrSurfaceOrigin, swizzle);
// Draw the dirty mipmap texture into a render target.
auto rtc1 = draw_mipmap_into_new_render_target(context.get(), proxyProvider, colorType,
alphaType, mipmapView, MipmapMode::kLinear);
auto rtc1 = draw_mipmap_into_new_render_target(dContext.get(), colorType, alphaType,
mipmapView, MipmapMode::kLinear);
auto rtc1Task = sk_ref_sp(rtc1->testingOnly_PeekLastOpsTask());
// Mipmaps should have gotten marked dirty during makeClosed, then marked clean again as
@ -458,8 +458,8 @@ DEF_GPUTEST(GrManyDependentsMipMappedTest, reporter, /* options */) {
REPORTER_ASSERT(reporter, !mipmapProxy->mipmapsAreDirty());
// Draw the now-clean mipmap texture into a second target.
auto rtc2 = draw_mipmap_into_new_render_target(context.get(), proxyProvider, colorType,
alphaType, mipmapView, MipmapMode::kLinear);
auto rtc2 = draw_mipmap_into_new_render_target(dContext.get(), colorType, alphaType,
mipmapView, MipmapMode::kLinear);
auto rtc2Task = sk_ref_sp(rtc2->testingOnly_PeekLastOpsTask());
// Make sure the mipmap texture still has the same regen task.
@ -468,7 +468,7 @@ DEF_GPUTEST(GrManyDependentsMipMappedTest, reporter, /* options */) {
SkASSERT(!mipmapProxy->mipmapsAreDirty());
// Reset everything so we can go again, this time with the first draw not mipmapped.
context->flushAndSubmit();
dContext->flushAndSubmit();
// Mip regen tasks don't get added as dependencies until makeClosed().
REPORTER_ASSERT(reporter, rtc1Task->dependsOn(initialMipmapRegenTask));
@ -487,8 +487,8 @@ DEF_GPUTEST(GrManyDependentsMipMappedTest, reporter, /* options */) {
REPORTER_ASSERT(reporter, !mipmapProxy->mipmapsAreDirty());
// Draw the dirty mipmap texture into a render target, but don't do mipmap filtering.
rtc1 = draw_mipmap_into_new_render_target(context.get(), proxyProvider, colorType,
alphaType, mipmapView, MipmapMode::kNone);
rtc1 = draw_mipmap_into_new_render_target(dContext.get(), colorType, alphaType,
mipmapView, MipmapMode::kNone);
// Mipmaps should have gotten marked dirty during makeClosed() when adding the dependency.
// Since the last draw did not use mips, they will not have been regenerated and should
@ -500,9 +500,8 @@ DEF_GPUTEST(GrManyDependentsMipMappedTest, reporter, /* options */) {
mipmapRTCTask.get() == drawingManager->getLastRenderTask(mipmapProxy.get()));
// Draw the stil-dirty mipmap texture into a second target with mipmap filtering.
rtc2 = draw_mipmap_into_new_render_target(context.get(), proxyProvider, colorType,
alphaType, std::move(mipmapView),
MipmapMode::kLinear);
rtc2 = draw_mipmap_into_new_render_target(dContext.get(), colorType, alphaType,
std::move(mipmapView), MipmapMode::kLinear);
rtc2Task = sk_ref_sp(rtc2->testingOnly_PeekLastOpsTask());
// Make sure the mipmap texture now has a new last render task that regenerates the mips,
@ -513,7 +512,7 @@ DEF_GPUTEST(GrManyDependentsMipMappedTest, reporter, /* options */) {
SkASSERT(!mipmapProxy->mipmapsAreDirty());
// Mip regen tasks don't get added as dependencies until makeClosed().
context->flushAndSubmit();
dContext->flushAndSubmit();
REPORTER_ASSERT(reporter, rtc2Task->dependsOn(mipRegenTask2));
}
}

View File

@ -65,13 +65,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrTextureMipMapInvalidationTest, reporter, ct
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReimportImageTextureWithMipLevels, reporter, ctxInfo) {
auto ctx = ctxInfo.directContext();
if (!ctx->priv().caps()->mipmapSupport()) {
auto dContext = ctxInfo.directContext();
if (!dContext->priv().caps()->mipmapSupport()) {
return;
}
static constexpr auto kCreateWithMipMaps = true;
auto surf = SkSurface::MakeRenderTarget(
ctx, SkBudgeted::kYes,
dContext, SkBudgeted::kYes,
SkImageInfo::Make(100, 100, kRGBA_8888_SkColorType, kPremul_SkAlphaType), 1,
kTopLeft_GrSurfaceOrigin, nullptr, kCreateWithMipMaps);
if (!surf) {
@ -85,7 +85,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReimportImageTextureWithMipLevels, reporter,
surf.reset();
GrBackendTexture btex;
SkImage::BackendTextureReleaseProc texRelease;
if (!SkImage::MakeBackendTextureFromSkImage(ctx, std::move(img), &btex, &texRelease)) {
if (!SkImage::MakeBackendTextureFromSkImage(dContext, std::move(img), &btex, &texRelease)) {
// Not all backends support stealing textures yet.
// ERRORF(reporter, "Could not turn image into texture");
return;
@ -93,11 +93,11 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReimportImageTextureWithMipLevels, reporter,
REPORTER_ASSERT(reporter, btex.hasMipmaps());
// Reimport the texture as an image and perform a downsampling draw with medium quality which
// should use the upper MIP levels.
img = SkImage::MakeFromTexture(ctx, btex, kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType,
img = SkImage::MakeFromTexture(dContext, btex, kTopLeft_GrSurfaceOrigin, kRGBA_8888_SkColorType,
kPremul_SkAlphaType, nullptr);
const auto singlePixelInfo =
SkImageInfo::Make(1, 1, kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);
surf = SkSurface::MakeRenderTarget(ctx, SkBudgeted::kYes, singlePixelInfo, 1,
surf = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kYes, singlePixelInfo, 1,
kTopLeft_GrSurfaceOrigin, nullptr);
SkPaint paint;
paint.setFilterQuality(kMedium_SkFilterQuality);

View File

@ -207,9 +207,9 @@ DEF_TEST(ImageFilterCache_ImageBackedRaster, reporter) {
#include "src/gpu/GrTexture.h"
#include "src/gpu/GrTextureProxy.h"
static GrSurfaceProxyView create_proxy_view(GrRecordingContext* context) {
static GrSurfaceProxyView create_proxy_view(GrRecordingContext* rContext) {
SkBitmap srcBM = create_bm();
GrBitmapTextureMaker maker(context, srcBM, GrImageTexGenPolicy::kNew_Uncached_Budgeted);
GrBitmapTextureMaker maker(rContext, srcBM, GrImageTexGenPolicy::kNew_Uncached_Budgeted);
return maker.view(GrMipmapped::kNo);
}
@ -255,9 +255,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_ImageBackedGPU, reporter, ct
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_GPUBacked, reporter, ctxInfo) {
auto context = ctxInfo.directContext();
auto dContext = ctxInfo.directContext();
GrSurfaceProxyView srcView = create_proxy_view(context);
GrSurfaceProxyView srcView = create_proxy_view(dContext);
if (!srcView.proxy()) {
return;
}
@ -265,7 +265,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_GPUBacked, reporter, ctxInfo
const SkIRect& full = SkIRect::MakeWH(kFullSize, kFullSize);
sk_sp<SkSpecialImage> fullImg(SkSpecialImage::MakeDeferredFromGpu(
context, full,
dContext, full,
kNeedNewImageUniqueID_SpecialImage,
srcView,
GrColorType::kRGBA_8888, nullptr));
@ -273,7 +273,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageFilterCache_GPUBacked, reporter, ctxInfo
const SkIRect& subset = SkIRect::MakeXYWH(kPad, kPad, kSmallerSize, kSmallerSize);
sk_sp<SkSpecialImage> subsetImg(SkSpecialImage::MakeDeferredFromGpu(
context, subset,
dContext, subset,
kNeedNewImageUniqueID_SpecialImage,
std::move(srcView),
GrColorType::kRGBA_8888, nullptr));

View File

@ -476,27 +476,27 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeNonTextureImage, reporter, contex
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrContext_colorTypeSupportedAsImage, reporter, ctxInfo) {
auto context = ctxInfo.directContext();
auto dContext = ctxInfo.directContext();
static constexpr int kSize = 10;
for (int ct = 0; ct < kLastEnum_SkColorType; ++ct) {
SkColorType colorType = static_cast<SkColorType>(ct);
bool can = context->colorTypeSupportedAsImage(colorType);
bool can = dContext->colorTypeSupportedAsImage(colorType);
GrBackendTexture backendTex;
CreateBackendTexture(context, &backendTex, kSize, kSize, colorType, SkColors::kTransparent,
CreateBackendTexture(dContext, &backendTex, kSize, kSize, colorType, SkColors::kTransparent,
GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo);
auto img = SkImage::MakeFromTexture(context, backendTex, kTopLeft_GrSurfaceOrigin,
auto img = SkImage::MakeFromTexture(dContext, backendTex, kTopLeft_GrSurfaceOrigin,
colorType, kOpaque_SkAlphaType, nullptr);
REPORTER_ASSERT(reporter, can == SkToBool(img),
"colorTypeSupportedAsImage:%d, actual:%d, ct:%d", can, SkToBool(img),
colorType);
img.reset();
context->flushAndSubmit();
context->deleteBackendTexture(backendTex);
dContext->flushAndSubmit();
dContext->deleteBackendTexture(backendTex);
}
}
@ -818,12 +818,12 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c
const int kWidth = 10;
const int kHeight = 10;
auto ctx = ctxInfo.directContext();
auto dContext = ctxInfo.directContext();
SkImageInfo ii = SkImageInfo::Make(kWidth, kHeight, SkColorType::kRGBA_8888_SkColorType,
kPremul_SkAlphaType);
GrBackendTexture backendTex;
if (!CreateBackendTexture(ctx, &backendTex, ii, SkColors::kRed, GrMipmapped::kNo,
if (!CreateBackendTexture(dContext, &backendTex, ii, SkColors::kRed, GrMipmapped::kNo,
GrRenderable::kNo)) {
ERRORF(reporter, "couldn't create backend texture\n");
}
@ -831,7 +831,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c
TextureReleaseChecker releaseChecker;
GrSurfaceOrigin texOrigin = kBottomLeft_GrSurfaceOrigin;
sk_sp<SkImage> refImg(
SkImage::MakeFromTexture(ctx, backendTex, texOrigin, kRGBA_8888_SkColorType,
SkImage::MakeFromTexture(dContext, backendTex, texOrigin, kRGBA_8888_SkColorType,
kPremul_SkAlphaType, nullptr,
TextureReleaseChecker::Release, &releaseChecker));
@ -851,7 +851,7 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(SkImage_NewFromTextureRelease, reporter, c
refImg.reset(nullptr); // force a release of the image
REPORTER_ASSERT(reporter, 1 == releaseChecker.fReleaseCount);
DeleteBackendTexture(ctx, backendTex);
DeleteBackendTexture(dContext, backendTex);
}
static void test_cross_context_image(skiatest::Reporter* reporter, const GrContextOptions& options,

View File

@ -72,12 +72,12 @@ void draw_child(skiatest::Reporter* reporter,
const SkImageInfo childII = SkImageInfo::Make(CHILD_W, CHILD_H, kRGBA_8888_SkColorType,
kPremul_SkAlphaType);
auto childCtx = childInfo.directContext();
sk_sp<SkSurface> childSurface(SkSurface::MakeRenderTarget(childCtx, SkBudgeted::kNo,
auto childDContext = childInfo.directContext();
sk_sp<SkSurface> childSurface(SkSurface::MakeRenderTarget(childDContext, SkBudgeted::kNo,
childII, 0, kTopLeft_GrSurfaceOrigin,
nullptr));
sk_sp<SkImage> childImage = SkImage::MakeFromTexture(childCtx,
sk_sp<SkImage> childImage = SkImage::MakeFromTexture(childDContext,
backendTexture,
kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,

View File

@ -18,9 +18,9 @@
DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(TextureBindingsResetTest, reporter, ctxInfo) {
#define GL(F) GR_GL_CALL(ctxInfo.glContext()->gl(), F)
auto context = ctxInfo.directContext();
GrGpu* gpu = context->priv().getGpu();
GrGLGpu* glGpu = static_cast<GrGLGpu*>(context->priv().getGpu());
auto dContext = ctxInfo.directContext();
GrGpu* gpu = dContext->priv().getGpu();
GrGLGpu* glGpu = static_cast<GrGLGpu*>(dContext->priv().getGpu());
struct Target {
GrGLenum fName;
@ -69,9 +69,9 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(TextureBindingsResetTest, reporter, ctxInf
};
// Initialize texture unit/target combo bindings to 0.
context->flushAndSubmit();
dContext->flushAndSubmit();
resetBindings();
context->resetContext();
dContext->resetContext();
// Test creating a texture and then resetting bindings.
static constexpr SkISize kDims = {10, 10};
@ -79,15 +79,15 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(TextureBindingsResetTest, reporter, ctxInf
auto tex = gpu->createTexture(kDims, format, GrRenderable::kNo, 1, GrMipmapped::kNo,
SkBudgeted::kNo, GrProtected::kNo);
REPORTER_ASSERT(reporter, tex);
context->resetGLTextureBindings();
dContext->resetGLTextureBindings();
checkBindings();
resetBindings();
context->resetContext();
dContext->resetContext();
// Test drawing and then resetting bindings. This should force a MIP regeneration if MIP
// maps are supported as well.
auto info = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
auto surf = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info, 1, nullptr);
auto surf = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kYes, info, 1, nullptr);
surf->getCanvas()->clear(0x80FF0000);
auto img = surf->makeImageSnapshot();
surf->getCanvas()->clear(SK_ColorBLUE);
@ -98,13 +98,13 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(TextureBindingsResetTest, reporter, ctxInf
surf->getCanvas()->drawImage(img, 0, 0, &paint);
surf->getCanvas()->restore();
surf->flushAndSubmit();
context->resetGLTextureBindings();
dContext->resetGLTextureBindings();
checkBindings();
resetBindings();
context->resetContext();
dContext->resetContext();
if (supportExternal) {
GrBackendTexture texture2D = context->createBackendTexture(
GrBackendTexture texture2D = dContext->createBackendTexture(
10, 10, kRGBA_8888_SkColorType,
SkColors::kTransparent, GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo);
GrGLTextureInfo info2D;
@ -119,37 +119,37 @@ DEF_GPUTEST_FOR_GL_RENDERING_CONTEXTS(TextureBindingsResetTest, reporter, ctxInf
GrBackendTexture backendTexture(10, 10, GrMipmapped::kNo, infoExternal);
// Above texture creation will have messed with GL state and bindings.
resetBindings();
context->resetContext();
img = SkImage::MakeFromTexture(context, backendTexture, kTopLeft_GrSurfaceOrigin,
dContext->resetContext();
img = SkImage::MakeFromTexture(dContext, backendTexture, kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);
REPORTER_ASSERT(reporter, img);
surf->getCanvas()->drawImage(img, 0, 0);
img.reset();
surf->flushAndSubmit();
context->resetGLTextureBindings();
dContext->resetGLTextureBindings();
checkBindings();
resetBindings();
GL(DeleteTextures(1, &infoExternal.fID));
ctxInfo.glContext()->destroyEGLImage(eglImage);
context->deleteBackendTexture(texture2D);
context->resetContext();
dContext->deleteBackendTexture(texture2D);
dContext->resetContext();
}
if (supportRectangle) {
auto format = GrBackendFormat::MakeGL(GR_GL_RGBA8, GR_GL_TEXTURE_RECTANGLE);
GrBackendTexture rectangleTexture =
context->createBackendTexture(10, 10, format, GrMipmapped::kNo, GrRenderable::kNo);
dContext->createBackendTexture(10, 10, format, GrMipmapped::kNo, GrRenderable::kNo);
if (rectangleTexture.isValid()) {
img = SkImage::MakeFromTexture(context, rectangleTexture, kTopLeft_GrSurfaceOrigin,
img = SkImage::MakeFromTexture(dContext, rectangleTexture, kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);
REPORTER_ASSERT(reporter, img);
surf->getCanvas()->drawImage(img, 0, 0);
img.reset();
surf->flushAndSubmit();
context->resetGLTextureBindings();
dContext->resetGLTextureBindings();
checkBindings();
resetBindings();
context->deleteBackendTexture(rectangleTexture);
dContext->deleteBackendTexture(rectangleTexture);
}
}

View File

@ -32,11 +32,12 @@
#include "src/image/SkSurface_Gpu.h"
DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) {
auto context = ctxInfo.directContext();
auto dContext = ctxInfo.directContext();
GrBackendTexture backendTex;
CreateBackendTexture(context, &backendTex, 1, 1, kRGBA_8888_SkColorType, SkColors::kTransparent,
GrMipmapped::kNo, GrRenderable::kNo, GrProtected::kNo);
CreateBackendTexture(dContext, &backendTex, 1, 1, kRGBA_8888_SkColorType,
SkColors::kTransparent, GrMipmapped::kNo,
GrRenderable::kNo, GrProtected::kNo);
REPORTER_ASSERT(reporter, backendTex.isValid());
GrVkImageInfo info;
@ -60,13 +61,13 @@ DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) {
// Setting back the layout since we didn't actually change it
backendTex.setVkImageLayout(initLayout);
sk_sp<SkImage> wrappedImage = SkImage::MakeFromTexture(context, backendTex,
sk_sp<SkImage> wrappedImage = SkImage::MakeFromTexture(dContext, backendTex,
kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,
kPremul_SkAlphaType, nullptr);
REPORTER_ASSERT(reporter, wrappedImage.get());
const GrSurfaceProxyView* view = as_IB(wrappedImage)->view(context);
const GrSurfaceProxyView* view = as_IB(wrappedImage)->view(dContext);
REPORTER_ASSERT(reporter, view);
REPORTER_ASSERT(reporter, view->proxy()->isInstantiated());
GrTexture* texture = view->proxy()->peekTexture();
@ -120,7 +121,7 @@ DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkImageLayoutTest, reporter, ctxInfo) {
REPORTER_ASSERT(reporter, invalidTexture.isValid());
REPORTER_ASSERT(reporter, GrBackendTexture::TestingOnly_Equals(invalidTexture, invalidTexture));
context->deleteBackendTexture(backendTex);
dContext->deleteBackendTexture(backendTex);
}
// This test is disabled because it executes illegal vulkan calls which cause the validations layers

View File

@ -26,9 +26,8 @@ void draw(SkCanvas* canvas) {
canvas->drawPaint(paint);
SkDebugf("This is text output: %d", 2);
GrContext* context = canvas->getGrContext();
if (context) {
sk_sp<SkImage> tmp = SkImage::MakeFromTexture(context,
if (auto dContext = GrAsDirectContext(canvas->recordingContext())) {
sk_sp<SkImage> tmp = SkImage::MakeFromTexture(dContext,
backEndTexture,
kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,
@ -36,14 +35,14 @@ void draw(SkCanvas* canvas) {
nullptr);
// TODO: this sampleCnt parameter here should match that set in the options!
sk_sp<SkSurface> tmp2 = SkSurface::MakeFromBackendTexture(context,
sk_sp<SkSurface> tmp2 = SkSurface::MakeFromBackendTexture(dContext,
backEndTextureRenderTarget,
kTopLeft_GrSurfaceOrigin,
0, kRGBA_8888_SkColorType,
nullptr, nullptr);
// Note: this surface should only be renderable (i.e., not textureable)
sk_sp<SkSurface> tmp3 = SkSurface::MakeFromBackendRenderTarget(context,
sk_sp<SkSurface> tmp3 = SkSurface::MakeFromBackendRenderTarget(dContext,
backEndRenderTarget,
kTopLeft_GrSurfaceOrigin,
kRGBA_8888_SkColorType,