Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | List of all members
DM::ImageGenSrc Class Reference

#include <DMSrcSink.h>

Inheritance diagram for DM::ImageGenSrc:
DM::Src

Public Types

enum  Mode { kCodec_Mode , kPlatform_Mode }
 
- Public Types inherited from DM::Src
using GraphiteTestContext = skiatest::graphite::GraphiteTestContext
 

Public Member Functions

 ImageGenSrc (Path, Mode, SkAlphaType, bool)
 
Result draw (SkCanvas *, GraphiteTestContext *) const override
 
SkISize size () const override
 
Name name () const override
 
bool veto (SinkFlags) const override
 
bool serial () const override
 
- Public Member Functions inherited from DM::Src
virtual ~Src ()
 
virtual void modifyGrContextOptions (GrContextOptions *) const
 
virtual void modifyGraphiteContextOptions (skgpu::graphite::ContextOptions *) const
 
virtual int pageCount () const
 
virtual Result draw (int page, SkCanvas *canvas, GraphiteTestContext *graphiteTestContext) const
 
virtual SkISize size (int page) const
 

Detailed Description

Definition at line 232 of file DMSrcSink.h.

Member Enumeration Documentation

◆ Mode

Enumerator
kCodec_Mode 
kPlatform_Mode 

Definition at line 234 of file DMSrcSink.h.

234 {
235 kCodec_Mode, // Use CodecImageGenerator
236 kPlatform_Mode, // Uses CG or WIC
237 };

Constructor & Destructor Documentation

◆ ImageGenSrc()

DM::ImageGenSrc::ImageGenSrc ( Path  path,
Mode  mode,
SkAlphaType  alphaType,
bool  isGpu 
)

Definition at line 954 of file DMSrcSink.cpp.

955 : fPath(path)
956 , fMode(mode)
957 , fDstAlphaType(alphaType)
958 , fIsGpu(isGpu)
959 , fRunSerially(serial_from_path_name(path))
960{}
static bool serial_from_path_name(const SkString &path)

Member Function Documentation

◆ draw()

Result DM::ImageGenSrc::draw ( SkCanvas canvas,
GraphiteTestContext  
) const
overridevirtual

Implements DM::Src.

Definition at line 972 of file DMSrcSink.cpp.

