Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
PNGCodecGM Class Reference
Inheritance diagram for PNGCodecGM:
skiagm::GM

Public Types

enum class  DecodeMode { kGetAllPixels , kIncremental , kZeroInit }
 
enum class  DstColorType { kForceGrayscale , kForceNonNativePremulColor , kGetFromCanvas }
 
- Public Types inherited from skiagm::GM
enum  Mode { kGM_Mode , kSample_Mode , kBench_Mode }
 
using DrawResult = skiagm::DrawResult
 
using GraphiteTestContext = skiatest::graphite::GraphiteTestContext
 

Public Member Functions

 PNGCodecGM (std::string path, DecodeMode decodeMode, DstColorType dstColorType, SkAlphaType dstAlphaType)
 
bool isBazelOnly () const override
 
std::map< std::string, std::string > getGoldKeys () const override
 
- Public Member Functions inherited from skiagm::GM
 GM (SkColor backgroundColor=SK_ColorWHITE)
 
virtual ~GM ()
 
void setMode (Mode mode)
 
Mode getMode () const
 
DrawResult gpuSetup (SkCanvas *, SkString *errorMsg, GraphiteTestContext *=nullptr)
 
void gpuTeardown ()
 
void onceBeforeDraw ()
 
DrawResult draw (SkCanvas *canvas)
 
DrawResult draw (SkCanvas *, SkString *errorMsg)
 
void drawBackground (SkCanvas *)
 
DrawResult drawContent (SkCanvas *canvas)
 
DrawResult drawContent (SkCanvas *, SkString *errorMsg)
 
virtual bool runAsBench () const
 
SkScalar width ()
 
SkScalar height ()
 
SkColor getBGColor () const
 
void setBGColor (SkColor)
 
void drawSizeBounds (SkCanvas *, SkColor)
 
bool animate (double)
 
virtual bool onChar (SkUnichar)
 
bool getControls (SkMetaData *controls)
 
void setControls (const SkMetaData &controls)
 
virtual void modifyGrContextOptions (GrContextOptions *)
 
virtual void modifyGraphiteContextOptions (skgpu::graphite::ContextOptions *) const
 

Static Public Member Functions

static constexpr const char * DecodeModeToString (DecodeMode decodeMode)
 
static constexpr const char * DstColorTypeToString (DstColorType dstColorType)
 

Protected Member Functions

SkString getName () const override
 
SkISize getISize () override
 
DrawResult onDraw (SkCanvas *canvas, SkString *errorMsg) override
 
- Protected Member Functions inherited from skiagm::GM
virtual DrawResult onGpuSetup (SkCanvas *, SkString *, GraphiteTestContext *)
 
virtual void onGpuTeardown ()
 
virtual void onOnceBeforeDraw ()
 
virtual void onDraw (SkCanvas *)
 
virtual bool onAnimate (double)
 
virtual bool onGetControls (SkMetaData *)
 
virtual void onSetControls (const SkMetaData &)
 
GraphiteTestContextgraphiteTestContext () const
 

Additional Inherited Members

- Static Public Attributes inherited from skiagm::GM
static constexpr char kErrorMsg_DrawSkippedGpuOnly []
 

Detailed Description

Definition at line 145 of file png_codec.cpp.

Member Enumeration Documentation

◆ DecodeMode

enum class PNGCodecGM::DecodeMode
strong
Enumerator
kGetAllPixels 
kIncremental 
kZeroInit 

Definition at line 149 of file png_codec.cpp.

◆ DstColorType

enum class PNGCodecGM::DstColorType
strong
Enumerator
kForceGrayscale 
kForceNonNativePremulColor 
kGetFromCanvas 

Definition at line 157 of file png_codec.cpp.

Constructor & Destructor Documentation

◆ PNGCodecGM()

PNGCodecGM::PNGCodecGM ( std::string  path,
DecodeMode  decodeMode,
DstColorType  dstColorType,
SkAlphaType  dstAlphaType 
)
inline

