Flutter Engine
The Flutter Engine
mirrortile.cpp
Go to the documentation of this file.
1/*
2* Copyright 2022 Google Inc.
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 "gm/gm.h"
16
17/**
18 * Tests image shader mirror tile mode with scale factors of 1 and -1, with nearest and linear
19 * filtering, and with/without a half pixel offset between device and image space. The linear filter
20 * should only have an effect when there is a half pixel offset. We test mirror tile mode in x and
21 * in y separately.
22 */
23DEF_SIMPLE_GM_CAN_FAIL(mirror_tile, canvas, errorMsg, 140, 370) {
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};
35 colors,
36 sizeof(colors));
37 auto imgx = SkImages::RasterFromPixmapCopy(pmx);
38
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
Definition: color_source.cc:38
DEF_SIMPLE_GM_CAN_FAIL(mirror_tile, canvas, errorMsg, 140, 370)
Definition: mirrortile.cpp:23
SK_API sk_sp< SkImage > RasterFromPixmapCopy(const SkPixmap &pixmap)
PODArray< SkColor > colors
Definition: SkRecords.h:276
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 keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
SeparatedVector2 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