diff options
author | Robert Phillips <robertphillips@google.com> | 2017-01-30 08:06:27 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-01-30 13:40:15 +0000 |
commit | 40fd7c94c24bb30d888c3d85a79cbb96c7fbf800 (patch) | |
tree | 075e886c01de864ba982910f1854f47ba1ae95d8 /gm | |
parent | 55b72530fedeb58154635531751a8730982fbf2a (diff) |
Push GrTextureProxy down to more effects
Change-Id: Ie3f32a88f25af082c25bc6daf3fe24e303e80f9e
Reviewed-on: https://skia-review.googlesource.com/7616
Commit-Queue: Robert Phillips <robertphillips@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'gm')
-rw-r--r-- | gm/texdata.cpp | 3 | ||||
-rw-r--r-- | gm/texturedomaineffect.cpp | 30 | ||||
-rw-r--r-- | gm/windowrectangles.cpp | 10 | ||||
-rw-r--r-- | gm/yuvtorgbeffect.cpp | 6 |
4 files changed, 29 insertions, 20 deletions
diff --git a/gm/texdata.cpp b/gm/texdata.cpp index 70afd22ec5..6b229a3db3 100644 --- a/gm/texdata.cpp +++ b/gm/texdata.cpp @@ -16,6 +16,7 @@ #include "GrTextureContext.h" #include "GrFixedClip.h" #include "SkColorPriv.h" +#include "SkGr.h" #include "effects/GrPorterDuffXferProcessor.h" #include "effects/GrSimpleTextureEffect.h" @@ -86,9 +87,9 @@ DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) { GrSurfaceDesc desc; desc.fOrigin = i ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin; - desc.fConfig = kBGRA_8888_GrPixelConfig; desc.fWidth = 2 * S; desc.fHeight = 2 * S; + desc.fConfig = SkImageInfo2GrPixelConfig(ii, *context->caps()); sk_sp<GrSurfaceProxy> proxy = GrSurfaceProxy::MakeDeferred(*context->caps(), context->textureProvider(), diff --git a/gm/texturedomaineffect.cpp b/gm/texturedomaineffect.cpp index 0bebd8c97d..d5d98d556a 100644 --- a/gm/texturedomaineffect.cpp +++ b/gm/texturedomaineffect.cpp @@ -43,7 +43,10 @@ protected: } void onOnceBeforeDraw() override { - fBmp.allocN32Pixels(kTargetWidth, kTargetHeight); + // TODO: do this with surfaces & images and gpu backend + SkImageInfo ii = SkImageInfo::Make(kTargetWidth, kTargetHeight, kN32_SkColorType, + kPremul_SkAlphaType); + fBmp.allocPixels(ii); SkCanvas canvas(fBmp); canvas.clear(0x00000000); SkPaint paint; @@ -82,9 +85,17 @@ protected: return; } - sk_sp<GrTexture> texture( - GrRefCachedBitmapTexture(context, fBmp, GrSamplerParams::ClampNoFilter(), nullptr)); - if (!texture) { + GrSurfaceDesc desc; + desc.fWidth = fBmp.width(); + desc.fHeight = fBmp.height(); + desc.fConfig = SkImageInfo2GrPixelConfig(fBmp.info(), *context->caps()); + + sk_sp<GrSurfaceProxy> proxy(GrSurfaceProxy::MakeDeferred(*context->caps(), + context->textureProvider(), + desc, SkBudgeted::kYes, + fBmp.getPixels(), + fBmp.rowBytes())); + if (!proxy || !proxy->asTextureProxy()) { return; } @@ -92,14 +103,12 @@ protected: textureMatrices.push_back() = SkMatrix::I(); textureMatrices.push_back() = SkMatrix::MakeScale(1.5f, 0.85f); textureMatrices.push_back(); - textureMatrices.back().setRotate(45.f, texture->width() / 2.f, texture->height() / 2.f); + textureMatrices.back().setRotate(45.f, proxy->width() / 2.f, proxy->height() / 2.f); const SkIRect texelDomains[] = { fBmp.bounds(), - SkIRect::MakeXYWH(fBmp.width() / 4, - fBmp.height() / 4, - fBmp.width() / 2, - fBmp.height() / 2), + SkIRect::MakeXYWH(fBmp.width() / 4, fBmp.height() / 4, + fBmp.width() / 2, fBmp.height() / 2), }; SkRect renderRect = SkRect::Make(fBmp.bounds()); @@ -115,7 +124,8 @@ protected: grPaint.setXPFactory(GrPorterDuffXPFactory::Get(SkBlendMode::kSrc)); sk_sp<GrFragmentProcessor> fp( GrTextureDomainEffect::Make( - texture.get(), nullptr, textureMatrices[tm], + context, sk_ref_sp(proxy->asTextureProxy()), + nullptr, textureMatrices[tm], GrTextureDomain::MakeTexelDomainForMode(texelDomains[d], mode), mode, GrSamplerParams::kNone_FilterMode)); diff --git a/gm/windowrectangles.cpp b/gm/windowrectangles.cpp index 29356fc72a..c335c985ad 100644 --- a/gm/windowrectangles.cpp +++ b/gm/windowrectangles.cpp @@ -153,9 +153,10 @@ private: */ class AlphaOnlyClip final : public MaskOnlyClipBase { public: - AlphaOnlyClip(GrTexture* mask, int x, int y) { + AlphaOnlyClip(GrContext* context, sk_sp<GrTextureProxy> mask, int x, int y) { int w = mask->width(), h = mask->height(); - fFP = GrDeviceSpaceTextureDecalFragmentProcessor::Make(mask, SkIRect::MakeWH(w, h), {x, y}); + fFP = GrDeviceSpaceTextureDecalFragmentProcessor::Make(context, std::move(mask), + SkIRect::MakeWH(w, h), {x, y}); } private: bool apply(GrContext*, GrRenderTargetContext*, bool, bool, GrAppliedClip* out) const override { @@ -216,7 +217,6 @@ void WindowRectanglesMaskGM::visualizeAlphaMask(GrContext* ctx, GrRenderTargetCo SkRegion::kDifference_Op, false, GrAA::kNo, SkMatrix::I(), SkRect::MakeIWH(maskRTC->width(), maskRTC->height())); reducedClip.drawAlphaClipMask(maskRTC.get()); - sk_sp<GrTexture> mask(maskRTC->asTexture()); int x = kCoverRect.x() - kLayerRect.x(), y = kCoverRect.y() - kLayerRect.y(); @@ -224,9 +224,9 @@ void WindowRectanglesMaskGM::visualizeAlphaMask(GrContext* ctx, GrRenderTargetCo // Now visualize the alpha mask by drawing a rect over the area where it is defined. The regions // inside window rectangles or outside the scissor should still have the initial checkerboard // intact. (This verifies we didn't spend any time modifying those pixels in the mask.) - AlphaOnlyClip clip(mask.get(), x, y); + AlphaOnlyClip clip(ctx, sk_ref_sp(maskRTC->asDeferredTexture()), x, y); rtc->drawRect(clip, std::move(paint), GrAA::kYes, SkMatrix::I(), - SkRect::Make(SkIRect::MakeXYWH(x, y, mask->width(), mask->height()))); + SkRect::Make(SkIRect::MakeXYWH(x, y, maskRTC->width(), maskRTC->height()))); } void WindowRectanglesMaskGM::visualizeStencilMask(GrContext* ctx, GrRenderTargetContext* rtc, diff --git a/gm/yuvtorgbeffect.cpp b/gm/yuvtorgbeffect.cpp index fa82f9090b..1835fe3446 100644 --- a/gm/yuvtorgbeffect.cpp +++ b/gm/yuvtorgbeffect.cpp @@ -86,11 +86,11 @@ protected: { GrSurfaceDesc desc; desc.fOrigin = kTopLeft_GrSurfaceOrigin; - desc.fConfig = kAlpha_8_GrPixelConfig; for (int i = 0; i < 3; ++i) { desc.fWidth = fBmp[i].width(); desc.fHeight = fBmp[i].height(); + desc.fConfig = SkImageInfo2GrPixelConfig(fBmp[i].info(), *context->caps()); proxy[i] = GrSurfaceProxy::MakeDeferred(*context->caps(), context->textureProvider(), @@ -221,11 +221,9 @@ protected: for (int i = 0; i < 3; ++i) { int index = (0 == i) ? 0 : 1; - desc.fConfig = kAlpha_8_SkColorType == fBmp[index].colorType() - ? kAlpha_8_GrPixelConfig - : kBGRA_8888_GrPixelConfig; desc.fWidth = fBmp[index].width(); desc.fHeight = fBmp[index].height(); + desc.fConfig = SkImageInfo2GrPixelConfig(fBmp[index].info(), *context->caps()); proxy[i] = GrSurfaceProxy::MakeDeferred(*context->caps(), context->textureProvider(), |