Flutter Engine
The Flutter Engine
Functions
KeyTest.cpp File Reference
#include "tests/Test.h"
#include "src/base/SkArenaAlloc.h"
#include "src/gpu/graphite/ContextPriv.h"
#include "src/gpu/graphite/PaintParamsKey.h"
#include "src/gpu/graphite/ShaderCodeDictionary.h"

Go to the source code of this file.

Functions

 DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS (KeyWithInvalidCodeSnippetIDTest, reporter, context, CtsEnforcement::kNextRelease)
 
 DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS (KeyEqualityChecksSnippetID, reporter, context, CtsEnforcement::kNextRelease)
 
 DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS (ShaderInfoDetectsFixedFunctionBlend, reporter, context, CtsEnforcement::kNextRelease)
 

Function Documentation

◆ DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS() [1/3]

DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS ( KeyEqualityChecksSnippetID  ,
reporter  ,
context  ,
CtsEnforcement::kNextRelease   
)

Definition at line 81 of file KeyTest.cpp.

82 {
83 SkArenaAlloc arena{256};
84 ShaderCodeDictionary* dict = context->priv().shaderCodeDictionary();
85
86 int userSnippetID1 = dict->addRuntimeEffectSnippet("key1");
87 int userSnippetID2 = dict->addRuntimeEffectSnippet("key2");
88
89 PaintParamsKey keyA = create_key(dict, userSnippetID1, &arena);
90 PaintParamsKey keyB = create_key(dict, userSnippetID1, &arena);
91 PaintParamsKey keyC = create_key(dict, userSnippetID2, &arena);
92
93 // Verify that keyA matches keyB, and that it does not match keyC.
94 REPORTER_ASSERT(reporter, keyA == keyB);
95 REPORTER_ASSERT(reporter, keyA != keyC);
96 REPORTER_ASSERT(reporter, !(keyA == keyC));
97 REPORTER_ASSERT(reporter, !(keyA != keyB));
98}
reporter
Definition: FontMgrTest.cpp:39
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286

◆ DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS() [2/3]

DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS ( KeyWithInvalidCodeSnippetIDTest  ,
reporter  ,
context  ,
CtsEnforcement::kNextRelease   
)

Definition at line 52 of file KeyTest.cpp.

53 {
54 SkArenaAlloc arena{256};
55 ShaderCodeDictionary* dict = context->priv().shaderCodeDictionary();
56
57 // A builder without any data is invalid. The Builder and the PaintParamKeys can include
58 // invalid IDs without themselves becoming invalid. Normally adding an invalid ID triggers an
59 // assert in debug builds, since the properly functioning key system should never encounter an
60 // invalid ID.
63 REPORTER_ASSERT(reporter, !keyView->isValid());
64 REPORTER_ASSERT(reporter, !PaintParamsKey::Invalid().isValid());
65
66 // However, if the program gets in a malformed state on release builds, the key
67 // could contain an invalid ID. In that case the invalid snippet IDs are detected when
68 // reconstructing the key into an effect tree for SkSL generation. To test this, we manually
69 // construct an invalid span and test that it returns a null shader node tree when treated as
70 // a PaintParamsKey.
71 // NOTE: This is intentionally abusing memory to create a corrupt scenario and is dependent on
72 // the structure of PaintParamsKey (just SkSpan<const int32_t>).
73 int32_t invalidKeyData[3] = {(int32_t) BuiltInCodeSnippetID::kSolidColorShader,
75 (int32_t) BuiltInCodeSnippetID::kFixedFunctionSrcBlendMode};
76 SkSpan<const int32_t> invalidKeySpan{invalidKeyData, std::size(invalidKeyData)*sizeof(int32_t)};
77 const PaintParamsKey* fakeKey = reinterpret_cast<const PaintParamsKey*>(&invalidKeySpan);
78 REPORTER_ASSERT(reporter, fakeKey->getRootNodes(dict, &arena).empty());
79}
SkSpan< const ShaderNode * > getRootNodes(const ShaderCodeDictionary *, SkArenaAlloc *) const
static constexpr int kSkiaBuiltInReservedCnt
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259

◆ DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS() [3/3]

DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS ( ShaderInfoDetectsFixedFunctionBlend  ,
reporter  ,
context  ,
CtsEnforcement::kNextRelease   
)

Definition at line 100 of file KeyTest.cpp.

101 {
102 ShaderCodeDictionary* dict = context->priv().shaderCodeDictionary();
103
104 for (int bm = 0; bm <= (int) SkBlendMode::kLastCoeffMode; ++bm) {
107 UniquePaintParamsID paintID = dict->findOrCreate(&builder);
108
109 ShaderInfo shaderInfo{paintID, dict, /*rteDict=*/nullptr, /*ssboIndex=*/""};
110
111 SkBlendModeCoeff expectedSrc, expectedDst;
113 &expectedSrc, &expectedDst));
114 REPORTER_ASSERT(reporter, coeff_equal(expectedSrc, shaderInfo.blendInfo().fSrcBlend));
115 REPORTER_ASSERT(reporter, coeff_equal(expectedDst, shaderInfo.blendInfo().fDstBlend));
116 REPORTER_ASSERT(reporter, shaderInfo.blendInfo().fEquation == skgpu::BlendEquation::kAdd);
117 REPORTER_ASSERT(reporter, shaderInfo.blendInfo().fBlendConstant == SK_PMColor4fTRANSPARENT);
118
119 bool expectedWriteColor = BlendModifiesDst(skgpu::BlendEquation::kAdd,
120 shaderInfo.blendInfo().fSrcBlend,
121 shaderInfo.blendInfo().fDstBlend);
122 REPORTER_ASSERT(reporter, shaderInfo.blendInfo().fWritesColor == expectedWriteColor);
123 }
124}
SK_API bool SkBlendMode_AsCoeff(SkBlendMode mode, SkBlendModeCoeff *src, SkBlendModeCoeff *dst)
Definition: SkBlendMode.cpp:57
SkBlendMode
Definition: SkBlendMode.h:38
@ kLastCoeffMode
last porter duff blend mode
SkBlendModeCoeff
Definition: SkBlendMode.h:84
static size_t add_block(SkSBlockAllocator< N > &pool)
constexpr SkPMColor4f SK_PMColor4fTRANSPARENT
Definition: SkColorData.h:378
UniquePaintParamsID findOrCreate(PaintParamsKeyBuilder *) SK_EXCLUDES(fSpinLock)
static constexpr int kFixedFunctionBlendModeIDOffset
static constexpr bool BlendModifiesDst(BlendEquation equation, BlendCoeff srcCoeff, BlendCoeff dstCoeff)
Definition: Blend.h:134