Flutter Engine
The Flutter Engine
Functions
makecolorspace.cpp File Reference
#include "gm/gm.h"
#include "include/codec/SkCodec.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkData.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSize.h"
#include "include/core/SkString.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/ganesh/SkImageGanesh.h"
#include "src/core/SkImagePriv.h"
#include "tools/DecodeUtils.h"
#include "tools/Resources.h"
#include <initializer_list>
#include <memory>

Go to the source code of this file.

Functions

sk_sp< SkImagemake_raster_image (const char *path)
 
sk_sp< SkImagemake_color_space (sk_sp< SkImage > orig, sk_sp< SkColorSpace > colorSpace, SkCanvas *canvas)
 
 DEF_SIMPLE_GM_CAN_FAIL (makecolorspace, canvas, errorMsg, 128 *3, 128 *4)
 
 DEF_SIMPLE_GM_BG (makecolortypeandspace, canvas, 128 *3, 128 *4, SK_ColorWHITE)
 
 DEF_SIMPLE_GM_CAN_FAIL (reinterpretcolorspace, canvas, errorMsg, 128 *3, 128 *3)
 

Function Documentation

◆ DEF_SIMPLE_GM_BG()

DEF_SIMPLE_GM_BG ( makecolortypeandspace  ,
canvas  ,
128 *  3,
128 *  4,
SK_ColorWHITE   
)

Definition at line 104 of file makecolorspace.cpp.

104 {
106 ToolUtils::GetResourceAsImage("images/mandrill_128.png"),
107 ToolUtils::GetResourceAsImage("images/color_wheel.png"),
108 };
110
111 // Use the lazy images on the first iteration, and concrete (raster/GPU) images on the second
112 auto direct = GrAsDirectContext(canvas->recordingContext());
113 for (bool lazy : {true, false}) {
114 for (size_t j = 0; j < std::size(images); ++j) {
115 const SkImage* image = images[j].get();
116 if (!image) {
117 // Can happen on bots that abandon the GPU context
118 continue;
119 }
120
121 // Unmodified
122 canvas->drawImage(image, 0, 0);
123
124 // Change the color type/space of the image in a couple ways. In both cases, codec
125 // may fail, because we refuse to decode transparent sources to opaque color types.
126 // Guard against that, to avoid cascading failures in DDL.
127
128 // 565 in a wide color space (should be visibly quantized). Fails with the color_wheel,
129 // because of the codec issues mentioned above.
130 sk_sp<SkImage> image565;
131
132#if defined(SK_GRAPHITE)
133 if (auto recorder = canvas->recorder()) {
135 recorder, kRGB_565_SkColorType, rec2020, {});
136 } else
137#endif
138 {
140 }
141 if (image565) {
142 if (!lazy || image565->isTextureBacked() || image565->makeRasterImage()) {
143 canvas->drawImage(image565, 128, 0);
144 }
145 }
146
147 // Grayscale in the original color space. This fails in even more cases, due to the
148 // above opaque issue, and because Ganesh doesn't support drawing to gray, at all.
149 sk_sp<SkImage> imageGray;
150#if defined(SK_GRAPHITE)
151 if (auto recorder = canvas->recorder()) {
153 recorder, kGray_8_SkColorType, image->refColorSpace(), {});
154 } else
155#endif
156 {
159 }
160 if (imageGray) {
161 if (!lazy || imageGray->isTextureBacked() || imageGray->makeRasterImage()) {
162 canvas->drawImage(imageGray, 256, 0);
163 }
164 }
165
166#if defined(SK_GRAPHITE)
167 if (auto recorder = canvas->recorder()) {
168 images[j] = SkImages::TextureFromImage(recorder, image, {});
169 } else
170#endif
171 {
172 if (direct) {
174 } else {
175 images[j] = image->makeRasterImage(nullptr);
176 }
177 }
178
179 canvas->translate(0, 128);
180 }
181 }
182}
static GrDirectContext * GrAsDirectContext(GrContext_Base *base)
static sk_sp< SkColorSpace > rec2020()
@ kGray_8_SkColorType
pixel with grayscale level in 8-bit byte
Definition: SkColorType.h:35
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition: SkColorType.h:22
static sk_sp< SkColorSpace > MakeRGB(const skcms_TransferFunction &transferFn, const skcms_Matrix3x3 &toXYZ)
sk_sp< SkImage > makeRasterImage(GrDirectContext *, CachingHint cachingHint=kDisallow_CachingHint) const
Definition: SkImage.cpp:267
virtual sk_sp< SkImage > makeColorTypeAndColorSpace(GrDirectContext *direct, SkColorType targetColorType, sk_sp< SkColorSpace > targetCS) const =0
virtual bool isTextureBacked() const =0
sk_sp< SkColorSpace > refColorSpace() const
Definition: SkImage.cpp:158
std::array< MockImage, 3 > images
Definition: mock_vulkan.cc:41
SK_API sk_sp< SkImage > TextureFromImage(GrDirectContext *, const SkImage *, skgpu::Mipmapped=skgpu::Mipmapped::kNo, skgpu::Budgeted=skgpu::Budgeted::kYes)
static constexpr skcms_Matrix3x3 kRec2020
Definition: SkColorSpace.h:93
static constexpr skcms_TransferFunction kSRGB
Definition: SkColorSpace.h:45
sk_sp< const SkImage > image
Definition: SkRecords.h:269
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition: DecodeUtils.h:25
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

