Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: gm/gmmain.cpp

Issue 23567032: Have GMs read the GrContext via a setter/getter rather than a global. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: initialize fGr to NULL Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « gm/gm.cpp ('k') | gm/image.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1460 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 * Sets the global GrContext, accessible by individual GMs 1471 * Sets the global GrContext, accessible by individual GMs
1472 */ 1472 */
1473 static void SetGr(GrContext* grContext) { 1473 static void SetGr(GrContext* grContext) {
1474 SkSafeRef(grContext); 1474 SkSafeRef(grContext);
1475 gGrContext.reset(grContext); 1475 gGrContext.reset(grContext);
1476 } 1476 }
1477 1477
1478 /** 1478 /**
1479 * Gets the global GrContext, can be called by GM tests. 1479 * Gets the global GrContext, can be called by GM tests.
1480 */ 1480 */
1481 GrContext* GetGr(); 1481 static GrContext* GetGr() {
1482 GrContext* GetGr() {
1483 return gGrContext.get(); 1482 return gGrContext.get();
1484 } 1483 }
1485 1484
1486 /** 1485 /**
1487 * Sets the global GrContext and then resets it to its previous value at 1486 * Sets the global GrContext and then resets it to its previous value at
1488 * destruction. 1487 * destruction.
1489 */ 1488 */
1490 class AutoResetGr : SkNoncopyable { 1489 class AutoResetGr : SkNoncopyable {
1491 public: 1490 public:
1492 AutoResetGr() : fOld(NULL) {} 1491 AutoResetGr() : fOld(NULL) {}
1493 void set(GrContext* context) { 1492 void set(GrContext* context) {
1494 SkASSERT(NULL == fOld); 1493 SkASSERT(NULL == fOld);
1495 fOld = GetGr(); 1494 fOld = GetGr();
1496 SkSafeRef(fOld); 1495 SkSafeRef(fOld);
1497 SetGr(context); 1496 SetGr(context);
1498 } 1497 }
1499 ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); } 1498 ~AutoResetGr() { SetGr(fOld); SkSafeUnref(fOld); }
1500 private: 1499 private:
1501 GrContext* fOld; 1500 GrContext* fOld;
1502 }; 1501 };
1503 #else
1504 GrContext* GetGr();
1505 GrContext* GetGr() { return NULL; }
1506 #endif 1502 #endif
1507 } 1503 }
1508 1504
1509 template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) { 1505 template <typename T> void appendUnique(SkTDArray<T>* array, const T& value) {
1510 int index = array->find(value); 1506 int index = array->find(value);
1511 if (index < 0) { 1507 if (index < 0) {
1512 *array->append() = value; 1508 *array->append() = value;
1513 } 1509 }
1514 } 1510 }
1515 1511
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
1582 GrTextureDesc desc; 1578 GrTextureDesc desc;
1583 desc.fConfig = kSkia8888_GrPixelConfig; 1579 desc.fConfig = kSkia8888_GrPixelConfig;
1584 desc.fFlags = kRenderTarget_GrTextureFlagBit; 1580 desc.fFlags = kRenderTarget_GrTextureFlagBit;
1585 desc.fWidth = gm->getISize().width(); 1581 desc.fWidth = gm->getISize().width();
1586 desc.fHeight = gm->getISize().height(); 1582 desc.fHeight = gm->getISize().height();
1587 desc.fSampleCnt = config.fSampleCnt; 1583 desc.fSampleCnt = config.fSampleCnt;
1588 auGpuTarget.reset(gr->createUncachedTexture(desc, NULL, 0)); 1584 auGpuTarget.reset(gr->createUncachedTexture(desc, NULL, 0));
1589 if (NULL != auGpuTarget) { 1585 if (NULL != auGpuTarget) {
1590 gpuTarget = auGpuTarget; 1586 gpuTarget = auGpuTarget;
1591 grSuccess = true; 1587 grSuccess = true;
1592 autogr.set(gr); 1588 autogr.set(gr);
robertphillips 2013/09/16 18:13:38 Why not just "gr"?
mtklein 2013/09/16 18:17:43 No good reason. Got rid of GetGr() entirely.
1589 gm->setGr(GetGr());
1593 // Set the user specified cache limits if non-default. 1590 // Set the user specified cache limits if non-default.
1594 size_t bytes; 1591 size_t bytes;
1595 int count; 1592 int count;
1596 gr->getTextureCacheLimits(&count, &bytes); 1593 gr->getTextureCacheLimits(&count, &bytes);
1597 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) { 1594 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) {
1598 bytes = static_cast<size_t>(gGpuCacheSizeBytes); 1595 bytes = static_cast<size_t>(gGpuCacheSizeBytes);
1599 } 1596 }
1600 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) { 1597 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) {
1601 count = gGpuCacheSizeCount; 1598 count = gGpuCacheSizeCount;
1602 } 1599 }
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
2290 if (FLAGS_forceBWtext) { 2287 if (FLAGS_forceBWtext) {
2291 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); 2288 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref();
2292 } 2289 }
2293 } 2290 }
2294 2291
2295 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) 2292 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
2296 int main(int argc, char * const argv[]) { 2293 int main(int argc, char * const argv[]) {
2297 return tool_main(argc, (char**) argv); 2294 return tool_main(argc, (char**) argv);
2298 } 2295 }
2299 #endif 2296 #endif
OLDNEW
« no previous file with comments | « gm/gm.cpp ('k') | gm/image.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698