skia2/bench/AndroidCodecBench.cpp

57 lines
1.8 KiB
C++
Raw Normal View History

/*
* Copyright 2016 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "bench/AndroidCodecBench.h"
#include "bench/CodecBenchPriv.h"
#include "include/codec/SkAndroidCodec.h"
#include "include/core/SkBitmap.h"
#include "src/core/SkOSFile.h"
#include "tools/flags/CommandLineFlags.h"
AndroidCodecBench::AndroidCodecBench(SkString baseName, SkData* encoded, int sampleSize)
: fData(SkRef(encoded))
, fSampleSize(sampleSize)
{
// Parse filename and the color type to give the benchmark a useful name
fName.printf("AndroidCodec_%s_SampleSize%d", baseName.c_str(), sampleSize);
}
const char* AndroidCodecBench::onGetName() {
return fName.c_str();
}
bool AndroidCodecBench::isSuitableFor(Backend backend) {
return kNonRendering_Backend == backend;
}
void AndroidCodecBench::onDelayedSetup() {
std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(fData));
SkISize scaledSize = codec->getSampledDimensions(fSampleSize);
Revert "SkSurface asynchronous read APIs allow client to extend pixel lifetime" This reverts commit ce240cc6fd8ec95bd051c7df2173dad2ae8f6ad6. Reason for revert: crashing in chrome unit test, abandoned context related? Original change's description: > SkSurface asynchronous read APIs allow client to extend pixel lifetime > > Previously the pixel data passed to the client was only valid during > the client's callback. This meant if the client wanted to defer > processing of the data a copy was necessary. > > Now we pass an object to the callback and the pixel lifetime is tied > to the lifetime of that object. > > The object may be holding a GPU transfer buffer mapped. We don't assume > that the object will be released on the direct GrContext thread. So > when the object is destroyed it posts a message to a new type, > GrClientMappedBufferManager, hanging off the direct context. The direct > context will periodically check for messages and unmap and then unref > buffers so that they can be reused. Currently this is done in > GrContext::performDeferredCleanup() and GrDrawingManager::flush(). > > The old API is kept around for backwards compatibility but it is > reimplemented as a bridge on top of the new mechanism. > > Also a utility function to SkImageInfo is added to directly make a new > info with a specified dimensions rather than passing the width and > height separately to makeWH(). > > Bug: chromium:973403 > Bug: skia:8962 > > Change-Id: Id5cf04235376170142a48e90d3ecd13fd021a2a6 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/245457 > Reviewed-by: Brian Osman <brianosman@google.com> > Commit-Queue: Brian Salomon <bsalomon@google.com> TBR=bsalomon@google.com,brianosman@google.com Change-Id: Ic14cf07a7629b167c9f34a651aa87a0326e74207 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: chromium:973403, skia:8962 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/245721 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
2019-10-02 22:51:08 +00:00
fInfo = codec->getInfo().makeWH(scaledSize.width(), scaledSize.height())
.makeColorType(kN32_SkColorType);
if (kUnpremul_SkAlphaType == fInfo.alphaType()) {
fInfo = fInfo.makeAlphaType(kPremul_SkAlphaType);
}
fPixelStorage.reset(fInfo.computeMinByteSize());
}
void AndroidCodecBench::onDraw(int n, SkCanvas* canvas) {
std::unique_ptr<SkAndroidCodec> codec;
SkAndroidCodec::AndroidOptions options;
options.fSampleSize = fSampleSize;
for (int i = 0; i < n; i++) {
codec = SkAndroidCodec::MakeFromData(fData);
#ifdef SK_DEBUG
const SkCodec::Result result =
#endif
codec->getAndroidPixels(fInfo, fPixelStorage.get(), fInfo.minRowBytes(), &options);
SkASSERT(result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput);
}
}