Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 7fba244

Browse files
bsalomonSkia Commit-Bot
authored andcommitted
Remove copies for wrap modes in GrTextureProducer.
GrTextureEffect now supports implementing wrap modes in shaders for subsets and texture types with HW sampling restrictions. Change-Id: I5c93ade044465e13c5f56f7437fbbe288db0a8a8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/271056 Reviewed-by: Greg Daniel <[email protected]> Commit-Queue: Brian Salomon <[email protected]>
1 parent 706851d commit 7fba244

26 files changed

+168
-371
lines changed

gm/image_pict.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ class ImageCacheratorGM : public skiagm::GM {
273273
}
274274

275275
static void draw_as_tex(SkCanvas* canvas, SkImage* image, SkScalar x, SkScalar y) {
276-
GrSurfaceProxyView view = as_IB(image)->refView(canvas->getGrContext(),
277-
GrSamplerState::Filter::kBilerp, nullptr);
276+
GrSurfaceProxyView view =
277+
as_IB(image)->refView(canvas->getGrContext(), GrSamplerState::Filter::kBilerp);
278278
if (!view) {
279279
// show placeholder if we have no texture
280280
SkPaint paint;

src/gpu/GrBitmapTextureMaker.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,14 @@ GrSurfaceProxyView GrBitmapTextureMaker::refOriginalTextureProxyView(bool willBe
122122
return {};
123123
}
124124

125-
void GrBitmapTextureMaker::makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) {
125+
void GrBitmapTextureMaker::makeMipMappedKey(GrUniqueKey* mipMappedKey) {
126126
// Destination color space is irrelevant - we always upload the bitmap's contents as-is
127127
if (fOriginalKey.isValid()) {
128-
MakeCopyKeyFromOrigKey(fOriginalKey, copyParams, copyKey);
128+
MakeMipMappedKeyFromOriginalKey(fOriginalKey, mipMappedKey);
129129
}
130130
}
131131

132-
void GrBitmapTextureMaker::didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) {
133-
GrInstallBitmapUniqueKeyInvalidator(copyKey, contextUniqueID, fBitmap.pixelRef());
132+
void GrBitmapTextureMaker::didCacheMipMappedCopy(const GrUniqueKey& mipMappedKey,
133+
uint32_t contextUniqueID) {
134+
GrInstallBitmapUniqueKeyInvalidator(mipMappedKey, contextUniqueID, fBitmap.pixelRef());
134135
}

src/gpu/GrBitmapTextureMaker.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class GrBitmapTextureMaker : public GrTextureMaker {
2626
GrSurfaceProxyView refOriginalTextureProxyView(bool willBeMipped,
2727
AllowedTexGenType onlyIfFast) override;
2828

29-
void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) override;
30-
void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override;
29+
void makeMipMappedKey(GrUniqueKey* mipMappedKey) override;
30+
void didCacheMipMappedCopy(const GrUniqueKey& mipMappedKey, uint32_t contextUniqueID) override;
3131

3232
const SkBitmap fBitmap;
3333
const SkBackingFit fFit;

src/gpu/GrGpu.cpp

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -45,61 +45,14 @@ void GrGpu::disconnect(DisconnectType) {}
4545

4646
////////////////////////////////////////////////////////////////////////////////
4747

48-
bool GrGpu::IsACopyNeededForRepeatWrapMode(const GrCaps* caps,
49-
GrTextureProxy* texProxy,
50-
SkISize dimensions,
51-
GrSamplerState::Filter filter,
52-
GrTextureProducer::CopyParams* copyParams,
53-
SkScalar scaleAdjust[2]) {
54-
if (!caps->npotTextureTileSupport() &&
55-
(!SkIsPow2(dimensions.width()) || !SkIsPow2(dimensions.height()))) {
56-
SkASSERT(scaleAdjust);
57-
copyParams->fDimensions = {SkNextPow2(dimensions.width()), SkNextPow2(dimensions.height())};
58-
SkASSERT(scaleAdjust);
59-
scaleAdjust[0] = ((SkScalar)copyParams->fDimensions.width()) / dimensions.width();
60-
scaleAdjust[1] = ((SkScalar)copyParams->fDimensions.height()) / dimensions.height();
61-
switch (filter) {
62-
case GrSamplerState::Filter::kNearest:
63-
copyParams->fFilter = GrSamplerState::Filter::kNearest;
64-
break;
65-
case GrSamplerState::Filter::kBilerp:
66-
case GrSamplerState::Filter::kMipMap:
67-
// We are only ever scaling up so no reason to ever indicate kMipMap.
68-
copyParams->fFilter = GrSamplerState::Filter::kBilerp;
69-
break;
70-
}
71-
return true;
72-
}
73-
74-
if (texProxy) {
75-
// If the texture format itself doesn't support repeat wrap mode or mipmapping (and
76-
// those capabilities are required) force a copy.
77-
if (texProxy->hasRestrictedSampling()) {
78-
copyParams->fFilter = GrSamplerState::Filter::kNearest;
79-
copyParams->fDimensions = texProxy->dimensions();
80-
return true;
81-
}
82-
}
83-
84-
return false;
85-
}
86-
8748
bool GrGpu::IsACopyNeededForMips(const GrCaps* caps, const GrTextureProxy* texProxy,
88-
GrSamplerState::Filter filter,
89-
GrTextureProducer::CopyParams* copyParams) {
49+
GrSamplerState::Filter filter) {
9050
SkASSERT(texProxy);
91-
int mipCount = SkMipMap::ComputeLevelCount(texProxy->width(), texProxy->height());
92-
bool willNeedMips = GrSamplerState::Filter::kMipMap == filter && caps->mipMapSupport() &&
93-
mipCount;
94-
// If the texture format itself doesn't support mipmapping (and those capabilities are required)
95-
// force a copy.
96-
if (willNeedMips && texProxy->mipMapped() == GrMipMapped::kNo) {
97-
copyParams->fFilter = GrSamplerState::Filter::kNearest;
98-
copyParams->fDimensions = texProxy->dimensions();
99-
return true;
51+
if (filter != GrSamplerState::Filter::kMipMap || texProxy->mipMapped() == GrMipMapped::kYes ||
52+
!caps->mipMapSupport()) {
53+
return false;
10054
}
101-
102-
return false;
55+
return SkMipMap::ComputeLevelCount(texProxy->width(), texProxy->height()) > 0;
10356
}
10457

10558
static bool validate_texel_levels(SkISize dimensions, GrColorType texelColorType,

src/gpu/GrGpu.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -594,22 +594,12 @@ class GrGpu : public SkRefCnt {
594594
virtual GrStencilAttachment* createStencilAttachmentForRenderTarget(
595595
const GrRenderTarget*, int width, int height, int numStencilSamples) = 0;
596596

597-
// Determines whether a texture will need to be rescaled in order to be used with the
598-
// GrSamplerState.
599-
static bool IsACopyNeededForRepeatWrapMode(const GrCaps*,
600-
GrTextureProxy* texProxy,
601-
SkISize dimensions,
602-
GrSamplerState::Filter,
603-
GrTextureProducer::CopyParams*,
604-
SkScalar scaleAdjust[2]);
605-
606597
// Determines whether a texture will need to be copied because the draw requires mips but the
607598
// texutre doesn't have any. This call should be only checked if IsACopyNeededForTextureParams
608599
// fails. If the previous call succeeds, then a copy should be done using those params and the
609600
// mip mapping requirements will be handled there.
610601
static bool IsACopyNeededForMips(const GrCaps* caps, const GrTextureProxy* texProxy,
611-
GrSamplerState::Filter filter,
612-
GrTextureProducer::CopyParams* copyParams);
602+
GrSamplerState::Filter filter);
613603

614604
void handleDirtyContext() {
615605
if (fResetBits) {

src/gpu/GrImageTextureMaker.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@ GrSurfaceProxyView GrImageTextureMaker::refOriginalTextureProxyView(bool willBeM
3939
onlyIfFast);
4040
}
4141

42-
void GrImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) {
42+
void GrImageTextureMaker::makeMipMappedKey(GrUniqueKey* mipMappedKey) {
4343
if (fOriginalKey.isValid() && SkImage::kAllow_CachingHint == fCachingHint) {
4444
GrUniqueKey cacheKey;
4545
fImage->makeCacheKeyFromOrigKey(fOriginalKey, &cacheKey);
46-
MakeCopyKeyFromOrigKey(cacheKey, stretch, paramsCopyKey);
46+
MakeMipMappedKeyFromOriginalKey(cacheKey, mipMappedKey);
4747
}
4848
}
4949

50-
5150
/////////////////////////////////////////////////////////////////////////////////////////////////
5251

5352
GrYUVAImageTextureMaker::GrYUVAImageTextureMaker(GrContext* context, const SkImage* client,
@@ -75,13 +74,13 @@ GrSurfaceProxyView GrYUVAImageTextureMaker::refOriginalTextureProxyView(
7574
}
7675
}
7776

78-
void GrYUVAImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) {
77+
void GrYUVAImageTextureMaker::makeMipMappedKey(GrUniqueKey* mipMappedKey) {
7978
// TODO: Do we ever want to disable caching?
8079
if (fOriginalKey.isValid()) {
8180
GrUniqueKey cacheKey;
8281
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
8382
GrUniqueKey::Builder builder(&cacheKey, fOriginalKey, kDomain, 0, "Image");
84-
MakeCopyKeyFromOrigKey(cacheKey, stretch, paramsCopyKey);
83+
MakeMipMappedKeyFromOriginalKey(cacheKey, mipMappedKey);
8584
}
8685
}
8786

src/gpu/GrImageTextureMaker.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ class GrImageTextureMaker : public GrTextureMaker {
2222
SkImage::CachingHint chint, bool useDecal = false);
2323

2424
private:
25-
// TODO: consider overriding this, for the case where the underlying generator might be
26-
// able to efficiently produce a "stretched" texture natively (e.g. picture-backed)
27-
// GrTexture* generateTextureForParams(const CopyParams&) override;
2825
GrSurfaceProxyView refOriginalTextureProxyView(bool willBeMipped,
2926
AllowedTexGenType onlyIfFast) override;
3027

31-
void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override;
32-
void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override {}
28+
void makeMipMappedKey(GrUniqueKey* mipMappedKey) override;
29+
void didCacheMipMappedCopy(const GrUniqueKey& mipMappedKey, uint32_t contextUniqueID) override {
30+
}
3331

3432
const SkImage_Lazy* fImage;
3533
GrUniqueKey fOriginalKey;
@@ -53,8 +51,9 @@ class GrYUVAImageTextureMaker : public GrTextureMaker {
5351
GrSurfaceProxyView refOriginalTextureProxyView(bool willBeMipped,
5452
AllowedTexGenType onlyIfFast) override;
5553

56-
void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override;
57-
void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override {}
54+
void makeMipMappedKey(GrUniqueKey* mipMappedKey) override;
55+
void didCacheMipMappedCopy(const GrUniqueKey& mipMappedKey, uint32_t contextUniqueID) override {
56+
}
5857

5958
std::unique_ptr<GrFragmentProcessor> createFragmentProcessor(
6059
const SkMatrix& textureMatrix,

src/gpu/GrTextureAdjuster.cpp

Lines changed: 26 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -22,65 +22,47 @@ GrTextureAdjuster::GrTextureAdjuster(GrRecordingContext* context,
2222
, fOriginal(std::move(original))
2323
, fUniqueID(uniqueID) {}
2424

25-
void GrTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) {
25+
void GrTextureAdjuster::makeMipMappedKey(GrUniqueKey* mipMappedKey) {
2626
// Destination color space is irrelevant - we already have a texture so we're just sub-setting
2727
GrUniqueKey baseKey;
2828
GrMakeKeyFromImageID(&baseKey, fUniqueID, SkIRect::MakeSize(this->dimensions()));
29-
MakeCopyKeyFromOrigKey(baseKey, params, copyKey);
29+
MakeMipMappedKeyFromOriginalKey(baseKey, mipMappedKey);
3030
}
3131

32-
void GrTextureAdjuster::didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) {
32+
void GrTextureAdjuster::didCacheMipMappedCopy(const GrUniqueKey& mipMappedKey,
33+
uint32_t contextUniqueID) {
3334
// We don't currently have a mechanism for notifications on Images!
3435
}
3536

36-
GrSurfaceProxyView GrTextureAdjuster::copy(const CopyParams& copyParams, bool willBeMipped,
37-
bool copyForMipsOnly) {
37+
GrSurfaceProxyView GrTextureAdjuster::makeMippedCopy() {
3838
GrProxyProvider* proxyProvider = this->context()->priv().proxyProvider();
3939

4040
GrUniqueKey key;
41-
this->makeCopyKey(copyParams, &key);
41+
this->makeMipMappedKey(&key);
4242
sk_sp<GrTextureProxy> cachedCopy;
4343
const GrSurfaceProxyView& originalView = this->originalProxyView();
4444
if (key.isValid()) {
4545
cachedCopy = proxyProvider->findOrCreateProxyByUniqueKey(key, this->colorType());
46-
if (cachedCopy && (!willBeMipped || GrMipMapped::kYes == cachedCopy->mipMapped())) {
47-
// TODO: Once we no longer use CopyOnGpu which can fallback to arbitrary formats and
48-
// colorTypes, we can use the swizzle of the originalView.
49-
GrSwizzle swizzle = cachedCopy->textureSwizzleDoNotUse();
50-
return GrSurfaceProxyView(std::move(cachedCopy), originalView.origin(), swizzle);
46+
if (cachedCopy) {
47+
return {std::move(cachedCopy), originalView.origin(), originalView.swizzle()};
5148
}
5249
}
5350

54-
GrSurfaceProxyView copyView;
55-
if (copyForMipsOnly) {
56-
copyView = GrCopyBaseMipMapToTextureProxy(this->context(), originalView.proxy(),
57-
originalView.origin(), this->colorType());
58-
} else {
59-
copyView = CopyOnGpu(this->context(), this->originalProxyViewRef(), this->colorType(),
60-
copyParams, willBeMipped);
51+
GrSurfaceProxyView copyView = GrCopyBaseMipMapToTextureProxy(
52+
this->context(), originalView.proxy(), originalView.origin(), this->colorType());
53+
if (!copyView) {
54+
return {};
6155
}
62-
if (copyView.proxy()) {
63-
if (key.isValid()) {
64-
SkASSERT(copyView.origin() == originalView.origin());
65-
if (cachedCopy) {
66-
SkASSERT(GrMipMapped::kYes == copyView.asTextureProxy()->mipMapped() &&
67-
GrMipMapped::kNo == cachedCopy->mipMapped());
68-
// If we had a cachedProxy, that means there already is a proxy in the cache which
69-
// matches the key, but it does not have mip levels and we require them. Thus we
70-
// must remove the unique key from that proxy.
71-
SkASSERT(cachedCopy->getUniqueKey() == key);
72-
proxyProvider->removeUniqueKeyFromProxy(cachedCopy.get());
73-
}
74-
proxyProvider->assignUniqueKeyToProxy(key, copyView.asTextureProxy());
75-
this->didCacheCopy(key, proxyProvider->contextID());
76-
}
56+
if (key.isValid()) {
57+
SkASSERT(copyView.origin() == originalView.origin());
58+
proxyProvider->assignUniqueKeyToProxy(key, copyView.asTextureProxy());
59+
this->didCacheMipMappedCopy(key, proxyProvider->contextID());
7760
}
7861
return copyView;
7962
}
8063

8164
GrSurfaceProxyView GrTextureAdjuster::onRefTextureProxyViewForParams(GrSamplerState params,
82-
bool willBeMipped,
83-
SkScalar scaleAdjust[2]) {
65+
bool willBeMipped) {
8466
if (this->context()->priv().abandoned()) {
8567
// The texture was abandoned.
8668
return {};
@@ -92,51 +74,32 @@ GrSurfaceProxyView GrTextureAdjuster::onRefTextureProxyViewForParams(GrSamplerSt
9274
GrSurfaceProxyView view = this->originalProxyViewRef();
9375
GrTextureProxy* texProxy = view.asTextureProxy();
9476
SkASSERT(texProxy);
95-
CopyParams copyParams;
96-
97-
bool needsCopyForMipsOnly = false;
98-
if (!params.isRepeated() ||
99-
!GrGpu::IsACopyNeededForRepeatWrapMode(this->context()->priv().caps(), texProxy,
100-
texProxy->dimensions(), params.filter(), &copyParams,
101-
scaleAdjust)) {
102-
needsCopyForMipsOnly = GrGpu::IsACopyNeededForMips(this->context()->priv().caps(),
103-
texProxy, params.filter(),
104-
&copyParams);
105-
if (!needsCopyForMipsOnly) {
106-
return view;
107-
}
77+
if (!GrGpu::IsACopyNeededForMips(this->context()->priv().caps(), texProxy, params.filter())) {
78+
return view;
10879
}
10980

110-
GrSurfaceProxyView result = this->copy(copyParams, willBeMipped, needsCopyForMipsOnly);
111-
if (!result.proxy() && needsCopyForMipsOnly) {
81+
GrSurfaceProxyView copy = this->makeMippedCopy();
82+
if (!copy) {
11283
// If we were unable to make a copy and we only needed a copy for mips, then we will return
11384
// the source texture here and require that the GPU backend is able to fall back to using
11485
// bilerp if mips are required.
11586
return view;
11687
}
117-
SkASSERT(result.asTextureProxy());
118-
return result;
88+
SkASSERT(copy.asTextureProxy());
89+
return copy;
11990
}
12091

12192
std::unique_ptr<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor(
122-
const SkMatrix& origTextureMatrix,
93+
const SkMatrix& textureMatrix,
12394
const SkRect& constraintRect,
12495
FilterConstraint filterConstraint,
12596
bool coordsLimitedToConstraintRect,
12697
const GrSamplerState::Filter* filterOrNullForBicubic) {
127-
SkMatrix textureMatrix = origTextureMatrix;
128-
129-
SkScalar scaleAdjust[2] = { 1.0f, 1.0f };
130-
GrSurfaceProxyView view = this->viewForParams(filterOrNullForBicubic, scaleAdjust);
131-
if (!view.proxy()) {
98+
GrSurfaceProxyView view = this->viewForParams(filterOrNullForBicubic);
99+
if (!view) {
132100
return nullptr;
133101
}
134102
SkASSERT(view.asTextureProxy());
135-
// If we made a copy then we only copied the contentArea, in which case the new texture is all
136-
// content.
137-
if (view.proxy() != this->originalProxyView().proxy()) {
138-
textureMatrix.postScale(scaleAdjust[0], scaleAdjust[1]);
139-
}
140103

141104
SkRect domain;
142105
DomainMode domainMode =

src/gpu/GrTextureAdjuster.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,16 @@ class GrTextureAdjuster : public GrTextureProducer {
3333
uint32_t uniqueID, bool useDecal = false);
3434

3535
protected:
36-
void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) override;
37-
void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override;
36+
void makeMipMappedKey(GrUniqueKey* mipMappedKey) override;
37+
void didCacheMipMappedCopy(const GrUniqueKey& mipMappedKey, uint32_t contextUniqueID) override;
3838

3939
const GrSurfaceProxyView& originalProxyView() const { return fOriginal; }
4040
GrSurfaceProxyView originalProxyViewRef() const { return fOriginal; }
4141

4242
private:
43-
GrSurfaceProxyView onRefTextureProxyViewForParams(GrSamplerState, bool willBeMipped,
44-
SkScalar scaleAdjust[2]) override;
43+
GrSurfaceProxyView onRefTextureProxyViewForParams(GrSamplerState, bool willBeMipped) override;
4544

46-
GrSurfaceProxyView copy(const CopyParams& copyParams, bool willBeMipped, bool copyOnlyForMips);
45+
GrSurfaceProxyView makeMippedCopy();
4746

4847
GrSurfaceProxyView fOriginal;
4948
uint32_t fUniqueID;

0 commit comments

Comments
 (0)