aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Robert Phillips <robertphillips@google.com>2017-03-27 11:08:16 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-27 16:31:02 +0000
commit3798c86f6885f0b47fb2e659a43b48a4468a97ef (patch)
tree8670d4adcc7889af63b4168256f0325aa78aa3bd
parent465748c246dde8c131effdfa69aed82ef7a48af8 (diff)
Remove GrFragmentProcessor-derived class' GrTexture-based ctors
Split out into: https://skia-review.googlesource.com/c/8881/ (Switch GrTextureStripAtlas over to GrTextureProxies) https://skia-review.googlesource.com/c/8942/ (Wrap cached GrTextures in GrTextureProxies (e.g., blur profiles, nine-patch blurs, etc.)) https://skia-review.googlesource.com/c/8997/ (Clean up/remove unused GrFragmentProcessor-derived ctors) https://skia-review.googlesource.com/c/9191/ (Switch SkImageGenerator over to generating GrTextureProxies) https://skia-review.googlesource.com/c/9448/ (Switch GrYUVProvider over to GrTextureProxies) https://skia-review.googlesource.com/c/9559/ (Preparatory Proxification) https://skia-review.googlesource.com/c/9626/ (Consolidate Proxy caching code in GrResourceProvider) https://skia-review.googlesource.com/c/9683/ (More pre-emptive proxification) https://skia-review.googlesource.com/c/9917/ (Make experimental Perlin noise shader take texture proxies) https://skia-review.googlesource.com/c/9961/ (rename makeCopyForTextureParams to isACopyNeededForTextureParams) https://skia-review.googlesource.com/c/9945/ (Make SkImageCacherator be deferred) https://skia-review.googlesource.com/c/10180/ (Add new proxy-based DetermineDomainMode w/ test) Change-Id: Ia33389d92360e542a9d2bf395948deb04d017465 Reviewed-on: https://skia-review.googlesource.com/8823 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Robert Phillips <robertphillips@google.com>
-rw-r--r--src/core/SkImageCacherator.cpp6
-rw-r--r--src/gpu/GrGpu.h8
-rw-r--r--src/gpu/GrPaint.cpp28
-rw-r--r--src/gpu/GrPaint.h7
-rw-r--r--src/gpu/GrResourceProvider.h15
-rw-r--r--src/gpu/GrSurfaceProxyPriv.h6
-rw-r--r--src/gpu/GrTextureAdjuster.cpp61
-rw-r--r--src/gpu/GrTextureAdjuster.h23
-rw-r--r--src/gpu/GrTextureMaker.cpp48
-rw-r--r--src/gpu/GrTextureMaker.h11
-rw-r--r--src/gpu/GrTextureProducer.cpp219
-rw-r--r--src/gpu/GrTextureProducer.h20
-rw-r--r--src/gpu/SkGpuDevice.cpp31
-rw-r--r--src/gpu/SkGr.cpp6
-rw-r--r--src/gpu/effects/GrBicubicEffect.cpp22
-rw-r--r--src/gpu/effects/GrBicubicEffect.h27
-rw-r--r--src/gpu/effects/GrTextureDomain.cpp49
-rw-r--r--src/gpu/effects/GrTextureDomain.h19
-rw-r--r--src/gpu/gl/GrGLGpu.cpp12
-rw-r--r--src/gpu/gl/GrGLGpu.h2
-rw-r--r--src/image/SkImage_Base.h4
-rw-r--r--src/image/SkImage_Gpu.cpp26
-rw-r--r--src/image/SkImage_Gpu.h4
-rw-r--r--src/image/SkImage_Raster.cpp39
24 files changed, 139 insertions, 554 deletions
diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp
index 06d2279946..76da0e762e 100644
--- a/src/core/SkImageCacherator.cpp
+++ b/src/core/SkImageCacherator.cpp
@@ -627,12 +627,10 @@ sk_sp<GrTextureProxy> SkImageCacherator::lockAsTextureProxy(GrContext* ctx,
return nullptr;
}
- sk_sp<GrTexture> tex(GrImageTextureMaker(ctx, this, client, chint).refTextureForParams(
- params,
+ return GrImageTextureMaker(ctx, this, client, chint).refTextureProxyForParams(params,
dstColorSpace,
texColorSpace,
- scaleAdjust));
- return GrSurfaceProxy::MakeWrapped(std::move(tex));
+ scaleAdjust);
}
#endif
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index 1e283457fc..df8cb080a4 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -481,14 +481,14 @@ public:
// original texture but rather was handed the original texture. It adds additional checks
// relevant to original textures that were created external to Skia via
// GrResourceProvider::wrap methods.
- bool isACopyNeededForTextureParams(GrTexture* texture, const GrSamplerParams& params,
+ bool isACopyNeededForTextureParams(GrTextureProxy* proxy, const GrSamplerParams& params,
GrTextureProducer::CopyParams* copyParams,
SkScalar scaleAdjust[2]) const {
- if (this->isACopyNeededForTextureParams(texture->width(), texture->height(), params,
+ if (this->isACopyNeededForTextureParams(proxy->width(), proxy->height(), params,
copyParams, scaleAdjust)) {
return true;
}
- return this->onIsACopyNeededForTextureParams(texture, params, copyParams, scaleAdjust);
+ return this->onIsACopyNeededForTextureParams(proxy, params, copyParams, scaleAdjust);
}
// This is only to be used in GL-specific tests.
@@ -550,7 +550,7 @@ private:
virtual gr_instanced::InstancedRendering* onCreateInstancedRendering() = 0;
- virtual bool onIsACopyNeededForTextureParams(GrTexture* texture, const GrSamplerParams&,
+ virtual bool onIsACopyNeededForTextureParams(GrTextureProxy* proxy, const GrSamplerParams&,
GrTextureProducer::CopyParams*,
SkScalar scaleAdjust[2]) const {
return false;
diff --git a/src/gpu/GrPaint.cpp b/src/gpu/GrPaint.cpp
index fc35d69c15..5dc998eb27 100644
--- a/src/gpu/GrPaint.cpp
+++ b/src/gpu/GrPaint.cpp
@@ -20,34 +20,6 @@ void GrPaint::setCoverageSetOpXPFactory(SkRegion::Op regionOp, bool invertCovera
fXPFactory = GrCoverageSetOpXPFactory::Get(regionOp, invertCoverage);
}
-void GrPaint::addColorTextureProcessor(GrTexture* texture,
- sk_sp<GrColorSpaceXform> colorSpaceXform,
- const SkMatrix& matrix) {
- this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(texture,
- std::move(colorSpaceXform),
- matrix));
-}
-
-void GrPaint::addCoverageTextureProcessor(GrTexture* texture, const SkMatrix& matrix) {
- this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(texture, nullptr, matrix));
-}
-
-void GrPaint::addColorTextureProcessor(GrTexture* texture,
- sk_sp<GrColorSpaceXform> colorSpaceXform,
- const SkMatrix& matrix,
- const GrSamplerParams& params) {
- this->addColorFragmentProcessor(GrSimpleTextureEffect::Make(texture,
- std::move(colorSpaceXform),
- matrix, params));
-}
-
-void GrPaint::addCoverageTextureProcessor(GrTexture* texture,
- const SkMatrix& matrix,
- const GrSamplerParams& params) {
- this->addCoverageFragmentProcessor(GrSimpleTextureEffect::Make(texture, nullptr, matrix,
- params));
-}
-
void GrPaint::addColorTextureProcessor(GrResourceProvider* resourceProvider,
sk_sp<GrTextureProxy> proxy,
sk_sp<GrColorSpaceXform> colorSpaceXform,
diff --git a/src/gpu/GrPaint.h b/src/gpu/GrPaint.h
index 7f53d4a03b..bcf6858df8 100644
--- a/src/gpu/GrPaint.h
+++ b/src/gpu/GrPaint.h
@@ -111,13 +111,6 @@ public:
* Helpers for adding color or coverage effects that sample a texture. The matrix is applied
* to the src space position to compute texture coordinates.
*/
- void addColorTextureProcessor(GrTexture*, sk_sp<GrColorSpaceXform>, const SkMatrix&);
- void addCoverageTextureProcessor(GrTexture*, const SkMatrix&);
- void addColorTextureProcessor(GrTexture*, sk_sp<GrColorSpaceXform>, const SkMatrix&,
- const GrSamplerParams&);
- void addCoverageTextureProcessor(GrTexture*, const SkMatrix&, const GrSamplerParams&);
-
-
void addColorTextureProcessor(GrResourceProvider*, sk_sp<GrTextureProxy>,
sk_sp<GrColorSpaceXform>, const SkMatrix&);
void addColorTextureProcessor(GrResourceProvider*, sk_sp<GrTextureProxy>,
diff --git a/src/gpu/GrResourceProvider.h b/src/gpu/GrResourceProvider.h
index 0cf02677bd..6b3633c9a4 100644
--- a/src/gpu/GrResourceProvider.h
+++ b/src/gpu/GrResourceProvider.h
@@ -72,16 +72,9 @@ public:
/** Assigns a unique key to the texture. The texture will be findable via this key using
findTextureByUniqueKey(). If an existing texture has this key, it's key will be removed. */
- void assignUniqueKeyToTexture(const GrUniqueKey& key, GrTexture* texture) {
- SkASSERT(key.isValid());
- this->assignUniqueKeyToResource(key, texture);
- }
-
- /** Finds a texture by unique key. If the texture is found it is ref'ed and returned. */
- GrTexture* findAndRefTextureByUniqueKey(const GrUniqueKey& key);
-
void assignUniqueKeyToProxy(const GrUniqueKey& key, GrTextureProxy*);
+ /** Finds a texture by unique key. If the texture is found it is ref'ed and returned. */
sk_sp<GrTextureProxy> findProxyByUniqueKey(const GrUniqueKey& key);
/**
@@ -258,6 +251,12 @@ public:
private:
GrTexture* internalCreateApproxTexture(const GrSurfaceDesc& desc, uint32_t scratchTextureFlags);
+ GrTexture* findAndRefTextureByUniqueKey(const GrUniqueKey& key);
+ void assignUniqueKeyToTexture(const GrUniqueKey& key, GrTexture* texture) {
+ SkASSERT(key.isValid());
+ this->assignUniqueKeyToResource(key, texture);
+ }
+
GrTexture* refScratchTexture(const GrSurfaceDesc&, uint32_t scratchTextureFlags);
GrResourceCache* cache() { return fCache; }
diff --git a/src/gpu/GrSurfaceProxyPriv.h b/src/gpu/GrSurfaceProxyPriv.h
index cf2ce8b9db..64f1dc5f40 100644
--- a/src/gpu/GrSurfaceProxyPriv.h
+++ b/src/gpu/GrSurfaceProxyPriv.h
@@ -15,6 +15,12 @@
data members or virtual methods. */
class GrSurfaceProxyPriv {
public:
+ // If the proxy is already instantiated, return its backing GrTexture; if not,
+ // return null
+ const GrTexture* peekTexture() const {
+ return fProxy->fTarget ? fProxy->fTarget->asTexture() : nullptr;
+ }
+
// Beware! This call is only guaranteed to tell you if the proxy in question has
// any pending IO in its current state. It won't tell you about the IO state in the
// future when the proxy is actually used/instantiated.
diff --git a/src/gpu/GrTextureAdjuster.cpp b/src/gpu/GrTextureAdjuster.cpp
index 5dc71489ce..bb4d92aa54 100644
--- a/src/gpu/GrTextureAdjuster.cpp
+++ b/src/gpu/GrTextureAdjuster.cpp
@@ -14,20 +14,20 @@
#include "GrTexture.h"
#include "SkGr.h"
-GrTextureAdjuster::GrTextureAdjuster(GrContext* context, GrTexture* original,
+GrTextureAdjuster::GrTextureAdjuster(GrContext* context, sk_sp<GrTextureProxy> original,
SkAlphaType alphaType,
const SkIRect& contentArea, uint32_t uniqueID,
SkColorSpace* cs)
: INHERITED(contentArea.width(), contentArea.height(),
GrPixelConfigIsAlphaOnly(original->config()))
, fContext(context)
- , fOriginal(original)
+ , fOriginal(std::move(original))
, fAlphaType(alphaType)
, fColorSpace(cs)
, fUniqueID(uniqueID) {
- SkASSERT(SkIRect::MakeWH(original->width(), original->height()).contains(contentArea));
+ SkASSERT(SkIRect::MakeWH(fOriginal->width(), fOriginal->height()).contains(contentArea));
if (contentArea.fLeft > 0 || contentArea.fTop > 0 ||
- contentArea.fRight < original->width() || contentArea.fBottom < original->height()) {
+ contentArea.fRight < fOriginal->width() || contentArea.fBottom < fOriginal->height()) {
fContentArea.set(contentArea);
}
}
@@ -44,31 +44,6 @@ void GrTextureAdjuster::didCacheCopy(const GrUniqueKey& copyKey) {
// We don't currently have a mechanism for notifications on Images!
}
-sk_sp<GrTextureProxy> GrTextureAdjuster::originalProxyRef() {
- return GrSurfaceProxy::MakeWrapped(sk_ref_sp(fOriginal));
-}
-
-GrTexture* GrTextureAdjuster::refCopy(const CopyParams& copyParams) {
- GrTexture* texture = this->originalTexture();
- const SkIRect* contentArea = this->contentAreaOrNull();
- GrUniqueKey key;
- this->makeCopyKey(copyParams, &key, nullptr);
- if (key.isValid()) {
- GrTexture* cachedCopy = fContext->resourceProvider()->findAndRefTextureByUniqueKey(key);
- if (cachedCopy) {
- return cachedCopy;
- }
- }
- GrTexture* copy = CopyOnGpu(texture, contentArea, copyParams);
- if (copy) {
- if (key.isValid()) {
- fContext->resourceProvider()->assignUniqueKeyToTexture(key, copy);
- this->didCacheCopy(key);
- }
- }
- return copy;
-}
-
sk_sp<GrTextureProxy> GrTextureAdjuster::refTextureProxyCopy(const CopyParams& copyParams) {
GrUniqueKey key;
this->makeCopyKey(copyParams, &key, nullptr);
@@ -92,10 +67,11 @@ sk_sp<GrTextureProxy> GrTextureAdjuster::refTextureProxyCopy(const CopyParams& c
return copy;
}
-GrTexture* GrTextureAdjuster::refTextureSafeForParams(const GrSamplerParams& params,
- SkIPoint* outOffset,
- SkScalar scaleAdjust[2]) {
- GrTexture* texture = this->originalTexture();
+sk_sp<GrTextureProxy> GrTextureAdjuster::refTextureProxySafeForParams(
+ const GrSamplerParams& params,
+ SkIPoint* outOffset,
+ SkScalar scaleAdjust[2]) {
+ sk_sp<GrTextureProxy> proxy = this->originalProxyRef();
CopyParams copyParams;
const SkIRect* contentArea = this->contentAreaOrNull();
@@ -110,7 +86,7 @@ GrTexture* GrTextureAdjuster::refTextureSafeForParams(const GrSamplerParams& par
copyParams.fWidth = contentArea->width();
copyParams.fHeight = contentArea->height();
copyParams.fFilter = GrSamplerParams::kBilerp_FilterMode;
- } else if (!fContext->getGpu()->isACopyNeededForTextureParams(texture, params, &copyParams,
+ } else if (!fContext->getGpu()->isACopyNeededForTextureParams(proxy.get(), params, &copyParams,
scaleAdjust)) {
if (outOffset) {
if (contentArea) {
@@ -119,10 +95,10 @@ GrTexture* GrTextureAdjuster::refTextureSafeForParams(const GrSamplerParams& par
outOffset->set(0, 0);
}
}
- return SkRef(texture);
+ return proxy;
}
- GrTexture* copy = this->refCopy(copyParams);
+ sk_sp<GrTextureProxy> copy = this->refTextureProxyCopy(copyParams);
if (copy && outOffset) {
outOffset->set(0, 0);
}
@@ -155,20 +131,20 @@ sk_sp<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor(
params.setFilterMode(*filterOrNullForBicubic);
}
SkScalar scaleAdjust[2] = { 1.0f, 1.0f };
- sk_sp<GrTexture> texture(this->refTextureSafeForParams(params, nullptr, scaleAdjust));
- if (!texture) {
+ sk_sp<GrTextureProxy> proxy(this->refTextureProxySafeForParams(params, nullptr, scaleAdjust));
+ if (!proxy) {
return nullptr;
}
// If we made a copy then we only copied the contentArea, in which case the new texture is all
// content.
- if (texture.get() != this->originalTexture()) {
+ if (proxy.get() != this->originalProxy()) {
contentArea = nullptr;
textureMatrix.postScale(scaleAdjust[0], scaleAdjust[1]);
}
DomainMode domainMode =
DetermineDomainMode(*constraintRect, filterConstraint, coordsLimitedToConstraintRect,
- texture->width(), texture->height(),
+ proxy.get(),
contentArea, filterOrNullForBicubic,
&domain);
if (kTightCopy_DomainMode == domainMode) {
@@ -182,7 +158,7 @@ sk_sp<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor(
static const GrSamplerParams::FilterMode kBilerp = GrSamplerParams::kBilerp_FilterMode;
domainMode =
DetermineDomainMode(*constraintRect, filterConstraint, coordsLimitedToConstraintRect,
- texture->width(), texture->height(),
+ proxy.get(),
contentArea, &kBilerp, &domain);
SkASSERT(kTightCopy_DomainMode != domainMode);
}
@@ -190,7 +166,8 @@ sk_sp<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor(
(domain.fLeft <= domain.fRight && domain.fTop <= domain.fBottom));
sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(fColorSpace,
dstColorSpace);
- return CreateFragmentProcessorForDomainAndFilter(texture.get(), std::move(colorSpaceXform),
+ return CreateFragmentProcessorForDomainAndFilter(fContext->resourceProvider(), std::move(proxy),
+ std::move(colorSpaceXform),
textureMatrix, domainMode, domain,
filterOrNullForBicubic);
}
diff --git a/src/gpu/GrTextureAdjuster.h b/src/gpu/GrTextureAdjuster.h
index 09e639dd78..392af44439 100644
--- a/src/gpu/GrTextureAdjuster.h
+++ b/src/gpu/GrTextureAdjuster.h
@@ -23,8 +23,8 @@ public:
outOffset will be the top-left corner of the subset if a copy is not made. Otherwise,
the copy will be tight to the contents and outOffset will be (0, 0). If the copy's size
does not match subset's dimensions then the contents are scaled to fit the copy.*/
- GrTexture* refTextureSafeForParams(const GrSamplerParams&, SkIPoint* outOffset,
- SkScalar scaleAdjust[2]);
+ sk_sp<GrTextureProxy> refTextureProxySafeForParams(const GrSamplerParams&, SkIPoint* outOffset,
+ SkScalar scaleAdjust[2]);
sk_sp<GrFragmentProcessor> createFragmentProcessor(
const SkMatrix& textureMatrix,
@@ -36,7 +36,7 @@ public:
// We do not ref the texture nor the colorspace, so the caller must keep them in scope while
// this Adjuster is alive.
- GrTextureAdjuster(GrContext*, GrTexture*, SkAlphaType, const SkIRect& area,
+ GrTextureAdjuster(GrContext*, sk_sp<GrTextureProxy>, SkAlphaType, const SkIRect& area,
uint32_t uniqueID, SkColorSpace*);
protected:
@@ -45,21 +45,20 @@ protected:
SkColorSpace* dstColorSpace) override;
void didCacheCopy(const GrUniqueKey& copyKey) override;
- GrTexture* originalTexture() const { return fOriginal; }
- sk_sp<GrTextureProxy> originalProxyRef();
+ GrTextureProxy* originalProxy() const { return fOriginal.get(); }
+ sk_sp<GrTextureProxy> originalProxyRef() const { return fOriginal; }
/** Returns the content area or null for the whole original texture */
const SkIRect* contentAreaOrNull() { return fContentArea.getMaybeNull(); }
private:
- SkTLazy<SkIRect> fContentArea;
- GrContext* fContext;
- GrTexture* fOriginal;
- SkAlphaType fAlphaType;
- SkColorSpace* fColorSpace;
- uint32_t fUniqueID;
+ SkTLazy<SkIRect> fContentArea;
+ GrContext* fContext;
+ sk_sp<GrTextureProxy> fOriginal;
+ SkAlphaType fAlphaType;
+ SkColorSpace* fColorSpace;
+ uint32_t fUniqueID;
- GrTexture* refCopy(const CopyParams &copyParams);
sk_sp<GrTextureProxy> refTextureProxyCopy(const CopyParams &copyParams);
typedef GrTextureProducer INHERITED;
diff --git a/src/gpu/GrTextureMaker.cpp b/src/gpu/GrTextureMaker.cpp
index ee4641b5e7..4fb0c0db41 100644
--- a/src/gpu/GrTextureMaker.cpp
+++ b/src/gpu/GrTextureMaker.cpp
@@ -11,10 +11,10 @@
#include "GrGpu.h"
#include "GrResourceProvider.h"
-GrTexture* GrTextureMaker::refTextureForParams(const GrSamplerParams& params,
- SkColorSpace* dstColorSpace,
- sk_sp<SkColorSpace>* texColorSpace,
- SkScalar scaleAdjust[2]) {
+sk_sp<GrTextureProxy> GrTextureMaker::refTextureProxyForParams(const GrSamplerParams& params,
+ SkColorSpace* dstColorSpace,
+ sk_sp<SkColorSpace>* texColorSpace,
+ SkScalar scaleAdjust[2]) {
CopyParams copyParams;
bool willBeMipped = params.filterMode() == GrSamplerParams::kMipMap_FilterMode;
@@ -28,30 +28,25 @@ GrTexture* GrTextureMaker::refTextureForParams(const GrSamplerParams& params,
if (!fContext->getGpu()->isACopyNeededForTextureParams(this->width(), this->height(), params,
&copyParams, scaleAdjust)) {
- sk_sp<GrTextureProxy>proxy = this->refOriginalTextureProxy(willBeMipped, dstColorSpace);
- if (!proxy) {
- return nullptr;
- }
-
- sk_sp<GrTexture> tex(SkSafeRef(proxy->instantiate(fContext->resourceProvider())));
- return tex.release();
+ return this->refOriginalTextureProxy(willBeMipped, dstColorSpace);
}
GrUniqueKey copyKey;
this->makeCopyKey(copyParams, &copyKey, dstColorSpace);
if (copyKey.isValid()) {
- GrTexture* result = fContext->resourceProvider()->findAndRefTextureByUniqueKey(copyKey);
+ sk_sp<GrTextureProxy> result(fContext->resourceProvider()->findProxyByUniqueKey(copyKey));
if (result) {
return result;
}
}
- GrTexture* result = this->generateTextureForParams(copyParams, willBeMipped, dstColorSpace);
+ sk_sp<GrTextureProxy> result(this->generateTextureProxyForParams(copyParams, willBeMipped,
+ dstColorSpace));
if (!result) {
return nullptr;
}
if (copyKey.isValid()) {
- fContext->resourceProvider()->assignUniqueKeyToTexture(copyKey, result);
+ fContext->resourceProvider()->assignUniqueKeyToProxy(copyKey, result.get());
this->didCacheCopy(copyKey);
}
return result;
@@ -86,9 +81,10 @@ sk_sp<GrFragmentProcessor> GrTextureMaker::createFragmentProcessor(
}
sk_sp<SkColorSpace> texColorSpace;
SkScalar scaleAdjust[2] = { 1.0f, 1.0f };
- sk_sp<GrTexture> texture(this->refTextureForParams(params, dstColorSpace, &texColorSpace,
- scaleAdjust));
- if (!texture) {
+ sk_sp<GrTextureProxy> proxy(this->refTextureProxyForParams(params, dstColorSpace,
+ &texColorSpace,
+ scaleAdjust));
+ if (!proxy) {
return nullptr;
}
SkMatrix adjustedMatrix = textureMatrix;
@@ -96,28 +92,24 @@ sk_sp<GrFragmentProcessor> GrTextureMaker::createFragmentProcessor(
SkRect domain;
DomainMode domainMode =
DetermineDomainMode(constraintRect, filterConstraint, coordsLimitedToConstraintRect,
- texture->width(), texture->height(),
+ proxy.get(),
nullptr, fmForDetermineDomain, &domain);
SkASSERT(kTightCopy_DomainMode != domainMode);
sk_sp<GrColorSpaceXform> colorSpaceXform = GrColorSpaceXform::Make(texColorSpace.get(),
dstColorSpace);
- return CreateFragmentProcessorForDomainAndFilter(texture.get(), std::move(colorSpaceXform),
+ return CreateFragmentProcessorForDomainAndFilter(fContext->resourceProvider(), std::move(proxy),
+ std::move(colorSpaceXform),
adjustedMatrix, domainMode, domain,
filterOrNullForBicubic);
}
-GrTexture* GrTextureMaker::generateTextureForParams(const CopyParams& copyParams, bool willBeMipped,
- SkColorSpace* dstColorSpace) {
+sk_sp<GrTextureProxy> GrTextureMaker::generateTextureProxyForParams(const CopyParams& copyParams,
+ bool willBeMipped,
+ SkColorSpace* dstColorSpace) {
sk_sp<GrTextureProxy> original(this->refOriginalTextureProxy(willBeMipped, dstColorSpace));
if (!original) {
return nullptr;
}
- sk_sp<GrTextureProxy> copy = CopyOnGpu(fContext, std::move(original), nullptr, copyParams);
- if (!copy) {
- return nullptr;
- }
-
- sk_sp<GrTexture> tex(SkSafeRef(copy->instantiate(fContext->resourceProvider())));
- return tex.release();
+ return CopyOnGpu(fContext, std::move(original), nullptr, copyParams);
}
diff --git a/src/gpu/GrTextureMaker.h b/src/gpu/GrTextureMaker.h
index 7c0621beb2..909d3480bf 100644
--- a/src/gpu/GrTextureMaker.h
+++ b/src/gpu/GrTextureMaker.h
@@ -23,8 +23,10 @@ public:
* in order to correct the absolute texture coordinates.
* Places the color space of the texture in (*texColorSpace).
*/
- GrTexture* refTextureForParams(const GrSamplerParams&, SkColorSpace* dstColorSpace,
- sk_sp<SkColorSpace>* texColorSpace, SkScalar scaleAdjust[2]);
+ sk_sp<GrTextureProxy> refTextureProxyForParams(const GrSamplerParams&,
+ SkColorSpace* dstColorSpace,
+ sk_sp<SkColorSpace>* texColorSpace,
+ SkScalar scaleAdjust[2]);
sk_sp<GrFragmentProcessor> createFragmentProcessor(
const SkMatrix& textureMatrix,
@@ -62,8 +64,9 @@ protected:
* Subclass may override this if they can handle creating the texture more directly than
* by copying.
*/
- virtual GrTexture* generateTextureForParams(const CopyParams&, bool willBeMipped,
- SkColorSpace* dstColorSpace);
+ virtual sk_sp<GrTextureProxy> generateTextureProxyForParams(const CopyParams&,
+ bool willBeMipped,
+ SkColorSpace* dstColorSpace);
GrContext* context() const { return fContext; }
diff --git a/src/gpu/GrTextureProducer.cpp b/src/gpu/GrTextureProducer.cpp
index a8390ee9bc..d226c3feb6 100644
--- a/src/gpu/GrTextureProducer.cpp
+++ b/src/gpu/GrTextureProducer.cpp
@@ -16,56 +16,6 @@
#include "effects/GrSimpleTextureEffect.h"
#include "effects/GrTextureDomain.h"
-GrTexture* GrTextureProducer::CopyOnGpu(GrTexture* inputTexture, const SkIRect* subset,
- const CopyParams& copyParams) {
- SkASSERT(!subset || !subset->isEmpty());
- GrContext* context = inputTexture->getContext();
- SkASSERT(context);
-
- GrPixelConfig config = GrMakePixelConfigUncompressed(inputTexture->config());
-
- sk_sp<GrRenderTargetContext> copyRTC = context->makeRenderTargetContextWithFallback(
- SkBackingFit::kExact, copyParams.fWidth, copyParams.fHeight, config, nullptr);
- if (!copyRTC) {
- return nullptr;
- }
-
- GrPaint paint;
- paint.setGammaCorrect(true);
-
- if (copyParams.fFilter != GrSamplerParams::kNone_FilterMode && subset &&
- (subset->width() != copyParams.fWidth || subset->height() != copyParams.fHeight)) {
- SkRect domain;
- domain.fLeft = subset->fLeft + 0.5f;
- domain.fTop = subset->fTop + 0.5f;
- domain.fRight = subset->fRight - 0.5f;
- domain.fBottom = subset->fBottom - 0.5f;
- // This would cause us to read values from outside the subset. Surely, the caller knows
- // better!
- SkASSERT(copyParams.fFilter != GrSamplerParams::kMipMap_FilterMode);
- paint.addColorFragmentProcessor(
- GrTextureDomainEffect::Make(inputTexture, nullptr, SkMatrix::I(), domain,
- GrTextureDomain::kClamp_Mode,
- copyParams.fFilter));
- } else {
- GrSamplerParams params(SkShader::kClamp_TileMode, copyParams.fFilter);
- paint.addColorTextureProcessor(inputTexture, nullptr, SkMatrix::I(), params);
- }
- paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
-
- SkRect localRect;
- if (subset) {
- localRect = SkRect::Make(*subset);
- } else {
- localRect = SkRect::MakeWH(inputTexture->width(), inputTexture->height());
- }
-
- SkRect dstRect = SkRect::MakeIWH(copyParams.fWidth, copyParams.fHeight);
- copyRTC->fillRectToRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(), dstRect,
- localRect);
- return copyRTC->asTexture().release();
-}
-
sk_sp<GrTextureProxy> GrTextureProducer::CopyOnGpu(GrContext* context,
sk_sp<GrTextureProxy> inputProxy,
const SkIRect* subset,
@@ -128,145 +78,17 @@ sk_sp<GrTextureProxy> GrTextureProducer::CopyOnGpu(GrContext* context,
/** Determines whether a texture domain is necessary and if so what domain to use. There are two
* rectangles to consider:
- * - The first is the content area specified by the texture adjuster. We can *never* allow
- * filtering to cause bleed of pixels outside this rectangle.
- * - The second rectangle is the constraint rectangle, which is known to be contained by the
- * content area. The filterConstraint specifies whether we are allowed to bleed across this
- * rect.
+ * - The first is the content area specified by the texture adjuster (i.e., textureContentArea).
+ * We can *never* allow filtering to cause bleed of pixels outside this rectangle.
+ * - The second rectangle is the constraint rectangle (i.e., constraintRect), which is known to
+ * be contained by the content area. The filterConstraint specifies whether we are allowed to
+ * bleed across this rect.
*
* We want to avoid using a domain if possible. We consider the above rectangles, the filter type,
* and whether the coords generated by the draw would all fall within the constraint rect. If the
* latter is true we only need to consider whether the filter would extend beyond the rects.
*/
GrTextureProducer::DomainMode GrTextureProducer::DetermineDomainMode(
- const SkRect& constraintRect,
- FilterConstraint filterConstraint,
- bool coordsLimitedToConstraintRect,
- int texW, int texH,
- const SkIRect* textureContentArea,
- const GrSamplerParams::FilterMode* filterModeOrNullForBicubic,
- SkRect* domainRect) {
-
- SkASSERT(SkRect::MakeIWH(texW, texH).contains(constraintRect));
- // We only expect a content area rect if there is some non-content area.
- SkASSERT(!textureContentArea ||
- (!textureContentArea->contains(SkIRect::MakeWH(texW, texH)) &&
- SkRect::Make(*textureContentArea).contains(constraintRect)));
-
- SkRect textureBounds = SkRect::MakeIWH(texW, texH);
- // If the src rectangle contains the whole texture then no need for a domain.
- if (constraintRect.contains(textureBounds)) {
- return kNoDomain_DomainMode;
- }
-
- bool restrictFilterToRect = (filterConstraint == GrTextureProducer::kYes_FilterConstraint);
-
- // If we can filter outside the constraint rect, and there is no non-content area of the
- // texture, and we aren't going to generate sample coords outside the constraint rect then we
- // don't need a domain.
- if (!restrictFilterToRect && !textureContentArea && coordsLimitedToConstraintRect) {
- return kNoDomain_DomainMode;
- }
-
- // Get the domain inset based on sampling mode (or bail if mipped)
- SkScalar filterHalfWidth = 0.f;
- if (filterModeOrNullForBicubic) {
- switch (*filterModeOrNullForBicubic) {
- case GrSamplerParams::kNone_FilterMode:
- if (coordsLimitedToConstraintRect) {
- return kNoDomain_DomainMode;
- } else {
- filterHalfWidth = 0.f;
- }
- break;
- case GrSamplerParams::kBilerp_FilterMode:
- filterHalfWidth = .5f;
- break;
- case GrSamplerParams::kMipMap_FilterMode:
- if (restrictFilterToRect || textureContentArea) {
- // No domain can save us here.
- return kTightCopy_DomainMode;
- }
- return kNoDomain_DomainMode;
- }
- } else {
- // bicubic does nearest filtering internally.
- filterHalfWidth = 1.5f;
- }
-
- // Both bilerp and bicubic use bilinear filtering and so need to be clamped to the center
- // of the edge texel. Pinning to the texel center has no impact on nearest mode and MIP-maps
-
- static const SkScalar kDomainInset = 0.5f;
- // Figure out the limits of pixels we're allowed to sample from.
- // Unless we know the amount of outset and the texture matrix we have to conservatively enforce
- // the domain.
- if (restrictFilterToRect) {
- *domainRect = constraintRect.makeInset(kDomainInset, kDomainInset);
- } else if (textureContentArea) {
- // If we got here then: there is a textureContentArea, the coords are limited to the
- // constraint rect, and we're allowed to filter across the constraint rect boundary. So
- // we check whether the filter would reach across the edge of the content area.
- // We will only set the sides that are required.
-
- domainRect->setLargest();
- if (coordsLimitedToConstraintRect) {
- // We may be able to use the fact that the texture coords are limited to the constraint
- // rect in order to avoid having to add a domain.
- bool needContentAreaConstraint = false;
- if (textureContentArea->fLeft > 0 &&
- textureContentArea->fLeft + filterHalfWidth > constraintRect.fLeft) {
- domainRect->fLeft = textureContentArea->fLeft + kDomainInset;
- needContentAreaConstraint = true;
- }
- if (textureContentArea->fTop > 0 &&
- textureContentArea->fTop + filterHalfWidth > constraintRect.fTop) {
- domainRect->fTop = textureContentArea->fTop + kDomainInset;
- needContentAreaConstraint = true;
- }
- if (textureContentArea->fRight < texW &&
- textureContentArea->fRight - filterHalfWidth < constraintRect.fRight) {
- domainRect->fRight = textureContentArea->fRight - kDomainInset;
- needContentAreaConstraint = true;
- }
- if (textureContentArea->fBottom < texH &&
- textureContentArea->fBottom - filterHalfWidth < constraintRect.fBottom) {
- domainRect->fBottom = textureContentArea->fBottom - kDomainInset;
- needContentAreaConstraint = true;
- }
- if (!needContentAreaConstraint) {
- return kNoDomain_DomainMode;
- }
- } else {
- // Our sample coords for the texture are allowed to be outside the constraintRect so we
- // don't consider it when computing the domain.
- if (textureContentArea->fLeft != 0) {
- domainRect->fLeft = textureContentArea->fLeft + kDomainInset;
- }
- if (textureContentArea->fTop != 0) {
- domainRect->fTop = textureContentArea->fTop + kDomainInset;
- }
- if (textureContentArea->fRight != texW) {
- domainRect->fRight = textureContentArea->fRight - kDomainInset;
- }
- if (textureContentArea->fBottom != texH) {
- domainRect->fBottom = textureContentArea->fBottom - kDomainInset;
- }
- }
- } else {
- return kNoDomain_DomainMode;
- }
-
- if (domainRect->fLeft > domainRect->fRight) {
- domainRect->fLeft = domainRect->fRight = SkScalarAve(domainRect->fLeft, domainRect->fRight);
- }
- if (domainRect->fTop > domainRect->fBottom) {
- domainRect->fTop = domainRect->fBottom = SkScalarAve(domainRect->fTop, domainRect->fBottom);
- }
- return kDomain_DomainMode;
-}
-
-GrTextureProducer::DomainMode GrTextureProducer::DetermineDomainMode(
const SkRect& constraintRect,
FilterConstraint filterConstraint,
bool coordsLimitedToConstraintRect,
@@ -402,37 +224,6 @@ GrTextureProducer::DomainMode GrTextureProducer::DetermineDomainMode(
}
sk_sp<GrFragmentProcessor> GrTextureProducer::CreateFragmentProcessorForDomainAndFilter(
- GrTexture* texture,
- sk_sp<GrColorSpaceXform> colorSpaceXform,
- const SkMatrix& textureMatrix,
- DomainMode domainMode,
- const SkRect& domain,
- const GrSamplerParams::FilterMode* filterOrNullForBicubic) {
- SkASSERT(kTightCopy_DomainMode != domainMode);
- if (filterOrNullForBicubic) {
- if (kDomain_DomainMode == domainMode) {
- return GrTextureDomainEffect::Make(texture, std::move(colorSpaceXform), textureMatrix,
- domain, GrTextureDomain::kClamp_Mode,
- *filterOrNullForBicubic);
- } else {
- GrSamplerParams params(SkShader::kClamp_TileMode, *filterOrNullForBicubic);
- return GrSimpleTextureEffect::Make(texture, std::move(colorSpaceXform), textureMatrix,
- params);
- }
- } else {
- if (kDomain_DomainMode == domainMode) {
- return GrBicubicEffect::Make(texture, std::move(colorSpaceXform), textureMatrix,
- domain);
- } else {
- static const SkShader::TileMode kClampClamp[] =
- { SkShader::kClamp_TileMode, SkShader::kClamp_TileMode };
- return GrBicubicEffect::Make(texture, std::move(colorSpaceXform), textureMatrix,
- kClampClamp);
- }
- }
-}
-
-sk_sp<GrFragmentProcessor> GrTextureProducer::CreateFragmentProcessorForDomainAndFilter(
GrResourceProvider* resourceProvider,
sk_sp<GrTextureProxy> proxy,
sk_sp<GrColorSpaceXform> colorSpaceXform,
diff --git a/src/gpu/GrTextureProducer.h b/src/gpu/GrTextureProducer.h
index e9d1665461..35e60f0552 100644
--- a/src/gpu/GrTextureProducer.h
+++ b/src/gpu/GrTextureProducer.h
@@ -119,9 +119,6 @@ protected:
kTightCopy_DomainMode
};
- static GrTexture* CopyOnGpu(GrTexture* inputTexture, const SkIRect* subset,
- const CopyParams& copyParams);
-
static sk_sp<GrTextureProxy> CopyOnGpu(GrContext*, sk_sp<GrTextureProxy> inputProxy,
const SkIRect* subset, const CopyParams& copyParams);
@@ -129,29 +126,12 @@ protected:
const SkRect& constraintRect,
FilterConstraint filterConstraint,
bool coordsLimitedToConstraintRect,
- int texW, int texH,
- const SkIRect* textureContentArea,
- const GrSamplerParams::FilterMode* filterModeOrNullForBicubic,
- SkRect* domainRect);
-
- static DomainMode DetermineDomainMode(
- const SkRect& constraintRect,
- FilterConstraint filterConstraint,
- bool coordsLimitedToConstraintRect,
GrTextureProxy*,
const SkIRect* textureContentArea,
const GrSamplerParams::FilterMode* filterModeOrNullForBicubic,
SkRect* domainRect);
static sk_sp<GrFragmentProcessor> CreateFragmentProcessorForDomainAndFilter(
- GrTexture* texture,
- sk_sp<GrColorSpaceXform> colorSpaceXform,
- const SkMatrix& textureMatrix,
- DomainMode domainMode,
- const SkRect& domain,
- const GrSamplerParams::FilterMode* filterOrNullForBicubic);
-
- static sk_sp<GrFragmentProcessor> CreateFragmentProcessorForDomainAndFilter(
GrResourceProvider*,
sk_sp<GrTextureProxy> proxy,
sk_sp<GrColorSpaceXform>,
diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp
index 11134095ca..4e16d5965f 100644
--- a/src/gpu/SkGpuDevice.cpp
+++ b/src/gpu/SkGpuDevice.cpp
@@ -1370,11 +1370,12 @@ void SkGpuDevice::drawImage(const SkImage* image, SkScalar x, SkScalar y,
SkMatrix viewMatrix = this->ctm();
viewMatrix.preTranslate(x, y);
uint32_t pinnedUniqueID;
- if (sk_sp<GrTexture> tex = as_IB(image)->refPinnedTexture(&pinnedUniqueID)) {
+
+ if (sk_sp<GrTextureProxy> proxy = as_IB(image)->refPinnedTextureProxy(&pinnedUniqueID)) {
CHECK_SHOULD_DRAW();
- GrTextureAdjuster adjuster(this->context(), tex.get(), image->alphaType(),
- image->bounds(), pinnedUniqueID,
- as_IB(image)->onImageInfo().colorSpace());
+ GrTextureAdjuster adjuster(this->context(), std::move(proxy),
+ image->alphaType(), image->bounds(),
+ pinnedUniqueID, as_IB(image)->onImageInfo().colorSpace());
this->drawTextureProducer(&adjuster, nullptr, nullptr, SkCanvas::kFast_SrcRectConstraint,
viewMatrix, this->clip(), paint);
return;
@@ -1403,10 +1404,10 @@ void SkGpuDevice::drawImageRect(const SkImage* image, const SkRect* src,
SkCanvas::SrcRectConstraint constraint) {
ASSERT_SINGLE_OWNER
uint32_t pinnedUniqueID;
- if (sk_sp<GrTexture> tex = as_IB(image)->refPinnedTexture(&pinnedUniqueID)) {
+ if (sk_sp<GrTextureProxy> proxy = as_IB(image)->refPinnedTextureProxy(&pinnedUniqueID)) {
CHECK_SHOULD_DRAW();
- GrTextureAdjuster adjuster(this->context(), tex.get(), image->alphaType(),
- image->bounds(), pinnedUniqueID,
+ GrTextureAdjuster adjuster(this->context(), std::move(proxy),
+ image->alphaType(), image->bounds(), pinnedUniqueID,
as_IB(image)->onImageInfo().colorSpace());
this->drawTextureProducer(&adjuster, src, &dst, constraint, this->ctm(), this->clip(),
paint);
@@ -1479,11 +1480,11 @@ void SkGpuDevice::drawImageNine(const SkImage* image,
const SkIRect& center, const SkRect& dst, const SkPaint& paint) {
ASSERT_SINGLE_OWNER
uint32_t pinnedUniqueID;
- if (sk_sp<GrTexture> tex = as_IB(image)->refPinnedTexture(&pinnedUniqueID)) {
+ if (sk_sp<GrTextureProxy> proxy = as_IB(image)->refPinnedTextureProxy(&pinnedUniqueID)) {
CHECK_SHOULD_DRAW();
- GrTextureAdjuster adjuster(this->context(), tex.get(), image->alphaType(),
- image->bounds(), pinnedUniqueID,
- as_IB(image)->onImageInfo().colorSpace());
+ GrTextureAdjuster adjuster(this->context(), std::move(proxy),
+ image->alphaType(), image->bounds(),
+ pinnedUniqueID, as_IB(image)->onImageInfo().colorSpace());
this->drawProducerNine(&adjuster, center, dst, paint);
} else {
SkBitmap bm;
@@ -1535,11 +1536,11 @@ void SkGpuDevice::drawImageLattice(const SkImage* image,
const SkPaint& paint) {
ASSERT_SINGLE_OWNER
uint32_t pinnedUniqueID;
- if (sk_sp<GrTexture> tex = as_IB(image)->refPinnedTexture(&pinnedUniqueID)) {
+ if (sk_sp<GrTextureProxy> proxy = as_IB(image)->refPinnedTextureProxy(&pinnedUniqueID)) {
CHECK_SHOULD_DRAW();
- GrTextureAdjuster adjuster(this->context(), tex.get(), image->alphaType(),
- image->bounds(), pinnedUniqueID,
- as_IB(image)->onImageInfo().colorSpace());
+ GrTextureAdjuster adjuster(this->context(), std::move(proxy),
+ image->alphaType(), image->bounds(),
+ pinnedUniqueID, as_IB(image)->onImageInfo().colorSpace());
this->drawProducerLattice(&adjuster, lattice, dst, paint);
} else {
SkBitmap bm;
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 155199812d..56ce5455a7 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -271,10 +271,8 @@ sk_sp<GrTextureProxy> GrRefCachedBitmapTextureProxy(GrContext* ctx,
const GrSamplerParams& params,
SkScalar scaleAdjust[2]) {
// Caller doesn't care about the texture's color space (they can always get it from the bitmap)
- sk_sp<GrTexture> tex(GrBitmapTextureMaker(ctx, bitmap).refTextureForParams(params, nullptr,
- nullptr,
- scaleAdjust));
- return GrSurfaceProxy::MakeWrapped(std::move(tex));
+ return GrBitmapTextureMaker(ctx, bitmap).refTextureProxyForParams(params, nullptr,
+ nullptr, scaleAdjust);
}
sk_sp<GrTextureProxy> GrMakeCachedBitmapProxy(GrResourceProvider* resourceProvider,
diff --git a/src/gpu/effects/GrBicubicEffect.cpp b/src/gpu/effects/GrBicubicEffect.cpp
index 71816e5d0b..b418096da5 100644
--- a/src/gpu/effects/GrBicubicEffect.cpp
+++ b/src/gpu/effects/GrBicubicEffect.cpp
@@ -131,28 +131,6 @@ void GrGLBicubicEffect::onSetData(const GrGLSLProgramDataManager& pdman,
}
}
-GrBicubicEffect::GrBicubicEffect(GrTexture* texture,
- sk_sp<GrColorSpaceXform> colorSpaceXform,
- const SkMatrix& matrix,
- const SkShader::TileMode tileModes[2])
- : INHERITED(texture, std::move(colorSpaceXform), matrix,
- GrSamplerParams(tileModes, GrSamplerParams::kNone_FilterMode),
- ModulationFlags(texture->config()))
- , fDomain(GrTextureDomain::IgnoredDomain()) {
- this->initClassID<GrBicubicEffect>();
-}
-
-GrBicubicEffect::GrBicubicEffect(GrTexture* texture,
- sk_sp<GrColorSpaceXform> colorSpaceXform,
- const SkMatrix& matrix,
- const SkRect& domain)
- : INHERITED(texture, std::move(colorSpaceXform), matrix,
- GrSamplerParams(SkShader::kClamp_TileMode, GrSamplerParams::kNone_FilterMode),
- ModulationFlags(texture->config()))
- , fDomain(texture, domain, GrTextureDomain::kClamp_Mode) {
- this->initClassID<GrBicubicEffect>();
-}
-
GrBicubicEffect::GrBicubicEffect(GrResourceProvider* resourceProvider, sk_sp<GrTextureProxy> proxy,
sk_sp<GrColorSpaceXform> colorSpaceXform,
const SkMatrix &matrix,
diff --git a/src/gpu/effects/GrBicubicEffect.h b/src/gpu/effects/GrBicubicEffect.h
index e24422f5e8..7cc8c1ef79 100644
--- a/src/gpu/effects/GrBicubicEffect.h
+++ b/src/gpu/effects/GrBicubicEffect.h
@@ -29,28 +29,6 @@ public:
/**
* Create a Mitchell filter effect with specified texture matrix and x/y tile modes.
*/
- static sk_sp<GrFragmentProcessor> Make(GrTexture* tex,
- sk_sp<GrColorSpaceXform> colorSpaceXform,
- const SkMatrix& matrix,
- const SkShader::TileMode tileModes[2]) {
- return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(tex, std::move(colorSpaceXform),
- matrix, tileModes));
- }
-
- /**
- * Create a Mitchell filter effect with a texture matrix and a domain.
- */
- static sk_sp<GrFragmentProcessor> Make(GrTexture* tex,
- sk_sp<GrColorSpaceXform> colorSpaceXform,
- const SkMatrix& matrix,
- const SkRect& domain) {
- return sk_sp<GrFragmentProcessor>(new GrBicubicEffect(tex, std::move(colorSpaceXform),
- matrix, domain));
- }
-
- /**
- * Create a Mitchell filter effect with specified texture matrix and x/y tile modes.
- */
static sk_sp<GrFragmentProcessor> Make(GrResourceProvider* resourceProvider,
sk_sp<GrTextureProxy> proxy,
sk_sp<GrColorSpaceXform> colorSpaceXform,
@@ -85,11 +63,6 @@ public:
GrSamplerParams::FilterMode* filterMode);
private:
- GrBicubicEffect(GrTexture*, sk_sp<GrColorSpaceXform>, const SkMatrix &matrix,
- const SkShader::TileMode tileModes[2]);
- GrBicubicEffect(GrTexture*, sk_sp<GrColorSpaceXform>, const SkMatrix &matrix,
- const SkRect& domain);
-
GrBicubicEffect(GrResourceProvider*, sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>,
const SkMatrix &matrix, const SkShader::TileMode tileModes[2]);
GrBicubicEffect(GrResourceProvider*, sk_sp<GrTextureProxy>, sk_sp<GrColorSpaceXform>,
diff --git a/src/gpu/effects/GrTextureDomain.cpp b/src/gpu/effects/GrTextureDomain.cpp
index d7c74aafc4..91b1e552b9 100644
--- a/src/gpu/effects/GrTextureDomain.cpp
+++ b/src/gpu/effects/GrTextureDomain.cpp
@@ -232,22 +232,6 @@ void GrTextureDomain::GLDomain::setData(const GrGLSLProgramDataManager& pdman,
}
///////////////////////////////////////////////////////////////////////////////
-sk_sp<GrFragmentProcessor> GrTextureDomainEffect::Make(GrTexture* texture,
- sk_sp<GrColorSpaceXform> colorSpaceXform,
- const SkMatrix& matrix,
- const SkRect& domain,
- GrTextureDomain::Mode mode,
- GrSamplerParams::FilterMode filterMode) {
- if (GrTextureDomain::kIgnore_Mode == mode ||
- (GrTextureDomain::kClamp_Mode == mode && can_ignore_rect(texture, domain))) {
- return GrSimpleTextureEffect::Make(texture, std::move(colorSpaceXform), matrix, filterMode);
- } else {
- return sk_sp<GrFragmentProcessor>(
- new GrTextureDomainEffect(texture, std::move(colorSpaceXform), matrix, domain, mode,
- filterMode));
- }
-}
-
inline GrFragmentProcessor::OptimizationFlags GrTextureDomainEffect::OptFlags(
GrPixelConfig config, GrTextureDomain::Mode mode) {
if (mode == GrTextureDomain::kDecal_Mode || !GrPixelConfigIsOpaque(config)) {
@@ -258,20 +242,6 @@ inline GrFragmentProcessor::OptimizationFlags GrTextureDomainEffect::OptFlags(
}
}
-GrTextureDomainEffect::GrTextureDomainEffect(GrTexture* texture,
- sk_sp<GrColorSpaceXform> colorSpaceXform,
- const SkMatrix& matrix,
- const SkRect& domain,
- GrTextureDomain::Mode mode,
- GrSamplerParams::FilterMode filterMode)
- : GrSingleTextureEffect(texture, std::move(colorSpaceXform), matrix, filterMode,
- OptFlags(texture->config(), mode))
- , fTextureDomain(texture, domain, mode) {
- SkASSERT(mode != GrTextureDomain::kRepeat_Mode ||
- filterMode == GrSamplerParams::kNone_FilterMode);
- this->initClassID<GrTextureDomainEffect>();
-}
-
sk_sp<GrFragmentProcessor> GrTextureDomainEffect::Make(GrResourceProvider* resourceProvider,
sk_sp<GrTextureProxy> proxy,
sk_sp<GrColorSpaceXform> colorSpaceXform,
@@ -388,25 +358,6 @@ sk_sp<GrFragmentProcessor> GrTextureDomainEffect::TestCreate(GrProcessorTestData
#endif
///////////////////////////////////////////////////////////////////////////////
-
-sk_sp<GrFragmentProcessor> GrDeviceSpaceTextureDecalFragmentProcessor::Make(GrTexture* texture,
- const SkIRect& subset, const SkIPoint& deviceSpaceOffset) {
- return sk_sp<GrFragmentProcessor>(new GrDeviceSpaceTextureDecalFragmentProcessor(
- texture, subset, deviceSpaceOffset));
-}
-
-GrDeviceSpaceTextureDecalFragmentProcessor::GrDeviceSpaceTextureDecalFragmentProcessor(
- GrTexture* texture, const SkIRect& subset, const SkIPoint& deviceSpaceOffset)
- : INHERITED(kCompatibleWithCoverageAsAlpha_OptimizationFlag)
- , fTextureSampler(texture, GrSamplerParams::ClampNoFilter())
- , fTextureDomain(texture, GrTextureDomain::MakeTexelDomain(subset),
- GrTextureDomain::kDecal_Mode) {
- this->addTextureSampler(&fTextureSampler);
- fDeviceSpaceOffset.fX = deviceSpaceOffset.fX - subset.fLeft;
- fDeviceSpaceOffset.fY = deviceSpaceOffset.fY - subset.fTop;
- this->initClassID<GrDeviceSpaceTextureDecalFragmentProcessor>();
-}
-
sk_sp<GrFragmentProcessor> GrDeviceSpaceTextureDecalFragmentProcessor::Make(
GrResourceProvider* resourceProvider,
sk_sp<GrTextureProxy> proxy,
diff --git a/src/gpu/effects/GrTextureDomain.h b/src/gpu/effects/GrTextureDomain.h
index 11a9819917..d8cd69569b 100644
--- a/src/gpu/effects/GrTextureDomain.h
+++ b/src/gpu/effects/GrTextureDomain.h
@@ -153,13 +153,6 @@ protected:
class GrTextureDomainEffect : public GrSingleTextureEffect {
public:
- static sk_sp<GrFragmentProcessor> Make(GrTexture*,
- sk_sp<GrColorSpaceXform>,
- const SkMatrix&,
- const SkRect& domain,
- GrTextureDomain::Mode,
- GrSamplerParams::FilterMode filterMode);
-
static sk_sp<GrFragmentProcessor> Make(GrResourceProvider*,
sk_sp<GrTextureProxy>,
sk_sp<GrColorSpaceXform>,
@@ -182,13 +175,6 @@ public:
private:
GrTextureDomain fTextureDomain;
- GrTextureDomainEffect(GrTexture*,
- sk_sp<GrColorSpaceXform>,
- const SkMatrix&,
- const SkRect& domain,
- GrTextureDomain::Mode,
- GrSamplerParams::FilterMode);
-
GrTextureDomainEffect(GrResourceProvider*,
sk_sp<GrTextureProxy>,
sk_sp<GrColorSpaceXform>,
@@ -212,9 +198,6 @@ private:
class GrDeviceSpaceTextureDecalFragmentProcessor : public GrFragmentProcessor {
public:
- static sk_sp<GrFragmentProcessor> Make(GrTexture*, const SkIRect& subset,
- const SkIPoint& deviceSpaceOffset);
-
static sk_sp<GrFragmentProcessor> Make(GrResourceProvider*, sk_sp<GrTextureProxy>,
const SkIRect& subset,
const SkIPoint& deviceSpaceOffset);
@@ -236,8 +219,6 @@ private:
GrTextureDomain fTextureDomain;
SkIPoint fDeviceSpaceOffset;
- GrDeviceSpaceTextureDecalFragmentProcessor(GrTexture*, const SkIRect&, const SkIPoint&);
-
GrDeviceSpaceTextureDecalFragmentProcessor(GrResourceProvider*, sk_sp<GrTextureProxy>,
const SkIRect&, const SkIPoint&);
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index f7b32c27ba..19d3197e5a 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -20,6 +20,7 @@
#include "GrRenderTargetPriv.h"
#include "GrShaderCaps.h"
#include "GrSurfacePriv.h"
+#include "GrSurfaceProxyPriv.h"
#include "GrTexturePriv.h"
#include "GrTypes.h"
#include "SkAutoMalloc.h"
@@ -4421,13 +4422,20 @@ GrGLAttribArrayState* GrGLGpu::HWVertexArrayState::bindInternalVertexArray(GrGLG
return attribState;
}
-bool GrGLGpu::onIsACopyNeededForTextureParams(GrTexture* texture,
+bool GrGLGpu::onIsACopyNeededForTextureParams(GrTextureProxy* proxy,
const GrSamplerParams& textureParams,
GrTextureProducer::CopyParams* copyParams,
SkScalar scaleAdjust[2]) const {
+ const GrTexture* texture = proxy->priv().peekTexture();
+ if (!texture) {
+ // The only way to get and EXTERNAL or RECTANGLE texture in Ganesh is to wrap them.
+ // In that case the proxy should already be instantiated.
+ return false;
+ }
+
if (textureParams.isTiled() ||
GrSamplerParams::kMipMap_FilterMode == textureParams.filterMode()) {
- GrGLTexture* glTexture = static_cast<GrGLTexture*>(texture);
+ const GrGLTexture* glTexture = static_cast<const GrGLTexture*>(texture);
if (GR_GL_TEXTURE_EXTERNAL == glTexture->target() ||
GR_GL_TEXTURE_RECTANGLE == glTexture->target()) {
copyParams->fFilter = GrSamplerParams::kNone_FilterMode;
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index 6e0d900b6e..1fc25576fe 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -189,7 +189,7 @@ private:
bool renderTarget, GrGLTexture::TexParams* initialTexParams,
const SkTArray<GrMipLevel>& texels);
- bool onIsACopyNeededForTextureParams(GrTexture*, const GrSamplerParams&,
+ bool onIsACopyNeededForTextureParams(GrTextureProxy*, const GrSamplerParams&,
GrTextureProducer::CopyParams*,
SkScalar scaleAdjust[2]) const override;
diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h
index e31044ac5e..5bdf9403e5 100644
--- a/src/image/SkImage_Base.h
+++ b/src/image/SkImage_Base.h
@@ -55,7 +55,9 @@ public:
virtual sk_sp<GrTextureProxy> asTextureProxyRef(GrContext*, const GrSamplerParams&,
SkColorSpace*, sk_sp<SkColorSpace>*,
SkScalar scaleAdjust[2]) const = 0;
- virtual sk_sp<GrTexture> refPinnedTexture(uint32_t* uniqueID) const { return nullptr; }
+ virtual sk_sp<GrTextureProxy> refPinnedTextureProxy(uint32_t* uniqueID) const {
+ return nullptr;
+ }
virtual GrBackendObject onGetTextureHandle(bool flushPendingGrContextIO,
GrSurfaceOrigin* origin) const {
return 0;
diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp
index b4ec0649f2..68a2df05a1 100644
--- a/src/image/SkImage_Gpu.cpp
+++ b/src/image/SkImage_Gpu.cpp
@@ -106,16 +106,10 @@ sk_sp<GrTextureProxy> SkImage_Gpu::asTextureProxyRef(GrContext* context,
if (texColorSpace) {
*texColorSpace = this->fColorSpace;
}
- GrTexture* texture = fProxy->instantiate(fContext->resourceProvider());
- if (!texture) {
- return nullptr;
- }
- GrTextureAdjuster adjuster(fContext, texture, this->alphaType(), this->bounds(),
+ GrTextureAdjuster adjuster(fContext, fProxy, this->alphaType(), this->bounds(),
this->uniqueID(), this->fColorSpace.get());
- sk_sp<GrTexture> tex(adjuster.refTextureSafeForParams(params, nullptr, scaleAdjust));
-
- return GrSurfaceProxy::MakeWrapped(std::move(tex));
+ return adjuster.refTextureProxySafeForParams(params, nullptr, scaleAdjust);
}
static void apply_premul(const SkImageInfo& info, void* pixels, size_t rowBytes) {
@@ -390,18 +384,18 @@ sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace
std::move(imageColorSpace));
}
-static sk_sp<SkImage> create_image_from_maker(GrContext* context,
- GrTextureMaker* maker, SkAlphaType at, uint32_t id,
+static sk_sp<SkImage> create_image_from_maker(GrContext* context, GrTextureMaker* maker,
+ SkAlphaType at, uint32_t id,
SkColorSpace* dstColorSpace) {
sk_sp<SkColorSpace> texColorSpace;
- sk_sp<GrTexture> texture(maker->refTextureForParams(GrSamplerParams::ClampNoFilter(),
- dstColorSpace, &texColorSpace, nullptr));
- if (!texture) {
+ sk_sp<GrTextureProxy> proxy(maker->refTextureProxyForParams(GrSamplerParams::ClampNoFilter(),
+ dstColorSpace,
+ &texColorSpace, nullptr));
+ if (!proxy) {
return nullptr;
}
- sk_sp<GrTextureProxy> proxy = GrSurfaceProxy::MakeWrapped(std::move(texture));
- return sk_make_sp<SkImage_Gpu>(context, id, at, std::move(proxy),
- std::move(texColorSpace), SkBudgeted::kNo);
+ return sk_make_sp<SkImage_Gpu>(context, id, at,
+ std::move(proxy), std::move(texColorSpace), SkBudgeted::kNo);
}
sk_sp<SkImage> SkImage::makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace) const {
diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h
index 87a97ee732..8c3df394f3 100644
--- a/src/image/SkImage_Gpu.h
+++ b/src/image/SkImage_Gpu.h
@@ -45,9 +45,9 @@ public:
sk_sp<SkColorSpace>*,
SkScalar scaleAdjust[2]) const override;
- sk_sp<GrTexture> refPinnedTexture(uint32_t* uniqueID) const override {
+ sk_sp<GrTextureProxy> refPinnedTextureProxy(uint32_t* uniqueID) const override {
*uniqueID = this->uniqueID();
- return sk_ref_sp(this->peekTexture());
+ return fProxy;
}
GrBackendObject onGetTextureHandle(bool flushPendingGrContextIO,
GrSurfaceOrigin* origin) const override;
diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp
index a4c7c7de89..30262ddbc3 100644
--- a/src/image/SkImage_Raster.cpp
+++ b/src/image/SkImage_Raster.cpp
@@ -121,7 +121,7 @@ public:
sk_sp<SkImage> onMakeColorSpace(sk_sp<SkColorSpace>) const override;
#if SK_SUPPORT_GPU
- sk_sp<GrTexture> refPinnedTexture(uint32_t* uniqueID) const override;
+ sk_sp<GrTextureProxy> refPinnedTextureProxy(uint32_t* uniqueID) const override;
bool onPinAsTexture(GrContext*) const override;
void onUnpinAsTexture(GrContext*) const override;
#endif
@@ -130,7 +130,7 @@ private:
SkBitmap fBitmap;
#if SK_SUPPORT_GPU
- mutable sk_sp<GrTexture> fPinnedTexture;
+ mutable sk_sp<GrTextureProxy> fPinnedProxy;
mutable int32_t fPinnedCount = 0;
mutable uint32_t fPinnedUniqueID = 0;
#endif
@@ -158,7 +158,7 @@ SkImage_Raster::SkImage_Raster(const Info& info, sk_sp<SkData> data, size_t rowB
SkImage_Raster::~SkImage_Raster() {
#if SK_SUPPORT_GPU
- SkASSERT(nullptr == fPinnedTexture.get()); // want the caller to have manually unpinned
+ SkASSERT(nullptr == fPinnedProxy.get()); // want the caller to have manually unpinned
#endif
}
@@ -192,13 +192,12 @@ sk_sp<GrTextureProxy> SkImage_Raster::asTextureProxyRef(GrContext* context,
}
uint32_t uniqueID;
- sk_sp<GrTexture> tex = this->refPinnedTexture(&uniqueID);
+ sk_sp<GrTextureProxy> tex = this->refPinnedTextureProxy(&uniqueID);
if (tex) {
- GrTextureAdjuster adjuster(context, fPinnedTexture.get(),
+ GrTextureAdjuster adjuster(context, fPinnedProxy,
fBitmap.alphaType(), fBitmap.bounds(),
fPinnedUniqueID, fBitmap.colorSpace());
- tex.reset(adjuster.refTextureSafeForParams(params, nullptr, scaleAdjust));
- return GrSurfaceProxy::MakeWrapped(std::move(tex));
+ return adjuster.refTextureProxySafeForParams(params, nullptr, scaleAdjust);
}
return GrRefCachedBitmapTextureProxy(context, fBitmap, params, scaleAdjust);
@@ -207,33 +206,26 @@ sk_sp<GrTextureProxy> SkImage_Raster::asTextureProxyRef(GrContext* context,
#if SK_SUPPORT_GPU
-sk_sp<GrTexture> SkImage_Raster::refPinnedTexture(uint32_t* uniqueID) const {
- if (fPinnedTexture) {
+sk_sp<GrTextureProxy> SkImage_Raster::refPinnedTextureProxy(uint32_t* uniqueID) const {
+ if (fPinnedProxy) {
SkASSERT(fPinnedCount > 0);
SkASSERT(fPinnedUniqueID != 0);
*uniqueID = fPinnedUniqueID;
- return fPinnedTexture;
+ return fPinnedProxy;
}
return nullptr;
}
bool SkImage_Raster::onPinAsTexture(GrContext* ctx) const {
- if (fPinnedTexture) {
+ if (fPinnedProxy) {
SkASSERT(fPinnedCount > 0);
SkASSERT(fPinnedUniqueID != 0);
- SkASSERT(fPinnedTexture->getContext() == ctx);
} else {
SkASSERT(fPinnedCount == 0);
SkASSERT(fPinnedUniqueID == 0);
- sk_sp<GrTextureProxy> proxy = GrRefCachedBitmapTextureProxy(
- ctx, fBitmap,
- GrSamplerParams::ClampNoFilter(),
- nullptr);
- if (!proxy) {
- return false;
- }
- fPinnedTexture.reset(SkSafeRef(proxy->instantiate(ctx->resourceProvider())));
- if (!fPinnedTexture) {
+ fPinnedProxy = GrRefCachedBitmapTextureProxy(ctx, fBitmap,
+ GrSamplerParams::ClampNoFilter(), nullptr);
+ if (!fPinnedProxy) {
return false;
}
fPinnedUniqueID = fBitmap.getGenerationID();
@@ -247,12 +239,9 @@ void SkImage_Raster::onUnpinAsTexture(GrContext* ctx) const {
// Note: we always decrement, even if fPinnedTexture is null
SkASSERT(fPinnedCount > 0);
SkASSERT(fPinnedUniqueID != 0);
- if (fPinnedTexture) {
- SkASSERT(fPinnedTexture->getContext() == ctx);
- }
if (0 == --fPinnedCount) {
- fPinnedTexture.reset(nullptr);
+ fPinnedProxy.reset(nullptr);
fPinnedUniqueID = 0;
}
}