◆ DEF_SIMPLE_GM_CAN_FAIL() [1/2]

DEF_SIMPLE_GM_CAN_FAIL ( makecolorspace  ,
canvas  ,
errorMsg  ,
128 *  3,
128 *  4 
)

Definition at line 71 of file makecolorspace.cpp.

71 {
74 sk_sp<SkColorSpace> wideGamutLinear = wideGamut->makeLinearGamma();
75
76 // Lazy images
77 sk_sp<SkImage> opaqueImage = ToolUtils::GetResourceAsImage("images/mandrill_128.png");
78 sk_sp<SkImage> premulImage = ToolUtils::GetResourceAsImage("images/color_wheel.png");
79 if (!opaqueImage || !premulImage) {
80 *errorMsg = "Failed to load images. Did you forget to set the resourcePath?";
82 }
83
84 canvas->drawImage(opaqueImage, 0.0f, 0.0f);
85 canvas->drawImage(make_color_space(opaqueImage, wideGamut, canvas), 128.0f, 0.0f);
86 canvas->drawImage(make_color_space(opaqueImage, wideGamutLinear, canvas), 256.0f, 0.0f);
87 canvas->drawImage(premulImage, 0.0f, 128.0f);
88 canvas->drawImage(make_color_space(premulImage, wideGamut, canvas), 128.0f, 128.0f);
89 canvas->drawImage(make_color_space(premulImage, wideGamutLinear, canvas), 256.0f, 128.0f);
90 canvas->translate(0.0f, 256.0f);
91
92 // Raster images
93 opaqueImage = make_raster_image("images/mandrill_128.png");
94 premulImage = make_raster_image("images/color_wheel.png");
95 canvas->drawImage(opaqueImage, 0.0f, 0.0f);
96 canvas->drawImage(make_color_space(opaqueImage, wideGamut, canvas), 128.0f, 0.0f);
97 canvas->drawImage(make_color_space(opaqueImage, wideGamutLinear, canvas), 256.0f, 0.0f);
98 canvas->drawImage(premulImage, 0.0f, 128.0f);
99 canvas->drawImage(make_color_space(premulImage, wideGamut, canvas), 128.0f, 128.0f);
100 canvas->drawImage(make_color_space(premulImage, wideGamutLinear, canvas), 256.0f, 128.0f);
102}
sk_sp< SkColorSpace > makeLinearGamma() const
sk_sp< SkImage > make_raster_image(const char *path)
sk_sp< SkImage > make_color_space(sk_sp< SkImage > orig, sk_sp< SkColorSpace > colorSpace, SkCanvas *canvas)
static constexpr skcms_Matrix3x3 kAdobeRGB
Definition: SkColorSpace.h:77

◆ DEF_SIMPLE_GM_CAN_FAIL() [2/2]

DEF_SIMPLE_GM_CAN_FAIL ( reinterpretcolorspace  ,
canvas  ,
errorMsg  ,
128 *  3,
128 *  3 
)

Definition at line 184 of file makecolorspace.cpp.

