AndroidCodecBench.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * Copyright 2016 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. #include "bench/AndroidCodecBench.h"
  8. #include "bench/CodecBenchPriv.h"
  9. #include "include/codec/SkAndroidCodec.h"
  10. #include "include/core/SkBitmap.h"
  11. #include "src/core/SkOSFile.h"
  12. #include "tools/flags/CommandLineFlags.h"
  13. AndroidCodecBench::AndroidCodecBench(SkString baseName, SkData* encoded, int sampleSize)
  14. : fData(SkRef(encoded))
  15. , fSampleSize(sampleSize)
  16. {
  17. // Parse filename and the color type to give the benchmark a useful name
  18. fName.printf("AndroidCodec_%s_SampleSize%d", baseName.c_str(), sampleSize);
  19. }
  20. const char* AndroidCodecBench::onGetName() {
  21. return fName.c_str();
  22. }
  23. bool AndroidCodecBench::isSuitableFor(Backend backend) {
  24. return kNonRendering_Backend == backend;
  25. }
  26. void AndroidCodecBench::onDelayedSetup() {
  27. std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(fData));
  28. SkISize scaledSize = codec->getSampledDimensions(fSampleSize);
  29. fInfo = codec->getInfo().makeWH(scaledSize.width(), scaledSize.height())
  30. .makeColorType(kN32_SkColorType);
  31. if (kUnpremul_SkAlphaType == fInfo.alphaType()) {
  32. fInfo = fInfo.makeAlphaType(kPremul_SkAlphaType);
  33. }
  34. fPixelStorage.reset(fInfo.computeMinByteSize());
  35. }
  36. void AndroidCodecBench::onDraw(int n, SkCanvas* canvas) {
  37. std::unique_ptr<SkAndroidCodec> codec;
  38. SkAndroidCodec::AndroidOptions options;
  39. options.fSampleSize = fSampleSize;
  40. for (int i = 0; i < n; i++) {
  41. codec = SkAndroidCodec::MakeFromData(fData);
  42. #ifdef SK_DEBUG
  43. const SkCodec::Result result =
  44. #endif
  45. codec->getAndroidPixels(fInfo, fPixelStorage.get(), fInfo.minRowBytes(), &options);
  46. SkASSERT(result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput);
  47. }
  48. }