Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 967 of file DeferredDisplayListTest.cpp.

Function Documentation

◆ DDLMakeRenderTargetTestImpl()

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

Definition at line 914 of file DeferredDisplayListTest.cpp.

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

◆ DDLSurfaceCharacterizationTestImpl()

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

Definition at line 449 of file DeferredDisplayListTest.cpp.

449 {
450 // Create a bitmap that we can readback into
454 bitmap.allocPixels(imageInfo);
455
457
458 // First, create a DDL using the stock SkSurface parameters
459 {
460 SurfaceParameters params(dContext);
461 if (dContext->backend() == GrBackendApi::kVulkan) {
462 params.setVkRTInputAttachmentSupport(true);
463 }
464 ddl = params.createDDL(dContext);
465 SkAssertResult(ddl);
466
467 // The DDL should draw into an SkSurface created with the same parameters
468 sk_sp<SkSurface> s = params.make(dContext);
469 if (!s) {
470 return;
471 }
472
474 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
475
476 dContext->flush();
477 }
478
479 // Then, alter each parameter in turn and check that the DDL & surface are incompatible
480 for (int i = 0; i < SurfaceParameters::kNumParams; ++i) {
481 SurfaceParameters params(dContext);
482 if (!params.modify(i)) {
483 continue;
484 }
485
486 sk_sp<SkSurface> s = params.make(dContext);
487 if (!s) {
488 continue;
489 }
490
492 "DDLSurfaceCharacterizationTest failed on parameter: %d\n", i);
493 dContext->flush();
494 }
495
496 // Next test the compatibility of resource cache parameters
497 {
498 const SurfaceParameters params(dContext);
499
500 sk_sp<SkSurface> s = params.make(dContext);
501
502 size_t maxResourceBytes = dContext->getResourceCacheLimit();
503
504 dContext->setResourceCacheLimit(maxResourceBytes/2);
506
507 // DDL TODO: once proxies/ops can be de-instantiated we can re-enable these tests.
508 // For now, DDLs are drawn once.
509#if 0
510 // resource limits >= those at characterization time are accepted
511 context->setResourceCacheLimits(2*maxResourceCount, maxResourceBytes);
513 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
514
515 context->setResourceCacheLimits(maxResourceCount, 2*maxResourceBytes);
517 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
518
519 context->setResourceCacheLimits(maxResourceCount, maxResourceBytes);
521 s->readPixels(imageInfo, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
522#endif
523
524 dContext->flush();
525 }
526
527 // Test that the textureability of the DDL characterization can block a DDL draw
528 {
529 SurfaceParameters params(dContext);
530 params.disableTextureability();
531
532 sk_sp<SkSurface> s = params.make(dContext);
533 if (s) {
534 // bc the DDL was made w/ textureability
536
537 dContext->flush();
538 }
539 }
540
541 // Make sure non-GPU-backed surfaces fail characterization
542 {
544
545 sk_sp<SkSurface> rasterSurface = SkSurfaces::Raster(ii);
547 REPORTER_ASSERT(reporter, !rasterSurface->characterize(&c));
548 }
549
550 // Exercise the createResized method
551 {
552 SurfaceParameters params(dContext);
553
554 sk_sp<SkSurface> s = params.make(dContext);
555 if (!s) {
556 return;
557 }
558
560 SkAssertResult(s->characterize(&char0));
561
562 // Too small
563 GrSurfaceCharacterization char1 = char0.createResized(-1, -1);
565
566 // Too large
567 GrSurfaceCharacterization char2 = char0.createResized(1000000, 32);
569
570 // Just right
571 GrSurfaceCharacterization char3 = char0.createResized(32, 32);
573 REPORTER_ASSERT(reporter, 32 == char3.width());
574 REPORTER_ASSERT(reporter, 32 == char3.height());
575 }
576
577 // Exercise the createColorSpace method
578 {
579 SurfaceParameters params(dContext);
580
581 sk_sp<SkSurface> s = params.make(dContext);
582 if (!s) {
583 return;
584 }
585
587 SkAssertResult(s->characterize(&char0));
588
589 // The default params create an sRGB color space
592
593 {
595
596 GrSurfaceCharacterization char1 = char0.createColorSpace(std::move(newCS));
600 }
601
602 {
603 GrSurfaceCharacterization char2 = char0.createColorSpace(nullptr);
606 }
607
608 {
610
612 REPORTER_ASSERT(reporter, !invalid.isValid());
613 GrSurfaceCharacterization stillInvalid = invalid.createColorSpace(std::move(newCS));
614 REPORTER_ASSERT(reporter, !stillInvalid.isValid());
615 }
616 }
617
618 // Exercise the createBackendFormat method
619 {
620 SurfaceParameters params(dContext);
621
622 sk_sp<SkSurface> s = params.make(dContext);
623 if (!s) {
624 return;
625 }
626
628 SkAssertResult(s->characterize(&char0));
629
630 // The default params create a renderable RGBA8 surface
631 auto originalBackendFormat = dContext->defaultBackendFormat(kRGBA_8888_SkColorType,
632 GrRenderable::kYes);
633 REPORTER_ASSERT(reporter, originalBackendFormat.isValid());
634 REPORTER_ASSERT(reporter, char0.backendFormat() == originalBackendFormat);
635
636 auto newBackendFormat = dContext->defaultBackendFormat(kRGB_565_SkColorType,
637 GrRenderable::kYes);
638
639 if (newBackendFormat.isValid()) {
641 newBackendFormat);
643 REPORTER_ASSERT(reporter, char1.backendFormat() == newBackendFormat);
644
646 REPORTER_ASSERT(reporter, !invalid.isValid());
648 newBackendFormat);
649 REPORTER_ASSERT(reporter, !stillInvalid.isValid());
650 }
651 }
652
653 // Exercise the createFBO0 method
654 if (dContext->backend() == GrBackendApi::kOpenGL) {
655 SurfaceParameters params(dContext);
656 // If the original characterization is textureable then we will fail trying to make an
657 // FBO0 characterization
658 params.disableTextureability();
659
660 sk_sp<SkSurface> s = params.make(dContext);
661 if (!s) {
662 return;
663 }
664
666 SkAssertResult(s->characterize(&char0));
667
668 // The default params create a non-FBO0 surface
669 REPORTER_ASSERT(reporter, !char0.usesGLFBO0());
670
671 {
672 GrSurfaceCharacterization char1 = char0.createFBO0(true);
674 REPORTER_ASSERT(reporter, char1.usesGLFBO0());
675 }
676
677 {
679 REPORTER_ASSERT(reporter, !invalid.isValid());
680 GrSurfaceCharacterization stillInvalid = invalid.createFBO0(true);
681 REPORTER_ASSERT(reporter, !stillInvalid.isValid());
682 }
683 }
684}
static bool invalid(const SkISize &size)
@ kOpaque_SkAlphaType
pixel is opaque
Definition SkAlphaType.h:28
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define SkAssertResult(cond)
Definition SkAssert.h:123
@ 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()
struct MyStruct s
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
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 1380 of file DeferredDisplayListTest.cpp.