972 {
973 if (kRGB_565_SkColorType == canvas->imageInfo().colorType()) {
974 return Result::Skip("Uninteresting to test image generator to 565.");
975 }
976
978 if (!encoded) {
979 return Result::Fatal("Couldn't read %s.", fPath.c_str());
980 }
981
982#if defined(SK_BUILD_FOR_WIN)
983 // Initialize COM in order to test with WIC.
984 SkAutoCoInitialize com;
985 if (!com.succeeded()) {
986 return Result::Fatal("Could not initialize COM.");
987 }
988#endif
989
990 std::unique_ptr<SkImageGenerator> gen(nullptr);
991 switch (fMode) {
992 case kCodec_Mode:
994 if (!gen) {
995 return Result::Fatal("Could not create codec image generator.");
996 }
997 break;
998 case kPlatform_Mode: {
999#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
1000 gen = SkImageGeneratorCG::MakeFromEncodedCG(encoded);
1001#elif defined(SK_BUILD_FOR_WIN)
1002 gen = SkImageGeneratorWIC::MakeFromEncodedWIC(encoded);
1003#elif defined(SK_ENABLE_NDK_IMAGES)
1004 gen = SkImageGeneratorNDK::MakeFromEncodedNDK(encoded);
1005#endif
1006 if (!gen) {
1007 return Result::Fatal("Could not create platform image generator.");
1008 }
1009 break;
1010 }
1011 default:
1012 SkASSERT(false);
1013 return Result::Fatal("Invalid image generator mode");
1014 }
1015
1016 // Test deferred decoding path on GPU
1017 if (fIsGpu) {
1019 if (!image) {
1020 return Result::Fatal("Could not create image from codec image generator.");
1021 }
1022 canvas->drawImage(image, 0, 0);
1023 return Result::Ok();
1024 }
1025
1026 // Test various color and alpha types on CPU
1027 SkImageInfo decodeInfo = gen->getInfo().makeAlphaType(fDstAlphaType);
1028
1029 int bpp = decodeInfo.bytesPerPixel();
1030 size_t rowBytes = decodeInfo.width() * bpp;
1031 SkAutoMalloc pixels(decodeInfo.height() * rowBytes);
1032 if (!gen->getPixels(decodeInfo, pixels.get(), rowBytes)) {
1034#if defined(SK_BUILD_FOR_WIN)
1035 if (kPlatform_Mode == fMode) {
1036 // Do not issue a fatal error for WIC flakiness.
1037 status = Result::Status::Skip;
1038 }
1039#endif
1040 return Result(
1041 status,
1042 SkStringPrintf("Image generator could not getPixels() for %s\n", fPath.c_str()));
1043 }
1044
1045 set_bitmap_color_space(&decodeInfo);
1046 draw_to_canvas(canvas, decodeInfo, pixels.get(), rowBytes,
1048 return Result::Ok();
1049}
#define SkASSERT(cond)
Definition SkAssert.h:116
@ kRGB_565_SkColorType
pixel with 5 bits red, 6 bits green, 5 bits blue, in 16-bit word
Definition SkColorType.h:22
SK_API SkString static SkString SkStringPrintf()
Definition SkString.h:287
@ kGetFromCanvas_DstColorType
Definition DMSrcSink.h:167
static Result Ok()
Definition DMSrcSink.h:50
SkImageInfo imageInfo() const
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
static std::unique_ptr< SkImageGenerator > MakeFromEncodedCodec(sk_sp< SkData >, std::optional< SkAlphaType >=std::nullopt)
static sk_sp< SkData > MakeFromFileName(const char path[])
Definition SkData.cpp:148
const char * c_str() const
Definition SkString.h:133
sk_sp< SkImage > image
Definition examples.cpp:29
static void draw_to_canvas(SkCanvas *canvas, const SkImageInfo &info, void *pixels, size_t rowBytes, CodecSrc::DstColorType dstColorType, SkScalar left=0, SkScalar top=0)
static void set_bitmap_color_space(SkImageInfo *info)
SK_API sk_sp< SkImage > DeferredFromGenerator(std::unique_ptr< SkImageGenerator > imageGenerator)
Definition gen.py:1
int bytesPerPixel() const
int width() const
SkColorType colorType() const
int height() const

◆ name()

Name DM::ImageGenSrc::name ( ) const
overridevirtual

Implements DM::Src.

Definition at line 1060 of file DMSrcSink.cpp.

1060 {
1061 return SkOSPath::Basename(fPath.c_str());
1062}
static SkString Basename(const char *fullPath)
Definition SkOSPath.cpp:23

◆ serial()

bool DM::ImageGenSrc::serial ( ) const
inlineoverridevirtual

Reimplemented from DM::Src.

Definition at line 244 of file DMSrcSink.h.

244{ return fRunSerially; }

◆ size()

SkISize DM::ImageGenSrc::size ( ) const
overridevirtual

Implements DM::Src.

Definition at line 1051 of file DMSrcSink.cpp.

1051 {
1053 std::unique_ptr<SkCodec> codec(SkCodec::MakeFromData(encoded));
1054 if (nullptr == codec) {
1055 return {0, 0};
1056 }
1057 return codec->getInfo().dimensions();
1058}
static std::unique_ptr< SkCodec > MakeFromData(sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
Definition SkCodec.cpp:241

◆ veto()

bool DM::ImageGenSrc::veto ( SinkFlags  flags) const
overridevirtual

Reimplemented from DM::Src.

Definition at line 962 of file DMSrcSink.cpp.

962 {
963 if (fIsGpu) {
964 // MSAA runs tend to run out of memory and tests the same code paths as regular gpu configs.
965 return flags.type != SinkFlags::kGPU || flags.approach != SinkFlags::kDirect ||
966 flags.multisampled == SinkFlags::kMultisampled;
967 }
968
969 return flags.type != SinkFlags::kRaster || flags.approach != SinkFlags::kDirect;
970}
FlutterSemanticsFlag flags

The documentation for this class was generated from the following files: