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

Commit bf5cb0f

Browse files
rphilliSkia Commit-Bot
authored andcommitted
Revert "Remove copies for wrap modes in GrTextureProducer."
This reverts commit 7fba244. Reason for revert: See if this is blocking the Chrome roll Original change's description: > 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]> [email protected],[email protected] Change-Id: I14397bec8ff4ba165c28faa8f44497f47d865862 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/c/skia/+/272522 Reviewed-by: Robert Phillips <[email protected]> Commit-Queue: Robert Phillips <[email protected]>
1 parent 3928466 commit bf5cb0f

26 files changed

+371
-168
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 =
277-
as_IB(image)->refView(canvas->getGrContext(), GrSamplerState::Filter::kBilerp);
276+
GrSurfaceProxyView view = as_IB(image)->refView(canvas->getGrContext(),
277+
GrSamplerState::Filter::kBilerp, nullptr);
278278
if (!view) {
279279
// show placeholder if we have no texture
280280
SkPaint paint;

src/gpu/GrBitmapTextureMaker.cpp

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

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

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

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 makeMipMappedKey(GrUniqueKey* mipMappedKey) override;
30-
void didCacheMipMappedCopy(const GrUniqueKey& mipMappedKey, uint32_t contextUniqueID) override;
29+
void makeCopyKey(const CopyParams& copyParams, GrUniqueKey* copyKey) override;
30+
void didCacheCopy(const GrUniqueKey& copyKey, uint32_t contextUniqueID) override;
3131

3232
const SkBitmap fBitmap;
3333
const SkBackingFit fFit;

src/gpu/GrGpu.cpp

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,61 @@ 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+
4887
bool GrGpu::IsACopyNeededForMips(const GrCaps* caps, const GrTextureProxy* texProxy,
49-
GrSamplerState::Filter filter) {
88+
GrSamplerState::Filter filter,
89+
GrTextureProducer::CopyParams* copyParams) {
5090
SkASSERT(texProxy);
51-
if (filter != GrSamplerState::Filter::kMipMap || texProxy->mipMapped() == GrMipMapped::kYes ||
52-
!caps->mipMapSupport()) {
53-
return false;
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;
54100
}
55-
return SkMipMap::ComputeLevelCount(texProxy->width(), texProxy->height()) > 0;
101+
102+
return false;
56103
}
57104

58105
static bool validate_texel_levels(SkISize dimensions, GrColorType texelColorType,

src/gpu/GrGpu.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,22 @@ 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+
597606
// Determines whether a texture will need to be copied because the draw requires mips but the
598607
// texutre doesn't have any. This call should be only checked if IsACopyNeededForTextureParams
599608
// fails. If the previous call succeeds, then a copy should be done using those params and the
600609
// mip mapping requirements will be handled there.
601610
static bool IsACopyNeededForMips(const GrCaps* caps, const GrTextureProxy* texProxy,
602-
GrSamplerState::Filter filter);
611+
GrSamplerState::Filter filter,
612+
GrTextureProducer::CopyParams* copyParams);
603613

604614
void handleDirtyContext() {
605615
if (fResetBits) {

src/gpu/GrImageTextureMaker.cpp

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

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

50+
5051
/////////////////////////////////////////////////////////////////////////////////////////////////
5152

5253
GrYUVAImageTextureMaker::GrYUVAImageTextureMaker(GrContext* context, const SkImage* client,
@@ -74,13 +75,13 @@ GrSurfaceProxyView GrYUVAImageTextureMaker::refOriginalTextureProxyView(
7475
}
7576
}
7677

77-
void GrYUVAImageTextureMaker::makeMipMappedKey(GrUniqueKey* mipMappedKey) {
78+
void GrYUVAImageTextureMaker::makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) {
7879
// TODO: Do we ever want to disable caching?
7980
if (fOriginalKey.isValid()) {
8081
GrUniqueKey cacheKey;
8182
static const GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
8283
GrUniqueKey::Builder builder(&cacheKey, fOriginalKey, kDomain, 0, "Image");
83-
MakeMipMappedKeyFromOriginalKey(cacheKey, mipMappedKey);
84+
MakeCopyKeyFromOrigKey(cacheKey, stretch, paramsCopyKey);
8485
}
8586
}
8687

src/gpu/GrImageTextureMaker.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ 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;
2528
GrSurfaceProxyView refOriginalTextureProxyView(bool willBeMipped,
2629
AllowedTexGenType onlyIfFast) override;
2730

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

3234
const SkImage_Lazy* fImage;
3335
GrUniqueKey fOriginalKey;
@@ -51,9 +53,8 @@ class GrYUVAImageTextureMaker : public GrTextureMaker {
5153
GrSurfaceProxyView refOriginalTextureProxyView(bool willBeMipped,
5254
AllowedTexGenType onlyIfFast) override;
5355

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

5859
std::unique_ptr<GrFragmentProcessor> createFragmentProcessor(
5960
const SkMatrix& textureMatrix,

src/gpu/GrTextureAdjuster.cpp

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

25-
void GrTextureAdjuster::makeMipMappedKey(GrUniqueKey* mipMappedKey) {
25+
void GrTextureAdjuster::makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) {
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-
MakeMipMappedKeyFromOriginalKey(baseKey, mipMappedKey);
29+
MakeCopyKeyFromOrigKey(baseKey, params, copyKey);
3030
}
3131

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

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

4040
GrUniqueKey key;
41-
this->makeMipMappedKey(&key);
41+
this->makeCopyKey(copyParams, &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) {
47-
return {std::move(cachedCopy), originalView.origin(), originalView.swizzle()};
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);
4851
}
4952
}
5053

51-
GrSurfaceProxyView copyView = GrCopyBaseMipMapToTextureProxy(
52-
this->context(), originalView.proxy(), originalView.origin(), this->colorType());
53-
if (!copyView) {
54-
return {};
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);
5561
}
56-
if (key.isValid()) {
57-
SkASSERT(copyView.origin() == originalView.origin());
58-
proxyProvider->assignUniqueKeyToProxy(key, copyView.asTextureProxy());
59-
this->didCacheMipMappedCopy(key, proxyProvider->contextID());
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+
}
6077
}
6178
return copyView;
6279
}
6380

