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