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

Side by Side Diff: gm/gmmain.cpp

Issue 13211002: Make GM render to render targets that are also textures. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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 | « no previous file | include/gpu/SkGpuDevice.h » ('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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #pragma warning(push) 43 #pragma warning(push)
44 #pragma warning(disable : 4530) 44 #pragma warning(disable : 4530)
45 #endif 45 #endif
46 #include "json/value.h" 46 #include "json/value.h"
47 #ifdef SK_BUILD_FOR_WIN 47 #ifdef SK_BUILD_FOR_WIN
48 #pragma warning(pop) 48 #pragma warning(pop)
49 #endif 49 #endif
50 50
51 #if SK_SUPPORT_GPU 51 #if SK_SUPPORT_GPU
52 #include "GrContextFactory.h" 52 #include "GrContextFactory.h"
53 #include "GrRenderTarget.h"
54 #include "SkGpuDevice.h" 53 #include "SkGpuDevice.h"
55 typedef GrContextFactory::GLContextType GLContextType; 54 typedef GrContextFactory::GLContextType GLContextType;
56 #define DEFAULT_CACHE_VALUE -1 55 #define DEFAULT_CACHE_VALUE -1
57 static int gGpuCacheSizeBytes; 56 static int gGpuCacheSizeBytes;
58 static int gGpuCacheSizeCount; 57 static int gGpuCacheSizeCount;
59 #else 58 #else
60 class GrContextFactory; 59 class GrContextFactory;
61 class GrContext; 60 class GrContext;
62 class GrRenderTarget; 61 class GrSurface;
63 typedef int GLContextType; 62 typedef int GLContextType;
64 #endif 63 #endif
65 64
66 extern bool gSkSuppressFontCachePurgeSpew; 65 extern bool gSkSuppressFontCachePurgeSpew;
67 66
68 #ifdef SK_SUPPORT_PDF 67 #ifdef SK_SUPPORT_PDF
69 #include "SkPDFDevice.h" 68 #include "SkPDFDevice.h"
70 #include "SkPDFDocument.h" 69 #include "SkPDFDocument.h"
71 #endif 70 #endif
72 71
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 if (!isPDF) { 365 if (!isPDF) {
367 canvas->concat(gm->getInitialTransform()); 366 canvas->concat(gm->getInitialTransform());
368 } 367 }
369 installFilter(canvas); 368 installFilter(canvas);
370 gm->setCanvasIsDeferred(isDeferred); 369 gm->setCanvasIsDeferred(isDeferred);
371 gm->draw(canvas); 370 gm->draw(canvas);
372 canvas->setDrawFilter(NULL); 371 canvas->setDrawFilter(NULL);
373 } 372 }
374 373
375 static ErrorCombination generate_image(GM* gm, const ConfigData& gRec, 374 static ErrorCombination generate_image(GM* gm, const ConfigData& gRec,
376 GrContext* context, 375 GrSurface* gpuTarget,
377 GrRenderTarget* rt,
378 SkBitmap* bitmap, 376 SkBitmap* bitmap,
379 bool deferred) { 377 bool deferred) {
380 SkISize size (gm->getISize()); 378 SkISize size (gm->getISize());
381 setup_bitmap(gRec, size, bitmap); 379 setup_bitmap(gRec, size, bitmap);
382 380
383 SkAutoTUnref<SkCanvas> canvas; 381 SkAutoTUnref<SkCanvas> canvas;
384 382
385 if (gRec.fBackend == kRaster_Backend) { 383 if (gRec.fBackend == kRaster_Backend) {
386 SkAutoTUnref<SkDevice> device(new SkDevice(*bitmap)); 384 SkAutoTUnref<SkDevice> device(new SkDevice(*bitmap));
387 if (deferred) { 385 if (deferred) {
388 canvas.reset(new SkDeferredCanvas(device)); 386 canvas.reset(new SkDeferredCanvas(device));
389 } else { 387 } else {
390 canvas.reset(new SkCanvas(device)); 388 canvas.reset(new SkCanvas(device));
391 } 389 }
392 invokeGM(gm, canvas, false, deferred); 390 invokeGM(gm, canvas, false, deferred);
393 canvas->flush(); 391 canvas->flush();
394 } 392 }
395 #if SK_SUPPORT_GPU 393 #if SK_SUPPORT_GPU
396 else { // GPU 394 else { // GPU
397 if (NULL == context) { 395 SkAutoTUnref<SkDevice> device(SkGpuDevice::Create(gpuTarget));
398 return ErrorCombination(kNoGpuContext_ErrorType);
399 }
400 SkAutoTUnref<SkDevice> device(new SkGpuDevice(context, rt));
401 if (deferred) { 396 if (deferred) {
402 canvas.reset(new SkDeferredCanvas(device)); 397 canvas.reset(new SkDeferredCanvas(device));
403 } else { 398 } else {
404 canvas.reset(new SkCanvas(device)); 399 canvas.reset(new SkCanvas(device));
405 } 400 }
406 invokeGM(gm, canvas, false, deferred); 401 invokeGM(gm, canvas, false, deferred);
407 // the device is as large as the current rendertarget, so 402 // the device is as large as the current rendertarget, so
408 // we explicitly only readback the amount we expect (in 403 // we explicitly only readback the amount we expect (in
409 // size) overwrite our previous allocation 404 // size) overwrite our previous allocation
410 bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth, 405 bitmap->setConfig(SkBitmap::kARGB_8888_Config, size.fWidth,
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 SkMemoryStream pictReadback(dst, streamSize); 814 SkMemoryStream pictReadback(dst, streamSize);
820 SkPicture* retval = new SkPicture (&pictReadback); 815 SkPicture* retval = new SkPicture (&pictReadback);
821 return retval; 816 return retval;
822 } 817 }
823 818
824 // Test: draw into a bitmap or pdf. 819 // Test: draw into a bitmap or pdf.
825 // Depending on flags, possibly compare to an expected image. 820 // Depending on flags, possibly compare to an expected image.
826 ErrorCombination test_drawing(GM* gm, 821 ErrorCombination test_drawing(GM* gm,
827 const ConfigData& gRec, 822 const ConfigData& gRec,
828 const char writePath [], 823 const char writePath [],
829 GrContext* context, 824 GrSurface* gpuTarget,
830 GrRenderTarget* rt,
831 SkBitmap* bitmap) { 825 SkBitmap* bitmap) {
832 SkDynamicMemoryWStream document; 826 SkDynamicMemoryWStream document;
833 827
834 if (gRec.fBackend == kRaster_Backend || 828 if (gRec.fBackend == kRaster_Backend ||
835 gRec.fBackend == kGPU_Backend) { 829 gRec.fBackend == kGPU_Backend) {
836 // Early exit if we can't generate the image. 830 // Early exit if we can't generate the image.
837 ErrorCombination errors = generate_image(gm, gRec, context, rt, bitm ap, false); 831 ErrorCombination errors = generate_image(gm, gRec, gpuTarget, bitmap , false);
838 if (!errors.isEmpty()) { 832 if (!errors.isEmpty()) {
839 // TODO: Add a test to exercise what the stdout and 833 // TODO: Add a test to exercise what the stdout and
840 // JSON look like if we get an "early error" while 834 // JSON look like if we get an "early error" while
841 // trying to generate the image. 835 // trying to generate the image.
842 return errors; 836 return errors;
843 } 837 }
844 } else if (gRec.fBackend == kPDF_Backend) { 838 } else if (gRec.fBackend == kPDF_Backend) {
845 generate_pdf(gm, document); 839 generate_pdf(gm, document);
846 #if CAN_IMAGE_PDF 840 #if CAN_IMAGE_PDF
847 SkAutoDataUnref data(document.copyToData()); 841 SkAutoDataUnref data(document.copyToData());
848 SkMemoryStream stream(data->data(), data->size()); 842 SkMemoryStream stream(data->data(), data->size());
849 SkPDFDocumentToBitmap(&stream, bitmap); 843 SkPDFDocumentToBitmap(&stream, bitmap);
850 #endif 844 #endif
851 } else if (gRec.fBackend == kXPS_Backend) { 845 } else if (gRec.fBackend == kXPS_Backend) {
852 generate_xps(gm, document); 846 generate_xps(gm, document);
853 } 847 }
854 return compare_test_results_to_stored_expectations( 848 return compare_test_results_to_stored_expectations(
855 gm, gRec, writePath, *bitmap, &document); 849 gm, gRec, writePath, *bitmap, &document);
856 } 850 }
857 851
858 ErrorCombination test_deferred_drawing(GM* gm, 852 ErrorCombination test_deferred_drawing(GM* gm,
859 const ConfigData& gRec, 853 const ConfigData& gRec,
860 const SkBitmap& referenceBitmap, 854 const SkBitmap& referenceBitmap,
861 GrContext* context, 855 GrSurface* gpuTarget) {
862 GrRenderTarget* rt) {
863 SkDynamicMemoryWStream document; 856 SkDynamicMemoryWStream document;
864 857
865 if (gRec.fBackend == kRaster_Backend || 858 if (gRec.fBackend == kRaster_Backend ||
866 gRec.fBackend == kGPU_Backend) { 859 gRec.fBackend == kGPU_Backend) {
867 SkBitmap bitmap; 860 SkBitmap bitmap;
868 // Early exit if we can't generate the image, but this is 861 // Early exit if we can't generate the image, but this is
869 // expected in some cases, so don't report a test failure. 862 // expected in some cases, so don't report a test failure.
870 ErrorCombination errors = generate_image(gm, gRec, context, rt, &bit map, true); 863 ErrorCombination errors = generate_image(gm, gRec, gpuTarget, &bitma p, true);
871 // TODO(epoger): This logic is the opposite of what is 864 // TODO(epoger): This logic is the opposite of what is
872 // described above... if we succeeded in generating the 865 // described above... if we succeeded in generating the
873 // -deferred image, we exit early! We should fix this 866 // -deferred image, we exit early! We should fix this
874 // ASAP, because it is hiding -deferred errors... but for 867 // ASAP, because it is hiding -deferred errors... but for
875 // now, I'm leaving the logic as it is so that the 868 // now, I'm leaving the logic as it is so that the
876 // refactoring change 869 // refactoring change
877 // https://codereview.chromium.org/12992003/ is unblocked. 870 // https://codereview.chromium.org/12992003/ is unblocked.
878 // 871 //
879 // Filed as https://code.google.com/p/skia/issues/detail?id=1180 872 // Filed as https://code.google.com/p/skia/issues/detail?id=1180
880 // ('image-surface gm test is failing in "deferred" mode, 873 // ('image-surface gm test is failing in "deferred" mode,
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 continue; 1169 continue;
1177 } 1170 }
1178 if ((gmFlags & GM::kSkipGPU_Flag) && 1171 if ((gmFlags & GM::kSkipGPU_Flag) &&
1179 kGPU_Backend == config.fBackend) { 1172 kGPU_Backend == config.fBackend) {
1180 continue; 1173 continue;
1181 } 1174 }
1182 1175
1183 // Now we know that we want to run this test and record its 1176 // Now we know that we want to run this test and record its
1184 // success or failure. 1177 // success or failure.
1185 ErrorCombination errorsForThisConfig; 1178 ErrorCombination errorsForThisConfig;
1186 GrRenderTarget* renderTarget = NULL; 1179 GrSurface* gpuTarget = NULL;
1187 #if SK_SUPPORT_GPU 1180 #if SK_SUPPORT_GPU
1188 SkAutoTUnref<GrRenderTarget> rt; 1181 SkAutoTUnref<GrSurface> auGpuTarget;
1189 AutoResetGr autogr; 1182 AutoResetGr autogr;
1190 if ((errorsForThisConfig.isEmpty()) && (kGPU_Backend == config.fBackend) ) { 1183 if ((errorsForThisConfig.isEmpty()) && (kGPU_Backend == config.fBackend) ) {
1191 GrContext* gr = grFactory->get(config.fGLContextType); 1184 GrContext* gr = grFactory->get(config.fGLContextType);
1192 bool grSuccess = false; 1185 bool grSuccess = false;
1193 if (gr) { 1186 if (gr) {
1194 // create a render target to back the device 1187 // create a render target to back the device
1195 GrTextureDesc desc; 1188 GrTextureDesc desc;
1196 desc.fConfig = kSkia8888_GrPixelConfig; 1189 desc.fConfig = kSkia8888_GrPixelConfig;
1197 desc.fFlags = kRenderTarget_GrTextureFlagBit; 1190 desc.fFlags = kRenderTarget_GrTextureFlagBit;
1198 desc.fWidth = gm->getISize().width(); 1191 desc.fWidth = gm->getISize().width();
1199 desc.fHeight = gm->getISize().height(); 1192 desc.fHeight = gm->getISize().height();
1200 desc.fSampleCnt = config.fSampleCnt; 1193 desc.fSampleCnt = config.fSampleCnt;
1201 GrTexture* tex = gr->createUncachedTexture(desc, NULL, 0); 1194 auGpuTarget.reset(gr->createUncachedTexture(desc, NULL, 0));
1202 if (tex) { 1195 if (NULL != auGpuTarget) {
1203 rt.reset(tex->asRenderTarget()); 1196 gpuTarget = auGpuTarget;
1204 rt.get()->ref(); 1197 grSuccess = true;
1205 tex->unref();
1206 autogr.set(gr); 1198 autogr.set(gr);
1207 renderTarget = rt.get(); 1199 // Set the user specified cache limits if non-default.
1208 grSuccess = NULL != renderTarget; 1200 size_t bytes;
1201 int count;
1202 gr->getTextureCacheLimits(&count, &bytes);
1203 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) {
1204 bytes = static_cast<size_t>(gGpuCacheSizeBytes);
1205 }
1206 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) {
1207 count = gGpuCacheSizeCount;
1208 }
1209 gr->setTextureCacheLimits(count, bytes);
1209 } 1210 }
1210 // Set the user specified cache limits if non-default.
1211 size_t bytes;
1212 int count;
1213 gr->getTextureCacheLimits(&count, &bytes);
1214 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) {
1215 bytes = static_cast<size_t>(gGpuCacheSizeBytes);
1216 }
1217 if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) {
1218 count = gGpuCacheSizeCount;
1219 }
1220 gr->setTextureCacheLimits(count, bytes);
1221 } 1211 }
1222 if (!grSuccess) { 1212 if (!grSuccess) {
1223 errorsForThisConfig.add(kNoGpuContext_ErrorType); 1213 errorsForThisConfig.add(kNoGpuContext_ErrorType);
1224 } 1214 }
1225 } 1215 }
1226 #endif 1216 #endif
1227 1217
1228 SkBitmap comparisonBitmap; 1218 SkBitmap comparisonBitmap;
1229 1219
1230 const char* writePath; 1220 const char* writePath;
1231 if (FLAGS_writePath.count() == 1) { 1221 if (FLAGS_writePath.count() == 1) {
1232 writePath = FLAGS_writePath[0]; 1222 writePath = FLAGS_writePath[0];
1233 } else { 1223 } else {
1234 writePath = NULL; 1224 writePath = NULL;
1235 } 1225 }
1236 if (errorsForThisConfig.isEmpty()) { 1226 if (errorsForThisConfig.isEmpty()) {
1237 errorsForThisConfig.add(gmmain.test_drawing(gm, config, writePath, G etGr(), 1227 errorsForThisConfig.add(gmmain.test_drawing(gm,config, writePath, gp uTarget,
1238 renderTarget, &compariso nBitmap)); 1228 &comparisonBitmap));
1239 } 1229 }
1240 1230
1241 if (FLAGS_deferred && errorsForThisConfig.isEmpty() && 1231 if (FLAGS_deferred && errorsForThisConfig.isEmpty() &&
1242 (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBacke nd)) { 1232 (kGPU_Backend == config.fBackend || kRaster_Backend == config.fBacke nd)) {
1243 errorsForThisConfig.add(gmmain.test_deferred_drawing(gm, config, com parisonBitmap, 1233 errorsForThisConfig.add(gmmain.test_deferred_drawing(gm, config, com parisonBitmap,
1244 GetGr(), render Target)); 1234 gpuTarget));
1245 } 1235 }
1246 1236
1247 errorsForAllConfigs.add(errorsForThisConfig); 1237 errorsForAllConfigs.add(errorsForThisConfig);
1248 } 1238 }
1249 return errorsForAllConfigs; 1239 return errorsForAllConfigs;
1250 } 1240 }
1251 1241
1252 /** 1242 /**
1253 * Run this test in a number of different drawing modes (pipe, 1243 * Run this test in a number of different drawing modes (pipe,
1254 * deferred, tiled, etc.), confirming that the resulting bitmaps all 1244 * deferred, tiled, etc.), confirming that the resulting bitmaps all
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1588 SkISize size = gm->getISize(); 1578 SkISize size = gm->getISize();
1589 gm_fprintf(stdout, "%sdrawing... %s [%d %d]\n", moduloStr.c_str(), short Name, 1579 gm_fprintf(stdout, "%sdrawing... %s [%d %d]\n", moduloStr.c_str(), short Name,
1590 size.width(), size.height()); 1580 size.width(), size.height());
1591 1581
1592 ErrorCombination testErrors; 1582 ErrorCombination testErrors;
1593 testErrors.add(run_multiple_configs(gmmain, gm, configs, grFactory)); 1583 testErrors.add(run_multiple_configs(gmmain, gm, configs, grFactory));
1594 1584
1595 SkBitmap comparisonBitmap; 1585 SkBitmap comparisonBitmap;
1596 const ConfigData compareConfig = 1586 const ConfigData compareConfig =
1597 { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextT ype, 0, kRW_ConfigFlag, "comparison", false }; 1587 { SkBitmap::kARGB_8888_Config, kRaster_Backend, kDontCare_GLContextT ype, 0, kRW_ConfigFlag, "comparison", false };
1598 testErrors.add(gmmain.generate_image( 1588 testErrors.add(gmmain.generate_image(gm, compareConfig, NULL, &compariso nBitmap, false));
1599 gm, compareConfig, NULL, NULL, &comparisonBitmap, false));
1600 1589
1601 // TODO(epoger): only run this if gmmain.generate_image() succeeded? 1590 // TODO(epoger): only run this if gmmain.generate_image() succeeded?
1602 // Otherwise, what are we comparing against? 1591 // Otherwise, what are we comparing against?
1603 testErrors.add(run_multiple_modes(gmmain, gm, compareConfig, comparisonB itmap, 1592 testErrors.add(run_multiple_modes(gmmain, gm, compareConfig, comparisonB itmap,
1604 tileGridReplayScales)); 1593 tileGridReplayScales));
1605 1594
1606 // Update overall results. 1595 // Update overall results.
1607 // We only tabulate the particular error types that we currently 1596 // We only tabulate the particular error types that we currently
1608 // care about (e.g., missing reference images). Later on, if we 1597 // care about (e.g., missing reference images). Later on, if we
1609 // want to also tabulate other error types, we can do so. 1598 // want to also tabulate other error types, we can do so.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1668 if (FLAGS_forceBWtext) { 1657 if (FLAGS_forceBWtext) {
1669 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref(); 1658 canvas->setDrawFilter(SkNEW(BWTextDrawFilter))->unref();
1670 } 1659 }
1671 } 1660 }
1672 1661
1673 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL) 1662 #if !defined(SK_BUILD_FOR_IOS) && !defined(SK_BUILD_FOR_NACL)
1674 int main(int argc, char * const argv[]) { 1663 int main(int argc, char * const argv[]) {
1675 return tool_main(argc, (char**) argv); 1664 return tool_main(argc, (char**) argv);
1676 } 1665 }
1677 #endif 1666 #endif
OLDNEW
« no previous file with comments | « no previous file | include/gpu/SkGpuDevice.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698