diff options
author | Greg Daniel <egdaniel@google.com> | 2018-06-12 16:39:59 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-06-13 13:55:56 +0000 |
commit | 5f4b09d523a761a3a5c622bb01eeba47905da5f0 (patch) | |
tree | 899574a311503375d911ee6486894eb921138550 /src | |
parent | ed8ed91ec8c0eb523262eb7bb91558399c7e591f (diff) |
Allow caller to specify if the want mip maps in makeTextureImage call.
Since Ganesh no longer will allocate mips late, this gives the clients a
way to tell skia that they want the texture they will be using to have mips.
It also supports allowing a client to take a non mipped texture backed
image and turn it into a new image which is mipped and texture backed.
Bug: chromium:834837
Change-Id: I1781ce618c22023b6309f248e7ee49e69bd3c6df
Reviewed-on: https://skia-review.googlesource.com/134323
Commit-Queue: Greg Daniel <egdaniel@google.com>
Reviewed-by: Eric Karl <ericrk@chromium.org>
Reviewed-by: Cary Clark <caryclark@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/gpu/GrTextureProducer.cpp | 15 | ||||
-rw-r--r-- | src/gpu/GrTextureProducer.h | 15 | ||||
-rw-r--r-- | src/image/SkImage.cpp | 3 | ||||
-rw-r--r-- | src/image/SkImage_Gpu.cpp | 35 |
4 files changed, 56 insertions, 12 deletions
diff --git a/src/gpu/GrTextureProducer.cpp b/src/gpu/GrTextureProducer.cpp index 1e9c3acd16..59962c55b1 100644 --- a/src/gpu/GrTextureProducer.cpp +++ b/src/gpu/GrTextureProducer.cpp @@ -235,3 +235,18 @@ sk_sp<GrTextureProxy> GrTextureProducer::refTextureProxyForParams( (result->width() == this->width() && result->height() == this->height())); return result; } + +sk_sp<GrTextureProxy> GrTextureProducer::refTextureProxy(GrMipMapped willNeedMips, + SkColorSpace* dstColorSpace, + sk_sp<SkColorSpace>* proxyColorSpace) { + GrSamplerState::Filter filter = + GrMipMapped::kNo == willNeedMips ? GrSamplerState::Filter::kNearest + : GrSamplerState::Filter::kMipMap; + GrSamplerState sampler(GrSamplerState::WrapMode::kClamp, filter); + auto result = + 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())); + return result; +} diff --git a/src/gpu/GrTextureProducer.h b/src/gpu/GrTextureProducer.h index 467948dfa6..c458d4fbe6 100644 --- a/src/gpu/GrTextureProducer.h +++ b/src/gpu/GrTextureProducer.h @@ -98,6 +98,21 @@ public: proxyColorSpace, scaleAdjust); } + /** + * Returns a texture that is safe for use with the dstColorSpace. If willNeedMips is true then + * the returned texture is guaranteed to have allocated mip map levels. This can be a + * performance win if future draws with the texture require mip maps. + * + * Places the color space of the texture in (*proxyColorSpace). + */ + // TODO: Once we remove support for npot textures, we should add a flag for must support repeat + // wrap mode. To support that flag now would require us to support scaleAdjust array like in + // refTextureProxyForParams, however the current public API that uses this call does not expose + // that array. + sk_sp<GrTextureProxy> refTextureProxy(GrMipMapped willNeedMips, + SkColorSpace* dstColorSpace, + sk_sp<SkColorSpace>* proxyColorSpace); + virtual ~GrTextureProducer() {} int width() const { return fWidth; } diff --git a/src/image/SkImage.cpp b/src/image/SkImage.cpp index 1d5e2dbf27..ee0eff08a9 100644 --- a/src/image/SkImage.cpp +++ b/src/image/SkImage.cpp @@ -385,7 +385,8 @@ sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace return nullptr; } -sk_sp<SkImage> SkImage::makeTextureImage(GrContext*, SkColorSpace* dstColorSpace) const { +sk_sp<SkImage> SkImage::makeTextureImage(GrContext*, SkColorSpace* dstColorSpace, + GrMipMapped mipMapped) const { return nullptr; } diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 01f0c1ff8a..faba37383c 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -498,12 +498,13 @@ sk_sp<SkImage> SkImage::MakeFromNV12TexturesCopy(GrContext* ctx, SkYUVColorSpace size, origin, std::move(imageColorSpace)); } -static sk_sp<SkImage> create_image_from_maker(GrContext* context, GrTextureMaker* maker, - SkAlphaType at, uint32_t id, - SkColorSpace* dstColorSpace) { +static sk_sp<SkImage> create_image_from_producer(GrContext* context, GrTextureProducer* producer, + SkAlphaType at, uint32_t id, + SkColorSpace* dstColorSpace, + GrMipMapped mipMapped) { sk_sp<SkColorSpace> texColorSpace; - sk_sp<GrTextureProxy> proxy(maker->refTextureProxyForParams( - GrSamplerState::ClampNearest(), dstColorSpace, &texColorSpace, nullptr)); + sk_sp<GrTextureProxy> proxy(producer->refTextureProxy(mipMapped, dstColorSpace, + &texColorSpace)); if (!proxy) { return nullptr; } @@ -511,24 +512,36 @@ static sk_sp<SkImage> create_image_from_maker(GrContext* context, GrTextureMaker std::move(texColorSpace), SkBudgeted::kNo); } -sk_sp<SkImage> SkImage::makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace) const { +sk_sp<SkImage> SkImage::makeTextureImage(GrContext* context, SkColorSpace* dstColorSpace, + GrMipMapped mipMapped) const { if (!context) { return nullptr; } if (GrContext* incumbent = as_IB(this)->context()) { - return incumbent == context ? sk_ref_sp(const_cast<SkImage*>(this)) : nullptr; + if (incumbent != context) { + return nullptr; + } + sk_sp<GrTextureProxy> proxy = as_IB(this)->asTextureProxyRef(); + SkASSERT(proxy); + if (GrMipMapped::kNo == mipMapped || proxy->mipMapped() == mipMapped) { + return sk_ref_sp(const_cast<SkImage*>(this)); + } + GrTextureAdjuster adjuster(context, std::move(proxy), this->alphaType(), + this->uniqueID(), this->colorSpace()); + return create_image_from_producer(context, &adjuster, this->alphaType(), + this->uniqueID(), dstColorSpace, mipMapped); } if (this->isLazyGenerated()) { GrImageTextureMaker maker(context, this, kDisallow_CachingHint); - return create_image_from_maker(context, &maker, this->alphaType(), - this->uniqueID(), dstColorSpace); + return create_image_from_producer(context, &maker, this->alphaType(), + this->uniqueID(), dstColorSpace, mipMapped); } if (const SkBitmap* bmp = as_IB(this)->onPeekBitmap()) { GrBitmapTextureMaker maker(context, *bmp); - return create_image_from_maker(context, &maker, this->alphaType(), - this->uniqueID(), dstColorSpace); + return create_image_from_producer(context, &maker, this->alphaType(), + this->uniqueID(), dstColorSpace, mipMapped); } return nullptr; } |