Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Namespaces | Functions
SkSLCross.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkSurfaceProps.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GrDirectContext.h"
#include "include/private/SkColorData.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "src/core/SkSLTypeShared.h"
#include "src/gpu/SkBackingFit.h"
#include "src/gpu/ganesh/GrColor.h"
#include "src/gpu/ganesh/GrFragmentProcessor.h"
#include "src/gpu/ganesh/GrImageInfo.h"
#include "src/gpu/ganesh/GrPaint.h"
#include "src/gpu/ganesh/GrPixmap.h"
#include "src/gpu/ganesh/SurfaceDrawContext.h"
#include "src/gpu/ganesh/glsl/GrGLSLFragmentShaderBuilder.h"
#include "src/gpu/ganesh/glsl/GrGLSLProgramDataManager.h"
#include "src/gpu/ganesh/glsl/GrGLSLUniformHandler.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include <memory>
#include <utility>

Go to the source code of this file.

Namespaces

namespace  skgpu
 

Functions

static void run_test (skiatest::Reporter *, GrDirectContext *, skgpu::ganesh::SurfaceDrawContext *, SkVector a, SkVector b, float expectedCrossProduct)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SkSLCross, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 

Function Documentation

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS()

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( SkSLCross  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 51 of file SkSLCross.cpp.

51 {
52 GrDirectContext* dContext = ctxInfo.directContext();
55 nullptr,
57 {1, 1},
59 /*label=*/"SkSLCross_Test");
60 if (!sdc) {
61 ERRORF(reporter, "could not create render target context.");
62 return;
63 }
64 run_test(reporter, dContext, sdc.get(), {3,4}, {5,6}, -2); // Negative.
65 run_test(reporter, dContext, sdc.get(), {3,4}, {-5,-6}, 2); // Positive.
66 run_test(reporter, dContext, sdc.get(), {0, 2.287f}, {0, -7.741f}, 0); // Zero.
67 run_test(reporter, dContext, sdc.get(), {62.17f, 0}, {-43.49f, 0}, 0); // Zero.
68}
reporter
#define ERRORF(r,...)
Definition Test.h:293
static std::unique_ptr< SurfaceDrawContext > Make(GrRecordingContext *, GrColorType, sk_sp< GrSurfaceProxy >, sk_sp< SkColorSpace >, GrSurfaceOrigin, const SkSurfaceProps &)
void run_test(skiatest::Reporter *reporter, Context *context, SkISize surfaceSize, SkISize recordingSize, SkISize replayOffset, DrawCallback draw, const std::vector< Expectation > &expectations)

◆ run_test()

static void run_test ( skiatest::Reporter reporter,
GrDirectContext directContext,
skgpu::ganesh::SurfaceDrawContext sdc,
SkVector  a,
SkVector  b,
float  expectedCrossProduct 
)
static

Definition at line 128 of file SkSLCross.cpp.

133 {
134 SkASSERT(sdc->width() == 1);
135 SkASSERT(sdc->height() == 1);
136
137 sdc->clear(SkPMColor4f::FromBytes_RGBA(0xbaaaaaad));
138
139 GrPaint crossPaint;
140 crossPaint.setColor4f(SK_PMColor4fWHITE);
142 crossPaint.setColorFragmentProcessor(std::make_unique<VisualizeCrossProductSignFP>(a, b));
143 sdc->drawRect(/*clip=*/nullptr, std::move(crossPaint), GrAA::kNo, SkMatrix::I(),
144 SkRect::MakeWH(1,1));
145
148 &result,
149 sizeof(GrColor));
150 sdc->readPixels(directContext, resultPM, {0, 0});
151
152 SkASSERT(expectedCrossProduct == a.cross(b));
153 if (expectedCrossProduct > 0) {
154 REPORTER_ASSERT(reporter, result == GrColorPackRGBA(0, 255, 0, 255)); // Green.
155 } else if (expectedCrossProduct < 0) {
156 REPORTER_ASSERT(reporter, result == GrColorPackRGBA(255, 0, 0, 255)); // Red.
157 } else {
158 REPORTER_ASSERT(reporter, result == GrColorPackRGBA(0, 0, 0, 255)); // Black.
159 }
160}
static GrColor GrColorPackRGBA(unsigned r, unsigned g, unsigned b, unsigned a)
Definition GrColor.h:46
uint32_t GrColor
Definition GrColor.h:25
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define SkASSERT(cond)
Definition SkAssert.h:116
@ kSrcOver
r = s + (1-sa)*d
constexpr SkPMColor4f SK_PMColor4fWHITE
@ 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
void setColorFragmentProcessor(std::unique_ptr< GrFragmentProcessor > fp)
Definition GrPaint.h:65
void setColor4f(const SkPMColor4f &color)
Definition GrPaint.h:50
void setPorterDuffXPFactory(SkBlendMode mode)
Definition GrPaint.cpp:28
static const SkMatrix & I()
bool readPixels(GrDirectContext *dContext, GrPixmap dst, SkIPoint srcPt)
void drawRect(const GrClip *, GrPaint &&paint, GrAA, const SkMatrix &viewMatrix, const SkRect &, const GrStyle *style=nullptr)
void clear(const SkIRect &rect, const SkRGBA4f< AlphaType > &color)
static bool b
struct MyStruct a[10]
GAsyncResult * result
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static SkRGBA4f FromBytes_RGBA(uint32_t color)
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609