1380 {
1381 auto context = ctxInfo.directContext();
1382
1383 for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) {
1384 SkColorType colorType = static_cast<SkColorType>(ct);
1385
1386 SurfaceParameters params(context);
1387 params.setColorType(colorType);
1388 params.setColorSpace(nullptr);
1389
1391 }
1392}
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 1052 of file DeferredDisplayListTest.cpp.

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

1026 {
1027 auto dContext = ctxInfo.directContext();
1028
1029 {
1032
1033 GrSurfaceCharacterization characterization;
1034 SkAssertResult(s->characterize(&characterization));
1035
1036 // never calling getCanvas means the backing surface is never allocated
1037 GrDeferredDisplayListRecorder recorder(characterization);
1038 }
1039
1040 {
1042
1044
1045 const GrSurfaceCharacterization c = recorder.characterization();
1047 REPORTER_ASSERT(reporter, !recorder.getCanvas());
1048 REPORTER_ASSERT(reporter, !recorder.detach());
1049 }
1050}
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 930 of file DeferredDisplayListTest.cpp.

933 {
934 auto context = ctxInfo.directContext();
935
937}
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 1265 of file DeferredDisplayListTest.cpp.

1265 {
1266 auto context = ctxInfo.directContext();
1267
1270
1272 bitmap.allocPixels(ii);
1273
1274 GrSurfaceCharacterization characterization;
1275 SkAssertResult(s->characterize(&characterization));
1276
1277 GrDeferredDisplayListRecorder recorder(characterization);
1278
1279 SkCanvas* canvas1 = recorder.getCanvas();
1280
1281 canvas1->clear(SK_ColorRED);
1282
1283 canvas1->save();
1284 canvas1->clipRect(SkRect::MakeXYWH(8, 8, 16, 16));
1285
1286 sk_sp<GrDeferredDisplayList> ddl1 = recorder.detach();
1287
1288 SkCanvas* canvas2 = recorder.getCanvas();
1289
1290 SkPaint p;
1291 p.setColor(SK_ColorGREEN);
1292 canvas2->drawRect(SkRect::MakeWH(32, 32), p);
1293
1294 sk_sp<GrDeferredDisplayList> ddl2 = recorder.detach();
1295
1296 REPORTER_ASSERT(reporter, ddl1->priv().lazyProxyData());
1297 REPORTER_ASSERT(reporter, ddl2->priv().lazyProxyData());
1298
1299 // The lazy proxy data being different ensures that the SkSurface, SkCanvas and backing-
1300 // lazy proxy are all different between the two DDLs
1301 REPORTER_ASSERT(reporter, ddl1->priv().lazyProxyData() != ddl2->priv().lazyProxyData());
1302
1305
1306 // Make sure the clipRect from DDL1 didn't percolate into DDL2
1307 s->readPixels(ii, bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
1308 for (int y = 0; y < 32; ++y) {
1309 for (int x = 0; x < 32; ++x) {
1311 if (bitmap.getColor(x, y) != SK_ColorGREEN) {
1312 return; // we only really need to report the error once
1313 }
1314 }
1315 }
1316}
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
void drawRect(const SkRect &rect, const SkPaint &paint)
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void clear(SkColor color)
Definition SkCanvas.h:1199
int save()
Definition SkCanvas.cpp:451
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 820 of file DeferredDisplayListTest.cpp.

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

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [6/9]

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

Definition at line 400 of file DeferredDisplayListTest.cpp.

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

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [7/9]

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

Definition at line 1186 of file DeferredDisplayListTest.cpp.

1189 {
1190 using namespace skgpu;
1191
1192 auto context = ctxInfo.directContext();
1193
1194 Protected isProtected = Protected(context->priv().caps()->supportsProtectedContent());
1195
1197 sk_sp<SkSurface> s = SkSurfaces::RenderTarget(context, Budgeted::kNo, ii);
1198
1199 GrSurfaceCharacterization characterization;
1200 SkAssertResult(s->characterize(&characterization));
1201
1202 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeFromInfo(context, ii,
1203 Mipmapped::kNo,
1204 Renderable::kNo,
1205 isProtected);
1206 if (!mbet) {
1207 ERRORF(reporter, "Could not make texture.");
1208 return;
1209 }
1210
1211 FulfillInfo fulfillInfo;
1212 fulfillInfo.fTex = GrPromiseImageTexture::Make(mbet->texture());
1213
1215
1216 {
1217 GrDeferredDisplayListRecorder recorder(characterization);
1218
1219 GrBackendFormat format = context->defaultBackendFormat(kRGBA_8888_SkColorType,
1220 GrRenderable::kNo);
1221 SkASSERT(format.isValid());
1222
1223 SkCanvas* canvas = recorder.getCanvas();
1224
1225 sk_sp<SkImage> promiseImage =
1227 format,
1228 SkISize::Make(32, 32),
1229 skgpu::Mipmapped::kNo,
1233 nullptr,
1236 &fulfillInfo);
1237
1238 canvas->clear(SK_ColorRED);
1239 canvas->drawImage(promiseImage, 0, 0);
1240 ddl = recorder.detach();
1241 }
1242
1243 context->flushAndSubmit();
1244
1246
1247 GrFlushInfo flushInfo;
1248 context->flush(s.get(), SkSurfaces::BackendSurfaceAccess::kPresent, flushInfo);
1249 context->submit(GrSyncCpu::kNo);
1250
1251 REPORTER_ASSERT(reporter, fulfillInfo.fFulfilled);
1252
1253 // In order to receive the done callback with the low-level APIs we need to re-flush
1254 context->flush(s.get());
1255 context->submit(GrSyncCpu::kYes);
1256
1257 REPORTER_ASSERT(reporter, fulfillInfo.fReleased);
1258
1259 REPORTER_ASSERT(reporter, fulfillInfo.fTex->unique());
1260 fulfillInfo.fTex.reset();
1261}
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
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)
@ 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 790 of file DeferredDisplayListTest.cpp.

