aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Greg Daniel <egdaniel@google.com>2018-06-12 16:39:59 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-13 13:55:56 +0000
commit5f4b09d523a761a3a5c622bb01eeba47905da5f0 (patch)
tree899574a311503375d911ee6486894eb921138550 /tests
parented8ed91ec8c0eb523262eb7bb91558399c7e591f (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 'tests')
-rw-r--r--tests/ImageTest.cpp80
1 files changed, 47 insertions, 33 deletions
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<SkImage> create_codec_image() {
sk_sp<SkData> src(sk_tool_utils::EncodeImageToData(bitmap, SkEncodedImageFormat::kPNG, 100));
return SkImage::MakeFromEncoded(std::move(src));
}
-static sk_sp<SkImage> create_gpu_image(GrContext* context) {
+static sk_sp<SkImage> 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<SkImage> image(factory());
- if (!image) {
- ERRORF(reporter, "Error creating image.");
- continue;
- }
+ for (auto mipMapped : {GrMipMapped::kNo, GrMipMapped::kYes}) {
+ for (auto factory : imageFactories) {
+ sk_sp<SkImage> image(factory());
+ if (!image) {
+ ERRORF(reporter, "Error creating image.");
+ continue;
+ }
- sk_sp<SkImage> texImage(image->makeTextureImage(context, dstColorSpace.get()));
- if (!texImage) {
- GrContext* imageContext = as_IB(image)->context();
+ sk_sp<SkImage> 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();
}
}