| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkData.h" | 8 #include "SkData.h" |
| 9 #include "SkGraphics.h" | 9 #include "SkGraphics.h" |
| 10 #include "SkImageGenerator.h" | 10 #include "SkImageGenerator.h" |
| 11 #include "Test.h" | 11 #include "Test.h" |
| 12 | 12 |
| 13 static bool gMyFactoryWasCalled; | 13 static bool gMyFactoryWasCalled; |
| 14 | 14 |
| 15 static SkImageGenerator* my_factory(SkData*) { | 15 static SkImageGenerator* my_factory(SkData*) { |
| 16 gMyFactoryWasCalled = true; | 16 gMyFactoryWasCalled = true; |
| 17 return NULL; | 17 return nullptr; |
| 18 } | 18 } |
| 19 | 19 |
| 20 static void test_imagegenerator_factory(skiatest::Reporter* reporter) { | 20 static void test_imagegenerator_factory(skiatest::Reporter* reporter) { |
| 21 // just need a non-empty data to test things | 21 // just need a non-empty data to test things |
| 22 SkAutoTUnref<SkData> data(SkData::NewWithCString("test_imagegenerator_factor
y")); | 22 SkAutoTUnref<SkData> data(SkData::NewWithCString("test_imagegenerator_factor
y")); |
| 23 | 23 |
| 24 gMyFactoryWasCalled = false; | 24 gMyFactoryWasCalled = false; |
| 25 | 25 |
| 26 SkImageGenerator* gen; | 26 SkImageGenerator* gen; |
| 27 REPORTER_ASSERT(reporter, !gMyFactoryWasCalled); | 27 REPORTER_ASSERT(reporter, !gMyFactoryWasCalled); |
| 28 | 28 |
| 29 gen = SkImageGenerator::NewFromEncoded(data); | 29 gen = SkImageGenerator::NewFromEncoded(data); |
| 30 REPORTER_ASSERT(reporter, NULL == gen); | 30 REPORTER_ASSERT(reporter, nullptr == gen); |
| 31 REPORTER_ASSERT(reporter, !gMyFactoryWasCalled); | 31 REPORTER_ASSERT(reporter, !gMyFactoryWasCalled); |
| 32 | 32 |
| 33 // Test is racy, in that it hopes no other thread is changing this global... | 33 // Test is racy, in that it hopes no other thread is changing this global... |
| 34 SkGraphics::ImageGeneratorFromEncodedFactory prev = | 34 SkGraphics::ImageGeneratorFromEncodedFactory prev = |
| 35 SkGraphics::SetImageGeneratorFromEncodedFact
ory(my_factory); | 35 SkGraphics::SetImageGeneratorFromEncodedFact
ory(my_factory); |
| 36 gen = SkImageGenerator::NewFromEncoded(data); | 36 gen = SkImageGenerator::NewFromEncoded(data); |
| 37 REPORTER_ASSERT(reporter, NULL == gen); | 37 REPORTER_ASSERT(reporter, nullptr == gen); |
| 38 REPORTER_ASSERT(reporter, gMyFactoryWasCalled); | 38 REPORTER_ASSERT(reporter, gMyFactoryWasCalled); |
| 39 SkGraphics::SetImageGeneratorFromEncodedFactory(prev); | 39 SkGraphics::SetImageGeneratorFromEncodedFactory(prev); |
| 40 } | 40 } |
| 41 | 41 |
| 42 class MyImageGenerator : public SkImageGenerator { | 42 class MyImageGenerator : public SkImageGenerator { |
| 43 public: | 43 public: |
| 44 MyImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(0, 0)) {} | 44 MyImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(0, 0)) {} |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 DEF_TEST(ImageGenerator, reporter) { | 47 DEF_TEST(ImageGenerator, reporter) { |
| 48 MyImageGenerator ig; | 48 MyImageGenerator ig; |
| 49 SkISize sizes[3]; | 49 SkISize sizes[3]; |
| 50 sizes[0] = SkISize::Make(200, 200); | 50 sizes[0] = SkISize::Make(200, 200); |
| 51 sizes[1] = SkISize::Make(100, 100); | 51 sizes[1] = SkISize::Make(100, 100); |
| 52 sizes[2] = SkISize::Make( 50, 50); | 52 sizes[2] = SkISize::Make( 50, 50); |
| 53 void* planes[3] = { NULL }; | 53 void* planes[3] = { nullptr }; |
| 54 size_t rowBytes[3] = { 0 }; | 54 size_t rowBytes[3] = { 0 }; |
| 55 SkYUVColorSpace colorSpace; | 55 SkYUVColorSpace colorSpace; |
| 56 | 56 |
| 57 // Check that the YUV decoding API does not cause any crashes | 57 // Check that the YUV decoding API does not cause any crashes |
| 58 ig.getYUV8Planes(sizes, NULL, NULL, &colorSpace); | 58 ig.getYUV8Planes(sizes, nullptr, nullptr, &colorSpace); |
| 59 ig.getYUV8Planes(sizes, NULL, NULL, NULL); | 59 ig.getYUV8Planes(sizes, nullptr, nullptr, nullptr); |
| 60 ig.getYUV8Planes(sizes, planes, NULL, NULL); | 60 ig.getYUV8Planes(sizes, planes, nullptr, nullptr); |
| 61 ig.getYUV8Planes(sizes, NULL, rowBytes, NULL); | 61 ig.getYUV8Planes(sizes, nullptr, rowBytes, nullptr); |
| 62 ig.getYUV8Planes(sizes, planes, rowBytes, NULL); | 62 ig.getYUV8Planes(sizes, planes, rowBytes, nullptr); |
| 63 ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace); | 63 ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace); |
| 64 | 64 |
| 65 int dummy; | 65 int dummy; |
| 66 planes[0] = planes[1] = planes[2] = &dummy; | 66 planes[0] = planes[1] = planes[2] = &dummy; |
| 67 rowBytes[0] = rowBytes[1] = rowBytes[2] = 250; | 67 rowBytes[0] = rowBytes[1] = rowBytes[2] = 250; |
| 68 | 68 |
| 69 ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace); | 69 ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace); |
| 70 | 70 |
| 71 test_imagegenerator_factory(reporter); | 71 test_imagegenerator_factory(reporter); |
| 72 } | 72 } |
| OLD | NEW |