Flutter Engine
The Flutter Engine
imagedither.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2024 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 "gm/gm.h"
21
24 "half4 main(half4 src, half4 dst) { return ((dst.rgb - 0.25) * 16).rgb1; }"))
25 .effect->makeBlender(nullptr);
26}
27
28DEF_SIMPLE_GM_CAN_FAIL(image_dither, canvas, errorMsg, 425, 110) {
29 if (!canvas->getSurface()) {
30 // This GM relies on a high-precision (F16) image to determine if image draws are dithered.
31 // Serializing configs will tend to throw away that data (compressing to PNG), so they will
32 // produce different results before/after serialization (and thus fail).
33 *errorMsg = "Not supported in recording mode";
35 }
36
37 // First, we make a non-dithered image with a shallow radial gradient. This will be our source:
38 const SkColor colors[] = { 0xFF555555, 0xFF444444 };
39 const SkPoint points[] = {{0, 0}, {100, 100}};
42 SkPaint gradientPaint;
43 gradientPaint.setShader(gradient);
44
47 surface->getCanvas()->drawPaint(gradientPaint);
48 sk_sp<SkImage> image = surface->makeImageSnapshot();
49
50 // Now, we draw it three times:
51 // 1) As-is (no dither), to ensure that our source image doesn't have any dithering included
52 // 2) Using an image shader, with dithering enabled on the paint
53 // 3) With drawImage, with dithering enabled on the paint
54 //
55 // We'd like #2 and #3 to both respect the dither flag, for consistency (b/320529640)
56 canvas->translate(5, 5);
57
58 canvas->drawImage(image, 0, 0);
59 canvas->translate(105, 0);
60
61 SkPaint imageShaderPaint;
62 imageShaderPaint.setShader(image->makeShader(SkSamplingOptions{}));
63 imageShaderPaint.setDither(true);
64 canvas->drawRect({0, 0, 100, 100}, imageShaderPaint);
65 canvas->translate(105, 0);
66
67 SkPaint drawImagePaint;
68 drawImagePaint.setDither(true);
69 canvas->drawImage(image, 0, 0, SkSamplingOptions{}, &drawImagePaint);
70 canvas->translate(105, 0);
71
72 // Also draw the actual gradient with the dither flag, to see how it should look:
73 gradientPaint.setDither(true);
74 canvas->drawRect({0, 0, 100, 100}, gradientPaint);
75
76 SkPaint colorStretchPaint;
77 colorStretchPaint.setBlender(stretch_colors_blender());
78 canvas->drawPaint(colorStretchPaint);
79
81}
static const int points[]
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition: SkColorType.h:38
uint32_t SkColor
Definition: SkColor.h:37
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkImage.cpp:179
void setDither(bool dither)
Definition: SkPaint.h:182
void setShader(sk_sp< SkShader > shader)
void setBlender(sk_sp< SkBlender > blender)
Definition: SkPaint.cpp:155
sk_sp< SkBlender > makeBlender(sk_sp< const SkData > uniforms, SkSpan< const ChildPtr > children={}) const
static Result MakeForBlender(SkString sksl, const Options &)
VkSurfaceKHR surface
Definition: main.cc:49
sk_sp< SkBlender > stretch_colors_blender()
Definition: imagedither.cpp:22
DEF_SIMPLE_GM_CAN_FAIL(image_dither, canvas, errorMsg, 425, 110)
Definition: imagedither.cpp:28
sk_sp< const SkImage > image
Definition: SkRecords.h:269
PODArray< SkColor > colors
Definition: SkRecords.h:276
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
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
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
sk_sp< SkRuntimeEffect > effect