Flutter Engine
The Flutter Engine
Classes | Macros | Typedefs | Functions
SkAAClip.cpp File Reference
#include "src/core/SkAAClip.h"
#include "include/core/SkClipOp.h"
#include "include/core/SkPath.h"
#include "include/core/SkRegion.h"
#include "include/core/SkTypes.h"
#include "include/private/SkColorData.h"
#include "include/private/base/SkCPUTypes.h"
#include "include/private/base/SkDebug.h"
#include "include/private/base/SkMacros.h"
#include "include/private/base/SkMalloc.h"
#include "include/private/base/SkMath.h"
#include "include/private/base/SkTDArray.h"
#include "include/private/base/SkTo.h"
#include "src/core/SkBlitter.h"
#include "src/core/SkMask.h"
#include "src/core/SkScan.h"
#include <algorithm>
#include <atomic>
#include <cstring>

Go to the source code of this file.

Classes

struct  SkAAClip::RunHead
 
class  SkAAClip::Builder
 
class  SkAAClip::Builder::Blitter
 

Macros

#define AUTO_AACLIP_VALIDATE(clip)
 

Typedefs

typedef void(* MergeAAProc) (const void *src, int width, const uint8_t *row, int initialRowCount, void *dst)
 

Functions

static void count_left_right_zeros (const uint8_t *row, int width, int *leftZ, int *riteZ)
 
static int trim_row_left_right (uint8_t *row, int width, int leftZ, int riteZ)
 
static bool row_is_all_zeros (const uint8_t *row, int width)
 
static void expandToRuns (const uint8_t *SK_RESTRICT data, int initialCount, int width, int16_t *SK_RESTRICT runs, SkAlpha *SK_RESTRICT aa)
 
static void merge (const uint8_t *SK_RESTRICT row, int rowN, const SkAlpha *SK_RESTRICT srcAA, const int16_t *SK_RESTRICT srcRuns, SkAlpha *SK_RESTRICT dstAA, int16_t *SK_RESTRICT dstRuns, int width)
 
static void small_memcpy (void *dst, const void *src, size_t n)
 
static void small_bzero (void *dst, size_t n)
 
static uint8_t mergeOne (uint8_t value, unsigned alpha)
 
static uint16_t mergeOne (uint16_t value, unsigned alpha)
 
template<typename T >
void mergeT (const void *inSrc, int srcN, const uint8_t *SK_RESTRICT row, int rowN, void *inDst)
 
static MergeAAProc find_merge_aa_proc (SkMask::Format format)
 
static U8CPU bit2byte (int bitInAByte)
 
static void upscaleBW2A8 (SkMask *dstMask, const SkMask &srcMask)
 

Macro Definition Documentation

◆ AUTO_AACLIP_VALIDATE

#define AUTO_AACLIP_VALIDATE (   clip)

Definition at line 47 of file SkAAClip.cpp.

Typedef Documentation

◆ MergeAAProc

typedef void(* MergeAAProc) (const void *src, int width, const uint8_t *row, int initialRowCount, void *dst)

Definition at line 1788 of file SkAAClip.cpp.

Function Documentation

◆ bit2byte()

static U8CPU bit2byte ( int  bitInAByte)
static

Definition at line 1861 of file SkAAClip.cpp.

1861 {
1862 SkASSERT(bitInAByte <= 0xFF);
1863 // negation turns any non-zero into 0xFFFFFF??, so we just shift down
1864 // some value >= 8 to get a full FF value
1865 return -bitInAByte >> 8;
1866}
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ count_left_right_zeros()

static void count_left_right_zeros ( const uint8_t *  row,
int  width,
int leftZ,
int riteZ 
)
static

Definition at line 972 of file SkAAClip.cpp.

