diff options
author | Robert Phillips <robertphillips@google.com> | 2018-03-08 09:51:04 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-03-08 15:26:51 +0000 |
commit | c7c2baf0cf264b9d0d9c0f67cfb827a7e4a5e32c (patch) | |
tree | 6af65cc34a6b4557fd24d029c447c2822bdb9699 /src/effects | |
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/effects')
-rw-r--r-- | src/effects/GrCircleBlurFragmentProcessor.cpp | 32 | ||||
-rw-r--r-- | src/effects/GrCircleBlurFragmentProcessor.fp | 34 |
2 files changed, 33 insertions, 33 deletions
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; } |