Flutter Engine
The Flutter Engine
Functions
SkBitmapProcState.cpp File Reference
#include "src/core/SkBitmapProcState.h"
#include "include/core/SkAlphaType.h"
#include "include/core/SkColorPriv.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkTileMode.h"
#include "include/private/base/SkMacros.h"
#include "include/private/base/SkTPin.h"
#include "src/core/SkMemset.h"
#include "src/core/SkMipmapAccessor.h"
#include <algorithm>
#include <cstring>
#include <tuple>

Go to the source code of this file.

Functions

static void Clamp_S32_opaque_D32_nofilter_DX_shaderproc (const void *sIn, int x, int y, SkPMColor *dst, int count)
 
static void S32_alpha_D32_nofilter_DX (const SkBitmapProcState &s, const uint32_t *xy, int count, SkPMColor *colors)
 
static void S32_alpha_D32_nofilter_DXDY (const SkBitmapProcState &s, const uint32_t *xy, int count, SkPMColor *colors)
 
static bool matrix_only_scale_translate (const SkMatrix &m)
 
static bool just_trans_general (const SkMatrix &matrix)
 
static bool just_trans_integral (const SkMatrix &m)
 
static bool valid_for_filtering (unsigned dimension)
 
static void Clamp_S32_D32_nofilter_trans_shaderproc (const void *sIn, int x, int y, SkPMColor *colors, int count)
 
static int sk_int_mod (int x, int n)
 
static int sk_int_mirror (int x, int n)
 
static void Repeat_S32_D32_nofilter_trans_shaderproc (const void *sIn, int x, int y, SkPMColor *colors, int count)
 
static void filter_32_alpha (unsigned t, SkPMColor color0, SkPMColor color1, SkPMColor *dstColor, unsigned alphaScale)
 
static void S32_D32_constX_shaderproc (const void *sIn, int x, int y, SkPMColor *colors, int count)
 
static void DoNothing_shaderproc (const void *, int x, int y, SkPMColor *colors, int count)
 

Function Documentation

◆ Clamp_S32_D32_nofilter_trans_shaderproc()

static void Clamp_S32_D32_nofilter_trans_shaderproc ( const void *  sIn,
int  x,
int  y,
SkPMColor colors,
int  count 
)
static

Definition at line 302 of file SkBitmapProcState.cpp.

305 {
306 const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
307 SkASSERT(s.fInvMatrix.isTranslate());
308 SkASSERT(count > 0 && colors != nullptr);
309 SkASSERT(!s.fBilerp);
310
311 const int maxX = s.fPixmap.width() - 1;
312 const int maxY = s.fPixmap.height() - 1;
313 int ix = s.fFilterOneX + x;
314 int iy = SkTPin(s.fFilterOneY + y, 0, maxY);
315 const SkPMColor* row = s.fPixmap.addr32(0, iy);
316
317 // clamp to the left
318 if (ix < 0) {
319 int n = std::min(-ix, count);
320 SkOpts::memset32(colors, row[0], n);
321 count -= n;
322 if (0 == count) {
323 return;
324 }
325 colors += n;
326 SkASSERT(-ix == n);
327 ix = 0;
328 }
329 // copy the middle
330 if (ix <= maxX) {
331 int n = std::min(maxX - ix + 1, count);
332 memcpy(colors, row + ix, n * sizeof(SkPMColor));
333 count -= n;
334 if (0 == count) {
335 return;
336 }
337 colors += n;
338 }
339 SkASSERT(count > 0);
340 // clamp to the right
341 SkOpts::memset32(colors, row[maxX], count);
342}
int count
Definition: FontMgrTest.cpp:50
#define SkASSERT(cond)
Definition: SkAssert.h:116
uint32_t SkPMColor
Definition: SkColor.h:205
static constexpr const T & SkTPin(const T &x, const T &lo, const T &hi)
Definition: SkTPin.h:19
struct MyStruct s
static float min(float r, float g, float b)
Definition: hsl.cpp:48
double y
double x
void(* memset32)(uint32_t[], uint32_t, int)
PODArray< SkColor > colors
Definition: SkRecords.h:276

