1fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot/* 2fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Copyright 2016 Google Inc. 3fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * 4fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * Use of this source code is governed by a BSD-style license that can be 5fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot * found in the LICENSE file. 6fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot */ 7fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 8fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#include "AndroidCodecBench.h" 9fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#include "CodecBenchPriv.h" 10fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#include "SkBitmap.h" 11fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#include "SkAndroidCodec.h" 12fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#include "SkCommandLineFlags.h" 13fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#include "SkOSFile.h" 14fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 15fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team RobotAndroidCodecBench::AndroidCodecBench(SkString baseName, SkData* encoded, int sampleSize) 16fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot : fData(SkRef(encoded)) 17fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot , fSampleSize(sampleSize) 18fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot{ 19fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot // Parse filename and the color type to give the benchmark a useful name 20fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot fName.printf("AndroidCodec_%s_SampleSize%d", baseName.c_str(), sampleSize); 21fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot} 22fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 23fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotconst char* AndroidCodecBench::onGetName() { 24fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return fName.c_str(); 25fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot} 26fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 27fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotbool AndroidCodecBench::isSuitableFor(Backend backend) { 28fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot return kNonRendering_Backend == backend; 29fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot} 30fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 31fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotvoid AndroidCodecBench::onDelayedSetup() { 32fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot std::unique_ptr<SkAndroidCodec> codec(SkAndroidCodec::MakeFromData(fData)); 33fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkISize scaledSize = codec->getSampledDimensions(fSampleSize); 34fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 35fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot fInfo = codec->getInfo().makeWH(scaledSize.width(), scaledSize.height()) 36fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot .makeColorType(kN32_SkColorType); 37fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot if (kUnpremul_SkAlphaType == fInfo.alphaType()) { 38fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot fInfo = fInfo.makeAlphaType(kPremul_SkAlphaType); 39fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 40fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 41fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot fPixelStorage.reset(fInfo.computeMinByteSize()); 42fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot} 43fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot 44fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robotvoid AndroidCodecBench::onDraw(int n, SkCanvas* canvas) { 45fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot std::unique_ptr<SkAndroidCodec> codec; 46fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkAndroidCodec::AndroidOptions options; 47fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot options.fSampleSize = fSampleSize; 48fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot for (int i = 0; i < n; i++) { 49fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot codec = SkAndroidCodec::MakeFromData(fData); 50fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#ifdef SK_DEBUG 51fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot const SkCodec::Result result = 52fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot#endif 53fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot codec->getAndroidPixels(fInfo, fPixelStorage.get(), fInfo.minRowBytes(), &options); 54fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot SkASSERT(result == SkCodec::kSuccess || result == SkCodec::kIncompleteInput); 55fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot } 56fe17456d5e528078ce69b5f15cf7adf1fab963fandroid-build-team Robot} 57