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" |
| 10 |
9 #if SK_SUPPORT_GPU | 11 #if SK_SUPPORT_GPU |
10 #include "GrContextFactory.h" | 12 #include "GrContextFactory.h" |
11 #endif | 13 #endif |
12 #include "SkImage.h" | 14 #include "SkImage.h" |
13 #include "SkSurface.h" | 15 #include "SkSurface.h" |
| 16 #include "SkReadBuffer.h" |
| 17 #include "SkWriteBuffer.h" |
14 | 18 |
15 #include "Test.h" | 19 static void test_flatten(skiatest::Reporter* reporter, const SkImageInfo& info)
{ |
| 20 // just need a safe amount of storage |
| 21 char storage[sizeof(SkImageInfo)*2]; |
| 22 SkWriteBuffer wb(storage, sizeof(storage)); |
| 23 info.flatten(wb); |
| 24 SkASSERT(wb.bytesWritten() < sizeof(storage)); |
| 25 |
| 26 SkReadBuffer rb(storage, wb.bytesWritten()); |
| 27 SkImageInfo info2; |
| 28 |
| 29 // pick a noisy byte pattern, so we ensure that unflatten sets all of our fi
elds |
| 30 memset(&info2, 0xB8, sizeof(info2)); |
| 31 |
| 32 info2.unflatten(rb); |
| 33 REPORTER_ASSERT(reporter, rb.offset() == wb.bytesWritten()); |
| 34 REPORTER_ASSERT(reporter, info == info2); |
| 35 } |
| 36 |
| 37 DEF_TEST(ImageInfo_flattening, reporter) { |
| 38 for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) { |
| 39 for (int at = 0; at <= kLastEnum_SkAlphaType; ++at) { |
| 40 for (int pt = 0; pt <= kLastEnum_SkColorProfileType; ++pt) { |
| 41 SkImageInfo info = SkImageInfo::Make(100, 200, |
| 42 static_cast<SkColorType>(ct
), |
| 43 static_cast<SkAlphaType>(at
), |
| 44 static_cast<SkColorProfileT
ype>(pt)); |
| 45 test_flatten(reporter, info); |
| 46 } |
| 47 } |
| 48 } |
| 49 } |
16 | 50 |
17 static void check_isopaque(skiatest::Reporter* reporter, SkSurface* surface, boo
l expectedOpaque) { | 51 static void check_isopaque(skiatest::Reporter* reporter, SkSurface* surface, boo
l expectedOpaque) { |
18 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); | 52 SkAutoTUnref<SkImage> image(surface->newImageSnapshot()); |
19 REPORTER_ASSERT(reporter, image->isOpaque() == expectedOpaque); | 53 REPORTER_ASSERT(reporter, image->isOpaque() == expectedOpaque); |
20 } | 54 } |
21 | 55 |
22 DEF_TEST(ImageIsOpaqueTest, reporter) { | 56 DEF_TEST(ImageIsOpaqueTest, reporter) { |
23 SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5); | 57 SkImageInfo infoTransparent = SkImageInfo::MakeN32Premul(5, 5); |
24 SkAutoTUnref<SkSurface> surfaceTransparent(SkSurface::NewRaster(infoTranspar
ent)); | 58 SkAutoTUnref<SkSurface> surfaceTransparent(SkSurface::NewRaster(infoTranspar
ent)); |
25 check_isopaque(reporter, surfaceTransparent, false); | 59 check_isopaque(reporter, surfaceTransparent, false); |
(...skipping 26 matching lines...) Expand all Loading... |
52 SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType)
; | 86 SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType)
; |
53 SkAutoTUnref<SkSurface> surfaceOpaque(SkSurface::NewRenderTarget(context
, infoOpaque)); | 87 SkAutoTUnref<SkSurface> surfaceOpaque(SkSurface::NewRenderTarget(context
, infoOpaque)); |
54 #if 0 | 88 #if 0 |
55 // this is failing right now : TODO fix me | 89 // this is failing right now : TODO fix me |
56 check_isopaque(reporter, surfaceOpaque, true); | 90 check_isopaque(reporter, surfaceOpaque, true); |
57 #endif | 91 #endif |
58 } | 92 } |
59 } | 93 } |
60 | 94 |
61 #endif | 95 #endif |
OLD | NEW |