OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "ColorCodecBench.h" | 8 #include "ColorCodecBench.h" |
9 #include "Resources.h" | 9 #include "Resources.h" |
10 #include "SkCodec.h" | 10 #include "SkCodec.h" |
11 #include "SkColorSpaceXform.h" | 11 #include "SkColorSpaceXform.h" |
12 #include "SkCommandLineFlags.h" | 12 #include "SkCommandLineFlags.h" |
13 | 13 |
14 #if defined(SK_TEST_QCMS) | 14 #if defined(SK_TEST_QCMS) |
15 DEFINE_bool(qcms, false, "Bench qcms color conversion"); | 15 DEFINE_bool(qcms, false, "Bench qcms color conversion"); |
16 #endif | 16 #endif |
17 DEFINE_bool(xform_only, false, "Only time the color xform, do not include the de
code time"); | 17 DEFINE_bool(xform_only, false, "Only time the color xform, do not include the de
code time"); |
18 DEFINE_bool(srgb, false, "Convert to srgb dst space"); | 18 DEFINE_bool(srgb, false, "Convert to srgb dst space"); |
| 19 DEFINE_bool(half, false, "Convert to half floats"); |
19 | 20 |
20 ColorCodecBench::ColorCodecBench(const char* name, sk_sp<SkData> encoded) | 21 ColorCodecBench::ColorCodecBench(const char* name, sk_sp<SkData> encoded) |
21 : fEncoded(std::move(encoded)) | 22 : fEncoded(std::move(encoded)) |
22 #if defined(SK_TEST_QCMS) | 23 #if defined(SK_TEST_QCMS) |
23 , fDstSpaceQCMS(nullptr) | 24 , fDstSpaceQCMS(nullptr) |
24 #endif | 25 #endif |
25 { | 26 { |
26 fName.appendf("Color%s", FLAGS_xform_only ? "Xform" : "Codec"); | 27 fName.appendf("Color%s", FLAGS_xform_only ? "Xform" : "Codec"); |
27 #if defined(SK_TEST_QCMS) | 28 #if defined(SK_TEST_QCMS) |
28 fName.appendf("%s", FLAGS_qcms ? "QCMS" : ""); | 29 fName.appendf("%s", FLAGS_qcms ? "QCMS" : ""); |
29 #endif | 30 #endif |
30 fName.appendf("_%s", name); | 31 fName.appendf("_%s", name); |
31 } | 32 } |
32 | 33 |
33 const char* ColorCodecBench::onGetName() { | 34 const char* ColorCodecBench::onGetName() { |
34 return fName.c_str(); | 35 return fName.c_str(); |
35 } | 36 } |
36 | 37 |
37 bool ColorCodecBench::isSuitableFor(Backend backend) { | 38 bool ColorCodecBench::isSuitableFor(Backend backend) { |
38 return kNonRendering_Backend == backend; | 39 return kNonRendering_Backend == backend; |
39 } | 40 } |
40 | 41 |
41 void ColorCodecBench::decodeAndXform() { | 42 void ColorCodecBench::decodeAndXform() { |
42 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fEncoded.get())); | 43 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fEncoded.get())); |
43 #ifdef SK_DEBUG | 44 #ifdef SK_DEBUG |
44 const SkCodec::Result result = | 45 const SkCodec::Result result = |
45 #endif | 46 #endif |
46 codec->startScanlineDecode(fInfo); | 47 codec->startScanlineDecode(fSrcInfo); |
47 SkASSERT(SkCodec::kSuccess == result); | 48 SkASSERT(SkCodec::kSuccess == result); |
48 | 49 |
49 sk_sp<SkColorSpace> srcSpace = sk_ref_sp(codec->getColorSpace()); | 50 sk_sp<SkColorSpace> srcSpace = sk_ref_sp(codec->getColorSpace()); |
50 if (!srcSpace) { | 51 if (!srcSpace) { |
51 srcSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); | 52 srcSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
52 } | 53 } |
53 std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(srcSpace,
fDstSpace); | 54 std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(srcSpace,
fDstSpace); |
54 SkASSERT(xform); | 55 SkASSERT(xform); |
55 | 56 |
56 void* dst = fDst.get(); | 57 void* dst = fDst.get(); |
57 for (int y = 0; y < fInfo.height(); y++) { | 58 for (int y = 0; y < fSrcInfo.height(); y++) { |
58 #ifdef SK_DEBUG | 59 #ifdef SK_DEBUG |
59 const int rows = | 60 const int rows = |
60 #endif | 61 #endif |
61 codec->getScanlines(fSrc.get(), 1, 0); | 62 codec->getScanlines(fSrc.get(), 1, 0); |
62 SkASSERT(1 == rows); | 63 SkASSERT(1 == rows); |
63 | 64 |
64 xform->applyTo8888((SkPMColor*) dst, (uint32_t*) fSrc.get(), fInfo.width
()); | 65 FLAGS_half ? |
65 dst = SkTAddOffset<void>(dst, fInfo.minRowBytes()); | 66 xform->applyToF16((uint64_t*) dst, (uint32_t*) fSrc.get(), fSrcI
nfo.width()) : |
| 67 xform->applyTo8888((SkPMColor*) dst, (uint32_t*) fSrc.get(), fSr
cInfo.width()); |
| 68 dst = SkTAddOffset<void>(dst, fDstInfo.minRowBytes()); |
66 } | 69 } |
67 } | 70 } |
68 | 71 |
69 #if defined(SK_TEST_QCMS) | 72 #if defined(SK_TEST_QCMS) |
70 void ColorCodecBench::decodeAndXformQCMS() { | 73 void ColorCodecBench::decodeAndXformQCMS() { |
71 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fEncoded.get())); | 74 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fEncoded.get())); |
72 #ifdef SK_DEBUG | 75 #ifdef SK_DEBUG |
73 const SkCodec::Result result = | 76 const SkCodec::Result result = |
74 #endif | 77 #endif |
75 codec->startScanlineDecode(fInfo); | 78 codec->startScanlineDecode(fSrcInfo); |
76 SkASSERT(SkCodec::kSuccess == result); | 79 SkASSERT(SkCodec::kSuccess == result); |
77 | 80 |
78 SkAutoTCallVProc<qcms_profile, qcms_profile_release> | 81 SkAutoTCallVProc<qcms_profile, qcms_profile_release> |
79 srcSpace(qcms_profile_from_memory(fSrcData->data(), fSrcData->size()
)); | 82 srcSpace(qcms_profile_from_memory(fSrcData->data(), fSrcData->size()
)); |
80 SkASSERT(srcSpace); | 83 SkASSERT(srcSpace); |
81 | 84 |
82 SkAutoTCallVProc<qcms_transform, qcms_transform_release> | 85 SkAutoTCallVProc<qcms_transform, qcms_transform_release> |
83 transform (qcms_transform_create(srcSpace, QCMS_DATA_RGBA_8, fDstSpa
ceQCMS.get(), | 86 transform (qcms_transform_create(srcSpace, QCMS_DATA_RGBA_8, fDstSpa
ceQCMS.get(), |
84 QCMS_DATA_RGBA_8, QCMS_INTENT_PERCE
PTUAL)); | 87 QCMS_DATA_RGBA_8, QCMS_INTENT_PERCE
PTUAL)); |
85 SkASSERT(transform); | 88 SkASSERT(transform); |
86 | 89 |
87 #ifdef SK_PMCOLOR_IS_RGBA | 90 #ifdef SK_PMCOLOR_IS_RGBA |
88 qcms_output_type outType = QCMS_OUTPUT_RGBX; | 91 qcms_output_type outType = QCMS_OUTPUT_RGBX; |
89 #else | 92 #else |
90 qcms_output_type outType = QCMS_OUTPUT_BGRX; | 93 qcms_output_type outType = QCMS_OUTPUT_BGRX; |
91 #endif | 94 #endif |
92 | 95 |
93 void* dst = fDst.get(); | 96 void* dst = fDst.get(); |
94 for (int y = 0; y < fInfo.height(); y++) { | 97 for (int y = 0; y < fSrcInfo.height(); y++) { |
95 #ifdef SK_DEBUG | 98 #ifdef SK_DEBUG |
96 const int rows = | 99 const int rows = |
97 #endif | 100 #endif |
98 codec->getScanlines(fSrc.get(), 1, 0); | 101 codec->getScanlines(fSrc.get(), 1, 0); |
99 SkASSERT(1 == rows); | 102 SkASSERT(1 == rows); |
100 | 103 |
101 qcms_transform_data_type(transform, fSrc.get(), dst, fInfo.width(), outT
ype); | 104 qcms_transform_data_type(transform, fSrc.get(), dst, fSrcInfo.width(), o
utType); |
102 dst = SkTAddOffset<void>(dst, fInfo.minRowBytes()); | 105 dst = SkTAddOffset<void>(dst, fDstInfo.minRowBytes()); |
103 } | 106 } |
104 } | 107 } |
105 #endif | 108 #endif |
106 | 109 |
107 void ColorCodecBench::xformOnly() { | 110 void ColorCodecBench::xformOnly() { |
108 sk_sp<SkColorSpace> srcSpace = SkColorSpace::NewICC(fSrcData->data(), fSrcDa
ta->size()); | 111 sk_sp<SkColorSpace> srcSpace = SkColorSpace::NewICC(fSrcData->data(), fSrcDa
ta->size()); |
109 if (!srcSpace) { | 112 if (!srcSpace) { |
110 srcSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); | 113 srcSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); |
111 } | 114 } |
112 std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(srcSpace,
fDstSpace); | 115 std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(srcSpace,
fDstSpace); |
113 SkASSERT(xform); | 116 SkASSERT(xform); |
114 | 117 |
115 void* dst = fDst.get(); | 118 void* dst = fDst.get(); |
116 void* src = fSrc.get(); | 119 void* src = fSrc.get(); |
117 for (int y = 0; y < fInfo.height(); y++) { | 120 for (int y = 0; y < fSrcInfo.height(); y++) { |
118 // Transform in place | 121 // Transform in place |
119 xform->applyTo8888((SkPMColor*) dst, (uint32_t*) src, fInfo.width()); | 122 FLAGS_half ? |
120 dst = SkTAddOffset<void>(dst, fInfo.minRowBytes()); | 123 xform->applyToF16((uint64_t*) dst, (uint32_t*) src, fSrcInfo.wid
th()) : |
121 src = SkTAddOffset<void>(src, fInfo.minRowBytes()); | 124 xform->applyTo8888((SkPMColor*) dst, (uint32_t*) src, fSrcInfo.w
idth()); |
| 125 dst = SkTAddOffset<void>(dst, fDstInfo.minRowBytes()); |
| 126 src = SkTAddOffset<void>(src, fSrcInfo.minRowBytes()); |
122 } | 127 } |
123 } | 128 } |
124 | 129 |
125 #if defined(SK_TEST_QCMS) | 130 #if defined(SK_TEST_QCMS) |
126 void ColorCodecBench::xformOnlyQCMS() { | 131 void ColorCodecBench::xformOnlyQCMS() { |
127 SkAutoTCallVProc<qcms_profile, qcms_profile_release> | 132 SkAutoTCallVProc<qcms_profile, qcms_profile_release> |
128 srcSpace(qcms_profile_from_memory(fSrcData->data(), fSrcData->size()
)); | 133 srcSpace(qcms_profile_from_memory(fSrcData->data(), fSrcData->size()
)); |
129 SkASSERT(srcSpace); | 134 SkASSERT(srcSpace); |
130 | 135 |
131 SkAutoTCallVProc<qcms_transform, qcms_transform_release> | 136 SkAutoTCallVProc<qcms_transform, qcms_transform_release> |
132 transform (qcms_transform_create(srcSpace, QCMS_DATA_RGBA_8, fDstSpa
ceQCMS.get(), | 137 transform (qcms_transform_create(srcSpace, QCMS_DATA_RGBA_8, fDstSpa
ceQCMS.get(), |
133 QCMS_DATA_RGBA_8, QCMS_INTENT_PERCE
PTUAL)); | 138 QCMS_DATA_RGBA_8, QCMS_INTENT_PERCE
PTUAL)); |
134 SkASSERT(transform); | 139 SkASSERT(transform); |
135 | 140 |
136 #ifdef SK_PMCOLOR_IS_RGBA | 141 #ifdef SK_PMCOLOR_IS_RGBA |
137 qcms_output_type outType = QCMS_OUTPUT_RGBX; | 142 qcms_output_type outType = QCMS_OUTPUT_RGBX; |
138 #else | 143 #else |
139 qcms_output_type outType = QCMS_OUTPUT_BGRX; | 144 qcms_output_type outType = QCMS_OUTPUT_BGRX; |
140 #endif | 145 #endif |
141 | 146 |
142 void* dst = fDst.get(); | 147 void* dst = fDst.get(); |
143 void* src = fSrc.get(); | 148 void* src = fSrc.get(); |
144 for (int y = 0; y < fInfo.height(); y++) { | 149 for (int y = 0; y < fSrcInfo.height(); y++) { |
145 // Transform in place | 150 // Transform in place |
146 qcms_transform_data_type(transform, src, dst, fInfo.width(), outType); | 151 qcms_transform_data_type(transform, src, dst, fSrcInfo.width(), outType)
; |
147 dst = SkTAddOffset<void>(dst, fInfo.minRowBytes()); | 152 dst = SkTAddOffset<void>(dst, fDstInfo.minRowBytes()); |
148 src = SkTAddOffset<void>(src, fInfo.minRowBytes()); | 153 src = SkTAddOffset<void>(src, fSrcInfo.minRowBytes()); |
149 } | 154 } |
150 } | 155 } |
151 #endif | 156 #endif |
152 | 157 |
153 void ColorCodecBench::onDelayedSetup() { | 158 void ColorCodecBench::onDelayedSetup() { |
154 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fEncoded.get())); | 159 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fEncoded.get())); |
155 fInfo = codec->getInfo().makeColorType(kRGBA_8888_SkColorType); | 160 fSrcInfo = codec->getInfo().makeColorType(kRGBA_8888_SkColorType); |
156 | 161 |
157 fDst.reset(fInfo.getSafeSize(fInfo.minRowBytes())); | 162 fDstInfo = fSrcInfo; |
| 163 if (FLAGS_half) { |
| 164 fDstInfo = fDstInfo.makeColorType(kRGBA_F16_SkColorType); |
| 165 } |
| 166 fDst.reset(fDstInfo.getSafeSize(fDstInfo.minRowBytes())); |
| 167 |
158 if (FLAGS_xform_only) { | 168 if (FLAGS_xform_only) { |
159 fSrc.reset(fInfo.getSafeSize(fInfo.minRowBytes())); | 169 fSrc.reset(fSrcInfo.getSafeSize(fSrcInfo.minRowBytes())); |
160 codec->getPixels(fInfo, fSrc.get(), fInfo.minRowBytes()); | 170 codec->getPixels(fSrcInfo, fSrc.get(), fSrcInfo.minRowBytes()); |
161 } else { | 171 } else { |
162 // Set-up a row buffer to decode into before transforming to dst. | 172 // Set-up a row buffer to decode into before transforming to dst. |
163 fSrc.reset(fInfo.minRowBytes()); | 173 fSrc.reset(fSrcInfo.minRowBytes()); |
164 } | 174 } |
165 | 175 |
166 fSrcData = codec->getICCData(); | 176 fSrcData = codec->getICCData(); |
167 sk_sp<SkData> dstData = SkData::MakeFromFileName( | 177 sk_sp<SkData> dstData = SkData::MakeFromFileName( |
168 GetResourcePath("monitor_profiles/HP_ZR30w.icc").c_str()); | 178 GetResourcePath("monitor_profiles/HP_ZR30w.icc").c_str()); |
169 SkASSERT(dstData); | 179 SkASSERT(dstData); |
170 | 180 |
171 | 181 |
172 #if defined(SK_TEST_QCMS) | 182 #if defined(SK_TEST_QCMS) |
173 if (FLAGS_qcms) { | 183 if (FLAGS_qcms) { |
174 fDstSpaceQCMS.reset(FLAGS_srgb ? | 184 fDstSpaceQCMS.reset(FLAGS_srgb ? |
175 qcms_profile_sRGB() : | 185 qcms_profile_sRGB() : |
176 qcms_profile_from_memory(dstData->data(), dstData->size())); | 186 qcms_profile_from_memory(dstData->data(), dstData->size())); |
177 SkASSERT(fDstSpaceQCMS); | 187 SkASSERT(fDstSpaceQCMS); |
178 | 188 |
179 // This call takes a non-trivial amount of time, but I think it's the mo
st fair to | 189 // This call takes a non-trivial amount of time, but I think it's the mo
st fair to |
180 // treat it as overhead. It only needs to happen once. | 190 // treat it as overhead. It only needs to happen once. |
181 qcms_profile_precache_output_transform(fDstSpaceQCMS); | 191 qcms_profile_precache_output_transform(fDstSpaceQCMS); |
182 } else | 192 } else |
183 #endif | 193 #endif |
184 { | 194 { |
185 fDstSpace = FLAGS_srgb ? SkColorSpace::NewNamed(SkColorSpace::kSRGB_Name
d) : | 195 fDstSpace = FLAGS_srgb ? SkColorSpace::NewNamed(SkColorSpace::kSRGB_Name
d) : |
186 SkColorSpace::NewICC(dstData->data(), dstData->
size()); | 196 SkColorSpace::NewICC(dstData->data(), dstData->
size()); |
187 SkASSERT(fDstSpace); | 197 SkASSERT(fDstSpace); |
188 } | 198 } |
189 } | 199 } |
190 | 200 |
191 void ColorCodecBench::onDraw(int n, SkCanvas*) { | 201 void ColorCodecBench::onDraw(int n, SkCanvas*) { |
| 202 if ((FLAGS_srgb || FLAGS_qcms) && FLAGS_half) { |
| 203 SkDebugf("Error: Contradicting flags.\n"); |
| 204 return; |
| 205 } |
| 206 |
192 for (int i = 0; i < n; i++) { | 207 for (int i = 0; i < n; i++) { |
193 #if defined(SK_TEST_QCMS) | 208 #if defined(SK_TEST_QCMS) |
194 if (FLAGS_qcms) { | 209 if (FLAGS_qcms) { |
195 if (FLAGS_xform_only) { | 210 if (FLAGS_xform_only) { |
196 this->xformOnlyQCMS(); | 211 this->xformOnlyQCMS(); |
197 } else { | 212 } else { |
198 this->decodeAndXformQCMS(); | 213 this->decodeAndXformQCMS(); |
199 } | 214 } |
200 } else | 215 } else |
201 #endif | 216 #endif |
202 { | 217 { |
203 if (FLAGS_xform_only) { | 218 if (FLAGS_xform_only) { |
204 this->xformOnly(); | 219 this->xformOnly(); |
205 } else { | 220 } else { |
206 this->decodeAndXform(); | 221 this->decodeAndXform(); |
207 } | 222 } |
208 } | 223 } |
209 } | 224 } |
210 } | 225 } |
OLD | NEW |