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

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

Issue 14929006: [MIPS] Added MIPS DSPr2 optimization for BGRAConvolve2D routine (Closed)
Patch Set: Add a non-templated parameter "has_alpha" for MIPS DSPr2 routines Created 7 years, 7 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
« no previous file with comments | « skia/ext/convolver.h ('k') | skia/ext/convolver_SSE2.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "skia/ext/convolver.h" 8 #include "skia/ext/convolver.h"
9 #include "skia/ext/convolver_SSE2.h" 9 #include "skia/ext/convolver_SSE2.h"
10 #include "skia/ext/convolver_mips_dspr2.h"
10 #include "third_party/skia/include/core/SkSize.h" 11 #include "third_party/skia/include/core/SkSize.h"
11 #include "third_party/skia/include/core/SkTypes.h" 12 #include "third_party/skia/include/core/SkTypes.h"
12 13
13 namespace skia { 14 namespace skia {
14 15
15 namespace { 16 namespace {
16 17
17 // Converts the argument to an 8-bit unsigned value by clamping to the range 18 // Converts the argument to an 8-bit unsigned value by clamping to the range
18 // 0-255. 19 // 0-255.
19 inline unsigned char ClampTo8(int a) { 20 inline unsigned char ClampTo8(int a) {
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 int pixel_width, 341 int pixel_width,
341 unsigned char* out_row, 342 unsigned char* out_row,
342 bool has_alpha); 343 bool has_alpha);
343 typedef void (*Convolve4RowsHorizontally_pointer)( 344 typedef void (*Convolve4RowsHorizontally_pointer)(
344 const unsigned char* src_data[4], 345 const unsigned char* src_data[4],
345 const ConvolutionFilter1D& filter, 346 const ConvolutionFilter1D& filter,
346 unsigned char* out_row[4]); 347 unsigned char* out_row[4]);
347 typedef void (*ConvolveHorizontally_pointer)( 348 typedef void (*ConvolveHorizontally_pointer)(
348 const unsigned char* src_data, 349 const unsigned char* src_data,
349 const ConvolutionFilter1D& filter, 350 const ConvolutionFilter1D& filter,
350 unsigned char* out_row); 351 unsigned char* out_row,
352 bool has_alpha);
351 353
352 struct ConvolveProcs { 354 struct ConvolveProcs {
353 // This is how many extra pixels may be read by the 355 // This is how many extra pixels may be read by the
354 // conolve*horizontally functions. 356 // conolve*horizontally functions.
355 int extra_horizontal_reads; 357 int extra_horizontal_reads;
356 ConvolveVertically_pointer convolve_vertically; 358 ConvolveVertically_pointer convolve_vertically;
357 Convolve4RowsHorizontally_pointer convolve_4rows_horizontally; 359 Convolve4RowsHorizontally_pointer convolve_4rows_horizontally;
358 ConvolveHorizontally_pointer convolve_horizontally; 360 ConvolveHorizontally_pointer convolve_horizontally;
359 }; 361 };
360 362
361 void SetupSIMD(ConvolveProcs *procs) { 363 void SetupSIMD(ConvolveProcs *procs) {
362 #ifdef SIMD_SSE2 364 #ifdef SIMD_SSE2
363 base::CPU cpu; 365 base::CPU cpu;
364 if (cpu.has_sse2()) { 366 if (cpu.has_sse2()) {
365 procs->extra_horizontal_reads = 3; 367 procs->extra_horizontal_reads = 3;
366 procs->convolve_vertically = &ConvolveVertically_SSE2; 368 procs->convolve_vertically = &ConvolveVertically_SSE2;
367 procs->convolve_4rows_horizontally = &Convolve4RowsHorizontally_SSE2; 369 procs->convolve_4rows_horizontally = &Convolve4RowsHorizontally_SSE2;
368 procs->convolve_horizontally = &ConvolveHorizontally_SSE2; 370 procs->convolve_horizontally = &ConvolveHorizontally_SSE2;
369 } 371 }
372 #elif defined SIMD_MIPS_DSPR2
373 procs->extra_horizontal_reads = 3;
374 procs->convolve_vertically = &ConvolveVertically_mips_dspr2;
375 procs->convolve_horizontally = &ConvolveHorizontally_mips_dspr2;
370 #endif 376 #endif
371 } 377 }
372 378
373 void BGRAConvolve2D(const unsigned char* source_data, 379 void BGRAConvolve2D(const unsigned char* source_data,
374 int source_byte_row_stride, 380 int source_byte_row_stride,
375 bool source_has_alpha, 381 bool source_has_alpha,
376 const ConvolutionFilter1D& filter_x, 382 const ConvolutionFilter1D& filter_x,
377 const ConvolutionFilter1D& filter_y, 383 const ConvolutionFilter1D& filter_y,
378 int output_byte_row_stride, 384 int output_byte_row_stride,
379 unsigned char* output, 385 unsigned char* output,
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 } 463 }
458 simd.convolve_4rows_horizontally(src, filter_x, out_row); 464 simd.convolve_4rows_horizontally(src, filter_x, out_row);
459 next_x_row += 4; 465 next_x_row += 4;
460 } else { 466 } else {
461 // Check if we need to avoid SSE2 for this row. 467 // Check if we need to avoid SSE2 for this row.
462 if (simd.convolve_horizontally && 468 if (simd.convolve_horizontally &&
463 next_x_row < last_filter_offset + last_filter_length - 469 next_x_row < last_filter_offset + last_filter_length -
464 avoid_simd_rows) { 470 avoid_simd_rows) {
465 simd.convolve_horizontally( 471 simd.convolve_horizontally(
466 &source_data[next_x_row * source_byte_row_stride], 472 &source_data[next_x_row * source_byte_row_stride],
467 filter_x, row_buffer.AdvanceRow()); 473 filter_x, row_buffer.AdvanceRow(), source_has_alpha);
468 } else { 474 } else {
469 if (source_has_alpha) { 475 if (source_has_alpha) {
470 ConvolveHorizontally<true>( 476 ConvolveHorizontally<true>(
471 &source_data[next_x_row * source_byte_row_stride], 477 &source_data[next_x_row * source_byte_row_stride],
472 filter_x, row_buffer.AdvanceRow()); 478 filter_x, row_buffer.AdvanceRow());
473 } else { 479 } else {
474 ConvolveHorizontally<false>( 480 ConvolveHorizontally<false>(
475 &source_data[next_x_row * source_byte_row_stride], 481 &source_data[next_x_row * source_byte_row_stride],
476 filter_x, row_buffer.AdvanceRow()); 482 filter_x, row_buffer.AdvanceRow());
477 } 483 }
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 672
667 for (; i < filter_length; ++i) 673 for (; i < filter_length; ++i)
668 accval += filter_values[i] * source_data[pixel_byte_index]; 674 accval += filter_values[i] * source_data[pixel_byte_index];
669 675
670 *target_byte = BringBackTo8(accval, absolute_values); 676 *target_byte = BringBackTo8(accval, absolute_values);
671 } 677 }
672 } 678 }
673 } 679 }
674 680
675 } // namespace skia 681 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/convolver.h ('k') | skia/ext/convolver_SSE2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698