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