Flutter Engine
The Flutter Engine
ImageShaderTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "tests/Test.h"
9
16#include "tools/GpuToolUtils.h"
17#include "tools/ToolUtils.h"
18
19namespace skgpu::graphite {
20
21namespace {
22
23constexpr SkColor4f kRectColor = SkColors::kRed;
24constexpr SkColor4f kBgColor = SkColors::kTransparent;
25
26struct Expectation {
29};
30
32 Context* context,
33 SkISize canvasSize,
34 SkISize imageSize,
35 SkRect srcRect,
36 SkRect dstRect,
37 SkTileMode tileMode,
38 SkSamplingOptions samplingOptions,
39 std::vector<Expectation> expectations) {
40 std::unique_ptr<Recorder> recorder = context->makeRecorder();
42 recorder.get(),
44 SkCanvas* canvas = surface->getCanvas();
45
48 0);
49 bitmap.eraseColor(kRectColor);
50 bitmap.setImmutable();
52
53 SkPaint p;
54 SkMatrix srcToDst = SkMatrix::RectToRect(srcRect, dstRect);
56 std::move(image), srcRect, tileMode, tileMode, samplingOptions, &srcToDst));
57 canvas->drawRect(dstRect, p);
58
59 SkPixmap pm;
60
63 bool peekPixelsSuccess = result.peekPixels(&pm);
64 REPORTER_ASSERT(reporter, peekPixelsSuccess);
65
66 bool readPixelsSuccess = surface->readPixels(pm, 0, 0);
67 REPORTER_ASSERT(reporter, readPixelsSuccess);
68
69 for (const Expectation& e : expectations) {
70 SkColor4f a = e.color;
71 SkColor4f b = pm.getColor4f(e.pos.fX, e.pos.fY);
73 a == b,
74 "At position {%.1f, %.1f}, "
75 "expected {%.1f, %.1f, %.1f, %.1f}, "
76 "found {%.1f, %.1f, %.1f, %.1f}",
77 e.pos.fX, e.pos.fY,
78 a.fR, a.fG, a.fB, a.fA,
79 b.fR, b.fG, b.fB, b.fA);
80 }
81}
82
83} // anonymous namespace
84
87 // Test that a subset bound covering less than half of a pixel causes that pixel not to be
88 // drawn when using decal tiling and nearest-neighbor filtering. In this case we have a subset
89 // that covers 3/4 the pixel column at y=1, all of the y=2 column, and 1/4 the y=3 column.
91 context,
92 /*canvasSize=*/SkISize::Make(100, 100),
93 /*imageSize=*/SkISize::Make(4, 4),
94 /*srcRect=*/SkRect::MakeLTRB(1.25, 0.0f, 3.25f, 2.0f),
95 /*dstRect=*/SkRect::MakeLTRB(0, 0, 80, 80),
98
99 // Pixel that should sample the image at y=1, since that's where the subset starts.
100 {{{0, 40}, kRectColor},
101 // Pixel that would sample the image at y=3, but the subset bound at y=3.25 prevents
102 // us from sampling the image.
103 {{75, 40}, kBgColor}});
104}
105
106} // namespace skgpu::graphite
reporter
Definition: FontMgrTest.cpp:39
SkPoint pos
SkColor4f color
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
SkTileMode
Definition: SkTileMode.h:13
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
static sk_sp< SkShader > MakeSubset(sk_sp< SkImage >, const SkRect &subset, SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix, bool clampAsIfUnpremul=false)
static SkMatrix RectToRect(const SkRect &src, const SkRect &dst, ScaleToFit mode=kFill_ScaleToFit)
Definition: SkMatrix.h:157
SkColor4f getColor4f(int x, int y) const
Definition: SkPixmap.cpp:388
VkSurfaceKHR surface
Definition: main.cc:49
static bool b
struct MyStruct a[10]
GAsyncResult * result
constexpr SkColor4f kRed
Definition: SkColor.h:440
constexpr SkColor4f kTransparent
Definition: SkColor.h:434
sk_sp< const SkImage > image
Definition: SkRecords.h:269
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)
sk_sp< SkImage > MakeTextureImage(SkCanvas *canvas, sk_sp< SkImage > orig)
Definition: bitmap.py:1
DEF_GRAPHITE_TEST_FOR_RENDERING_CONTEXTS(BufferManagerGpuOnlyBufferTest, reporter, context, CtsEnforcement::kNextRelease)
SkSamplingOptions(SkFilterMode::kLinear))
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646
static void test_draw(SkCanvas *canvas, const char label[])
Definition: surface.cpp:72