1a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#if !SK_SUPPORT_GPU 2a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#error "GPU support required" 3a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#endif 4a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 5a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "GrContext.h" 6a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "GrContextFactory.h" 7a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "GrRenderTarget.h" 8a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "SkGpuDevice.h" 9a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "gl/GrGLDefines.h" 10a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 11a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "SkBitmap.h" 128f6884aab8aecd7657cf3f9cdbc682f0deca29c5tfarina@chromium.org#include "SkCanvas.h" 13a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "SkColor.h" 14a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "SkDevice.h" 15a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "SkGraphics.h" 16a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "SkImageDecoder.h" 17a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "SkImageEncoder.h" 18a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "SkOSFile.h" 19a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "SkPicture.h" 20a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "SkRTConf.h" 21a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "SkRunnable.h" 228f6884aab8aecd7657cf3f9cdbc682f0deca29c5tfarina@chromium.org#include "SkStream.h" 23a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "SkString.h" 24a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "SkTArray.h" 25a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "SkTDArray.h" 26a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "SkThreadPool.h" 27a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "SkTime.h" 28a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#include "Test.h" 29a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 30a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#ifdef SK_BUILD_FOR_WIN 31a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com #define PATH_SLASH "\\" 32a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com #define IN_DIR "D:\\9-30-13\\" 33a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com #define OUT_DIR "D:\\skpSkGr\\11\\" 34a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com #define LINE_FEED "\r\n" 35a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#else 36a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com #define PATH_SLASH "/" 37a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com #define IN_DIR "/usr/local/google/home/caryclark" PATH_SLASH "9-30-13-skp" 38a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com #define OUT_DIR "/media/01CD75512A7F9EE0/4" PATH_SLASH 3978e7b4e1b928fa69f672be3c743df6d6c3ecbcedtfarina@chromium.org #define LINE_FEED "\n" 40a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#endif 41a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 42a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#define PATH_STR_SIZE 512 43a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 44a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic const struct { 45a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int directory; 46a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com const char* filename; 47a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} skipOverSkGr[] = { 48a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com {1, "http___accuweather_com_.skp"}, // Couldn't convert bitmap to texture.http___absoku072_com_ 49a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com}; 50a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 519e34473d7370a2aedf5b3f85c1d3aec40850829bcommit-bot@chromium.orgstatic const size_t skipOverSkGrCount = SK_ARRAY_COUNT(skipOverSkGr); 52a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 53a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com///////////////////////////////////////// 54a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 55a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comclass SkpSkGrThreadedRunnable; 56a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 57a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comenum TestStep { 58a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com kCompareBits, 59a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com kEncodeFiles, 60a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com}; 61a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 62a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comenum { 63a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com kMaxLength = 128, 64a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com kMaxFiles = 128, 65a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com}; 66a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 67a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstruct TestResult { 68a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com void init(int dirNo) { 69a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com fDirNo = dirNo; 70a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com sk_bzero(fFilename, sizeof(fFilename)); 71a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com fTestStep = kCompareBits; 72a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com fScaleOversized = true; 73a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 74a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 75a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString status() { 76a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString outStr; 77a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com outStr.printf("%s %d %d%s", fFilename, fPixelError, fTime, LINE_FEED); 78a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return outStr; 79a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 80a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 81a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com static void Test(int dirNo, const char* filename, TestStep testStep, bool verbose) { 82a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com TestResult test; 83a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com test.init(dirNo); 84a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com test.fTestStep = testStep; 85a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com strcpy(test.fFilename, filename); 86a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com test.testOne(); 87a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (verbose) { 88a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("%s", test.status().c_str()); 89a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 90a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 91a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 92a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com void test(int dirNo, const SkString& filename) { 93a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com init(dirNo); 94a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com strcpy(fFilename, filename.c_str()); 95a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com testOne(); 96a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 97a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 98a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com void testOne(); 99f54ad6f488845d0fc27734984e39185e15370fbcskia.committer@gmail.com 100a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com char fFilename[kMaxLength]; 101a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com TestStep fTestStep; 102a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int fDirNo; 103a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int fPixelError; 104a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int fTime; 105a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com bool fScaleOversized; 106a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com}; 107a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 108a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstruct SkpSkGrThreadState { 109a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com void init(int dirNo) { 110a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com fResult.init(dirNo); 111a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com fFoundCount = 0; 112a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com fSmallestError = 0; 113a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com sk_bzero(fFilesFound, sizeof(fFilesFound)); 114a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com sk_bzero(fDirsFound, sizeof(fDirsFound)); 115a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com sk_bzero(fError, sizeof(fError)); 116a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 117f54ad6f488845d0fc27734984e39185e15370fbcskia.committer@gmail.com 118a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com char fFilesFound[kMaxFiles][kMaxLength]; 119a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int fDirsFound[kMaxFiles]; 120a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int fError[kMaxFiles]; 121a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int fFoundCount; 122a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int fSmallestError; 123a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com skiatest::Reporter* fReporter; 124a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com TestResult fResult; 125a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com}; 126a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 127a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstruct SkpSkGrThreadedTestRunner { 128a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkpSkGrThreadedTestRunner(skiatest::Reporter* reporter, int threadCount) 129a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com : fNumThreads(threadCount) 130a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com , fReporter(reporter) { 131a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 132a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 133a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com ~SkpSkGrThreadedTestRunner(); 134a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com void render(); 135a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int fNumThreads; 136a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkTDArray<SkpSkGrThreadedRunnable*> fRunnables; 137a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com skiatest::Reporter* fReporter; 138a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com}; 139a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 140a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comclass SkpSkGrThreadedRunnable : public SkRunnable { 141a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.compublic: 142a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkpSkGrThreadedRunnable(void (*testFun)(SkpSkGrThreadState*), int dirNo, const char* str, 143a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkpSkGrThreadedTestRunner* runner) { 144a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkASSERT(strlen(str) < sizeof(fState.fResult.fFilename) - 1); 145a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com fState.init(dirNo); 146a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com strcpy(fState.fResult.fFilename, str); 147a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com fState.fReporter = runner->fReporter; 148a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com fTestFun = testFun; 149a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 150a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 151a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com virtual void run() SK_OVERRIDE { 152a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkGraphics::SetTLSFontCacheLimit(1 * 1024 * 1024); 153a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com (*fTestFun)(&fState); 154a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 155a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 156a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkpSkGrThreadState fState; 157a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com void (*fTestFun)(SkpSkGrThreadState*); 158a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com}; 159a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 160a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comSkpSkGrThreadedTestRunner::~SkpSkGrThreadedTestRunner() { 161a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (int index = 0; index < fRunnables.count(); index++) { 162a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDELETE(fRunnables[index]); 163a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 164a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 165a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 166a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comvoid SkpSkGrThreadedTestRunner::render() { 167a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkThreadPool pool(fNumThreads); 168a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (int index = 0; index < fRunnables.count(); ++ index) { 169a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com pool.add(fRunnables[index]); 170a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 171a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 172a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 173a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com//////////////////////////////////////////////// 174a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 175a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic const char outGrDir[] = OUT_DIR "grTest"; 176a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic const char outSkDir[] = OUT_DIR "skTest"; 177a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic const char outSkpDir[] = OUT_DIR "skpTest"; 178a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic const char outDiffDir[] = OUT_DIR "outTest"; 179a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic const char outStatusDir[] = OUT_DIR "statusTest"; 180a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 181a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic SkString make_filepath(int dirIndex, const char* dir, const char* name) { 182a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString path(dir); 183a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (dirIndex) { 184a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com path.appendf("%d", dirIndex); 185a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 186a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com path.append(PATH_SLASH); 187a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com path.append(name); 188a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return path; 189a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 190a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 191a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic SkString make_in_dir_name(int dirIndex) { 192a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString dirName(IN_DIR); 193a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com dirName.appendf("%d", dirIndex); 194a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!sk_exists(dirName.c_str())) { 195a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("could not read dir %s\n", dirName.c_str()); 196a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return SkString(); 197a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 198a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return dirName; 199a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 200a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 201a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic bool make_out_dirs() { 202a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString outDir = make_filepath(0, OUT_DIR, ""); 203a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!sk_exists(outDir.c_str())) { 204a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!sk_mkdir(outDir.c_str())) { 205a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("could not create dir %s\n", outDir.c_str()); 206a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return false; 207a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 208a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 209a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString grDir = make_filepath(0, outGrDir, ""); 210a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!sk_exists(grDir.c_str())) { 211a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!sk_mkdir(grDir.c_str())) { 212a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("could not create dir %s\n", grDir.c_str()); 213a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return false; 214a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 215a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 216a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString skDir = make_filepath(0, outSkDir, ""); 217a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!sk_exists(skDir.c_str())) { 218a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!sk_mkdir(skDir.c_str())) { 219a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("could not create dir %s\n", skDir.c_str()); 220a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return false; 221a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 222a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 223a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString skpDir = make_filepath(0, outSkpDir, ""); 224a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!sk_exists(skpDir.c_str())) { 225a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!sk_mkdir(skpDir.c_str())) { 226a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("could not create dir %s\n", skpDir.c_str()); 227a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return false; 228a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 229a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 230a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString diffDir = make_filepath(0, outDiffDir, ""); 231a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!sk_exists(diffDir.c_str())) { 232a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!sk_mkdir(diffDir.c_str())) { 233a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("could not create dir %s\n", diffDir.c_str()); 234a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return false; 235a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 236a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 237a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString statusDir = make_filepath(0, outStatusDir, ""); 238a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!sk_exists(statusDir.c_str())) { 239a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!sk_mkdir(statusDir.c_str())) { 240a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("could not create dir %s\n", statusDir.c_str()); 241a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return false; 242a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 243a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 244a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return true; 245a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 246a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 247a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic SkString make_png_name(const char* filename) { 248a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString pngName = SkString(filename); 249a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com pngName.remove(pngName.size() - 3, 3); 250a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com pngName.append("png"); 251a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return pngName; 252a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 253a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 254a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comtypedef GrContextFactory::GLContextType GLContextType; 255a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#ifdef SK_BUILD_FOR_WIN 256a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic const GLContextType kAngle = GrContextFactory::kANGLE_GLContextType; 257a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#else 258a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic const GLContextType kNative = GrContextFactory::kNative_GLContextType; 259a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#endif 260a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 261a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic int similarBits(const SkBitmap& gr, const SkBitmap& sk) { 262a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com const int kRowCount = 3; 263a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com const int kThreshold = 3; 264a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int width = SkTMin(gr.width(), sk.width()); 265a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (width < kRowCount) { 266a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return true; 267a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 268a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int height = SkTMin(gr.height(), sk.height()); 269a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (height < kRowCount) { 270a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return true; 271a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 272a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int errorTotal = 0; 273a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkTArray<char, true> errorRows; 274a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com errorRows.push_back_n(width * kRowCount); 275a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkAutoLockPixels autoGr(gr); 276a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkAutoLockPixels autoSk(sk); 277a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com char* base = &errorRows[0]; 278a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (int y = 0; y < height; ++y) { 279a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkPMColor* grRow = gr.getAddr32(0, y); 280a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkPMColor* skRow = sk.getAddr32(0, y); 281a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com char* cOut = &errorRows[(y % kRowCount) * width]; 282a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (int x = 0; x < width; ++x) { 283a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkPMColor grColor = grRow[x]; 284a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkPMColor skColor = skRow[x]; 285a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int dr = SkGetPackedR32(grColor) - SkGetPackedR32(skColor); 286a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int dg = SkGetPackedG32(grColor) - SkGetPackedG32(skColor); 287a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int db = SkGetPackedB32(grColor) - SkGetPackedB32(skColor); 288a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int error = SkTMax(SkAbs32(dr), SkTMax(SkAbs32(dg), SkAbs32(db))); 289a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if ((cOut[x] = error >= kThreshold) && x >= 2 290a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com && base[x - 2] && base[width + x - 2] && base[width * 2 + x - 2] 291a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com && base[x - 1] && base[width + x - 1] && base[width * 2 + x - 1] 292a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com && base[x - 0] && base[width + x - 0] && base[width * 2 + x - 0]) { 293a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com errorTotal += error; 294a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 295a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 296a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 297a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return errorTotal; 298a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 299a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 300a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic bool addError(SkpSkGrThreadState* data) { 301a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com bool foundSmaller = false; 302a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int dCount = data->fFoundCount; 303a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int pixelError = data->fResult.fPixelError; 304a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (data->fFoundCount < kMaxFiles) { 305a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com data->fError[dCount] = pixelError; 306a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com strcpy(data->fFilesFound[dCount], data->fResult.fFilename); 307a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com data->fDirsFound[dCount] = data->fResult.fDirNo; 308a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com ++data->fFoundCount; 309a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } else if (pixelError > data->fSmallestError) { 310a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int smallest = SK_MaxS32; 311a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int smallestIndex = 0; 312a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (int index = 0; index < kMaxFiles; ++index) { 313a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (smallest > data->fError[index]) { 314a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com smallest = data->fError[index]; 315a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com smallestIndex = index; 316a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 317a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 318a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com data->fError[smallestIndex] = pixelError; 319a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com strcpy(data->fFilesFound[smallestIndex], data->fResult.fFilename); 320a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com data->fDirsFound[smallestIndex] = data->fResult.fDirNo; 321a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com data->fSmallestError = SK_MaxS32; 322a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (int index = 0; index < kMaxFiles; ++index) { 323a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (data->fSmallestError > data->fError[index]) { 324a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com data->fSmallestError = data->fError[index]; 325a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 326a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 327a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("*%d*", data->fSmallestError); 328a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com foundSmaller = true; 329a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 330a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return foundSmaller; 331a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 332a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 333a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic SkMSec timePict(SkPicture* pic, SkCanvas* canvas) { 334a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com canvas->save(); 335a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int pWidth = pic->width(); 336a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int pHeight = pic->height(); 337a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com const int maxDimension = 1000; 338a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com const int slices = 3; 339a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int xInterval = SkTMax(pWidth - maxDimension, 0) / (slices - 1); 340a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int yInterval = SkTMax(pHeight - maxDimension, 0) / (slices - 1); 341f54ad6f488845d0fc27734984e39185e15370fbcskia.committer@gmail.com SkRect rect = {0, 0, SkIntToScalar(SkTMin(maxDimension, pWidth)), 342a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkIntToScalar(SkTMin(maxDimension, pHeight))}; 343a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com canvas->clipRect(rect); 344a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkMSec start = SkTime::GetMSecs(); 345a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (int x = 0; x < slices; ++x) { 346a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (int y = 0; y < slices; ++y) { 347a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com pic->draw(canvas); 348a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com canvas->translate(0, SkIntToScalar(yInterval)); 349a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 350a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com canvas->translate(SkIntToScalar(xInterval), SkIntToScalar(-yInterval * slices)); 351a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 352a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkMSec end = SkTime::GetMSecs(); 353a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com canvas->restore(); 354a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return end - start; 355a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 356a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 357a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic void drawPict(SkPicture* pic, SkCanvas* canvas, int scale) { 358a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com canvas->clear(SK_ColorWHITE); 359a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (scale != 1) { 360a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com canvas->save(); 361a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com canvas->scale(1.0f / scale, 1.0f / scale); 362a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 363a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com pic->draw(canvas); 364a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (scale != 1) { 365a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com canvas->restore(); 366a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 367a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 368a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 369a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic void writePict(const SkBitmap& bitmap, const char* outDir, const char* pngName) { 370a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString outFile = make_filepath(0, outDir, pngName); 371a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!SkImageEncoder::EncodeFile(outFile.c_str(), bitmap, 372a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkImageEncoder::kPNG_Type, 100)) { 373a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("unable to encode gr %s (width=%d height=%d)br \n", pngName, 374a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com bitmap.width(), bitmap.height()); 375a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 376a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 377a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 378a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comvoid TestResult::testOne() { 379a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkPicture* pic = NULL; 380a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com { 381a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString d; 382a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com d.printf(" {%d, \"%s\"},", fDirNo, fFilename); 383a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString path = make_filepath(fDirNo, IN_DIR, fFilename); 384a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkFILEStream stream(path.c_str()); 385a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!stream.isValid()) { 386a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("invalid stream %s\n", path.c_str()); 387a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com goto finish; 388a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 389a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (fTestStep == kEncodeFiles) { 390a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com size_t length = stream.getLength(); 391a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkTArray<char, true> bytes; 392a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com bytes.push_back_n(length); 393a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com stream.read(&bytes[0], length); 394a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com stream.rewind(); 395a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString wPath = make_filepath(0, outSkpDir, fFilename); 396a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkFILEWStream wStream(wPath.c_str()); 397a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com wStream.write(&bytes[0], length); 398a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com wStream.flush(); 399a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 400a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com pic = SkPicture::CreateFromStream(&stream, &SkImageDecoder::DecodeMemory); 401a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!pic) { 402a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("unable to decode %s\n", fFilename); 403a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com goto finish; 404a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 405a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int pWidth = pic->width(); 406a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int pHeight = pic->height(); 407a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int pLargerWH = SkTMax(pWidth, pHeight); 408a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com GrContextFactory contextFactory; 409a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#ifdef SK_BUILD_FOR_WIN 410a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com GrContext* context = contextFactory.get(kAngle); 411a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#else 412a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com GrContext* context = contextFactory.get(kNative); 413a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#endif 414a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (NULL == context) { 415a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("unable to allocate context for %s\n", fFilename); 416a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com goto finish; 417a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 418a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int maxWH = context->getMaxRenderTargetSize(); 419a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int scale = 1; 420a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com while (pLargerWH / scale > maxWH) { 421a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com scale *= 2; 422a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 423a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkBitmap bitmap; 424a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkIPoint dim; 425a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com do { 426a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com dim.fX = (pWidth + scale - 1) / scale; 427a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com dim.fY = (pHeight + scale - 1) / scale; 4289e34473d7370a2aedf5b3f85c1d3aec40850829bcommit-bot@chromium.org bool success = bitmap.allocN32Pixels(dim.fX, dim.fY); 429a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (success) { 430a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com break; 431a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 432a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("-%d-", scale); 433a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } while ((scale *= 2) < 256); 434a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (scale >= 256) { 435a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("unable to allocate bitmap for %s (w=%d h=%d) (sw=%d sh=%d)\n", 436a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com fFilename, pWidth, pHeight, dim.fX, dim.fY); 437a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com goto finish; 438a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 439a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkCanvas skCanvas(bitmap); 440a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com drawPict(pic, &skCanvas, fScaleOversized ? scale : 1); 441a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com GrTextureDesc desc; 442a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com desc.fConfig = kSkia8888_GrPixelConfig; 443a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com desc.fFlags = kRenderTarget_GrTextureFlagBit; 444a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com desc.fWidth = dim.fX; 445a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com desc.fHeight = dim.fY; 446a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com desc.fSampleCnt = 0; 447a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkAutoTUnref<GrTexture> texture(context->createUncachedTexture(desc, NULL, 0)); 448a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!texture) { 449a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("unable to allocate texture for %s (w=%d h=%d)\n", fFilename, 450a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com dim.fX, dim.fY); 451a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com goto finish; 452a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 453a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkGpuDevice grDevice(context, texture.get()); 454a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkCanvas grCanvas(&grDevice); 455a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com drawPict(pic, &grCanvas, fScaleOversized ? scale : 1); 456c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org 457c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org SkBitmap grBitmap; 458c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org grBitmap.allocPixels(grCanvas.imageInfo()); 459c3bd8af6d5722e854feca70c40d92f4954c5b67bcommit-bot@chromium.org grCanvas.readPixels(&grBitmap, 0, 0); 46002d6f546161e2c98d69066373cec3f54f3c46252skia.committer@gmail.com 461a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (fTestStep == kCompareBits) { 462a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com fPixelError = similarBits(grBitmap, bitmap); 463a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int skTime = timePict(pic, &skCanvas); 464a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int grTime = timePict(pic, &grCanvas); 465a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com fTime = skTime - grTime; 466a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } else if (fTestStep == kEncodeFiles) { 467a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString pngStr = make_png_name(fFilename); 468a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com const char* pngName = pngStr.c_str(); 469a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com writePict(grBitmap, outGrDir, pngName); 470a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com writePict(bitmap, outSkDir, pngName); 471a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 472a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 473a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comfinish: 474a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDELETE(pic); 475a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 476a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 477a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic SkString makeStatusString(int dirNo) { 478a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString statName; 479a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com statName.printf("stats%d.txt", dirNo); 480a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString statusFile = make_filepath(0, outStatusDir, statName.c_str()); 481a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return statusFile; 482a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 483a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 484a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comclass PreParser { 485a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.compublic: 486a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com PreParser(int dirNo) 487a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com : fDirNo(dirNo) 488a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com , fIndex(0) 489a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com , fStatusPath(makeStatusString(dirNo)) { 490a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!sk_exists(fStatusPath.c_str())) { 491a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return; 492a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 493a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkFILEStream reader; 494a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com reader.setPath(fStatusPath.c_str()); 495a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com while (fetch(reader, &fResults.push_back())) 496a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com ; 497a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com fResults.pop_back(); 498a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 499a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 500a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com bool fetch(SkFILEStream& reader, TestResult* result) { 501a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com char c; 502a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int i = 0; 503a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com result->init(fDirNo); 504a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com result->fPixelError = 0; 505a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com result->fTime = 0; 506a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com do { 507a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com bool readOne = reader.read(&c, 1) != 0; 508a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!readOne) { 509a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkASSERT(i == 0); 510a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return false; 511a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 512a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (c == ' ') { 513a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com result->fFilename[i++] = '\0'; 514a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com break; 515a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 516a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com result->fFilename[i++] = c; 517a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkASSERT(i < kMaxLength); 518a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } while (true); 519a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com do { 520a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkAssertResult(reader.read(&c, 1) != 0); 521a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (c == ' ') { 522a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com break; 523a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 524a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkASSERT(c >= '0' && c <= '9'); 525a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com result->fPixelError = result->fPixelError * 10 + (c - '0'); 526a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } while (true); 527a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com bool minus = false; 528a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com do { 529a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (reader.read(&c, 1) == 0) { 530a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com break; 531a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 532a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (c == '\r' && reader.read(&c, 1) == 0) { 533a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com break; 534a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 535a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (c == '\n') { 536a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com break; 537a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 538a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (c == '-') { 539a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com minus = true; 540a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com continue; 541a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 542a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkASSERT(c >= '0' && c <= '9'); 543a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com result->fTime = result->fTime * 10 + (c - '0'); 544a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } while (true); 545a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (minus) { 546a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com result->fTime = -result->fTime; 547a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 548a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return true; 549a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 550a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 551a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com bool match(const SkString& filename, SkFILEWStream* stream, TestResult* result) { 552a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (fIndex < fResults.count()) { 553a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com *result = fResults[fIndex++]; 554a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkASSERT(filename.equals(result->fFilename)); 555a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString outStr(result->status()); 556a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com stream->write(outStr.c_str(), outStr.size()); 557a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com stream->flush(); 558a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return true; 559a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 560a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return false; 561a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 562a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 563a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comprivate: 564a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int fDirNo; 565a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int fIndex; 566a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkTArray<TestResult, true> fResults; 567a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString fStatusPath; 568a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com}; 569a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 570a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic bool initTest() { 571a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#if !defined SK_BUILD_FOR_WIN && !defined SK_BUILD_FOR_MAC 572a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SK_CONF_SET("images.jpeg.suppressDecoderWarnings", true); 573a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SK_CONF_SET("images.png.suppressDecoderWarnings", true); 574a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com#endif 575a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return make_out_dirs(); 576a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 577a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 57878e7b4e1b928fa69f672be3c743df6d6c3ecbcedtfarina@chromium.orgDEF_TEST(SkpSkGr, reporter) { 579a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkTArray<TestResult, true> errors; 580a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!initTest()) { 581a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return; 582a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 583a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkpSkGrThreadState state; 584a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com state.init(0); 585a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int smallCount = 0; 586a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (int dirNo = 1; dirNo <= 100; ++dirNo) { 587a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString pictDir = make_in_dir_name(dirNo); 588a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkASSERT(pictDir.size()); 589a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (reporter->verbose()) { 590a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("dirNo=%d\n", dirNo); 591a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 592a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkOSFile::Iter iter(pictDir.c_str(), "skp"); 593a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString filename; 594a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int testCount = 0; 595a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com PreParser preParser(dirNo); 596a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkFILEWStream statusStream(makeStatusString(dirNo).c_str()); 597a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com while (iter.next(&filename)) { 598a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (size_t index = 0; index < skipOverSkGrCount; ++index) { 599a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (skipOverSkGr[index].directory == dirNo 600a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com && strcmp(filename.c_str(), skipOverSkGr[index].filename) == 0) { 601a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com goto skipOver; 602a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 603a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 604a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (preParser.match(filename, &statusStream, &state.fResult)) { 605a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com addError(&state); 606a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com ++testCount; 607a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com goto checkEarlyExit; 608a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 609a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (state.fSmallestError > 5000000) { 610a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com goto breakOut; 611a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 612a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com { 613a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com TestResult& result = state.fResult; 614a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com result.test(dirNo, filename); 615a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString outStr(result.status()); 616a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com statusStream.write(outStr.c_str(), outStr.size()); 617a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com statusStream.flush(); 618a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (1) { 619a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("%s", outStr.c_str()); 620a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 621a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com bool noMatch = addError(&state); 622a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (noMatch) { 623a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com smallCount = 0; 624a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } else if (++smallCount > 10000) { 625a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com goto breakOut; 626a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 627a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 628a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com ++testCount; 629a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (reporter->verbose()) { 630a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (testCount % 100 == 0) { 631a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("#%d\n", testCount); 632a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 633a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 63478e7b4e1b928fa69f672be3c743df6d6c3ecbcedtfarina@chromium.org skipOver: 63578e7b4e1b928fa69f672be3c743df6d6c3ecbcedtfarina@chromium.org reporter->bumpTestCount(); 636a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com checkEarlyExit: 637a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (1 && testCount == 20) { 638a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com break; 639a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 640a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 641a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 642a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.combreakOut: 643a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (reporter->verbose()) { 644a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (int index = 0; index < state.fFoundCount; ++index) { 645a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("%d %s %d\n", state.fDirsFound[index], state.fFilesFound[index], 646a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com state.fError[index]); 647a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 648a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 649a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (int index = 0; index < state.fFoundCount; ++index) { 650a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com TestResult::Test(state.fDirsFound[index], state.fFilesFound[index], kEncodeFiles, 651a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com reporter->verbose()); 652a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (reporter->verbose()) SkDebugf("+"); 653a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 654a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 655a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 656a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic void bumpCount(skiatest::Reporter* reporter, bool skipping) { 657a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (reporter->verbose()) { 658a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com static int threadTestCount; 659a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com sk_atomic_inc(&threadTestCount); 660a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!skipping && threadTestCount % 100 == 0) { 661a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("#%d\n", threadTestCount); 662a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 663a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (skipping && threadTestCount % 10000 == 0) { 664a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("#%d\n", threadTestCount); 665a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 666a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 667a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 668a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 669a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.comstatic void testSkGrMain(SkpSkGrThreadState* data) { 670a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com data->fResult.testOne(); 671a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com bumpCount(data->fReporter, false); 672a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com data->fReporter->bumpTestCount(); 673a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 674a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 67578e7b4e1b928fa69f672be3c743df6d6c3ecbcedtfarina@chromium.orgDEF_TEST(SkpSkGrThreaded, reporter) { 676a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!initTest()) { 677a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return; 678a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 679a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int threadCount = reporter->allowThreaded() ? 3 : 1; 680a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkpSkGrThreadedTestRunner testRunner(reporter, threadCount); 681a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (int dirIndex = 1; dirIndex <= 100; ++dirIndex) { 682a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString pictDir = make_in_dir_name(dirIndex); 683a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (pictDir.size() == 0) { 684a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com continue; 685a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 686a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkOSFile::Iter iter(pictDir.c_str(), "skp"); 687a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString filename; 688a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com while (iter.next(&filename)) { 689a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString pngName = make_png_name(filename.c_str()); 690a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString oldPng = make_filepath(dirIndex, outSkDir, pngName.c_str()); 691a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString newPng = make_filepath(dirIndex, outGrDir, pngName.c_str()); 692a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (sk_exists(oldPng.c_str()) && sk_exists(newPng.c_str())) { 693a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com bumpCount(reporter, true); 694a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com continue; 695a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 696a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (size_t index = 0; index < skipOverSkGrCount; ++index) { 697a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (skipOverSkGr[index].directory == dirIndex 698a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com && strcmp(filename.c_str(), skipOverSkGr[index].filename) == 0) { 699a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com bumpCount(reporter, true); 700a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com goto skipOver; 701a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 702a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 703a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com *testRunner.fRunnables.append() = SkNEW_ARGS(SkpSkGrThreadedRunnable, 704a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com (&testSkGrMain, dirIndex, filename.c_str(), &testRunner)); 705a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com skipOver: 706a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com ; 707a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 708a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 709a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com testRunner.render(); 710a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkpSkGrThreadState& max = testRunner.fRunnables[0]->fState; 711a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (int dirIndex = 2; dirIndex <= 100; ++dirIndex) { 712a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkpSkGrThreadState& state = testRunner.fRunnables[dirIndex - 1]->fState; 713a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (int index = 0; index < state.fFoundCount; ++index) { 714a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int maxIdx = max.fFoundCount; 715a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (maxIdx < kMaxFiles) { 716a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com max.fError[maxIdx] = state.fError[index]; 717a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com strcpy(max.fFilesFound[maxIdx], state.fFilesFound[index]); 718a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com max.fDirsFound[maxIdx] = state.fDirsFound[index]; 719a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com ++max.fFoundCount; 720a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com continue; 721a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 722a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (maxIdx = 0; maxIdx < max.fFoundCount; ++maxIdx) { 723a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (max.fError[maxIdx] < state.fError[index]) { 724a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com max.fError[maxIdx] = state.fError[index]; 725a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com strcpy(max.fFilesFound[maxIdx], state.fFilesFound[index]); 726a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com max.fDirsFound[maxIdx] = state.fDirsFound[index]; 727a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com break; 728a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 729a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 730a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 731a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 732a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com TestResult encoder; 733a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com encoder.fTestStep = kEncodeFiles; 734a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com for (int index = 0; index < max.fFoundCount; ++index) { 735a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com encoder.fDirNo = max.fDirsFound[index]; 736a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com strcpy(encoder.fFilename, max.fFilesFound[index]); 737a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com encoder.testOne(); 738a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkDebugf("+"); 739a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 740a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 741a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com 74278e7b4e1b928fa69f672be3c743df6d6c3ecbcedtfarina@chromium.orgDEF_TEST(SkpSkGrOneOff, reporter) { 743a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (!initTest()) { 744a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return; 745a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 746a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int testIndex = 166; 747a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com int dirIndex = skipOverSkGr[testIndex - 166].directory; 748a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString pictDir = make_in_dir_name(dirIndex); 749a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com if (pictDir.size() == 0) { 750a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com return; 751a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com } 752a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com SkString filename(skipOverSkGr[testIndex - 166].filename); 753a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com TestResult::Test(dirIndex, filename.c_str(), kCompareBits, reporter->verbose()); 754a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com TestResult::Test(dirIndex, filename.c_str(), kEncodeFiles, reporter->verbose()); 755a2bbc6e19d5332e81784e582c290cc060f40c4c7caryclark@google.com} 756