973 {
974 int zeros = 0;
975 do {
976 if (row[1]) {
977 break;
978 }
979 int n = row[0];
980 SkASSERT(n > 0);
981 SkASSERT(n <= width);
982 zeros += n;
983 row += 2;
984 width -= n;
985 } while (width > 0);
986 *leftZ = zeros;
987
988 if (0 == width) {
989 // this line is completely empty return 'width' in both variables
990 *riteZ = *leftZ;
991 return;
992 }
993
994 zeros = 0;
995 while (width > 0) {
996 int n = row[0];
997 SkASSERT(n > 0);
998 if (0 == row[1]) {
999 zeros += n;
1000 } else {
1001 zeros = 0;
1002 }
1003 row += 2;
1004 width -= n;
1005 }
1006 *riteZ = zeros;
1007}
int32_t width

◆ expandToRuns()

static void expandToRuns ( const uint8_t *SK_RESTRICT  data,
int  initialCount,
int  width,
int16_t *SK_RESTRICT  runs,
SkAlpha *SK_RESTRICT  aa 
)
static

Definition at line 1622 of file SkAAClip.cpp.

1623 {
1624 // we don't read our initial n from data, since the caller may have had to
1625 // clip it, hence the initialCount parameter.
1626 int n = initialCount;
1627 for (;;) {
1628 if (n > width) {
1629 n = width;
1630 }
1631 SkASSERT(n > 0);
1632 runs[0] = n;
1633 runs += n;
1634
1635 aa[0] = data[1];
1636 aa += n;
1637
1638 data += 2;
1639 width -= n;
1640 if (0 == width) {
1641 break;
1642 }
1643 // load the next count
1644 n = data[0];
1645 }
1646 runs[0] = 0; // sentinel
1647}
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ find_merge_aa_proc()

static MergeAAProc find_merge_aa_proc ( SkMask::Format  format)
static

Definition at line 1845 of file SkAAClip.cpp.

1845 {
1846 switch (format) {
1847 case SkMask::kBW_Format:
1848 SkDEBUGFAIL("unsupported");
1849 return nullptr;
1850 case SkMask::kA8_Format:
1851 case SkMask::k3D_Format:
1852 return mergeT<uint8_t> ;
1854 return mergeT<uint16_t>;
1855 default:
1856 SkDEBUGFAIL("unsupported");
1857 return nullptr;
1858 }
1859}
#define SkDEBUGFAIL(message)
Definition: SkAssert.h:118
uint32_t uint32_t * format
@ k3D_Format
3 8bit per pixl planes: alpha, mul, add
Definition: SkMask.h:29
@ kA8_Format
8bits per pixel mask (e.g. antialiasing)
Definition: SkMask.h:28
@ kLCD16_Format
565 alpha for r/g/b
Definition: SkMask.h:31
@ kBW_Format
1bit per pixel mask (e.g. monochrome)
Definition: SkMask.h:27

◆ merge()

static void merge ( const uint8_t *SK_RESTRICT  row,
int  rowN,
const SkAlpha *SK_RESTRICT  srcAA,
const int16_t *SK_RESTRICT  srcRuns,
SkAlpha *SK_RESTRICT  dstAA,
int16_t *SK_RESTRICT  dstRuns,
int  width 
)
static

Definition at line 1691 of file SkAAClip.cpp.

1696 {
1697 SkDEBUGCODE(int accumulated = 0;)
1698 int srcN = srcRuns[0];
1699 // do we need this check?
1700 if (0 == srcN) {
1701 return;
1702 }
1703
1704 for (;;) {
1705 SkASSERT(rowN > 0);
1706 SkASSERT(srcN > 0);
1707
1708 unsigned newAlpha = SkMulDiv255Round(srcAA[0], row[1]);
1709 int minN = std::min(srcN, rowN);
1710 dstRuns[0] = minN;
1711 dstRuns += minN;
1712 dstAA[0] = newAlpha;
1713 dstAA += minN;
1714
1715 if (0 == (srcN -= minN)) {
1716 srcN = srcRuns[0]; // refresh
1717 srcRuns += srcN;
1718 srcAA += srcN;
1719 srcN = srcRuns[0]; // reload
1720 if (0 == srcN) {
1721 break;
1722 }
1723 }
1724 if (0 == (rowN -= minN)) {
1725 row += 2;
1726 rowN = row[0]; // reload
1727 }
1728
1729 SkDEBUGCODE(accumulated += minN;)
1730 SkASSERT(accumulated <= width);
1731 }
1732 dstRuns[0] = 0;
1733}
static U8CPU SkMulDiv255Round(U16CPU a, U16CPU b)
Definition: SkMath.h:73
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
static float min(float r, float g, float b)
Definition: hsl.cpp:48

