OLD | NEW |
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 "SkConvolver.h" | 5 #include "SkConvolver.h" |
| 6 #include "SkMath.h" |
6 #include "SkSize.h" | 7 #include "SkSize.h" |
7 #include "SkTypes.h" | 8 #include "SkTypes.h" |
8 | 9 |
9 namespace { | 10 namespace { |
10 | 11 |
11 // Converts the argument to an 8-bit unsigned value by clamping to the range | 12 // Converts the argument to an 8-bit unsigned value by clamping to the range |
12 // 0-255. | 13 // 0-255. |
13 inline unsigned char ClampTo8(int a) { | 14 inline unsigned char ClampTo8(int a) { |
14 if (static_cast<unsigned>(a) < 256) { | 15 if (static_cast<unsigned>(a) < 256) { |
15 return a; // Avoid the extra check in the common case. | 16 return a; // Avoid the extra check in the common case. |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 *filterOffset = filter.fOffset; | 352 *filterOffset = filter.fOffset; |
352 *filterLength = filter.fTrimmedLength; | 353 *filterLength = filter.fTrimmedLength; |
353 *specifiedFilterlength = filter.fLength; | 354 *specifiedFilterlength = filter.fLength; |
354 if (filter.fTrimmedLength == 0) { | 355 if (filter.fTrimmedLength == 0) { |
355 return nullptr; | 356 return nullptr; |
356 } | 357 } |
357 | 358 |
358 return &fFilterValues[filter.fDataLocation]; | 359 return &fFilterValues[filter.fDataLocation]; |
359 } | 360 } |
360 | 361 |
361 void BGRAConvolve2D(const unsigned char* sourceData, | 362 bool BGRAConvolve2D(const unsigned char* sourceData, |
362 int sourceByteRowStride, | 363 int sourceByteRowStride, |
363 bool sourceHasAlpha, | 364 bool sourceHasAlpha, |
364 const SkConvolutionFilter1D& filterX, | 365 const SkConvolutionFilter1D& filterX, |
365 const SkConvolutionFilter1D& filterY, | 366 const SkConvolutionFilter1D& filterY, |
366 int outputByteRowStride, | 367 int outputByteRowStride, |
367 unsigned char* output, | 368 unsigned char* output, |
368 const SkConvolutionProcs& convolveProcs, | 369 const SkConvolutionProcs& convolveProcs, |
369 bool useSimdIfPossible) { | 370 bool useSimdIfPossible) { |
370 | 371 |
371 int maxYFilterSize = filterY.maxFilter(); | 372 int maxYFilterSize = filterY.maxFilter(); |
(...skipping 14 matching lines...) Expand all Loading... |
386 // are available. This prevents us from having to store the entire | 387 // are available. This prevents us from having to store the entire |
387 // intermediate image and helps cache coherency. | 388 // intermediate image and helps cache coherency. |
388 // We will need four extra rows to allow horizontal convolution could be don
e | 389 // We will need four extra rows to allow horizontal convolution could be don
e |
389 // simultaneously. We also pad each row in row buffer to be aligned-up to | 390 // simultaneously. We also pad each row in row buffer to be aligned-up to |
390 // 16 bytes. | 391 // 16 bytes. |
391 // TODO(jiesun): We do not use aligned load from row buffer in vertical | 392 // TODO(jiesun): We do not use aligned load from row buffer in vertical |
392 // convolution pass yet. Somehow Windows does not like it. | 393 // convolution pass yet. Somehow Windows does not like it. |
393 int rowBufferWidth = (filterX.numValues() + 15) & ~0xF; | 394 int rowBufferWidth = (filterX.numValues() + 15) & ~0xF; |
394 int rowBufferHeight = maxYFilterSize + | 395 int rowBufferHeight = maxYFilterSize + |
395 (convolveProcs.fConvolve4RowsHorizontally ? 4 : 0); | 396 (convolveProcs.fConvolve4RowsHorizontally ? 4 : 0); |
| 397 |
| 398 // check for too-big allocation requests : crbug.com/528628 |
| 399 { |
| 400 int64_t size = sk_64_mul(rowBufferWidth, rowBufferHeight); |
| 401 // need some limit, to avoid over-committing success from malloc, but th
en |
| 402 // crashing when we try to actually use the memory. |
| 403 // 100meg seems big enough to allow "normal" zoom factors and image size
s through |
| 404 // while avoiding the crash seen by the bug (crbug.com/528628) |
| 405 if (size > 100 * 1024 * 1024) { |
| 406 // SkDebugf("BGRAConvolve2D: tmp allocation [%lld] too big\n", size); |
| 407 return false; |
| 408 } |
| 409 } |
| 410 |
396 CircularRowBuffer rowBuffer(rowBufferWidth, | 411 CircularRowBuffer rowBuffer(rowBufferWidth, |
397 rowBufferHeight, | 412 rowBufferHeight, |
398 filterOffset); | 413 filterOffset); |
399 | 414 |
400 // Loop over every possible output row, processing just enough horizontal | 415 // Loop over every possible output row, processing just enough horizontal |
401 // convolutions to run each subsequent vertical convolution. | 416 // convolutions to run each subsequent vertical convolution. |
402 SkASSERT(outputByteRowStride >= filterX.numValues() * 4); | 417 SkASSERT(outputByteRowStride >= filterX.numValues() * 4); |
403 int numOutputRows = filterY.numValues(); | 418 int numOutputRows = filterY.numValues(); |
404 | 419 |
405 // We need to check which is the last line to convolve before we advance 4 | 420 // We need to check which is the last line to convolve before we advance 4 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 firstRowForFilter, | 494 firstRowForFilter, |
480 filterX.numValues(), curOutputRow
, | 495 filterX.numValues(), curOutputRow
, |
481 sourceHasAlpha); | 496 sourceHasAlpha); |
482 } else { | 497 } else { |
483 ConvolveVertically(filterValues, filterLength, | 498 ConvolveVertically(filterValues, filterLength, |
484 firstRowForFilter, | 499 firstRowForFilter, |
485 filterX.numValues(), curOutputRow, | 500 filterX.numValues(), curOutputRow, |
486 sourceHasAlpha); | 501 sourceHasAlpha); |
487 } | 502 } |
488 } | 503 } |
| 504 return true; |
489 } | 505 } |
OLD | NEW |