From 5f4b09d523a761a3a5c622bb01eeba47905da5f0 Mon Sep 17 00:00:00 2001 From: Greg Daniel Date: Tue, 12 Jun 2018 16:39:59 -0400 Subject: 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 Reviewed-by: Eric Karl Reviewed-by: Cary Clark Reviewed-by: Brian Salomon --- tests/ImageTest.cpp | 80 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 47 insertions(+), 33 deletions(-) (limited to 'tests/ImageTest.cpp') diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 930d7c0c86..dc7576acad 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -147,9 +147,10 @@ static sk_sp create_codec_image() { sk_sp src(sk_tool_utils::EncodeImageToData(bitmap, SkEncodedImageFormat::kPNG, 100)); return SkImage::MakeFromEncoded(std::move(src)); } -static sk_sp create_gpu_image(GrContext* context) { +static sk_sp create_gpu_image(GrContext* context, bool withMips = false) { const SkImageInfo info = SkImageInfo::MakeN32(20, 20, kOpaque_SkAlphaType); - auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info)); + auto surface(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo, info, 0, + kBottomLeft_GrSurfaceOrigin, nullptr, withMips)); draw_image_test_pattern(surface->getCanvas()); return surface->makeImageSnapshot(); } @@ -385,6 +386,8 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeTextureImage, reporter, contextIn create_picture_image, // Create a texture image. [context] { return create_gpu_image(context); }, + // Create a texture image with mips + //[context] { return create_gpu_image(context, true); }, // Create a texture image in a another GrContext. [otherContextInfo] { auto restore = otherContextInfo.testContext()->makeCurrentAndAutoRestore(); @@ -400,43 +403,54 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkImage_makeTextureImage, reporter, contextIn }; for (auto& dstColorSpace : dstColorSpaces) { - for (auto factory : imageFactories) { - sk_sp image(factory()); - if (!image) { - ERRORF(reporter, "Error creating image."); - continue; - } + for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) { + for (auto factory : imageFactories) { + sk_sp image(factory()); + if (!image) { + ERRORF(reporter, "Error creating image."); + continue; + } - sk_sp texImage(image->makeTextureImage(context, dstColorSpace.get())); - if (!texImage) { - GrContext* imageContext = as_IB(image)->context(); + sk_sp texImage(image->makeTextureImage(context, dstColorSpace.get(), + mipMapped)); + if (!texImage) { + GrContext* imageContext = as_IB(image)->context(); - // We expect to fail if image comes from a different GrContext. - if (!image->isTextureBacked() || imageContext == context) { - ERRORF(reporter, "makeTextureImage failed."); + // We expect to fail if image comes from a different GrContext. + if (!image->isTextureBacked() || imageContext == context) { + ERRORF(reporter, "makeTextureImage failed."); + } + continue; } - continue; - } - if (!texImage->isTextureBacked()) { - ERRORF(reporter, "makeTextureImage returned non-texture image."); - continue; - } - if (image->isTextureBacked()) { - GrSurfaceProxy* origProxy = as_IB(image)->peekProxy(); - GrSurfaceProxy* copyProxy = as_IB(texImage)->peekProxy(); - - if (origProxy->underlyingUniqueID() != copyProxy->underlyingUniqueID()) { - ERRORF(reporter, "makeTextureImage made unnecessary texture copy."); + if (!texImage->isTextureBacked()) { + ERRORF(reporter, "makeTextureImage returned non-texture image."); + continue; + } + if (GrMipMapped::kYes == mipMapped && + as_IB(texImage)->peekProxy()->mipMapped() != mipMapped) { + ERRORF(reporter, "makeTextureImage returned non-mipmapped texture."); + continue; + } + if (image->isTextureBacked()) { + GrSurfaceProxy* origProxy = as_IB(image)->peekProxy(); + GrSurfaceProxy* copyProxy = as_IB(texImage)->peekProxy(); + + if (origProxy->underlyingUniqueID() != copyProxy->underlyingUniqueID()) { + SkASSERT(origProxy->asTextureProxy()); + if (GrMipMapped::kNo == mipMapped || + GrMipMapped::kYes == origProxy->asTextureProxy()->mipMapped()) { + ERRORF(reporter, "makeTextureImage made unnecessary texture copy."); + } + } + } + if (image->width() != texImage->width() || image->height() != texImage->height()) { + ERRORF(reporter, "makeTextureImage changed the image size."); + } + if (image->alphaType() != texImage->alphaType()) { + ERRORF(reporter, "makeTextureImage changed image alpha type."); } - } - if (image->width() != texImage->width() || image->height() != texImage->height()) { - ERRORF(reporter, "makeTextureImage changed the image size."); - } - if (image->alphaType() != texImage->alphaType()) { - ERRORF(reporter, "makeTextureImage changed image alpha type."); } } - context->flush(); } } -- cgit v1.2.3