Home | History | Annotate | Download | only in bench
      1 
      2 /*
      3  * Copyright 2011 Google Inc.
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 #include "Benchmark.h"
      9 #include "SkBitmap.h"
     10 #include "SkCommandLineFlags.h"
     11 #include "SkImageDecoder.h"
     12 #include "SkOSFile.h"
     13 #include "SkString.h"
     14 #include "sk_tool_utils.h"
     15 
     16 DEFINE_string(decodeBenchFilename, "resources/CMYK.jpeg", "Path to image for DecodeBench.");
     17 
     18 class DecodeBench : public Benchmark {
     19     const SkColorType fPrefColorType;
     20     SkString          fName;
     21 public:
     22     DecodeBench(SkColorType ct) : fPrefColorType(ct) {
     23         SkString fname = SkOSPath::SkBasename(FLAGS_decodeBenchFilename[0]);
     24         fName.printf("decode_%s_%s", sk_tool_utils::colortype_name(ct), fname.c_str());
     25     }
     26 
     27     virtual bool isSuitableFor(Backend backend) SK_OVERRIDE {
     28         return backend == kNonRendering_Backend;
     29     }
     30 
     31 protected:
     32     virtual const char* onGetName() {
     33         return fName.c_str();
     34     }
     35 
     36     virtual void onDraw(const int loops, SkCanvas*) {
     37         for (int i = 0; i < loops; i++) {
     38             SkBitmap bm;
     39             SkImageDecoder::DecodeFile(FLAGS_decodeBenchFilename[0], &bm, fPrefColorType,
     40                                        SkImageDecoder::kDecodePixels_Mode);
     41         }
     42     }
     43 
     44 private:
     45     typedef Benchmark INHERITED;
     46 };
     47 
     48 DEF_BENCH( return new DecodeBench(kN32_SkColorType); )
     49 DEF_BENCH( return new DecodeBench(kRGB_565_SkColorType); )
     50 DEF_BENCH( return new DecodeBench(kARGB_4444_SkColorType); )
     51