Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
SkSLES2ConformanceTest.cpp File Reference
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkData.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkShader.h"
#include "include/core/SkString.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkRuntimeEffect.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "src/core/SkOSFile.h"
#include "src/utils/SkOSPath.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include "tools/Resources.h"
#include <functional>

Go to the source code of this file.

Functions

static void test_expect_fail (skiatest::Reporter *r, const char *testFile)
 
static void test_expect_pass (skiatest::Reporter *r, SkSurface *surface, const char *testFile)
 
static void iterate_dir (const char *directory, const std::function< void(const char *)> &run)
 
 DEF_TEST (SkSL_ES2Conformance_Pass_CPU, r)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SkSL_ES2Conformance_Pass_GPU, r, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_TEST (SkSL_ES2Conformance_Fail, r)
 

Function Documentation

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS()

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( SkSL_ES2Conformance_Pass_GPU  ,
,
ctxInfo  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 119 of file SkSLES2ConformanceTest.cpp.

122 {
125 SkSurfaces::RenderTarget(ctxInfo.directContext(), skgpu::Budgeted::kNo, info));
126 iterate_dir("sksl/es2_conformance/pass/", [&](const char* path) {
127 test_expect_pass(r, surface.get(), path);
128 });
129}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static void test_expect_pass(skiatest::Reporter *r, SkSurface *surface, const char *testFile)
static void iterate_dir(const char *directory, const std::function< void(const char *)> &run)
VkSurfaceKHR surface
Definition main.cc:49
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_TEST() [1/2]

DEF_TEST ( SkSL_ES2Conformance_Fail  ,
 
)

Definition at line 131 of file SkSLES2ConformanceTest.cpp.

131 {
132 iterate_dir("sksl/es2_conformance/fail/", [&](const char* path) {
133 test_expect_fail(r, path);
134 });
135}
static void test_expect_fail(skiatest::Reporter *r, const char *testFile)

◆ DEF_TEST() [2/2]

DEF_TEST ( SkSL_ES2Conformance_Pass_CPU  ,
 
)

Definition at line 110 of file SkSLES2ConformanceTest.cpp.

110 {
113
114 iterate_dir("sksl/es2_conformance/pass/", [&](const char* path) {
115 test_expect_pass(r, surface.get(), path);
116 });
117}
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)

◆ iterate_dir()

static void iterate_dir ( const char *  directory,
const std::function< void(const char *)> &  run 
)
static

Definition at line 99 of file SkSLES2ConformanceTest.cpp.

99 {
100 SkString resourceDirectory = GetResourcePath(directory);
101 SkOSFile::Iter iter(resourceDirectory.c_str(), ".rts");
103
104 while (iter.next(&name, /*getDir=*/false)) {
105 SkString path(SkOSPath::Join(directory, name.c_str()));
106 run(path.c_str());
107 }
108}
SkString GetResourcePath(const char *resource)
Definition Resources.cpp:23
static SkString Join(const char *rootPath, const char *relativePath)
Definition SkOSPath.cpp:14
const char * c_str() const
Definition SkString.h:133
const char * name
Definition fuchsia.cc:50
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57
Definition run.py:1

◆ test_expect_fail()

static void test_expect_fail ( skiatest::Reporter r,
const char *  testFile 
)
static

Definition at line 41 of file SkSLES2ConformanceTest.cpp.

41 {
43 sk_sp<SkData> shaderData = GetResourceAsData(testFile);
44 if (!shaderData) {
45 ERRORF(r, "%s: Unable to load file", SkOSPath::Basename(testFile).c_str());
46 return;
47 }
48
49 SkString shaderString{reinterpret_cast<const char*>(shaderData->bytes()), shaderData->size()};
51 if (result.effect) {
52 ERRORF(r, "%s: Expected failure, but compiled successfully",
53 SkOSPath::Basename(testFile).c_str());
54 return;
55 }
56}
const char * options
sk_sp< SkData > GetResourceAsData(const char *resource)
Definition Resources.cpp:42
#define ERRORF(r,...)
Definition Test.h:293
static SkString Basename(const char *fullPath)
Definition SkOSPath.cpp:23
static Result MakeForShader(SkString sksl, const Options &)
GAsyncResult * result

◆ test_expect_pass()

static void test_expect_pass ( skiatest::Reporter r,
SkSurface surface,
const char *  testFile 
)
static

Definition at line 58 of file SkSLES2ConformanceTest.cpp.

58 {
60 sk_sp<SkData> shaderData = GetResourceAsData(testFile);
61 if (!shaderData) {
62 ERRORF(r, "%s: Unable to load file", testFile);
63 return;
64 }
65
66 SkString shaderString{reinterpret_cast<const char*>(shaderData->bytes()), shaderData->size()};
68 if (!result.effect) {
69 ERRORF(r, "%s: %s", testFile, result.errorText.c_str());
70 return;
71 }
72
74 sk_sp<SkShader> shader = builder.makeShader();
75 if (!shader) {
76 ERRORF(r, "%s: Unable to build shader", testFile);
77 return;
78 }
79
80 SkPaint paintShader;
81 paintShader.setShader(shader);
82 surface->getCanvas()->drawRect(SkRect::MakeWH(1, 1), paintShader);
83
85 REPORTER_ASSERT(r, bitmap.tryAllocPixels(surface->imageInfo()));
86 REPORTER_ASSERT(r, surface->readPixels(bitmap.info(), bitmap.getPixels(), bitmap.rowBytes(),
87 /*srcX=*/0, /*srcY=*/0));
88
89 SkColor color = bitmap.getColor(0, 0);
90 if (color != SkColorSetARGB(0xFF, 0x00, 0xFF, 0x00)) {
91 ERRORF(r, "%s: Expected solid green. Actual:\n"
92 "RRGGBBAA\n"
93 "%02X%02X%02X%02X",
94 testFile,
96 }
97}
SkColor4f color
#define SkColorGetR(color)
Definition SkColor.h:65
#define SkColorGetG(color)
Definition SkColor.h:69
uint32_t SkColor
Definition SkColor.h:37
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition SkColor.h:49
#define SkColorGetA(color)
Definition SkColor.h:61
#define SkColorGetB(color)
Definition SkColor.h:73
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
void setShader(sk_sp< SkShader > shader)
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609