Add api for passing mipped hint into ImageGenerator onGenerateTexture

This does not actually add any additional functionality to the generators.
Once this lands I will enable the generators one at a time to more easily
monitor the effects of each one.

Bug: skia:
Change-Id: I382a1acfaebcbf9ad44c9873b87cdbbe02a13602
Reviewed-on: https://skia-review.googlesource.com/57083
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Greg Daniel <egdaniel@google.com>
This commit is contained in:
Greg Daniel 2017-10-09 09:57:35 -04:00 committed by Skia Commit-Bot
parent 1fc0909065
commit f88c12ea20
12 changed files with 30 additions and 18 deletions

View File

@ -165,7 +165,8 @@ public:
protected:
sk_sp<GrTextureProxy> onGenerateTexture(GrContext* ctx, const SkImageInfo& info,
const SkIPoint& origin,
SkTransferFunctionBehavior) override {
SkTransferFunctionBehavior,
bool willBeMipped) override {
SkASSERT(ctx);
SkASSERT(ctx == fCtx.get());

View File

@ -140,10 +140,16 @@ public:
* It must be non-NULL. The generator should only succeed if:
* - its internal context is the same
* - it can somehow convert its texture into one that is valid for the provided context.
*
* If the willNeedMipMaps flag is true, the generator should try to create a TextureProxy that
* at least has the mip levels allocated and the base layer filled in. If this is not possible,
* the generator is allowed to return a non mipped proxy, but this will have some additional
* overhead in later allocating mips and copying of the base layer.
*/
sk_sp<GrTextureProxy> generateTexture(GrContext*, const SkImageInfo& info,
const SkIPoint& origin,
SkTransferFunctionBehavior behavior);
SkTransferFunctionBehavior behavior,
bool willNeedMipMaps);
#endif
/**
@ -185,7 +191,8 @@ protected:
virtual TexGenType onCanGenerateTexture() const { return TexGenType::kNone; }
virtual sk_sp<GrTextureProxy> onGenerateTexture(GrContext*, const SkImageInfo&, const SkIPoint&,
SkTransferFunctionBehavior); // returns nullptr
SkTransferFunctionBehavior,
bool willNeedMipMaps); // returns nullptr
#endif
private:

View File

@ -64,7 +64,7 @@ bool SkColorSpaceXformImageGenerator::onGetPixels(const SkImageInfo& info, void*
sk_sp<GrTextureProxy> SkColorSpaceXformImageGenerator::onGenerateTexture(
GrContext* ctx, const SkImageInfo& info, const SkIPoint& origin,
SkTransferFunctionBehavior) {
SkTransferFunctionBehavior, bool willNeedMipMaps) {
// FIXME:
// This always operates as if SkTranferFunctionBehavior is kIgnore. Should we add
// options so that caller can also request kRespect?

View File

@ -23,7 +23,8 @@ protected:
#if SK_SUPPORT_GPU
sk_sp<GrTextureProxy> onGenerateTexture(GrContext*, const SkImageInfo&, const SkIPoint&,
SkTransferFunctionBehavior) override;
SkTransferFunctionBehavior,
bool willNeedMipMaps) override;
TexGenType onCanGenerateTexture() const override {
return TexGenType::kExpensive;
}

View File

@ -66,17 +66,19 @@ bool SkImageGenerator::getYUV8Planes(const SkYUVSizeInfo& sizeInfo, void* planes
sk_sp<GrTextureProxy> SkImageGenerator::generateTexture(GrContext* ctx, const SkImageInfo& info,
const SkIPoint& origin,
SkTransferFunctionBehavior behavior) {
SkTransferFunctionBehavior behavior,
bool willNeedMipMaps) {
SkIRect srcRect = SkIRect::MakeXYWH(origin.x(), origin.y(), info.width(), info.height());
if (!SkIRect::MakeWH(fInfo.width(), fInfo.height()).contains(srcRect)) {
return nullptr;
}
return this->onGenerateTexture(ctx, info, origin, behavior);
return this->onGenerateTexture(ctx, info, origin, behavior, willNeedMipMaps);
}
sk_sp<GrTextureProxy> SkImageGenerator::onGenerateTexture(GrContext*, const SkImageInfo&,
const SkIPoint&,
SkTransferFunctionBehavior) {
SkTransferFunctionBehavior,
bool willNeedMipMaps) {
return nullptr;
}
#endif

View File

@ -102,7 +102,7 @@ SkImageGenerator::MakeFromPicture(const SkISize& size, sk_sp<SkPicture> picture,
#if SK_SUPPORT_GPU
sk_sp<GrTextureProxy> SkPictureImageGenerator::onGenerateTexture(
GrContext* ctx, const SkImageInfo& info, const SkIPoint& origin,
SkTransferFunctionBehavior behavior) {
SkTransferFunctionBehavior behavior, bool willNeedMipMaps) {
SkASSERT(ctx);
bool useXformCanvas = SkTransferFunctionBehavior::kIgnore == behavior && info.colorSpace();

View File

@ -23,7 +23,8 @@ protected:
#if SK_SUPPORT_GPU
TexGenType onCanGenerateTexture() const override { return TexGenType::kExpensive; }
sk_sp<GrTextureProxy> onGenerateTexture(GrContext*, const SkImageInfo&, const SkIPoint&,
SkTransferFunctionBehavior) override;
SkTransferFunctionBehavior,
bool willNeedMipMaps) override;
#endif
private:

View File

@ -98,7 +98,7 @@ void GrAHardwareBufferImageGenerator::deleteImageTexture(void* context) {
sk_sp<GrTextureProxy> GrAHardwareBufferImageGenerator::onGenerateTexture(
GrContext* context, const SkImageInfo& info, const SkIPoint& origin,
SkTransferFunctionBehavior) {
SkTransferFunctionBehavior, bool willNeedMipMaps) {
auto proxy = this->makeProxy(context);
if (!proxy) {
return nullptr;

View File

@ -36,7 +36,8 @@ protected:
#if SK_SUPPORT_GPU
TexGenType onCanGenerateTexture() const override { return TexGenType::kCheap; }
sk_sp<GrTextureProxy> onGenerateTexture(GrContext*, const SkImageInfo&, const SkIPoint&,
SkTransferFunctionBehavior) override;
SkTransferFunctionBehavior,
bool willNeedMipMaps) override;
#endif
private:

View File

@ -118,7 +118,7 @@ void GrBackendTextureImageGenerator::ReleaseRefHelper_TextureReleaseProc(void* c
sk_sp<GrTextureProxy> GrBackendTextureImageGenerator::onGenerateTexture(
GrContext* context, const SkImageInfo& info, const SkIPoint& origin,
SkTransferFunctionBehavior) {
SkTransferFunctionBehavior, bool willNeedMipMaps) {
SkASSERT(context);
if (context->contextPriv().getBackend() != fBackendTexture.backend()) {

View File

@ -30,7 +30,8 @@ protected:
#if SK_SUPPORT_GPU
TexGenType onCanGenerateTexture() const override { return TexGenType::kCheap; }
sk_sp<GrTextureProxy> onGenerateTexture(GrContext*, const SkImageInfo&, const SkIPoint&,
SkTransferFunctionBehavior) override;
SkTransferFunctionBehavior,
bool willNeedMipMaps) override;
#endif
private:

View File

@ -788,10 +788,8 @@ sk_sp<GrTextureProxy> SkImage_Lazy::lockTextureProxy(GrContext* ctx,
SkImageGenerator::TexGenType::kCheap != generator->onCanGenerateTexture()) {
return nullptr;
}
// TODO: Pass a flag into generateTexture which says we want to be mipped. If the generator
// can handle creating a mipped surface, then it can either generate the base layer or all
// the layers directly. Otherwise it just returns a non mipped surface as it currently does.
if ((proxy = generator->generateTexture(ctx, genPixelsInfo, fOrigin, behavior))) {
if ((proxy = generator->generateTexture(ctx, genPixelsInfo, fOrigin, behavior,
willBeMipped))) {
SK_HISTOGRAM_ENUMERATION("LockTexturePath", kNative_LockTexturePath,
kLockTexturePathCount);
set_key_on_proxy(ctx->resourceProvider(), proxy.get(), nullptr, key);