Definition at line 189 of file png_codec.cpp.

193 : skiagm::GM()
194 , fPath(path)
195 , fDecodeMode(decodeMode)
196 , fDstColorType(dstColorType)
197 , fDstAlphaType(dstAlphaType) {}

Member Function Documentation

◆ DecodeModeToString()

static constexpr const char * PNGCodecGM::DecodeModeToString ( DecodeMode  decodeMode)
inlinestaticconstexpr

Definition at line 163 of file png_codec.cpp.

163 {
164 switch (decodeMode) {
166 return "kGetAllPixels";
168 return "kIncremental";
170 return "kZeroInit";
171 }
173 }
#define SkUNREACHABLE
Definition SkAssert.h:135

◆ DstColorTypeToString()

static constexpr const char * PNGCodecGM::DstColorTypeToString ( DstColorType  dstColorType)
inlinestaticconstexpr

Definition at line 175 of file png_codec.cpp.

175 {
176 switch (dstColorType) {
178 return "kForceGrayscale";
180 return "kForceNonNativePremulColor";
182 return "kGetFromCanvas";
183 }
185 }

◆ getGoldKeys()

std::map< std::string, std::string > PNGCodecGM::getGoldKeys ( ) const
inlineoverridevirtual

Reimplemented from skiagm::GM.

Definition at line 204 of file png_codec.cpp.

204 {
205 return std::map<std::string, std::string>{
206 {"name", getName().c_str()},
207 {"source_type", "image"},
208 {"decode_mode", DecodeModeToString(fDecodeMode)},
209 {"dst_color_type", DstColorTypeToString(fDstColorType)},
210 {"dst_alpha_type", sk_alpha_type_to_str(fDstAlphaType)},
211 };
212 }
static constexpr const char * DstColorTypeToString(DstColorType dstColorType)
SkString getName() const override
static constexpr const char * DecodeModeToString(DecodeMode decodeMode)
const char * c_str() const
Definition SkString.h:133
static constexpr const char * sk_alpha_type_to_str(SkAlphaType alphaType)

◆ getISize()

SkISize PNGCodecGM::getISize ( )
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 224 of file png_codec.cpp.

224 {
225 DecodeResult decodeResult = decode(fPath);
226 if (decodeResult.errorMsg != "") {
227 return {0, 0};
228 }
229 return decodeResult.codec->dimensions();
230 }
static DecodeResult decode(std::string path)
std::unique_ptr< SkCodec > codec
std::string errorMsg

◆ getName()

SkString PNGCodecGM::getName ( ) const
inlineoverrideprotectedvirtual

Implements skiagm::GM.

Definition at line 217 of file png_codec.cpp.

217 {
218 SkString name = SkOSPath::Basename(fPath.c_str());
219 return name;
220 }
static SkString Basename(const char *fullPath)
Definition SkOSPath.cpp:23
const char * name
Definition fuchsia.cc:50

◆ isBazelOnly()

bool PNGCodecGM::isBazelOnly ( ) const
inlineoverridevirtual

Reimplemented from skiagm::GM.

Definition at line 199 of file png_codec.cpp.

199 {
200 // This GM class overlaps with DM's CodecSrc and related sources.
201 return true;
202 }

◆ onDraw()

DrawResult PNGCodecGM::onDraw ( SkCanvas canvas,
SkString errorMsg 
)
inlineoverrideprotectedvirtual

Reimplemented from skiagm::GM.

Definition at line 234 of file png_codec.cpp.

