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 "include/core/SkBitmap.h" 11 #include "include/core/SkGraphics.h" 12 #include "include/core/SkPath.h" 13 #include "include/pathops/SkPathOps.h" 14 #include "include/private/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 } // namespace skiatest 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, SkPathFillType); 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 & 0xFF); 59 fState.fB = (b & 0xFF); 60 fState.fC = (c & 0xFF); 61 fState.fD = (d & 0xFF); 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 (*fTestFun)(&fState); 87 } 88 89 private: 90 PathOpsThreadState fState; 91 void (*fTestFun)(PathOpsThreadState*); 92 }; 93 94 #endif 95