Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
VerticesTest.cpp File Reference
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSurface.h"
#include "include/core/SkVertices.h"
#include "src/base/SkAutoMalloc.h"
#include "src/core/SkReadBuffer.h"
#include "src/core/SkVerticesPriv.h"
#include "src/core/SkWriteBuffer.h"
#include "tests/Test.h"
#include "tools/ToolUtils.h"
#include <cstdint>

Go to the source code of this file.

Functions

static bool equal (const SkVertices *vert0, const SkVertices *vert1)
 
static void self_test (const sk_sp< SkVertices > &v0, skiatest::Reporter *reporter)
 
 DEF_TEST (Vertices, reporter)
 
static void fill_triangle (SkCanvas *canvas, const SkPoint pts[], SkColor c)
 
 DEF_TEST (Vertices_clipping, reporter)
 

Function Documentation

◆ DEF_TEST() [1/2]

DEF_TEST ( Vertices  ,
reporter   
)

Definition at line 86 of file VerticesTest.cpp.

86 {
87 int vCount = 5;
88 int iCount = 9; // odd value exercises padding logic in encode()
89
90 // color-tex tests
91 const uint32_t texFlags[] = { 0, SkVertices::kHasTexCoords_BuilderFlag };
92 const uint32_t colFlags[] = { 0, SkVertices::kHasColors_BuilderFlag };
93 for (auto texF : texFlags) {
94 for (auto colF : colFlags) {
95 uint32_t flags = texF | colF;
96
98
99 for (int i = 0; i < vCount; ++i) {
100 float x = (float)i;
101 builder.positions()[i].set(x, 1);
102 if (builder.texCoords()) {
103 builder.texCoords()[i].set(x, 2);
104 }
105 if (builder.colors()) {
106 builder.colors()[i] = SkColorSetARGB(0xFF, i, 0x80, 0);
107 }
108 }
109 for (int i = 0; i < iCount; ++i) {
110 builder.indices()[i] = i % vCount;
111 }
112 self_test(builder.detach(), reporter);
113 }
114 }
115
116 {
117 // This has the maximum number of vertices to be rewritten as indexed triangles without
118 // overflowing a 16bit index.
121 REPORTER_ASSERT(reporter, builder.isValid());
122 }
123 {
124 // This has too many to be rewritten.
127 REPORTER_ASSERT(reporter, !builder.isValid());
128 }
129 {
130 // Only two vertices - can't be rewritten.
133 REPORTER_ASSERT(reporter, !builder.isValid());
134 }
135 {
136 // Minimum number of indices to be rewritten.
139 REPORTER_ASSERT(reporter, builder.isValid());
140 }
141 {
142 // Too few indices to be rewritten.
145 REPORTER_ASSERT(reporter, !builder.isValid());
146 }
147}
reporter
static constexpr SkColor SkColorSetARGB(U8CPU a, U8CPU r, U8CPU g, U8CPU b)
Definition SkColor.h:49
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
static void self_test(const sk_sp< SkVertices > &v0, skiatest::Reporter *reporter)
@ kHasTexCoords_BuilderFlag
Definition SkVertices.h:63
@ kHasColors_BuilderFlag
Definition SkVertices.h:64
@ kTriangleFan_VertexMode
Definition SkVertices.h:33
@ kTriangles_VertexMode
Definition SkVertices.h:31
FlutterSemanticsFlag flags
double x

◆ DEF_TEST() [2/2]

DEF_TEST ( Vertices_clipping  ,
reporter   
)

Definition at line 155 of file VerticesTest.cpp.