234 {
235 DecodeResult decodeResult = decode(fPath);
236 if (decodeResult.errorMsg != "") {
237 *errorMsg = decodeResult.errorMsg.c_str();
238 return DrawResult::kFail;
239 }
240 std::unique_ptr<SkCodec> codec = std::move(decodeResult.codec);
241
242 SkImageInfo decodeInfo = codec->getInfo();
243 if (*errorMsg = validateCanvasColorTypeAndGetDecodeInfo(&decodeInfo,
244 canvas->imageInfo().colorType());
245 *errorMsg != SkString()) {
246 return DrawResult::kFail;
247 }
248
249 SkISize size = codec->dimensions();
250 decodeInfo = decodeInfo.makeDimensions(size);
251
252 const int bpp = decodeInfo.bytesPerPixel();
253 const size_t rowBytes = size.width() * bpp;
254 const size_t safeSize = decodeInfo.computeByteSize(rowBytes);
255 SkAutoMalloc pixels(safeSize);
256
258 if (DecodeMode::kZeroInit == fDecodeMode) {
259 memset(pixels.get(), 0, size.height() * rowBytes);
260 options.fZeroInitialized = SkCodec::kYes_ZeroInitialized;
261 }
262
263 // For codec srcs, we want the "draw" step to be a memcpy. Any interesting color space or
264 // color format conversions should be performed by the codec. Sometimes the output of the
265 // decode will be in an interesting color space. On our srgb and f16 backends, we need to
266 // "pretend" that the color space is standard sRGB to avoid triggering color conversion
267 // at draw time.
268 SkImageInfo bitmapInfo = decodeInfo.makeColorSpace(SkColorSpace::MakeSRGB());
269
270 if (kRGBA_8888_SkColorType == decodeInfo.colorType() ||
271 kBGRA_8888_SkColorType == decodeInfo.colorType()) {
272 bitmapInfo = bitmapInfo.makeColorType(kN32_SkColorType);
273 }
274
275 switch (fDecodeMode) {
278 switch (codec->getPixels(decodeInfo, pixels.get(), rowBytes, &options)) {
280 // We consider these to be valid, since we should still decode what is
281 // available.
284 break;
285 default:
286 // Everything else is considered a failure.
287 *errorMsg = SkStringPrintf("Couldn't getPixels %s.", fPath.c_str());
288 return DrawResult::kFail;
289 }
290
291 drawToCanvas(canvas, bitmapInfo, pixels.get(), rowBytes);
292 break;
293 }
295 void* dst = pixels.get();
296 uint32_t height = decodeInfo.height();
297 if (SkCodec::kSuccess ==
298 codec->startIncrementalDecode(decodeInfo, dst, rowBytes, &options)) {
299 int rowsDecoded;
300 auto result = codec->incrementalDecode(&rowsDecoded);
302 codec->fillIncompleteImage(decodeInfo,
303 dst,
304 rowBytes,
306 height,
307 rowsDecoded);
308 }
309 } else {
310 *errorMsg = "Could not start incremental decode";
311 return DrawResult::kFail;
312 }
313 drawToCanvas(canvas, bitmapInfo, dst, rowBytes);
314 break;
315 }
316 default:
317 SkASSERT(false);
318 *errorMsg = "Invalid fDecodeMode";
319 return DrawResult::kFail;
320 }
321 return DrawResult::kOk;
322 }
const char * options
#define SkASSERT(cond)
Definition SkAssert.h:116
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition SkColorType.h:24
SK_API SkString static SkString SkStringPrintf()
Definition SkString.h:287
SkImageInfo imageInfo() const
@ kYes_ZeroInitialized
Definition SkCodec.h:308
@ kNo_ZeroInitialized
Definition SkCodec.h:315
@ kIncompleteInput
Definition SkCodec.h:84
@ kSuccess
Definition SkCodec.h:80
@ kErrorInInput
Definition SkCodec.h:91
static sk_sp< SkColorSpace > MakeSRGB()
SkScalar height()
Definition gm.h:162
GAsyncResult * result
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
dst
Definition cp.py:12
size_t computeByteSize(size_t rowBytes) const
SkImageInfo makeDimensions(SkISize newSize) const
int bytesPerPixel() const
SkImageInfo makeColorSpace(sk_sp< SkColorSpace > cs) const
SkColorType colorType() const
int height() const
SkImageInfo makeColorType(SkColorType newColorType) const

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