diff options
author | robertphillips <robertphillips@google.com> | 2016-07-26 11:38:17 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-07-26 11:38:17 -0700 |
commit | 7e922765545f42ce691e4f3d5fbbd4e44ba47ff1 (patch) | |
tree | 40f15d00e25acaf015f46e45d11d1858eb3b8cf6 | |
parent | 3a0dbde1cfa84b08c7dd5b597142e9f6179f2d07 (diff) |
Reduce usage of MakeRenderTargetDirect
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2187573002
Review-Url: https://codereview.chromium.org/2187573002
-rw-r--r-- | include/core/SkSurface.h | 14 | ||||
-rw-r--r-- | include/gpu/GrDrawContext.h | 1 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 31 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.h | 14 | ||||
-rw-r--r-- | src/image/SkSurface.cpp | 4 | ||||
-rw-r--r-- | src/image/SkSurface_Gpu.cpp | 7 | ||||
-rw-r--r-- | tests/DeviceTest.cpp | 3 | ||||
-rw-r--r-- | tests/ReadPixelsTest.cpp | 13 | ||||
-rw-r--r-- | tests/ReadWriteAlphaTest.cpp | 31 | ||||
-rw-r--r-- | tests/SurfaceTest.cpp | 13 | ||||
-rw-r--r-- | tests/WritePixelsTest.cpp | 13 | ||||
-rw-r--r-- | tests/skbug5221.cpp | 3 |
12 files changed, 73 insertions, 74 deletions
diff --git a/include/core/SkSurface.h b/include/core/SkSurface.h index 4d38d300c9..e60f50e3fa 100644 --- a/include/core/SkSurface.h +++ b/include/core/SkSurface.h @@ -140,11 +140,19 @@ public: * Return a new surface whose contents will be drawn to an offscreen * render target, allocated by the surface. */ - static sk_sp<SkSurface> MakeRenderTarget( - GrContext*, SkBudgeted, const SkImageInfo&, int sampleCount, const SkSurfaceProps*); + static sk_sp<SkSurface> MakeRenderTarget(GrContext*, SkBudgeted, const SkImageInfo&, + int sampleCount, GrSurfaceOrigin, + const SkSurfaceProps*); + + static sk_sp<SkSurface> MakeRenderTarget(GrContext* context, SkBudgeted budgeted, + const SkImageInfo& info, int sampleCount, + const SkSurfaceProps* props) { + return MakeRenderTarget(context, budgeted, info, sampleCount, + kBottomLeft_GrSurfaceOrigin, props); + } static sk_sp<SkSurface> MakeRenderTarget(GrContext* gr, SkBudgeted b, const SkImageInfo& info) { - return MakeRenderTarget(gr, b, info, 0, nullptr); + return MakeRenderTarget(gr, b, info, 0, kBottomLeft_GrSurfaceOrigin, nullptr); } #ifdef SK_SUPPORT_LEGACY_NEW_SURFACE_API diff --git a/include/gpu/GrDrawContext.h b/include/gpu/GrDrawContext.h index d5bde08288..e305cc1197 100644 --- a/include/gpu/GrDrawContext.h +++ b/include/gpu/GrDrawContext.h @@ -281,6 +281,7 @@ public: } const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; } SkColorSpace* getColorSpace() const { return fColorSpace.get(); } + GrSurfaceOrigin origin() const { return fRenderTarget->origin(); } bool wasAbandoned() const; diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 116d3c6e4c..b81a94a194 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -124,14 +124,15 @@ sk_sp<SkBaseDevice> SkGpuDevice::Make(sk_sp<GrDrawContext> drawContext, sk_sp<SkGpuDevice> SkGpuDevice::Make(GrContext* context, SkBudgeted budgeted, const SkImageInfo& info, int sampleCount, + GrSurfaceOrigin origin, const SkSurfaceProps* props, InitContents init) { unsigned flags; if (!CheckAlphaTypeAndGetFlags(&info, init, &flags)) { return nullptr; } - sk_sp<GrDrawContext> drawContext(CreateDrawContext(context, budgeted, info, - sampleCount, props)); + sk_sp<GrDrawContext> drawContext(MakeDrawContext(context, budgeted, info, + sampleCount, origin, props)); if (!drawContext) { return nullptr; } @@ -153,11 +154,12 @@ SkGpuDevice::SkGpuDevice(sk_sp<GrDrawContext> drawContext, int width, int height } } -sk_sp<GrDrawContext> SkGpuDevice::CreateDrawContext(GrContext* context, - SkBudgeted budgeted, - const SkImageInfo& origInfo, - int sampleCount, - const SkSurfaceProps* surfaceProps) { +sk_sp<GrDrawContext> SkGpuDevice::MakeDrawContext(GrContext* context, + SkBudgeted budgeted, + const SkImageInfo& origInfo, + int sampleCount, + GrSurfaceOrigin origin, + const SkSurfaceProps* surfaceProps) { if (kUnknown_SkColorType == origInfo.colorType() || origInfo.width() < 0 || origInfo.height() < 0) { return nullptr; @@ -188,7 +190,7 @@ sk_sp<GrDrawContext> SkGpuDevice::CreateDrawContext(GrContext* context, return context->newDrawContext(SkBackingFit::kExact, // Why exact? origInfo.width(), origInfo.height(), config, sk_ref_sp(cs), sampleCount, - kDefault_GrSurfaceOrigin, surfaceProps, budgeted); + origin, surfaceProps, budgeted); } sk_sp<SkSpecialImage> SkGpuDevice::filterTexture(const SkDraw& draw, @@ -276,11 +278,12 @@ void SkGpuDevice::replaceDrawContext(bool shouldRetainContent) { SkBudgeted budgeted = fRenderTarget->resourcePriv().isBudgeted(); - sk_sp<GrDrawContext> newDC(CreateDrawContext(this->context(), - budgeted, - this->imageInfo(), - fDrawContext->numColorSamples(), - &this->surfaceProps())); + sk_sp<GrDrawContext> newDC(MakeDrawContext(this->context(), + budgeted, + this->imageInfo(), + fDrawContext->numColorSamples(), + fDrawContext->origin(), + &this->surfaceProps())); if (!newDC) { return; } @@ -1769,7 +1772,7 @@ sk_sp<SkSurface> SkGpuDevice::makeSurface(const SkImageInfo& info, const SkSurfa // TODO: Change the signature of newSurface to take a budgeted parameter. static const SkBudgeted kBudgeted = SkBudgeted::kNo; return SkSurface::MakeRenderTarget(fContext, kBudgeted, info, fDrawContext->desc().fSampleCnt, - &props); + fDrawContext->origin(), &props); } SkImageFilterCache* SkGpuDevice::getImageFilterCache() { diff --git a/src/gpu/SkGpuDevice.h b/src/gpu/SkGpuDevice.h index 4cfd02421a..8624ae19f3 100644 --- a/src/gpu/SkGpuDevice.h +++ b/src/gpu/SkGpuDevice.h @@ -62,7 +62,8 @@ public: * the resource cache budget. On failure, returns nullptr. */ static sk_sp<SkGpuDevice> Make(GrContext*, SkBudgeted, const SkImageInfo&, - int sampleCount, const SkSurfaceProps*, InitContents); + int sampleCount, GrSurfaceOrigin, + const SkSurfaceProps*, InitContents); ~SkGpuDevice() override {} @@ -265,11 +266,12 @@ private: bool drawDashLine(const SkPoint pts[2], const SkPaint& paint); void drawStrokedLine(const SkPoint pts[2], const SkDraw&, const SkPaint&); - static sk_sp<GrDrawContext> CreateDrawContext(GrContext*, - SkBudgeted, - const SkImageInfo&, - int sampleCount, - const SkSurfaceProps*); + static sk_sp<GrDrawContext> MakeDrawContext(GrContext*, + SkBudgeted, + const SkImageInfo&, + int sampleCount, + GrSurfaceOrigin, + const SkSurfaceProps*); friend class GrAtlasTextContext; friend class SkSurface_Gpu; // for access to surfaceProps diff --git a/src/image/SkSurface.cpp b/src/image/SkSurface.cpp index 2035e4cc8a..73b8286082 100644 --- a/src/image/SkSurface.cpp +++ b/src/image/SkSurface.cpp @@ -228,8 +228,8 @@ sk_sp<SkSurface> SkSurface::MakeRenderTargetDirect(GrRenderTarget*, sk_sp<SkColo return nullptr; } -sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext*, SkBudgeted, const SkImageInfo&, int, - const SkSurfaceProps*) { +sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext*, SkBudgeted, const SkImageInfo&, + int, GrSurfaceOrigin, const SkSurfaceProps*) { return nullptr; } diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp index ef8dd5f06e..d8b4cee2dc 100644 --- a/src/image/SkSurface_Gpu.cpp +++ b/src/image/SkSurface_Gpu.cpp @@ -67,10 +67,11 @@ SkCanvas* SkSurface_Gpu::onNewCanvas() { sk_sp<SkSurface> SkSurface_Gpu::onNewSurface(const SkImageInfo& info) { int sampleCount = fDevice->accessDrawContext()->numColorSamples(); + GrSurfaceOrigin origin = fDevice->accessDrawContext()->origin(); // TODO: Make caller specify this (change virtual signature of onNewSurface). static const SkBudgeted kBudgeted = SkBudgeted::kNo; return SkSurface::MakeRenderTarget(fDevice->context(), kBudgeted, info, sampleCount, - &this->props()); + origin, &this->props()); } sk_sp<SkImage> SkSurface_Gpu::onNewImageSnapshot(SkBudgeted budgeted, ForceCopyMode forceCopyMode) { @@ -145,9 +146,9 @@ sk_sp<SkSurface> SkSurface::MakeRenderTargetDirect(GrRenderTarget* target, sk_sp<SkSurface> SkSurface::MakeRenderTarget(GrContext* ctx, SkBudgeted budgeted, const SkImageInfo& info, int sampleCount, - const SkSurfaceProps* props) { + GrSurfaceOrigin origin, const SkSurfaceProps* props) { sk_sp<SkGpuDevice> device(SkGpuDevice::Make( - ctx, budgeted, info, sampleCount, props, SkGpuDevice::kClear_InitContents)); + ctx, budgeted, info, sampleCount, origin, props, SkGpuDevice::kClear_InitContents)); if (!device) { return nullptr; } diff --git a/tests/DeviceTest.cpp b/tests/DeviceTest.cpp index d6bd1bfe47..f7d855a266 100644 --- a/tests/DeviceTest.cpp +++ b/tests/DeviceTest.cpp @@ -81,7 +81,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SpecialImage_GPUDevice, reporter, ctxInfo) { SkImageInfo ii = SkImageInfo::MakeN32Premul(2*kWidth, 2*kHeight); sk_sp<SkBaseDevice> gpuDev(SkGpuDevice::Make(context, SkBudgeted::kNo, ii, - 0, nullptr, SkGpuDevice::kClear_InitContents)); + 0, kBottomLeft_GrSurfaceOrigin, nullptr, + SkGpuDevice::kClear_InitContents)); SkBitmap bm; SkAssertResult(bm.tryAllocN32Pixels(kWidth, kHeight)); diff --git a/tests/ReadPixelsTest.cpp b/tests/ReadPixelsTest.cpp index 5d3bfc9902..c1fa4d2328 100644 --- a/tests/ReadPixelsTest.cpp +++ b/tests/ReadPixelsTest.cpp @@ -387,17 +387,10 @@ DEF_TEST(ReadPixels, reporter) { } #if SK_SUPPORT_GPU DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadPixels_Gpu, reporter, ctxInfo) { + const SkImageInfo ii = SkImageInfo::MakeN32Premul(DEV_W, DEV_H); for (auto& origin : {kBottomLeft_GrSurfaceOrigin, kTopLeft_GrSurfaceOrigin}) { - GrSurfaceDesc desc; - desc.fFlags = kRenderTarget_GrSurfaceFlag; - desc.fWidth = DEV_W; - desc.fHeight = DEV_H; - desc.fConfig = kSkia8888_GrPixelConfig; - desc.fOrigin = origin; - SkAutoTUnref<GrTexture> surfaceTexture( - ctxInfo.grContext()->textureProvider()->createTexture(desc, SkBudgeted::kNo)); - auto surface(SkSurface::MakeRenderTargetDirect(surfaceTexture->asRenderTarget(), nullptr)); - desc.fFlags = kNone_GrSurfaceFlags; + sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kNo, + ii, 0, origin, nullptr)); test_readpixels(reporter, surface, kLast_BitmapInit); } } diff --git a/tests/ReadWriteAlphaTest.cpp b/tests/ReadWriteAlphaTest.cpp index 16f43ea310..e5240666aa 100644 --- a/tests/ReadWriteAlphaTest.cpp +++ b/tests/ReadWriteAlphaTest.cpp @@ -41,12 +41,10 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) { bool match; static const size_t kRowBytes[] = {0, X_SIZE, X_SIZE + 1, 2 * X_SIZE - 1}; - for (int rt = 0; rt < 2; ++rt) { + { GrSurfaceDesc desc; - // let Skia know we will be using this texture as a render target - desc.fFlags = rt ? kRenderTarget_GrSurfaceFlag : kNone_GrSurfaceFlags; - // it is a single channel texture - desc.fConfig = kAlpha_8_GrPixelConfig; + desc.fFlags = kNone_GrSurfaceFlags; + desc.fConfig = kAlpha_8_GrPixelConfig; // it is a single channel texture desc.fWidth = X_SIZE; desc.fHeight = Y_SIZE; @@ -54,14 +52,16 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) { memset(alphaData, 0, X_SIZE * Y_SIZE); SkAutoTUnref<GrTexture> texture( ctxInfo.grContext()->textureProvider()->createTexture(desc, SkBudgeted::kNo, alphaData, - 0)); + 0)); if (!texture) { - if (!rt) { - ERRORF(reporter, "Could not create alpha texture."); - } - continue; + ERRORF(reporter, "Could not create alpha texture."); + return; } + const SkImageInfo ii = SkImageInfo::MakeA8(X_SIZE, Y_SIZE); + sk_sp<SkSurface> surf(SkSurface::MakeRenderTarget(ctxInfo.grContext(), + SkBudgeted::kNo, ii)); + // create a distinctive texture for (int y = 0; y < Y_SIZE; ++y) { for (int x = 0; x < X_SIZE; ++x) { @@ -87,14 +87,12 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) { // make sure the original & read back versions match SkString msg; - msg.printf("rt:%d, rb:%d A8", rt, SkToU32(rowBytes)); + msg.printf("rb:%d A8", SkToU32(rowBytes)); validate_alpha_data(reporter, X_SIZE, Y_SIZE, readback.get(), nonZeroRowBytes, alphaData, msg); - // Now try writing on the single channel texture (if we could create as a RT). - if (texture->asRenderTarget()) { - sk_sp<SkSurface> surf(SkSurface::MakeRenderTargetDirect(texture->asRenderTarget(), - nullptr)); + // Now try writing to a single channel surface (if we could create one). + if (surf) { SkCanvas* canvas = surf->getCanvas(); SkPaint paint; @@ -106,8 +104,7 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ReadWriteAlpha, reporter, ctxInfo) { canvas->drawRect(rect, paint); memset(readback.get(), kClearValue, nonZeroRowBytes * Y_SIZE); - result = texture->readPixels(0, 0, desc.fWidth, desc.fHeight, - desc.fConfig, readback.get(), rowBytes); + result = surf->readPixels(ii, readback.get(), nonZeroRowBytes, 0, 0); REPORTER_ASSERT_MESSAGE(reporter, result, "A8 readPixels after clear failed"); match = true; diff --git a/tests/SurfaceTest.cpp b/tests/SurfaceTest.cpp index 8d2ba51e19..87c3a52fc9 100644 --- a/tests/SurfaceTest.cpp +++ b/tests/SurfaceTest.cpp @@ -56,7 +56,7 @@ static sk_sp<SkSurface> create_gpu_surface(GrContext* context, SkAlphaType at = if (requestedInfo) { *requestedInfo = info; } - return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, nullptr); + return SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info); } static sk_sp<SkSurface> create_gpu_scratch_surface(GrContext* context, SkAlphaType at = kPremul_SkAlphaType, @@ -65,7 +65,7 @@ static sk_sp<SkSurface> create_gpu_scratch_surface(GrContext* context, if (requestedInfo) { *requestedInfo = info; } - return SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info, 0, nullptr); + return SkSurface::MakeRenderTarget(context, SkBudgeted::kYes, info); } #endif @@ -79,8 +79,7 @@ DEF_TEST(SurfaceEmpty, reporter) { DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SurfaceEmpty_Gpu, reporter, ctxInfo) { const SkImageInfo info = SkImageInfo::Make(0, 0, kN32_SkColorType, kPremul_SkAlphaType); REPORTER_ASSERT(reporter, nullptr == - SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kNo, info, 0, - nullptr)); + SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kNo, info)); } #endif @@ -335,13 +334,13 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(UniqueImageSnapshot_Gpu, reporter, ctxInfo) { desc.fHeight = 10; desc.fFlags = kRenderTarget_GrBackendTextureFlag; desc.fTextureHandle = textureObject; - GrTexture* texture = context->textureProvider()->wrapBackendTexture(desc); + { - auto surface(SkSurface::MakeRenderTargetDirect(texture->asRenderTarget(), nullptr)); + sk_sp<SkSurface> surface(SkSurface::MakeFromBackendTexture(context, desc, nullptr)); test_unique_image_snap(reporter, surface.get(), true, imageBackingStore, surfaceBackingStore); } - texture->unref(); + context->getGpu()->deleteTestingOnlyBackendTexture(textureObject); } } diff --git a/tests/WritePixelsTest.cpp b/tests/WritePixelsTest.cpp index ec88f03c2b..1839a40183 100644 --- a/tests/WritePixelsTest.cpp +++ b/tests/WritePixelsTest.cpp @@ -407,16 +407,11 @@ DEF_TEST(WritePixels, reporter) { } #if SK_SUPPORT_GPU DEF_GPUTEST_FOR_RENDERING_CONTEXTS(WritePixels_Gpu, reporter, ctxInfo) { + const SkImageInfo ii = SkImageInfo::MakeN32Premul(DEV_W, DEV_H); + for (auto& origin : { kTopLeft_GrSurfaceOrigin, kBottomLeft_GrSurfaceOrigin }) { - GrSurfaceDesc desc; - desc.fFlags = kRenderTarget_GrSurfaceFlag; - desc.fWidth = DEV_W; - desc.fHeight = DEV_H; - desc.fConfig = kSkia8888_GrPixelConfig; - desc.fOrigin = origin; - SkAutoTUnref<GrTexture> texture( - ctxInfo.grContext()->textureProvider()->createTexture(desc, SkBudgeted::kNo)); - auto surface(SkSurface::MakeRenderTargetDirect(texture->asRenderTarget(), nullptr)); + sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(ctxInfo.grContext(), SkBudgeted::kNo, + ii, 0, origin, nullptr)); test_write_pixels(reporter, surface.get()); } } diff --git a/tests/skbug5221.cpp b/tests/skbug5221.cpp index dfd065f0b7..0220e54d5f 100644 --- a/tests/skbug5221.cpp +++ b/tests/skbug5221.cpp @@ -26,8 +26,7 @@ DEF_TEST(skbug5221, r) { #if SK_SUPPORT_GPU DEF_GPUTEST_FOR_ALL_CONTEXTS(skbug5221_GPU, r, contextInfo) { sk_sp<SkSurface> surface(SkSurface::MakeRenderTarget(contextInfo.grContext(), SkBudgeted::kYes, - SkImageInfo::MakeN32Premul(256, 256), 0, - nullptr)); + SkImageInfo::MakeN32Premul(256, 256))); test(surface->getCanvas()); } #endif |