Flutter Engine
The Flutter Engine
Classes | Enumerations | Functions | Variables
DeferredDisplayListTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSize.h"
#include "include/core/SkSurface.h"
#include "include/core/SkSurfaceProps.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrContextThreadSafeProxy.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/gpu/GrTypes.h"
#include "include/gpu/ganesh/SkImageGanesh.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "include/private/chromium/GrDeferredDisplayList.h"
#include "include/private/chromium/GrDeferredDisplayListRecorder.h"
#include "include/private/chromium/GrPromiseImageTexture.h"
#include "include/private/chromium/GrSurfaceCharacterization.h"
#include "include/private/chromium/SkImageChromium.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrDeferredDisplayListPriv.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
#include "src/gpu/ganesh/GrTextureProxy.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include "tools/gpu/BackendSurfaceFactory.h"
#include "tools/gpu/ManagedBackendTexture.h"
#include "tools/gpu/ProxyUtils.h"
#include <cstddef>
#include <initializer_list>
#include <memory>
#include <utility>

Go to the source code of this file.

Classes

class  SurfaceParameters
 
struct  TextureReleaseChecker
 
struct  FulfillInfo
 

Enumerations

enum class  DDLStage { kMakeImage , kDrawImage , kDetach , kDrawDDL }
 

Functions

static bool is_compatible (const GrSurfaceCharacterization &gsc, const GrBackendTexture &backendTex)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (DDLOperatorEqTest, reporter, ctxInfo, CtsEnforcement::kNever)
 