184 {
185 // We draw a 3x3 grid. The three rows are lazy (encoded), raster, and GPU (or another copy of
186 // raster so all configs look similar). In each row, we draw three variants:
187 // - The original image (should look normal).
188 // - The image, reinterpreted as being in the color-spin space. The pixel data isn't changed,
189 // so in untagged configs, this looks like the first column. In tagged configs, this has the
190 // the effect of rotating the colors (RGB -> GBR).
191 // - The image converted to the color-spin space, then reinterpreted as being sRGB. In all
192 // configs, this appears to be spun backwards (RGB -> BRG), and tests the composition of
193 // these two APIs.
194
195 // In all cases, every column should be identical. In tagged configs, the 'R' in the columns
196 // should be Red, Green, Blue.
197
200 sk_sp<SkImage> image = ToolUtils::GetResourceAsImage("images/color_wheel.png");
201 if (!image) {
202 *errorMsg = "Failed to load image. Did you forget to set the resourcePath?";
204 }
205
206 // Lazy images
207 canvas->drawImage(image, 0.0f, 0.0f);
208 canvas->drawImage(image->reinterpretColorSpace(spin), 128.0f, 0.0f);
209 canvas->drawImage(image->makeColorSpace(nullptr, spin)->reinterpretColorSpace(srgb), 256.0f, 0.0f);
210
211 canvas->translate(0.0f, 128.0f);
212
213 // Raster images
215 canvas->drawImage(image, 0.0f, 0.0f);
216 canvas->drawImage(image->reinterpretColorSpace(spin), 128.0f, 0.0f);
217 canvas->drawImage(image->makeColorSpace(nullptr, spin)->reinterpretColorSpace(srgb), 256.0f, 0.0f);
218
219 canvas->translate(0.0f, 128.0f);
220
221 // GPU images
222 auto direct = GrAsDirectContext(canvas->recordingContext());
223
224 sk_sp<SkImage> gpuImage;
225#if defined(SK_GRAPHITE)
226 if (auto recorder = canvas->recorder()) {
227 gpuImage = SkImages::TextureFromImage(recorder, image, {});
228 } else
229#endif
230 {
231 gpuImage = SkImages::TextureFromImage(direct, image);
232 }
233 if (gpuImage) {
234 image = gpuImage;
235 }
236
237 canvas->drawImage(image, 0.0f, 0.0f);
238 canvas->drawImage(image->reinterpretColorSpace(spin), 128.0f, 0.0f);
239
240#if defined(SK_GRAPHITE)
241 if (auto recorder = canvas->recorder()) {
242 gpuImage = image->makeColorSpace(recorder, spin, {});
243 } else
244#endif
245 {
246 gpuImage = image->makeColorSpace(direct, spin);
247 }
248 if (gpuImage) {
249 canvas->drawImage(gpuImage->reinterpretColorSpace(srgb), 256.0f, 0.0f);
250 }
251
253}
static sk_sp< SkColorSpace > MakeSRGB()
sk_sp< SkColorSpace > makeColorSpin() const
virtual sk_sp< SkImage > makeColorSpace(GrDirectContext *direct, sk_sp< SkColorSpace > target) const =0
sk_sp< SkImage > reinterpretColorSpace(sk_sp< SkColorSpace > newColorSpace) const
Definition: SkImage.cpp:241
static sk_sp< SkColorFilter > spin(sk_sp< SkColorFilter > cf)

◆ make_color_space()

sk_sp< SkImage > make_color_space ( sk_sp< SkImage orig,
sk_sp< SkColorSpace colorSpace,
SkCanvas canvas 
)

Definition at line 40 of file makecolorspace.cpp.

42 {
43 if (!orig) {
44 return nullptr;
45 }
46
47 sk_sp<SkImage> xform;
48#if defined(SK_GRAPHITE)
49 if (auto recorder = canvas->recorder()) {
50 xform = orig->makeColorSpace(recorder, colorSpace, {});
51 } else
52#endif
53 {
54 auto direct = GrAsDirectContext(canvas->recordingContext());
55 xform = orig->makeColorSpace(direct, colorSpace);
56 }
57
58 if (!xform) {
59 return nullptr;
60 }
61
62 // Assign an sRGB color space on the xformed image, so we can see the effects of the xform
63 // when we draw.
65 if (colorSpace->gammaIsLinear()) {
67 }
68 return xform->reinterpretColorSpace(std::move(srgb));
69}
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
virtual skgpu::graphite::Recorder * recorder() const
Definition: SkCanvas.cpp:1641
bool gammaIsLinear() const
static sk_sp< SkColorSpace > MakeSRGBLinear()

◆ make_raster_image()

sk_sp< SkImage > make_raster_image ( const char *  path)

Definition at line 33 of file makecolorspace.cpp.

33 {
34 sk_sp<SkData> resourceData = GetResourceAsData(path);
35 std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(resourceData);
36
37 return std::get<0>(codec->getImage());
38}
sk_sp< SkData > GetResourceAsData(const char *resource)
Definition: Resources.cpp:42
static std::unique_ptr< SkCodec > MakeFromData(sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
Definition: SkCodec.cpp:241
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
const myers::Point & get< 0 >(const myers::Segment &s)
Definition: Myers.h:80