◆ Clamp_S32_opaque_D32_nofilter_DX_shaderproc()

static void Clamp_S32_opaque_D32_nofilter_DX_shaderproc ( const void *  sIn,
int  x,
int  y,
SkPMColor dst,
int  count 
)
static

Definition at line 33 of file SkBitmapProcState.cpp.

34 {
35 const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
36 SkASSERT(s.fInvMatrix.isScaleTranslate());
37 SkASSERT(s.fAlphaScale == 256);
38
39 const unsigned maxX = s.fPixmap.width() - 1;
41 int dstY;
42 {
43 const SkBitmapProcStateAutoMapper mapper(s, x, y);
44 const unsigned maxY = s.fPixmap.height() - 1;
45 dstY = SkTPin<int>(mapper.intY(), 0, maxY);
46 fx = mapper.fractionalIntX();
47 }
48
49 const SkPMColor* src = s.fPixmap.addr32(0, dstY);
50 const SkFractionalInt dx = s.fInvSxFractionalInt;
51
52 // Check if we're safely inside [0...maxX] so no need to clamp each computed index.
53 //
54 if ((uint64_t)SkFractionalIntToInt(fx) <= maxX &&
55 (uint64_t)SkFractionalIntToInt(fx + dx * (count - 1)) <= maxX)
56 {
57 int count4 = count >> 2;
58 for (int i = 0; i < count4; ++i) {
59 SkPMColor src0 = src[SkFractionalIntToInt(fx)]; fx += dx;
60 SkPMColor src1 = src[SkFractionalIntToInt(fx)]; fx += dx;
61 SkPMColor src2 = src[SkFractionalIntToInt(fx)]; fx += dx;
62 SkPMColor src3 = src[SkFractionalIntToInt(fx)]; fx += dx;
63 dst[0] = src0;
64 dst[1] = src1;
65 dst[2] = src2;
66 dst[3] = src3;
67 dst += 4;
68 }
69 for (int i = (count4 << 2); i < count; ++i) {
70 unsigned index = SkFractionalIntToInt(fx);
71 SkASSERT(index <= maxX);
72 *dst++ = src[index];
73 fx += dx;
74 }
75 } else {
76 for (int i = 0; i < count; ++i) {
77 dst[i] = src[SkTPin<int>(SkFractionalIntToInt(fx), 0, maxX)];
78 fx += dx;
79 }
80 }
81}
SkFixed3232 SkFractionalInt
#define SkFractionalIntToInt(x)
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition: SkRecords.h:208
dst
Definition: cp.py:12

◆ DoNothing_shaderproc()

static void DoNothing_shaderproc ( const void *  ,
int  x,
int  y,
SkPMColor colors,
int  count 
)
static

Definition at line 519 of file SkBitmapProcState.cpp.

520 {
521 // if we get called, the matrix is too tricky, so we just draw nothing
523}

◆ filter_32_alpha()

static void filter_32_alpha ( unsigned  t,
SkPMColor  color0,
SkPMColor  color1,
SkPMColor dstColor,
unsigned  alphaScale 
)
inlinestatic

Definition at line 392 of file SkBitmapProcState.cpp.

396 {
397 SkASSERT((unsigned)t <= 0xF);
398 SkASSERT(alphaScale <= 256);
399
400 const uint32_t mask = 0xFF00FF;
401
402 int scale = 256 - 16*t;
403 uint32_t lo = (color0 & mask) * scale;
404 uint32_t hi = ((color0 >> 8) & mask) * scale;
405
406 scale = 16*t;
407 lo += (color1 & mask) * scale;
408 hi += ((color1 >> 8) & mask) * scale;
409
410 // TODO: if (alphaScale < 256) ...
411 lo = ((lo >> 8) & mask) * alphaScale;
412 hi = ((hi >> 8) & mask) * alphaScale;
413
414 *dstColor = ((lo >> 8) & mask) | (hi & ~mask);
415}
const Scalar scale

