Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Functions | Variables
ImageGeneratorTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkData.h"
#include "include/core/SkGraphics.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageGenerator.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPicture.h"
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkYUVAInfo.h"
#include "include/core/SkYUVAPixmaps.h"
#include "src/base/SkAutoMalloc.h"
#include "src/image/SkImageGeneratorPriv.h"
#include "tests/Test.h"
#include <memory>

Go to the source code of this file.

Classes

class  MyImageGenerator
 

Functions

static std::unique_ptr< SkImageGeneratormy_factory (sk_sp< SkData >)
 
static void test_imagegenerator_factory (skiatest::Reporter *reporter)
 
 DEF_TEST (ImageGenerator, reporter)
 
static sk_sp< SkPicturemake_picture ()
 
 DEF_TEST (PictureImageGenerator, reporter)
 

Variables

static bool gMyFactoryWasCalled
 

Function Documentation

◆ DEF_TEST() [1/2]

DEF_TEST ( ImageGenerator  ,
reporter   
)

Definition at line 76 of file ImageGeneratorTest.cpp.

76 {
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}
reporter
static void test_imagegenerator_factory(skiatest::Reporter *reporter)
@ kJPEG_Full_SkYUVColorSpace
describes full range
Definition SkImageInfo.h:69
bool getYUVAPlanes(const SkYUVAPixmaps &yuvaPixmaps)
bool queryYUVAInfo(const SkYUVAPixmapInfo::SupportedDataTypes &supportedDataTypes, SkYUVAPixmapInfo *yuvaPixmapInfo) const
@ 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)

◆ DEF_TEST() [2/2]

DEF_TEST ( PictureImageGenerator  ,
reporter   
)

Definition at line 104 of file ImageGeneratorTest.cpp.

104 {
105 const struct {
107 SkAlphaType fAlphaType;
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}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
static sk_sp< SkPicture > make_picture()
SkColorType fColorType
kUnpremul_SkAlphaType
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
SK_API int SkColorTypeBytesPerPixel(SkColorType ct)
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
static sk_sp< SkColorSpace > MakeSRGB()
std::unique_ptr< SkImageGenerator > MakeFromPicture(const SkISize &, sk_sp< SkPicture >, const SkMatrix *, const SkPaint *, SkImages::BitDepth, sk_sp< SkColorSpace >, SkSurfaceProps props)
@ 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)

◆ make_picture()

static sk_sp< SkPicture > make_picture ( )
static

Definition at line 98 of file ImageGeneratorTest.cpp.

98 {
99 SkPictureRecorder recorder;
100 recorder.beginRecording(100, 100)->drawColor(SK_ColorRED);
101 return recorder.finishRecordingAsPicture();
102}
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition SkCanvas.h:1182
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()

◆ my_factory()

static std::unique_ptr< SkImageGenerator > my_factory ( sk_sp< SkData )
static

Definition at line 38 of file ImageGeneratorTest.cpp.

38 {
40 return nullptr;
41}
static bool gMyFactoryWasCalled

◆ test_imagegenerator_factory()

static void test_imagegenerator_factory ( skiatest::Reporter reporter)
static

Definition at line 43 of file ImageGeneratorTest.cpp.

43 {
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}
static std::unique_ptr< SkImageGenerator > my_factory(sk_sp< SkData >)
static float prev(float f)
static sk_sp< SkData > MakeWithCString(const char cstr[])
Definition SkData.cpp:195
static ImageGeneratorFromEncodedDataFactory SetImageGeneratorFromEncodedDataFactory(ImageGeneratorFromEncodedDataFactory)
std::unique_ptr< SkImageGenerator > MakeFromEncoded(sk_sp< SkData > data, std::optional< SkAlphaType > at)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
Definition switches.h:41

Variable Documentation

◆ gMyFactoryWasCalled

bool gMyFactoryWasCalled
static

Definition at line 35 of file ImageGeneratorTest.cpp.