793 {
794 auto context = ctxInfo.directContext();
795
797}
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 970 of file DeferredDisplayListTest.cpp.

973 {
974 auto dContext = ctxInfo.directContext();
975
976 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(dContext,
977 kSize,
978 kSize,
980 skgpu::Mipmapped::kNo,
981 GrRenderable::kNo,
982 skgpu::Protected::kNo);
983 if (!mbet) {
984 return;
985 }
986
987 SurfaceParameters params(dContext);
988
989 sk_sp<SkSurface> s = params.make(dContext);
990 if (!s) {
991 return;
992 }
993
995 SkAssertResult(s->characterize(&c));
996
998
999 SkCanvas* canvas = recorder.getCanvas();
1000 SkASSERT(canvas);
1001
1002 auto rContext = canvas->recordingContext();
1003 if (!rContext) {
1004 return;
1005 }
1006
1007 // Wrapped Backend Textures are not supported in DDL
1008 TextureReleaseChecker releaseChecker;
1010 rContext,
1011 mbet->texture(),
1015 nullptr,
1016 sk_gpu_test::ManagedBackendTexture::ReleaseProc,
1017 mbet->releaseContext(TextureReleaseChecker::Release, &releaseChecker));
1019}
static constexpr int kSize
sk_sp< SkImage > image
Definition examples.cpp:29
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)
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
GrBackendApi backend() const
SK_API bool GetVkImageInfo(const GrBackendTexture &, GrVkImageInfo *)
VkImageUsageFlags fImageUsageFlags
Definition GrVkTypes.h:31
@ VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT

