| 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 "Resources.h" |
| 9 #include "Test.h" | 10 #include "Test.h" |
| 10 | 11 |
| 11 #if SK_SUPPORT_GPU | 12 #if SK_SUPPORT_GPU |
| 12 #include "GrContext.h" | 13 #include "GrContext.h" |
| 13 #endif | 14 #endif |
| 14 #include "SkImage.h" | 15 #include "SkImage.h" |
| 15 #include "SkSurface.h" | 16 #include "SkSurface.h" |
| 16 #include "SkReadBuffer.h" | 17 #include "SkReadBuffer.h" |
| 17 #include "SkWriteBuffer.h" | 18 #include "SkWriteBuffer.h" |
| 18 | 19 |
| 19 static void test_flatten(skiatest::Reporter* reporter, const SkImageInfo& info)
{ | 20 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. | 21 // Need a safe amount of 4-byte aligned storage. Note that one of the test
ICC profiles |
| 21 int32_t storage[(sizeof(SkImageInfo)*2) / sizeof(int32_t)]; | 22 // is ~7500 bytes. |
| 22 SkBinaryWriteBuffer wb(storage, sizeof(storage)); | 23 const size_t storageBytes = 8000; |
| 24 SkAutoTMalloc<uint32_t> storage(storageBytes / sizeof(uint32_t)); |
| 25 SkBinaryWriteBuffer wb(storage.get(), storageBytes); |
| 23 info.flatten(wb); | 26 info.flatten(wb); |
| 24 SkASSERT(wb.bytesWritten() < sizeof(storage)); | 27 SkASSERT(wb.bytesWritten() < storageBytes); |
| 25 | 28 |
| 26 SkReadBuffer rb(storage, wb.bytesWritten()); | 29 SkReadBuffer rb(storage.get(), wb.bytesWritten()); |
| 27 | 30 |
| 28 // pick a noisy byte pattern, so we ensure that unflatten sets all of our fi
elds | 31 // 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); | 32 SkImageInfo info2 = SkImageInfo::Make(0xB8, 0xB8, (SkColorType) 0xB8, (SkAlp
haType) 0xB8); |
| 30 | 33 |
| 31 info2.unflatten(rb); | 34 info2.unflatten(rb); |
| 32 REPORTER_ASSERT(reporter, rb.offset() == wb.bytesWritten()); | 35 REPORTER_ASSERT(reporter, rb.offset() == wb.bytesWritten()); |
| 33 | 36 |
| 34 REPORTER_ASSERT(reporter, info == info2); | 37 REPORTER_ASSERT(reporter, info == info2); |
| 35 } | 38 } |
| 36 | 39 |
| 37 DEF_TEST(ImageInfo_flattening, reporter) { | 40 DEF_TEST(ImageInfo_flattening, reporter) { |
| 41 sk_sp<SkData> data = |
| 42 SkData::MakeFromFileName(GetResourcePath("icc_profiles/HP_ZR30w.icc
").c_str()); |
| 43 sk_sp<SkColorSpace> space0 = SkColorSpace::NewICC(data->data(), data->size()
); |
| 44 data = SkData::MakeFromFileName( GetResourcePath("icc_profiles/HP_Z32x.icc")
.c_str()); |
| 45 sk_sp<SkColorSpace> space1 = SkColorSpace::NewICC(data->data(), data->size()
); |
| 46 data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperLeft.icc"
).c_str()); |
| 47 sk_sp<SkColorSpace> space2 = SkColorSpace::NewICC(data->data(), data->size()
); |
| 48 data = SkData::MakeFromFileName(GetResourcePath("icc_profiles/upperRight.icc
").c_str()); |
| 49 sk_sp<SkColorSpace> space3 = SkColorSpace::NewICC(data->data(), data->size()
); |
| 50 |
| 38 sk_sp<SkColorSpace> spaces[] = { | 51 sk_sp<SkColorSpace> spaces[] = { |
| 39 nullptr, | 52 nullptr, |
| 40 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named), | 53 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named), |
| 41 SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named), | 54 SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named), |
| 55 space0, |
| 56 space1, |
| 57 space2, |
| 58 space3, |
| 42 }; | 59 }; |
| 43 | 60 |
| 44 for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) { | 61 for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) { |
| 45 for (int at = 0; at <= kLastEnum_SkAlphaType; ++at) { | 62 for (int at = 0; at <= kLastEnum_SkAlphaType; ++at) { |
| 46 for (auto& cs : spaces) { | 63 for (auto& cs : spaces) { |
| 47 SkImageInfo info = SkImageInfo::Make(100, 200, | 64 SkImageInfo info = SkImageInfo::Make(100, 200, |
| 48 static_cast<SkColorType>(ct
), | 65 static_cast<SkColorType>(ct
), |
| 49 static_cast<SkAlphaType>(at
), | 66 static_cast<SkAlphaType>(at
), |
| 50 cs); | 67 cs); |
| 51 test_flatten(reporter, info); | 68 test_flatten(reporter, info); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 78 auto surfaceTransparent(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo
, infoTransparent)); | 95 auto surfaceTransparent(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo
, infoTransparent)); |
| 79 check_isopaque(reporter, surfaceTransparent, false); | 96 check_isopaque(reporter, surfaceTransparent, false); |
| 80 | 97 |
| 81 SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType); | 98 SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType); |
| 82 auto surfaceOpaque(SkSurface::MakeRenderTarget(context,SkBudgeted::kNo, info
Opaque)); | 99 auto surfaceOpaque(SkSurface::MakeRenderTarget(context,SkBudgeted::kNo, info
Opaque)); |
| 83 | 100 |
| 84 check_isopaque(reporter, surfaceOpaque, true); | 101 check_isopaque(reporter, surfaceOpaque, true); |
| 85 } | 102 } |
| 86 | 103 |
| 87 #endif | 104 #endif |
| OLD | NEW |