Clean up more tests wrt GrContext

Change-Id: I70189e316be19f28d70c2fae832a868101fd3329
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/303998
Reviewed-by: Adlai Holler <adlai@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
Robert Phillips 2020-07-20 10:56:01 -04:00 committed by Skia Commit-Bot
parent daa5859e49
commit c8ae494401
5 changed files with 189 additions and 181 deletions

View File

@ -7,6 +7,7 @@
#include "include/core/SkCanvas.h" #include "include/core/SkCanvas.h"
#include "include/gpu/GrDirectContext.h" #include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "src/core/SkAutoPixmapStorage.h" #include "src/core/SkAutoPixmapStorage.h"
#include "src/core/SkCompressedDataUtils.h" #include "src/core/SkCompressedDataUtils.h"
#include "src/core/SkMipmap.h" #include "src/core/SkMipmap.h"
@ -51,7 +52,7 @@ sk_sp<SkImage> create_image(GrContext* context, const GrBackendTexture& backendT
// Draw the compressed backend texture (wrapped in an SkImage) into an RGBA surface, attempting // Draw the compressed backend texture (wrapped in an SkImage) into an RGBA surface, attempting
// to access all the mipMap levels. // to access all the mipMap levels.
static void check_compressed_mipmaps(GrContext* context, sk_sp<SkImage> img, static void check_compressed_mipmaps(GrRecordingContext* rContext, sk_sp<SkImage> img,
SkImage::CompressionType compressionType, SkImage::CompressionType compressionType,
const SkColor4f expectedColors[6], const SkColor4f expectedColors[6],
GrMipMapped mipMapped, GrMipMapped mipMapped,
@ -60,7 +61,7 @@ static void check_compressed_mipmaps(GrContext* context, sk_sp<SkImage> img,
SkImageInfo readbackSurfaceII = SkImageInfo::Make(32, 32, kRGBA_8888_SkColorType, SkImageInfo readbackSurfaceII = SkImageInfo::Make(32, 32, kRGBA_8888_SkColorType,
kPremul_SkAlphaType); kPremul_SkAlphaType);
sk_sp<SkSurface> surf = SkSurface::MakeRenderTarget(context, sk_sp<SkSurface> surf = SkSurface::MakeRenderTarget(rContext,
SkBudgeted::kNo, SkBudgeted::kNo,
readbackSurfaceII, 1, readbackSurfaceII, 1,
kTopLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin,
@ -107,13 +108,13 @@ static void check_compressed_mipmaps(GrContext* context, sk_sp<SkImage> img,
} }
// Verify that we can readback from a compressed texture // Verify that we can readback from a compressed texture
static void check_readback(GrContext* context, sk_sp<SkImage> img, static void check_readback(GrDirectContext* dContext, sk_sp<SkImage> img,
SkImage::CompressionType compressionType, SkImage::CompressionType compressionType,
const SkColor4f& expectedColor, const SkColor4f& expectedColor,
skiatest::Reporter* reporter, const char* label) { skiatest::Reporter* reporter, const char* label) {
#ifdef SK_BUILD_FOR_IOS #ifdef SK_BUILD_FOR_IOS
// reading back ETC2 is broken on Metal/iOS (skbug.com/9839) // reading back ETC2 is broken on Metal/iOS (skbug.com/9839)
if (context->backend() == GrBackendApi::kMetal) { if (dContext->backend() == GrBackendApi::kMetal) {
return; return;
} }
#endif #endif
@ -135,32 +136,32 @@ static void check_readback(GrContext* context, sk_sp<SkImage> img,
} }
// Test initialization of compressed GrBackendTextures to a specific color // Test initialization of compressed GrBackendTextures to a specific color
static void test_compressed_color_init(GrContext* context, static void test_compressed_color_init(GrDirectContext* dContext,
skiatest::Reporter* reporter, skiatest::Reporter* reporter,
std::function<GrBackendTexture (GrContext*, std::function<GrBackendTexture (GrDirectContext*,
const SkColor4f&, const SkColor4f&,
GrMipMapped)> create, GrMipMapped)> create,
const SkColor4f& color, const SkColor4f& color,
SkImage::CompressionType compression, SkImage::CompressionType compression,
GrMipMapped mipMapped) { GrMipMapped mipMapped) {
GrBackendTexture backendTex = create(context, color, mipMapped); GrBackendTexture backendTex = create(dContext, color, mipMapped);
if (!backendTex.isValid()) { if (!backendTex.isValid()) {
return; return;
} }
sk_sp<SkImage> img = create_image(context, backendTex); sk_sp<SkImage> img = create_image(dContext, backendTex);
if (!img) { if (!img) {
return; return;
} }
SkColor4f expectedColors[6] = { color, color, color, color, color, color }; SkColor4f expectedColors[6] = { color, color, color, color, color, color };
check_compressed_mipmaps(context, img, compression, expectedColors, mipMapped, check_compressed_mipmaps(dContext, img, compression, expectedColors, mipMapped,
reporter, "colorinit"); reporter, "colorinit");
check_readback(context, std::move(img), compression, color, reporter, check_readback(dContext, std::move(img), compression, color, reporter,
"solid readback"); "solid readback");
context->deleteBackendTexture(backendTex); dContext->deleteBackendTexture(backendTex);
} }
// Create compressed data pulling the color for each mipmap level from 'levelColors'. // Create compressed data pulling the color for each mipmap level from 'levelColors'.
@ -194,9 +195,9 @@ static std::unique_ptr<const char[]> make_compressed_data(SkImage::CompressionTy
// Verify that we can initialize a compressed backend texture with data (esp. // Verify that we can initialize a compressed backend texture with data (esp.
// the mipmap levels). // the mipmap levels).
static void test_compressed_data_init(GrContext* context, static void test_compressed_data_init(GrDirectContext* dContext,
skiatest::Reporter* reporter, skiatest::Reporter* reporter,
std::function<GrBackendTexture (GrContext*, std::function<GrBackendTexture (GrDirectContext*,
const char* data, const char* data,
size_t dataSize, size_t dataSize,
GrMipMapped)> create, GrMipMapped)> create,
@ -217,27 +218,27 @@ static void test_compressed_data_init(GrContext* context,
size_t dataSize = SkCompressedDataSize(compression, { 32, 32 }, nullptr, size_t dataSize = SkCompressedDataSize(compression, { 32, 32 }, nullptr,
mipMapped == GrMipMapped::kYes); mipMapped == GrMipMapped::kYes);
GrBackendTexture backendTex = create(context, data.get(), dataSize, mipMapped); GrBackendTexture backendTex = create(dContext, data.get(), dataSize, mipMapped);
if (!backendTex.isValid()) { if (!backendTex.isValid()) {
return; return;
} }
sk_sp<SkImage> img = create_image(context, backendTex); sk_sp<SkImage> img = create_image(dContext, backendTex);
if (!img) { if (!img) {
return; return;
} }
check_compressed_mipmaps(context, img, compression, expectedColors, check_compressed_mipmaps(dContext, img, compression, expectedColors,
mipMapped, reporter, "pixmap"); mipMapped, reporter, "pixmap");
check_readback(context, std::move(img), compression, expectedColors[0], reporter, check_readback(dContext, std::move(img), compression, expectedColors[0], reporter,
"data readback"); "data readback");
context->deleteBackendTexture(backendTex); dContext->deleteBackendTexture(backendTex);
} }
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CompressedBackendAllocationTest, reporter, ctxInfo) { DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CompressedBackendAllocationTest, reporter, ctxInfo) {
auto context = ctxInfo.directContext(); auto dContext = ctxInfo.directContext();
const GrCaps* caps = context->priv().caps(); const GrCaps* caps = dContext->priv().caps();
struct { struct {
SkImage::CompressionType fCompression; SkImage::CompressionType fCompression;
@ -249,7 +250,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CompressedBackendAllocationTest, reporter, ct
}; };
for (auto combo : combinations) { for (auto combo : combinations) {
GrBackendFormat format = context->compressedBackendFormat(combo.fCompression); GrBackendFormat format = dContext->compressedBackendFormat(combo.fCompression);
if (!format.isValid()) { if (!format.isValid()) {
continue; continue;
} }
@ -265,27 +266,27 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(CompressedBackendAllocationTest, reporter, ct
// color initialized // color initialized
{ {
auto createWithColorMtd = [format](GrContext* context, auto createWithColorMtd = [format](GrDirectContext* dContext,
const SkColor4f& color, const SkColor4f& color,
GrMipMapped mipMapped) { GrMipMapped mipMapped) {
return context->createCompressedBackendTexture(32, 32, format, color, return dContext->createCompressedBackendTexture(32, 32, format, color,
mipMapped, GrProtected::kNo); mipMapped, GrProtected::kNo);
}; };
test_compressed_color_init(context, reporter, createWithColorMtd, test_compressed_color_init(dContext, reporter, createWithColorMtd,
combo.fColor, combo.fCompression, mipMapped); combo.fColor, combo.fCompression, mipMapped);
} }
// data initialized // data initialized
{ {
auto createWithDataMtd = [format](GrContext* context, auto createWithDataMtd = [format](GrDirectContext* dContext,
const char* data, size_t dataSize, const char* data, size_t dataSize,
GrMipMapped mipMapped) { GrMipMapped mipMapped) {
return context->createCompressedBackendTexture(32, 32, format, data, dataSize, return dContext->createCompressedBackendTexture(32, 32, format, data, dataSize,
mipMapped, GrProtected::kNo); mipMapped, GrProtected::kNo);
}; };
test_compressed_data_init(context, reporter, createWithDataMtd, test_compressed_data_init(dContext, reporter, createWithDataMtd,
combo.fCompression, mipMapped); combo.fCompression, mipMapped);
} }

View File

@ -24,6 +24,7 @@
#include "include/gpu/GrBackendSurface.h" #include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrContextThreadSafeProxy.h" #include "include/gpu/GrContextThreadSafeProxy.h"
#include "include/gpu/GrDirectContext.h" #include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/gpu/GrTypes.h" #include "include/gpu/GrTypes.h"
#include "include/gpu/gl/GrGLTypes.h" #include "include/gpu/gl/GrGLTypes.h"
#include "include/private/GrTypesPriv.h" #include "include/private/GrTypesPriv.h"
@ -31,6 +32,7 @@
#include "src/gpu/GrCaps.h" #include "src/gpu/GrCaps.h"
#include "src/gpu/GrContextPriv.h" #include "src/gpu/GrContextPriv.h"
#include "src/gpu/GrGpu.h" #include "src/gpu/GrGpu.h"
#include "src/gpu/GrRecordingContextPriv.h"
#include "src/gpu/GrRenderTargetContext.h" #include "src/gpu/GrRenderTargetContext.h"
#include "src/gpu/GrRenderTargetProxy.h" #include "src/gpu/GrRenderTargetProxy.h"
#include "src/gpu/GrTextureProxy.h" #include "src/gpu/GrTextureProxy.h"
@ -58,8 +60,8 @@ public:
static const int kFBO0Count = 9; static const int kFBO0Count = 9;
static const int kProtectedCount = 11; static const int kProtectedCount = 11;
SurfaceParameters(GrContext* context) SurfaceParameters(GrRecordingContext* rContext)
: fBackend(context->backend()) : fBackend(rContext->backend())
, fWidth(64) , fWidth(64)
, fHeight(64) , fHeight(64)
, fOrigin(kTopLeft_GrSurfaceOrigin) , fOrigin(kTopLeft_GrSurfaceOrigin)
@ -72,8 +74,8 @@ public:
, fIsTextureable(true) , fIsTextureable(true)
, fIsProtected(GrProtected::kNo) { , fIsProtected(GrProtected::kNo) {
#ifdef SK_VULKAN #ifdef SK_VULKAN
if (GrBackendApi::kVulkan == context->backend()) { if (GrBackendApi::kVulkan == rContext->backend()) {
const GrVkCaps* vkCaps = (const GrVkCaps*) context->priv().caps(); const GrVkCaps* vkCaps = (const GrVkCaps*) rContext->priv().caps();
fIsProtected = GrProtected(vkCaps->supportsProtectedMemory()); fIsProtected = GrProtected(vkCaps->supportsProtectedMemory());
} }
@ -141,10 +143,10 @@ public:
} }
} }
SkSurfaceCharacterization createCharacterization(GrContext* context) const { SkSurfaceCharacterization createCharacterization(GrDirectContext* dContext) const {
size_t maxResourceBytes = context->getResourceCacheLimit(); size_t maxResourceBytes = dContext->getResourceCacheLimit();
if (!context->colorTypeSupportedAsSurface(fColorType)) { if (!dContext->colorTypeSupportedAsSurface(fColorType)) {
return SkSurfaceCharacterization(); return SkSurfaceCharacterization();
} }
@ -152,13 +154,13 @@ public:
SkImageInfo ii = SkImageInfo::Make(fWidth, fHeight, fColorType, SkImageInfo ii = SkImageInfo::Make(fWidth, fHeight, fColorType,
kPremul_SkAlphaType, fColorSpace); kPremul_SkAlphaType, fColorSpace);
GrBackendFormat backendFormat = context->defaultBackendFormat(fColorType, GrBackendFormat backendFormat = dContext->defaultBackendFormat(fColorType,
GrRenderable::kYes); GrRenderable::kYes);
if (!backendFormat.isValid()) { if (!backendFormat.isValid()) {
return SkSurfaceCharacterization(); return SkSurfaceCharacterization();
} }
SkSurfaceCharacterization c = context->threadSafeProxy()->createCharacterization( SkSurfaceCharacterization c = dContext->threadSafeProxy()->createCharacterization(
maxResourceBytes, ii, backendFormat, fSampleCount, maxResourceBytes, ii, backendFormat, fSampleCount,
fOrigin, fSurfaceProps, fShouldCreateMipMaps, fOrigin, fSurfaceProps, fShouldCreateMipMaps,
fUsesGLFBO0, fIsTextureable, fIsProtected); fUsesGLFBO0, fIsTextureable, fIsProtected);
@ -166,8 +168,8 @@ public:
} }
// Create a DDL whose characterization captures the current settings // Create a DDL whose characterization captures the current settings
sk_sp<SkDeferredDisplayList> createDDL(GrContext* context) const { sk_sp<SkDeferredDisplayList> createDDL(GrDirectContext* dContext) const {
SkSurfaceCharacterization c = this->createCharacterization(context); SkSurfaceCharacterization c = this->createCharacterization(dContext);
SkAssertResult(c.isValid()); SkAssertResult(c.isValid());
SkDeferredDisplayListRecorder r(c); SkDeferredDisplayListRecorder r(c);
@ -181,8 +183,8 @@ public:
} }
// Create the surface with the current set of parameters // Create the surface with the current set of parameters
sk_sp<SkSurface> make(GrContext* context, GrBackendTexture* backend) const { sk_sp<SkSurface> make(GrDirectContext* dContext, GrBackendTexture* backend) const {
const SkSurfaceCharacterization c = this->createCharacterization(context); const SkSurfaceCharacterization c = this->createCharacterization(dContext);
GrMipMapped mipmapped = !fIsTextureable GrMipMapped mipmapped = !fIsTextureable
? GrMipMapped::kNo ? GrMipMapped::kNo
@ -190,7 +192,7 @@ public:
#ifdef SK_GL #ifdef SK_GL
if (fUsesGLFBO0) { if (fUsesGLFBO0) {
if (GrBackendApi::kOpenGL != context->backend()) { if (GrBackendApi::kOpenGL != dContext->backend()) {
return nullptr; return nullptr;
} }
@ -204,7 +206,7 @@ public:
return nullptr; return nullptr;
} }
sk_sp<SkSurface> result = SkSurface::MakeFromBackendRenderTarget(context, backendRT, sk_sp<SkSurface> result = SkSurface::MakeFromBackendRenderTarget(dContext, backendRT,
fOrigin, fColorType, fOrigin, fColorType,
fColorSpace, fColorSpace,
&fSurfaceProps); &fSurfaceProps);
@ -212,7 +214,7 @@ public:
return result; return result;
} }
#endif #endif
CreateBackendTexture(context, backend, fWidth, fHeight, fColorType, CreateBackendTexture(dContext, backend, fWidth, fHeight, fColorType,
SkColors::kTransparent, mipmapped, GrRenderable::kYes, fIsProtected); SkColors::kTransparent, mipmapped, GrRenderable::kYes, fIsProtected);
if (!backend->isValid()) { if (!backend->isValid()) {
return nullptr; return nullptr;
@ -226,17 +228,17 @@ public:
if (!fIsTextureable) { if (!fIsTextureable) {
// Create a surface w/ the current parameters but make it non-textureable // Create a surface w/ the current parameters but make it non-textureable
surface = SkSurface::MakeFromBackendTextureAsRenderTarget( surface = SkSurface::MakeFromBackendTextureAsRenderTarget(
context, *backend, fOrigin, fSampleCount, fColorType, dContext, *backend, fOrigin, fSampleCount, fColorType,
fColorSpace, &fSurfaceProps); fColorSpace, &fSurfaceProps);
} else { } else {
surface = SkSurface::MakeFromBackendTexture( surface = SkSurface::MakeFromBackendTexture(
context, *backend, fOrigin, fSampleCount, fColorType, dContext, *backend, fOrigin, fSampleCount, fColorType,
fColorSpace, &fSurfaceProps); fColorSpace, &fSurfaceProps);
} }
if (!surface) { if (!surface) {
SkASSERT(!c.isValid()); SkASSERT(!c.isValid());
this->cleanUpBackEnd(context, *backend); this->cleanUpBackEnd(dContext, *backend);
return nullptr; return nullptr;
} }
@ -245,8 +247,8 @@ public:
return surface; return surface;
} }
void cleanUpBackEnd(GrContext* context, const GrBackendTexture& backend) const { void cleanUpBackEnd(GrDirectContext* dContext, const GrBackendTexture& backend) const {
context->deleteBackendTexture(backend); dContext->deleteBackendTexture(backend);
} }
private: private:
@ -325,9 +327,9 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLOperatorEqTest, reporter, ctxInfo) {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// This tests SkSurfaceCharacterization/SkSurface compatibility // This tests SkSurfaceCharacterization/SkSurface compatibility
void DDLSurfaceCharacterizationTestImpl(GrContext* context, skiatest::Reporter* reporter) { void DDLSurfaceCharacterizationTestImpl(GrDirectContext* dContext, skiatest::Reporter* reporter) {
GrGpu* gpu = context->priv().getGpu(); GrGpu* gpu = dContext->priv().getGpu();
const GrCaps* caps = context->priv().caps(); const GrCaps* caps = dContext->priv().caps();
// Create a bitmap that we can readback into // Create a bitmap that we can readback into
SkImageInfo imageInfo = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType, SkImageInfo imageInfo = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType,
@ -339,38 +341,38 @@ void DDLSurfaceCharacterizationTestImpl(GrContext* context, skiatest::Reporter*
// First, create a DDL using the stock SkSurface parameters // First, create a DDL using the stock SkSurface parameters
{ {
SurfaceParameters params(context); SurfaceParameters params(dContext);
ddl = params.createDDL(context); ddl = params.createDDL(dContext);
SkAssertResult(ddl); SkAssertResult(ddl);
// The DDL should draw into an SkSurface created with the same parameters // The DDL should draw into an SkSurface created with the same parameters
GrBackendTexture backend; GrBackendTexture backend;
sk_sp<SkSurface> s = params.make(context, &backend); sk_sp<SkSurface> s = params.make(dContext, &backend);
if (!s) { if (!s) {
return; return;
} }
REPORTER_ASSERT(reporter, s->draw(ddl)); REPORTER_ASSERT(reporter, s->draw(ddl));
s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0); s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
context->flushAndSubmit(); dContext->flushAndSubmit();
gpu->testingOnly_flushGpuAndSync(); gpu->testingOnly_flushGpuAndSync();
s = nullptr; s = nullptr;
params.cleanUpBackEnd(context, backend); params.cleanUpBackEnd(dContext, backend);
} }
// Then, alter each parameter in turn and check that the DDL & surface are incompatible // Then, alter each parameter in turn and check that the DDL & surface are incompatible
for (int i = 0; i < SurfaceParameters::kNumParams; ++i) { for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
SurfaceParameters params(context); SurfaceParameters params(dContext);
params.modify(i); params.modify(i);
if (SurfaceParameters::kProtectedCount == i) { if (SurfaceParameters::kProtectedCount == i) {
if (context->backend() != GrBackendApi::kVulkan) { if (dContext->backend() != GrBackendApi::kVulkan) {
// Only the Vulkan backend respects the protected parameter // Only the Vulkan backend respects the protected parameter
continue; continue;
} }
#ifdef SK_VULKAN #ifdef SK_VULKAN
const GrVkCaps* vkCaps = (const GrVkCaps*) context->priv().caps(); const GrVkCaps* vkCaps = (const GrVkCaps*) dContext->priv().caps();
// And, even then, only when it is a protected context // And, even then, only when it is a protected context
if (!vkCaps->supportsProtectedMemory()) { if (!vkCaps->supportsProtectedMemory()) {
@ -380,7 +382,7 @@ void DDLSurfaceCharacterizationTestImpl(GrContext* context, skiatest::Reporter*
} }
GrBackendTexture backend; GrBackendTexture backend;
sk_sp<SkSurface> s = params.make(context, &backend); sk_sp<SkSurface> s = params.make(dContext, &backend);
if (!s) { if (!s) {
continue; continue;
} }
@ -392,7 +394,7 @@ void DDLSurfaceCharacterizationTestImpl(GrContext* context, skiatest::Reporter*
// If changing the sample count won't result in a different // If changing the sample count won't result in a different
// surface characterization, skip this step // surface characterization, skip this step
s = nullptr; s = nullptr;
params.cleanUpBackEnd(context, backend); params.cleanUpBackEnd(dContext, backend);
continue; continue;
} }
} }
@ -401,36 +403,36 @@ void DDLSurfaceCharacterizationTestImpl(GrContext* context, skiatest::Reporter*
// If changing the mipmap setting won't result in a different surface characterization, // If changing the mipmap setting won't result in a different surface characterization,
// skip this step // skip this step
s = nullptr; s = nullptr;
params.cleanUpBackEnd(context, backend); params.cleanUpBackEnd(dContext, backend);
continue; continue;
} }
if (SurfaceParameters::kFBO0Count == i && context->backend() != GrBackendApi::kOpenGL) { if (SurfaceParameters::kFBO0Count == i && dContext->backend() != GrBackendApi::kOpenGL) {
// FBO0 only affects the surface characterization when using OpenGL // FBO0 only affects the surface characterization when using OpenGL
s = nullptr; s = nullptr;
params.cleanUpBackEnd(context, backend); params.cleanUpBackEnd(dContext, backend);
continue; continue;
} }
REPORTER_ASSERT(reporter, !s->draw(ddl), REPORTER_ASSERT(reporter, !s->draw(ddl),
"DDLSurfaceCharacterizationTest failed on parameter: %d\n", i); "DDLSurfaceCharacterizationTest failed on parameter: %d\n", i);
context->flushAndSubmit(); dContext->flushAndSubmit();
gpu->testingOnly_flushGpuAndSync(); gpu->testingOnly_flushGpuAndSync();
s = nullptr; s = nullptr;
params.cleanUpBackEnd(context, backend); params.cleanUpBackEnd(dContext, backend);
} }
// Next test the compatibility of resource cache parameters // Next test the compatibility of resource cache parameters
{ {
const SurfaceParameters params(context); const SurfaceParameters params(dContext);
GrBackendTexture backend; GrBackendTexture backend;
sk_sp<SkSurface> s = params.make(context, &backend); sk_sp<SkSurface> s = params.make(dContext, &backend);
size_t maxResourceBytes = context->getResourceCacheLimit(); size_t maxResourceBytes = dContext->getResourceCacheLimit();
context->setResourceCacheLimit(maxResourceBytes/2); dContext->setResourceCacheLimit(maxResourceBytes/2);
REPORTER_ASSERT(reporter, !s->draw(ddl)); REPORTER_ASSERT(reporter, !s->draw(ddl));
// DDL TODO: once proxies/ops can be de-instantiated we can re-enable these tests. // DDL TODO: once proxies/ops can be de-instantiated we can re-enable these tests.
@ -450,27 +452,27 @@ void DDLSurfaceCharacterizationTestImpl(GrContext* context, skiatest::Reporter*
s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0); s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
#endif #endif
context->flushAndSubmit(); dContext->flushAndSubmit();
gpu->testingOnly_flushGpuAndSync(); gpu->testingOnly_flushGpuAndSync();
s = nullptr; s = nullptr;
params.cleanUpBackEnd(context, backend); params.cleanUpBackEnd(dContext, backend);
} }
// Test that the textureability of the DDL characterization can block a DDL draw // Test that the textureability of the DDL characterization can block a DDL draw
{ {
GrBackendTexture backend; GrBackendTexture backend;
SurfaceParameters params(context); SurfaceParameters params(dContext);
params.setShouldCreateMipMaps(false); params.setShouldCreateMipMaps(false);
params.setTextureable(false); params.setTextureable(false);
sk_sp<SkSurface> s = params.make(context, &backend); sk_sp<SkSurface> s = params.make(dContext, &backend);
if (s) { if (s) {
REPORTER_ASSERT(reporter, !s->draw(ddl)); // bc the DDL was made w/ textureability REPORTER_ASSERT(reporter, !s->draw(ddl)); // bc the DDL was made w/ textureability
context->flushAndSubmit(); dContext->flushAndSubmit();
gpu->testingOnly_flushGpuAndSync(); gpu->testingOnly_flushGpuAndSync();
s = nullptr; s = nullptr;
params.cleanUpBackEnd(context, backend); params.cleanUpBackEnd(dContext, backend);
} }
} }
@ -485,10 +487,10 @@ void DDLSurfaceCharacterizationTestImpl(GrContext* context, skiatest::Reporter*
// Exercise the createResized method // Exercise the createResized method
{ {
SurfaceParameters params(context); SurfaceParameters params(dContext);
GrBackendTexture backend; GrBackendTexture backend;
sk_sp<SkSurface> s = params.make(context, &backend); sk_sp<SkSurface> s = params.make(dContext, &backend);
if (!s) { if (!s) {
return; return;
} }
@ -511,15 +513,15 @@ void DDLSurfaceCharacterizationTestImpl(GrContext* context, skiatest::Reporter*
REPORTER_ASSERT(reporter, 32 == char3.height()); REPORTER_ASSERT(reporter, 32 == char3.height());
s = nullptr; s = nullptr;
params.cleanUpBackEnd(context, backend); params.cleanUpBackEnd(dContext, backend);
} }
// Exercise the createColorSpace method // Exercise the createColorSpace method
{ {
SurfaceParameters params(context); SurfaceParameters params(dContext);
GrBackendTexture backend; GrBackendTexture backend;
sk_sp<SkSurface> s = params.make(context, &backend); sk_sp<SkSurface> s = params.make(dContext, &backend);
if (!s) { if (!s) {
return; return;
} }
@ -556,15 +558,15 @@ void DDLSurfaceCharacterizationTestImpl(GrContext* context, skiatest::Reporter*
} }
s = nullptr; s = nullptr;
params.cleanUpBackEnd(context, backend); params.cleanUpBackEnd(dContext, backend);
} }
// Exercise the createBackendFormat method // Exercise the createBackendFormat method
{ {
SurfaceParameters params(context); SurfaceParameters params(dContext);
GrBackendTexture backend; GrBackendTexture backend;
sk_sp<SkSurface> s = params.make(context, &backend); sk_sp<SkSurface> s = params.make(dContext, &backend);
if (!s) { if (!s) {
return; return;
} }
@ -573,13 +575,13 @@ void DDLSurfaceCharacterizationTestImpl(GrContext* context, skiatest::Reporter*
SkAssertResult(s->characterize(&char0)); SkAssertResult(s->characterize(&char0));
// The default params create a renderable RGBA8 surface // The default params create a renderable RGBA8 surface
auto originalBackendFormat = context->defaultBackendFormat(kRGBA_8888_SkColorType, auto originalBackendFormat = dContext->defaultBackendFormat(kRGBA_8888_SkColorType,
GrRenderable::kYes); GrRenderable::kYes);
REPORTER_ASSERT(reporter, originalBackendFormat.isValid()); REPORTER_ASSERT(reporter, originalBackendFormat.isValid());
REPORTER_ASSERT(reporter, char0.backendFormat() == originalBackendFormat); REPORTER_ASSERT(reporter, char0.backendFormat() == originalBackendFormat);
auto newBackendFormat = context->defaultBackendFormat(kRGB_565_SkColorType, auto newBackendFormat = dContext->defaultBackendFormat(kRGB_565_SkColorType,
GrRenderable::kYes); GrRenderable::kYes);
if (newBackendFormat.isValid()) { if (newBackendFormat.isValid()) {
SkSurfaceCharacterization char1 = char0.createBackendFormat(kRGB_565_SkColorType, SkSurfaceCharacterization char1 = char0.createBackendFormat(kRGB_565_SkColorType,
@ -595,15 +597,15 @@ void DDLSurfaceCharacterizationTestImpl(GrContext* context, skiatest::Reporter*
} }
s = nullptr; s = nullptr;
params.cleanUpBackEnd(context, backend); params.cleanUpBackEnd(dContext, backend);
} }
// Exercise the createFBO0 method // Exercise the createFBO0 method
if (context->backend() == GrBackendApi::kOpenGL) { if (dContext->backend() == GrBackendApi::kOpenGL) {
SurfaceParameters params(context); SurfaceParameters params(dContext);
GrBackendTexture backend; GrBackendTexture backend;
sk_sp<SkSurface> s = params.make(context, &backend); sk_sp<SkSurface> s = params.make(dContext, &backend);
if (!s) { if (!s) {
return; return;
} }
@ -628,7 +630,7 @@ void DDLSurfaceCharacterizationTestImpl(GrContext* context, skiatest::Reporter*
} }
s = nullptr; s = nullptr;
params.cleanUpBackEnd(context, backend); params.cleanUpBackEnd(dContext, backend);
} }
} }
@ -761,34 +763,34 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(DDLNonTextureabilityTest, reporter, ctxInfo)
} }
static void test_make_render_target(skiatest::Reporter* reporter, static void test_make_render_target(skiatest::Reporter* reporter,
GrContext* context, GrDirectContext* dContext,
const SurfaceParameters& params) { const SurfaceParameters& params) {
{ {
const SkSurfaceCharacterization c = params.createCharacterization(context); const SkSurfaceCharacterization c = params.createCharacterization(dContext);
if (!c.isValid()) { if (!c.isValid()) {
GrBackendTexture backend; GrBackendTexture backend;
sk_sp<SkSurface> tmp = params.make(context, &backend); sk_sp<SkSurface> tmp = params.make(dContext, &backend);
// If we couldn't characterize the surface we shouldn't be able to create it either // If we couldn't characterize the surface we shouldn't be able to create it either
REPORTER_ASSERT(reporter, !tmp); REPORTER_ASSERT(reporter, !tmp);
if (tmp) { if (tmp) {
tmp = nullptr; tmp = nullptr;
params.cleanUpBackEnd(context, backend); params.cleanUpBackEnd(dContext, backend);
} }
return; return;
} }
} }
const SkSurfaceCharacterization c = params.createCharacterization(context); const SkSurfaceCharacterization c = params.createCharacterization(dContext);
GrBackendTexture backend; GrBackendTexture backend;
{ {
sk_sp<SkSurface> s = params.make(context, &backend); sk_sp<SkSurface> s = params.make(dContext, &backend);
REPORTER_ASSERT(reporter, s); REPORTER_ASSERT(reporter, s);
if (!s) { if (!s) {
REPORTER_ASSERT(reporter, !c.isValid()); REPORTER_ASSERT(reporter, !c.isValid());
params.cleanUpBackEnd(context, backend); params.cleanUpBackEnd(dContext, backend);
return; return;
} }
@ -800,26 +802,26 @@ static void test_make_render_target(skiatest::Reporter* reporter,
// Make an SkSurface from scratch // Make an SkSurface from scratch
{ {
sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, c, SkBudgeted::kYes); sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(dContext, c, SkBudgeted::kYes);
REPORTER_ASSERT(reporter, s); REPORTER_ASSERT(reporter, s);
REPORTER_ASSERT(reporter, s->isCompatible(c)); REPORTER_ASSERT(reporter, s->isCompatible(c));
} }
// Make an SkSurface that wraps the existing backend texture // Make an SkSurface that wraps the existing backend texture
{ {
sk_sp<SkSurface> s = SkSurface::MakeFromBackendTexture(context, c, backend); sk_sp<SkSurface> s = SkSurface::MakeFromBackendTexture(dContext, c, backend);
REPORTER_ASSERT(reporter, s); REPORTER_ASSERT(reporter, s);
REPORTER_ASSERT(reporter, s->isCompatible(c)); REPORTER_ASSERT(reporter, s->isCompatible(c));
} }
params.cleanUpBackEnd(context, backend); params.cleanUpBackEnd(dContext, backend);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// This tests the SkSurface::MakeRenderTarget variants that take an SkSurfaceCharacterization. // This tests the SkSurface::MakeRenderTarget variants that take an SkSurfaceCharacterization.
// In particular, the SkSurface, backendTexture and SkSurfaceCharacterization // In particular, the SkSurface, backendTexture and SkSurfaceCharacterization
// should always be compatible. // should always be compatible.
void DDLMakeRenderTargetTestImpl(GrContext* context, skiatest::Reporter* reporter) { void DDLMakeRenderTargetTestImpl(GrDirectContext* dContext, skiatest::Reporter* reporter) {
for (int i = 0; i < SurfaceParameters::kNumParams; ++i) { for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
if (SurfaceParameters::kFBO0Count == i) { if (SurfaceParameters::kFBO0Count == i) {
@ -828,12 +830,12 @@ void DDLMakeRenderTargetTestImpl(GrContext* context, skiatest::Reporter* reporte
} }
if (SurfaceParameters::kProtectedCount == i) { if (SurfaceParameters::kProtectedCount == i) {
if (context->backend() != GrBackendApi::kVulkan) { if (dContext->backend() != GrBackendApi::kVulkan) {
// Only the Vulkan backend respects the protected parameter // Only the Vulkan backend respects the protected parameter
continue; continue;
} }
#ifdef SK_VULKAN #ifdef SK_VULKAN
const GrVkCaps* vkCaps = (const GrVkCaps*) context->priv().caps(); const GrVkCaps* vkCaps = (const GrVkCaps*) dContext->priv().caps();
// And, even then, only when it is a protected context // And, even then, only when it is a protected context
if (!vkCaps->supportsProtectedMemory()) { if (!vkCaps->supportsProtectedMemory()) {
@ -843,14 +845,14 @@ void DDLMakeRenderTargetTestImpl(GrContext* context, skiatest::Reporter* reporte
} }
SurfaceParameters params(context); SurfaceParameters params(dContext);
params.modify(i); params.modify(i);
if (!context->priv().caps()->mipMapSupport()) { if (!dContext->priv().caps()->mipMapSupport()) {
params.setShouldCreateMipMaps(false); params.setShouldCreateMipMaps(false);
} }
test_make_render_target(reporter, context, params); test_make_render_target(reporter, dContext, params);
} }
} }

View File

@ -173,7 +173,9 @@ static void compare_pixmaps(skiatest::Reporter* reporter,
ComparePixels(expected, actual, tols, error); ComparePixels(expected, actual, tols, error);
} }
static void gpu_tests(GrContext* context, skiatest::Reporter* reporter, const TestCase& test) { static void gpu_tests(GrDirectContext* dContext,
skiatest::Reporter* reporter,
const TestCase& test) {
const SkImageInfo nativeII = SkImageInfo::Make(kSize, kSize, test.fColorType, test.fAlphaType); const SkImageInfo nativeII = SkImageInfo::Make(kSize, kSize, test.fColorType, test.fAlphaType);
const SkImageInfo f32Unpremul = SkImageInfo::Make(kSize, kSize, kRGBA_F32_SkColorType, const SkImageInfo f32Unpremul = SkImageInfo::Make(kSize, kSize, kRGBA_F32_SkColorType,
@ -181,11 +183,11 @@ static void gpu_tests(GrContext* context, skiatest::Reporter* reporter, const Te
// We had better not be able to render to prohibited colorTypes // We had better not be able to render to prohibited colorTypes
if (!test.fGpuCanMakeSurfaces) { if (!test.fGpuCanMakeSurfaces) {
auto s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, nativeII); auto s = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, nativeII);
REPORTER_ASSERT(reporter, !SkToBool(s)); REPORTER_ASSERT(reporter, !SkToBool(s));
} }
if (!context->colorTypeSupportedAsImage(test.fColorType)) { if (!dContext->colorTypeSupportedAsImage(test.fColorType)) {
return; return;
} }
@ -201,22 +203,22 @@ static void gpu_tests(GrContext* context, skiatest::Reporter* reporter, const Te
*(bool*)context = true; *(bool*)context = true;
}; };
if (fullInit) { if (fullInit) {
backendTex = context->createBackendTexture(&nativeExpected, 1, backendTex = dContext->createBackendTexture(&nativeExpected, 1,
GrRenderable::kNo, GrProtected::kNo, GrRenderable::kNo, GrProtected::kNo,
markFinished, &finishedBECreate); markFinished, &finishedBECreate);
} else { } else {
backendTex = context->createBackendTexture(kSize, kSize, test.fColorType, backendTex = dContext->createBackendTexture(kSize, kSize, test.fColorType,
SkColors::kWhite, GrMipMapped::kNo, SkColors::kWhite, GrMipMapped::kNo,
GrRenderable::kNo, GrProtected::kNo, GrRenderable::kNo, GrProtected::kNo,
markFinished, &finishedBECreate); markFinished, &finishedBECreate);
} }
REPORTER_ASSERT(reporter, backendTex.isValid()); REPORTER_ASSERT(reporter, backendTex.isValid());
context->submit(); dContext->submit();
while (backendTex.isValid() && !finishedBECreate) { while (backendTex.isValid() && !finishedBECreate) {
context->checkAsyncWorkCompletion(); dContext->checkAsyncWorkCompletion();
} }
auto img = SkImage::MakeFromTexture(context, backendTex, kTopLeft_GrSurfaceOrigin, auto img = SkImage::MakeFromTexture(dContext, backendTex, kTopLeft_GrSurfaceOrigin,
test.fColorType, test.fAlphaType, nullptr); test.fColorType, test.fAlphaType, nullptr);
REPORTER_ASSERT(reporter, SkToBool(img)); REPORTER_ASSERT(reporter, SkToBool(img));
@ -232,8 +234,8 @@ static void gpu_tests(GrContext* context, skiatest::Reporter* reporter, const Te
// SkSurface::readPixels with the same colorType as the source pixels round trips // SkSurface::readPixels with the same colorType as the source pixels round trips
// (when allowed) // (when allowed)
if (context->colorTypeSupportedAsSurface(test.fColorType)) { if (dContext->colorTypeSupportedAsSurface(test.fColorType)) {
auto s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, nativeII); auto s = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, nativeII);
REPORTER_ASSERT(reporter, SkToBool(s)); REPORTER_ASSERT(reporter, SkToBool(s));
{ {
@ -272,7 +274,7 @@ static void gpu_tests(GrContext* context, skiatest::Reporter* reporter, const Te
kRGBA_8888_SkColorType, kRGBA_8888_SkColorType,
kPremul_SkAlphaType); kPremul_SkAlphaType);
auto s = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, rgba8888Premul); auto s = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, rgba8888Premul);
REPORTER_ASSERT(reporter, SkToBool(s)); REPORTER_ASSERT(reporter, SkToBool(s));
{ {
@ -291,8 +293,8 @@ static void gpu_tests(GrContext* context, skiatest::Reporter* reporter, const Te
} }
img.reset(); img.reset();
context->flushAndSubmit(); dContext->flushAndSubmit();
context->deleteBackendTexture(backendTex); dContext->deleteBackendTexture(backendTex);
} }
} }

View File

@ -21,13 +21,13 @@ static void testing_finished_proc(void* ctx) {
*count += 1; *count += 1;
} }
static void busy_wait_for_callback(int* count, int expectedValue, GrContext* ctx, static void busy_wait_for_callback(int* count, int expectedValue, GrDirectContext* dContext,
skiatest::Reporter* reporter) { skiatest::Reporter* reporter) {
// Busy waiting should detect that the work is done. // Busy waiting should detect that the work is done.
auto begin = std::chrono::steady_clock::now(); auto begin = std::chrono::steady_clock::now();
auto end = begin; auto end = begin;
do { do {
ctx->checkAsyncWorkCompletion(); dContext->checkAsyncWorkCompletion();
end = std::chrono::steady_clock::now(); end = std::chrono::steady_clock::now();
} while (*count != expectedValue && (end - begin) < std::chrono::seconds(1)); } while (*count != expectedValue && (end - begin) < std::chrono::seconds(1));
if (*count != expectedValue) { if (*count != expectedValue) {
@ -37,18 +37,18 @@ static void busy_wait_for_callback(int* count, int expectedValue, GrContext* ctx
} }
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FlushFinishedProcTest, reporter, ctxInfo) { DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FlushFinishedProcTest, reporter, ctxInfo) {
auto ctx = ctxInfo.directContext(); auto dContext = ctxInfo.directContext();
SkImageInfo info = SkImageInfo info =
SkImageInfo::Make(8, 8, kRGBA_8888_SkColorType, kPremul_SkAlphaType); SkImageInfo::Make(8, 8, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info); sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, info);
SkCanvas* canvas = surface->getCanvas(); SkCanvas* canvas = surface->getCanvas();
canvas->clear(SK_ColorGREEN); canvas->clear(SK_ColorGREEN);
auto image = surface->makeImageSnapshot(); auto image = surface->makeImageSnapshot();
ctx->flush(); dContext->flush();
ctx->submit(true); dContext->submit(true);
int count = 0; int count = 0;
@ -57,22 +57,23 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FlushFinishedProcTest, reporter, ctxInfo) {
flushInfoFinishedProc.fFinishedContext = (void*)&count; flushInfoFinishedProc.fFinishedContext = (void*)&count;
// There is no work on the surface so flushing may immediately call the finished proc. // There is no work on the surface so flushing may immediately call the finished proc.
surface->flush(flushInfoFinishedProc); surface->flush(flushInfoFinishedProc);
ctx->submit(); dContext->submit();
REPORTER_ASSERT(reporter, count == 0 || count == 1); REPORTER_ASSERT(reporter, count == 0 || count == 1);
// Busy waiting should detect that the work is done. // Busy waiting should detect that the work is done.
busy_wait_for_callback(&count, 1, ctx, reporter); busy_wait_for_callback(&count, 1, dContext, reporter);
canvas->clear(SK_ColorRED); canvas->clear(SK_ColorRED);
surface->flush(flushInfoFinishedProc); surface->flush(flushInfoFinishedProc);
ctx->submit(); dContext->submit();
bool fenceSupport = dContext->priv().caps()->fenceSyncSupport();
bool expectAsyncCallback = bool expectAsyncCallback =
ctx->backend() == GrBackendApi::kVulkan || dContext->backend() == GrBackendApi::kVulkan ||
((ctx->backend() == GrBackendApi::kOpenGL) && ctx->priv().caps()->fenceSyncSupport()) || ((dContext->backend() == GrBackendApi::kOpenGL) && fenceSupport) ||
((ctx->backend() == GrBackendApi::kMetal) && ctx->priv().caps()->fenceSyncSupport()) || ((dContext->backend() == GrBackendApi::kMetal) && fenceSupport) ||
ctx->backend() == GrBackendApi::kDawn || dContext->backend() == GrBackendApi::kDawn ||
ctx->backend() == GrBackendApi::kDirect3D; dContext->backend() == GrBackendApi::kDirect3D;
if (expectAsyncCallback) { if (expectAsyncCallback) {
// On Vulkan the command buffer we just submitted may or may not have finished immediately // On Vulkan the command buffer we just submitted may or may not have finished immediately
// so the finish proc may not have been called. // so the finish proc may not have been called.
@ -80,14 +81,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FlushFinishedProcTest, reporter, ctxInfo) {
} else { } else {
REPORTER_ASSERT(reporter, count == 2); REPORTER_ASSERT(reporter, count == 2);
} }
ctx->flush(); dContext->flush();
ctx->submit(true); dContext->submit(true);
REPORTER_ASSERT(reporter, count == 2); REPORTER_ASSERT(reporter, count == 2);
// Test flushing via the SkImage // Test flushing via the SkImage
canvas->drawImage(image, 0, 0); canvas->drawImage(image, 0, 0);
image->flush(ctx, flushInfoFinishedProc); image->flush(dContext, flushInfoFinishedProc);
ctx->submit(); dContext->submit();
if (expectAsyncCallback) { if (expectAsyncCallback) {
// On Vulkan the command buffer we just submitted may or may not have finished immediately // On Vulkan the command buffer we just submitted may or may not have finished immediately
// so the finish proc may not have been called. // so the finish proc may not have been called.
@ -95,14 +96,14 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FlushFinishedProcTest, reporter, ctxInfo) {
} else { } else {
REPORTER_ASSERT(reporter, count == 3); REPORTER_ASSERT(reporter, count == 3);
} }
ctx->flush(); dContext->flush();
ctx->submit(true); dContext->submit(true);
REPORTER_ASSERT(reporter, count == 3); REPORTER_ASSERT(reporter, count == 3);
// Test flushing via the GrContext // Test flushing via the GrDirectContext
canvas->clear(SK_ColorBLUE); canvas->clear(SK_ColorBLUE);
ctx->flush(flushInfoFinishedProc); dContext->flush(flushInfoFinishedProc);
ctx->submit(); dContext->submit();
if (expectAsyncCallback) { if (expectAsyncCallback) {
// On Vulkan the command buffer we just submitted may or may not have finished immediately // On Vulkan the command buffer we just submitted may or may not have finished immediately
// so the finish proc may not have been called. // so the finish proc may not have been called.
@ -110,30 +111,30 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(FlushFinishedProcTest, reporter, ctxInfo) {
} else { } else {
REPORTER_ASSERT(reporter, count == 4); REPORTER_ASSERT(reporter, count == 4);
} }
ctx->flush(); dContext->flush();
ctx->submit(true); dContext->submit(true);
REPORTER_ASSERT(reporter, count == 4); REPORTER_ASSERT(reporter, count == 4);
// There is no work on the surface so flushing may immediately call the finished proc. // There is no work on the surface so flushing may immediately call the finished proc.
ctx->flush(flushInfoFinishedProc); dContext->flush(flushInfoFinishedProc);
ctx->submit(); dContext->submit();
REPORTER_ASSERT(reporter, count == 4 || count == 5); REPORTER_ASSERT(reporter, count == 4 || count == 5);
busy_wait_for_callback(&count, 5, ctx, reporter); busy_wait_for_callback(&count, 5, dContext, reporter);
count = 0; count = 0;
int count2 = 0; int count2 = 0;
canvas->clear(SK_ColorGREEN); canvas->clear(SK_ColorGREEN);
surface->flush(flushInfoFinishedProc); surface->flush(flushInfoFinishedProc);
ctx->submit(); dContext->submit();
// There is no work to be flushed here so this will return immediately, but make sure the // There is no work to be flushed here so this will return immediately, but make sure the
// finished call from this proc isn't called till the previous surface flush also is finished. // finished call from this proc isn't called till the previous surface flush also is finished.
flushInfoFinishedProc.fFinishedContext = (void*)&count2; flushInfoFinishedProc.fFinishedContext = (void*)&count2;
ctx->flush(flushInfoFinishedProc); dContext->flush(flushInfoFinishedProc);
ctx->submit(); dContext->submit();
REPORTER_ASSERT(reporter, count <= 1 && count2 <= count); REPORTER_ASSERT(reporter, count <= 1 && count2 <= count);
ctx->flush(); dContext->flush();
ctx->submit(true); dContext->submit(true);
REPORTER_ASSERT(reporter, count == 1); REPORTER_ASSERT(reporter, count == 1);
REPORTER_ASSERT(reporter, count == count2); REPORTER_ASSERT(reporter, count == count2);

View File

@ -22,18 +22,18 @@
#include "tools/gpu/GrContextFactory.h" #include "tools/gpu/GrContextFactory.h"
#include "tools/gpu/vk/VkTestHelper.h" #include "tools/gpu/vk/VkTestHelper.h"
static sk_sp<SkSurface> create_protected_sksurface(GrDirectContext* direct, static sk_sp<SkSurface> create_protected_sksurface(GrDirectContext* dContext,
skiatest::Reporter* reporter) { skiatest::Reporter* reporter) {
const int kW = 8; const int kW = 8;
const int kH = 8; const int kH = 8;
GrBackendTexture backendTex = direct->createBackendTexture( GrBackendTexture backendTex = dContext->createBackendTexture(
kW, kH, kRGBA_8888_SkColorType, GrMipMapped::kNo, GrRenderable::kYes, GrProtected::kYes); kW, kH, kRGBA_8888_SkColorType, GrMipMapped::kNo, GrRenderable::kYes, GrProtected::kYes);
REPORTER_ASSERT(reporter, backendTex.isValid()); REPORTER_ASSERT(reporter, backendTex.isValid());
REPORTER_ASSERT(reporter, backendTex.isProtected()); REPORTER_ASSERT(reporter, backendTex.isProtected());
SkSurfaceProps surfaceProps = SkSurfaceProps(0, SkSurfaceProps::kLegacyFontHost_InitType); SkSurfaceProps surfaceProps = SkSurfaceProps(0, SkSurfaceProps::kLegacyFontHost_InitType);
sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture( sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTexture(
direct, backendTex, kTopLeft_GrSurfaceOrigin, 1, dContext, backendTex, kTopLeft_GrSurfaceOrigin, 1,
kRGBA_8888_SkColorType, nullptr, &surfaceProps); kRGBA_8888_SkColorType, nullptr, &surfaceProps);
REPORTER_ASSERT(reporter, surface); REPORTER_ASSERT(reporter, surface);
return surface; return surface;
@ -56,24 +56,26 @@ DEF_GPUTEST(VkProtectedContext_CreateProtectedSkSurface, reporter, options) {
if (!protectedTestHelper->init()) { if (!protectedTestHelper->init()) {
return; return;
} }
REPORTER_ASSERT(reporter, protectedTestHelper->directContext() != nullptr);
auto dContext = protectedTestHelper->directContext();
REPORTER_ASSERT(reporter, dContext != nullptr);
const int kW = 8; const int kW = 8;
const int kH = 8; const int kH = 8;
GrBackendTexture backendTex = GrBackendTexture backendTex = dContext->createBackendTexture(kW, kH, kRGBA_8888_SkColorType,
protectedTestHelper->directContext()->createBackendTexture( GrMipMapped::kNo,
kW, kH, kRGBA_8888_SkColorType, GrMipMapped::kNo, GrRenderable::kNo, GrRenderable::kNo,
GrProtected::kYes); GrProtected::kYes);
REPORTER_ASSERT(reporter, backendTex.isValid()); REPORTER_ASSERT(reporter, backendTex.isValid());
REPORTER_ASSERT(reporter, backendTex.isProtected()); REPORTER_ASSERT(reporter, backendTex.isProtected());
SkSurfaceProps surfaceProps = SkSurfaceProps(0, SkSurfaceProps::kLegacyFontHost_InitType); SkSurfaceProps surfaceProps = SkSurfaceProps(0, SkSurfaceProps::kLegacyFontHost_InitType);
sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTextureAsRenderTarget( sk_sp<SkSurface> surface = SkSurface::MakeFromBackendTextureAsRenderTarget(
protectedTestHelper->directContext(), backendTex, kTopLeft_GrSurfaceOrigin, 1, dContext, backendTex, kTopLeft_GrSurfaceOrigin, 1,
kRGBA_8888_SkColorType, nullptr, &surfaceProps); kRGBA_8888_SkColorType, nullptr, &surfaceProps);
REPORTER_ASSERT(reporter, surface); REPORTER_ASSERT(reporter, surface);
protectedTestHelper->directContext()->deleteBackendTexture(backendTex); dContext->deleteBackendTexture(backendTex);
} }
DEF_GPUTEST(VkProtectedContext_CreateNonprotectedTextureInProtectedContext, reporter, options) { DEF_GPUTEST(VkProtectedContext_CreateNonprotectedTextureInProtectedContext, reporter, options) {
@ -144,11 +146,11 @@ DEF_GPUTEST(VkProtectedContext_AsyncReadFromProtectedSurface, reporter, options)
return; return;
} }
auto direct = protectedTestHelper->directContext(); auto dContext = protectedTestHelper->directContext();
REPORTER_ASSERT(reporter, direct != nullptr); REPORTER_ASSERT(reporter, dContext != nullptr);
auto surface = create_protected_sksurface(direct, reporter); auto surface = create_protected_sksurface(dContext, reporter);
REPORTER_ASSERT(reporter, surface); REPORTER_ASSERT(reporter, surface);
AsyncContext cbContext; AsyncContext cbContext;
const auto image_info = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType, const auto image_info = SkImageInfo::Make(10, 10, kRGBA_8888_SkColorType, kPremul_SkAlphaType,
@ -157,13 +159,13 @@ DEF_GPUTEST(VkProtectedContext_AsyncReadFromProtectedSurface, reporter, options)
image_info.bounds(), image_info.dimensions(), image_info.bounds(), image_info.dimensions(),
SkSurface::RescaleGamma::kSrc, kNone_SkFilterQuality, SkSurface::RescaleGamma::kSrc, kNone_SkFilterQuality,
&async_callback, &cbContext); &async_callback, &cbContext);
direct->submit(); dContext->submit();
while (!cbContext.fCalled) { while (!cbContext.fCalled) {
direct->checkAsyncWorkCompletion(); dContext->checkAsyncWorkCompletion();
} }
REPORTER_ASSERT(reporter, !cbContext.fResult); REPORTER_ASSERT(reporter, !cbContext.fResult);
direct->deleteBackendTexture( dContext->deleteBackendTexture(
surface->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess)); surface->getBackendTexture(SkSurface::kFlushRead_BackendHandleAccess));
} }
@ -338,7 +340,7 @@ DEF_GPUTEST(VkProtectedContext_DrawProtectedImageOnProtectedSurface, reporter, o
////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////
// Test out DDLs using a protected Vulkan context // Test out DDLs using a protected Vulkan context
void DDLMakeRenderTargetTestImpl(GrContext* context, skiatest::Reporter* reporter); void DDLMakeRenderTargetTestImpl(GrDirectContext*, skiatest::Reporter*);
DEF_GPUTEST(VkProtectedContext_DDLMakeRenderTargetTest, reporter, ctxInfo) { DEF_GPUTEST(VkProtectedContext_DDLMakeRenderTargetTest, reporter, ctxInfo) {
auto protectedTestHelper = std::make_unique<VkTestHelper>(true); auto protectedTestHelper = std::make_unique<VkTestHelper>(true);
@ -350,7 +352,7 @@ DEF_GPUTEST(VkProtectedContext_DDLMakeRenderTargetTest, reporter, ctxInfo) {
DDLMakeRenderTargetTestImpl(protectedTestHelper->directContext(), reporter); DDLMakeRenderTargetTestImpl(protectedTestHelper->directContext(), reporter);
} }
void DDLSurfaceCharacterizationTestImpl(GrContext* context, skiatest::Reporter* reporter); void DDLSurfaceCharacterizationTestImpl(GrDirectContext*, skiatest::Reporter*);
DEF_GPUTEST(VkProtectedContext_DDLSurfaceCharacterizationTest, reporter, ctxInfo) { DEF_GPUTEST(VkProtectedContext_DDLSurfaceCharacterizationTest, reporter, ctxInfo) {
auto protectedTestHelper = std::make_unique<VkTestHelper>(true); auto protectedTestHelper = std::make_unique<VkTestHelper>(true);