Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
ImageNewShaderTest.cpp File Reference
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTileMode.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/DecodeUtils.h"
#include "tools/Resources.h"
#include <cstring>

Go to the source code of this file.

Functions

static void test_bitmap_equality (skiatest::Reporter *reporter, SkBitmap &bm1, SkBitmap &bm2)
 
static void paint_source (SkSurface *sourceSurface)
 
static void run_shader_test (skiatest::Reporter *reporter, SkSurface *sourceSurface, SkSurface *destinationSurface, SkImageInfo &info)
 
 DEF_TEST (ImageNewShader, reporter)
 
static void gpu_to_gpu (skiatest::Reporter *reporter, GrRecordingContext *rContext)
 
static void raster_to_gpu (skiatest::Reporter *reporter, GrRecordingContext *rContext)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (ImageNewShader_GPU, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_TEST (ImageRawShader, reporter)
 

Function Documentation

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS()

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

Definition at line 143 of file ImageNewShaderTest.cpp.

146 {
147 auto dContext = ctxInfo.directContext();
148
149 // GPU -> GPU
150 gpu_to_gpu(reporter, dContext);
151
152 // GPU -> RASTER not currently supported
153
154 // RASTER -> GPU
155 raster_to_gpu(reporter, dContext);
156}
reporter
static void gpu_to_gpu(skiatest::Reporter *reporter, GrRecordingContext *rContext)
static void raster_to_gpu(skiatest::Reporter *reporter, GrRecordingContext *rContext)

◆ DEF_TEST() [1/2]

DEF_TEST ( ImageNewShader  ,
reporter   
)

Definition at line 116 of file ImageNewShaderTest.cpp.

116 {
118
119 auto sourceSurface(SkSurfaces::Raster(info));
120 auto destinationSurface(SkSurfaces::Raster(info));
121
122 run_shader_test(reporter, sourceSurface.get(), destinationSurface.get(), info);
123}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static void run_shader_test(skiatest::Reporter *reporter, SkSurface *sourceSurface, SkSurface *destinationSurface, SkImageInfo &info)
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static SkImageInfo MakeN32Premul(int width, int height)

◆ DEF_TEST() [2/2]

DEF_TEST ( ImageRawShader  ,
reporter   
)

Definition at line 158 of file ImageNewShaderTest.cpp.

158 {
159 auto image = ToolUtils::GetResourceAsImage("images/mandrill_32.png");
161
162 // We should be able to turn this into a "raw" image shader:
164
165 // ... but not if we request cubic filtering
167}
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
sk_sp< SkShader > makeRawShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition SkImage.cpp:207
sk_sp< SkImage > image
Definition examples.cpp:29
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition DecodeUtils.h:25
static constexpr SkCubicResampler Mitchell()

◆ gpu_to_gpu()

static void gpu_to_gpu ( skiatest::Reporter reporter,
GrRecordingContext rContext 
)
static

Definition at line 125 of file ImageNewShaderTest.cpp.

125 {
127
128 auto sourceSurface(SkSurfaces::RenderTarget(rContext, skgpu::Budgeted::kNo, info));
129 auto destinationSurface(SkSurfaces::RenderTarget(rContext, skgpu::Budgeted::kNo, info));
130
131 run_shader_test(reporter, sourceSurface.get(), destinationSurface.get(), info);
132}
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)

◆ paint_source()

static void paint_source ( SkSurface sourceSurface)
static

Definition at line 41 of file ImageNewShaderTest.cpp.

41 {
42 SkCanvas* sourceCanvas = sourceSurface->getCanvas();
43 sourceCanvas->clear(0xFFDEDEDE);
44
45 SkPaint paintColor;
46 paintColor.setColor(0xFFFF0000);
48
53 SkIntToScalar(sourceSurface->height()));
54
55 sourceCanvas->drawRect(rect, paintColor);
56}
#define SkIntToScalar(x)
Definition SkScalar.h:57
void drawRect(const SkRect &rect, const SkPaint &paint)
void clear(SkColor color)
Definition SkCanvas.h:1199
void setStyle(Style style)
Definition SkPaint.cpp:105
void setColor(SkColor color)
Definition SkPaint.cpp:119
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
SkCanvas * getCanvas()
Definition SkSurface.cpp:82
int height() const
Definition SkSurface.h:184
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659