◆ mergeOne() [1/2]

static uint16_t mergeOne ( uint16_t  value,
unsigned  alpha 
)
inlinestatic

Definition at line 1803 of file SkAAClip.cpp.

1803 {
1804 unsigned r = SkGetPackedR16(value);
1805 unsigned g = SkGetPackedG16(value);
1806 unsigned b = SkGetPackedB16(value);
1807 return SkPackRGB16(SkMulDiv255Round(r, alpha),
1808 SkMulDiv255Round(g, alpha),
1809 SkMulDiv255Round(b, alpha));
1810}
#define SkGetPackedB16(color)
Definition: SkColorData.h:32
#define SkGetPackedG16(color)
Definition: SkColorData.h:31
static uint16_t SkPackRGB16(unsigned r, unsigned g, unsigned b)
Definition: SkColorData.h:141
#define SkGetPackedR16(color)
Definition: SkColorData.h:30
static bool b
uint8_t value

◆ mergeOne() [2/2]

static uint8_t mergeOne ( uint8_t  value,
unsigned  alpha 
)
inlinestatic

Definition at line 1799 of file SkAAClip.cpp.

1799 {
1800 return SkMulDiv255Round(value, alpha);
1801}

◆ mergeT()

template<typename T >
void mergeT ( const void *  inSrc,
int  srcN,
const uint8_t *SK_RESTRICT  row,
int  rowN,
void *  inDst 
)

Definition at line 1813 of file SkAAClip.cpp.

1813 {
1814 const T* SK_RESTRICT src = static_cast<const T*>(inSrc);
1815 T* SK_RESTRICT dst = static_cast<T*>(inDst);
1816 for (;;) {
1817 SkASSERT(rowN > 0);
1818 SkASSERT(srcN > 0);
1819
1820 int n = std::min(rowN, srcN);
1821 unsigned rowA = row[1];
1822 if (0xFF == rowA) {
1823 small_memcpy(dst, src, n * sizeof(T));
1824 } else if (0 == rowA) {
1825 small_bzero(dst, n * sizeof(T));
1826 } else {
1827 for (int i = 0; i < n; ++i) {
1828 dst[i] = mergeOne(src[i], rowA);
1829 }
1830 }
1831
1832 if (0 == (srcN -= n)) {
1833 break;
1834 }
1835
1836 src += n;
1837 dst += n;
1838
1839 SkASSERT(rowN == n);
1840 row += 2;
1841 rowN = row[0];
1842 }
1843}
static void small_memcpy(void *dst, const void *src, size_t n)
Definition: SkAAClip.cpp:1791
static uint8_t mergeOne(uint8_t value, unsigned alpha)
Definition: SkAAClip.cpp:1799
static void small_bzero(void *dst, size_t n)
Definition: SkAAClip.cpp:1795
#define SK_RESTRICT
Definition: SkFeatures.h:42
dst
Definition: cp.py:12
#define T
Definition: precompiler.cc:65

◆ row_is_all_zeros()

static bool row_is_all_zeros ( const uint8_t *  row,
int  width 
)
static

Definition at line 1116 of file SkAAClip.cpp.

1116 {
1117 SkASSERT(width > 0);
1118 do {
1119 if (row[1]) {
1120 return false;
1121 }
1122 int n = row[0];
1123 SkASSERT(n <= width);
1124 width -= n;
1125 row += 2;
1126 } while (width > 0);
1127 SkASSERT(0 == width);
1128 return true;
1129}

◆ small_bzero()

static void small_bzero ( void *  dst,
size_t  n 
)
static

Definition at line 1795 of file SkAAClip.cpp.

1795 {
1796 sk_bzero(dst, n);
1797}
sk_bzero(glyphs, sizeof(glyphs))

◆ small_memcpy()

static void small_memcpy ( void *  dst,
const void *  src,
size_t  n 
)
static

Definition at line 1791 of file SkAAClip.cpp.

