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 "SkTypes.h" | 8 #include "SkTypes.h" |
9 #include "Test.h" | 9 #include "Test.h" |
10 | 10 |
11 #if SK_SUPPORT_GPU | 11 #if SK_SUPPORT_GPU |
12 #include "GrContext.h" | 12 #include "GrContext.h" |
13 #endif | 13 #endif |
14 #include "SkImage.h" | 14 #include "SkImage.h" |
15 #include "SkSurface.h" | 15 #include "SkSurface.h" |
16 #include "SkReadBuffer.h" | 16 #include "SkReadBuffer.h" |
17 #include "SkWriteBuffer.h" | 17 #include "SkWriteBuffer.h" |
18 | 18 |
19 static void test_flatten(skiatest::Reporter* reporter, const SkImageInfo& info)
{ | 19 static void test_flatten(skiatest::Reporter* reporter, const SkImageInfo& info)
{ |
20 // just need a safe amount of storage, but ensure that it is 4-byte aligned. | 20 // just need a safe amount of storage, but ensure that it is 4-byte aligned. |
21 int32_t storage[(sizeof(SkImageInfo)*2) / sizeof(int32_t)]; | 21 int32_t storage[(sizeof(SkImageInfo)*2) / sizeof(int32_t)]; |
22 SkBinaryWriteBuffer wb(storage, sizeof(storage)); | 22 SkBinaryWriteBuffer wb(storage, sizeof(storage)); |
23 info.flatten(wb); | 23 info.flatten(wb); |
24 SkASSERT(wb.bytesWritten() < sizeof(storage)); | 24 SkASSERT(wb.bytesWritten() < sizeof(storage)); |
25 | 25 |
26 SkReadBuffer rb(storage, wb.bytesWritten()); | 26 SkReadBuffer rb(storage, wb.bytesWritten()); |
27 | 27 |
28 // pick a noisy byte pattern, so we ensure that unflatten sets all of our fi
elds | 28 // pick a noisy byte pattern, so we ensure that unflatten sets all of our fi
elds |
29 SkImageInfo info2 = SkImageInfo::Make(0xB8, 0xB8, (SkColorType) 0xB8, (SkAlp
haType) 0xB8, | 29 SkImageInfo info2 = SkImageInfo::Make(0xB8, 0xB8, (SkColorType) 0xB8, (SkAlp
haType) 0xB8); |
30 (SkColorProfileType) 0xB8); | |
31 | 30 |
32 info2.unflatten(rb); | 31 info2.unflatten(rb); |
33 REPORTER_ASSERT(reporter, rb.offset() == wb.bytesWritten()); | 32 REPORTER_ASSERT(reporter, rb.offset() == wb.bytesWritten()); |
34 | 33 |
35 // FIXME (msarett): | 34 // FIXME (msarett): |
36 // Support flatten/unflatten of SkColorSpace objects. | 35 // Support flatten/unflatten of SkColorSpace objects. |
37 REPORTER_ASSERT(reporter, info.makeColorSpace(nullptr) == info2.makeColorSpa
ce(nullptr)); | 36 REPORTER_ASSERT(reporter, info.makeColorSpace(nullptr) == info2.makeColorSpa
ce(nullptr)); |
38 } | 37 } |
39 | 38 |
40 DEF_TEST(ImageInfo_flattening, reporter) { | 39 DEF_TEST(ImageInfo_flattening, reporter) { |
| 40 sk_sp<SkColorSpace> spaces[] = { |
| 41 nullptr, |
| 42 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named), |
| 43 SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named), |
| 44 }; |
| 45 |
41 for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) { | 46 for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) { |
42 for (int at = 0; at <= kLastEnum_SkAlphaType; ++at) { | 47 for (int at = 0; at <= kLastEnum_SkAlphaType; ++at) { |
43 for (int pt = 0; pt <= kLastEnum_SkColorProfileType; ++pt) { | 48 for (auto& cs : spaces) { |
44 SkImageInfo info = SkImageInfo::Make(100, 200, | 49 SkImageInfo info = SkImageInfo::Make(100, 200, |
45 static_cast<SkColorType>(ct
), | 50 static_cast<SkColorType>(ct
), |
46 static_cast<SkAlphaType>(at
), | 51 static_cast<SkAlphaType>(at
), |
47 static_cast<SkColorProfileT
ype>(pt)); | 52 cs); |
48 test_flatten(reporter, info); | 53 test_flatten(reporter, info); |
49 } | 54 } |
50 } | 55 } |
51 } | 56 } |
52 } | 57 } |
53 | 58 |
54 static void check_isopaque(skiatest::Reporter* reporter, const sk_sp<SkSurface>&
surface, | 59 static void check_isopaque(skiatest::Reporter* reporter, const sk_sp<SkSurface>&
surface, |
55 bool expectedOpaque) { | 60 bool expectedOpaque) { |
56 sk_sp<SkImage> image(surface->makeImageSnapshot()); | 61 sk_sp<SkImage> image(surface->makeImageSnapshot()); |
57 REPORTER_ASSERT(reporter, image->isOpaque() == expectedOpaque); | 62 REPORTER_ASSERT(reporter, image->isOpaque() == expectedOpaque); |
(...skipping 17 matching lines...) Expand all Loading... |
75 auto surfaceTransparent(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo
, infoTransparent)); | 80 auto surfaceTransparent(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo
, infoTransparent)); |
76 check_isopaque(reporter, surfaceTransparent, false); | 81 check_isopaque(reporter, surfaceTransparent, false); |
77 | 82 |
78 SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType); | 83 SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType); |
79 auto surfaceOpaque(SkSurface::MakeRenderTarget(context,SkBudgeted::kNo, info
Opaque)); | 84 auto surfaceOpaque(SkSurface::MakeRenderTarget(context,SkBudgeted::kNo, info
Opaque)); |
80 | 85 |
81 check_isopaque(reporter, surfaceOpaque, true); | 86 check_isopaque(reporter, surfaceOpaque, true); |
82 } | 87 } |
83 | 88 |
84 #endif | 89 #endif |
OLD | NEW |