Allow GrSingleTextureEffect to take GrTextureProxies
Change-Id: I1dd441a5838f665c6815a5c629f5763f43f66e09 Reviewed-on: https://skia-review.googlesource.com/7429 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
This commit is contained in:
parent
c8c901fc36
commit
901f29ad3e
115
gm/texdata.cpp
115
gm/texdata.cpp
@ -11,13 +11,56 @@
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrContext.h"
|
||||
#include "GrContextPriv.h"
|
||||
#include "GrRenderTargetContext.h"
|
||||
#include "GrTextureContext.h"
|
||||
#include "GrFixedClip.h"
|
||||
#include "SkColorPriv.h"
|
||||
#include "effects/GrPorterDuffXferProcessor.h"
|
||||
#include "effects/GrSimpleTextureEffect.h"
|
||||
|
||||
constexpr int S = 200;
|
||||
constexpr int kStride = 2 * S;
|
||||
|
||||
// Fill in the pixels:
|
||||
// gray | white
|
||||
// -------------
|
||||
// black | gray
|
||||
static void fill_in_pixels(SkPMColor* pixels) {
|
||||
const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40);
|
||||
const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff);
|
||||
const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00);
|
||||
|
||||
int offset = 0;
|
||||
|
||||
// fill upper-left
|
||||
for (int y = 0; y < S; ++y) {
|
||||
for (int x = 0; x < S; ++x) {
|
||||
pixels[offset + y * kStride + x] = gray;
|
||||
}
|
||||
}
|
||||
// fill upper-right
|
||||
offset = S;
|
||||
for (int y = 0; y < S; ++y) {
|
||||
for (int x = 0; x < S; ++x) {
|
||||
pixels[offset + y * kStride + x] = white;
|
||||
}
|
||||
}
|
||||
// fill lower left
|
||||
offset = S * kStride;
|
||||
for (int y = 0; y < S; ++y) {
|
||||
for (int x = 0; x < S; ++x) {
|
||||
pixels[offset + y * kStride + x] = black;
|
||||
}
|
||||
}
|
||||
// fill lower right
|
||||
offset = S * kStride + S;
|
||||
for (int y = 0; y < S; ++y) {
|
||||
for (int x = 0; x < S; ++x) {
|
||||
pixels[offset + y * kStride + x] = gray;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
|
||||
GrRenderTargetContext* renderTargetContext =
|
||||
@ -32,56 +75,35 @@ DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
|
||||
return;
|
||||
}
|
||||
|
||||
const SkImageInfo ii = SkImageInfo::Make(S, S, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
|
||||
|
||||
SkAutoTArray<SkPMColor> gTextureData((2 * S) * (2 * S));
|
||||
constexpr int stride = 2 * S;
|
||||
const SkPMColor gray = SkPackARGB32(0x40, 0x40, 0x40, 0x40);
|
||||
const SkPMColor white = SkPackARGB32(0xff, 0xff, 0xff, 0xff);
|
||||
const SkPMColor red = SkPackARGB32(0x80, 0x80, 0x00, 0x00);
|
||||
const SkPMColor blue = SkPackARGB32(0x80, 0x00, 0x00, 0x80);
|
||||
const SkPMColor green = SkPackARGB32(0x80, 0x00, 0x80, 0x00);
|
||||
const SkPMColor black = SkPackARGB32(0x00, 0x00, 0x00, 0x00);
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
int offset = 0;
|
||||
// fill upper-left
|
||||
for (int y = 0; y < S; ++y) {
|
||||
for (int x = 0; x < S; ++x) {
|
||||
gTextureData[offset + y * stride + x] = gray;
|
||||
}
|
||||
}
|
||||
// fill upper-right
|
||||
offset = S;
|
||||
for (int y = 0; y < S; ++y) {
|
||||
for (int x = 0; x < S; ++x) {
|
||||
gTextureData[offset + y * stride + x] = white;
|
||||
}
|
||||
}
|
||||
// fill lower left
|
||||
offset = S * stride;
|
||||
for (int y = 0; y < S; ++y) {
|
||||
for (int x = 0; x < S; ++x) {
|
||||
gTextureData[offset + y * stride + x] = black;
|
||||
}
|
||||
}
|
||||
// fill lower right
|
||||
offset = S * stride + S;
|
||||
for (int y = 0; y < S; ++y) {
|
||||
for (int x = 0; x < S; ++x) {
|
||||
gTextureData[offset + y * stride + x] = gray;
|
||||
}
|
||||
}
|
||||
fill_in_pixels(gTextureData.get());
|
||||
|
||||
GrSurfaceDesc desc;
|
||||
desc.fOrigin = i ? kBottomLeft_GrSurfaceOrigin : kTopLeft_GrSurfaceOrigin;
|
||||
desc.fConfig = kSkia8888_GrPixelConfig;
|
||||
desc.fConfig = kBGRA_8888_GrPixelConfig;
|
||||
desc.fWidth = 2 * S;
|
||||
desc.fHeight = 2 * S;
|
||||
GrTexture* texture = context->textureProvider()->createTexture(
|
||||
desc, SkBudgeted::kNo, gTextureData.get(), 0);
|
||||
|
||||
if (!texture) {
|
||||
sk_sp<GrSurfaceProxy> proxy = GrSurfaceProxy::MakeDeferred(*context->caps(),
|
||||
context->textureProvider(),
|
||||
desc, SkBudgeted::kNo,
|
||||
gTextureData.get(), 0);
|
||||
if (!proxy) {
|
||||
return;
|
||||
}
|
||||
|
||||
sk_sp<GrSurfaceContext> tContext = context->contextPriv().makeWrappedSurfaceContext(
|
||||
std::move(proxy), nullptr);
|
||||
|
||||
if (!tContext) {
|
||||
return;
|
||||
}
|
||||
sk_sp<GrTexture> au(texture);
|
||||
|
||||
// setup new clip
|
||||
GrFixedClip clip(SkIRect::MakeWH(2*S, 2*S));
|
||||
@ -91,29 +113,28 @@ DEF_SIMPLE_GM_BG(texdata, canvas, 2 * S, 2 * S, SK_ColorBLACK) {
|
||||
|
||||
SkMatrix vm;
|
||||
if (i) {
|
||||
vm.setRotate(90 * SK_Scalar1,
|
||||
S * SK_Scalar1,
|
||||
S * SK_Scalar1);
|
||||
vm.setRotate(90 * SK_Scalar1, S * SK_Scalar1, S * SK_Scalar1);
|
||||
} else {
|
||||
vm.reset();
|
||||
}
|
||||
paint.addColorTextureProcessor(texture, nullptr, vm);
|
||||
paint.addColorTextureProcessor(context, sk_ref_sp(tContext->asDeferredTexture()),
|
||||
nullptr, vm);
|
||||
|
||||
renderTargetContext->drawRect(clip, GrPaint(paint), GrAA::kNo, vm,
|
||||
SkRect::MakeWH(2 * S, 2 * S));
|
||||
|
||||
// now update the lower right of the texture in first pass
|
||||
// or upper right in second pass
|
||||
offset = 0;
|
||||
for (int y = 0; y < S; ++y) {
|
||||
for (int x = 0; x < S; ++x) {
|
||||
gTextureData[offset + y * stride + x] =
|
||||
((x + y) % 2) ? (i ? green : red) : blue;
|
||||
gTextureData[y * kStride + x] = ((x + y) % 2) ? (i ? green : red) : blue;
|
||||
}
|
||||
}
|
||||
texture->writePixels(S, (i ? 0 : S), S, S,
|
||||
texture->config(), gTextureData.get(),
|
||||
4 * stride);
|
||||
|
||||
if (!tContext->writePixels(ii, gTextureData.get(), 4 * kStride, S, i ? 0 : S)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
renderTargetContext->drawRect(clip, std::move(paint), GrAA::kNo, vm,
|
||||
SkRect::MakeWH(2 * S, 2 * S));
|
||||
}
|
||||
|
@ -20,6 +20,8 @@
|
||||
#include "SkTLazy.h"
|
||||
#include "effects/GrPorterDuffXferProcessor.h"
|
||||
|
||||
class GrTextureProxy;
|
||||
|
||||
/**
|
||||
* The paint describes how color and coverage are computed at each pixel by GrContext draw
|
||||
* functions and the how color is blended with the destination pixel.
|
||||
@ -116,6 +118,16 @@ public:
|
||||
const GrSamplerParams&);
|
||||
void addCoverageTextureProcessor(GrTexture*, const SkMatrix&, const GrSamplerParams&);
|
||||
|
||||
|
||||
void addColorTextureProcessor(GrContext*, sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>,
|
||||
const SkMatrix&);
|
||||
void addColorTextureProcessor(GrContext*, sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>,
|
||||
const SkMatrix&, const GrSamplerParams&);
|
||||
|
||||
void addCoverageTextureProcessor(GrContext*, sk_sp<GrTextureProxy>, const SkMatrix&);
|
||||
void addCoverageTextureProcessor(GrContext*, sk_sp<GrTextureProxy>,
|
||||
const SkMatrix&, const GrSamplerParams&);
|
||||
|
||||
int numColorFragmentProcessors() const { return fColorFragmentProcessors.count(); }
|
||||
int numCoverageFragmentProcessors() const { return fCoverageFragmentProcessors.count(); }
|
||||
int numTotalFragmentProcessors() const { return this->numColorFragmentProcessors() +
|
||||
|
@ -211,6 +211,8 @@ public:
|
||||
SkShader::TileMode tileXAndY = SkShader::kClamp_TileMode,
|
||||
GrShaderFlags visibility = kFragment_GrShaderFlag);
|
||||
|
||||
TextureSampler(GrTextureProvider*, sk_sp<GrTextureProxy>, const GrSamplerParams&);
|
||||
|
||||
// MDB TODO: ultimately we shouldn't need the texProvider parameter
|
||||
explicit TextureSampler(GrTextureProvider*, sk_sp<GrTextureProxy>,
|
||||
GrSamplerParams::FilterMode = GrSamplerParams::kNone_FilterMode,
|
||||
|
@ -44,6 +44,37 @@ void GrPaint::addCoverageTextureProcessor(GrTexture* texture,
|
||||
params));
|
||||
}
|
||||
|
||||
void GrPaint::addColorTextureProcessor(GrContext* ctx, sk_sp<GrTextureProxy> proxy,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
const SkMatrix& matrix) {
|
||||
this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(ctx, std::move(proxy),
|
||||
std::move(colorSpaceXform),
|
||||
matrix));
|
||||
}
|
||||
|
||||
void GrPaint::addColorTextureProcessor(GrContext* ctx, sk_sp<GrTextureProxy> proxy,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
const SkMatrix& matrix,
|
||||
const GrSamplerParams& params) {
|
||||
this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(ctx,
|
||||
std::move(proxy),
|
||||
std::move(colorSpaceXform),
|
||||
matrix, params));
|
||||
}
|
||||
|
||||
void GrPaint::addCoverageTextureProcessor(GrContext* ctx, sk_sp<GrTextureProxy> proxy,
|
||||
const SkMatrix& matrix) {
|
||||
this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(ctx, std::move(proxy),
|
||||
nullptr, matrix));
|
||||
}
|
||||
|
||||
void GrPaint::addCoverageTextureProcessor(GrContext* ctx, sk_sp<GrTextureProxy> proxy,
|
||||
const SkMatrix& matrix,
|
||||
const GrSamplerParams& params) {
|
||||
this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(ctx, std::move(proxy),
|
||||
nullptr, matrix, params));
|
||||
}
|
||||
|
||||
bool GrPaint::internalIsConstantBlendedColor(GrColor paintColor, GrColor* color) const {
|
||||
GrProcOptInfo colorProcInfo(paintColor, kRGBA_GrColorComponentFlags);
|
||||
colorProcInfo.analyzeProcessors(
|
||||
|
@ -208,6 +208,14 @@ GrProcessor::TextureSampler::TextureSampler(GrTexture* texture,
|
||||
this->reset(texture, filterMode, tileXAndY, visibility);
|
||||
}
|
||||
|
||||
GrProcessor::TextureSampler::TextureSampler(GrTextureProvider* texProvider,
|
||||
sk_sp<GrTextureProxy> proxy,
|
||||
const GrSamplerParams& params) {
|
||||
// For now, end the deferral at this time. Once all the TextureSamplers are swapped over
|
||||
// to taking a GrSurfaceProxy just use the IORefs on the proxy
|
||||
this->reset(proxy->instantiate(texProvider), params);
|
||||
}
|
||||
|
||||
GrProcessor::TextureSampler::TextureSampler(GrTextureProvider* texProvider,
|
||||
sk_sp<GrTextureProxy> proxy,
|
||||
GrSamplerParams::FilterMode filterMode,
|
||||
@ -215,7 +223,7 @@ GrProcessor::TextureSampler::TextureSampler(GrTextureProvider* texProvider,
|
||||
GrShaderFlags visibility) {
|
||||
// For now, end the deferral at this time. Once all the TextureSamplers are swapped over
|
||||
// to taking a GrSurfaceProxy just use the IORefs on the proxy
|
||||
this->reset( proxy->instantiate(texProvider), filterMode, tileXAndY, visibility);
|
||||
this->reset(proxy->instantiate(texProvider), filterMode, tileXAndY, visibility);
|
||||
}
|
||||
|
||||
void GrProcessor::TextureSampler::reset(GrTexture* texture,
|
||||
|
@ -9,6 +9,7 @@
|
||||
#define GrSimpleTextureEffect_DEFINED
|
||||
|
||||
#include "GrSingleTextureEffect.h"
|
||||
#include "GrTextureProxy.h"
|
||||
|
||||
class GrInvariantOutput;
|
||||
|
||||
@ -28,6 +29,14 @@ public:
|
||||
GrSamplerParams::kNone_FilterMode));
|
||||
}
|
||||
|
||||
static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, sk_sp<GrTextureProxy> proxy,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
const SkMatrix& matrix) {
|
||||
return sk_sp<GrFragmentProcessor>(
|
||||
new GrSimpleTextureEffect(ctx, std::move(proxy), std::move(colorSpaceXform), matrix,
|
||||
GrSamplerParams::kNone_FilterMode));
|
||||
}
|
||||
|
||||
/* clamp mode */
|
||||
static sk_sp<GrFragmentProcessor> Make(GrTexture* tex,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
@ -37,6 +46,15 @@ public:
|
||||
new GrSimpleTextureEffect(tex, std::move(colorSpaceXform), matrix, filterMode));
|
||||
}
|
||||
|
||||
static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, sk_sp<GrTextureProxy> proxy,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
const SkMatrix& matrix,
|
||||
GrSamplerParams::FilterMode filterMode) {
|
||||
return sk_sp<GrFragmentProcessor>(
|
||||
new GrSimpleTextureEffect(ctx, std::move(proxy), std::move(colorSpaceXform),
|
||||
matrix, filterMode));
|
||||
}
|
||||
|
||||
static sk_sp<GrFragmentProcessor> Make(GrTexture* tex,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
const SkMatrix& matrix,
|
||||
@ -45,6 +63,15 @@ public:
|
||||
matrix, p));
|
||||
}
|
||||
|
||||
static sk_sp<GrFragmentProcessor> Make(GrContext* ctx, sk_sp<GrTextureProxy> proxy,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
const SkMatrix& matrix,
|
||||
const GrSamplerParams& p) {
|
||||
return sk_sp<GrFragmentProcessor>(new GrSimpleTextureEffect(ctx, std::move(proxy),
|
||||
std::move(colorSpaceXform),
|
||||
matrix, p));
|
||||
}
|
||||
|
||||
virtual ~GrSimpleTextureEffect() {}
|
||||
|
||||
const char* name() const override { return "SimpleTexture"; }
|
||||
@ -58,6 +85,15 @@ private:
|
||||
this->initClassID<GrSimpleTextureEffect>();
|
||||
}
|
||||
|
||||
GrSimpleTextureEffect(GrContext* ctx, sk_sp<GrTextureProxy> proxy,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
const SkMatrix& matrix,
|
||||
GrSamplerParams::FilterMode filterMode)
|
||||
: GrSingleTextureEffect(ctx, std::move(proxy), std::move(colorSpaceXform),
|
||||
matrix, filterMode) {
|
||||
this->initClassID<GrSimpleTextureEffect>();
|
||||
}
|
||||
|
||||
GrSimpleTextureEffect(GrTexture* texture,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
const SkMatrix& matrix,
|
||||
@ -66,6 +102,14 @@ private:
|
||||
this->initClassID<GrSimpleTextureEffect>();
|
||||
}
|
||||
|
||||
GrSimpleTextureEffect(GrContext* ctx, sk_sp<GrTextureProxy> proxy,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
const SkMatrix& matrix,
|
||||
const GrSamplerParams& params)
|
||||
: GrSingleTextureEffect(ctx, std::move(proxy), std::move(colorSpaceXform), matrix, params) {
|
||||
this->initClassID<GrSimpleTextureEffect>();
|
||||
}
|
||||
|
||||
GrGLSLFragmentProcessor* onCreateGLSLInstance() const override;
|
||||
|
||||
void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
|
||||
|
@ -7,6 +7,9 @@
|
||||
|
||||
#include "effects/GrSingleTextureEffect.h"
|
||||
|
||||
#include "GrContext.h"
|
||||
#include "GrTextureProxy.h"
|
||||
|
||||
GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
const SkMatrix& m)
|
||||
@ -39,5 +42,37 @@ GrSingleTextureEffect::GrSingleTextureEffect(GrTexture* texture,
|
||||
this->addTextureSampler(&fTextureSampler);
|
||||
}
|
||||
|
||||
GrSingleTextureEffect::GrSingleTextureEffect(GrContext* ctx, sk_sp<GrTextureProxy> proxy,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
const SkMatrix& m)
|
||||
: fCoordTransform(ctx, m, proxy.get(), GrSamplerParams::kNone_FilterMode)
|
||||
, fTextureSampler(ctx->textureProvider(), std::move(proxy))
|
||||
, fColorSpaceXform(std::move(colorSpaceXform)) {
|
||||
this->addCoordTransform(&fCoordTransform);
|
||||
this->addTextureSampler(&fTextureSampler);
|
||||
}
|
||||
|
||||
GrSingleTextureEffect::GrSingleTextureEffect(GrContext* ctx, sk_sp<GrTextureProxy> proxy,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
const SkMatrix& m,
|
||||
GrSamplerParams::FilterMode filterMode)
|
||||
: fCoordTransform(ctx, m, proxy.get(), filterMode)
|
||||
, fTextureSampler(ctx->textureProvider(), std::move(proxy), filterMode)
|
||||
, fColorSpaceXform(std::move(colorSpaceXform)) {
|
||||
this->addCoordTransform(&fCoordTransform);
|
||||
this->addTextureSampler(&fTextureSampler);
|
||||
}
|
||||
|
||||
GrSingleTextureEffect::GrSingleTextureEffect(GrContext* ctx, sk_sp<GrTextureProxy> proxy,
|
||||
sk_sp<GrColorSpaceXform> colorSpaceXform,
|
||||
const SkMatrix& m,
|
||||
const GrSamplerParams& params)
|
||||
: fCoordTransform(ctx, m, proxy.get(), params.filterMode())
|
||||
, fTextureSampler(ctx->textureProvider(), std::move(proxy), params)
|
||||
, fColorSpaceXform(std::move(colorSpaceXform)) {
|
||||
this->addCoordTransform(&fCoordTransform);
|
||||
this->addTextureSampler(&fTextureSampler);
|
||||
}
|
||||
|
||||
GrSingleTextureEffect::~GrSingleTextureEffect() {
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "SkMatrix.h"
|
||||
|
||||
class GrTexture;
|
||||
class GrTextureProxy;
|
||||
|
||||
/**
|
||||
* A base class for effects that draw a single texture with a texture matrix. This effect has no
|
||||
@ -43,6 +44,17 @@ protected:
|
||||
const SkMatrix&,
|
||||
const GrSamplerParams&);
|
||||
|
||||
/** unfiltered, clamp mode */
|
||||
GrSingleTextureEffect(GrContext*,
|
||||
sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>, const SkMatrix&);
|
||||
/** clamp mode */
|
||||
GrSingleTextureEffect(GrContext*,
|
||||
sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>, const SkMatrix&,
|
||||
GrSamplerParams::FilterMode filterMode);
|
||||
GrSingleTextureEffect(GrContext*,
|
||||
sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>, const SkMatrix&,
|
||||
const GrSamplerParams&);
|
||||
|
||||
/**
|
||||
* Can be used as a helper to implement subclass onComputeInvariantOutput(). It assumes that
|
||||
* the subclass output color will be a modulation of the input color with a value read from the
|
||||
|
Loading…
Reference in New Issue
Block a user