Flutter Engine
The Flutter Engine
Functions
RasterPipelineCodeGeneratorTest.cpp File Reference
#include "include/core/SkColor.h"
#include "include/core/SkTypes.h"
#include "src/base/SkArenaAlloc.h"
#include "src/core/SkRasterPipeline.h"
#include "src/sksl/SkSLCompiler.h"
#include "src/sksl/SkSLProgramKind.h"
#include "src/sksl/SkSLProgramSettings.h"
#include "src/sksl/SkSLUtil.h"
#include "src/sksl/codegen/SkSLRasterPipelineBuilder.h"
#include "src/sksl/codegen/SkSLRasterPipelineCodeGenerator.h"
#include "src/sksl/ir/SkSLFunctionDeclaration.h"
#include "src/sksl/ir/SkSLProgram.h"
#include "src/sksl/tracing/SkSLDebugTracePriv.h"
#include "tests/Test.h"
#include <memory>
#include <optional>
#include <string>

Go to the source code of this file.

Functions

static void test (skiatest::Reporter *r, const char *src, SkSpan< const float > uniforms, SkColor4f startingColor, std::optional< SkColor4f > expectedResult)
 
 DEF_TEST (SkSLRasterPipelineCodeGeneratorNestedTernaryTest, r)
 
 DEF_TEST (SkSLRasterPipelineCodeGeneratorArithmeticTest, r)
 
 DEF_TEST (SkSLRasterPipelineCodeGeneratorCoercedTypeTest, r)
 
 DEF_TEST (SkSLRasterPipelineCodeGeneratorIdentitySwizzle, r)
 
 DEF_TEST (SkSLRasterPipelineCodeGeneratorBitwiseNotTest, r)
 
 DEF_TEST (SkSLRasterPipelineCodeGeneratorComparisonIntrinsicTest, r)
 

Function Documentation

◆ DEF_TEST() [1/6]

DEF_TEST ( SkSLRasterPipelineCodeGeneratorArithmeticTest  ,
 
)

Definition at line 115 of file RasterPipelineCodeGeneratorTest.cpp.

