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"
|
|
|
|
#include "SkGraphics.h"
|
2014-07-21 18:37:39 +00:00
|
|
|
#include "SkImageGenerator.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
2015-07-09 21:08:49 +00:00
|
|
|
static bool gMyFactoryWasCalled;
|
|
|
|
|
|
|
|
static SkImageGenerator* my_factory(SkData*) {
|
|
|
|
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
|
2015-07-09 22:41:11 +00:00
|
|
|
SkAutoTUnref<SkData> data(SkData::NewWithCString("test_imagegenerator_factory"));
|
2015-07-09 21:08:49 +00:00
|
|
|
|
|
|
|
gMyFactoryWasCalled = false;
|
2015-07-09 18:47:36 +00:00
|
|
|
|
|
|
|
SkImageGenerator* gen;
|
2015-07-09 21:08:49 +00:00
|
|
|
REPORTER_ASSERT(reporter, !gMyFactoryWasCalled);
|
2015-07-09 18:47:36 +00:00
|
|
|
|
|
|
|
gen = SkImageGenerator::NewFromEncoded(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...
|
|
|
|
SkGraphics::ImageGeneratorFromEncodedFactory prev =
|
2015-07-09 21:08:49 +00:00
|
|
|
SkGraphics::SetImageGeneratorFromEncodedFactory(my_factory);
|
2015-07-09 18:47:36 +00:00
|
|
|
gen = SkImageGenerator::NewFromEncoded(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
|
|
|
SkGraphics::SetImageGeneratorFromEncodedFactory(prev);
|
|
|
|
}
|
|
|
|
|
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;
|
2016-03-07 17:16:52 +00:00
|
|
|
SkISize sizes[3];
|
|
|
|
sizes[0] = SkISize::Make(200, 200);
|
|
|
|
sizes[1] = SkISize::Make(100, 100);
|
|
|
|
sizes[2] = SkISize::Make( 50, 50);
|
|
|
|
void* planes[3] = { nullptr };
|
|
|
|
size_t rowBytes[3] = { 0 };
|
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
|
2016-03-07 17:16:52 +00:00
|
|
|
ig.getYUV8Planes(sizes, nullptr, nullptr, &colorSpace);
|
|
|
|
ig.getYUV8Planes(sizes, nullptr, nullptr, nullptr);
|
|
|
|
ig.getYUV8Planes(sizes, planes, nullptr, nullptr);
|
|
|
|
ig.getYUV8Planes(sizes, nullptr, rowBytes, nullptr);
|
|
|
|
ig.getYUV8Planes(sizes, planes, rowBytes, nullptr);
|
|
|
|
ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace);
|
|
|
|
|
2014-07-21 18:37:39 +00:00
|
|
|
int dummy;
|
2016-03-07 17:16:52 +00:00
|
|
|
planes[0] = planes[1] = planes[2] = &dummy;
|
|
|
|
rowBytes[0] = rowBytes[1] = rowBytes[2] = 250;
|
|
|
|
|
|
|
|
ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace);
|
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
|
|
|
}
|