Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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
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) {
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)
#define DEFINE_bool(name, defaultValue, helpString)
const char * options
const char * backend
SkColorType fColorType
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
void onDelayedSetup() override
const char * onGetName() override
void onDraw(int n, SkCanvas *canvas) override
CodecBench(SkString basename, SkData *encoded, SkColorType colorType, SkAlphaType alphaType)
void * reset(size_t size=0, OnShrink shrink=kAlloc_OnShrink)
void * get()
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
@ kIncompleteInput
Definition SkCodec.h:84
@ kSuccess
Definition SkCodec.h:80
void printf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:534
const char * c_str() const
Definition SkString.h:133
GAsyncResult * result
ZeroInitialized fZeroInitialized
Definition SkCodec.h:329
SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
size_t minRowBytes() const
SkImageInfo makeColorSpace(sk_sp< SkColorSpace > cs) const
size_t computeMinByteSize() const
SkImageInfo makeColorType(SkColorType newColorType) const