diff options
author | 2018-03-08 09:51:04 -0500 | |
---|---|---|
committer | 2018-03-08 15:26:51 +0000 | |
commit | c7c2baf0cf264b9d0d9c0f67cfb827a7e4a5e32c (patch) | |
tree | 6af65cc34a6b4557fd24d029c447c2822bdb9699 /src | |
parent | 8c827ce7ea5b624792a9261f65d9515deb56a63d (diff) |
Additional DDL playback cleanup
This operates in tandem with https://skia-review.googlesource.com/c/skia/+/112702 (
Remove GrRestrictedAtlasManager) to get DDL playback working.
Change-Id: I6c2178fde760677bf79f2cf0a2dee8b5990aa5bc
Reviewed-on: https://skia-review.googlesource.com/113121
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Greg Daniel <egdaniel@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkDeferredDisplayListRecorder.cpp | 2 | ||||
-rw-r--r-- | src/core/SkMask.h | 6 | ||||
-rw-r--r-- | src/effects/GrCircleBlurFragmentProcessor.cpp | 32 | ||||
-rw-r--r-- | src/effects/GrCircleBlurFragmentProcessor.fp | 34 | ||||
-rw-r--r-- | src/gpu/GrBlurUtils.cpp | 39 | ||||
-rw-r--r-- | src/gpu/GrGpu.cpp | 8 | ||||
-rw-r--r-- | src/gpu/GrGpu.h | 10 | ||||
-rw-r--r-- | src/gpu/GrSurfaceProxy.cpp | 17 | ||||
-rw-r--r-- | src/gpu/GrTextureMaker.cpp | 7 | ||||
-rw-r--r-- | src/gpu/effects/GrTextureStripAtlas.cpp | 1 |
10 files changed, 93 insertions, 63 deletions
diff --git a/src/core/SkDeferredDisplayListRecorder.cpp b/src/core/SkDeferredDisplayListRecorder.cpp index acd7b67b4c..077548062d 100644 --- a/src/core/SkDeferredDisplayListRecorder.cpp +++ b/src/core/SkDeferredDisplayListRecorder.cpp @@ -71,7 +71,6 @@ bool SkDeferredDisplayListRecorder::init() { GrSurfaceDesc desc; desc.fFlags = kRenderTarget_GrSurfaceFlag; - desc.fOrigin = fCharacterization.origin(); desc.fWidth = fCharacterization.width(); desc.fHeight = fCharacterization.height(); desc.fConfig = fCharacterization.config(); @@ -95,6 +94,7 @@ bool SkDeferredDisplayListRecorder::init() { return sk_ref_sp<GrSurface>(lazyProxyData->fReplayDest->priv().peekSurface()); }, desc, + fCharacterization.origin(), GrRenderTargetFlags::kNone, GrProxyProvider::Textureable(fCharacterization.isTextureable()), GrMipMapped::kNo, diff --git a/src/core/SkMask.h b/src/core/SkMask.h index d4c5e3599c..1acd8f9cc3 100644 --- a/src/core/SkMask.h +++ b/src/core/SkMask.h @@ -146,6 +146,12 @@ public: SkMask::FreeImage(fImage); } + uint8_t* release() { + uint8_t* tmp = fImage; + fImage = nullptr; + return tmp; + } + private: uint8_t* fImage; }; diff --git a/src/effects/GrCircleBlurFragmentProcessor.cpp b/src/effects/GrCircleBlurFragmentProcessor.cpp index b345f27998..d44f431dd3 100644 --- a/src/effects/GrCircleBlurFragmentProcessor.cpp +++ b/src/effects/GrCircleBlurFragmentProcessor.cpp @@ -107,9 +107,9 @@ static uint8_t eval_at(float evalX, float circleR, const float* halfKernel, int // the size of the profile being computed. Then for each of the n profile entries we walk out k // steps in each horizontal direction multiplying the corresponding y evaluation by the half // kernel entry and sum these values to compute the profile entry. -static uint8_t* create_circle_profile(float sigma, float circleR, int profileTextureWidth) { +static void create_circle_profile(uint8_t* weights, float sigma, float circleR, + int profileTextureWidth) { const int numSteps = profileTextureWidth; - uint8_t* weights = new uint8_t[numSteps]; // The full kernel is 6 sigmas wide. int halfKernelSize = SkScalarCeilToInt(6.0f * sigma); @@ -134,17 +134,15 @@ static uint8_t* create_circle_profile(float sigma, float circleR, int profileTex } // Ensure the tail of the Gaussian goes to zero. weights[numSteps - 1] = 0; - return weights; } -static uint8_t* create_half_plane_profile(int profileWidth) { +static void create_half_plane_profile(uint8_t* profile, int profileWidth) { SkASSERT(!(profileWidth & 0x1)); // The full kernel is 6 sigmas wide. float sigma = profileWidth / 6.f; int halfKernelSize = profileWidth / 2; SkAutoTArray<float> halfKernel(halfKernelSize); - uint8_t* profile = new uint8_t[profileWidth]; // The half kernel should sum to 0.5. const float tot = 2.f * make_unnormalized_half_kernel(halfKernel.get(), halfKernelSize, sigma); @@ -163,7 +161,6 @@ static uint8_t* create_half_plane_profile(int profileWidth) { } // Ensure tail goes to 0. profile[profileWidth - 1] = 0; - return profile; } static sk_sp<GrTextureProxy> create_profile_texture(GrProxyProvider* proxyProvider, @@ -211,23 +208,26 @@ static sk_sp<GrTextureProxy> create_profile_texture(GrProxyProvider* proxyProvid proxyProvider->findOrCreateProxyByUniqueKey(key, kTopLeft_GrSurfaceOrigin); if (!blurProfile) { static constexpr int kProfileTextureWidth = 512; - GrSurfaceDesc texDesc; - texDesc.fWidth = kProfileTextureWidth; - texDesc.fHeight = 1; - texDesc.fConfig = kAlpha_8_GrPixelConfig; - std::unique_ptr<uint8_t[]> profile(nullptr); + SkBitmap bm; + if (!bm.tryAllocPixels(SkImageInfo::MakeA8(kProfileTextureWidth, 1))) { + return nullptr; + } + if (useHalfPlaneApprox) { - profile.reset(create_half_plane_profile(kProfileTextureWidth)); + create_half_plane_profile(bm.getAddr8(0, 0), kProfileTextureWidth); } else { // Rescale params to the size of the texture we're creating. SkScalar scale = kProfileTextureWidth / *textureRadius; - profile.reset( - create_circle_profile(sigma * scale, circleR * scale, kProfileTextureWidth)); + create_circle_profile(bm.getAddr8(0, 0), sigma * scale, circleR * scale, + kProfileTextureWidth); } - blurProfile = - proxyProvider->createTextureProxy(texDesc, SkBudgeted::kYes, profile.get(), 0); + bm.setImmutable(); + sk_sp<SkImage> image = SkImage::MakeFromBitmap(bm); + + blurProfile = proxyProvider->createTextureProxy(std::move(image), kNone_GrSurfaceFlags, 1, + SkBudgeted::kYes, SkBackingFit::kExact); if (!blurProfile) { return nullptr; } diff --git a/src/effects/GrCircleBlurFragmentProcessor.fp b/src/effects/GrCircleBlurFragmentProcessor.fp index ef4c2890f3..71e5937729 100644 --- a/src/effects/GrCircleBlurFragmentProcessor.fp +++ b/src/effects/GrCircleBlurFragmentProcessor.fp @@ -127,12 +127,12 @@ uniform half4 circleData; // the size of the profile being computed. Then for each of the n profile entries we walk out k // steps in each horizontal direction multiplying the corresponding y evaluation by the half // kernel entry and sum these values to compute the profile entry. - static uint8_t* create_circle_profile(float sigma, float circleR, int profileTextureWidth) { + static void create_circle_profile(uint8_t* weights, float sigma, float circleR, + int profileTextureWidth) { const int numSteps = profileTextureWidth; - uint8_t* weights = new uint8_t[numSteps]; // The full kernel is 6 sigmas wide. - int halfKernelSize = SkScalarCeilToInt(6.0f*sigma); + int halfKernelSize = SkScalarCeilToInt(6.0f * sigma); // round up to next multiple of 2 and then divide by 2 halfKernelSize = ((halfKernelSize + 1) & ~1) >> 1; @@ -154,17 +154,15 @@ uniform half4 circleData; } // Ensure the tail of the Gaussian goes to zero. weights[numSteps - 1] = 0; - return weights; } - static uint8_t* create_half_plane_profile(int profileWidth) { + static void create_half_plane_profile(uint8_t* profile, int profileWidth) { SkASSERT(!(profileWidth & 0x1)); // The full kernel is 6 sigmas wide. float sigma = profileWidth / 6.f; int halfKernelSize = profileWidth / 2; SkAutoTArray<float> halfKernel(halfKernelSize); - uint8_t* profile = new uint8_t[profileWidth]; // The half kernel should sum to 0.5. const float tot = 2.f * make_unnormalized_half_kernel(halfKernel.get(), halfKernelSize, @@ -184,7 +182,6 @@ uniform half4 circleData; } // Ensure tail goes to 0. profile[profileWidth - 1] = 0; - return profile; } static sk_sp<GrTextureProxy> create_profile_texture(GrProxyProvider* proxyProvider, @@ -233,23 +230,26 @@ uniform half4 circleData; proxyProvider->findOrCreateProxyByUniqueKey(key, kTopLeft_GrSurfaceOrigin); if (!blurProfile) { static constexpr int kProfileTextureWidth = 512; - GrSurfaceDesc texDesc; - texDesc.fWidth = kProfileTextureWidth; - texDesc.fHeight = 1; - texDesc.fConfig = kAlpha_8_GrPixelConfig; - std::unique_ptr<uint8_t[]> profile(nullptr); + SkBitmap bm; + if (!bm.tryAllocPixels(SkImageInfo::MakeA8(kProfileTextureWidth, 1))) { + return nullptr; + } + if (useHalfPlaneApprox) { - profile.reset(create_half_plane_profile(kProfileTextureWidth)); + create_half_plane_profile(bm.getAddr8(0, 0), kProfileTextureWidth); } else { // Rescale params to the size of the texture we're creating. SkScalar scale = kProfileTextureWidth / *textureRadius; - profile.reset(create_circle_profile(sigma * scale, circleR * scale, - kProfileTextureWidth)); + create_circle_profile(bm.getAddr8(0, 0), sigma * scale, circleR * scale, + kProfileTextureWidth); } - blurProfile = proxyProvider->createTextureProxy( - texDesc, SkBudgeted::kYes, profile.get(), 0); + bm.setImmutable(); + sk_sp<SkImage> image = SkImage::MakeFromBitmap(bm); + + blurProfile = proxyProvider->createTextureProxy(std::move(image), kNone_GrSurfaceFlags, 1, + SkBudgeted::kYes, SkBackingFit::kExact); if (!blurProfile) { return nullptr; } diff --git a/src/gpu/GrBlurUtils.cpp b/src/gpu/GrBlurUtils.cpp index 0bddd5c594..146f297987 100644 --- a/src/gpu/GrBlurUtils.cpp +++ b/src/gpu/GrBlurUtils.cpp @@ -6,15 +6,18 @@ */ #include "GrBlurUtils.h" -#include "GrRenderTargetContext.h" + #include "GrCaps.h" #include "GrContext.h" #include "GrContextPriv.h" #include "GrFixedClip.h" +#include "GrProxyProvider.h" +#include "GrRenderTargetContext.h" #include "GrRenderTargetContextPriv.h" -#include "effects/GrSimpleTextureEffect.h" #include "GrStyle.h" #include "GrTextureProxy.h" +#include "effects/GrSimpleTextureEffect.h" + #include "SkDraw.h" #include "SkGr.h" #include "SkMaskFilterBase.h" @@ -49,6 +52,10 @@ static bool draw_mask(GrRenderTargetContext* renderTargetContext, return true; } +static void mask_release_proc(void* addr, void* /*context*/) { + SkMask::FreeImage(addr); +} + static bool sw_draw_with_mask_filter(GrContext* context, GrRenderTargetContext* renderTargetContext, const GrClip& clipData, @@ -58,7 +65,7 @@ static bool sw_draw_with_mask_filter(GrContext* context, const SkIRect& clipBounds, GrPaint&& paint, SkStrokeRec::InitStyle fillOrHairline) { - SkMask srcM, dstM; + SkMask srcM, dstM; if (!SkDraw::DrawToMask(devPath, &clipBounds, filter, &viewMatrix, &srcM, SkMask::kComputeBoundsAndRenderImage_CreateMode, fillOrHairline)) { return false; @@ -77,25 +84,23 @@ static bool sw_draw_with_mask_filter(GrContext* context, // we now have a device-aligned 8bit mask in dstM, ready to be drawn using // the current clip (and identity matrix) and GrPaint settings - GrSurfaceDesc desc; - desc.fWidth = dstM.fBounds.width(); - desc.fHeight = dstM.fBounds.height(); - desc.fConfig = kAlpha_8_GrPixelConfig; - - sk_sp<GrSurfaceContext> sContext = context->contextPriv().makeDeferredSurfaceContext( - desc, kTopLeft_GrSurfaceOrigin, GrMipMapped::kNo, SkBackingFit::kApprox, - SkBudgeted::kYes); - if (!sContext) { + SkBitmap bm; + if (!bm.installPixels(SkImageInfo::MakeA8(dstM.fBounds.width(), dstM.fBounds.height()), + autoDst.release(), dstM.fRowBytes, mask_release_proc, nullptr)) { return false; } + bm.setImmutable(); - SkImageInfo ii = SkImageInfo::MakeA8(desc.fWidth, desc.fHeight); - if (!sContext->writePixels(ii, dstM.fImage, dstM.fRowBytes, 0, 0)) { - return false; - } + sk_sp<SkImage> image = SkImage::MakeFromBitmap(bm); + + auto proxyProvider = context->contextPriv().proxyProvider(); + sk_sp<GrTextureProxy> maskProxy = proxyProvider->createTextureProxy(std::move(image), + kNone_GrSurfaceFlags, + 1, SkBudgeted::kYes, + SkBackingFit::kApprox); return draw_mask(renderTargetContext, clipData, viewMatrix, - dstM.fBounds, std::move(paint), sContext->asTextureProxyRef()); + dstM.fBounds, std::move(paint), std::move(maskProxy)); } // Create a mask of 'devPath' and place the result in 'mask'. diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index 9a9c2d509a..fe42a9391e 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -44,12 +44,12 @@ void GrGpu::disconnect(DisconnectType) {} //////////////////////////////////////////////////////////////////////////////// -bool GrGpu::isACopyNeededForTextureParams(int width, int height, +bool GrGpu::IsACopyNeededForTextureParams(const GrCaps* caps, + int width, int height, const GrSamplerState& textureParams, GrTextureProducer::CopyParams* copyParams, - SkScalar scaleAdjust[2]) const { - const GrCaps& caps = *this->caps(); - if (textureParams.isRepeated() && !caps.npotTextureTileSupport() && + SkScalar scaleAdjust[2]) { + if (textureParams.isRepeated() && !caps->npotTextureTileSupport() && (!SkIsPow2(width) || !SkIsPow2(height))) { SkASSERT(scaleAdjust); copyParams->fWidth = GrNextPow2(width); diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h index 786fb31107..b06b0d7481 100644 --- a/src/gpu/GrGpu.h +++ b/src/gpu/GrGpu.h @@ -480,9 +480,9 @@ public: // Determines whether a texture will need to be rescaled in order to be used with the // GrSamplerState. This variation is called when the caller will create a new texture using the // resource provider from a non-texture src (cpu-backed image, ...). - bool isACopyNeededForTextureParams(int width, int height, const GrSamplerState&, - GrTextureProducer::CopyParams*, - SkScalar scaleAdjust[2]) const; + static bool IsACopyNeededForTextureParams(const GrCaps*, int width, int height, + const GrSamplerState&, GrTextureProducer::CopyParams*, + SkScalar scaleAdjust[2]); // Like the above but this variation should be called when the caller is not creating the // original texture but rather was handed the original texture. It adds additional checks @@ -491,8 +491,8 @@ public: bool isACopyNeededForTextureParams(GrTextureProxy* proxy, const GrSamplerState& params, GrTextureProducer::CopyParams* copyParams, SkScalar scaleAdjust[2]) const { - if (this->isACopyNeededForTextureParams(proxy->width(), proxy->height(), params, - copyParams, scaleAdjust)) { + if (IsACopyNeededForTextureParams(this->caps(), proxy->width(), proxy->height(), params, + copyParams, scaleAdjust)) { return true; } return this->onIsACopyNeededForTextureParams(proxy, params, copyParams, scaleAdjust); diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp index c78e9989df..76414b5945 100644 --- a/src/gpu/GrSurfaceProxy.cpp +++ b/src/gpu/GrSurfaceProxy.cpp @@ -22,6 +22,9 @@ #include "SkMipMap.h" #ifdef SK_DEBUG +#include "GrRenderTarget.h" +#include "GrRenderTargetPriv.h" + static bool is_valid_fully_lazy(const GrSurfaceDesc& desc, SkBackingFit fit) { return desc.fWidth <= 0 && desc.fHeight <= 0 && @@ -171,9 +174,17 @@ sk_sp<GrSurface> GrSurfaceProxy::createSurfaceImpl( void GrSurfaceProxy::assign(sk_sp<GrSurface> surface) { SkASSERT(!fTarget && surface); fTarget = surface.release(); + this->INHERITED::transferRefs(); #ifdef SK_DEBUG + if (this->asRenderTargetProxy()) { + SkASSERT(fTarget->asRenderTarget()); + if (this->asRenderTargetProxy()->needsStencil()) { + SkASSERT(fTarget->asRenderTarget()->renderTargetPriv().getStencilAttachment()); + } + } + if (kInvalidGpuMemorySize != this->getRawGpuMemorySize_debugOnly()) { SkASSERT(fTarget->gpuMemorySize() <= this->getRawGpuMemorySize_debugOnly()); } @@ -393,6 +404,12 @@ bool GrSurfaceProxyPriv::doLazyInstantiation(GrResourceProvider* resourceProvide fProxy->fWidth = surface->width(); fProxy->fHeight = surface->height(); + bool needsStencil = fProxy->asRenderTargetProxy() + ? fProxy->asRenderTargetProxy()->needsStencil() + : false; + + GrSurfaceProxyPriv::AttachStencilIfNeeded(resourceProvider, surface.get(), needsStencil); + SkASSERT(surface->config() == fProxy->fConfig); SkDEBUGCODE(fProxy->validateLazySurface(surface.get());) this->assign(std::move(surface)); diff --git a/src/gpu/GrTextureMaker.cpp b/src/gpu/GrTextureMaker.cpp index 5043675a0d..720f357a68 100644 --- a/src/gpu/GrTextureMaker.cpp +++ b/src/gpu/GrTextureMaker.cpp @@ -28,16 +28,17 @@ sk_sp<GrTextureProxy> GrTextureMaker::refTextureProxyForParams(const GrSamplerSt *texColorSpace = this->getColorSpace(dstColorSpace); } - GrGpu* gpu = fContext->contextPriv().getGpu(); sk_sp<GrTextureProxy> original(this->refOriginalTextureProxy(willBeMipped, dstColorSpace, AllowedTexGenType::kCheap)); if (original) { + GrGpu* gpu = fContext->contextPriv().getGpu(); + if (!gpu->isACopyNeededForTextureParams(original.get(), params, ©Params, scaleAdjust)) { return original; } } else { - if (!gpu->isACopyNeededForTextureParams(this->width(), this->height(), - params, ©Params, scaleAdjust)) { + if (!GrGpu::IsACopyNeededForTextureParams(fContext->caps(), this->width(), this->height(), + params, ©Params, scaleAdjust)) { return this->refOriginalTextureProxy(willBeMipped, dstColorSpace, AllowedTexGenType::kAny); } diff --git a/src/gpu/effects/GrTextureStripAtlas.cpp b/src/gpu/effects/GrTextureStripAtlas.cpp index 0025af0a59..59a35bcc6b 100644 --- a/src/gpu/effects/GrTextureStripAtlas.cpp +++ b/src/gpu/effects/GrTextureStripAtlas.cpp @@ -25,6 +25,7 @@ class GrTextureStripAtlas::Hash : public SkTDynamicHash<GrTextureStripAtlas::Atl int32_t GrTextureStripAtlas::gCacheCount = 0; +// DDL TODO: The texture strip atlas can't have this global! GrTextureStripAtlas::Hash* GrTextureStripAtlas::gAtlasCache = nullptr; GrTextureStripAtlas::Hash* GrTextureStripAtlas::GetCache() { |