Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: tests/ImageIsOpaqueTest.cpp

Issue 2085653003: Enable flattening and unflattening of SkColorSpace (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« src/core/SkColorSpace_Base.h ('K') | « src/core/SkImageInfo.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 REPORTER_ASSERT(reporter, info == info2);
36 // Support flatten/unflatten of SkColorSpace objects.
37 REPORTER_ASSERT(reporter, info.makeColorSpace(nullptr) == info2.makeColorSpa ce(nullptr));
38 } 35 }
39 36
40 DEF_TEST(ImageInfo_flattening, reporter) { 37 DEF_TEST(ImageInfo_flattening, reporter) {
38 sk_sp<SkColorSpace> spaces[] = {
39 nullptr,
40 SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named),
41 SkColorSpace::NewNamed(SkColorSpace::kAdobeRGB_Named),
42
43 // FIXME (msarett):
44 // We should test more complicated color spaces here. Right now we use a pointer
45 // comparison to check if color spaces are equal, so == only works on th e most
46 // basic profiles.
47 };
48
41 for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) { 49 for (int ct = 0; ct <= kLastEnum_SkColorType; ++ct) {
42 for (int at = 0; at <= kLastEnum_SkAlphaType; ++at) { 50 for (int at = 0; at <= kLastEnum_SkAlphaType; ++at) {
43 for (int pt = 0; pt <= kLastEnum_SkColorProfileType; ++pt) { 51 for (auto& cs : spaces) {
44 SkImageInfo info = SkImageInfo::Make(100, 200, 52 SkImageInfo info = SkImageInfo::Make(100, 200,
45 static_cast<SkColorType>(ct ), 53 static_cast<SkColorType>(ct ),
46 static_cast<SkAlphaType>(at ), 54 static_cast<SkAlphaType>(at ),
47 static_cast<SkColorProfileT ype>(pt)); 55 cs);
48 test_flatten(reporter, info); 56 test_flatten(reporter, info);
49 } 57 }
50 } 58 }
51 } 59 }
52 } 60 }
53 61
54 static void check_isopaque(skiatest::Reporter* reporter, const sk_sp<SkSurface>& surface, 62 static void check_isopaque(skiatest::Reporter* reporter, const sk_sp<SkSurface>& surface,
55 bool expectedOpaque) { 63 bool expectedOpaque) {
56 sk_sp<SkImage> image(surface->makeImageSnapshot()); 64 sk_sp<SkImage> image(surface->makeImageSnapshot());
57 REPORTER_ASSERT(reporter, image->isOpaque() == expectedOpaque); 65 REPORTER_ASSERT(reporter, image->isOpaque() == expectedOpaque);
(...skipping 17 matching lines...) Expand all
75 auto surfaceTransparent(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo , infoTransparent)); 83 auto surfaceTransparent(SkSurface::MakeRenderTarget(context, SkBudgeted::kNo , infoTransparent));
76 check_isopaque(reporter, surfaceTransparent, false); 84 check_isopaque(reporter, surfaceTransparent, false);
77 85
78 SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType); 86 SkImageInfo infoOpaque = SkImageInfo::MakeN32(5, 5, kOpaque_SkAlphaType);
79 auto surfaceOpaque(SkSurface::MakeRenderTarget(context,SkBudgeted::kNo, info Opaque)); 87 auto surfaceOpaque(SkSurface::MakeRenderTarget(context,SkBudgeted::kNo, info Opaque));
80 88
81 check_isopaque(reporter, surfaceOpaque, true); 89 check_isopaque(reporter, surfaceOpaque, true);
82 } 90 }
83 91
84 #endif 92 #endif
OLDNEW
« src/core/SkColorSpace_Base.h ('K') | « src/core/SkImageInfo.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698