◆ test_make_render_target()

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

Definition at line 869 of file DeferredDisplayListTest.cpp.

871 {
872 {
873 const GrSurfaceCharacterization c = params.createCharacterization(dContext);
874
875 if (!c.isValid()) {
876 sk_sp<SkSurface> tmp = params.make(dContext);
877 // If we couldn't characterize the surface we shouldn't be able to create it either
879 return;
880 }
881 }
882
883 const GrSurfaceCharacterization c = params.createCharacterization(dContext);
884 {
885 sk_sp<SkSurface> s = params.make(dContext);
887 if (!s) {
889 return;
890 }
891
894 SkSurfaces::GetBackendTexture(s.get(), SkSurfaces::BackendHandleAccess::kFlushRead);
895 if (backend.isValid()) {
897 }
898 REPORTER_ASSERT(reporter, s->isCompatible(c));
899 // Note that we're leaving 'backend' live here
900 }
901
902 // Make an SkSurface from scratch
903 {
906 REPORTER_ASSERT(reporter, s->isCompatible(c));
907 }
908}
const char * backend
static bool is_compatible(const GrSurfaceCharacterization &gsc, const GrBackendTexture &backendTex)
SK_API GrBackendTexture GetBackendTexture(SkSurface *, BackendHandleAccess)

◆ tracking_fulfill_proc()

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

Definition at line 1175 of file DeferredDisplayListTest.cpp.

1175 {
1176 FulfillInfo* info = (FulfillInfo*) context;
1177 info->fFulfilled = true;
1178 return info->fTex;
1179}
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 1181 of file DeferredDisplayListTest.cpp.

1181 {
1182 FulfillInfo* info = (FulfillInfo*) context;
1183 info->fReleased = true;
1184}

Variable Documentation

◆ kSize

constexpr int kSize = 8
staticconstexpr

Definition at line 957 of file DeferredDisplayListTest.cpp.