2014-07-21 18:37:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2015-07-09 18:47:36 +00:00
|
|
|
#include "SkData.h"
|
2017-05-16 14:39:06 +00:00
|
|
|
#include "SkCanvas.h"
|
2018-10-18 18:36:59 +00:00
|
|
|
|
2015-07-09 18:47:36 +00:00
|
|
|
#include "SkGraphics.h"
|
2014-07-21 18:37:39 +00:00
|
|
|
#include "SkImageGenerator.h"
|
2018-02-09 18:26:46 +00:00
|
|
|
#include "SkImageInfoPriv.h"
|
2018-10-18 18:36:59 +00:00
|
|
|
#include "SkYUVAIndex.h"
|
2014-07-21 18:37:39 +00:00
|
|
|
#include "Test.h"
|
|
|
|
|
2018-06-25 18:01:29 +00:00
|
|
|
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
|
|
|
|
#include "SkImageGeneratorCG.h"
|
|
|
|
#elif defined(SK_BUILD_FOR_WIN)
|
|
|
|
#include "SkImageGeneratorWIC.h"
|
|
|
|
#endif
|
|
|
|
|
2015-07-09 21:08:49 +00:00
|
|
|
static bool gMyFactoryWasCalled;
|
|
|
|
|
2017-02-15 20:14:16 +00:00
|
|
|
static std::unique_ptr<SkImageGenerator> my_factory(sk_sp<SkData>) {
|
2015-07-09 21:08:49 +00:00
|
|
|
gMyFactoryWasCalled = true;
|
2015-08-27 14:41:13 +00:00
|
|
|
return nullptr;
|
2015-07-09 18:47:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void test_imagegenerator_factory(skiatest::Reporter* reporter) {
|
2015-07-09 21:08:49 +00:00
|
|
|
// just need a non-empty data to test things
|
2016-08-02 21:40:46 +00:00
|
|
|
sk_sp<SkData> data(SkData::MakeWithCString("test_imagegenerator_factory"));
|
2015-07-09 21:08:49 +00:00
|
|
|
|
|
|
|
gMyFactoryWasCalled = false;
|
2015-07-09 18:47:36 +00:00
|
|
|
|
2015-07-09 21:08:49 +00:00
|
|
|
REPORTER_ASSERT(reporter, !gMyFactoryWasCalled);
|
2015-07-09 18:47:36 +00:00
|
|
|
|
2017-02-15 20:14:16 +00:00
|
|
|
std::unique_ptr<SkImageGenerator> gen = SkImageGenerator::MakeFromEncoded(data);
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == gen);
|
2015-07-09 21:08:49 +00:00
|
|
|
REPORTER_ASSERT(reporter, !gMyFactoryWasCalled);
|
2015-07-09 18:47:36 +00:00
|
|
|
|
|
|
|
// Test is racy, in that it hopes no other thread is changing this global...
|
2017-02-15 20:14:16 +00:00
|
|
|
auto prev = SkGraphics::SetImageGeneratorFromEncodedDataFactory(my_factory);
|
|
|
|
gen = SkImageGenerator::MakeFromEncoded(data);
|
2015-08-27 14:41:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, nullptr == gen);
|
2015-07-09 21:08:49 +00:00
|
|
|
REPORTER_ASSERT(reporter, gMyFactoryWasCalled);
|
2018-06-25 18:01:29 +00:00
|
|
|
|
|
|
|
// This just verifies that the signatures match.
|
|
|
|
#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
|
|
|
|
SkGraphics::SetImageGeneratorFromEncodedDataFactory(SkImageGeneratorCG::MakeFromEncodedCG);
|
|
|
|
#elif defined(SK_BUILD_FOR_WIN)
|
|
|
|
SkGraphics::SetImageGeneratorFromEncodedDataFactory(SkImageGeneratorWIC::MakeFromEncodedWIC);
|
|
|
|
#endif
|
|
|
|
|
2017-02-15 20:14:16 +00:00
|
|
|
SkGraphics::SetImageGeneratorFromEncodedDataFactory(prev);
|
2015-07-09 18:47:36 +00:00
|
|
|
}
|
|
|
|
|
2015-03-19 15:31:14 +00:00
|
|
|
class MyImageGenerator : public SkImageGenerator {
|
|
|
|
public:
|
|
|
|
MyImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(0, 0)) {}
|
|
|
|
};
|
|
|
|
|
2014-07-21 18:37:39 +00:00
|
|
|
DEF_TEST(ImageGenerator, reporter) {
|
2015-03-19 15:31:14 +00:00
|
|
|
MyImageGenerator ig;
|
2018-10-29 20:26:02 +00:00
|
|
|
SkYUVASizeInfo sizeInfo;
|
2018-10-18 18:36:59 +00:00
|
|
|
sizeInfo.fSizes[0] = SkISize::Make(200, 200);
|
|
|
|
sizeInfo.fSizes[1] = SkISize::Make(100, 100);
|
|
|
|
sizeInfo.fSizes[2] = SkISize::Make( 50, 50);
|
|
|
|
sizeInfo.fSizes[3] = SkISize::Make( 25, 25);
|
|
|
|
sizeInfo.fWidthBytes[0] = 0;
|
|
|
|
sizeInfo.fWidthBytes[1] = 0;
|
|
|
|
sizeInfo.fWidthBytes[2] = 0;
|
|
|
|
sizeInfo.fWidthBytes[3] = 0;
|
|
|
|
void* planes[4] = { nullptr };
|
|
|
|
SkYUVAIndex yuvaIndices[4];
|
2014-09-13 00:45:58 +00:00
|
|
|
SkYUVColorSpace colorSpace;
|
2014-07-21 18:37:39 +00:00
|
|
|
|
|
|
|
// Check that the YUV decoding API does not cause any crashes
|
2018-10-18 18:36:59 +00:00
|
|
|
ig.queryYUVA8(&sizeInfo, yuvaIndices, nullptr);
|
|
|
|
ig.queryYUVA8(&sizeInfo, yuvaIndices, &colorSpace);
|
|
|
|
sizeInfo.fWidthBytes[0] = 250;
|
|
|
|
sizeInfo.fWidthBytes[1] = 250;
|
|
|
|
sizeInfo.fWidthBytes[2] = 250;
|
|
|
|
sizeInfo.fWidthBytes[3] = 250;
|
|
|
|
yuvaIndices[0] = { 0, SkColorChannel::kR };
|
|
|
|
yuvaIndices[1] = { 1, SkColorChannel::kR };
|
|
|
|
yuvaIndices[2] = { 2, SkColorChannel::kR };
|
|
|
|
yuvaIndices[3] = { 3, SkColorChannel::kR };
|
2014-07-21 18:37:39 +00:00
|
|
|
int dummy;
|
2018-10-18 18:36:59 +00:00
|
|
|
planes[0] = planes[1] = planes[2] = planes[3] = &dummy;
|
|
|
|
ig.getYUVA8Planes(sizeInfo, yuvaIndices, planes);
|
2015-07-09 18:47:36 +00:00
|
|
|
|
2015-09-14 21:51:04 +00:00
|
|
|
// Suppressed due to https://code.google.com/p/skia/issues/detail?id=4339
|
|
|
|
if (false) {
|
|
|
|
test_imagegenerator_factory(reporter);
|
|
|
|
}
|
2014-07-21 18:37:39 +00:00
|
|
|
}
|
2017-04-13 19:13:36 +00:00
|
|
|
|
|
|
|
#include "SkAutoMalloc.h"
|
|
|
|
#include "SkPictureRecorder.h"
|
|
|
|
|
|
|
|
static sk_sp<SkPicture> make_picture() {
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
recorder.beginRecording(100, 100)->drawColor(SK_ColorRED);
|
|
|
|
return recorder.finishRecordingAsPicture();
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(PictureImageGenerator, reporter) {
|
|
|
|
const struct {
|
|
|
|
SkColorType fColorType;
|
|
|
|
SkAlphaType fAlphaType;
|
|
|
|
} recs[] = {
|
2018-10-10 17:20:38 +00:00
|
|
|
{ kRGBA_8888_SkColorType, kPremul_SkAlphaType },
|
|
|
|
{ kBGRA_8888_SkColorType, kPremul_SkAlphaType },
|
|
|
|
{ kRGBA_F16_SkColorType, kPremul_SkAlphaType },
|
|
|
|
{ kRGBA_F32_SkColorType, kPremul_SkAlphaType },
|
|
|
|
{ kRGBA_1010102_SkColorType, kPremul_SkAlphaType },
|
|
|
|
|
|
|
|
{ kRGBA_8888_SkColorType, kUnpremul_SkAlphaType },
|
|
|
|
{ kBGRA_8888_SkColorType, kUnpremul_SkAlphaType },
|
|
|
|
{ kRGBA_F16_SkColorType, kUnpremul_SkAlphaType },
|
|
|
|
{ kRGBA_F32_SkColorType, kUnpremul_SkAlphaType },
|
|
|
|
{ kRGBA_1010102_SkColorType, kUnpremul_SkAlphaType },
|
2017-04-13 19:13:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto colorspace = SkColorSpace::MakeSRGB();
|
|
|
|
auto picture = make_picture();
|
|
|
|
auto gen = SkImageGenerator::MakeFromPicture({100, 100}, picture, nullptr, nullptr,
|
|
|
|
SkImage::BitDepth::kU8, colorspace);
|
|
|
|
|
|
|
|
// worst case for all requests
|
2018-06-26 15:43:06 +00:00
|
|
|
SkAutoMalloc storage(100 * 100 * SkColorTypeBytesPerPixel(kRGBA_F32_SkColorType));
|
2017-04-13 19:13:36 +00:00
|
|
|
|
|
|
|
for (const auto& rec : recs) {
|
|
|
|
SkImageInfo info = SkImageInfo::Make(100, 100, rec.fColorType, rec.fAlphaType, colorspace);
|
2018-10-10 17:20:38 +00:00
|
|
|
REPORTER_ASSERT(reporter, gen->getPixels(info, storage.get(), info.minRowBytes()));
|
2017-04-13 19:13:36 +00:00
|
|
|
}
|
|
|
|
}
|
2017-06-08 13:37:01 +00:00
|
|
|
|