Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
SkDraw_vertices.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkBlender.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkPoint.h"
#include "include/core/SkPoint3.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkSurfaceProps.h"
#include "include/core/SkTypes.h"
#include "include/core/SkVertices.h"
#include "include/private/SkColorData.h"
#include "include/private/base/SkFloatingPoint.h"
#include "include/private/base/SkTo.h"
#include "src/base/SkArenaAlloc.h"
#include "src/core/SkBlenderBase.h"
#include "src/core/SkConvertPixels.h"
#include "src/core/SkCoreBlitters.h"
#include "src/core/SkDraw.h"
#include "src/core/SkRasterClip.h"
#include "src/core/SkScan.h"
#include "src/core/SkSurfacePriv.h"
#include "src/core/SkVertState.h"
#include "src/core/SkVerticesPriv.h"
#include "src/shaders/SkShaderBase.h"
#include "src/shaders/SkTransformShader.h"
#include "src/shaders/SkTriColorShader.h"
#include <cstddef>
#include <cstdint>
#include <optional>
#include <utility>

Go to the source code of this file.

Functions

static bool texture_to_matrix (const VertState &state, const SkPoint verts[], const SkPoint texs[], SkMatrix *matrix)
 
static SkPMColor4fconvert_colors (const SkColor src[], int count, SkColorSpace *deviceCS, SkArenaAlloc *alloc, bool skipColorXform)
 
static bool compute_is_opaque (const SkColor colors[], int count)
 
static void fill_triangle_2 (const VertState &state, SkBlitter *blitter, const SkRasterClip &rc, const SkPoint dev2[])
 
static void fill_triangle_3 (const VertState &state, SkBlitter *blitter, const SkRasterClip &rc, const SkPoint3 dev3[])
 
static void fill_triangle (const VertState &state, SkBlitter *blitter, const SkRasterClip &rc, const SkPoint dev2[], const SkPoint3 dev3[])
 

Variables

static constexpr int kMaxClippedTrianglePointCount = 4
 

Function Documentation

◆ compute_is_opaque()

static bool compute_is_opaque ( const SkColor  colors[],
int  count 
)
static

Definition at line 90 of file SkDraw_vertices.cpp.

90 {
91 uint32_t c = ~0;
92 for (int i = 0; i < count; ++i) {
93 c &= colors[i];
94 }
95 return SkColorGetA(c) == 0xFF;
96}
int count
#define SkColorGetA(color)
Definition SkColor.h:61
PODArray< SkColor > colors
Definition SkRecords.h:276

◆ convert_colors()

static SkPMColor4f * convert_colors ( const SkColor  src[],
int  count,
SkColorSpace deviceCS,
SkArenaAlloc alloc,
bool  skipColorXform 
)
static

Definition at line 73 of file SkDraw_vertices.cpp.

77 {
79
80 // Passing `nullptr` for the destination CS effectively disables color conversion.
81 auto dstCS = skipColorXform ? nullptr : sk_ref_sp(deviceCS);
84 SkImageInfo dstInfo =
86 SkAssertResult(SkConvertPixels(dstInfo, dst, 0, srcInfo, src, 0));
87 return dst;
88}
kUnpremul_SkAlphaType
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
#define SkAssertResult(cond)
Definition SkAssert.h:123
@ kBGRA_8888_SkColorType
pixel with 8 bits for blue, green, red, alpha; in 32-bit word
Definition SkColorType.h:26
@ kRGBA_F32_SkColorType
pixel using C float for red, green, blue, alpha; in 128-bit word
Definition SkColorType.h:40
bool SkConvertPixels(const SkImageInfo &dstInfo, void *dstPixels, size_t dstRB, const SkImageInfo &srcInfo, const void *srcPixels, size_t srcRB)
sk_sp< T > sk_ref_sp(T *obj)
Definition SkRefCnt.h:381
T * makeArray(size_t count)
static sk_sp< SkColorSpace > MakeSRGB()
dst
Definition cp.py:12
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ fill_triangle()

static void fill_triangle ( const VertState state,
SkBlitter blitter,
const SkRasterClip rc,
const SkPoint  dev2[],
const SkPoint3  dev3[] 
)
static

Definition at line 178 of file SkDraw_vertices.cpp.

179 {
180 if (dev3) {
181 fill_triangle_3(state, blitter, rc, dev3);
182 } else {
183 fill_triangle_2(state, blitter, rc, dev2);
184 }
185}
static void fill_triangle_3(const VertState &state, SkBlitter *blitter, const SkRasterClip &rc, const SkPoint3 dev3[])
static void fill_triangle_2(const VertState &state, SkBlitter *blitter, const SkRasterClip &rc, const SkPoint dev2[])
AtkStateType state

◆ fill_triangle_2()

static void fill_triangle_2 ( const VertState state,
SkBlitter blitter,
const SkRasterClip rc,
const SkPoint  dev2[] 
)
static

Definition at line 98 of file SkDraw_vertices.cpp.

