@@ -69,12 +69,13 @@ std::shared_ptr<GlyphAtlas> CreateGlyphAtlas(
6969}
7070
7171Rect PerVertexDataPositionToRect (
72- GlyphAtlasPipeline::VertexShader::PerVertexData data[6 ]) {
72+ std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData>::iterator
73+ data) {
7374 Scalar right = FLT_MIN;
7475 Scalar left = FLT_MAX;
7576 Scalar top = FLT_MAX;
7677 Scalar bottom = FLT_MIN;
77- for (int i = 0 ; i < 6 ; ++i) {
78+ for (int i = 0 ; i < 4 ; ++i) {
7879 right = std::max (right, data[i].position .x );
7980 left = std::min (left, data[i].position .x );
8081 top = std::min (top, data[i].position .y );
@@ -85,13 +86,13 @@ Rect PerVertexDataPositionToRect(
8586}
8687
8788Rect PerVertexDataUVToRect (
88- GlyphAtlasPipeline::VertexShader::PerVertexData data[ 6 ] ,
89+ std::vector< GlyphAtlasPipeline::VertexShader::PerVertexData>::iterator data,
8990 ISize texture_size) {
9091 Scalar right = FLT_MIN;
9192 Scalar left = FLT_MAX;
9293 Scalar top = FLT_MAX;
9394 Scalar bottom = FLT_MIN;
94- for (int i = 0 ; i < 6 ; ++i) {
95+ for (int i = 0 ; i < 4 ; ++i) {
9596 right = std::max (right, data[i].uv .x * texture_size.width );
9697 left = std::min (left, data[i].uv .x * texture_size.width );
9798 top = std::min (top, data[i].uv .y * texture_size.height );
@@ -111,7 +112,7 @@ TEST_P(TextContentsTest, SimpleComputeVertexData) {
111112 GTEST_SKIP () << " Results aren't stable across linux and macos." ;
112113#endif
113114
114- GlyphAtlasPipeline::VertexShader::PerVertexData data[ 6 ] ;
115+ std::vector< GlyphAtlasPipeline::VertexShader::PerVertexData> data ( 4 ) ;
115116
116117 std::shared_ptr<TextFrame> text_frame =
117118 MakeTextFrame (" 1" , " ahem.ttf" , TextOptions{.font_size = 50 });
@@ -128,13 +129,13 @@ TEST_P(TextContentsTest, SimpleComputeVertexData) {
128129 atlas_context, text_frame, /* offset=*/ {0 , 0 });
129130
130131 ISize texture_size = atlas->GetTexture ()->GetSize ();
131- TextContents::ComputeVertexData (data, text_frame, /* scale=*/ 1.0 ,
132+ TextContents::ComputeVertexData (data. data () , text_frame, /* scale=*/ 1.0 ,
132133 /* entity_transform=*/ Matrix (),
133134 /* offset=*/ Vector2 (0 , 0 ),
134135 /* glyph_properties=*/ std::nullopt , atlas);
135136
136- Rect position_rect = PerVertexDataPositionToRect (data);
137- Rect uv_rect = PerVertexDataUVToRect (data, texture_size);
137+ Rect position_rect = PerVertexDataPositionToRect (data. begin () );
138+ Rect uv_rect = PerVertexDataUVToRect (data. begin () , texture_size);
138139 // The -1 offset comes from Skia in `ComputeGlyphSize`. So since the font size
139140 // is 50, the math appears to be to get back a 50x50 rect and apply 1 pixel
140141 // of padding.
@@ -147,8 +148,7 @@ TEST_P(TextContentsTest, SimpleComputeVertexData2x) {
147148 GTEST_SKIP () << " Results aren't stable across linux and macos." ;
148149#endif
149150
150- GlyphAtlasPipeline::VertexShader::PerVertexData data[6 ];
151-
151+ std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData> data (4 );
152152 std::shared_ptr<TextFrame> text_frame =
153153 MakeTextFrame (" 1" , " ahem.ttf" , TextOptions{.font_size = 50 });
154154
@@ -166,15 +166,15 @@ TEST_P(TextContentsTest, SimpleComputeVertexData2x) {
166166
167167 ISize texture_size = atlas->GetTexture ()->GetSize ();
168168 TextContents::ComputeVertexData (
169- data, text_frame, static_cast <Scalar>(font_scale),
169+ data. data () , text_frame, static_cast <Scalar>(font_scale),
170170 /* entity_transform=*/
171171 Matrix::MakeScale ({static_cast <Scalar>(font_scale),
172172 static_cast <Scalar>(font_scale), 1 }),
173173 /* offset=*/ Vector2 (0 , 0 ),
174174 /* glyph_properties=*/ std::nullopt , atlas);
175175
176- Rect position_rect = PerVertexDataPositionToRect (data);
177- Rect uv_rect = PerVertexDataUVToRect (data, texture_size);
176+ Rect position_rect = PerVertexDataPositionToRect (data. begin () );
177+ Rect uv_rect = PerVertexDataUVToRect (data. begin () , texture_size);
178178 EXPECT_RECT_NEAR (position_rect, Rect::MakeXYWH (-1 , -81 , 102 , 102 ));
179179 EXPECT_RECT_NEAR (uv_rect, Rect::MakeXYWH (1.0 , 1.0 , 102 , 102 ));
180180}
@@ -196,24 +196,25 @@ TEST_P(TextContentsTest, MaintainsShape) {
196196 Rect uv_rect[2 ];
197197
198198 {
199- GlyphAtlasPipeline::VertexShader::PerVertexData data[12 ];
199+ std::vector<GlyphAtlasPipeline::VertexShader::PerVertexData> data (12 );
200+
200201 std::shared_ptr<GlyphAtlas> atlas =
201202 CreateGlyphAtlas (*GetContext (), context.get (), *host_buffer,
202203 GlyphAtlas::Type::kAlphaBitmap , font_scale,
203204 atlas_context, text_frame, /* offset=*/ {0 , 0 });
204205 ISize texture_size = atlas->GetTexture ()->GetSize ();
205206
206207 TextContents::ComputeVertexData (
207- data, text_frame, static_cast <Scalar>(font_scale),
208+ data. data () , text_frame, static_cast <Scalar>(font_scale),
208209 /* entity_transform=*/
209210 Matrix::MakeScale ({static_cast <Scalar>(font_scale),
210211 static_cast <Scalar>(font_scale), 1 }),
211212 /* offset=*/ Vector2 (0 , 0 ),
212213 /* glyph_properties=*/ std::nullopt , atlas);
213- position_rect[0 ] = PerVertexDataPositionToRect (data);
214- uv_rect[0 ] = PerVertexDataUVToRect (data, texture_size);
215- position_rect[1 ] = PerVertexDataPositionToRect (data + 6 );
216- uv_rect[1 ] = PerVertexDataUVToRect (data + 6 , texture_size);
214+ position_rect[0 ] = PerVertexDataPositionToRect (data. begin () );
215+ uv_rect[0 ] = PerVertexDataUVToRect (data. begin () , texture_size);
216+ position_rect[1 ] = PerVertexDataPositionToRect (data. begin () + 4 );
217+ uv_rect[1 ] = PerVertexDataUVToRect (data. begin () + 4 , texture_size);
217218 }
218219 EXPECT_NEAR (GetAspectRatio (position_rect[1 ]), GetAspectRatio (uv_rect[1 ]),
219220 0.001 )
@@ -226,7 +227,7 @@ TEST_P(TextContentsTest, SimpleSubpixel) {
226227 GTEST_SKIP () << " Results aren't stable across linux and macos." ;
227228#endif
228229
229- GlyphAtlasPipeline::VertexShader::PerVertexData data[ 6 ] ;
230+ std::vector< GlyphAtlasPipeline::VertexShader::PerVertexData> data ( 4 ) ;
230231
231232 std::shared_ptr<TextFrame> text_frame = MakeTextFrame (
232233 " 1" , " ahem.ttf" , TextOptions{.font_size = 50 , .is_subpixel = true });
@@ -245,12 +246,12 @@ TEST_P(TextContentsTest, SimpleSubpixel) {
245246
246247 ISize texture_size = atlas->GetTexture ()->GetSize ();
247248 TextContents::ComputeVertexData (
248- data, text_frame, /* scale=*/ 1.0 ,
249+ data. data () , text_frame, /* scale=*/ 1.0 ,
249250 /* entity_transform=*/ Matrix::MakeTranslation (offset), offset,
250251 /* glyph_properties=*/ std::nullopt , atlas);
251252
252- Rect position_rect = PerVertexDataPositionToRect (data);
253- Rect uv_rect = PerVertexDataUVToRect (data, texture_size);
253+ Rect position_rect = PerVertexDataPositionToRect (data. begin () );
254+ Rect uv_rect = PerVertexDataUVToRect (data. begin () , texture_size);
254255 // The values at Point(0, 0).
255256 // EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-1, -41, 52, 52));
256257 // EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 52, 52));
@@ -263,7 +264,7 @@ TEST_P(TextContentsTest, SimpleSubpixel3x) {
263264 GTEST_SKIP () << " Results aren't stable across linux and macos." ;
264265#endif
265266
266- GlyphAtlasPipeline::VertexShader::PerVertexData data[ 6 ] ;
267+ std::vector< GlyphAtlasPipeline::VertexShader::PerVertexData> data ( 4 ) ;
267268
268269 std::shared_ptr<TextFrame> text_frame = MakeTextFrame (
269270 " 1" , " ahem.ttf" , TextOptions{.font_size = 50 , .is_subpixel = true });
@@ -283,16 +284,16 @@ TEST_P(TextContentsTest, SimpleSubpixel3x) {
283284
284285 ISize texture_size = atlas->GetTexture ()->GetSize ();
285286 TextContents::ComputeVertexData (
286- data, text_frame, static_cast <Scalar>(font_scale),
287+ data. data () , text_frame, static_cast <Scalar>(font_scale),
287288 /* entity_transform=*/
288289 Matrix::MakeTranslation (offset) *
289290 Matrix::MakeScale ({static_cast <Scalar>(font_scale),
290291 static_cast <Scalar>(font_scale), 1 }),
291292 offset,
292293 /* glyph_properties=*/ std::nullopt , atlas);
293294
294- Rect position_rect = PerVertexDataPositionToRect (data);
295- Rect uv_rect = PerVertexDataUVToRect (data, texture_size);
295+ Rect position_rect = PerVertexDataPositionToRect (data. begin () );
296+ Rect uv_rect = PerVertexDataUVToRect (data. begin () , texture_size);
296297 // Values at Point(0, 0)
297298 // EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-1, -121, 152, 152));
298299 // EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 152, 152));
@@ -307,7 +308,7 @@ TEST_P(TextContentsTest, SimpleSubpixel26) {
307308 GTEST_SKIP () << " Results aren't stable across linux and macos." ;
308309#endif
309310
310- GlyphAtlasPipeline::VertexShader::PerVertexData data[ 6 ] ;
311+ std::vector< GlyphAtlasPipeline::VertexShader::PerVertexData> data ( 4 ) ;
311312
312313 std::shared_ptr<TextFrame> text_frame = MakeTextFrame (
313314 " 1" , " ahem.ttf" , TextOptions{.font_size = 50 , .is_subpixel = true });
@@ -326,12 +327,12 @@ TEST_P(TextContentsTest, SimpleSubpixel26) {
326327
327328 ISize texture_size = atlas->GetTexture ()->GetSize ();
328329 TextContents::ComputeVertexData (
329- data, text_frame, /* scale=*/ 1.0 ,
330+ data. data () , text_frame, /* scale=*/ 1.0 ,
330331 /* entity_transform=*/ Matrix::MakeTranslation (offset), offset,
331332 /* glyph_properties=*/ std::nullopt , atlas);
332333
333- Rect position_rect = PerVertexDataPositionToRect (data);
334- Rect uv_rect = PerVertexDataUVToRect (data, texture_size);
334+ Rect position_rect = PerVertexDataPositionToRect (data. begin () );
335+ Rect uv_rect = PerVertexDataUVToRect (data. begin () , texture_size);
335336 // The values without subpixel.
336337 // EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-1, -41, 52, 52));
337338 // EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 52, 52));
@@ -344,7 +345,7 @@ TEST_P(TextContentsTest, SimpleSubpixel80) {
344345 GTEST_SKIP () << " Results aren't stable across linux and macos." ;
345346#endif
346347
347- GlyphAtlasPipeline::VertexShader::PerVertexData data[ 6 ] ;
348+ std::vector< GlyphAtlasPipeline::VertexShader::PerVertexData> data ( 4 ) ;
348349
349350 std::shared_ptr<TextFrame> text_frame = MakeTextFrame (
350351 " 1" , " ahem.ttf" , TextOptions{.font_size = 50 , .is_subpixel = true });
@@ -363,12 +364,12 @@ TEST_P(TextContentsTest, SimpleSubpixel80) {
363364
364365 ISize texture_size = atlas->GetTexture ()->GetSize ();
365366 TextContents::ComputeVertexData (
366- data, text_frame, /* scale=*/ 1.0 ,
367+ data. data () , text_frame, /* scale=*/ 1.0 ,
367368 /* entity_transform=*/ Matrix::MakeTranslation (offset), offset,
368369 /* glyph_properties=*/ std::nullopt , atlas);
369370
370- Rect position_rect = PerVertexDataPositionToRect (data);
371- Rect uv_rect = PerVertexDataUVToRect (data, texture_size);
371+ Rect position_rect = PerVertexDataPositionToRect (data. begin () );
372+ Rect uv_rect = PerVertexDataUVToRect (data. begin () , texture_size);
372373 // The values without subpixel.
373374 // EXPECT_RECT_NEAR(position_rect, Rect::MakeXYWH(-1, -41, 52, 52));
374375 // EXPECT_RECT_NEAR(uv_rect, Rect::MakeXYWH(1.0, 1.0, 52, 52));
0 commit comments