◆ just_trans_general()

static bool just_trans_general ( const SkMatrix matrix)
static

For the purposes of drawing bitmaps, if a matrix is "almost" translate go ahead and treat it as if it were, so that subsequent code can go fast.

Definition at line 162 of file SkBitmapProcState.cpp.

162 {
164
165 const SkScalar tol = SK_Scalar1 / 32768;
166
169}
static bool matrix_only_scale_translate(const SkMatrix &m)
static bool SkScalarNearlyZero(SkScalar x, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:101
#define SK_Scalar1
Definition: SkScalar.h:18
static constexpr int kMScaleX
horizontal scale factor
Definition: SkMatrix.h:353
static constexpr int kMScaleY
vertical scale factor
Definition: SkMatrix.h:357
float SkScalar
Definition: extension.cpp:12
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258

◆ just_trans_integral()

static bool just_trans_integral ( const SkMatrix m)
static

Determine if the matrix can be treated as integral-only-translate, for the purpose of filtering.

Definition at line 175 of file SkBitmapProcState.cpp.

175 {
176 static constexpr SkScalar tol = SK_Scalar1 / 256;
177
178 return m.getType() <= SkMatrix::kTranslate_Mask
179 && SkScalarNearlyEqual(m.getTranslateX(), SkScalarRoundToScalar(m.getTranslateX()), tol)
180 && SkScalarNearlyEqual(m.getTranslateY(), SkScalarRoundToScalar(m.getTranslateY()), tol);
181}
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition: SkScalar.h:107
#define SkScalarRoundToScalar(x)
Definition: SkScalar.h:32
@ kTranslate_Mask
translation SkMatrix
Definition: SkMatrix.h:193

◆ matrix_only_scale_translate()

static bool matrix_only_scale_translate ( const SkMatrix m)
static

Definition at line 154 of file SkBitmapProcState.cpp.

154 {
155 return (m.getType() & ~SkMatrix::kTranslate_Mask) == SkMatrix::kScale_Mask;
156}
@ kScale_Mask
scale SkMatrix
Definition: SkMatrix.h:194

◆ Repeat_S32_D32_nofilter_trans_shaderproc()

static void Repeat_S32_D32_nofilter_trans_shaderproc ( const void *  sIn,
int  x,
int  y,
SkPMColor colors,
int  count 
)
static

Definition at line 364 of file SkBitmapProcState.cpp.

367 {
368 const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
369 SkASSERT(s.fInvMatrix.isTranslate());
370 SkASSERT(count > 0 && colors != nullptr);
371 SkASSERT(!s.fBilerp);
372
373 const int stopX = s.fPixmap.width();
374 const int stopY = s.fPixmap.height();
375 int ix = s.fFilterOneX + x;
376 int iy = sk_int_mod(s.fFilterOneY + y, stopY);
377 const SkPMColor* row = s.fPixmap.addr32(0, iy);
378
379 ix = sk_int_mod(ix, stopX);
380 for (;;) {
381 int n = std::min(stopX - ix, count);
382 memcpy(colors, row + ix, n * sizeof(SkPMColor));
383 count -= n;
384 if (0 == count) {
385 return;
386 }
387 colors += n;
388 ix = 0;
389 }
390}
static int sk_int_mod(int x, int n)

◆ S32_alpha_D32_nofilter_DX()

static void S32_alpha_D32_nofilter_DX ( const SkBitmapProcState s,
const uint32_t *  xy,
int  count,
SkPMColor colors 
)
static

Definition at line 83 of file SkBitmapProcState.cpp.

84 {
85 SkASSERT(count > 0 && colors != nullptr);
86 SkASSERT(s.fInvMatrix.isScaleTranslate());
87 SkASSERT(!s.fBilerp);
88 SkASSERT(4 == s.fPixmap.info().bytesPerPixel());
89 SkASSERT(s.fAlphaScale <= 256);
90
91 // xy is a 32-bit y-coordinate, followed by 16-bit x-coordinates.
92 unsigned y = *xy++;
93 SkASSERT(y < (unsigned)s.fPixmap.height());
94
95 auto row = (const SkPMColor*)( (const char*)s.fPixmap.addr() + y * s.fPixmap.rowBytes() );
96
97 if (1 == s.fPixmap.width()) {
98 SkOpts::memset32(colors, SkAlphaMulQ(row[0], s.fAlphaScale), count);
99 return;
100 }
101
102 // Step 4 xs == 2 uint32_t at a time.
103 while (count >= 4) {
104 uint32_t x01 = *xy++,
105 x23 = *xy++;
106
107 SkPMColor p0 = row[UNPACK_PRIMARY_SHORT (x01)];
108 SkPMColor p1 = row[UNPACK_SECONDARY_SHORT(x01)];
109 SkPMColor p2 = row[UNPACK_PRIMARY_SHORT (x23)];
110 SkPMColor p3 = row[UNPACK_SECONDARY_SHORT(x23)];
111
112 *colors++ = SkAlphaMulQ(p0, s.fAlphaScale);
113 *colors++ = SkAlphaMulQ(p1, s.fAlphaScale);
114 *colors++ = SkAlphaMulQ(p2, s.fAlphaScale);
115 *colors++ = SkAlphaMulQ(p3, s.fAlphaScale);
116
117 count -= 4;
118 }
119
120 // Step 1 x == 1 uint16_t at a time.
121 auto x = (const uint16_t*)xy;
122 while (count --> 0) {
123 *colors++ = SkAlphaMulQ(row[*x++], s.fAlphaScale);
124 }
125}
#define UNPACK_PRIMARY_SHORT(packed)
#define UNPACK_SECONDARY_SHORT(packed)
static SK_ALWAYS_INLINE uint32_t SkAlphaMulQ(uint32_t c, unsigned scale)
Definition: SkColorPriv.h:142

◆ S32_alpha_D32_nofilter_DXDY()

static void S32_alpha_D32_nofilter_DXDY ( const SkBitmapProcState s,
const uint32_t *  xy,
int  count,
SkPMColor colors 
)
static

Definition at line 127 of file SkBitmapProcState.cpp.

128 {
129 SkASSERT(count > 0 && colors != nullptr);
130 SkASSERT(!s.fBilerp);
131 SkASSERT(4 == s.fPixmap.info().bytesPerPixel());
132 SkASSERT(s.fAlphaScale <= 256);
133
134 auto src = (const char*)s.fPixmap.addr();
135 size_t rb = s.fPixmap.rowBytes();
136
137 while (count --> 0) {
138 uint32_t XY = *xy++,
139 x = XY & 0xffff,
140 y = XY >> 16;
141 SkASSERT(x < (unsigned)s.fPixmap.width ());
142 SkASSERT(y < (unsigned)s.fPixmap.height());
143 *colors++ = SkAlphaMulQ(((const SkPMColor*)(src + y*rb))[x], s.fAlphaScale);
144 }
145}

◆ S32_D32_constX_shaderproc()

static void S32_D32_constX_shaderproc ( const void *  sIn,
int  x,
int  y,
SkPMColor colors,
int  count 
)
static

Definition at line 417 of file SkBitmapProcState.cpp.

420 {
421 const SkBitmapProcState& s = *static_cast<const SkBitmapProcState*>(sIn);
422 SkASSERT(s.fInvMatrix.isScaleTranslate());
423 SkASSERT(count > 0 && colors != nullptr);
424 SkASSERT(1 == s.fPixmap.width());
425
426 int iY0;
428 int iSubY SK_INIT_TO_AVOID_WARNING;
429
430 if (s.fBilerp) {
431 SkBitmapProcState::MatrixProc mproc = s.getMatrixProc();
432 uint32_t xy[2];
433
434 mproc(s, xy, 1, x, y);
435
436 iY0 = xy[0] >> 18;
437 iY1 = xy[0] & 0x3FFF;
438 iSubY = (xy[0] >> 14) & 0xF;
439 } else {
440 int yTemp;
441
442 if (s.fInvMatrix.isTranslate()) {
443 yTemp = s.fFilterOneY + y;
444 } else{
445 const SkBitmapProcStateAutoMapper mapper(s, x, y);
446
447 // When the matrix has a scale component the setup code in
448 // chooseProcs multiples the inverse matrix by the inverse of the
449 // bitmap's width and height. Since this method is going to do
450 // its own tiling and sampling we need to undo that here.
451 if (SkTileMode::kClamp != s.fTileModeX || SkTileMode::kClamp != s.fTileModeY) {
452 yTemp = SkFractionalIntToInt(mapper.fractionalIntY() * s.fPixmap.height());
453 } else {
454 yTemp = mapper.intY();
455 }
456 }
457
458 const int stopY = s.fPixmap.height();
459 switch (s.fTileModeY) {
461 iY0 = SkTPin(yTemp, 0, stopY-1);
462 break;
464 iY0 = sk_int_mod(yTemp, stopY);
465 break;
467 default:
468 iY0 = sk_int_mirror(yTemp, stopY);
469 break;
470 }
471
472#ifdef SK_DEBUG
473 {
474 const SkBitmapProcStateAutoMapper mapper(s, x, y);
475 int iY2;
476
477 if (!s.fInvMatrix.isTranslate() &&
478 (SkTileMode::kClamp != s.fTileModeX || SkTileMode::kClamp != s.fTileModeY)) {
479 iY2 = SkFractionalIntToInt(mapper.fractionalIntY() * s.fPixmap.height());
480 } else {
481 iY2 = mapper.intY();
482 }
483
484 switch (s.fTileModeY) {
486 iY2 = SkTPin(iY2, 0, stopY-1);
487 break;
489 iY2 = sk_int_mod(iY2, stopY);
490 break;
492 default:
493 iY2 = sk_int_mirror(iY2, stopY);
494 break;
495 }
496
497 SkASSERT(iY0 == iY2);
498 }
499#endif
500 }
501
502 const SkPMColor* row0 = s.fPixmap.addr32(0, iY0);
504
505 if (s.fBilerp) {
506 const SkPMColor* row1 = s.fPixmap.addr32(0, iY1);
507 filter_32_alpha(iSubY, *row0, *row1, &color, s.fAlphaScale);
508 } else {
509 if (s.fAlphaScale < 256) {
510 color = SkAlphaMulQ(*row0, s.fAlphaScale);
511 } else {
512 color = *row0;
513 }
514 }
515
517}
static void filter_32_alpha(unsigned t, SkPMColor color0, SkPMColor color1, SkPMColor *dstColor, unsigned alphaScale)
static int sk_int_mirror(int x, int n)
#define SK_INIT_TO_AVOID_WARNING
Definition: SkMacros.h:58
DlColor color
void(* MatrixProc)(const SkBitmapProcState &, uint32_t bitmapXY[], int count, int x, int y)

◆ sk_int_mirror()

static int sk_int_mirror ( int  x,
int  n 
)
inlinestatic

Definition at line 356 of file SkBitmapProcState.cpp.

356 {
357 x = sk_int_mod(x, 2 * n);
358 if (x >= n) {
359 x = n + ~(x - n);
360 }
361 return x;
362}

◆ sk_int_mod()

static int sk_int_mod ( int  x,
int  n 
)
inlinestatic

Definition at line 344 of file SkBitmapProcState.cpp.

344 {
345 SkASSERT(n > 0);
346 if ((unsigned)x >= (unsigned)n) {
347 if (x < 0) {
348 x = n + ~(~x % n);
349 } else {
350 x = x % n;
351 }
352 }
353 return x;
354}

◆ valid_for_filtering()

static bool valid_for_filtering ( unsigned  dimension)
static

Definition at line 183 of file SkBitmapProcState.cpp.

183 {
184 // for filtering, width and height must fit in 14bits, since we use steal
185 // 2 bits from each to store our 4bit subpixel data
186 return (dimension & ~0x3FFF) == 0;
187}