void DDLSurfaceCharacterizationTestImpl (GrDirectContext *dContext, skiatest::Reporter *reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (DDLSurfaceCharacterizationTest, reporter, ctxInfo, CtsEnforcement::kNever)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (DDLNonTextureabilityTest, reporter, ctxInfo, CtsEnforcement::kNever)
 
static void test_make_render_target (skiatest::Reporter *reporter, GrDirectContext *dContext, const SurfaceParameters &params)
 
void DDLMakeRenderTargetTestImpl (GrDirectContext *dContext, skiatest::Reporter *reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (DDLMakeRenderTargetTest, reporter, ctxInfo, CtsEnforcement::kNever)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (DDLWrapBackendTest, reporter, ctxInfo, CtsEnforcement::kNever)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (DDLInvalidRecorder, reporter, ctxInfo, CtsEnforcement::kNever)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (DDLCreateCharacterizationFailures, reporter, ctxInfo, CtsEnforcement::kNever)
 
static sk_sp< GrPromiseImageTexturetracking_fulfill_proc (void *context)
 
static void tracking_release_proc (void *context)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (DDLSkSurfaceFlush, reporter, ctxInfo, CtsEnforcement::kNever)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (DDLMultipleDDLs, reporter, ctxInfo, CtsEnforcement::kNever)
 
 DEF_GANESH_TEST_FOR_GL_CONTEXT (DDLCompatibilityTest, reporter, ctxInfo, CtsEnforcement::kNever)
 

Variables

static constexpr int kSize = 8
 

Enumeration Type Documentation

◆ DDLStage

enum class DDLStage
strong
Enumerator
kMakeImage 
kDrawImage 
kDetach 
kDrawDDL 

Definition at line 963 of file DeferredDisplayListTest.cpp.

Function Documentation

◆ DDLMakeRenderTargetTestImpl()

void DDLMakeRenderTargetTestImpl ( GrDirectContext dContext,
skiatest::Reporter reporter 
)

Definition at line 910 of file DeferredDisplayListTest.cpp.

910 {
911 for (int i = -1; i < SurfaceParameters::kNumParams; ++i) {
913 // MakeRenderTarget doesn't support FBO0 or vulkan secondary command buffers
914 continue;
915 }
916
917 SurfaceParameters params(dContext);
918 if (i >= 0 && !params.modify(i)) {
919 continue;
920 }
921
923 }
924}
static void test_make_render_target(skiatest::Reporter *reporter, GrDirectContext *dContext, const SurfaceParameters &params)
reporter
Definition: FontMgrTest.cpp:39
const EmbeddedViewParams * params

◆ DDLSurfaceCharacterizationTestImpl()

void DDLSurfaceCharacterizationTestImpl ( GrDirectContext dContext,
skiatest::Reporter reporter 
)

Definition at line 445 of file DeferredDisplayListTest.cpp.

445 {
446 // Create a bitmap that we can readback into
450 bitmap.allocPixels(imageInfo);
451
453
454 // First, create a DDL using the stock SkSurface parameters
455 {
456 SurfaceParameters params(dContext);
457 if (dContext->backend() == GrBackendApi::kVulkan) {
458 params.setVkRTInputAttachmentSupport(true);
459 }
460 ddl = params.createDDL(dContext);
461 SkAssertResult(ddl);
462
463 // The DDL should draw into an SkSurface created with the same parameters
464 sk_sp<SkSurface> s = params.make(dContext);
465 if (!s) {
466 return;
467 }
468
470 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
471
472 dContext->flush();
473 }
474
475 // Then, alter each parameter in turn and check that the DDL & surface are incompatible
476 for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
477 SurfaceParameters params(dContext);
478 if (!params.modify(i)) {
479 continue;
480 }
481
482 sk_sp<SkSurface> s = params.make(dContext);
483 if (!s) {
484 continue;
485 }
486
488 "DDLSurfaceCharacterizationTest failed on parameter: %d\n", i);
489 dContext->flush();
490 }
491
492 // Next test the compatibility of resource cache parameters
493 {
494 const SurfaceParameters params(dContext);
495
496 sk_sp<SkSurface> s = params.make(dContext);
497
498 size_t maxResourceBytes = dContext->getResourceCacheLimit();
499
500 dContext->setResourceCacheLimit(maxResourceBytes/2);
502
503 // DDL TODO: once proxies/ops can be de-instantiated we can re-enable these tests.
504 // For now, DDLs are drawn once.
505#if 0
506 // resource limits >= those at characterization time are accepted
507 context->setResourceCacheLimits(2*maxResourceCount, maxResourceBytes);
509 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
510
511 context->setResourceCacheLimits(maxResourceCount, 2*maxResourceBytes);
513 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
514
515 context->setResourceCacheLimits(maxResourceCount, maxResourceBytes);
517 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
518#endif
519
520 dContext->flush();
521 }
522
523 // Test that the textureability of the DDL characterization can block a DDL draw
524 {
525 SurfaceParameters params(dContext);
526 params.disableTextureability();
527
528 sk_sp<SkSurface> s = params.make(dContext);
529 if (s) {
530 // bc the DDL was made w/ textureability
532
533 dContext->flush();
534 }
535 }
536
537 // Make sure non-GPU-backed surfaces fail characterization
538 {
540
541 sk_sp<SkSurface> rasterSurface = SkSurfaces::Raster(ii);
543 REPORTER_ASSERT(reporter, !rasterSurface->characterize(&c));
544 }
545
546 // Exercise the createResized method
547 {
548 SurfaceParameters params(dContext);
549
550 sk_sp<SkSurface> s = params.make(dContext);
551 if (!s) {
552 return;
553 }
554
556 SkAssertResult(s->characterize(&char0));
557
558 // Too small
559 GrSurfaceCharacterization char1 = char0.createResized(-1, -1);
561
562 // Too large
563 GrSurfaceCharacterization char2 = char0.createResized(1000000, 32);
565
566 // Just right
567 GrSurfaceCharacterization char3 = char0.createResized(32, 32);
569 REPORTER_ASSERT(reporter, 32 == char3.width());
570 REPORTER_ASSERT(reporter, 32 == char3.height());
571 }
572
573 // Exercise the createColorSpace method
574 {
575 SurfaceParameters params(dContext);
576
577 sk_sp<SkSurface> s = params.make(dContext);
578 if (!s) {
579 return;
580 }
581
583 SkAssertResult(s->characterize(&char0));
584
585 // The default params create an sRGB color space
588
589 {
591
592 GrSurfaceCharacterization char1 = char0.createColorSpace(std::move(newCS));
596 }
597
598 {
599 GrSurfaceCharacterization char2 = char0.createColorSpace(nullptr);
602 }
603
604 {
606
608 REPORTER_ASSERT(reporter, !invalid.isValid());
609 GrSurfaceCharacterization stillInvalid = invalid.createColorSpace(std::move(newCS));
610 REPORTER_ASSERT(reporter, !stillInvalid.isValid());
611 }
612 }
613
614 // Exercise the createBackendFormat method
615 {
616 SurfaceParameters params(dContext);
617
618 sk_sp<SkSurface> s = params.make(dContext);
619 if (!s) {
620 return;
621 }
622
624 SkAssertResult(s->characterize(&char0));
625
626 // The default params create a renderable RGBA8 surface
627 auto originalBackendFormat = dContext->defaultBackendFormat(kRGBA_8888_SkColorType,
629 REPORTER_ASSERT(reporter, originalBackendFormat.isValid());
630 REPORTER_ASSERT(reporter, char0.backendFormat() == originalBackendFormat);
631
632 auto newBackendFormat = dContext->defaultBackendFormat(kRGB_565_SkColorType,
634
635 if (newBackendFormat.isValid()) {
637 newBackendFormat);
639 REPORTER_ASSERT(reporter, char1.backendFormat() == newBackendFormat);
640
642 REPORTER_ASSERT(reporter, !invalid.isValid());
643 auto stillInvalid = invalid.createBackendFormat(kRGB_565_SkColorType,
644 newBackendFormat);
645 REPORTER_ASSERT(reporter, !stillInvalid.isValid());
646 }
647 }
648
649 // Exercise the createFBO0 method
650 if (dContext->backend() == GrBackendApi::kOpenGL) {
651 SurfaceParameters params(dContext);
652 // If the original characterization is textureable then we will fail trying to make an
653 // FBO0 characterization
654 params.disableTextureability();
655
656 sk_sp<SkSurface> s = params.make(dContext);
657 if (!s) {
658 return;
659 }
660
662 SkAssertResult(s->characterize(&char0));
663
664 // The default params create a non-FBO0 surface
665 REPORTER_ASSERT(reporter, !char0.usesGLFBO0());
666
667 {
668 GrSurfaceCharacterization char1 = char0.createFBO0(true);
670 REPORTER_ASSERT(reporter, char1.usesGLFBO0());
671 }
672
673 {
675 REPORTER_ASSERT(reporter, !invalid.isValid());
676 GrSurfaceCharacterization stillInvalid = invalid.createFBO0(true);
677 REPORTER_ASSERT(reporter, !stillInvalid.isValid());
678 }
679 }
680}
static bool invalid(const SkISize &size)
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
@ kOpaque_SkAlphaType
pixel is opaque
Definition: SkAlphaType.h:28
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition: SkColorType.h:22
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
SK_API GrBackendApi backend() const
SK_API GrBackendFormat defaultBackendFormat(SkColorType, GrRenderable) const
size_t getResourceCacheLimit() const
GrSemaphoresSubmitted flush(const GrFlushInfo &info)
void setResourceCacheLimit(size_t maxResourceBytes)
GrSurfaceCharacterization createColorSpace(sk_sp< SkColorSpace >) const
GrSurfaceCharacterization createFBO0(bool usesGLFBO0) const
GrSurfaceCharacterization createResized(int width, int height) const
GrSurfaceCharacterization createBackendFormat(SkColorType colorType, const GrBackendFormat &backendFormat) const
bool gammaIsLinear() const
bool isSRGB() const
static sk_sp< SkColorSpace > MakeSRGBLinear()
bool characterize(GrSurfaceCharacterization *characterization) const
Definition: SkSurface.cpp:239
struct MyStruct s
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
Definition: bitmap.py:1
SK_API bool DrawDDL(SkSurface *, sk_sp< const GrDeferredDisplayList > ddl)
static SkImageInfo MakeN32(int width, int height, SkAlphaType at)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ DEF_GANESH_TEST_FOR_GL_CONTEXT()

