OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2016 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 | |
8 #include "ColorCodecBench.h" | |
9 #include "Resources.h" | |
10 #include "SkCodec.h" | |
11 #include "SkColorSpaceXform.h" | |
12 #include "SkCommandLineFlags.h" | |
13 | |
14 #if !defined(GOOGLE3) | |
scroggo
2016/06/02 18:51:50
nit: My general preference would be to have a sepa
msarett
2016/06/02 19:34:39
I'll follow up with this change - so I can fix it
| |
15 #include "qcms.h" | |
16 #endif | |
17 | |
18 #if !defined(GOOGLE3) | |
19 DEFINE_bool(qcms, false, "Bench qcms color conversion"); | |
20 #endif | |
21 DEFINE_bool(xform_only, false, "Only bench the color xform, do not include the d ecode time"); | |
scroggo
2016/06/02 18:51:50
nit: "bench" -> "time"
msarett
2016/06/02 19:34:39
Done.
| |
22 | |
23 ColorCodecBench::ColorCodecBench(const char* name, sk_sp<SkData> encoded) | |
24 : fEncoded(encoded) | |
25 { | |
26 fName.appendf("Color%s", FLAGS_xform_only ? "Xform" : "Codec"); | |
27 #if !defined(GOOGLE3) | |
28 fName.appendf("%s", FLAGS_qcms ? "QCMS" : ""); | |
29 #endif | |
30 fName.appendf("_%s", name); | |
31 } | |
32 | |
33 const char* ColorCodecBench::onGetName() { | |
34 return fName.c_str(); | |
35 } | |
36 | |
37 bool ColorCodecBench::isSuitableFor(Backend backend) { | |
38 return kNonRendering_Backend == backend; | |
39 } | |
40 | |
41 static void decode_and_xform(SkData* encoded, void* dst, void* srcRow, const SkI mageInfo& info, | |
42 SkData* dstProfile, SkData* srcProfile) { | |
43 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | |
44 #ifdef SK_DEBUG | |
45 const SkCodec::Result result = | |
46 #endif | |
47 codec->startScanlineDecode(info); | |
48 SkASSERT(SkCodec::kSuccess == result); | |
49 | |
50 sk_sp<SkColorSpace> srcSpace = sk_ref_sp(codec->getColorSpace()); | |
51 if (srcSpace) { | |
scroggo
2016/06/02 18:51:50
Should this be if (!srcSpace)?
msarett
2016/06/02 19:34:39
Yes! Good catch.
| |
52 srcSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); | |
53 } | |
54 sk_sp<SkColorSpace> dstSpace = SkColorSpace::NewICC(dstProfile->data(), dstP rofile->size()); | |
scroggo
2016/06/02 18:51:50
Do you want this to be part of the timing? Otherwi
msarett
2016/06/02 19:34:39
Good point, let's create this outside the loop.
| |
55 SkASSERT(dstSpace); | |
56 std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(srcSpace, dstSpace); | |
57 SkASSERT(xform); | |
58 | |
59 for (int y = 0; y < info.height(); y++) { | |
60 #ifdef SK_DEBUG | |
61 const int rows = | |
62 #endif | |
63 codec->getScanlines(srcRow, 1, 0); | |
64 SkASSERT(1 == rows); | |
65 | |
66 xform->xform_RGBA_8888((uint32_t*) dst, (uint32_t*) srcRow, info.width() ); | |
67 dst = SkTAddOffset<void>(dst, info.minRowBytes()); | |
68 } | |
69 } | |
70 | |
71 #if !defined(GOOGLE3) | |
72 static void decode_and_xform_qcms(SkData* encoded, void* dst, void* srcRow, cons t SkImageInfo& info, | |
73 SkData* dstProfile, SkData* srcProfile) { | |
74 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); | |
75 #ifdef SK_DEBUG | |
76 const SkCodec::Result result = | |
77 #endif | |
78 codec->startScanlineDecode(info); | |
79 SkASSERT(SkCodec::kSuccess == result); | |
80 | |
81 SkAutoTCallVProc<qcms_profile, qcms_profile_release> | |
82 srcSpace(qcms_profile_from_memory(srcProfile->data(), srcProfile->si ze())); | |
83 SkASSERT(srcSpace); | |
84 | |
85 SkAutoTCallVProc<qcms_profile, qcms_profile_release> | |
86 dstSpace(qcms_profile_from_memory(dstProfile->data(), dstProfile->si ze())); | |
87 SkASSERT(dstSpace); | |
88 SkAutoTCallVProc<qcms_transform, qcms_transform_release> | |
89 transform (qcms_transform_create(srcSpace, QCMS_DATA_RGBA_8, dstSpac e, | |
90 QCMS_DATA_RGBA_8, QCMS_INTENT_PERCE PTUAL)); | |
91 SkASSERT(transform); | |
92 | |
93 #ifdef SK_PMCOLOR_IS_RGBA | |
94 qcms_output_type outType = QCMS_OUTPUT_RGBX; | |
95 #else | |
96 qcms_output_type outType = QCMS_OUTPUT_BGRX; | |
97 #endif | |
98 | |
99 for (int y = 0; y < info.height(); y++) { | |
100 #ifdef SK_DEBUG | |
101 const int rows = | |
102 #endif | |
103 codec->getScanlines(srcRow, 1, 0); | |
104 SkASSERT(1 == rows); | |
105 | |
106 qcms_transform_data_type(transform, srcRow, dst, info.width(), outType); | |
107 dst = SkTAddOffset<void>(dst, info.minRowBytes()); | |
108 } | |
109 } | |
110 #endif | |
111 | |
112 static void xform_only(SkData* encoded, void* dst, void* srcRow, const SkImageIn fo& info, | |
scroggo
2016/06/02 18:51:49
nit: Maybe comment out srcRow, since you're not us
msarett
2016/06/02 19:34:39
Done.
| |
113 SkData* dstProfile, SkData* srcProfile) { | |
114 sk_sp<SkColorSpace> srcSpace = SkColorSpace::NewICC(srcProfile->data(), srcP rofile->size()); | |
115 if (srcSpace) { | |
scroggo
2016/06/02 18:51:50
!srcSpace
msarett
2016/06/02 19:34:39
Done.
| |
116 srcSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named); | |
117 } | |
118 sk_sp<SkColorSpace> dstSpace = SkColorSpace::NewICC(dstProfile->data(), dstP rofile->size()); | |
119 SkASSERT(dstSpace); | |
120 std::unique_ptr<SkColorSpaceXform> xform = SkColorSpaceXform::New(srcSpace, dstSpace); | |
121 SkASSERT(xform); | |
122 | |
123 for (int y = 0; y < info.height(); y++) { | |
124 // Transform in place | |
scroggo
2016/06/02 18:51:50
Why is this in place, but not some others?
msarett
2016/06/02 19:34:39
I decided to time the "xform only" benches in plac
scroggo
2016/06/02 20:42:31
Looking at this a little harder, won't the second
msarett
2016/06/02 22:17:47
You're right, I didn't think past the first loop i
| |
125 xform->xform_RGBA_8888((uint32_t*) dst, (uint32_t*) dst, info.width()); | |
126 dst = SkTAddOffset<void>(dst, info.minRowBytes()); | |
127 } | |
128 } | |
129 | |
130 #if !defined(GOOGLE3) | |
131 static void xform_only_qcms(SkData* encoded, void* dst, void* srcRow, const SkIm ageInfo& info, | |
132 SkData* dstProfile, SkData* srcProfile) { | |
133 SkAutoTCallVProc<qcms_profile, qcms_profile_release> | |
134 srcSpace(qcms_profile_from_memory(srcProfile->data(), srcProfile->si ze())); | |
135 SkASSERT(srcSpace); | |
136 | |
137 SkAutoTCallVProc<qcms_profile, qcms_profile_release> | |
138 dstSpace(qcms_profile_from_memory(dstProfile->data(), dstProfile->si ze())); | |
139 SkASSERT(dstSpace); | |
140 SkAutoTCallVProc<qcms_transform, qcms_transform_release> | |
141 transform (qcms_transform_create(srcSpace, QCMS_DATA_RGBA_8, dstSpac e, | |
142 QCMS_DATA_RGBA_8, QCMS_INTENT_PERCE PTUAL)); | |
143 SkASSERT(transform); | |
144 | |
145 #ifdef SK_PMCOLOR_IS_RGBA | |
146 qcms_output_type outType = QCMS_OUTPUT_RGBX; | |
147 #else | |
148 qcms_output_type outType = QCMS_OUTPUT_BGRX; | |
149 #endif | |
150 | |
151 for (int y = 0; y < info.height(); y++) { | |
152 // Transform in place | |
153 qcms_transform_data_type(transform, dst, dst, info.width(), outType); | |
154 dst = SkTAddOffset<void>(dst, info.minRowBytes()); | |
155 } | |
156 } | |
157 #endif | |
158 | |
159 void ColorCodecBench::onDelayedSetup() { | |
160 SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(fEncoded.get())); | |
161 fInfo = codec->getInfo().makeColorType(kRGBA_8888_SkColorType); | |
162 | |
163 fDst.reset(fInfo.getSafeSize(fInfo.minRowBytes())); | |
164 if (FLAGS_xform_only) { | |
165 codec->getPixels(fInfo, fDst.get(), fInfo.minRowBytes()); | |
166 } else { | |
167 // Set-up a row buffer to decode into before transforming to dst. | |
168 fSrcRow.reset(fInfo.minRowBytes()); | |
169 } | |
170 | |
171 fDstProfile = SkData::MakeFromFileName( | |
172 GetResourcePath("monitor_profiles/HP_ZR30w.icc").c_str()); | |
173 SkASSERT(fDstProfile); | |
174 fSrcProfile = codec->getICCData(); | |
175 | |
176 #if !defined(GOOGLE3) | |
177 if (FLAGS_qcms) { | |
178 fProc = FLAGS_xform_only ? xform_only_qcms : decode_and_xform_qcms; | |
179 } else | |
180 #endif | |
181 { | |
182 fProc = FLAGS_xform_only ? xform_only : decode_and_xform; | |
183 } | |
184 } | |
185 | |
186 void ColorCodecBench::onDraw(int n, SkCanvas* canvas) { | |
scroggo
2016/06/02 18:51:50
nit: no need for the name "canvas" here, which is
msarett
2016/06/02 19:34:39
Done.
| |
187 for (int i = 0; i < n; i++) { | |
188 fProc(fEncoded.get(), fDst.get(), fSrcRow.get(), fInfo, fDstProfile.get( ), | |
189 fSrcProfile.get()); | |
190 } | |
191 } | |
OLD | NEW |