Flutter Engine
The Flutter Engine
Classes | Macros | Functions
RecordTest.cpp File Reference
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "src/core/SkRecord.h"
#include "src/core/SkRecords.h"
#include "tests/RecordTestUtils.h"
#include "tests/Test.h"
#include <cstdint>
#include <new>

Go to the source code of this file.

Classes

class  AreaSummer
 
struct  Stretch
 

Macros

#define APPEND(record, type, ...)   new (record.append<type>()) type{__VA_ARGS__}
 

Functions

 DEF_TEST (Record, r)
 
 DEF_TEST (Record_defrag, r)
 
template<typename T >
static bool is_aligned (const T *p)
 
 DEF_TEST (Record_Alignment, r)
 

Macro Definition Documentation

◆ APPEND

#define APPEND (   record,
  type,
  ... 
)    new (record.append<type>()) type{__VA_ARGS__}

Definition at line 56 of file RecordTest.cpp.

Function Documentation

◆ DEF_TEST() [1/3]

DEF_TEST ( Record  ,
 
)

Definition at line 59 of file RecordTest.cpp.

59 {
60 SkRecord record;
61
62 // Add a simple DrawRect command.
63 SkRect rect = SkRect::MakeWH(10, 10);
65 APPEND(record, SkRecords::DrawRect, paint, rect);
66
67 // Its area should be 100.
68 AreaSummer summer;
69 summer.apply(record);
70 REPORTER_ASSERT(r, summer.area() == 100);
71
72 // Scale 2x.
73 Stretch stretch;
74 stretch.apply(&record);
75
76 // Now its area should be 100 + 400.
77 summer.apply(record);
78 REPORTER_ASSERT(r, summer.area() == 500);
79}
#define APPEND(record, type,...)
Definition: RecordTest.cpp:56
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
void apply(const SkRecord &record)
Definition: RecordTest.cpp:31
int area() const
Definition: RecordTest.cpp:29
const Paint & paint
Definition: color_source.cc:38
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609
void apply(SkRecord *record)
Definition: RecordTest.cpp:49

◆ DEF_TEST() [2/3]

DEF_TEST ( Record_Alignment  ,
 
)

Definition at line 107 of file RecordTest.cpp.

107 {
108 SkRecord record;
109 REPORTER_ASSERT(r, is_aligned(record.alloc<uint8_t>()));
110 REPORTER_ASSERT(r, is_aligned(record.alloc<uint16_t>()));
111 REPORTER_ASSERT(r, is_aligned(record.alloc<uint32_t>()));
112 REPORTER_ASSERT(r, is_aligned(record.alloc<void*>()));
113
114 // It's not clear if we care that 8-byte values are aligned on 32-bit machines.
115 if (sizeof(void*) == 8) {
116 REPORTER_ASSERT(r, is_aligned(record.alloc<double>()));
117 REPORTER_ASSERT(r, is_aligned(record.alloc<uint64_t>()));
118 }
119}
static bool is_aligned(const T *p)
Definition: RecordTest.cpp:103
T * alloc(size_t count=1)
Definition: SkRecord.h:61

◆ DEF_TEST() [3/3]

DEF_TEST ( Record_defrag  ,
 
)

Definition at line 81 of file RecordTest.cpp.

81 {
82 SkRecord record;
83 APPEND(record, SkRecords::Save);
84 APPEND(record, SkRecords::ClipRect);
85 APPEND(record, SkRecords::NoOp);
86 APPEND(record, SkRecords::DrawRect);
87 APPEND(record, SkRecords::NoOp);
88 APPEND(record, SkRecords::NoOp);
89 APPEND(record, SkRecords::Restore);
90 REPORTER_ASSERT(r, record.count() == 7);
91
92 record.defrag();
93 REPORTER_ASSERT(r, record.count() == 4);
94 assert_type<SkRecords::Save >(r, record, 0);
95 assert_type<SkRecords::ClipRect>(r, record, 1);
96 assert_type<SkRecords::DrawRect>(r, record, 2);
97 assert_type<SkRecords::Restore >(r, record, 3);
98}
int count() const
Definition: SkRecord.h:38
void defrag()
Definition: SkRecord.cpp:30

◆ is_aligned()

template<typename T >
static bool is_aligned ( const T p)
static

Definition at line 103 of file RecordTest.cpp.

103 {
104 return (((uintptr_t)p) & (sizeof(T) - 1)) == 0;
105}
#define T
Definition: precompiler.cc:65