1 /* 2 * Copyright 2012 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 #ifndef PathOpsThreadedCommon_DEFINED 8 #define PathOpsThreadedCommon_DEFINED 9 10 #include "SkBitmap.h" 11 #include "SkGraphics.h" 12 #include "SkPath.h" 13 #include "SkPathOps.h" 14 #include "SkTDArray.h" 15 16 #include <string> 17 18 #define PATH_STR_SIZE 512 19 20 class PathOpsThreadedRunnable; 21 22 namespace skiatest { 23 class Reporter; 24 } 25 26 struct PathOpsThreadState { 27 unsigned char fA; 28 unsigned char fB; 29 unsigned char fC; 30 unsigned char fD; 31 std::string fPathStr; 32 const char* fKey; 33 char fSerialNo[256]; 34 skiatest::Reporter* fReporter; 35 SkBitmap* fBitmap; 36 37 void outputProgress(const char* pathStr, SkPath::FillType); 38 void outputProgress(const char* pathStr, SkPathOp); 39 }; 40 41 class PathOpsThreadedTestRunner { 42 public: PathOpsThreadedTestRunner(skiatest::Reporter * reporter)43 PathOpsThreadedTestRunner(skiatest::Reporter* reporter) : fReporter(reporter) {} 44 45 ~PathOpsThreadedTestRunner(); 46 47 void render(); 48 49 public: 50 SkTDArray<PathOpsThreadedRunnable*> fRunnables; 51 skiatest::Reporter* fReporter; 52 }; 53 54 class PathOpsThreadedRunnable { 55 public: PathOpsThreadedRunnable(void (* testFun)(PathOpsThreadState *),int a,int b,int c,int d,PathOpsThreadedTestRunner * runner)56 PathOpsThreadedRunnable(void (*testFun)(PathOpsThreadState*), int a, int b, int c, int d, 57 PathOpsThreadedTestRunner* runner) { 58 fState.fA = a; 59 fState.fB = b; 60 fState.fC = c; 61 fState.fD = d; 62 fState.fReporter = runner->fReporter; 63 fTestFun = testFun; 64 } 65 PathOpsThreadedRunnable(void (* testFun)(PathOpsThreadState *),const char * str,PathOpsThreadedTestRunner * runner)66 PathOpsThreadedRunnable(void (*testFun)(PathOpsThreadState*), const char* str, 67 PathOpsThreadedTestRunner* runner) { 68 SkASSERT(strlen(str) < sizeof(fState.fSerialNo) - 1); 69 strcpy(fState.fSerialNo, str); 70 fState.fReporter = runner->fReporter; 71 fTestFun = testFun; 72 } 73 PathOpsThreadedRunnable(void (* testFun)(PathOpsThreadState *),int dirNo,const char * str,PathOpsThreadedTestRunner * runner)74 PathOpsThreadedRunnable(void (*testFun)(PathOpsThreadState*), int dirNo, const char* str, 75 PathOpsThreadedTestRunner* runner) { 76 SkASSERT(strlen(str) < sizeof(fState.fSerialNo) - 1); 77 fState.fA = dirNo; 78 strcpy(fState.fSerialNo, str); 79 fState.fReporter = runner->fReporter; 80 fTestFun = testFun; 81 } 82 operator()83 void operator()() { 84 SkBitmap bitmap; 85 fState.fBitmap = &bitmap; 86 SkGraphics::SetTLSFontCacheLimit(1 * 1024 * 1024); 87 (*fTestFun)(&fState); 88 } 89 90 private: 91 PathOpsThreadState fState; 92 void (*fTestFun)(PathOpsThreadState*); 93 }; 94 95 #endif 96