Leon Scroggins III | 87caae6 | 2020-05-04 10:02:45 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2020 Google LLC |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | // Make sure SkUserConfig.h is included so #defines are available on |
| 9 | // Android. |
| 10 | #include "include/core/SkTypes.h" |
| 11 | #ifdef SK_ENABLE_ANDROID_UTILS |
| 12 | #include "client_utils/android/BitmapRegionDecoder.h" |
| 13 | #include "include/codec/SkAndroidCodec.h" |
| 14 | #include "include/codec/SkCodec.h" |
| 15 | #include "tests/Test.h" |
| 16 | #include "tools/Resources.h" |
| 17 | |
| 18 | DEF_TEST(BRD_types, r) { |
| 19 | static const struct { |
| 20 | const char* name; |
| 21 | bool supported; |
| 22 | } gRec[] = { |
| 23 | { "images/arrow.png", true }, |
| 24 | { "images/box.gif", false }, |
| 25 | { "images/baby_tux.webp", true }, |
| 26 | { "images/brickwork-texture.jpg", true }, |
| 27 | { "images/color_wheel.ico", false }, |
| 28 | #ifdef SK_CODEC_DECODES_RAW |
| 29 | { "images/sample_1mp.dng", false }, |
| 30 | #endif |
| 31 | { "images/mandrill.wbmp", false }, |
| 32 | { "images/randPixels.bmp", false }, |
| 33 | }; |
| 34 | |
| 35 | for (const auto& rec : gRec) { |
| 36 | auto data = GetResourceAsData(rec.name); |
| 37 | if (!data) return; |
| 38 | |
| 39 | REPORTER_ASSERT(r, SkCodec::MakeFromData(data) != nullptr); |
| 40 | REPORTER_ASSERT(r, SkAndroidCodec::MakeFromData(data) != nullptr); |
| 41 | |
| 42 | auto brd = android::skia::BitmapRegionDecoder::Make(data); |
| 43 | if (rec.supported) { |
| 44 | if (!brd) ERRORF(r, "Failed to create BRD from %s", rec.name); |
| 45 | } else { |
| 46 | if (brd) ERRORF(r, "Should *not* create BRD from %s", rec.name); |
| 47 | } |
| 48 | } |
| 49 | } |
| 50 | #endif // SK_ENABLE_ANDROID_UTILS |