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" | |
9 #include "SkGraphics.h" | |
8 #include "SkImageGenerator.h" | 10 #include "SkImageGenerator.h" |
9 #include "Test.h" | 11 #include "Test.h" |
10 | 12 |
13 static SkImageGenerator* my_factory(SkData* data) { | |
14 int* ptr = *(int**)data->data(); | |
15 *ptr = 1; // signal that we were called | |
16 return NULL; | |
17 } | |
18 | |
19 static void test_imagegenerator_factory(skiatest::Reporter* reporter) { | |
scroggo
2015/07/09 19:01:15
Why not make this its own test, with DEF_TEST?
reed1
2015/07/09 19:05:45
Just style difference. When I see the output from
| |
20 int factoryHasBeenCalled = 0; | |
21 int* sentinelPtr = &factoryHasBeenCalled; | |
22 SkData* data = SkData::NewWithCopy(&sentinelPtr, sizeof(sentinelPtr)); | |
23 | |
24 SkImageGenerator* gen; | |
25 REPORTER_ASSERT(reporter, 0 == *sentinelPtr); | |
26 | |
27 gen = SkImageGenerator::NewFromEncoded(data); | |
28 REPORTER_ASSERT(reporter, NULL == gen); | |
29 REPORTER_ASSERT(reporter, 0 == *sentinelPtr); | |
30 | |
31 // Test is racy, in that it hopes no other thread is changing this global... | |
32 SkGraphics::ImageGeneratorFromEncodedFactory prev = | |
33 SkGraphics::GetImageGeneratorFro mEncodedFactory(); | |
34 SkGraphics::SetImageGeneratorFromEncodedFactory(my_factory); | |
35 gen = SkImageGenerator::NewFromEncoded(data); | |
36 REPORTER_ASSERT(reporter, NULL == gen); | |
37 REPORTER_ASSERT(reporter, 1 == *sentinelPtr); | |
38 SkGraphics::SetImageGeneratorFromEncodedFactory(prev); | |
39 } | |
40 | |
11 class MyImageGenerator : public SkImageGenerator { | 41 class MyImageGenerator : public SkImageGenerator { |
12 public: | 42 public: |
13 MyImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(0, 0)) {} | 43 MyImageGenerator() : SkImageGenerator(SkImageInfo::MakeN32Premul(0, 0)) {} |
14 }; | 44 }; |
15 | 45 |
16 DEF_TEST(ImageGenerator, reporter) { | 46 DEF_TEST(ImageGenerator, reporter) { |
17 MyImageGenerator ig; | 47 MyImageGenerator ig; |
18 SkISize sizes[3]; | 48 SkISize sizes[3]; |
19 sizes[0] = SkISize::Make(200, 200); | 49 sizes[0] = SkISize::Make(200, 200); |
20 sizes[1] = SkISize::Make(100, 100); | 50 sizes[1] = SkISize::Make(100, 100); |
21 sizes[2] = SkISize::Make( 50, 50); | 51 sizes[2] = SkISize::Make( 50, 50); |
22 void* planes[3] = { NULL }; | 52 void* planes[3] = { NULL }; |
23 size_t rowBytes[3] = { 0 }; | 53 size_t rowBytes[3] = { 0 }; |
24 SkYUVColorSpace colorSpace; | 54 SkYUVColorSpace colorSpace; |
25 | 55 |
26 // Check that the YUV decoding API does not cause any crashes | 56 // Check that the YUV decoding API does not cause any crashes |
27 ig.getYUV8Planes(sizes, NULL, NULL, &colorSpace); | 57 ig.getYUV8Planes(sizes, NULL, NULL, &colorSpace); |
28 ig.getYUV8Planes(sizes, NULL, NULL, NULL); | 58 ig.getYUV8Planes(sizes, NULL, NULL, NULL); |
29 ig.getYUV8Planes(sizes, planes, NULL, NULL); | 59 ig.getYUV8Planes(sizes, planes, NULL, NULL); |
30 ig.getYUV8Planes(sizes, NULL, rowBytes, NULL); | 60 ig.getYUV8Planes(sizes, NULL, rowBytes, NULL); |
31 ig.getYUV8Planes(sizes, planes, rowBytes, NULL); | 61 ig.getYUV8Planes(sizes, planes, rowBytes, NULL); |
32 ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace); | 62 ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace); |
33 | 63 |
34 int dummy; | 64 int dummy; |
35 planes[0] = planes[1] = planes[2] = &dummy; | 65 planes[0] = planes[1] = planes[2] = &dummy; |
36 rowBytes[0] = rowBytes[1] = rowBytes[2] = 250; | 66 rowBytes[0] = rowBytes[1] = rowBytes[2] = 250; |
37 | 67 |
38 ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace); | 68 ig.getYUV8Planes(sizes, planes, rowBytes, &colorSpace); |
69 | |
70 test_imagegenerator_factory(reporter); | |
39 } | 71 } |
OLD | NEW |