BitmapRegionDecoderBench.cpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #include "bench/BitmapRegionDecoderBench.h"
  8. #include "bench/CodecBenchPriv.h"
  9. #include "include/core/SkBitmap.h"
  10. #include "src/core/SkOSFile.h"
  11. BitmapRegionDecoderBench::BitmapRegionDecoderBench(const char* baseName, SkData* encoded,
  12. SkColorType colorType, uint32_t sampleSize, const SkIRect& subset)
  13. : fBRD(nullptr)
  14. , fData(SkRef(encoded))
  15. , fColorType(colorType)
  16. , fSampleSize(sampleSize)
  17. , fSubset(subset)
  18. {
  19. // Choose a useful name for the color type
  20. const char* colorName = color_type_to_str(colorType);
  21. fName.printf("BRD_%s_%s", baseName, colorName);
  22. if (1 != sampleSize) {
  23. fName.appendf("_%.3f", 1.0f / (float) sampleSize);
  24. }
  25. }
  26. const char* BitmapRegionDecoderBench::onGetName() {
  27. return fName.c_str();
  28. }
  29. bool BitmapRegionDecoderBench::isSuitableFor(Backend backend) {
  30. return kNonRendering_Backend == backend;
  31. }
  32. void BitmapRegionDecoderBench::onDelayedSetup() {
  33. fBRD.reset(SkBitmapRegionDecoder::Create(fData, SkBitmapRegionDecoder::kAndroidCodec_Strategy));
  34. }
  35. void BitmapRegionDecoderBench::onDraw(int n, SkCanvas* canvas) {
  36. auto ct = fBRD->computeOutputColorType(fColorType);
  37. auto cs = fBRD->computeOutputColorSpace(ct, nullptr);
  38. for (int i = 0; i < n; i++) {
  39. SkBitmap bm;
  40. SkAssertResult(fBRD->decodeRegion(&bm, nullptr, fSubset, fSampleSize, ct, false, cs));
  41. }
  42. }