OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 /* | 8 /* |
9 * Code for the "gm" (Golden Master) rendering comparison tool. | 9 * Code for the "gm" (Golden Master) rendering comparison tool. |
10 * | 10 * |
(...skipping 1446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1457 | 1457 |
1458 static const PDFRasterizerData* findPDFRasterizer(const char rasterizer[]) { | 1458 static const PDFRasterizerData* findPDFRasterizer(const char rasterizer[]) { |
1459 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); i++) { | 1459 for (int i = 0; i < (int)SK_ARRAY_COUNT(kPDFRasterizers); i++) { |
1460 if (!strcmp(rasterizer, kPDFRasterizers[i].fName)) { | 1460 if (!strcmp(rasterizer, kPDFRasterizers[i].fName)) { |
1461 return &kPDFRasterizers[i]; | 1461 return &kPDFRasterizers[i]; |
1462 } | 1462 } |
1463 } | 1463 } |
1464 return NULL; | 1464 return NULL; |
1465 } | 1465 } |
1466 | 1466 |
1467 namespace skiagm { | |
1468 #if SK_SUPPORT_GPU | |
1469 SkAutoTUnref<GrContext> gGrContext; | |
1470 /** | |
1471 * Sets the global GrContext, accessible by individual GMs | |
1472 */ | |
1473 static void SetGr(GrContext* grContext) { | |
1474 SkSafeRef(grContext); | |
1475 gGrContext.reset(grContext); | |
1476 } | |
1477 | |
1478 /** | |
1479 * Gets the global GrContext, can be called by GM tests. | |
1480 */ | |
1481 GrContext* GetGr(); | |
1482 GrContext* GetGr() { | |
1483 return gGrContext.get(); | |
1484 } | |
1485 | |
1486 /** | |
1487 * Sets the global GrContext and then resets it to its previous value at | |
1488 * destruction. | |
1489 */ | |
1490 class AutoResetGr : SkNoncopyable { | |
1491 public: | |
1492 AutoResetGr() : fOld(NULL) {} | |
1493 void set(GrContext* context) { | |
1494 SkASSERT(NULL == fOld); | |
1495 fOld = GetGr(); | |
1496 SkSafeRef(fOld); | |
1497 SetGr(context); | |
1498 } | |
1499 ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); } | |
1500 private: | |
1501 GrContext* fOld; | |
1502 }; | |
1503 #else | |
1504 GrContext* GetGr(); | |
1505 GrContext* GetGr() { return NULL; } | |
1506 #endif | |
1507 } | |
1508 | |
1509 template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) { | 1467 template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) { |
1510 int index = array->find(value); | 1468 int index = array->find(value); |
1511 if (index < 0) { | 1469 if (index < 0) { |
1512 *array->append() = value; | 1470 *array->append() = value; |
1513 } | 1471 } |
1514 } | 1472 } |
1515 | 1473 |
1516 /** | 1474 /** |
1517 * Run this test in a number of different configs (8888, 565, PDF, | 1475 * Run this test in a number of different configs (8888, 565, PDF, |
1518 * etc.), confirming that the resulting bitmaps match expectations | 1476 * etc.), confirming that the resulting bitmaps match expectations |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1566 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType); | 1524 errorsForAllConfigs.add(kIntentionallySkipped_ErrorType); |
1567 continue; | 1525 continue; |
1568 } | 1526 } |
1569 | 1527 |
1570 // Now we know that we want to run this test and record its | 1528 // Now we know that we want to run this test and record its |
1571 // success or failure. | 1529 // success or failure. |
1572 ErrorCombination errorsForThisConfig; | 1530 ErrorCombination errorsForThisConfig; |
1573 GrSurface* gpuTarget = NULL; | 1531 GrSurface* gpuTarget = NULL; |
1574 #if SK_SUPPORT_GPU | 1532 #if SK_SUPPORT_GPU |
1575 SkAutoTUnref<GrSurface> auGpuTarget; | 1533 SkAutoTUnref<GrSurface> auGpuTarget; |
1576 AutoResetGr autogr; | |
1577 if ((errorsForThisConfig.isEmpty()) && (kGPU_Backend == config.fBackend)
) { | 1534 if ((errorsForThisConfig.isEmpty()) && (kGPU_Backend == config.fBackend)
) { |
1578 GrContext* gr = grFactory->get(config.fGLContextType); | 1535 GrContext* gr = grFactory->get(config.fGLContextType); |
1579 bool grSuccess = false; | 1536 bool grSuccess = false; |
1580 if (gr) { | 1537 if (gr) { |
1581 // create a render target to back the device | 1538 // create a render target to back the device |
1582 GrTextureDesc desc; | 1539 GrTextureDesc desc; |
1583 desc.fConfig = kSkia8888_GrPixelConfig; | 1540 desc.fConfig = kSkia8888_GrPixelConfig; |
1584 desc.fFlags = kRenderTarget_GrTextureFlagBit; | 1541 desc.fFlags = kRenderTarget_GrTextureFlagBit; |
1585 desc.fWidth = gm->getISize().width(); | 1542 desc.fWidth = gm->getISize().width(); |
1586 desc.fHeight = gm->getISize().height(); | 1543 desc.fHeight = gm->getISize().height(); |
1587 desc.fSampleCnt = config.fSampleCnt; | 1544 desc.fSampleCnt = config.fSampleCnt; |
1588 auGpuTarget.reset(gr->createUncachedTexture(desc, NULL, 0)); | 1545 auGpuTarget.reset(gr->createUncachedTexture(desc, NULL, 0)); |
1589 if (NULL != auGpuTarget) { | 1546 if (NULL != auGpuTarget) { |
1590 gpuTarget = auGpuTarget; | 1547 gpuTarget = auGpuTarget; |
1591 grSuccess = true; | 1548 grSuccess = true; |
1592 autogr.set(gr); | |
1593 // Set the user specified cache limits if non-default. | 1549 // Set the user specified cache limits if non-default. |
1594 size_t bytes; | 1550 size_t bytes; |
1595 int count; | 1551 int count; |
1596 gr->getTextureCacheLimits(&count, &bytes); | 1552 gr->getTextureCacheLimits(&count, &bytes); |
1597 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) { | 1553 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) { |
1598 bytes = static_cast<size_t>(gGpuCacheSizeBytes); | 1554 bytes = static_cast<size_t>(gGpuCacheSizeBytes); |
1599 } | 1555 } |
1600 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) { | 1556 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) { |
1601 count = gGpuCacheSizeCount; | 1557 count = gGpuCacheSizeCount; |
1602 } | 1558 } |
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2290 if (FLAGS_forceBWtext) { | 2246 if (FLAGS_forceBWtext) { |
2291 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); | 2247 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); |
2292 } | 2248 } |
2293 } | 2249 } |
2294 | 2250 |
2295 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) | 2251 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) |
2296 int main(int argc, char * const argv[]) { | 2252 int main(int argc, char * const argv[]) { |
2297 return tool_main(argc, (char**) argv); | 2253 return tool_main(argc, (char**) argv); |
2298 } | 2254 } |
2299 #endif | 2255 #endif |
OLD | NEW |