Revert "Don't require mips in GrTextureProducer if texture is 1x1."
This reverts commit 5191fd7555d34225ef771ad4cac65bcbbb50a89c.
Reason for revert: breaking angle
Original change's description:
> Don't require mips in GrTextureProducer if texture is 1x1.
>
> Bug: chromium:862921
> Change-Id: I5f3584ad36e160a5a09d0a37e31e147155076b4d
> Reviewed-on: https://skia-review.googlesource.com/142586
> Reviewed-by: Brian Osman <brianosman@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Commit-Queue: Greg Daniel <egdaniel@google.com>
TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com
Change-Id: Iaef7a56b061cb41f4c75ec20d8df77d3e52b194d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: chromium:862921
Reviewed-on: https://skia-review.googlesource.com/142600
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
diff --git a/src/gpu/GrTextureAdjuster.cpp b/src/gpu/GrTextureAdjuster.cpp
index b2fc058..d016896 100644
--- a/src/gpu/GrTextureAdjuster.cpp
+++ b/src/gpu/GrTextureAdjuster.cpp
@@ -17,8 +17,9 @@
SkAlphaType alphaType,
uint32_t uniqueID,
SkColorSpace* cs)
- : INHERITED(context, original->width(), original->height(),
+ : INHERITED(original->width(), original->height(),
GrPixelConfigIsAlphaOnly(original->config()))
+ , fContext(context)
, fOriginal(std::move(original))
, fAlphaType(alphaType)
, fColorSpace(cs)
@@ -76,7 +77,6 @@
const GrSamplerState& params,
SkColorSpace* dstColorSpace,
sk_sp<SkColorSpace>* texColorSpace,
- bool willBeMipped,
SkScalar scaleAdjust[2]) {
sk_sp<GrTextureProxy> proxy = this->originalProxyRef();
CopyParams copyParams;
@@ -105,6 +105,8 @@
}
}
+ bool willBeMipped = GrSamplerState::Filter::kMipMap == params.filter() &&
+ fContext->contextPriv().caps()->mipMapSupport();
sk_sp<GrTextureProxy> result = this->refTextureProxyCopy(copyParams, willBeMipped);
if (!result && needsCopyForMipsOnly) {
// If we were unable to make a copy and we only needed a copy for mips, then we will return
diff --git a/src/gpu/GrTextureAdjuster.h b/src/gpu/GrTextureAdjuster.h
index ad02ae0..e43e87b 100644
--- a/src/gpu/GrTextureAdjuster.h
+++ b/src/gpu/GrTextureAdjuster.h
@@ -46,11 +46,11 @@
sk_sp<GrTextureProxy> onRefTextureProxyForParams(const GrSamplerState&,
SkColorSpace* dstColorSpace,
sk_sp<SkColorSpace>* proxyColorSpace,
- bool willBeMipped,
SkScalar scaleAdjust[2]) override;
sk_sp<GrTextureProxy> refTextureProxyCopy(const CopyParams& copyParams, bool willBeMipped);
+ GrContext* fContext;
sk_sp<GrTextureProxy> fOriginal;
SkAlphaType fAlphaType;
SkColorSpace* fColorSpace;
diff --git a/src/gpu/GrTextureMaker.cpp b/src/gpu/GrTextureMaker.cpp
index 820e47a..22870cc 100644
--- a/src/gpu/GrTextureMaker.cpp
+++ b/src/gpu/GrTextureMaker.cpp
@@ -16,7 +16,6 @@
sk_sp<GrTextureProxy> GrTextureMaker::onRefTextureProxyForParams(const GrSamplerState& params,
SkColorSpace* dstColorSpace,
sk_sp<SkColorSpace>* texColorSpace,
- bool willBeMipped,
SkScalar scaleAdjust[2]) {
if (this->width() > fContext->contextPriv().caps()->maxTextureSize() ||
this->height() > fContext->contextPriv().caps()->maxTextureSize()) {
@@ -24,6 +23,11 @@
}
CopyParams copyParams;
+ bool willBeMipped = params.filter() == GrSamplerState::Filter::kMipMap;
+
+ if (!fContext->contextPriv().caps()->mipMapSupport()) {
+ willBeMipped = false;
+ }
if (texColorSpace) {
*texColorSpace = this->getColorSpace(dstColorSpace);
diff --git a/src/gpu/GrTextureMaker.h b/src/gpu/GrTextureMaker.h
index e2dd3c8..a365b50 100644
--- a/src/gpu/GrTextureMaker.h
+++ b/src/gpu/GrTextureMaker.h
@@ -28,7 +28,8 @@
protected:
GrTextureMaker(GrContext* context, int width, int height, bool isAlphaOnly)
- : INHERITED(context, width, height, isAlphaOnly) {}
+ : INHERITED(width, height, isAlphaOnly)
+ , fContext(context) {}
/**
* Return the maker's "original" texture. It is the responsibility of the maker to handle any
@@ -53,9 +54,10 @@
sk_sp<GrTextureProxy> onRefTextureProxyForParams(const GrSamplerState&,
SkColorSpace* dstColorSpace,
sk_sp<SkColorSpace>* proxyColorSpace,
- bool willBeMipped,
SkScalar scaleAdjust[2]) override;
+ GrContext* fContext;
+
typedef GrTextureProducer INHERITED;
};
diff --git a/src/gpu/GrTextureProducer.cpp b/src/gpu/GrTextureProducer.cpp
index cdf2a47..59962c5 100644
--- a/src/gpu/GrTextureProducer.cpp
+++ b/src/gpu/GrTextureProducer.cpp
@@ -11,7 +11,6 @@
#include "GrRenderTargetContext.h"
#include "GrTextureProxy.h"
#include "SkGr.h"
-#include "SkMipMap.h"
#include "SkRectPriv.h"
#include "effects/GrBicubicEffect.h"
#include "effects/GrSimpleTextureEffect.h"
@@ -227,18 +226,8 @@
SkDEBUGCODE(bool expectNoScale = (sampler.filter() != GrSamplerState::Filter::kMipMap &&
!sampler.isRepeated()));
SkASSERT(scaleAdjust || expectNoScale);
-
- int mipCount = SkMipMap::ComputeLevelCount(this->width(), this->height());
- bool willBeMipped = GrSamplerState::Filter::kMipMap == sampler.filter() && mipCount &&
- fContext->contextPriv().caps()->mipMapSupport();
-
auto result =
- this->onRefTextureProxyForParams(sampler, dstColorSpace, proxyColorSpace, willBeMipped,
- scaleAdjust);
-
- // Check to make sure that if we say the texture willBeMipped that the returned texture has mip
- // maps.
- SkASSERT(!result || !willBeMipped || result->mipMapped() == GrMipMapped::kYes);
+ this->onRefTextureProxyForParams(sampler, dstColorSpace, proxyColorSpace, scaleAdjust);
// Check that the "no scaling expected" case always returns a proxy of the same size as the
// producer.
@@ -254,18 +243,8 @@
GrMipMapped::kNo == willNeedMips ? GrSamplerState::Filter::kNearest
: GrSamplerState::Filter::kMipMap;
GrSamplerState sampler(GrSamplerState::WrapMode::kClamp, filter);
-
- int mipCount = SkMipMap::ComputeLevelCount(this->width(), this->height());
- bool willBeMipped = GrSamplerState::Filter::kMipMap == sampler.filter() && mipCount &&
- fContext->contextPriv().caps()->mipMapSupport();
-
auto result =
- this->onRefTextureProxyForParams(sampler, dstColorSpace, proxyColorSpace,
- willBeMipped, nullptr);
-
- // Check to make sure that if we say the texture willBeMipped that the returned texture has mip
- // maps.
- SkASSERT(!result || !willBeMipped || result->mipMapped() == GrMipMapped::kYes);
+ this->onRefTextureProxyForParams(sampler, dstColorSpace, proxyColorSpace, nullptr);
// Check that no scaling occured and we returned a proxy of the same size as the producer.
SkASSERT(!result || (result->width() == this->width() && result->height() == this->height()));
diff --git a/src/gpu/GrTextureProducer.h b/src/gpu/GrTextureProducer.h
index 66adb6f..b42bbcf 100644
--- a/src/gpu/GrTextureProducer.h
+++ b/src/gpu/GrTextureProducer.h
@@ -124,9 +124,8 @@
protected:
friend class GrTextureProducer_TestAccess;
- GrTextureProducer(GrContext* context, int width, int height, bool isAlphaOnly)
- : fContext(context)
- , fWidth(width)
+ GrTextureProducer(int width, int height, bool isAlphaOnly)
+ : fWidth(width)
, fHeight(height)
, fIsAlphaOnly(isAlphaOnly) {}
@@ -186,13 +185,10 @@
const SkRect& domain,
const GrSamplerState::Filter* filterOrNullForBicubic);
- GrContext* fContext;
-
private:
virtual sk_sp<GrTextureProxy> onRefTextureProxyForParams(const GrSamplerState&,
SkColorSpace* dstColorSpace,
sk_sp<SkColorSpace>* proxyColorSpace,
- bool willBeMipped,
SkScalar scaleAdjust[2]) = 0;
const int fWidth;
diff --git a/src/gpu/vk/GrVkGpuCommandBuffer.cpp b/src/gpu/vk/GrVkGpuCommandBuffer.cpp
index d58a8b5..91adb5a 100644
--- a/src/gpu/vk/GrVkGpuCommandBuffer.cpp
+++ b/src/gpu/vk/GrVkGpuCommandBuffer.cpp
@@ -622,8 +622,7 @@
}
// Check if we need to regenerate any mip maps
- if (GrSamplerState::Filter::kMipMap == sampler.samplerState().filter() &&
- (vkTexture->width() != 1 || vkTexture->height() != 1)) {
+ if (GrSamplerState::Filter::kMipMap == sampler.samplerState().filter()) {
SkASSERT(vkTexture->texturePriv().mipMapped() == GrMipMapped::kYes);
if (vkTexture->texturePriv().mipMapsAreDirty()) {
gpu->regenerateMipMapLevels(vkTexture);
diff --git a/tests/GrMipMappedTest.cpp b/tests/GrMipMappedTest.cpp
index ee4838d..3c47598 100644
--- a/tests/GrMipMappedTest.cpp
+++ b/tests/GrMipMappedTest.cpp
@@ -289,40 +289,3 @@
}
}
}
-
-// Test that we don't create a mip mapped texture if the size is 1x1 even if the filter mode is set
-// to use mips. This test passes by not crashing or hitting asserts in code.
-DEF_GPUTEST_FOR_RENDERING_CONTEXTS(Gr1x1TextureMipMappedTest, reporter, ctxInfo) {
- GrContext* context = ctxInfo.grContext();
- if (!context->contextPriv().caps()->mipMapSupport()) {
- return;
- }
-
- // Make surface to draw into
- SkImageInfo info = SkImageInfo::MakeN32(16, 16, kPremul_SkAlphaType);
- sk_sp<SkSurface> surface = SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info);
-
- // Make 1x1 raster bitmap
- SkBitmap bmp;
- bmp.allocN32Pixels(1, 1);
- SkPMColor* pixel = reinterpret_cast<SkPMColor*>(bmp.getPixels());
- *pixel = 0;
-
- sk_sp<SkImage> bmpImage = SkImage::MakeFromBitmap(bmp);
-
- // Make sure we scale so we don't optimize out the use of mips.
- surface->getCanvas()->scale(0.5f, 0.5f);
-
- SkPaint paint;
- // This should upload the image to a non mipped GrTextureProxy.
- surface->getCanvas()->drawImage(bmpImage, 0, 0, &paint);
- surface->flush();
-
- // Now set the filter quality to high so we use mip maps. We should find the non mipped texture
- // in the cache for the SkImage. Since the texture is 1x1 we should just use that texture
- // instead of trying to do a copy to a mipped texture.
- paint.setFilterQuality(kHigh_SkFilterQuality);
- surface->getCanvas()->drawImage(bmpImage, 0, 0, &paint);
- surface->flush();
-}
-