155 {
156 // A very large triangle has to be geometrically clipped (since its "fast" clipping is
157 // normally done in after building SkFixed coordinates). Check that we handle this.
158 // (and don't assert).
160
161 SkPoint pts[] = { { -10, 1 }, { -10, 2 }, { 1e9f, 1.5f } };
162 fill_triangle(surf->getCanvas(), pts, SK_ColorBLACK);
163
164 ToolUtils::PixelIter iter(surf.get());
165 SkIPoint loc;
166 while (void* addr = iter.next(&loc)) {
167 SkPMColor c = *(SkPMColor*)addr;
168 if (loc.fY == 1) {
169 REPORTER_ASSERT(reporter, c == 0xFF000000);
170 } else {
171 REPORTER_ASSERT(reporter, c == 0);
172 }
173 }
174}
uint32_t SkPMColor
Definition SkColor.h:205
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
static void fill_triangle(SkCanvas *canvas, const SkPoint pts[], SkColor c)
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
int32_t fY
y-axis value
static SkImageInfo MakeN32Premul(int width, int height)

◆ equal()

static bool equal ( const SkVertices vert0,
const SkVertices vert1 
)
static

Definition at line 26 of file VerticesTest.cpp.

26 {
27 SkVerticesPriv v0(vert0->priv()), v1(vert1->priv());
28
29 if (v0.mode() != v1.mode()) {
30 return false;
31 }
32 if (v0.vertexCount() != v1.vertexCount()) {
33 return false;
34 }
35 if (v0.indexCount() != v1.indexCount()) {
36 return false;
37 }
38
39 if (!!v0.texCoords() != !!v1.texCoords()) {
40 return false;
41 }
42 if (!!v0.colors() != !!v1.colors()) {
43 return false;
44 }
45
46 for (int i = 0; i < v0.vertexCount(); ++i) {
47 if (v0.positions()[i] != v1.positions()[i]) {
48 return false;
49 }
50 if (v0.texCoords()) {
51 if (v0.texCoords()[i] != v1.texCoords()[i]) {
52 return false;
53 }
54 }
55 if (v0.colors()) {
56 if (v0.colors()[i] != v1.colors()[i]) {
57 return false;
58 }
59 }
60 }
61 for (int i = 0; i < v0.indexCount(); ++i) {
62 if (v0.indices()[i] != v1.indices()[i]) {
63 return false;
64 }
65 }
66 return true;
67}
SkVerticesPriv priv()

◆ fill_triangle()

static void fill_triangle ( SkCanvas canvas,
const SkPoint  pts[],
SkColor  c 
)
static

Definition at line 149 of file VerticesTest.cpp.

149 {
150 SkColor colors[] = { c, c, c };
151 auto verts = SkVertices::MakeCopy(SkVertices::kTriangles_VertexMode, 3, pts, nullptr, colors);
152 canvas->drawVertices(verts, SkBlendMode::kSrc, SkPaint());
153}
uint32_t SkColor
Definition SkColor.h:37
void drawVertices(const SkVertices *vertices, SkBlendMode mode, const SkPaint &paint)
static sk_sp< SkVertices > MakeCopy(VertexMode mode, int vertexCount, const SkPoint positions[], const SkPoint texs[], const SkColor colors[], int indexCount, const uint16_t indices[])
PODArray< SkColor > colors
Definition SkRecords.h:276

◆ self_test()

static void self_test ( const sk_sp< SkVertices > &  v0,
skiatest::Reporter reporter 
)
static

Definition at line 69 of file VerticesTest.cpp.

69 {
70 SkBinaryWriteBuffer writer({});
71 v0->priv().encode(writer);
72
73 SkAutoMalloc buf(writer.bytesWritten());
74 writer.writeToMemory(buf.get());
75 SkReadBuffer reader(buf.get(), writer.bytesWritten());
76
78
79 REPORTER_ASSERT(reporter, v1 != nullptr);
81 REPORTER_ASSERT(reporter, v1->uniqueID() != 0);
82 REPORTER_ASSERT(reporter, v0->uniqueID() != v1->uniqueID());
83 REPORTER_ASSERT(reporter, equal(v0.get(), v1.get()));
84}
static bool equal(const SkVertices *vert0, const SkVertices *vert1)
void encode(SkWriteBuffer &) const
static sk_sp< SkVertices > Decode(SkReadBuffer &)
uint32_t uniqueID() const
Definition SkVertices.h:97
T * get() const
Definition SkRefCnt.h:303