116 {},
117 /*startingColor=*/SkColor4f{0.0, 0.0, 0.0, 0.0},
118 /*expectedResult=*/SkColor4f{0.499f, 0.499f, 0.499f, 0.499f});
119}
120
121DEF_TEST(SkSLRasterPipelineCodeGeneratorArithmeticTest, r) {
DEF_TEST(SkSLRasterPipelineCodeGeneratorNestedTernaryTest, r)

◆ DEF_TEST() [2/6]

DEF_TEST ( SkSLRasterPipelineCodeGeneratorBitwiseNotTest  ,
 
)

Definition at line 144 of file RasterPipelineCodeGeneratorTest.cpp.

144 {0.0, 1.0, 0.0, 1.0,
145 1.0, 0.0, 0.0, 1.0};
146 test(r,
147 R"__SkSL__(
148 uniform half4 colorGreen;
149 uniform float4 colorRed;
150 half4 main(half4 color) {
151 return ((colorGreen + colorRed) == float4(1.0, 1.0, 0.0, 2.0)) ? colorGreen
152 : colorGreen.gr01;
static void test(skiatest::Reporter *r, const char *src, SkSpan< const float > uniforms, SkColor4f startingColor, std::optional< SkColor4f > expectedResult)

◆ DEF_TEST() [3/6]

DEF_TEST ( SkSLRasterPipelineCodeGeneratorCoercedTypeTest  ,
 
)

Definition at line 123 of file RasterPipelineCodeGeneratorTest.cpp.

124 {
125 const half4 colorGreen = half4(0,1,0,1), colorRed = half4(1,0,0,1);
126
127 half a = 3.0, b = 4.0, c = a + b - 2.0;
128 if (a*a + b*b == c*c*c/5.0) {
129 int A = 3, B = 4, C = A + B - 2;
130 if (A*A + B*B == C*C*C/5) {
131 return colorGreen;
static bool b
struct MyStruct a[10]
Vec< 4, uint16_t > half4
Definition: SkVx.h:1176

◆ DEF_TEST() [4/6]

DEF_TEST ( SkSLRasterPipelineCodeGeneratorComparisonIntrinsicTest  ,
 
)

Definition at line 154 of file RasterPipelineCodeGeneratorTest.cpp.

156 {0.0, 0.0, 0.0, 0.0},
157 /*expectedResult=*/SkColor4f{0.0, 1.0, 0.0, 1.0});
158}
159
160DEF_TEST(SkSLRasterPipelineCodeGeneratorIdentitySwizzle, r) {

◆ DEF_TEST() [5/6]

DEF_TEST ( SkSLRasterPipelineCodeGeneratorIdentitySwizzle  ,
 
)

Definition at line 133 of file RasterPipelineCodeGeneratorTest.cpp.

138 {},
139 /*startingColor=*/SkColor4f{0.0, 0.0, 0.0, 0.0},
140 /*expectedResult=*/SkColor4f{0.0f, 1.0f, 0.0f, 1.0f});
141}
142

◆ DEF_TEST() [6/6]

DEF_TEST ( SkSLRasterPipelineCodeGeneratorNestedTernaryTest  ,
 
)

Definition at line 106 of file RasterPipelineCodeGeneratorTest.cpp.

106 {
107 // Add in your SkSL here.
108 test(r,
109 R"__SkSL__(
110 half4 main(half4) {
111 half three = 3, one = 1, two = 2;
112 half result = (three > (one > two ? 2.0 : 5.0)) ? 1.0 : 0.499;
113 return half4(result);

◆ test()

static void test ( skiatest::Reporter r,
const char *  src,
SkSpan< const float >  uniforms,
SkColor4f  startingColor,
std::optional< SkColor4f expectedResult 
)
static

Definition at line 32 of file RasterPipelineCodeGeneratorTest.cpp.

36 {
39 settings.fMaxVersionAllowed = SkSL::Version::k300;
40 std::unique_ptr<SkSL::Program> program = compiler.convertProgram(
42 if (!program) {
43 ERRORF(r, "Unexpected error compiling %s\n%s", src, compiler.errorText().c_str());
44 return;
45 }
46 const SkSL::FunctionDeclaration* main = program->getFunction("main");
47 if (!main) {
48 ERRORF(r, "Program must have a 'main' function");
49 return;
50 }
51 SkArenaAlloc alloc(/*firstHeapAllocation=*/1000);
52 SkRasterPipeline pipeline(&alloc);
53 pipeline.appendConstantColor(&alloc, startingColor);
54 SkSL::DebugTracePriv debugTrace;
55 std::unique_ptr<SkSL::RP::Program> rasterProg =
56 SkSL::MakeRasterPipelineProgram(*program, *main->definition(), &debugTrace);
57 if (!rasterProg && !expectedResult.has_value()) {
58 // We didn't get a program, as expected. Test passes.
59 return;
60 }
61 if (!rasterProg && expectedResult.has_value()) {
62 ERRORF(r, "MakeRasterPipelineProgram failed");
63 return;
64 }
65 if (rasterProg && !expectedResult.has_value()) {
66 ERRORF(r, "MakeRasterPipelineProgram should have failed, but didn't");
67 return;
68 }
69
70#if defined(DUMP_PROGRAMS)
71 // Dump the program instructions via SkDebugf.
72 SkDebugf("-----\n\n");
74 rasterProg->dump(&stream);
75 SkDebugf("\n-----\n\n");
76#endif
77
78 // Append the SkSL program to the raster pipeline.
79 rasterProg->appendStages(&pipeline, &alloc, /*callbacks=*/nullptr, uniforms);
80
81 // Move the float values from RGBA into an 8888 memory buffer.
84 pipeline.append(SkRasterPipelineOp::store_8888, &outCtx);
85 pipeline.run(0, 0, 1, 1);
86
87 // Make sure the first pixel (exclusively) of `out` matches RGBA.
88 uint32_t expected = expectedResult->toBytes_RGBA();
89 REPORTER_ASSERT(r, out[0] == expected,
90 "Got:%02X%02X%02X%02X Expected:%02X%02X%02X%02X",
91 (out[0] >> 24) & 0xFF,
92 (out[0] >> 16) & 0xFF,
93 (out[0] >> 8) & 0xFF,
94 out[0] & 0xFF,
95 (expected >> 24) & 0xFF,
96 (expected >> 16) & 0xFF,
97 (expected >> 8) & 0xFF,
98 expected & 0xFF);
99
100 // Make sure the rest of the pixels are untouched.
101 for (size_t i = 1; i < std::size(out); ++i) {
102 REPORTER_ASSERT(r, out[i] == 0);
103 }
104}
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static constexpr int SkRasterPipeline_kMaxStride_highp
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
#define ERRORF(r,...)
Definition: Test.h:293
std::unique_ptr< RP::Program > MakeRasterPipelineProgram(const SkSL::Program &program, const FunctionDefinition &function, DebugTracePriv *debugTrace, bool writeTraceOps)
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
Definition: main.py:1
compiler
Definition: malisc.py:17