From 123ac1d4eab757052407064623643fdc59f85363 Mon Sep 17 00:00:00 2001 From: "bsalomon@google.com" Date: Thu, 28 Mar 2013 19:18:12 +0000 Subject: [PATCH] Make GM render to render targets that are also textures. Review URL: https://codereview.chromium.org/13211002 git-svn-id: http://skia.googlecode.com/svn/trunk@8438 2bbb7eff-a529-9590-31e7-b0007b416f81 --- gm/gmmain.cpp | 67 ++++++++++++++++----------------------- include/gpu/SkGpuDevice.h | 11 ++++++- src/gpu/SkGpuDevice.cpp | 12 +++++++ 3 files changed, 50 insertions(+), 40 deletions(-) diff --git a/gm/gmmain.cpp b/gm/gmmain.cpp index 55e1c2a3c3..7150452ac4 100644 --- a/gm/gmmain.cpp +++ b/gm/gmmain.cpp @@ -50,7 +50,6 @@ #if SK_SUPPORT_GPU #include "GrContextFactory.h" -#include "GrRenderTarget.h" #include "SkGpuDevice.h" typedef GrContextFactory::GLContextType GLContextType; #define DEFAULT_CACHE_VALUE -1 @@ -59,7 +58,7 @@ static int gGpuCacheSizeCount; #else class GrContextFactory; class GrContext; -class GrRenderTarget; +class GrSurface; typedef int GLContextType; #endif @@ -373,8 +372,7 @@ public: } static ErrorCombination generate_image(GM* gm, const ConfigData& gRec, - GrContext* context, - GrRenderTarget* rt, + GrSurface* gpuTarget, SkBitmap* bitmap, bool deferred) { SkISize size (gm->getISize()); @@ -394,10 +392,7 @@ public: } #if SK_SUPPORT_GPU else { // GPU - if (NULL == context) { - return ErrorCombination(kNoGpuContext_ErrorType); - } - SkAutoTUnref device(new SkGpuDevice(context, rt)); + SkAutoTUnref device(SkGpuDevice::Create(gpuTarget)); if (deferred) { canvas.reset(new SkDeferredCanvas(device)); } else { @@ -826,15 +821,14 @@ public: ErrorCombination test_drawing(GM* gm, const ConfigData& gRec, const char writePath [], - GrContext* context, - GrRenderTarget* rt, + GrSurface* gpuTarget, SkBitmap* bitmap) { SkDynamicMemoryWStream document; if (gRec.fBackend == kRaster_Backend || gRec.fBackend == kGPU_Backend) { // Early exit if we can't generate the image. - ErrorCombination errors = generate_image(gm, gRec, context, rt, bitmap, false); + ErrorCombination errors = generate_image(gm, gRec, gpuTarget, bitmap, false); if (!errors.isEmpty()) { // TODO: Add a test to exercise what the stdout and // JSON look like if we get an "early error" while @@ -858,8 +852,7 @@ public: ErrorCombination test_deferred_drawing(GM* gm, const ConfigData& gRec, const SkBitmap& referenceBitmap, - GrContext* context, - GrRenderTarget* rt) { + GrSurface* gpuTarget) { SkDynamicMemoryWStream document; if (gRec.fBackend == kRaster_Backend || @@ -867,7 +860,7 @@ public: SkBitmap bitmap; // Early exit if we can't generate the image, but this is // expected in some cases, so don't report a test failure. - ErrorCombination errors = generate_image(gm, gRec, context, rt, &bitmap, true); + ErrorCombination errors = generate_image(gm, gRec, gpuTarget, &bitmap, true); // TODO(epoger): This logic is the opposite of what is // described above... if we succeeded in generating the // -deferred image, we exit early! We should fix this @@ -1183,9 +1176,9 @@ ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, const SkTDArray rt; + SkAutoTUnref auGpuTarget; AutoResetGr autogr; if ((errorsForThisConfig.isEmpty()) && (kGPU_Backend == config.fBackend)) { GrContext* gr = grFactory->get(config.fGLContextType); @@ -1198,26 +1191,23 @@ ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, const SkTDArraygetISize().width(); desc.fHeight = gm->getISize().height(); desc.fSampleCnt = config.fSampleCnt; - GrTexture* tex = gr->createUncachedTexture(desc, NULL, 0); - if (tex) { - rt.reset(tex->asRenderTarget()); - rt.get()->ref(); - tex->unref(); + auGpuTarget.reset(gr->createUncachedTexture(desc, NULL, 0)); + if (NULL != auGpuTarget) { + gpuTarget = auGpuTarget; + grSuccess = true; autogr.set(gr); - renderTarget = rt.get(); - grSuccess = NULL != renderTarget; + // Set the user specified cache limits if non-default. + size_t bytes; + int count; + gr->getTextureCacheLimits(&count, &bytes); + if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) { + bytes = static_cast(gGpuCacheSizeBytes); + } + if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) { + count = gGpuCacheSizeCount; + } + gr->setTextureCacheLimits(count, bytes); } - // Set the user specified cache limits if non-default. - size_t bytes; - int count; - gr->getTextureCacheLimits(&count, &bytes); - if (DEFAULT_CACHE_VALUE != gGpuCacheSizeBytes) { - bytes = static_cast(gGpuCacheSizeBytes); - } - if (DEFAULT_CACHE_VALUE != gGpuCacheSizeCount) { - count = gGpuCacheSizeCount; - } - gr->setTextureCacheLimits(count, bytes); } if (!grSuccess) { errorsForThisConfig.add(kNoGpuContext_ErrorType); @@ -1234,14 +1224,14 @@ ErrorCombination run_multiple_configs(GMMain &gmmain, GM *gm, const SkTDArrayasRenderTarget() || NULL == surface->getContext()) { + return NULL; + } + if (surface->asTexture()) { + return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asTexture())); + } else { + return SkNEW_ARGS(SkGpuDevice, (surface->getContext(), surface->asRenderTarget())); + } +} + SkGpuDevice::SkGpuDevice(GrContext* context, GrTexture* texture) : SkDevice(make_bitmap(context, texture->asRenderTarget())) { this->initFromRenderTarget(context, texture->asRenderTarget(), false);