Clean up some uses of GrContext in tests
Change-Id: Ic1f2f4edb8bfa27fa28f5da22575e1280a51d37b Reviewed-on: https://skia-review.googlesource.com/c/skia/+/303641 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Adlai Holler <adlai@google.com>
This commit is contained in:
parent
2a138b9a99
commit
fe4b481324
@ -28,10 +28,10 @@
|
||||
#include "src/gpu/mtl/GrMtlCppUtil.h"
|
||||
#endif
|
||||
|
||||
static void wait_on_backend_work_to_finish(GrContext* context, bool* finishedCreate) {
|
||||
context->submit();
|
||||
static void wait_on_backend_work_to_finish(GrDirectContext* dContext, bool* finishedCreate) {
|
||||
dContext->submit();
|
||||
while (finishedCreate && !(*finishedCreate)) {
|
||||
context->checkAsyncWorkCompletion();
|
||||
dContext->checkAsyncWorkCompletion();
|
||||
}
|
||||
if (finishedCreate) {
|
||||
// The same boolean (pointed to by finishedCreate) is often used multiply and sequentially
|
||||
@ -41,10 +41,11 @@ static void wait_on_backend_work_to_finish(GrContext* context, bool* finishedCre
|
||||
}
|
||||
}
|
||||
|
||||
static void delete_backend_texture(GrContext* context, const GrBackendTexture& backendTexture,
|
||||
static void delete_backend_texture(GrDirectContext* dContext,
|
||||
const GrBackendTexture& backendTexture,
|
||||
bool* finishedCreate) {
|
||||
wait_on_backend_work_to_finish(context, finishedCreate);
|
||||
context->deleteBackendTexture(backendTexture);
|
||||
wait_on_backend_work_to_finish(dContext, finishedCreate);
|
||||
dContext->deleteBackendTexture(backendTexture);
|
||||
}
|
||||
|
||||
static void mark_signaled(void* context) {
|
||||
@ -52,17 +53,20 @@ static void mark_signaled(void* context) {
|
||||
}
|
||||
|
||||
// Test wrapping of GrBackendObjects in SkSurfaces and SkImages (non-static since used in Mtl test)
|
||||
void test_wrapping(GrContext* context, skiatest::Reporter* reporter,
|
||||
std::function<GrBackendTexture (GrContext*,
|
||||
void test_wrapping(GrDirectContext* dContext,
|
||||
skiatest::Reporter* reporter,
|
||||
std::function<GrBackendTexture (GrDirectContext*,
|
||||
GrMipMapped,
|
||||
GrRenderable)> create,
|
||||
GrColorType grColorType, GrMipMapped mipMapped, GrRenderable renderable,
|
||||
GrColorType grColorType,
|
||||
GrMipMapped mipMapped,
|
||||
GrRenderable renderable,
|
||||
bool* finishedBECreate) {
|
||||
GrResourceCache* cache = context->priv().getResourceCache();
|
||||
GrResourceCache* cache = dContext->priv().getResourceCache();
|
||||
|
||||
const int initialCount = cache->getResourceCount();
|
||||
|
||||
GrBackendTexture backendTex = create(context, mipMapped, renderable);
|
||||
GrBackendTexture backendTex = create(dContext, mipMapped, renderable);
|
||||
if (!backendTex.isValid()) {
|
||||
ERRORF(reporter, "Couldn't create backendTexture for grColorType %d renderable %s\n",
|
||||
grColorType,
|
||||
@ -77,12 +81,12 @@ void test_wrapping(GrContext* context, skiatest::Reporter* reporter,
|
||||
|
||||
// Wrapping a backendTexture in an image requires an SkColorType
|
||||
if (kUnknown_SkColorType == skColorType) {
|
||||
delete_backend_texture(context, backendTex, finishedBECreate);
|
||||
delete_backend_texture(dContext, backendTex, finishedBECreate);
|
||||
return;
|
||||
}
|
||||
|
||||
if (GrRenderable::kYes == renderable && context->colorTypeSupportedAsSurface(skColorType)) {
|
||||
sk_sp<SkSurface> surf = SkSurface::MakeFromBackendTexture(context,
|
||||
if (GrRenderable::kYes == renderable && dContext->colorTypeSupportedAsSurface(skColorType)) {
|
||||
sk_sp<SkSurface> surf = SkSurface::MakeFromBackendTexture(dContext,
|
||||
backendTex,
|
||||
kTopLeft_GrSurfaceOrigin,
|
||||
0,
|
||||
@ -97,7 +101,7 @@ void test_wrapping(GrContext* context, skiatest::Reporter* reporter,
|
||||
}
|
||||
|
||||
{
|
||||
sk_sp<SkImage> img = SkImage::MakeFromTexture(context,
|
||||
sk_sp<SkImage> img = SkImage::MakeFromTexture(dContext,
|
||||
backendTex,
|
||||
kTopLeft_GrSurfaceOrigin,
|
||||
skColorType,
|
||||
@ -122,7 +126,7 @@ void test_wrapping(GrContext* context, skiatest::Reporter* reporter,
|
||||
|
||||
REPORTER_ASSERT(reporter, initialCount == cache->getResourceCount());
|
||||
|
||||
delete_backend_texture(context, backendTex, finishedBECreate);
|
||||
delete_backend_texture(dContext, backendTex, finishedBECreate);
|
||||
}
|
||||
|
||||
static bool isBGRA8(const GrBackendFormat& format) {
|
||||
@ -234,11 +238,11 @@ static SkColor4f get_expected_color(SkColor4f orig, SkColorType ct) {
|
||||
return SkColor4f::FromColor(tmp);
|
||||
}
|
||||
|
||||
static void check_mipmaps(GrContext* context, const GrBackendTexture& backendTex,
|
||||
SkColorType skColorType, const SkColor4f expectedColors[6],
|
||||
skiatest::Reporter* reporter, const char* label);
|
||||
static void check_mipmaps(GrDirectContext*, const GrBackendTexture&,
|
||||
SkColorType, const SkColor4f expectedColors[6],
|
||||
skiatest::Reporter*, const char* label);
|
||||
|
||||
static void check_base_readbacks(GrContext* context, const GrBackendTexture& backendTex,
|
||||
static void check_base_readbacks(GrDirectContext* dContext, const GrBackendTexture& backendTex,
|
||||
SkColorType skColorType, GrRenderable renderable,
|
||||
const SkColor4f& color, skiatest::Reporter* reporter,
|
||||
const char* label) {
|
||||
@ -263,7 +267,7 @@ static void check_base_readbacks(GrContext* context, const GrBackendTexture& bac
|
||||
}
|
||||
|
||||
{
|
||||
sk_sp<SkImage> img = SkImage::MakeFromTexture(context,
|
||||
sk_sp<SkImage> img = SkImage::MakeFromTexture(dContext,
|
||||
backendTex,
|
||||
kTopLeft_GrSurfaceOrigin,
|
||||
skColorType,
|
||||
@ -287,8 +291,8 @@ static void check_base_readbacks(GrContext* context, const GrBackendTexture& bac
|
||||
|
||||
// This will mark any mipmaps as dirty (bc that is what we do when we wrap a renderable
|
||||
// backend texture) so it must be done last!
|
||||
if (GrRenderable::kYes == renderable && context->colorTypeSupportedAsSurface(skColorType)) {
|
||||
sk_sp<SkSurface> surf = SkSurface::MakeFromBackendTexture(context,
|
||||
if (GrRenderable::kYes == renderable && dContext->colorTypeSupportedAsSurface(skColorType)) {
|
||||
sk_sp<SkSurface> surf = SkSurface::MakeFromBackendTexture(dContext,
|
||||
backendTex,
|
||||
kTopLeft_GrSurfaceOrigin,
|
||||
0,
|
||||
@ -306,14 +310,18 @@ static void check_base_readbacks(GrContext* context, const GrBackendTexture& bac
|
||||
}
|
||||
|
||||
// Test initialization of GrBackendObjects to a specific color (non-static since used in Mtl test)
|
||||
void test_color_init(GrContext* context, skiatest::Reporter* reporter,
|
||||
std::function<GrBackendTexture (GrContext*,
|
||||
void test_color_init(GrDirectContext* dContext,
|
||||
skiatest::Reporter* reporter,
|
||||
std::function<GrBackendTexture (GrDirectContext*,
|
||||
const SkColor4f&,
|
||||
GrMipMapped,
|
||||
GrRenderable)> create,
|
||||
GrColorType grColorType, const SkColor4f& color,
|
||||
GrMipMapped mipMapped, GrRenderable renderable, bool* finishedBECreate) {
|
||||
GrBackendTexture backendTex = create(context, color, mipMapped, renderable);
|
||||
GrColorType grColorType,
|
||||
const SkColor4f& color,
|
||||
GrMipMapped mipMapped,
|
||||
GrRenderable renderable,
|
||||
bool* finishedBECreate) {
|
||||
GrBackendTexture backendTex = create(dContext, color, mipMapped, renderable);
|
||||
if (!backendTex.isValid()) {
|
||||
// errors here should be reported by the test_wrapping test
|
||||
return;
|
||||
@ -324,7 +332,7 @@ void test_color_init(GrContext* context, skiatest::Reporter* reporter,
|
||||
// Can't wrap backend textures in images and surfaces w/o an SkColorType
|
||||
if (kUnknown_SkColorType == skColorType) {
|
||||
// TODO: burrow in and scrappily check that data was uploaded!
|
||||
delete_backend_texture(context, backendTex, finishedBECreate);
|
||||
delete_backend_texture(dContext, backendTex, finishedBECreate);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -333,43 +341,44 @@ void test_color_init(GrContext* context, skiatest::Reporter* reporter,
|
||||
SkColor4f expectedColor = get_expected_color(testColor, skColorType);
|
||||
SkColor4f expectedColors[6] = {expectedColor, expectedColor, expectedColor,
|
||||
expectedColor, expectedColor, expectedColor};
|
||||
check_mipmaps(context, backendTex, skColorType, expectedColors, reporter, "colorinit");
|
||||
check_mipmaps(dContext, backendTex, skColorType, expectedColors,
|
||||
reporter, "colorinit");
|
||||
}
|
||||
|
||||
// The last step in this test will dirty the mipmaps so do it last
|
||||
check_base_readbacks(context, backendTex, skColorType, renderable, testColor, reporter,
|
||||
"colorinit");
|
||||
check_base_readbacks(dContext, backendTex, skColorType, renderable, testColor,
|
||||
reporter, "colorinit");
|
||||
};
|
||||
|
||||
checkBackendTexture(color);
|
||||
|
||||
// Make sure the initial create work has finished so we can test the update independently.
|
||||
wait_on_backend_work_to_finish(context, finishedBECreate);
|
||||
wait_on_backend_work_to_finish(dContext, finishedBECreate);
|
||||
|
||||
SkColor4f newColor = {color.fB , color.fR, color.fG, color.fA };
|
||||
|
||||
// Reupload the new data and make sure everything still works. We test with an SkColorType so
|
||||
// we may actually swizzle the input during the create path. The update does not do any swizzle
|
||||
// of the passed in color. So we manually do it here so we get the same expected results.
|
||||
SkColor4f swizzledColor = context->priv().caps()->getWriteSwizzle(
|
||||
SkColor4f swizzledColor = dContext->priv().caps()->getWriteSwizzle(
|
||||
backendTex.getBackendFormat(), grColorType).applyTo(newColor);
|
||||
context->updateBackendTexture(backendTex, swizzledColor, mark_signaled, finishedBECreate);
|
||||
dContext->updateBackendTexture(backendTex, swizzledColor, mark_signaled, finishedBECreate);
|
||||
|
||||
checkBackendTexture(newColor);
|
||||
|
||||
delete_backend_texture(context, backendTex, finishedBECreate);
|
||||
delete_backend_texture(dContext, backendTex, finishedBECreate);
|
||||
}
|
||||
|
||||
// Draw the backend texture (wrapped in an SkImage) into an RGBA surface, attempting to access
|
||||
// all the mipMap levels.
|
||||
static void check_mipmaps(GrContext* context, const GrBackendTexture& backendTex,
|
||||
static void check_mipmaps(GrDirectContext* dContext, const GrBackendTexture& backendTex,
|
||||
SkColorType skColorType, const SkColor4f expectedColors[6],
|
||||
skiatest::Reporter* reporter, const char* label) {
|
||||
|
||||
#ifdef SK_GL
|
||||
// skbug.com/9141 (RGBA_F32 mipmaps appear to be broken on some Mali devices)
|
||||
if (GrBackendApi::kOpenGL == context->backend()) {
|
||||
GrGLGpu* glGPU = static_cast<GrGLGpu*>(context->priv().getGpu());
|
||||
if (GrBackendApi::kOpenGL == dContext->backend()) {
|
||||
GrGLGpu* glGPU = static_cast<GrGLGpu*>(dContext->priv().getGpu());
|
||||
|
||||
if (kRGBA_F32_SkColorType == skColorType &&
|
||||
kGLES_GrGLStandard == glGPU->ctxInfo().standard()) {
|
||||
@ -387,7 +396,7 @@ static void check_mipmaps(GrContext* context, const GrBackendTexture& backendTex
|
||||
SkAlphaType at = SkColorTypeIsAlwaysOpaque(skColorType) ? kOpaque_SkAlphaType
|
||||
: kPremul_SkAlphaType;
|
||||
|
||||
sk_sp<SkImage> img = SkImage::MakeFromTexture(context,
|
||||
sk_sp<SkImage> img = SkImage::MakeFromTexture(dContext,
|
||||
backendTex,
|
||||
kTopLeft_GrSurfaceOrigin,
|
||||
skColorType,
|
||||
@ -400,7 +409,7 @@ static void check_mipmaps(GrContext* context, const GrBackendTexture& backendTex
|
||||
SkImageInfo readbackSurfaceII = SkImageInfo::Make(32, 32, kRGBA_8888_SkColorType,
|
||||
kPremul_SkAlphaType);
|
||||
|
||||
sk_sp<SkSurface> surf = SkSurface::MakeRenderTarget(context,
|
||||
sk_sp<SkSurface> surf = SkSurface::MakeRenderTarget(dContext,
|
||||
SkBudgeted::kNo,
|
||||
readbackSurfaceII, 1,
|
||||
kTopLeft_GrSurfaceOrigin,
|
||||
@ -457,13 +466,16 @@ static int make_pixmaps(SkColorType skColorType, GrMipMapped mipMapped,
|
||||
}
|
||||
|
||||
// Test initialization of GrBackendObjects using SkPixmaps
|
||||
static void test_pixmap_init(GrContext* context, skiatest::Reporter* reporter,
|
||||
std::function<GrBackendTexture (GrContext*,
|
||||
static void test_pixmap_init(GrDirectContext* dContext,
|
||||
skiatest::Reporter* reporter,
|
||||
std::function<GrBackendTexture (GrDirectContext*,
|
||||
const SkPixmap srcData[],
|
||||
int numLevels,
|
||||
GrRenderable)> create,
|
||||
SkColorType skColorType, GrMipMapped mipMapped,
|
||||
GrRenderable renderable, bool* finishedBECreate) {
|
||||
SkColorType skColorType,
|
||||
GrMipMapped mipMapped,
|
||||
GrRenderable renderable,
|
||||
bool* finishedBECreate) {
|
||||
SkAutoPixmapStorage pixmapMem[6];
|
||||
SkColor4f colors[6] = {
|
||||
{ 1.0f, 0.0f, 0.0f, 1.0f }, // R
|
||||
@ -483,7 +495,7 @@ static void test_pixmap_init(GrContext* context, skiatest::Reporter* reporter,
|
||||
pixmaps[i].reset(pixmapMem[i].info(), pixmapMem[i].addr(), pixmapMem[i].rowBytes());
|
||||
}
|
||||
|
||||
GrBackendTexture backendTex = create(context, pixmaps, numMipLevels, renderable);
|
||||
GrBackendTexture backendTex = create(dContext, pixmaps, numMipLevels, renderable);
|
||||
if (!backendTex.isValid()) {
|
||||
// errors here should be reported by the test_wrapping test
|
||||
return;
|
||||
@ -491,7 +503,7 @@ static void test_pixmap_init(GrContext* context, skiatest::Reporter* reporter,
|
||||
|
||||
if (skColorType == kBGRA_8888_SkColorType && !isBGRA8(backendTex.getBackendFormat())) {
|
||||
// When kBGRA is backed by an RGBA something goes wrong in the swizzling
|
||||
delete_backend_texture(context, backendTex, finishedBECreate);
|
||||
delete_backend_texture(dContext, backendTex, finishedBECreate);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -506,18 +518,18 @@ static void test_pixmap_init(GrContext* context, skiatest::Reporter* reporter,
|
||||
get_expected_color(colors[5], skColorType),
|
||||
};
|
||||
|
||||
check_mipmaps(context, backendTex, skColorType, expectedColors, reporter, "pixmap");
|
||||
check_mipmaps(dContext, backendTex, skColorType, expectedColors, reporter, "pixmap");
|
||||
}
|
||||
|
||||
// The last step in this test will dirty the mipmaps so do it last
|
||||
check_base_readbacks(context, backendTex, skColorType, renderable, colors[0], reporter,
|
||||
check_base_readbacks(dContext, backendTex, skColorType, renderable, colors[0], reporter,
|
||||
"pixmap");
|
||||
};
|
||||
|
||||
checkBackendTexture(colors);
|
||||
|
||||
// Make sure the initial create work has finished so we can test the update independently.
|
||||
wait_on_backend_work_to_finish(context, finishedBECreate);
|
||||
wait_on_backend_work_to_finish(dContext, finishedBECreate);
|
||||
|
||||
SkColor4f colorsNew[6] = {
|
||||
{1.0f, 1.0f, 0.0f, 0.2f}, // Y
|
||||
@ -533,12 +545,12 @@ static void test_pixmap_init(GrContext* context, skiatest::Reporter* reporter,
|
||||
}
|
||||
|
||||
// Upload new data and make sure everything still works
|
||||
context->updateBackendTexture(backendTex, pixmaps, numMipLevels, mark_signaled,
|
||||
finishedBECreate);
|
||||
dContext->updateBackendTexture(backendTex, pixmaps, numMipLevels, mark_signaled,
|
||||
finishedBECreate);
|
||||
|
||||
checkBackendTexture(colorsNew);
|
||||
|
||||
delete_backend_texture(context, backendTex, finishedBECreate);
|
||||
delete_backend_texture(dContext, backendTex, finishedBECreate);
|
||||
}
|
||||
|
||||
enum class VkLayout {
|
||||
@ -728,17 +740,18 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ColorTypeBackendAllocationTest, reporter, ctx
|
||||
}
|
||||
|
||||
{
|
||||
auto uninitCreateMtd = [colorType](GrContext* context, GrMipMapped mipMapped,
|
||||
auto uninitCreateMtd = [colorType](GrDirectContext* dContext,
|
||||
GrMipMapped mipMapped,
|
||||
GrRenderable renderable) {
|
||||
auto result = context->createBackendTexture(32, 32, colorType,
|
||||
mipMapped, renderable,
|
||||
GrProtected::kNo);
|
||||
auto result = dContext->createBackendTexture(32, 32, colorType,
|
||||
mipMapped, renderable,
|
||||
GrProtected::kNo);
|
||||
check_vk_layout(result, VkLayout::kUndefined);
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
{
|
||||
GrBackendFormat format = context->defaultBackendFormat(colorType,
|
||||
renderable);
|
||||
GrBackendFormat format = dContext->defaultBackendFormat(colorType,
|
||||
renderable);
|
||||
SkASSERT(format == result.getBackendFormat());
|
||||
}
|
||||
#endif
|
||||
@ -756,20 +769,19 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ColorTypeBackendAllocationTest, reporter, ctx
|
||||
|
||||
{
|
||||
|
||||
auto createWithColorMtd = [colorType, finishedPtr](GrContext* context,
|
||||
auto createWithColorMtd = [colorType, finishedPtr](GrDirectContext* dContext,
|
||||
const SkColor4f& color,
|
||||
GrMipMapped mipMapped,
|
||||
GrRenderable renderable) {
|
||||
auto result = context->createBackendTexture(32, 32, colorType, color,
|
||||
mipMapped, renderable,
|
||||
GrProtected::kNo,
|
||||
mark_signaled,
|
||||
finishedPtr);
|
||||
auto result = dContext->createBackendTexture(32, 32, colorType, color,
|
||||
mipMapped, renderable,
|
||||
GrProtected::kNo,
|
||||
mark_signaled, finishedPtr);
|
||||
check_vk_layout(result, VkLayout::kReadOnlyOptimal);
|
||||
|
||||
#ifdef SK_DEBUG
|
||||
{
|
||||
GrBackendFormat format = context->defaultBackendFormat(colorType,
|
||||
GrBackendFormat format = dContext->defaultBackendFormat(colorType,
|
||||
renderable);
|
||||
SkASSERT(format == result.getBackendFormat());
|
||||
}
|
||||
@ -795,19 +807,19 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ColorTypeBackendAllocationTest, reporter, ctx
|
||||
}
|
||||
|
||||
{
|
||||
auto createWithSrcDataMtd = [finishedPtr](GrContext* context,
|
||||
auto createWithSrcDataMtd = [finishedPtr](GrDirectContext* dContext,
|
||||
const SkPixmap srcData[],
|
||||
int numLevels,
|
||||
GrRenderable renderable) {
|
||||
SkASSERT(srcData && numLevels);
|
||||
auto result = context->createBackendTexture(srcData, numLevels, renderable,
|
||||
GrProtected::kNo, mark_signaled,
|
||||
finishedPtr);
|
||||
auto result = dContext->createBackendTexture(srcData, numLevels, renderable,
|
||||
GrProtected::kNo, mark_signaled,
|
||||
finishedPtr);
|
||||
check_vk_layout(result, VkLayout::kReadOnlyOptimal);
|
||||
#ifdef SK_DEBUG
|
||||
{
|
||||
auto format = context->defaultBackendFormat(srcData[0].colorType(),
|
||||
renderable);
|
||||
auto format = dContext->defaultBackendFormat(srcData[0].colorType(),
|
||||
renderable);
|
||||
SkASSERT(format == result.getBackendFormat());
|
||||
}
|
||||
#endif
|
||||
@ -907,10 +919,11 @@ DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(GLBackendAllocationTest, reporter, ctxInfo) {
|
||||
}
|
||||
|
||||
{
|
||||
auto uninitCreateMtd = [format](GrContext* context, GrMipMapped mipMapped,
|
||||
auto uninitCreateMtd = [format](GrDirectContext* dContext,
|
||||
GrMipMapped mipMapped,
|
||||
GrRenderable renderable) {
|
||||
return context->createBackendTexture(32, 32, format, mipMapped,
|
||||
renderable, GrProtected::kNo);
|
||||
return dContext->createBackendTexture(32, 32, format, mipMapped,
|
||||
renderable, GrProtected::kNo);
|
||||
};
|
||||
|
||||
test_wrapping(context, reporter, uninitCreateMtd, combo.fColorType,
|
||||
@ -945,12 +958,12 @@ DEF_GPUTEST_FOR_ALL_GL_CONTEXTS(GLBackendAllocationTest, reporter, ctxInfo) {
|
||||
bool* finishedPtr = &finishedBackendCreation;
|
||||
|
||||
auto createWithColorMtd = [format, swizzle, finishedPtr](
|
||||
GrContext* context,
|
||||
GrDirectContext* dContext,
|
||||
const SkColor4f& color,
|
||||
GrMipMapped mipMapped,
|
||||
GrRenderable renderable) {
|
||||
auto swizzledColor = swizzle.applyTo(color);
|
||||
return context->createBackendTexture(
|
||||
return dContext->createBackendTexture(
|
||||
32, 32, format, swizzledColor, mipMapped, renderable,
|
||||
GrProtected::kNo, mark_signaled, finishedPtr);
|
||||
};
|
||||
@ -1059,12 +1072,13 @@ DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkBackendAllocationTest, reporter, ctxInfo) {
|
||||
}
|
||||
|
||||
{
|
||||
auto uninitCreateMtd = [format](GrContext* context, GrMipMapped mipMapped,
|
||||
auto uninitCreateMtd = [format](GrDirectContext* dContext,
|
||||
GrMipMapped mipMapped,
|
||||
GrRenderable renderable) {
|
||||
GrBackendTexture beTex = context->createBackendTexture(32, 32, format,
|
||||
mipMapped,
|
||||
renderable,
|
||||
GrProtected::kNo);
|
||||
GrBackendTexture beTex = dContext->createBackendTexture(32, 32, format,
|
||||
mipMapped,
|
||||
renderable,
|
||||
GrProtected::kNo);
|
||||
check_vk_layout(beTex, VkLayout::kUndefined);
|
||||
return beTex;
|
||||
};
|
||||
@ -1110,16 +1124,18 @@ DEF_GPUTEST_FOR_VULKAN_CONTEXT(VkBackendAllocationTest, reporter, ctxInfo) {
|
||||
bool* finishedPtr = &finishedBackendCreation;
|
||||
|
||||
auto createWithColorMtd = [format, swizzle, finishedPtr](
|
||||
GrContext* context, const SkColor4f& color, GrMipMapped mipMapped,
|
||||
GrDirectContext* dContext,
|
||||
const SkColor4f& color,
|
||||
GrMipMapped mipMapped,
|
||||
GrRenderable renderable) {
|
||||
auto swizzledColor = swizzle.applyTo(color);
|
||||
GrBackendTexture beTex = context->createBackendTexture(32, 32, format,
|
||||
swizzledColor,
|
||||
mipMapped,
|
||||
renderable,
|
||||
GrProtected::kNo,
|
||||
mark_signaled,
|
||||
finishedPtr);
|
||||
GrBackendTexture beTex = dContext->createBackendTexture(32, 32, format,
|
||||
swizzledColor,
|
||||
mipMapped,
|
||||
renderable,
|
||||
GrProtected::kNo,
|
||||
mark_signaled,
|
||||
finishedPtr);
|
||||
check_vk_layout(beTex, VkLayout::kReadOnlyOptimal);
|
||||
return beTex;
|
||||
};
|
||||
|
@ -14,35 +14,39 @@
|
||||
#include "src/gpu/ops/GrTextureOp.h"
|
||||
#include "tests/Test.h"
|
||||
|
||||
static std::unique_ptr<GrRenderTargetContext> new_RTC(GrContext* context) {
|
||||
static std::unique_ptr<GrRenderTargetContext> new_RTC(GrRecordingContext* rContext) {
|
||||
return GrRenderTargetContext::Make(
|
||||
context, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, {128, 128});
|
||||
rContext, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, {128, 128});
|
||||
}
|
||||
|
||||
sk_sp<GrSurfaceProxy> create_proxy(GrContext* context) {
|
||||
sk_sp<GrSurfaceProxy> create_proxy(GrRecordingContext* rContext) {
|
||||
static constexpr SkISize kDimensions = {128, 128};
|
||||
|
||||
const GrBackendFormat format = context->priv().caps()->getDefaultBackendFormat(
|
||||
const GrBackendFormat format = rContext->priv().caps()->getDefaultBackendFormat(
|
||||
GrColorType::kRGBA_8888,
|
||||
GrRenderable::kYes);
|
||||
return context->priv().proxyProvider()->createProxy(
|
||||
return rContext->priv().proxyProvider()->createProxy(
|
||||
format, kDimensions, GrRenderable::kYes, 1, GrMipMapped::kNo, SkBackingFit::kExact,
|
||||
SkBudgeted::kNo, GrProtected::kNo, GrInternalSurfaceFlags::kNone);
|
||||
}
|
||||
|
||||
typedef GrQuadAAFlags (*PerQuadAAFunc)(int i);
|
||||
|
||||
typedef void (*BulkRectTest)(skiatest::Reporter* reporter, GrContext* context,
|
||||
PerQuadAAFunc perQuadAA, GrAAType overallAA, SkBlendMode blendMode,
|
||||
int requestedTotNumQuads, int expectedNumOps);
|
||||
typedef void (*BulkRectTest)(skiatest::Reporter*,
|
||||
GrDirectContext*,
|
||||
PerQuadAAFunc perQuadAA,
|
||||
GrAAType overallAA,
|
||||
SkBlendMode,
|
||||
int requestedTotNumQuads,
|
||||
int expectedNumOps);
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
static void bulk_fill_rect_create_test(skiatest::Reporter* reporter, GrContext* context,
|
||||
static void bulk_fill_rect_create_test(skiatest::Reporter* reporter, GrDirectContext* dContext,
|
||||
PerQuadAAFunc perQuadAA, GrAAType overallAA,
|
||||
SkBlendMode blendMode,
|
||||
int requestedTotNumQuads, int expectedNumOps) {
|
||||
|
||||
std::unique_ptr<GrRenderTargetContext> rtc = new_RTC(context);
|
||||
std::unique_ptr<GrRenderTargetContext> rtc = new_RTC(dContext);
|
||||
|
||||
auto quads = new GrRenderTargetContext::QuadSetEntry[requestedTotNumQuads];
|
||||
|
||||
@ -55,7 +59,7 @@ static void bulk_fill_rect_create_test(skiatest::Reporter* reporter, GrContext*
|
||||
|
||||
GrPaint paint;
|
||||
paint.setXPFactory(SkBlendMode_AsXPFactory(blendMode));
|
||||
GrFillRectOp::AddFillRectOps(rtc.get(), nullptr, context, std::move(paint), overallAA,
|
||||
GrFillRectOp::AddFillRectOps(rtc.get(), nullptr, dContext, std::move(paint), overallAA,
|
||||
SkMatrix::I(), quads, requestedTotNumQuads);
|
||||
|
||||
GrOpsTask* opsTask = rtc->testingOnly_PeekLastOpsTask();
|
||||
@ -73,21 +77,21 @@ static void bulk_fill_rect_create_test(skiatest::Reporter* reporter, GrContext*
|
||||
REPORTER_ASSERT(reporter, expectedNumOps == actualNumOps);
|
||||
REPORTER_ASSERT(reporter, requestedTotNumQuads == actualTotNumQuads);
|
||||
|
||||
context->flushAndSubmit();
|
||||
dContext->flushAndSubmit();
|
||||
|
||||
delete[] quads;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
static void bulk_texture_rect_create_test(skiatest::Reporter* reporter, GrContext* context,
|
||||
static void bulk_texture_rect_create_test(skiatest::Reporter* reporter, GrDirectContext* dContext,
|
||||
PerQuadAAFunc perQuadAA, GrAAType overallAA,
|
||||
SkBlendMode blendMode,
|
||||
int requestedTotNumQuads, int expectedNumOps) {
|
||||
|
||||
std::unique_ptr<GrRenderTargetContext> rtc = new_RTC(context);
|
||||
std::unique_ptr<GrRenderTargetContext> rtc = new_RTC(dContext);
|
||||
|
||||
sk_sp<GrSurfaceProxy> proxyA = create_proxy(context);
|
||||
sk_sp<GrSurfaceProxy> proxyB = create_proxy(context);
|
||||
sk_sp<GrSurfaceProxy> proxyA = create_proxy(dContext);
|
||||
sk_sp<GrSurfaceProxy> proxyB = create_proxy(dContext);
|
||||
GrSurfaceProxyView proxyViewA(std::move(proxyA), kTopLeft_GrSurfaceOrigin, GrSwizzle::RGBA());
|
||||
GrSurfaceProxyView proxyViewB(std::move(proxyB), kTopLeft_GrSurfaceOrigin, GrSwizzle::RGBA());
|
||||
|
||||
@ -106,7 +110,7 @@ static void bulk_texture_rect_create_test(skiatest::Reporter* reporter, GrContex
|
||||
set[i].fAAFlags = perQuadAA(i);
|
||||
}
|
||||
|
||||
GrTextureOp::AddTextureSetOps(rtc.get(), nullptr, context, set, requestedTotNumQuads,
|
||||
GrTextureOp::AddTextureSetOps(rtc.get(), nullptr, dContext, set, requestedTotNumQuads,
|
||||
requestedTotNumQuads, // We alternate so proxyCnt == cnt
|
||||
GrSamplerState::Filter::kNearest,
|
||||
GrTextureOp::Saturate::kYes,
|
||||
@ -121,7 +125,7 @@ static void bulk_texture_rect_create_test(skiatest::Reporter* reporter, GrContex
|
||||
int actualTotNumQuads = 0;
|
||||
|
||||
if (blendMode != SkBlendMode::kSrcOver ||
|
||||
!context->priv().caps()->dynamicStateArrayGeometryProcessorTextureSupport()) {
|
||||
!dContext->priv().caps()->dynamicStateArrayGeometryProcessorTextureSupport()) {
|
||||
// In either of these two cases, GrTextureOp creates one op per quad instead. Since
|
||||
// each entry alternates proxies but overlaps geometrically, this will prevent the ops
|
||||
// from being merged back into fewer ops.
|
||||
@ -139,13 +143,13 @@ static void bulk_texture_rect_create_test(skiatest::Reporter* reporter, GrContex
|
||||
REPORTER_ASSERT(reporter, expectedNumOps == actualNumOps);
|
||||
REPORTER_ASSERT(reporter, requestedTotNumQuads == actualTotNumQuads);
|
||||
|
||||
context->flushAndSubmit();
|
||||
dContext->flushAndSubmit();
|
||||
|
||||
delete[] set;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
static void run_test(GrContext* context, skiatest::Reporter* reporter, BulkRectTest test) {
|
||||
static void run_test(GrDirectContext* dContext, skiatest::Reporter* reporter, BulkRectTest test) {
|
||||
// This is the simple case where there is no AA at all. We expect 2 non-AA clumps of quads.
|
||||
{
|
||||
auto noAA = [](int i) -> GrQuadAAFlags {
|
||||
@ -154,7 +158,7 @@ static void run_test(GrContext* context, skiatest::Reporter* reporter, BulkRectT
|
||||
|
||||
static const int kNumExpectedOps = 2;
|
||||
|
||||
test(reporter, context, noAA, GrAAType::kNone, SkBlendMode::kSrcOver,
|
||||
test(reporter, dContext, noAA, GrAAType::kNone, SkBlendMode::kSrcOver,
|
||||
2*GrResourceProvider::MaxNumNonAAQuads(), kNumExpectedOps);
|
||||
}
|
||||
|
||||
@ -167,7 +171,7 @@ static void run_test(GrContext* context, skiatest::Reporter* reporter, BulkRectT
|
||||
|
||||
static const int kNumExpectedOps = 2;
|
||||
|
||||
test(reporter, context, noAA, GrAAType::kCoverage, SkBlendMode::kSrcOver,
|
||||
test(reporter, dContext, noAA, GrAAType::kCoverage, SkBlendMode::kSrcOver,
|
||||
2*GrResourceProvider::MaxNumNonAAQuads(), kNumExpectedOps);
|
||||
}
|
||||
|
||||
@ -181,7 +185,7 @@ static void run_test(GrContext* context, skiatest::Reporter* reporter, BulkRectT
|
||||
int numExpectedOps = 2*GrResourceProvider::MaxNumNonAAQuads() /
|
||||
GrResourceProvider::MaxNumAAQuads();
|
||||
|
||||
test(reporter, context, alternateAA, GrAAType::kCoverage, SkBlendMode::kSrcOver,
|
||||
test(reporter, dContext, alternateAA, GrAAType::kCoverage, SkBlendMode::kSrcOver,
|
||||
2*GrResourceProvider::MaxNumNonAAQuads(), numExpectedOps);
|
||||
}
|
||||
|
||||
@ -196,7 +200,7 @@ static void run_test(GrContext* context, skiatest::Reporter* reporter, BulkRectT
|
||||
|
||||
static const int kNumExpectedOps = 2;
|
||||
|
||||
test(reporter, context, runOfNonAA, GrAAType::kCoverage, SkBlendMode::kSrcOver,
|
||||
test(reporter, dContext, runOfNonAA, GrAAType::kCoverage, SkBlendMode::kSrcOver,
|
||||
2*GrResourceProvider::MaxNumAAQuads(), kNumExpectedOps);
|
||||
}
|
||||
|
||||
@ -211,7 +215,7 @@ static void run_test(GrContext* context, skiatest::Reporter* reporter, BulkRectT
|
||||
|
||||
static const int kNumExpectedOps = 2;
|
||||
|
||||
test(reporter, context, fixedAA, GrAAType::kCoverage, SkBlendMode::kSrcATop,
|
||||
test(reporter, dContext, fixedAA, GrAAType::kCoverage, SkBlendMode::kSrcATop,
|
||||
2*GrResourceProvider::MaxNumAAQuads(), kNumExpectedOps);
|
||||
}
|
||||
}
|
||||
|
@ -59,12 +59,12 @@ static bool check_rect(GrRenderTargetContext* rtc, const SkIRect& rect, uint32_t
|
||||
return true;
|
||||
}
|
||||
|
||||
std::unique_ptr<GrRenderTargetContext> newRTC(GrContext* context, int w, int h) {
|
||||
std::unique_ptr<GrRenderTargetContext> newRTC(GrRecordingContext* rContext, int w, int h) {
|
||||
return GrRenderTargetContext::Make(
|
||||
context, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, {w, h});
|
||||
rContext, GrColorType::kRGBA_8888, nullptr, SkBackingFit::kExact, {w, h});
|
||||
}
|
||||
|
||||
static void clear_op_test(skiatest::Reporter* reporter, GrContext* context) {
|
||||
static void clear_op_test(skiatest::Reporter* reporter, GrRecordingContext* rContext) {
|
||||
static const int kW = 10;
|
||||
static const int kH = 10;
|
||||
|
||||
@ -95,7 +95,7 @@ static void clear_op_test(skiatest::Reporter* reporter, GrContext* context) {
|
||||
static const SkPMColor4f kColor1f = SkPMColor4f::FromBytes_RGBA(kColor1);
|
||||
static const SkPMColor4f kColor2f = SkPMColor4f::FromBytes_RGBA(kColor2);
|
||||
|
||||
rtContext = newRTC(context, kW, kH);
|
||||
rtContext = newRTC(rContext, kW, kH);
|
||||
SkASSERT(rtContext);
|
||||
|
||||
// Check a full clear
|
||||
@ -105,7 +105,7 @@ static void clear_op_test(skiatest::Reporter* reporter, GrContext* context) {
|
||||
failX, failY);
|
||||
}
|
||||
|
||||
rtContext = newRTC(context, kW, kH);
|
||||
rtContext = newRTC(rContext, kW, kH);
|
||||
SkASSERT(rtContext);
|
||||
|
||||
// Check two full clears, same color
|
||||
@ -116,7 +116,7 @@ static void clear_op_test(skiatest::Reporter* reporter, GrContext* context) {
|
||||
failX, failY);
|
||||
}
|
||||
|
||||
rtContext = newRTC(context, kW, kH);
|
||||
rtContext = newRTC(rContext, kW, kH);
|
||||
SkASSERT(rtContext);
|
||||
|
||||
// Check two full clears, different colors
|
||||
@ -127,7 +127,7 @@ static void clear_op_test(skiatest::Reporter* reporter, GrContext* context) {
|
||||
failX, failY);
|
||||
}
|
||||
|
||||
rtContext = newRTC(context, kW, kH);
|
||||
rtContext = newRTC(rContext, kW, kH);
|
||||
SkASSERT(rtContext);
|
||||
|
||||
// Test a full clear followed by a same color inset clear
|
||||
@ -138,7 +138,7 @@ static void clear_op_test(skiatest::Reporter* reporter, GrContext* context) {
|
||||
failX, failY);
|
||||
}
|
||||
|
||||
rtContext = newRTC(context, kW, kH);
|
||||
rtContext = newRTC(rContext, kW, kH);
|
||||
SkASSERT(rtContext);
|
||||
|
||||
// Test a inset clear followed by same color full clear
|
||||
@ -149,7 +149,7 @@ static void clear_op_test(skiatest::Reporter* reporter, GrContext* context) {
|
||||
failX, failY);
|
||||
}
|
||||
|
||||
rtContext = newRTC(context, kW, kH);
|
||||
rtContext = newRTC(rContext, kW, kH);
|
||||
SkASSERT(rtContext);
|
||||
|
||||
// Test a full clear followed by a different color inset clear
|
||||
@ -167,7 +167,7 @@ static void clear_op_test(skiatest::Reporter* reporter, GrContext* context) {
|
||||
failX, failY);
|
||||
}
|
||||
|
||||
rtContext = newRTC(context, kW, kH);
|
||||
rtContext = newRTC(rContext, kW, kH);
|
||||
SkASSERT(rtContext);
|
||||
|
||||
// Test a inset clear followed by a different full clear
|
||||
@ -178,7 +178,7 @@ static void clear_op_test(skiatest::Reporter* reporter, GrContext* context) {
|
||||
failX, failY);
|
||||
}
|
||||
|
||||
rtContext = newRTC(context, kW, kH);
|
||||
rtContext = newRTC(rContext, kW, kH);
|
||||
SkASSERT(rtContext);
|
||||
|
||||
// Check three nested clears from largest to smallest where outermost and innermost are same
|
||||
@ -205,7 +205,7 @@ static void clear_op_test(skiatest::Reporter* reporter, GrContext* context) {
|
||||
failX, failY);
|
||||
}
|
||||
|
||||
rtContext = newRTC(context, kW, kH);
|
||||
rtContext = newRTC(rContext, kW, kH);
|
||||
SkASSERT(rtContext);
|
||||
|
||||
// Swap the order of the second two clears in the above test.
|
||||
@ -236,10 +236,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ClearOp, reporter, ctxInfo) {
|
||||
clear_op_test(reporter, workaroundFactory.get(ctxInfo.type()));
|
||||
}
|
||||
|
||||
void fullscreen_clear_with_layer_test(skiatest::Reporter* reporter, GrContext* context) {
|
||||
void fullscreen_clear_with_layer_test(skiatest::Reporter* reporter, GrRecordingContext* rContext) {
|
||||
const SkImageInfo ii = SkImageInfo::Make(400, 77, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
||||
|
||||
sk_sp<SkSurface> surf = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, ii);
|
||||
sk_sp<SkSurface> surf = SkSurface::MakeRenderTarget(rContext, SkBudgeted::kYes, ii);
|
||||
SkCanvas* canvas = surf->getCanvas();
|
||||
|
||||
SkPaint paints[2];
|
||||
|
@ -13,20 +13,26 @@
|
||||
#include "src/gpu/mtl/GrMtlCaps.h"
|
||||
|
||||
// In BackendAllocationTest.cpp
|
||||
void test_wrapping(GrContext* context, skiatest::Reporter* reporter,
|
||||
std::function<GrBackendTexture (GrContext*,
|
||||
void test_wrapping(GrDirectContext*,
|
||||
skiatest::Reporter*,
|
||||
std::function<GrBackendTexture (GrDirectContext*,
|
||||
GrMipMapped,
|
||||
GrRenderable)> create,
|
||||
GrColorType colorType, GrMipMapped mipMapped, GrRenderable renderable,
|
||||
GrColorType,
|
||||
GrMipMapped,
|
||||
GrRenderable,
|
||||
bool* finishedBackendCreation);
|
||||
|
||||
void test_color_init(GrContext* context, skiatest::Reporter* reporter,
|
||||
std::function<GrBackendTexture (GrContext*,
|
||||
void test_color_init(GrDirectContext*,
|
||||
skiatest::Reporter*,
|
||||
std::function<GrBackendTexture (GrDirectContext*,
|
||||
const SkColor4f&,
|
||||
GrMipMapped,
|
||||
GrRenderable)> create,
|
||||
GrColorType colorType, const SkColor4f& color,
|
||||
GrMipMapped mipMapped, GrRenderable renderable,
|
||||
GrColorType,
|
||||
const SkColor4f&,
|
||||
GrMipMapped,
|
||||
GrRenderable,
|
||||
bool* finishedBackendCreation);
|
||||
|
||||
static void mark_signaled(void* context) {
|
||||
@ -34,8 +40,8 @@ static void mark_signaled(void* context) {
|
||||
}
|
||||
|
||||
DEF_GPUTEST_FOR_METAL_CONTEXT(MtlBackendAllocationTest, reporter, ctxInfo) {
|
||||
auto context = ctxInfo.directContext();
|
||||
const GrMtlCaps* mtlCaps = static_cast<const GrMtlCaps*>(context->priv().caps());
|
||||
auto dContext = ctxInfo.directContext();
|
||||
const GrMtlCaps* mtlCaps = static_cast<const GrMtlCaps*>(dContext->priv().caps());
|
||||
|
||||
constexpr SkColor4f kTransCol { 0, 0.25f, 0.75f, 0.5f };
|
||||
constexpr SkColor4f kGrayCol { 0.75f, 0.75f, 0.75f, 0.75f };
|
||||
@ -112,15 +118,15 @@ DEF_GPUTEST_FOR_METAL_CONTEXT(MtlBackendAllocationTest, reporter, ctxInfo) {
|
||||
}
|
||||
|
||||
{
|
||||
auto uninitCreateMtd = [format](GrContext* context,
|
||||
auto uninitCreateMtd = [format](GrDirectContext* dContext,
|
||||
GrMipMapped mipMapped,
|
||||
GrRenderable renderable) {
|
||||
return context->createBackendTexture(32, 32, format,
|
||||
mipMapped, renderable,
|
||||
GrProtected::kNo);
|
||||
return dContext->createBackendTexture(32, 32, format,
|
||||
mipMapped, renderable,
|
||||
GrProtected::kNo);
|
||||
};
|
||||
|
||||
test_wrapping(context, reporter, uninitCreateMtd,
|
||||
test_wrapping(dContext, reporter, uninitCreateMtd,
|
||||
combo.fColorType, mipMapped, renderable, nullptr);
|
||||
}
|
||||
|
||||
@ -152,13 +158,15 @@ DEF_GPUTEST_FOR_METAL_CONTEXT(MtlBackendAllocationTest, reporter, ctxInfo) {
|
||||
bool* finishedPtr = &finishedBackendCreation;
|
||||
|
||||
auto createWithColorMtd = [format, swizzle, finishedPtr](
|
||||
GrContext* context, const SkColor4f& color, GrMipMapped mipMapped,
|
||||
GrDirectContext* dContext,
|
||||
const SkColor4f& color,
|
||||
GrMipMapped mipMapped,
|
||||
GrRenderable renderable) {
|
||||
auto swizzledColor = swizzle.applyTo(color);
|
||||
return context->createBackendTexture(32, 32, format, swizzledColor,
|
||||
mipMapped, renderable,
|
||||
GrProtected::kNo,
|
||||
mark_signaled, finishedPtr);
|
||||
return dContext->createBackendTexture(32, 32, format, swizzledColor,
|
||||
mipMapped, renderable,
|
||||
GrProtected::kNo,
|
||||
mark_signaled, finishedPtr);
|
||||
};
|
||||
// We make our comparison color using SkPixmap::erase(color) on a pixmap of
|
||||
// combo.fColorType and then calling SkPixmap::readPixels(). erase() will premul
|
||||
@ -172,7 +180,7 @@ DEF_GPUTEST_FOR_METAL_CONTEXT(MtlBackendAllocationTest, reporter, ctxInfo) {
|
||||
color.fB * color.fA,
|
||||
1.f};
|
||||
}
|
||||
test_color_init(context, reporter, createWithColorMtd, combo.fColorType, color,
|
||||
test_color_init(dContext, reporter, createWithColorMtd, combo.fColorType, color,
|
||||
mipMapped, renderable, finishedPtr);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user