Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
PropertyObserver.cpp File Reference
#include "include/core/SkColor.h"
#include "include/core/SkFontMgr.h"
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkStream.h"
#include "modules/skottie/include/Skottie.h"
#include "modules/skottie/include/SkottieProperty.h"
#include "tests/Test.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"

Go to the source code of this file.

Functions

 DEF_TEST (Skottie_Props, reporter)
 
 DEF_TEST (Skottie_Props_Revalidation, reporter)
 

Function Documentation

◆ DEF_TEST() [1/2]

DEF_TEST ( Skottie_Props  ,
reporter   
)

Definition at line 270 of file PropertyObserver.cpp.

270 {
273 auto test_font_manager = sk_make_sp<MockFontMgr>(test_typeface);
274
275 SkMemoryStream stream(gTestJson, strlen(gTestJson));
276 auto observer = sk_make_sp<MockPropertyObserver>();
277
278 auto animation = skottie::Animation::Builder()
279 .setPropertyObserver(observer)
280 .setFontManager(test_font_manager)
281 .make(&stream);
282
283 REPORTER_ASSERT(reporter, animation);
284
285 const auto& colors = observer->colors();
286 REPORTER_ASSERT(reporter, colors.size() == 2);
287 REPORTER_ASSERT(reporter, colors[0].node_name.equals("fill_0"));
288 REPORTER_ASSERT(reporter, colors[0].handle->get() == 0xffff0000);
289 REPORTER_ASSERT(reporter, colors[1].node_name.equals("fill_effect_0"));
290 REPORTER_ASSERT(reporter, colors[1].handle->get() == 0xff00ff00);
291
292 const auto& colorsWithFullKeypath = observer->colorsWithFullKeypath();
293 REPORTER_ASSERT(reporter, colorsWithFullKeypath.size() == 2);
294 REPORTER_ASSERT(reporter, colorsWithFullKeypath[0].node_name.equals("layer_0.fill_0"));
295 REPORTER_ASSERT(reporter, colorsWithFullKeypath[0].handle->get() == 0xffff0000);
296 REPORTER_ASSERT(reporter, colorsWithFullKeypath[1].node_name.equals("layer_0.fill_effect_0"));
297 REPORTER_ASSERT(reporter, colorsWithFullKeypath[1].handle->get() == 0xff00ff00);
298
299 const auto& opacities = observer->opacities();
300 REPORTER_ASSERT(reporter, opacities.size() == 3);
301 REPORTER_ASSERT(reporter, opacities[0].node_name.equals("shape_transform_0"));
302 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(opacities[0].handle->get(), 100));
303 REPORTER_ASSERT(reporter, opacities[1].node_name.equals("layer_0"));
304 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(opacities[1].handle->get(), 50));
305
306 const auto& transforms = observer->transforms();
307 REPORTER_ASSERT(reporter, transforms.size() == 3);
308 REPORTER_ASSERT(reporter, transforms[0].node_name.equals("layer_0"));
309 REPORTER_ASSERT(reporter, transforms[0].handle->get() == skottie::TransformPropertyValue({
310 SkPoint::Make(0, 0),
311 SkPoint::Make(0, 0),
312 SkVector::Make(100, 100),
313 0,
314 0,
315 0
316 }));
317 REPORTER_ASSERT(reporter, transforms[1].node_name.equals("layer_1"));
318 REPORTER_ASSERT(reporter, transforms[1].handle->get() == skottie::TransformPropertyValue({
319 SkPoint::Make(0, 0),
320 SkPoint::Make(25, 25),
321 SkVector::Make(100, 100),
322 0,
323 0,
324 0
325 }));
326 REPORTER_ASSERT(reporter, transforms[2].node_name.equals("shape_transform_0"));
327 REPORTER_ASSERT(reporter, transforms[2].handle->get() == skottie::TransformPropertyValue({
328 SkPoint::Make(0, 0),
329 SkPoint::Make(0, 0),
330 SkVector::Make(50, 50),
331 0,
332 0,
333 0
334 }));
335
336 const auto& texts = observer->texts();
337 REPORTER_ASSERT(reporter, texts.size() == 1);
338 REPORTER_ASSERT(reporter, texts[0].node_name.equals("layer_1"));
341 SkString("inline_text"),
342 100,
343 0, 100,
344 0,
345 120,
346 12,
347 0,
348 0,
350 Shaper::VAlign::kTopBaseline,
351 Shaper::ResizePolicy::kNone,
352 Shaper::LinebreakPolicy::kExplicit,
353 Shaper::Direction::kLTR,
354 Shaper::Capitalization::kNone,
358 TextPaintOrder::kFillStroke,
360 false,
361 false,
362 nullptr,
363 SkString(),
364 SkString("test-family")
365 });
366 REPORTER_ASSERT(reporter, texts[0].handle->get() == text_prop);
367 text_prop.fLocale = "custom_lc";
368 texts[0].handle->set(text_prop);
369 REPORTER_ASSERT(reporter, texts[0].handle->get() == text_prop);
370}
reporter
static void test_typeface(skiatest::Reporter *reporter)
constexpr SkColor SK_ColorTRANSPARENT
Definition SkColor.h:99
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:107
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
@ kDefault_Join
equivalent to kMiter_Join
Definition SkPaint.h:363
Builder & setPropertyObserver(sk_sp< PropertyObserver >)
Definition Skottie.cpp:319
Builder & setFontManager(sk_sp< SkFontMgr >)
Definition Skottie.cpp:314
sk_sp< Animation > make(SkStream *)
Definition Skottie.cpp:349
PODArray< SkColor > colors
Definition SkRecords.h:276
sk_sp< SkTypeface > DefaultPortableTypeface()
static constexpr SkRect MakeEmpty()
Definition SkRect.h:595

◆ DEF_TEST() [2/2]

DEF_TEST ( Skottie_Props_Revalidation  ,
reporter   
)

Definition at line 372 of file PropertyObserver.cpp.

372 {
375 auto test_font_manager = sk_make_sp<MockFontMgr>(test_typeface);
376
377 SkMemoryStream stream(gTestJson, strlen(gTestJson));
378 auto observer = sk_make_sp<MockPropertyObserver>(true);
379
380 auto animation = skottie::Animation::Builder()
381 .setPropertyObserver(observer)
382 .setFontManager(test_font_manager)
383 .make(&stream);
384
385 REPORTER_ASSERT(reporter, animation);
386
387 SkPictureRecorder recorder;
388 // Rendering without seek() should not trigger revalidation asserts.
389 animation->render(recorder.beginRecording(100, 100));
390
391 // Mutate all props.
392 for (const auto& c : observer->colors()) {
393 c.handle->set(SK_ColorGRAY);
394 }
395 for (const auto& o : observer->opacities()) {
396 o.handle->set(0.25f);
397 }
398 for (const auto& t : observer->texts()) {
399 t.handle->set(make_text_prop("bar"));
400 }
401 for (const auto& t : observer->transforms()) {
402 t.handle->set({
403 { 1000, 1000 },
404 { 2000, 2000 },
405 { 20, 20 },
406 5,
407 0,
408 0,
409 });
410 }
411
412 // Rendering without seek() after property mutation should not trigger revalidation asserts.
413 animation->render(recorder.beginRecording(100, 100));
414}
constexpr SkColor SK_ColorGRAY
Definition SkColor.h:113
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)