DEF_GANESH_TEST_FOR_GL_CONTEXT ( DDLCompatibilityTest  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 1376 of file DeferredDisplayListTest.cpp.

1376 {
1377 auto context = ctxInfo.directContext();
1378
1379 for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) {
1380 SkColorType colorType = static_cast<SkColorType>(ct);
1381
1382 SurfaceParameters params(context);
1383 params.setColorType(colorType);
1384 params.setColorSpace(nullptr);
1385
1387 }
1388}
SkColorType
Definition: SkColorType.h:19
@ kLastEnum_SkColorType
last valid value
Definition: SkColorType.h:56
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [1/9]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( DDLCreateCharacterizationFailures  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 1048 of file DeferredDisplayListTest.cpp.

1051 {
1052 using namespace skgpu;
1053
1054 auto dContext = ctxInfo.directContext();
1055 size_t maxResourceBytes = dContext->getResourceCacheLimit();
1056 auto proxy = dContext->threadSafeProxy().get();
1057
1058 Protected isProtected = Protected(dContext->priv().caps()->supportsProtectedContent());
1059
1060 auto check_create_fails = [proxy, reporter, maxResourceBytes](
1061 const GrBackendFormat& backendFormat,
1062 int width,
1063 int height,
1064 SkColorType ct,
1065 bool willUseGLFBO0,
1066 bool isTextureable,
1067 Protected prot,
1068 bool vkRTSupportsInputAttachment,
1069 bool forVulkanSecondaryCommandBuffer) {
1070 const SkSurfaceProps surfaceProps(0x0, kRGB_H_SkPixelGeometry);
1071
1073 kPremul_SkAlphaType, nullptr);
1074
1076 proxy->createCharacterization(maxResourceBytes,
1077 ii,
1078 backendFormat,
1079 1,
1081 surfaceProps,
1083 willUseGLFBO0,
1084 isTextureable,
1085 prot,
1086 vkRTSupportsInputAttachment,
1087 forVulkanSecondaryCommandBuffer);
1089 };
1090
1091 GrBackendFormat goodBackendFormat = dContext->defaultBackendFormat(kRGBA_8888_SkColorType,
1093 SkASSERT(goodBackendFormat.isValid());
1094
1095 GrBackendFormat badBackendFormat;
1096 SkASSERT(!badBackendFormat.isValid());
1097
1100
1101 static const bool kIsTextureable = true;
1102 static const bool kIsNotTextureable = false;
1103
1104 static const bool kGoodUseFBO0 = false;
1105 static const bool kBadUseFBO0 = true;
1106
1107 static const bool kGoodVkInputAttachment = false;
1108 static const bool kBadVkInputAttachment = true;
1109
1110 static const bool kGoodForVkSCB = false;
1111 static const bool kBadForVkSCB = true;
1112
1113 int goodWidth = 64;
1114 int goodHeight = 64;
1115 int badWidths[] = { 0, 1048576 };
1116 int badHeights[] = { 0, 1048576 };
1117
1118
1119 // In each of the check_create_fails calls there is one bad parameter that should cause the
1120 // creation of the characterization to fail.
1121 check_create_fails(goodBackendFormat, goodWidth, badHeights[0], kGoodCT, kGoodUseFBO0,
1122 kIsTextureable, isProtected, kGoodVkInputAttachment, kGoodForVkSCB);
1123 check_create_fails(goodBackendFormat, goodWidth, badHeights[1], kGoodCT, kGoodUseFBO0,
1124 kIsTextureable, isProtected, kGoodVkInputAttachment, kGoodForVkSCB);
1125 check_create_fails(goodBackendFormat, badWidths[0], goodHeight, kGoodCT, kGoodUseFBO0,
1126 kIsTextureable, isProtected, kGoodVkInputAttachment, kGoodForVkSCB);
1127 check_create_fails(goodBackendFormat, badWidths[1], goodHeight, kGoodCT, kGoodUseFBO0,
1128 kIsTextureable, isProtected, kGoodVkInputAttachment, kGoodForVkSCB);
1129 check_create_fails(badBackendFormat, goodWidth, goodHeight, kGoodCT, kGoodUseFBO0,
1130 kIsTextureable, isProtected, kGoodVkInputAttachment, kGoodForVkSCB);
1131 check_create_fails(goodBackendFormat, goodWidth, goodHeight, kBadCT, kGoodUseFBO0,
1132 kIsTextureable, isProtected, kGoodVkInputAttachment, kGoodForVkSCB);
1133 // This fails because we always try to make a characterization that is textureable and we can't
1134 // have UseFBO0 be true and textureable.
1135 check_create_fails(goodBackendFormat, goodWidth, goodHeight, kGoodCT, kBadUseFBO0,
1136 kIsTextureable, isProtected, kGoodVkInputAttachment, kGoodForVkSCB);
1137 if (dContext->backend() == GrBackendApi::kVulkan) {
1138 // The following fails because forVulkanSecondaryCommandBuffer is true and
1139 // isTextureable is true. This is not a legal combination.
1140 check_create_fails(goodBackendFormat, goodWidth, goodHeight, kGoodCT, kGoodUseFBO0,
1141 kIsTextureable, isProtected, kGoodVkInputAttachment, kBadForVkSCB);
1142 // The following fails because forVulkanSecondaryCommandBuffer is true and
1143 // vkRTSupportsInputAttachment is true. This is not a legal combination.
1144 check_create_fails(goodBackendFormat, goodWidth, goodHeight, kGoodCT, kGoodUseFBO0,
1145 kIsNotTextureable, isProtected, kBadVkInputAttachment,
1146 kBadForVkSCB);
1147 // The following fails because forVulkanSecondaryCommandBuffer is true and
1148 // willUseGLFBO0 is true. This is not a legal combination.
1149 check_create_fails(goodBackendFormat, goodWidth, goodHeight, kGoodCT, kBadUseFBO0,
1150 kIsNotTextureable, isProtected, kGoodVkInputAttachment,
1151 kBadForVkSCB);
1152 } else {
1153 // The following set vulkan only flags on non vulkan backends.
1154 check_create_fails(goodBackendFormat, goodWidth, goodHeight, kGoodCT, kGoodUseFBO0,
1155 kIsTextureable, isProtected, kBadVkInputAttachment, kGoodForVkSCB);
1156 check_create_fails(goodBackendFormat, goodWidth, goodHeight, kGoodCT, kGoodUseFBO0,
1157 kIsNotTextureable, isProtected, kGoodVkInputAttachment,
1158 kBadForVkSCB);
1159 }
1160}
@ kBottomLeft_GrSurfaceOrigin
Definition: GrTypes.h:149
skgpu::Protected Protected
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kUnknown_SkColorType
uninitialized
Definition: SkColorType.h:20
@ kRGB_H_SkPixelGeometry
bool isValid() const
Definition: GpuTools.h:21
Protected
Definition: GpuTypes.h:61
int32_t height
int32_t width

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [2/9]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( DDLInvalidRecorder  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 1019 of file DeferredDisplayListTest.cpp.

1022 {
1023 auto dContext = ctxInfo.directContext();
1024
1025 {
1028
1029 GrSurfaceCharacterization characterization;
1030 SkAssertResult(s->characterize(&characterization));
1031
1032 // never calling getCanvas means the backing surface is never allocated
1033 GrDeferredDisplayListRecorder recorder(characterization);
1034 }
1035
1036 {
1038
1040
1041 const GrSurfaceCharacterization c = recorder.characterization();
1043 REPORTER_ASSERT(reporter, !recorder.getCanvas());
1044 REPORTER_ASSERT(reporter, !recorder.detach());
1045 }
1046}
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
static SkImageInfo MakeN32Premul(int width, int height)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [3/9]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( DDLMakeRenderTargetTest  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 926 of file DeferredDisplayListTest.cpp.

929 {
930 auto context = ctxInfo.directContext();
931
933}
void DDLMakeRenderTargetTestImpl(GrDirectContext *dContext, skiatest::Reporter *reporter)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [4/9]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( DDLMultipleDDLs  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 1261 of file DeferredDisplayListTest.cpp.

1261 {
1262 auto context = ctxInfo.directContext();
1263
1266
1268 bitmap.allocPixels(ii);
1269
1270 GrSurfaceCharacterization characterization;
1271 SkAssertResult(s->characterize(&characterization));
1272
1273 GrDeferredDisplayListRecorder recorder(characterization);
1274
1275 SkCanvas* canvas1 = recorder.getCanvas();
1276
1277 canvas1->clear(SK_ColorRED);
1278
1279 canvas1->save();
1280 canvas1->clipRect(SkRect::MakeXYWH(8, 8, 16, 16));
1281
1282 sk_sp<GrDeferredDisplayList> ddl1 = recorder.detach();
1283
1284 SkCanvas* canvas2 = recorder.getCanvas();
1285
1286 SkPaint p;
1287 p.setColor(SK_ColorGREEN);
1288 canvas2->drawRect(SkRect::MakeWH(32, 32), p);
1289
1290 sk_sp<GrDeferredDisplayList> ddl2 = recorder.detach();
1291
1294
1295 // The lazy proxy data being different ensures that the SkSurface, SkCanvas and backing-
1296 // lazy proxy are all different between the two DDLs
1298
1301
1302 // Make sure the clipRect from DDL1 didn't percolate into DDL2
1303 s->readPixels(ii, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
1304 for (int y = 0; y < 32; ++y) {
1305 for (int x = 0; x < 32; ++x) {
1307 if (bitmap.getColor(x, y) != SK_ColorGREEN) {
1308 return; // we only really need to report the error once
1309 }
1310 }
1311 }
1312}
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
const GrDeferredDisplayList::LazyProxyData * lazyProxyData() const
GrDeferredDisplayListPriv priv()
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
Definition: SkCanvas.cpp:1361
void clear(SkColor color)
Definition: SkCanvas.h:1199
int save()
Definition: SkCanvas.cpp:447
double y
double x
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [5/9]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( DDLNonTextureabilityTest  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 816 of file DeferredDisplayListTest.cpp.

819 {
820 auto context = ctxInfo.directContext();
821
822 // Create a bitmap that we can readback into
826 bitmap.allocPixels(imageInfo);
827
828 for (bool textureability : { true, false }) {
830
831 // First, create a DDL w/o textureability (and thus no mipmaps). TODO: once we have
832 // reusable DDLs, move this outside of the loop.
833 {
834 SurfaceParameters params(context);
835 params.disableTextureability();
836 if (context->backend() == GrBackendApi::kVulkan) {
837 params.setVkRTInputAttachmentSupport(true);
838 }
839
840 ddl = params.createDDL(context);
841 SkAssertResult(ddl);
842 }
843
844 // Then verify it can draw into either flavor of destination
845 SurfaceParameters params(context);
846 if (!textureability) {
847 params.disableTextureability();
848 }
849 if (context->backend() == GrBackendApi::kVulkan) {
850 params.setVkRTInputAttachmentSupport(true);
851 }
852
853 sk_sp<SkSurface> s = params.make(context);
854 if (!s) {
855 continue;
856 }
857
859 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
860
861 context->flush();
862 }
863}

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [6/9]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( DDLOperatorEqTest  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 396 of file DeferredDisplayListTest.cpp.

399 {
400 auto context = ctxInfo.directContext();
401
402 for (int i = -1; i < SurfaceParameters::kNumParams; ++i) {
403 SurfaceParameters params1(context);
404 bool didModify1 = i >= 0 && params1.modify(i);
405
406 GrSurfaceCharacterization char1 = params1.createCharacterization(context);
407 if (!char1.isValid()) {
408 continue; // can happen on some platforms (ChromeOS)
409 }
410
411 for (int j = -1; j < SurfaceParameters::kNumParams; ++j) {
412 SurfaceParameters params2(context);
413 bool didModify2 = j >= 0 && params2.modify(j);
414
415 GrSurfaceCharacterization char2 = params2.createCharacterization(context);
416 if (!char2.isValid()) {
417 continue; // can happen on some platforms (ChromeOS)
418 }
419
420 if (i == j || (!didModify1 && !didModify2)) {
421 REPORTER_ASSERT(reporter, char1 == char2);
422 } else {
423 REPORTER_ASSERT(reporter, char1 != char2);
424 }
425 }
426 }
427
428 {
429 SurfaceParameters params(context);
430
431 GrSurfaceCharacterization valid = params.createCharacterization(context);
432 SkASSERT(valid.isValid());
433
434 GrSurfaceCharacterization inval1, inval2;
435 SkASSERT(!inval1.isValid() && !inval2.isValid());
436
437 REPORTER_ASSERT(reporter, inval1 != inval2);
438 REPORTER_ASSERT(reporter, valid != inval1);
439 REPORTER_ASSERT(reporter, inval1 != valid);
440 }
441}

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [7/9]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( DDLSkSurfaceFlush  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 1182 of file DeferredDisplayListTest.cpp.

1185 {
1186 using namespace skgpu;
1187
1188 auto context = ctxInfo.directContext();
1189
1190 Protected isProtected = Protected(context->priv().caps()->supportsProtectedContent());
1191
1193 sk_sp<SkSurface> s = SkSurfaces::RenderTarget(context, Budgeted::kNo, ii);
1194
1195 GrSurfaceCharacterization characterization;
1196 SkAssertResult(s->characterize(&characterization));
1197
1198 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(context, ii,
1201 isProtected);
1202 if (!mbet) {
1203 ERRORF(reporter, "Could not make texture.");
1204 return;
1205 }
1206
1207 FulfillInfo fulfillInfo;
1208 fulfillInfo.fTex = GrPromiseImageTexture::Make(mbet->texture());
1209
1211
1212 {
1213 GrDeferredDisplayListRecorder recorder(characterization);
1214
1215 GrBackendFormat format = context->defaultBackendFormat(kRGBA_8888_SkColorType,
1217 SkASSERT(format.isValid());
1218
1219 SkCanvas* canvas = recorder.getCanvas();
1220
1221 sk_sp<SkImage> promiseImage =
1223 format,
1224 SkISize::Make(32, 32),
1229 nullptr,
1232 &fulfillInfo);
1233
1234 canvas->clear(SK_ColorRED);
1235 canvas->drawImage(promiseImage, 0, 0);
1236 ddl = recorder.detach();
1237 }
1238
1239 context->flushAndSubmit();
1240
1242
1243 GrFlushInfo flushInfo;
1244 context->flush(s.get(), SkSurfaces::BackendSurfaceAccess::kPresent, flushInfo);
1245 context->submit(GrSyncCpu::kNo);
1246
1247 REPORTER_ASSERT(reporter, fulfillInfo.fFulfilled);
1248
1249 // In order to receive the done callback with the low-level APIs we need to re-flush
1250 context->flush(s.get());
1251 context->submit(GrSyncCpu::kYes);
1252
1253 REPORTER_ASSERT(reporter, fulfillInfo.fReleased);
1254
1255 REPORTER_ASSERT(reporter, fulfillInfo.fTex->unique());
1256 fulfillInfo.fTex.reset();
1257}
static sk_sp< GrPromiseImageTexture > tracking_fulfill_proc(void *context)
static void tracking_release_proc(void *context)
@ kTopLeft_GrSurfaceOrigin
Definition: GrTypes.h:148
#define ERRORF(r,...)
Definition: Test.h:293
sk_sp< GrContextThreadSafeProxy > threadSafeProxy()
static sk_sp< GrPromiseImageTexture > Make(const GrBackendTexture &backendTexture)
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
bool unique() const
Definition: SkRefCnt.h:175
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310
uint32_t uint32_t * format
SK_API sk_sp< SkImage > PromiseTextureFrom(skgpu::graphite::Recorder *, SkISize dimensions, const skgpu::graphite::TextureInfo &, const SkColorInfo &, skgpu::Origin origin, skgpu::graphite::Volatile, GraphitePromiseTextureFulfillProc, GraphitePromiseImageReleaseProc, GraphitePromiseTextureReleaseProc, GraphitePromiseImageContext, std::string_view label={})
@ kPresent
back-end surface will be used for presenting to screen
sk_sp< GrPromiseImageTexture > fTex
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [8/9]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( DDLSurfaceCharacterizationTest  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 786 of file DeferredDisplayListTest.cpp.

789 {
790 auto context = ctxInfo.directContext();
791
793}
void DDLSurfaceCharacterizationTestImpl(GrDirectContext *dContext, skiatest::Reporter *reporter)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [9/9]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( DDLWrapBackendTest  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 966 of file DeferredDisplayListTest.cpp.

969 {
970 auto dContext = ctxInfo.directContext();
971
972 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(dContext,
973 kSize,
974 kSize,
979 if (!mbet) {
980 return;
981 }
982
983 SurfaceParameters params(dContext);
984
985 sk_sp<SkSurface> s = params.make(dContext);
986 if (!s) {
987 return;
988 }
989
991 SkAssertResult(s->characterize(&c));
992
994
995 SkCanvas* canvas = recorder.getCanvas();
996 SkASSERT(canvas);
997
998 auto rContext = canvas->recordingContext();
999 if (!rContext) {
1000 return;
1001 }
1002
1003 // Wrapped Backend Textures are not supported in DDL
1004 TextureReleaseChecker releaseChecker;
1006 rContext,
1007 mbet->texture(),
1011 nullptr,
1012 sk_gpu_test::ManagedBackendTexture::ReleaseProc,
1013 mbet->releaseContext(TextureReleaseChecker::Release, &releaseChecker));
1015}
static constexpr int kSize
SK_API sk_sp< SkImage > BorrowTextureFrom(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)
sk_sp< const SkImage > image
Definition: SkRecords.h:269
static void Release(void *self)

◆ is_compatible()

static bool is_compatible ( const GrSurfaceCharacterization gsc,
const GrBackendTexture backendTex 
)
static

Definition at line 69 of file DeferredDisplayListTest.cpp.

69 {
70 if (!gsc.isValid() || !backendTex.isValid()) {
71 return false;
72 }
73
74 if (gsc.backendFormat() != backendTex.getBackendFormat()) {
75 return false;
76 }
77
78 if (gsc.usesGLFBO0()) {
79 // It is a backend texture so can't be wrapping FBO0
80 return false;
81 }
82
83 if (gsc.vulkanSecondaryCBCompatible()) {
84 return false;
85 }
86
87 if (gsc.vkRTSupportsInputAttachment()) {
88 if (backendTex.backend() != GrBackendApi::kVulkan) {
89 return false;
90 }
91#ifdef SK_VULKAN
92 GrVkImageInfo vkInfo;
93 if (!GrBackendTextures::GetVkImageInfo(backendTex, &vkInfo)) {
94 return false;
95 }
97 return false;
98 }
99#endif // SK_VULKAN
100 }
101
102 if (gsc.isMipMapped() && !backendTex.hasMipmaps()) {
103 // backend texture is allowed to have mipmaps even if the characterization doesn't require
104 // them.
105 return false;
106 }
107
108 if (gsc.width() != backendTex.width() || gsc.height() != backendTex.height()) {
109 return false;
110 }
111
112 if (gsc.isProtected() != skgpu::Protected(backendTex.isProtected())) {
113 return false;
114 }
115
116 return true;
117}
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35
GrBackendFormat getBackendFormat() const
bool hasMipmaps() const
bool isValid() const
bool isProtected() const
GrBackendApi backend() const
SK_API bool GetVkImageInfo(const GrBackendTexture &, GrVkImageInfo *)
VkImageUsageFlags fImageUsageFlags
Definition: GrVkTypes.h:31
@ VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT
Definition: vulkan_core.h:2359

◆ test_make_render_target()

static void test_make_render_target ( skiatest::Reporter reporter,
GrDirectContext dContext,
const SurfaceParameters params 
)
static

Definition at line 865 of file DeferredDisplayListTest.cpp.

867 {
868 {
869 const GrSurfaceCharacterization c = params.createCharacterization(dContext);
870
871 if (!c.isValid()) {
872 sk_sp<SkSurface> tmp = params.make(dContext);
873 // If we couldn't characterize the surface we shouldn't be able to create it either
875 return;
876 }
877 }
878
879 const GrSurfaceCharacterization c = params.createCharacterization(dContext);
880 {
881 sk_sp<SkSurface> s = params.make(dContext);
883 if (!s) {
885 return;
886 }
887
891 if (backend.isValid()) {
893 }
894 REPORTER_ASSERT(reporter, s->isCompatible(c));
895 // Note that we're leaving 'backend' live here
896 }
897
898 // Make an SkSurface from scratch
899 {
902 REPORTER_ASSERT(reporter, s->isCompatible(c));
903 }
904}
const char * backend
static bool is_compatible(const GrSurfaceCharacterization &gsc, const GrBackendTexture &backendTex)
@ kFlushRead
back-end object is readable
SK_API GrBackendTexture GetBackendTexture(SkSurface *, BackendHandleAccess)

◆ tracking_fulfill_proc()

static sk_sp< GrPromiseImageTexture > tracking_fulfill_proc ( void *  context)
static

Definition at line 1171 of file DeferredDisplayListTest.cpp.

1171 {
1172 FulfillInfo* info = (FulfillInfo*) context;
1173 info->fFulfilled = true;
1174 return info->fTex;
1175}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213

◆ tracking_release_proc()

static void tracking_release_proc ( void *  context)
static

Definition at line 1177 of file DeferredDisplayListTest.cpp.

1177 {
1178 FulfillInfo* info = (FulfillInfo*) context;
1179 info->fReleased = true;
1180}

Variable Documentation

◆ kSize

constexpr int kSize = 8
staticconstexpr

Definition at line 953 of file DeferredDisplayListTest.cpp.