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

Side by Side Diff: src/core/SkBitmapProcState.cpp

Issue 1534243002: Revert of Fix UB function problems for shaders and mask. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years 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 | « src/core/SkBitmapProcState.h ('k') | src/core/SkBitmapProcState_shaderproc.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 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkBitmapCache.h" 8 #include "SkBitmapCache.h"
9 #include "SkBitmapController.h" 9 #include "SkBitmapController.h"
10 #include "SkBitmapProcState.h" 10 #include "SkBitmapProcState.h"
11 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
12 #include "SkFilterProc.h" 12 #include "SkFilterProc.h"
13 #include "SkPaint.h" 13 #include "SkPaint.h"
14 #include "SkShader.h" // for tilemodes 14 #include "SkShader.h" // for tilemodes
15 #include "SkUtilsArm.h" 15 #include "SkUtilsArm.h"
16 #include "SkBitmapScaler.h" 16 #include "SkBitmapScaler.h"
17 #include "SkMipMap.h" 17 #include "SkMipMap.h"
18 #include "SkPixelRef.h" 18 #include "SkPixelRef.h"
19 #include "SkImageEncoder.h" 19 #include "SkImageEncoder.h"
20 #include "SkResourceCache.h" 20 #include "SkResourceCache.h"
21 21
22 #if !SK_ARM_NEON_IS_NONE 22 #if !SK_ARM_NEON_IS_NONE
23 // These are defined in src/opts/SkBitmapProcState_arm_neon.cpp 23 // These are defined in src/opts/SkBitmapProcState_arm_neon.cpp
24 extern const SkBitmapProcState::SampleProc16 gSkBitmapProcStateSample16_neon[]; 24 extern const SkBitmapProcState::SampleProc16 gSkBitmapProcStateSample16_neon[];
25 extern const SkBitmapProcState::SampleProc32 gSkBitmapProcStateSample32_neon[]; 25 extern const SkBitmapProcState::SampleProc32 gSkBitmapProcStateSample32_neon[];
26 extern void S16_D16_filter_DX_neon(const SkBitmapProcState&, const uint32_t*, i nt, uint16_t*); 26 extern void S16_D16_filter_DX_neon(const SkBitmapProcState&, const uint32_t*, i nt, uint16_t*);
27 extern void Clamp_S16_D16_filter_DX_shaderproc_neon(const void *, int, int, uin t16_t*, int); 27 extern void Clamp_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&, i nt, int, uint16_t*, int);
28 extern void Repeat_S16_D16_filter_DX_shaderproc_neon(const void *, int, int, ui nt16_t*, int); 28 extern void Repeat_S16_D16_filter_DX_shaderproc_neon(const SkBitmapProcState&, int, int, uint16_t*, int);
29 extern void SI8_opaque_D32_filter_DX_neon(const SkBitmapProcState&, const uint3 2_t*, int, SkPMColor*); 29 extern void SI8_opaque_D32_filter_DX_neon(const SkBitmapProcState&, const uint3 2_t*, int, SkPMColor*);
30 extern void SI8_opaque_D32_filter_DX_shaderproc_neon(const void *, int, int, ui nt32_t*, int); 30 extern void SI8_opaque_D32_filter_DX_shaderproc_neon(const SkBitmapProcState&, int, int, uint32_t*, int);
31 extern void Clamp_SI8_opaque_D32_filter_DX_shaderproc_neon(const void*, int, in t, uint32_t*, int); 31 extern void Clamp_SI8_opaque_D32_filter_DX_shaderproc_neon(const SkBitmapProcSt ate&, int, int, uint32_t*, int);
32 #endif 32 #endif
33 33
34 extern void Clamp_S32_opaque_D32_nofilter_DX_shaderproc(const void*, int, int, u int32_t*, int); 34 extern void Clamp_S32_opaque_D32_nofilter_DX_shaderproc(const SkBitmapProcState& , int, int, uint32_t*, int);
35 35
36 #define NAME_WRAP(x) x 36 #define NAME_WRAP(x) x
37 #include "SkBitmapProcState_filter.h" 37 #include "SkBitmapProcState_filter.h"
38 #include "SkBitmapProcState_procs.h" 38 #include "SkBitmapProcState_procs.h"
39 39
40 SkBitmapProcState::SkBitmapProcState(const SkBitmapProvider& provider, 40 SkBitmapProcState::SkBitmapProcState(const SkBitmapProvider& provider,
41 SkShader::TileMode tmx, SkShader::TileMode tmy) 41 SkShader::TileMode tmx, SkShader::TileMode tmy)
42 : fProvider(provider) 42 : fProvider(provider)
43 , fBMState(nullptr) 43 , fBMState(nullptr)
44 { 44 {
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 fShaderProc32 = this->chooseShaderProc32(); 384 fShaderProc32 = this->chooseShaderProc32();
385 } 385 }
386 } 386 }
387 387
388 // see if our platform has any accelerated overrides 388 // see if our platform has any accelerated overrides
389 this->platformProcs(); 389 this->platformProcs();
390 390
391 return true; 391 return true;
392 } 392 }
393 393
394 static void Clamp_S32_D32_nofilter_trans_shaderproc(const void* sIn, 394 static void Clamp_S32_D32_nofilter_trans_shaderproc(const SkBitmapProcState& s,
395 int x, int y, 395 int x, int y,
396 SkPMColor* SK_RESTRICT color s, 396 SkPMColor* SK_RESTRICT color s,
397 int count) { 397 int count) {
398 const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
399 SkASSERT(((s.fInvType & ~SkMatrix::kTranslate_Mask)) == 0); 398 SkASSERT(((s.fInvType & ~SkMatrix::kTranslate_Mask)) == 0);
400 SkASSERT(s.fInvKy == 0); 399 SkASSERT(s.fInvKy == 0);
401 SkASSERT(count > 0 && colors != nullptr); 400 SkASSERT(count > 0 && colors != nullptr);
402 SkASSERT(kNone_SkFilterQuality == s.fFilterLevel); 401 SkASSERT(kNone_SkFilterQuality == s.fFilterLevel);
403 402
404 const int maxX = s.fPixmap.width() - 1; 403 const int maxX = s.fPixmap.width() - 1;
405 const int maxY = s.fPixmap.height() - 1; 404 const int maxY = s.fPixmap.height() - 1;
406 int ix = s.fFilterOneX + x; 405 int ix = s.fFilterOneX + x;
407 int iy = SkClampMax(s.fFilterOneY + y, maxY); 406 int iy = SkClampMax(s.fFilterOneY + y, maxY);
408 #ifdef SK_DEBUG 407 #ifdef SK_DEBUG
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 } 458 }
460 459
461 static inline int sk_int_mirror(int x, int n) { 460 static inline int sk_int_mirror(int x, int n) {
462 x = sk_int_mod(x, 2 * n); 461 x = sk_int_mod(x, 2 * n);
463 if (x >= n) { 462 if (x >= n) {
464 x = n + ~(x - n); 463 x = n + ~(x - n);
465 } 464 }
466 return x; 465 return x;
467 } 466 }
468 467
469 static void Repeat_S32_D32_nofilter_trans_shaderproc(const void* sIn, 468 static void Repeat_S32_D32_nofilter_trans_shaderproc(const SkBitmapProcState& s,
470 int x, int y, 469 int x, int y,
471 SkPMColor* SK_RESTRICT colo rs, 470 SkPMColor* SK_RESTRICT colo rs,
472 int count) { 471 int count) {
473 const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
474 SkASSERT(((s.fInvType & ~SkMatrix::kTranslate_Mask)) == 0); 472 SkASSERT(((s.fInvType & ~SkMatrix::kTranslate_Mask)) == 0);
475 SkASSERT(s.fInvKy == 0); 473 SkASSERT(s.fInvKy == 0);
476 SkASSERT(count > 0 && colors != nullptr); 474 SkASSERT(count > 0 && colors != nullptr);
477 SkASSERT(kNone_SkFilterQuality == s.fFilterLevel); 475 SkASSERT(kNone_SkFilterQuality == s.fFilterLevel);
478 476
479 const int stopX = s.fPixmap.width(); 477 const int stopX = s.fPixmap.width();
480 const int stopY = s.fPixmap.height(); 478 const int stopY = s.fPixmap.height();
481 int ix = s.fFilterOneX + x; 479 int ix = s.fFilterOneX + x;
482 int iy = sk_int_mod(s.fFilterOneY + y, stopY); 480 int iy = sk_int_mod(s.fFilterOneY + y, stopY);
483 #ifdef SK_DEBUG 481 #ifdef SK_DEBUG
(...skipping 16 matching lines...) Expand all
500 memcpy(colors, row + ix, n * sizeof(SkPMColor)); 498 memcpy(colors, row + ix, n * sizeof(SkPMColor));
501 count -= n; 499 count -= n;
502 if (0 == count) { 500 if (0 == count) {
503 return; 501 return;
504 } 502 }
505 colors += n; 503 colors += n;
506 ix = 0; 504 ix = 0;
507 } 505 }
508 } 506 }
509 507
510 static void S32_D32_constX_shaderproc(const void* sIn, 508 static void S32_D32_constX_shaderproc(const SkBitmapProcState& s,
511 int x, int y, 509 int x, int y,
512 SkPMColor* SK_RESTRICT colors, 510 SkPMColor* SK_RESTRICT colors,
513 int count) { 511 int count) {
514 const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
515 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) == 0); 512 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) == 0);
516 SkASSERT(s.fInvKy == 0); 513 SkASSERT(s.fInvKy == 0);
517 SkASSERT(count > 0 && colors != nullptr); 514 SkASSERT(count > 0 && colors != nullptr);
518 SkASSERT(1 == s.fPixmap.width()); 515 SkASSERT(1 == s.fPixmap.width());
519 516
520 int iY0; 517 int iY0;
521 int iY1 SK_INIT_TO_AVOID_WARNING; 518 int iY1 SK_INIT_TO_AVOID_WARNING;
522 int iSubY SK_INIT_TO_AVOID_WARNING; 519 int iSubY SK_INIT_TO_AVOID_WARNING;
523 520
524 if (kNone_SkFilterQuality != s.fFilterLevel) { 521 if (kNone_SkFilterQuality != s.fFilterLevel) {
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 if (s.fAlphaScale < 256) { 611 if (s.fAlphaScale < 256) {
615 color = SkAlphaMulQ(*row0, s.fAlphaScale); 612 color = SkAlphaMulQ(*row0, s.fAlphaScale);
616 } else { 613 } else {
617 color = *row0; 614 color = *row0;
618 } 615 }
619 } 616 }
620 617
621 sk_memset32(colors, color, count); 618 sk_memset32(colors, color, count);
622 } 619 }
623 620
624 static void DoNothing_shaderproc(const void*, int x, int y, 621 static void DoNothing_shaderproc(const SkBitmapProcState&, int x, int y,
625 SkPMColor* SK_RESTRICT colors, int count) { 622 SkPMColor* SK_RESTRICT colors, int count) {
626 // if we get called, the matrix is too tricky, so we just draw nothing 623 // if we get called, the matrix is too tricky, so we just draw nothing
627 sk_memset32(colors, 0, count); 624 sk_memset32(colors, 0, count);
628 } 625 }
629 626
630 bool SkBitmapProcState::setupForTranslate() { 627 bool SkBitmapProcState::setupForTranslate() {
631 SkPoint pt; 628 SkPoint pt;
632 fInvProc(fInvMatrix, SK_ScalarHalf, SK_ScalarHalf, &pt); 629 fInvProc(fInvMatrix, SK_ScalarHalf, SK_ScalarHalf, &pt);
633 630
634 /* 631 /*
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 804
808 if (fFilterLevel != kNone_SkFilterQuality) { 805 if (fFilterLevel != kNone_SkFilterQuality) {
809 size >>= 1; 806 size >>= 1;
810 } 807 }
811 808
812 return size; 809 return size;
813 } 810 }
814 811
815 /////////////////////// 812 ///////////////////////
816 813
817 void Clamp_S32_opaque_D32_nofilter_DX_shaderproc(const void* sIn, int x, int y, 814 void Clamp_S32_opaque_D32_nofilter_DX_shaderproc(const SkBitmapProcState& s, in t x, int y,
818 SkPMColor* SK_RESTRICT dst, in t count) { 815 SkPMColor* SK_RESTRICT dst, in t count) {
819 const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
820 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask | 816 SkASSERT((s.fInvType & ~(SkMatrix::kTranslate_Mask |
821 SkMatrix::kScale_Mask)) == 0); 817 SkMatrix::kScale_Mask)) == 0);
822 818
823 const unsigned maxX = s.fPixmap.width() - 1; 819 const unsigned maxX = s.fPixmap.width() - 1;
824 SkFractionalInt fx; 820 SkFractionalInt fx;
825 int dstY; 821 int dstY;
826 { 822 {
827 SkPoint pt; 823 SkPoint pt;
828 s.fInvProc(s.fInvMatrix, SkIntToScalar(x) + SK_ScalarHalf, SkIntToScalar (y) + SK_ScalarHalf, 824 s.fInvProc(s.fInvMatrix, SkIntToScalar(x) + SK_ScalarHalf, SkIntToScalar (y) + SK_ScalarHalf,
829 &pt); 825 &pt);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 fx += dx; 858 fx += dx;
863 } 859 }
864 } else { 860 } else {
865 for (int i = 0; i < count; ++i) { 861 for (int i = 0; i < count; ++i) {
866 dst[i] = src[SkClampMax(SkFractionalIntToInt(fx), maxX)]; 862 dst[i] = src[SkClampMax(SkFractionalIntToInt(fx), maxX)];
867 fx += dx; 863 fx += dx;
868 } 864 }
869 } 865 }
870 } 866 }
871 867
OLDNEW
« no previous file with comments | « src/core/SkBitmapProcState.h ('k') | src/core/SkBitmapProcState_shaderproc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698