14e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)/* 24e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) * Copyright 2011 Google Inc. 34e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) * 44e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) * Use of this source code is governed by a BSD-style license that can be 54e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) * found in the LICENSE file. 64e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) */ 74e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "Benchmark.h" 8cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "SkCanvas.h" 9cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "SkPathUtils.h" 104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "SkRandom.h" 114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "SkString.h" 124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "SkTime.h" 134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#define H 16 154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#define W 16 164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#define STRIDE 2 174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)//this function is redefined for sample, test, and bench. is there anywhere 194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// I can put it to avoid code duplcation? 204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)static void fillRandomBits( int chars, char* bits ){ 214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) SkRandom rand(SkTime::GetMSecs()); 224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) for (int i = 0; i < chars; ++i){ 244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) bits[i] = rand.nextU(); 254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)static void path_proc(char* bits, SkPath* path) { 291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SkPathUtils::BitsToPath_Path(path, bits, H, W, STRIDE); 301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccistatic void region_proc(char* bits, SkPath* path) { 331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci SkPathUtils::BitsToPath_Region(path, bits, H, W, STRIDE); 341320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci} 351320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 361320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci/// Emulates the mix of rects blitted by gmail during scrolling 371320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass PathUtilsBench : public Benchmark { 381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) typedef void (*Proc)(char*, SkPath*); 391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Proc fProc; 411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) SkString fName; 421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) char* bits[H * STRIDE]; 431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 44cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)public: 45cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) PathUtilsBench(Proc proc, const char name[]) { 46cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) fProc = proc; 47cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) fName.printf("pathUtils_%s", name); 48cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 49cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 50cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) } 51cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 52cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)protected: 53cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) virtual const char* onGetName() { return fName.c_str(); } 545d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void onDraw(const int loops, SkCanvas* canvas) { 565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 575d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) for (int i = 0; i < loops; ++i){ 585d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) //create a random 16x16 bitmap 595d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) fillRandomBits(H * STRIDE, (char*) &bits); 604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 614e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) //use passed function pointer to handle it 62 SkPath path; 63 fProc( (char*) &bits, &path); 64 } 65 } 66 67private: 68 typedef Benchmark INHERITED; 69}; 70 71DEF_BENCH( return SkNEW_ARGS(PathUtilsBench, (path_proc, "path")); ) 72DEF_BENCH( return SkNEW_ARGS(PathUtilsBench, (region_proc, "region")); ) 73