6481
GrSurfaceProxyView GrTextureAdjuster::onRefTextureProxyViewForParams(GrSamplerState params,
65-
bool willBeMipped) {
82+
bool willBeMipped,
83+
SkScalar scaleAdjust[2]) {
6684
if (this->context()->priv().abandoned()) {
6785
// The texture was abandoned.
6886
return {};
@@ -74,32 +92,51 @@ GrSurfaceProxyView GrTextureAdjuster::onRefTextureProxyViewForParams(GrSamplerSt
7492
GrSurfaceProxyView view = this->originalProxyViewRef();
7593
GrTextureProxy* texProxy = view.asTextureProxy();
7694
SkASSERT(texProxy);
77-
if (!GrGpu::IsACopyNeededForMips(this->context()->priv().caps(), texProxy, params.filter())) {
78-
return view;
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+
}
79108
}
80109

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

92121
std::unique_ptr<GrFragmentProcessor> GrTextureAdjuster::createFragmentProcessor(
93-
const SkMatrix& textureMatrix,
122+
const SkMatrix& origTextureMatrix,
94123
const SkRect& constraintRect,
95124
FilterConstraint filterConstraint,
96125
bool coordsLimitedToConstraintRect,
97126
const GrSamplerState::Filter* filterOrNullForBicubic) {
98-
GrSurfaceProxyView view = this->viewForParams(filterOrNullForBicubic);
99-
if (!view) {
127+
SkMatrix textureMatrix = origTextureMatrix;
128+
129+
SkScalar scaleAdjust[2] = { 1.0f, 1.0f };
130+
GrSurfaceProxyView view = this->viewForParams(filterOrNullForBicubic, scaleAdjust);
131+
if (!view.proxy()) {
100132
return nullptr;
101133
}
102134
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+
}
103140

104141
SkRect domain;
105142
DomainMode domainMode =

src/gpu/GrTextureAdjuster.h

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

3535
protected:
36-
void makeMipMappedKey(GrUniqueKey* mipMappedKey) override;
37-
void didCacheMipMappedCopy(const GrUniqueKey& mipMappedKey, uint32_t contextUniqueID) override;
36+
void makeCopyKey(const CopyParams& params, GrUniqueKey* copyKey) override;
37+
void didCacheCopy(const GrUniqueKey& copyKey, 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) override;
43+
GrSurfaceProxyView onRefTextureProxyViewForParams(GrSamplerState, bool willBeMipped,
44+
SkScalar scaleAdjust[2]) override;
4445

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

4748
GrSurfaceProxyView fOriginal;
4849
uint32_t fUniqueID;

0 commit comments

Comments
 (0)