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
DEF_TEST(BRD_types,r)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 #if defined(SK_CODEC_DECODES_ICO)
28 {"images/color_wheel.ico", false},
29 #endif
30 #if defined(SK_CODEC_DECODES_RAW)
31 {"images/sample_1mp.dng", false},
32 #endif
33 {"images/mandrill.wbmp", false},
34 {"images/randPixels.bmp", false},
35 };
36
37 for (const auto& rec : gRec) {
38 skiatest::ReporterContext context(r, rec.name);
39 auto data = GetResourceAsData(rec.name);
40 if (!data) return;
41
42 REPORTER_ASSERT(r, SkCodec::MakeFromData(data) != nullptr);
43 REPORTER_ASSERT(r, SkAndroidCodec::MakeFromData(data) != nullptr);
44
45 auto brd = android::skia::BitmapRegionDecoder::Make(data);
46 if (rec.supported) {
47 if (!brd) ERRORF(r, "Failed to create BRD from %s", rec.name);
48 } else {
49 if (brd) ERRORF(r, "Should *not* create BRD from %s", rec.name);
50 }
51 }
52 }
53 #endif // SK_ENABLE_ANDROID_UTILS
54