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>
diff --git a/gm/texdata.cpp b/gm/texdata.cpp
index 70afd22..6b229a3 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 @@
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 0bebd8c..d5d98d5 100644
--- a/gm/texturedomaineffect.cpp
+++ b/gm/texturedomaineffect.cpp
@@ -43,7 +43,10 @@
}
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 @@
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 @@
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 @@
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 29356fc..c335c98 100644
--- a/gm/windowrectangles.cpp
+++ b/gm/windowrectangles.cpp
@@ -153,9 +153,10 @@
*/
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 @@
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 @@
// 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 fa82f90..1835fe3 100644
--- a/gm/yuvtorgbeffect.cpp
+++ b/gm/yuvtorgbeffect.cpp
@@ -86,11 +86,11 @@
{
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 @@
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(),