Flutter Engine
The Flutter Engine
Functions
RuntimeBlendTest.cpp File Reference
#include "include/core/SkBitmap.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkBlender.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.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/SkSurface.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include "tools/RuntimeBlendUtils.h"
#include <cmath>
#include <initializer_list>
#include <vector>

Go to the source code of this file.

Functions

static bool nearly_equal (const SkColor &x, const SkColor &y)
 
static void test_blend (skiatest::Reporter *r, SkSurface *surface)
 
 DEF_TEST (SkRuntimeBlender_CPU, r)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SkRuntimeBlender_GPU, r, ctxInfo, CtsEnforcement::kApiLevel_T)
 

Function Documentation

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS()

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

Definition at line 109 of file RuntimeBlendTest.cpp.

112 {
113 const SkImageInfo info = SkImageInfo::MakeN32Premul(/*width=*/1, /*height=*/1);
115 SkSurfaces::RenderTarget(ctxInfo.directContext(), skgpu::Budgeted::kNo, info));
116 test_blend(r, surface.get());
117}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static void test_blend(skiatest::Reporter *r, SkSurface *surface)
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()

DEF_TEST ( SkRuntimeBlender_CPU  ,
 
)

Definition at line 102 of file RuntimeBlendTest.cpp.

102 {
103 const SkImageInfo info = SkImageInfo::MakeN32Premul(/*width=*/1, /*height=*/1);
105
106 test_blend(r, surface.get());
107}
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)

◆ nearly_equal()

static bool nearly_equal ( const SkColor x,
const SkColor y 
)
static

Definition at line 33 of file RuntimeBlendTest.cpp.

33 {
34 const int kTolerance = 1;
35 return abs((int)SkColorGetA(x) - (int)SkColorGetA(y)) <= kTolerance &&
36 abs((int)SkColorGetR(x) - (int)SkColorGetR(y)) <= kTolerance &&
37 abs((int)SkColorGetG(x) - (int)SkColorGetG(y)) <= kTolerance &&
38 abs((int)SkColorGetB(x) - (int)SkColorGetB(y)) <= kTolerance;
39}
static constexpr float kTolerance
Definition: GrQuadUtils.cpp:29
#define SkColorGetR(color)
Definition: SkColor.h:65
#define SkColorGetG(color)
Definition: SkColor.h:69
#define SkColorGetA(color)
Definition: SkColor.h:61
#define SkColorGetB(color)
Definition: SkColor.h:73
double y
double x
SIN Vec< N, float > abs(const Vec< N, float > &x)
Definition: SkVx.h:707

◆ test_blend()

static void test_blend ( skiatest::Reporter r,
SkSurface surface 
)
static

Definition at line 41 of file RuntimeBlendTest.cpp.

41 {
43 REPORTER_ASSERT(r, bitmap.tryAllocPixels(surface->imageInfo()));
44
45 for (int m = 0; m < kSkBlendModeCount; ++m) {
47 for (int alpha : {0x80, 0xFF}) {
48 for (bool useShader : {false, true}) {
49 std::vector<SkColor> colors;
50 for (bool useRuntimeBlend : {false, true}) {
51 // Draw a solid red pixel.
53 paint.setColor(SK_ColorRED);
54 paint.setBlendMode(SkBlendMode::kSrc);
55 surface->getCanvas()->drawRect(SkRect::MakeWH(1, 1), paint);
56
57 // Draw a blue pixel on top of it, using the passed-in blend mode.
58 if (useShader) {
59 // Install a different color in the paint, to ensure we're using the shader
60 paint.setColor(SK_ColorGREEN);
61 paint.setShader(SkShaders::Color(SkColorSetARGB(alpha, 0x00, 0x00, 0xFF)));
62 } else {
63 paint.setColor(SkColorSetARGB(alpha, 0x00, 0x00, 0xFF));
64 }
65 if (useRuntimeBlend) {
67 } else {
68 paint.setBlendMode(mode);
69 }
70 surface->getCanvas()->drawRect(SkRect::MakeWH(1, 1), paint);
71
72 // Read back the red/blue blended pixel.
74 surface->readPixels(bitmap.info(),
75 bitmap.getPixels(),
76 bitmap.rowBytes(),
77 /*srcX=*/0,
78 /*srcY=*/0));
79 colors.push_back(bitmap.getColor(/*x=*/0, /*y=*/0));
80 }
81
84 "Expected: %s %s %s blend matches. Actual: Built-in "
85 "A=%02X R=%02X G=%02X B=%02X, Runtime A=%02X R=%02X G=%02X B=%02X",
87 (alpha == 0xFF) ? "solid" : "transparent",
88 useShader ? "shader" : "paint",
97 }
98 }
99 }
100}
static bool nearly_equal(const SkColor &x, const SkColor &y)
sk_sp< SkBlender > GetRuntimeBlendForBlendMode(SkBlendMode mode)
SK_API const char * SkBlendMode_Name(SkBlendMode blendMode)
static constexpr int kSkBlendModeCount
Definition: SkBlendMode.h:76
SkBlendMode
Definition: SkBlendMode.h:38
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition: SkColor.h:49
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
const Paint & paint
Definition: color_source.cc:38
PODArray< SkColor > colors
Definition: SkRecords.h:276
SK_API sk_sp< SkShader > Color(SkColor)
Definition: bitmap.py:1
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 mode
Definition: switches.h:228
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609