Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
mirrortile.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkImage.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkShader.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTileMode.h"

Go to the source code of this file.

Functions

 DEF_SIMPLE_GM_CAN_FAIL (mirror_tile, canvas, errorMsg, 140, 370)
 

Function Documentation

◆ DEF_SIMPLE_GM_CAN_FAIL()

DEF_SIMPLE_GM_CAN_FAIL ( mirror_tile  ,
canvas  ,
errorMsg  ,
140  ,
370   
)

Tests image shader mirror tile mode with scale factors of 1 and -1, with nearest and linear filtering, and with/without a half pixel offset between device and image space. The linear filter should only have an effect when there is a half pixel offset. We test mirror tile mode in x and in y separately.

Definition at line 23 of file mirrortile.cpp.

23 {
24 // We don't run this test on the GPU because we're at the driver/hw's mercy for how this
25 // is handled. We also don't test this on recording or vector canvases.
26 if (SkPixmap unused; !canvas->peekPixels(&unused)) {
27 *errorMsg = "Test only works with canvases backed by CPU pixels";
29 }
30
31 uint32_t colors[] {0xFFFF0000, 0xFF00FF00, 0xFF0000FF};
32 SkPixmap pmx(SkImageInfo::Make({std::size(colors), 1},
35 colors,
36 sizeof(colors));
37 auto imgx = SkImages::RasterFromPixmapCopy(pmx);
38
39 SkPixmap pmy(SkImageInfo::Make({1, std::size(colors)},
42 colors,
43 sizeof(colors[0]));
44 auto imgy = SkImages::RasterFromPixmapCopy(pmy);
45
46 // We draw offscreen and then zoom that up to make the result clear.
47 auto surf = canvas->makeSurface(canvas->imageInfo().makeWH(80, 80));
48 SkASSERT(surf);
49 auto* c = surf->getCanvas();
50 c->clear(SK_ColorWHITE);
51
52 for (bool offset : {false, true}) {
55
56 // Draw single row image with mirror tiling in x and clamped in y.
57 paint.setShader(imgx->makeShader(SkTileMode::kMirror,
60 c->save();
61 c->translate(imgx->width(), 0);
62 if (offset) {
63 c->translate(0.5, 0);
64 }
65 c->drawRect(SkRect::MakeXYWH(-imgx->width(), 0, 3*imgx->width(), 5), paint);
66 c->restore();
67
68 // Draw single column image with mirror tiling in y and clamped in x.
69 paint.setShader(imgy->makeShader(SkTileMode::kClamp,
72 c->save();
73 c->translate(3*imgx->width() + 3, imgy->height());
74 if (offset) {
75 c->translate(0, 0.5);
76 }
77 c->drawRect(SkRect::MakeXYWH(0, -imgy->height(), 5, 3*imgy->height()), paint);
78 c->restore();
79
80 c->translate(0, 3*imgy->height() + 3);
81 }
82 }
83
84 canvas->scale(8, 8);
85 canvas->drawImage(surf->makeImageSnapshot(), 0, 0);
87}
static bool unused
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define SkASSERT(cond)
Definition SkAssert.h:116
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
SkFilterMode
const Paint & paint
SK_API sk_sp< SkImage > RasterFromPixmapCopy(const SkPixmap &pixmap)
PODArray< SkColor > colors
Definition SkRecords.h:276
Point offset
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659