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

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

Issue 14929006: [MIPS] Added MIPS DSPr2 optimization for BGRAConvolve2D routine (Closed)
Patch Set: 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_mips_dspr2.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 317 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 const ConvolutionFilter1D::Fixed* filter_values, 338 const ConvolutionFilter1D::Fixed* filter_values,
338 int filter_length, 339 int filter_length,
339 unsigned char* const* source_data_rows, 340 unsigned char* const* source_data_rows,
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]);
348 #if SIMD_MIPS_DSPR2
349 typedef void (*ConvolveHorizontally_pointer)(
350 const unsigned char* src_data,
351 const ConvolutionFilter1D& filter,
352 unsigned char* out_row,
353 bool has_alpha);
hubbe 2013/05/10 19:39:09 Just add "has_alpha" to all implementations instea
Stephen White 2013/05/10 20:31:26 +1 to that.
354 #else
347 typedef void (*ConvolveHorizontally_pointer)( 355 typedef void (*ConvolveHorizontally_pointer)(
348 const unsigned char* src_data, 356 const unsigned char* src_data,
349 const ConvolutionFilter1D& filter, 357 const ConvolutionFilter1D& filter,
350 unsigned char* out_row); 358 unsigned char* out_row);
359 #endif
351 360
352 struct ConvolveProcs { 361 struct ConvolveProcs {
353 // This is how many extra pixels may be read by the 362 // This is how many extra pixels may be read by the
354 // conolve*horizontally functions. 363 // conolve*horizontally functions.
355 int extra_horizontal_reads; 364 int extra_horizontal_reads;
356 ConvolveVertically_pointer convolve_vertically; 365 ConvolveVertically_pointer convolve_vertically;
357 Convolve4RowsHorizontally_pointer convolve_4rows_horizontally; 366 Convolve4RowsHorizontally_pointer convolve_4rows_horizontally;
358 ConvolveHorizontally_pointer convolve_horizontally; 367 ConvolveHorizontally_pointer convolve_horizontally;
359 }; 368 };
360 369
361 void SetupSIMD(ConvolveProcs *procs) { 370 void SetupSIMD(ConvolveProcs *procs) {
362 #ifdef SIMD_SSE2 371 #ifdef SIMD_SSE2
363 base::CPU cpu; 372 base::CPU cpu;
364 if (cpu.has_sse2()) { 373 if (cpu.has_sse2()) {
365 procs->extra_horizontal_reads = 3; 374 procs->extra_horizontal_reads = 3;
366 procs->convolve_vertically = &ConvolveVertically_SSE2; 375 procs->convolve_vertically = &ConvolveVertically_SSE2;
367 procs->convolve_4rows_horizontally = &Convolve4RowsHorizontally_SSE2; 376 procs->convolve_4rows_horizontally = &Convolve4RowsHorizontally_SSE2;
368 procs->convolve_horizontally = &ConvolveHorizontally_SSE2; 377 procs->convolve_horizontally = &ConvolveHorizontally_SSE2;
369 } 378 }
379 #elif defined SIMD_MIPS_DSPR2
Stephen White 2013/05/10 20:31:26 You use "#if" above, but "#if defined" here. Plea
Stephen White 2013/05/13 14:08:43 Sorry, my mistake. This should be #elif defined(S
Teodora Novkovic 2013/05/13 16:23:06 Done.
Teodora Novkovic 2013/05/13 16:23:06 Done.
380 procs->extra_horizontal_reads = 3;
381 procs->convolve_vertically = &ConvolveVertically_mips_dspr2;
382 procs->convolve_horizontally = &ConvolveHorizontally_mips_dspr2;
370 #endif 383 #endif
371 } 384 }
372 385
373 void BGRAConvolve2D(const unsigned char* source_data, 386 void BGRAConvolve2D(const unsigned char* source_data,
374 int source_byte_row_stride, 387 int source_byte_row_stride,
375 bool source_has_alpha, 388 bool source_has_alpha,
376 const ConvolutionFilter1D& filter_x, 389 const ConvolutionFilter1D& filter_x,
377 const ConvolutionFilter1D& filter_y, 390 const ConvolutionFilter1D& filter_y,
378 int output_byte_row_stride, 391 int output_byte_row_stride,
379 unsigned char* output, 392 unsigned char* output,
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 src[i] = &source_data[(next_x_row + i) * source_byte_row_stride]; 468 src[i] = &source_data[(next_x_row + i) * source_byte_row_stride];
456 out_row[i] = row_buffer.AdvanceRow(); 469 out_row[i] = row_buffer.AdvanceRow();
457 } 470 }
458 simd.convolve_4rows_horizontally(src, filter_x, out_row); 471 simd.convolve_4rows_horizontally(src, filter_x, out_row);
459 next_x_row += 4; 472 next_x_row += 4;
460 } else { 473 } else {
461 // Check if we need to avoid SSE2 for this row. 474 // Check if we need to avoid SSE2 for this row.
462 if (simd.convolve_horizontally && 475 if (simd.convolve_horizontally &&
463 next_x_row < last_filter_offset + last_filter_length - 476 next_x_row < last_filter_offset + last_filter_length -
464 avoid_simd_rows) { 477 avoid_simd_rows) {
478 #if SIMD_MIPS_DSPR2
479 simd.convolve_horizontally(
480 &source_data[next_x_row * source_byte_row_stride],
481 filter_x, row_buffer.AdvanceRow(), source_has_alpha);
482 #else
465 simd.convolve_horizontally( 483 simd.convolve_horizontally(
466 &source_data[next_x_row * source_byte_row_stride], 484 &source_data[next_x_row * source_byte_row_stride],
467 filter_x, row_buffer.AdvanceRow()); 485 filter_x, row_buffer.AdvanceRow());
486 #endif
468 } else { 487 } else {
469 if (source_has_alpha) { 488 if (source_has_alpha) {
470 ConvolveHorizontally<true>( 489 ConvolveHorizontally<true>(
471 &source_data[next_x_row * source_byte_row_stride], 490 &source_data[next_x_row * source_byte_row_stride],
472 filter_x, row_buffer.AdvanceRow()); 491 filter_x, row_buffer.AdvanceRow());
473 } else { 492 } else {
474 ConvolveHorizontally<false>( 493 ConvolveHorizontally<false>(
475 &source_data[next_x_row * source_byte_row_stride], 494 &source_data[next_x_row * source_byte_row_stride],
476 filter_x, row_buffer.AdvanceRow()); 495 filter_x, row_buffer.AdvanceRow());
477 } 496 }
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
666 685
667 for (; i < filter_length; ++i) 686 for (; i < filter_length; ++i)
668 accval += filter_values[i] * source_data[pixel_byte_index]; 687 accval += filter_values[i] * source_data[pixel_byte_index];
669 688
670 *target_byte = BringBackTo8(accval, absolute_values); 689 *target_byte = BringBackTo8(accval, absolute_values);
671 } 690 }
672 } 691 }
673 } 692 }
674 693
675 } // namespace skia 694 } // namespace skia
OLDNEW
« no previous file with comments | « skia/ext/convolver.h ('k') | skia/ext/convolver_mips_dspr2.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698