◆ raster_to_gpu()

static void raster_to_gpu ( skiatest::Reporter reporter,
GrRecordingContext rContext 
)
static

Definition at line 134 of file ImageNewShaderTest.cpp.

134 {
136
137 auto sourceSurface(SkSurfaces::Raster(info));
138 auto destinationSurface(SkSurfaces::RenderTarget(rContext, skgpu::Budgeted::kNo, info));
139
140 run_shader_test(reporter, sourceSurface.get(), destinationSurface.get(), info);
141}

◆ run_shader_test()

static void run_shader_test ( skiatest::Reporter reporter,
SkSurface sourceSurface,
SkSurface destinationSurface,
SkImageInfo info 
)
static

Definition at line 58 of file ImageNewShaderTest.cpp.

59 {
60 paint_source(sourceSurface);
61
62 sk_sp<SkImage> sourceImage(sourceSurface->makeImageSnapshot());
63 sk_sp<SkShader> sourceShader = sourceImage->makeShader(
65
67 paint.setShader(sourceShader);
68
69 SkCanvas* destinationCanvas = destinationSurface->getCanvas();
70 destinationCanvas->clear(SK_ColorTRANSPARENT);
71 destinationCanvas->drawPaint(paint);
72
73 SkBitmap bmOrig;
74 bmOrig.allocN32Pixels(info.width(), info.height());
75 sourceSurface->readPixels(bmOrig, 0, 0);
76
77
78 SkBitmap bm;
79 bm.allocN32Pixels(info.width(), info.height());
80 destinationSurface->readPixels(bm, 0, 0);
81
82 test_bitmap_equality(reporter, bmOrig, bm);
83
84 // Test with a translated shader
86 matrix.setTranslate(SkIntToScalar(-1), SkIntToScalar(0));
87
88 sk_sp<SkShader> sourceShaderTranslated = sourceImage->makeShader(
91 SkSamplingOptions(), &matrix);
92
93 destinationCanvas->clear(SK_ColorTRANSPARENT);
94
95 SkPaint paintTranslated;
96 paintTranslated.setShader(sourceShaderTranslated);
97
98 destinationCanvas->drawPaint(paintTranslated);
99
100 SkBitmap bmt;
101 bmt.allocN32Pixels(info.width(), info.height());
102 destinationSurface->readPixels(bmt, 0, 0);
103
104 // Test correctness
105 {
106 for (int y = 0; y < info.height(); y++) {
107 REPORTER_ASSERT(reporter, 0xFFFF0000 == bmt.getColor(0, y));
108
109 for (int x = 1; x < info.width(); x++) {
110 REPORTER_ASSERT(reporter, 0xFFDEDEDE == bmt.getColor(x, y));
111 }
112 }
113 }
114}
static void paint_source(SkSurface *sourceSurface)
static void test_bitmap_equality(skiatest::Reporter *reporter, SkBitmap &bm1, SkBitmap &bm2)
constexpr SkColor SK_ColorTRANSPARENT
Definition SkColor.h:99
SkColor getColor(int x, int y) const
Definition SkBitmap.h:874
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition SkBitmap.cpp:232
void drawPaint(const SkPaint &paint)
void setShader(sk_sp< SkShader > shader)
sk_sp< SkImage > makeImageSnapshot()
Definition SkSurface.cpp:90
bool readPixels(const SkPixmap &dst, int srcX, int srcY)
const Paint & paint
double y
double x
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258

◆ test_bitmap_equality()

static void test_bitmap_equality ( skiatest::Reporter reporter,
SkBitmap bm1,
SkBitmap bm2 
)
static

Definition at line 36 of file ImageNewShaderTest.cpp.

36 {
38 REPORTER_ASSERT(reporter, 0 == memcmp(bm1.getPixels(), bm2.getPixels(), bm1.computeByteSize()));
39}
size_t computeByteSize() const
Definition SkBitmap.h:293
void * getPixels() const
Definition SkBitmap.h:283