99 {
100 SkPoint tmp[] = {
101 dev2[state.f0], dev2[state.f1], dev2[state.f2]
102 };
103 SkScan::FillTriangle(tmp, rc, blitter);
104}
static void FillTriangle(const SkPoint pts[], const SkRasterClip &, SkBlitter *)

◆ fill_triangle_3()

static void fill_triangle_3 ( const VertState state,
SkBlitter blitter,
const SkRasterClip rc,
const SkPoint3  dev3[] 
)
static

Definition at line 107 of file SkDraw_vertices.cpp.

108 {
109 // Compute the crossing point (across zero) for the two values, expressed as a
110 // normalized 0...1 value. If curr is 0, returns 0. If next is 0, returns 1.
111 auto computeT = [](float curr, float next) {
112 // Check that 0 is between next and curr.
113 SkASSERT((next <= 0 && 0 < curr) || (curr <= 0 && 0 < next));
114 float t = curr / (curr - next);
115 SkASSERT(0 <= t && t <= 1);
116 return t;
117 };
118
119 auto lerp = [](SkPoint3 curr, SkPoint3 next, float t) {
120 return curr + t * (next - curr);
121 };
122
123 constexpr float tol = 0.05f;
124 // tol is the nudge away from zero, to keep the numerics nice.
125 // Think of it as our near-clipping-plane (or w-plane).
126 auto clip = [&](SkPoint3 curr, SkPoint3 next) {
127 // Return the point between curr and next where the fZ value crosses tol.
128 // To be (really) perspective correct, we should be computing based on 1/Z, not Z.
129 // For now, this is close enough (and faster).
130 return lerp(curr, next, computeT(curr.fZ - tol, next.fZ - tol));
131 };
132
133 // Clip a triangle (based on its homogeneous W values), and return the projected polygon.
134 // Since we only clip against one "edge"/plane, the max number of points in the clipped
135 // polygon is 4.
136 auto clipTriangle = [&](SkPoint dst[], const int idx[3], const SkPoint3 pts[]) -> int {
138 SkPoint3* outP = outPoints;
139
140 for (int i = 0; i < 3; ++i) {
141 int curr = idx[i];
142 int next = idx[(i + 1) % 3];
143 if (pts[curr].fZ > tol) {
144 *outP++ = pts[curr];
145 if (pts[next].fZ <= tol) { // curr is IN, next is OUT
146 *outP++ = clip(pts[curr], pts[next]);
147 }
148 } else {
149 if (pts[next].fZ > tol) { // curr is OUT, next is IN
150 *outP++ = clip(pts[curr], pts[next]);
151 }
152 }
153 }
154
155 const int count = SkTo<int>(outP - outPoints);
156 SkASSERT(count == 0 || count == 3 || count == 4);
157 for (int i = 0; i < count; ++i) {
158 float scale = sk_ieee_float_divide(1.0f, outPoints[i].fZ);
159 dst[i].set(outPoints[i].fX * scale, outPoints[i].fY * scale);
160 }
161 return count;
162 };
163
165 int idx[] = { state.f0, state.f1, state.f2 };
166 if (int n = clipTriangle(tmp, idx, dev3)) {
167 // TODO: SkScan::FillConvexPoly(tmp, n, ...);
168 SkASSERT(n == 3 || n == 4);
169 SkScan::FillTriangle(tmp, rc, blitter);
170 if (n == 4) {
171 tmp[1] = tmp[2];
172 tmp[2] = tmp[3];
173 SkScan::FillTriangle(tmp, rc, blitter);
174 }
175 }
176}
static float next(float f)
#define SkASSERT(cond)
Definition SkAssert.h:116
static constexpr int kMaxClippedTrianglePointCount
static constexpr float sk_ieee_float_divide(float numer, float denom)
static SkPath clip(const SkPath &path, const SkHalfPlane &plane)
Definition SkPath.cpp:3824
const Scalar scale
SkScalar fZ
Definition SkPoint3.h:16
static SkPoint lerp(const SkPoint &a, const SkPoint &b, float T)

◆ texture_to_matrix()

static bool texture_to_matrix ( const VertState state,
const SkPoint  verts[],
const SkPoint  texs[],
SkMatrix matrix 
)
static

Definition at line 51 of file SkDraw_vertices.cpp.

52 {
53 SkPoint src[3], dst[3];
54
55 src[0] = verts[state.f0];
56 src[1] = verts[state.f1];
57 src[2] = verts[state.f2];
58 dst[0] = texs[state.f0];
59 dst[1] = texs[state.f1];
60 dst[2] = texs[state.f2];
61 return matrix->setPolyToPoly(src, dst, 3);
62}
unsigned useCenter Optional< SkMatrix > matrix
Definition SkRecords.h:258
PODArray< SkRect > texs
Definition SkRecords.h:333

Variable Documentation

◆ kMaxClippedTrianglePointCount

constexpr int kMaxClippedTrianglePointCount = 4
staticconstexpr

Definition at line 106 of file SkDraw_vertices.cpp.