1791 {
1792 memcpy(dst, src, n);
1793}

◆ trim_row_left_right()

static int trim_row_left_right ( uint8_t *  row,
int  width,
int  leftZ,
int  riteZ 
)
static

Definition at line 1011 of file SkAAClip.cpp.

1011 {
1012 int trim = 0;
1013 while (leftZ > 0) {
1014 SkASSERT(0 == row[1]);
1015 int n = row[0];
1016 SkASSERT(n > 0);
1017 SkASSERT(n <= width);
1018 width -= n;
1019 row += 2;
1020 if (n > leftZ) {
1021 row[-2] = n - leftZ;
1022 break;
1023 }
1024 trim += 2;
1025 leftZ -= n;
1026 SkASSERT(leftZ >= 0);
1027 }
1028
1029 if (riteZ) {
1030 // walk row to the end, and then we'll back up to trim riteZ
1031 while (width > 0) {
1032 int n = row[0];
1033 SkASSERT(n <= width);
1034 width -= n;
1035 row += 2;
1036 }
1037 // now skip whole runs of zeros
1038 do {
1039 row -= 2;
1040 SkASSERT(0 == row[1]);
1041 int n = row[0];
1042 SkASSERT(n > 0);
1043 if (n > riteZ) {
1044 row[0] = n - riteZ;
1045 break;
1046 }
1047 riteZ -= n;
1048 SkASSERT(riteZ >= 0);
1049 } while (riteZ > 0);
1050 }
1051
1052 return trim;
1053}
static SkCanvas * trim(SkCanvas *canvas, SkScalar width, SkScalar height, const SkRect *content)
Definition: SkDocument.cpp:19

◆ upscaleBW2A8()

static void upscaleBW2A8 ( SkMask dstMask,
const SkMask srcMask 
)
static

Definition at line 1868 of file SkAAClip.cpp.

1868 {
1870 SkASSERT(SkMask::kA8_Format == dstMask->fFormat);
1871
1872 const int width = srcMask.fBounds.width();
1873 const int height = srcMask.fBounds.height();
1874
1875 const uint8_t* SK_RESTRICT src = (const uint8_t*)srcMask.fImage;
1876 const size_t srcRB = srcMask.fRowBytes;
1877 uint8_t* SK_RESTRICT dst = const_cast<uint8_t*>(dstMask->fImage);
1878 const size_t dstRB = dstMask->fRowBytes;
1879
1880 const int wholeBytes = width >> 3;
1881 const int leftOverBits = width & 7;
1882
1883 for (int y = 0; y < height; ++y) {
1884 uint8_t* SK_RESTRICT d = dst;
1885 for (int i = 0; i < wholeBytes; ++i) {
1886 int srcByte = src[i];
1887 d[0] = bit2byte(srcByte & (1 << 7));
1888 d[1] = bit2byte(srcByte & (1 << 6));
1889 d[2] = bit2byte(srcByte & (1 << 5));
1890 d[3] = bit2byte(srcByte & (1 << 4));
1891 d[4] = bit2byte(srcByte & (1 << 3));
1892 d[5] = bit2byte(srcByte & (1 << 2));
1893 d[6] = bit2byte(srcByte & (1 << 1));
1894 d[7] = bit2byte(srcByte & (1 << 0));
1895 d += 8;
1896 }
1897 if (leftOverBits) {
1898 int srcByte = src[wholeBytes];
1899 for (int x = 0; x < leftOverBits; ++x) {
1900 *d++ = bit2byte(srcByte & 0x80);
1901 srcByte <<= 1;
1902 }
1903 }
1904 src += srcRB;
1905 dst += dstRB;
1906 }
1907}
static U8CPU bit2byte(int bitInAByte)
Definition: SkAAClip.cpp:1861
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
double y
double x
int32_t height
constexpr int32_t height() const
Definition: SkRect.h:165
constexpr int32_t width() const
Definition: SkRect.h:158
const uint32_t fRowBytes
Definition: SkMask.h:43
uint8_t const *const fImage
Definition: SkMask.h:41
const SkIRect fBounds
Definition: SkMask.h:42
const Format fFormat
Definition: SkMask.h:44