Flutter Engine
The Flutter Engine
ImageGeneratorTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 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
13#include "include/core/SkData.h"
25#include "tests/Test.h"
26
27#include <memory>
28
29#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
31#elif defined(SK_BUILD_FOR_WIN)
33#endif
34
36
37// NOLINTNEXTLINE(performance-unnecessary-value-param)
38static std::unique_ptr<SkImageGenerator> my_factory(sk_sp<SkData>) {
40 return nullptr;
41}
42
44 // just need a non-empty data to test things
45 sk_sp<SkData> data(SkData::MakeWithCString("test_imagegenerator_factory"));
46
47 gMyFactoryWasCalled = false;
48
50
51 std::unique_ptr<SkImageGenerator> gen = SkImageGenerators::MakeFromEncoded(data);
52 REPORTER_ASSERT(reporter, nullptr == gen);
54
55 // Test is racy, in that it hopes no other thread is changing this global...
58 REPORTER_ASSERT(reporter, nullptr == gen);
60
61 // This just verifies that the signatures match.
62#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
63 SkGraphics::SetImageGeneratorFromEncodedDataFactory(SkImageGeneratorCG::MakeFromEncodedCG);
64#elif defined(SK_BUILD_FOR_WIN)
65 SkGraphics::SetImageGeneratorFromEncodedDataFactory(SkImageGeneratorWIC::MakeFromEncodedWIC);
66#endif
67
69}
70
72public:
73 MyImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(0, 0)) {}
74};
75
76DEF_TEST(ImageGenerator, reporter) {
78 SkYUVAPixmapInfo yuvaPixmapInfo;
79
80 // Check that the YUV decoding API does not cause any crashes
82 SkYUVAInfo yuvaInfo({250, 250},
86 yuvaPixmapInfo = SkYUVAPixmapInfo(yuvaInfo,
88 /*rowBytes[]*/ nullptr);
89 SkYUVAPixmaps yuvaPixmaps = SkYUVAPixmaps::Allocate(yuvaPixmapInfo);
90 ig.getYUVAPlanes(yuvaPixmaps);
91
92 // Suppressed due to https://code.google.com/p/skia/issues/detail?id=4339
93 if ((false)) {
95 }
96}
97
99 SkPictureRecorder recorder;
100 recorder.beginRecording(100, 100)->drawColor(SK_ColorRED);
101 return recorder.finishRecordingAsPicture();
102}
103
104DEF_TEST(PictureImageGenerator, reporter) {
105 const struct {
108 } recs[] = {
114
120 };
121
122 auto colorspace = SkColorSpace::MakeSRGB();
123 auto picture = make_picture();
125 {100, 100}, picture, nullptr, nullptr, SkImages::BitDepth::kU8, colorspace);
126
127 // worst case for all requests
129
130 for (const auto& rec : recs) {
131 SkImageInfo info = SkImageInfo::Make(100, 100, rec.fColorType, rec.fAlphaType, colorspace);
132 REPORTER_ASSERT(reporter, gen->getPixels(info, storage.get(), info.minRowBytes()));
133 }
134}
135
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
reporter
Definition: FontMgrTest.cpp:39
static bool gMyFactoryWasCalled
static void test_imagegenerator_factory(skiatest::Reporter *reporter)
static std::unique_ptr< SkImageGenerator > my_factory(sk_sp< SkData >)
static sk_sp< SkPicture > make_picture()
DEF_TEST(ImageGenerator, reporter)
static float prev(float f)
SkColorType fColorType
kUnpremul_SkAlphaType
SkAlphaType fAlphaType
SkAlphaType
Definition: SkAlphaType.h:26
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
SkColorType
Definition: SkColorType.h:19
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition: SkColorType.h:26
@ kRGBA_F16_SkColorType
pixel with half floats for red, green, blue, alpha;
Definition: SkColorType.h:38
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
@ kRGBA_F32_SkColorType
pixel using C float for red, green, blue, alpha; in 128-bit word
Definition: SkColorType.h:40
@ kRGBA_1010102_SkColorType
10 bits for red, green, blue; 2 bits for alpha; in 32-bit word
Definition: SkColorType.h:27
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
SK_API int SkColorTypeBytesPerPixel(SkColorType ct)
Definition: SkImageInfo.cpp:16
@ kJPEG_Full_SkYUVColorSpace
describes full range
Definition: SkImageInfo.h:69
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
static sk_sp< SkColorSpace > MakeSRGB()
static sk_sp< SkData > MakeWithCString(const char cstr[])
Definition: SkData.cpp:195
static ImageGeneratorFromEncodedDataFactory SetImageGeneratorFromEncodedDataFactory(ImageGeneratorFromEncodedDataFactory)
bool getYUVAPlanes(const SkYUVAPixmaps &yuvaPixmaps)
bool queryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes &supportedDataTypes, SkYUVAPixmapInfo *yuvaPixmapInfo) const
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
@ kY_UV
Plane 0: Y, Plane 1: UV.
@ k420
1 set of UV values for each 2x2 block of Y values.
static constexpr SupportedDataTypes All()
@ kUnorm8
8 bit unsigned normalized
static SkYUVAPixmaps Allocate(const SkYUVAPixmapInfo &yuvaPixmapInfo)
std::unique_ptr< SkImageGenerator > MakeFromPicture(const SkISize &, sk_sp< SkPicture >, const SkMatrix *, const SkPaint *, SkImages::BitDepth, sk_sp< SkColorSpace >, SkSurfaceProps props)
std::unique_ptr< SkImageGenerator > MakeFromEncoded(sk_sp< SkData > data, std::optional< SkAlphaType > at)
@ kU8
uses 8-bit unsigned int per color component
sk_sp< const SkPicture > picture
Definition: SkRecords.h:299
Definition: gen.py:1
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63