Flutter Engine
The Flutter Engine
CodecBench.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 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
8#include "bench/CodecBench.h"
12#include "src/core/SkOSFile.h"
14
15// Actually zeroing the memory would throw off timing, so we just lie.
16static DEFINE_bool(zero_init, false,
17 "Pretend our destination is zero-intialized, simulating Android?");
18
20 SkAlphaType alphaType)
22 , fAlphaType(alphaType)
23 , fData(SkRef(encoded))
24{
25 // Parse filename and the color type to give the benchmark a useful name
26 fName.printf("Codec_%s_%s%s", baseName.c_str(), color_type_to_str(colorType),
27 alpha_type_to_str(alphaType));
28 // Ensure that we can create an SkCodec from this data.
30}
31
32const char* CodecBench::onGetName() {
33 return fName.c_str();
34}
35
38}
39
41 std::unique_ptr<SkCodec> codec = SkCodec::MakeFromData(fData);
42
43 fInfo = codec->getInfo().makeColorType(fColorType)
44 .makeAlphaType(fAlphaType)
45 .makeColorSpace(nullptr);
46
47 fPixelStorage.reset(fInfo.computeMinByteSize());
48}
49
50void CodecBench::onDraw(int n, SkCanvas* canvas) {
51 std::unique_ptr<SkCodec> codec;
53 if (FLAGS_zero_init) {
54 options.fZeroInitialized = SkCodec::kYes_ZeroInitialized;
55 }
56 for (int i = 0; i < n; i++) {
57 codec = SkCodec::MakeFromData(fData);
58#ifdef SK_DEBUG
60#endif
61 codec->getPixels(fInfo, fPixelStorage.get(), fInfo.minRowBytes(),
62 &options);
65 }
66}
const char * alpha_type_to_str(SkAlphaType alphaType)
const char * color_type_to_str(SkColorType colorType)
static DEFINE_bool(zero_init, false, "Pretend our destination is zero-intialized, simulating Android?")
const char * options
const char * backend
SkColorType fColorType
SkAlphaType fAlphaType
SkAlphaType
Definition: SkAlphaType.h:26
#define SkASSERT(cond)
Definition: SkAssert.h:116
SkColorType
Definition: SkColorType.h:19
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static T * SkRef(T *obj)
Definition: SkRefCnt.h:132
bool isSuitableFor(Backend backend) override
Definition: CodecBench.cpp:36
void onDelayedSetup() override
Definition: CodecBench.cpp:40
const char * onGetName() override
Definition: CodecBench.cpp:32
void onDraw(int n, SkCanvas *canvas) override
Definition: CodecBench.cpp:50
CodecBench(SkString basename, SkData *encoded, SkColorType colorType, SkAlphaType alphaType)
Definition: CodecBench.cpp:19
void * reset(size_t size=0, OnShrink shrink=kAlloc_OnShrink)
Definition: SkAutoMalloc.h:53
void * get()
Definition: SkAutoMalloc.h:64
static std::unique_ptr< SkCodec > MakeFromData(sk_sp< SkData >, SkSpan< const SkCodecs::Decoder > decoders, SkPngChunkReader *=nullptr)
Definition: SkCodec.cpp:241
@ kYes_ZeroInitialized
Definition: SkCodec.h:308
Result
Definition: SkCodec.h:76
@ kIncompleteInput
Definition: SkCodec.h:84
@ kSuccess
Definition: SkCodec.h:80
Definition: SkData.h:25
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:534
const char * c_str() const
Definition: SkString.h:133
GAsyncResult * result
SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
Definition: SkImageInfo.h:466
size_t minRowBytes() const
Definition: SkImageInfo.h:517
SkImageInfo makeColorSpace(sk_sp< SkColorSpace > cs) const
size_t computeMinByteSize() const
Definition: SkImageInfo.h:578
SkImageInfo makeColorType(SkColorType newColorType) const
Definition: SkImageInfo.h:475