Revert "Convert GrConfigConversionEffect to a runtime FP"
This reverts commit 4a778130080c181dd7fb3df7d7aeb0e35b049f1e.
Reason for revert: Memory regression in Chrome.
Original change's description:
> Convert GrConfigConversionEffect to a runtime FP
>
> Change-Id: I7f22447cf3356b1558d73665ff3e9b61639ebe83
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/423576
> Auto-Submit: Brian Osman <brianosman@google.com>
> Commit-Queue: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>
TBR=bsalomon@google.com,brianosman@google.com,ethannicholas@google.com
Change-Id: I05497295b88b378f0aa236f18118fe676bbf05c9
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/424256
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/GrDirectContextPriv.cpp b/src/gpu/GrDirectContextPriv.cpp
index dc770f9..b00a1a2 100644
--- a/src/gpu/GrDirectContextPriv.cpp
+++ b/src/gpu/GrDirectContextPriv.cpp
@@ -9,7 +9,6 @@
#include "include/gpu/GrContextThreadSafeProxy.h"
#include "include/gpu/GrDirectContext.h"
-#include "src/core/SkRuntimeEffectPriv.h"
#include "src/gpu/GrAuditTrail.h"
#include "src/gpu/GrContextThreadSafeProxyPriv.h"
#include "src/gpu/GrDrawingManager.h"
@@ -22,6 +21,7 @@
#include "src/gpu/GrThreadSafePipelineBuilder.h"
#include "src/gpu/SkGr.h"
#include "src/gpu/effects/GrSkSLFP.h"
+#include "src/gpu/effects/generated/GrConfigConversionEffect.h"
#include "src/gpu/text/GrAtlasManager.h"
#include "src/gpu/text/GrTextBlobCache.h"
#include "src/image/SkImage_Base.h"
@@ -192,129 +192,12 @@
}
#endif
-// Both of these effects aggressively round to the nearest exact (N / 255) floating point values.
-// This lets us find a round-trip preserving pair on some GPUs that do odd byte to float conversion.
-static std::unique_ptr<GrFragmentProcessor> make_premul_effect(
- std::unique_ptr<GrFragmentProcessor> fp) {
- if (!fp) {
- return nullptr;
- }
-
- static auto effect = SkMakeRuntimeEffect(SkRuntimeEffect::MakeForColorFilter, R"(
- half4 main(half4 color) {
- color = floor(color * 255 + 0.5) / 255;
- color.rgb = floor(color.rgb * color.a * 255 + 0.5) / 255;
- return color;
- }
- )");
-
- fp = GrSkSLFP::Make(effect, "ToPremul", std::move(fp), GrSkSLFP::OptFlags::kNone);
- return GrFragmentProcessor::HighPrecision(std::move(fp));
-}
-
-static std::unique_ptr<GrFragmentProcessor> make_unpremul_effect(
- std::unique_ptr<GrFragmentProcessor> fp) {
- if (!fp) {
- return nullptr;
- }
-
- static auto effect = SkMakeRuntimeEffect(SkRuntimeEffect::MakeForColorFilter, R"(
- half4 main(half4 color) {
- color = floor(color * 255 + 0.5) / 255;
- color.rgb = color.a <= 0 ? half3(0) : floor(color.rgb / color.a * 255 + 0.5) / 255;
- return color;
- }
- )");
-
- fp = GrSkSLFP::Make(effect, "ToUnpremul", std::move(fp), GrSkSLFP::OptFlags::kNone);
- return GrFragmentProcessor::HighPrecision(std::move(fp));
-}
-
-static bool test_for_preserving_PM_conversions(GrDirectContext* dContext) {
- static constexpr int kSize = 256;
- SkAutoTMalloc<uint32_t> data(kSize * kSize * 3);
- uint32_t* srcData = data.get();
-
- // Fill with every possible premultiplied A, color channel value. There will be 256-y duplicate
- // values in row y. We set r, g, and b to the same value since they are handled identically.
- for (int y = 0; y < kSize; ++y) {
- for (int x = 0; x < kSize; ++x) {
- uint8_t* color = reinterpret_cast<uint8_t*>(&srcData[kSize*y + x]);
- color[3] = y;
- color[2] = std::min(x, y);
- color[1] = std::min(x, y);
- color[0] = std::min(x, y);
- }
- }
-
- const SkImageInfo pmII =
- SkImageInfo::Make(kSize, kSize, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
- const SkImageInfo upmII = pmII.makeAlphaType(kUnpremul_SkAlphaType);
-
- auto readSFC = GrSurfaceFillContext::Make(dContext, upmII, SkBackingFit::kExact);
- auto tempSFC = GrSurfaceFillContext::Make(dContext, pmII, SkBackingFit::kExact);
- if (!readSFC || !tempSFC) {
- return false;
- }
-
- // This function is only ever called if we are in a GrDirectContext since we are calling read
- // pixels here. Thus the pixel data will be uploaded immediately and we don't need to keep the
- // pixel data alive in the proxy. Therefore the ReleaseProc is nullptr.
- SkBitmap bitmap;
- bitmap.installPixels(pmII, srcData, 4 * kSize);
- bitmap.setImmutable();
-
- auto dataView = std::get<0>(GrMakeUncachedBitmapProxyView(dContext, bitmap));
- if (!dataView) {
- return false;
- }
-
- uint32_t* firstRead = data.get() + kSize*kSize;
- uint32_t* secondRead = data.get() + 2*kSize*kSize;
- std::fill_n( firstRead, kSize*kSize, 0);
- std::fill_n(secondRead, kSize*kSize, 0);
-
- GrPixmap firstReadPM( upmII, firstRead, kSize*sizeof(uint32_t));
- GrPixmap secondReadPM(upmII, secondRead, kSize*sizeof(uint32_t));
-
- // We do a PM->UPM draw from dataTex to readTex and read the data. Then we do a UPM->PM draw
- // from readTex to tempTex followed by a PM->UPM draw to readTex and finally read the data.
- // We then verify that two reads produced the same values.
-
- auto fp1 = make_unpremul_effect(GrTextureEffect::Make(std::move(dataView), bitmap.alphaType()));
- readSFC->fillRectWithFP(SkIRect::MakeWH(kSize, kSize), std::move(fp1));
- if (!readSFC->readPixels(dContext, firstReadPM, {0, 0})) {
- return false;
- }
-
- auto fp2 = make_premul_effect(
- GrTextureEffect::Make(readSFC->readSurfaceView(), readSFC->colorInfo().alphaType()));
- tempSFC->fillRectWithFP(SkIRect::MakeWH(kSize, kSize), std::move(fp2));
-
- auto fp3 = make_unpremul_effect(
- GrTextureEffect::Make(tempSFC->readSurfaceView(), tempSFC->colorInfo().alphaType()));
- readSFC->fillRectWithFP(SkIRect::MakeWH(kSize, kSize), std::move(fp3));
-
- if (!readSFC->readPixels(dContext, secondReadPM, {0, 0})) {
- return false;
- }
-
- for (int y = 0; y < kSize; ++y) {
- for (int x = 0; x <= y; ++x) {
- if (firstRead[kSize*y + x] != secondRead[kSize*y + x]) {
- return false;
- }
- }
- }
-
- return true;
-}
-
bool GrDirectContextPriv::validPMUPMConversionExists() {
ASSERT_SINGLE_OWNER
if (!fContext->fDidTestPMConversions) {
- fContext->fPMUPMConversionsRoundTrip = test_for_preserving_PM_conversions(fContext);
+ fContext->fPMUPMConversionsRoundTrip =
+ GrConfigConversionEffect::TestForPreservingPMConversions(fContext);
fContext->fDidTestPMConversions = true;
}
@@ -330,7 +213,7 @@
// ...and it should have succeeded
SkASSERT(this->validPMUPMConversionExists());
- return make_unpremul_effect(std::move(fp));
+ return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToUnpremul);
}
std::unique_ptr<GrFragmentProcessor> GrDirectContextPriv::createUPMToPMEffect(
@@ -341,7 +224,7 @@
// ...and it should have succeeded
SkASSERT(this->validPMUPMConversionExists());
- return make_premul_effect(std::move(fp));
+ return GrConfigConversionEffect::Make(std::move(fp), PMConversion::kToPremul);
}
sk_sp<SkBaseGpuDevice> GrDirectContextPriv::createDevice(GrColorType colorType,