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

Side by Side Diff: skia/ext/convolver_unittest.cc

Issue 1540963004: Switch to standard integer types in skia/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: missed some Created 4 years, 12 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stdint.h>
5 #include <string.h> 6 #include <string.h>
6 #include <time.h> 7 #include <time.h>
7 #include <algorithm> 8 #include <algorithm>
8 #include <numeric> 9 #include <numeric>
9 #include <vector> 10 #include <vector>
10 11
11 #include "base/basictypes.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h"
13 #include "base/time/time.h" 14 #include "base/time/time.h"
14 #include "skia/ext/convolver.h" 15 #include "skia/ext/convolver.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/skia/include/core/SkBitmap.h" 17 #include "third_party/skia/include/core/SkBitmap.h"
17 #include "third_party/skia/include/core/SkColorPriv.h" 18 #include "third_party/skia/include/core/SkColorPriv.h"
18 #include "third_party/skia/include/core/SkRect.h" 19 #include "third_party/skia/include/core/SkRect.h"
19 #include "third_party/skia/include/core/SkTypes.h" 20 #include "third_party/skia/include/core/SkTypes.h"
20 21
21 namespace skia { 22 namespace skia {
22 23
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 252
252 // Test both cases with different has_alpha. 253 // Test both cases with different has_alpha.
253 for (int alpha = 0; alpha < 2; alpha++) { 254 for (int alpha = 0; alpha < 2; alpha++) {
254 // Convolve using C code. 255 // Convolve using C code.
255 base::TimeTicks resize_start; 256 base::TimeTicks resize_start;
256 base::TimeDelta delta_c, delta_sse; 257 base::TimeDelta delta_c, delta_sse;
257 unsigned char* r1 = static_cast<unsigned char*>(result_c.getPixels()); 258 unsigned char* r1 = static_cast<unsigned char*>(result_c.getPixels());
258 unsigned char* r2 = static_cast<unsigned char*>(result_sse.getPixels()); 259 unsigned char* r2 = static_cast<unsigned char*>(result_sse.getPixels());
259 260
260 resize_start = base::TimeTicks::Now(); 261 resize_start = base::TimeTicks::Now();
261 BGRAConvolve2D(static_cast<const uint8*>(source.getPixels()), 262 BGRAConvolve2D(static_cast<const uint8_t*>(source.getPixels()),
262 static_cast<int>(source.rowBytes()), 263 static_cast<int>(source.rowBytes()), (alpha != 0), x_filter,
263 (alpha != 0), x_filter, y_filter, 264 y_filter, static_cast<int>(result_c.rowBytes()), r1, false);
264 static_cast<int>(result_c.rowBytes()), r1, false);
265 delta_c = base::TimeTicks::Now() - resize_start; 265 delta_c = base::TimeTicks::Now() - resize_start;
266 266
267 resize_start = base::TimeTicks::Now(); 267 resize_start = base::TimeTicks::Now();
268 // Convolve using SSE2 code 268 // Convolve using SSE2 code
269 BGRAConvolve2D(static_cast<const uint8*>(source.getPixels()), 269 BGRAConvolve2D(static_cast<const uint8_t*>(source.getPixels()),
270 static_cast<int>(source.rowBytes()), 270 static_cast<int>(source.rowBytes()), (alpha != 0), x_filter,
271 (alpha != 0), x_filter, y_filter, 271 y_filter, static_cast<int>(result_sse.rowBytes()), r2, true);
272 static_cast<int>(result_sse.rowBytes()), r2, true);
273 delta_sse = base::TimeTicks::Now() - resize_start; 272 delta_sse = base::TimeTicks::Now() - resize_start;
274 273
275 // Unfortunately I could not enable the performance check now. 274 // Unfortunately I could not enable the performance check now.
276 // Most bots use debug version, and there are great difference between 275 // Most bots use debug version, and there are great difference between
277 // the code generation for intrinsic, etc. In release version speed 276 // the code generation for intrinsic, etc. In release version speed
278 // difference was 150%-200% depend on alpha channel presence; 277 // difference was 150%-200% depend on alpha channel presence;
279 // while in debug version speed difference was 96%-120%. 278 // while in debug version speed difference was 96%-120%.
280 // TODO(jiesun): optimize further until we could enable this for 279 // TODO(jiesun): optimize further until we could enable this for
281 // debug version too. 280 // debug version too.
282 // EXPECT_LE(delta_sse, delta_c); 281 // EXPECT_LE(delta_sse, delta_c);
283 282
284 int64 c_us = delta_c.InMicroseconds(); 283 int64_t c_us = delta_c.InMicroseconds();
285 int64 sse_us = delta_sse.InMicroseconds(); 284 int64_t sse_us = delta_sse.InMicroseconds();
286 VLOG(1) << "from:" << source_width << "x" << source_height 285 VLOG(1) << "from:" << source_width << "x" << source_height
287 << " to:" << dest_width << "x" << dest_height 286 << " to:" << dest_width << "x" << dest_height
288 << (alpha ? " with alpha" : " w/o alpha"); 287 << (alpha ? " with alpha" : " w/o alpha");
289 VLOG(1) << "c:" << c_us << " sse:" << sse_us; 288 VLOG(1) << "c:" << c_us << " sse:" << sse_us;
290 VLOG(1) << "ratio:" << static_cast<float>(c_us) / sse_us; 289 VLOG(1) << "ratio:" << static_cast<float>(c_us) / sse_us;
291 290
292 // Comparing result. 291 // Comparing result.
293 for (unsigned int i = 0; i < dest_height; i++) { 292 for (unsigned int i = 0; i < dest_height; i++) {
294 EXPECT_FALSE(memcmp(r1, r2, dest_width * 4)); // RGBA always 293 EXPECT_FALSE(memcmp(r1, r2, dest_width * 4)); // RGBA always
295 r1 += result_c.rowBytes(); 294 r1 += result_c.rowBytes();
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 fp_gradient_kernel.end()), -1.5f); 522 fp_gradient_kernel.end()), -1.5f);
524 EXPECT_LT(*std::min_element(fp_gradient_kernel.begin(), 523 EXPECT_LT(*std::min_element(fp_gradient_kernel.begin(),
525 fp_gradient_kernel.end()), 0.0f); 524 fp_gradient_kernel.end()), 0.0f);
526 EXPECT_LT(*std::max_element(fp_gradient_kernel.begin(), 525 EXPECT_LT(*std::max_element(fp_gradient_kernel.begin(),
527 fp_gradient_kernel.end()), 1.5f); 526 fp_gradient_kernel.end()), 1.5f);
528 EXPECT_GT(*std::max_element(fp_gradient_kernel.begin(), 527 EXPECT_GT(*std::max_element(fp_gradient_kernel.begin(),
529 fp_gradient_kernel.end()), 0.0f); 528 fp_gradient_kernel.end()), 0.0f);
530 } 529 }
531 530
532 } // namespace skia 531 } // namespace skia
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698