Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
#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());
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}
static constexpr PaintParamsKey Invalid()
SkSpan< const ShaderNode * > getRootNodes(const ShaderCodeDictionary *, SkArenaAlloc *) const
static constexpr int kSkiaBuiltInReservedCnt

◆ 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)
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
Type::kYUV Type::kRGBA() int(0.7 *637)
UniquePaintParamsID findOrCreate(PaintParamsKeyBuilder *) SK_EXCLUDES(fSpinLock)
static constexpr int kFixedFunctionBlendModeIDOffset