diff options
author | 2016-01-30 10:01:40 -0800 | |
---|---|---|
committer | 2016-01-30 10:01:40 -0800 | |
commit | 8e74f80ca1bd32581a583e2325daf4b46d892ee5 (patch) | |
tree | dd5ada2bc987c8fd7843342b85c72dc102a64aa4 /tests | |
parent | 9cd016e9b63f3827580d5b19a187dbf26b8e1436 (diff) |
Add SkImage factory method that forces image to be resolved to a texture.
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1631053003
Review URL: https://codereview.chromium.org/1631053003
Diffstat (limited to 'tests')
-rw-r--r-- | tests/ImageTest.cpp | 76 |
1 files changed, 70 insertions, 6 deletions
diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 575fc1c287..1bf56c53a2 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -5,6 +5,9 @@ * found in the LICENSE file. */ +#include <functional> +#include "DMGpuSupport.h" + #include "SkBitmap.h" #include "SkCanvas.h" #include "SkData.h" @@ -21,12 +24,6 @@ #include "SkUtils.h" #include "Test.h" -#if SK_SUPPORT_GPU -#include "GrContext.h" -#include "gl/GrGLInterface.h" -#include "gl/GrGLUtil.h" -#endif - static void assert_equal(skiatest::Reporter* reporter, SkImage* a, const SkIRect* subsetA, SkImage* b) { const int widthA = subsetA ? subsetA->width() : a->width(); @@ -87,6 +84,15 @@ static SkImage* create_data_image() { SkAutoTUnref<SkData> data(create_image_data(&info)); return SkImage::NewRasterData(info, data, info.minRowBytes()); } +#if SK_SUPPORT_GPU // not gpu-specific but currently only used in GPU tests +static SkImage* create_picture_image() { + SkPictureRecorder recorder; + SkCanvas* canvas = recorder.beginRecording(10, 10); + canvas->clear(SK_ColorCYAN); + SkAutoTUnref<SkPicture> picture(recorder.endRecording()); + return SkImage::NewFromPicture(picture, SkISize::Make(10, 10), nullptr, nullptr); +}; +#endif // Want to ensure that our Release is called when the owning image is destroyed struct RasterDataHolder { RasterDataHolder() : fReleaseCount(0) {} @@ -376,6 +382,64 @@ DEF_GPUTEST_FOR_NATIVE_CONTEXT(SkImage_Gpu2Cpu, reporter, context) { REPORTER_ASSERT(reporter, !SkBitmapCache::Find(uniqueID, &cachedBitmap)); } } + +DEF_GPUTEST_FOR_NATIVE_CONTEXT(SkImage_newTextureImage, reporter, context, glContext) { + GrContextFactory otherFactory; + GrContextFactory::ContextInfo otherContextInfo = + otherFactory.getContextInfo(GrContextFactory::kNative_GLContextType); + glContext->makeCurrent(); + + std::function<SkImage*()> imageFactories[] = { + create_image, + create_codec_image, + create_data_image, + // Create an image from a picture. + create_picture_image, + // Create a texture image. + [context] { return create_gpu_image(context); }, + // Create a texture image in a another GrContext. + [glContext, otherContextInfo] { + otherContextInfo.fGLContext->makeCurrent(); + SkImage* otherContextImage = create_gpu_image(otherContextInfo.fGrContext); + glContext->makeCurrent(); + return otherContextImage; + } + }; + + for (auto factory : imageFactories) { + SkAutoTUnref<SkImage> image(factory()); + if (!image) { + ERRORF(reporter, "Error creating image."); + continue; + } + GrTexture* origTexture = as_IB(image)->peekTexture(); + + SkAutoTUnref<SkImage> texImage(image->newTextureImage(context)); + if (!texImage) { + // We execpt to fail if image comes from a different GrContext. + if (!origTexture || origTexture->getContext() == context) { + ERRORF(reporter, "newTextureImage failed."); + } + continue; + } + GrTexture* copyTexture = as_IB(texImage)->peekTexture(); + if (!copyTexture) { + ERRORF(reporter, "newTextureImage returned non-texture image."); + continue; + } + if (origTexture) { + if (origTexture != copyTexture) { + ERRORF(reporter, "newTextureImage made unnecessary texture copy."); + } + } + if (image->width() != texImage->width() || image->height() != texImage->height()) { + ERRORF(reporter, "newTextureImage changed the image size."); + } + if (image->isOpaque() != texImage->isOpaque()) { + ERRORF(reporter, "newTextureImage changed image opaqueness."); + } + } +} #endif // https://bug.skia.org/4390 |