Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Macros | Functions | Variables
RecorderTest.cpp File Reference
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImage.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkSurface.h"
#include "include/private/base/SkMalloc.h"
#include "src/core/SkRecord.h"
#include "src/core/SkRecorder.h"
#include "src/core/SkRecords.h"
#include "tests/Test.h"

Go to the source code of this file.

Classes

class  Tally
 

Macros

#define COUNT(T)   + 1
 

Functions

 DEF_TEST (Recorder, r)
 
 DEF_TEST (Recorder_RefLeaking, r)
 
 DEF_TEST (Recorder_drawImage_takeReference, reporter)
 
 DEF_TEST (Recorder_boundsOverflow, reporter)
 

Variables

static const int kRecordTypes = SK_RECORD_TYPES(COUNT)
 

Macro Definition Documentation

◆ COUNT

#define COUNT (   T)    + 1

Definition at line 25 of file RecorderTest.cpp.

Function Documentation

◆ DEF_TEST() [1/4]

DEF_TEST ( Recorder  ,
 
)

Definition at line 50 of file RecorderTest.cpp.

50 {
51 SkRecord record;
52 SkRecorder recorder(&record, 1920, 1080);
53
54 recorder.drawRect(SkRect::MakeWH(10, 10), SkPaint());
55
56 Tally tally;
57 tally.apply(record);
58 REPORTER_ASSERT(r, 1 == tally.count<SkRecords::DrawRect>());
59}
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
void apply(const SkRecord &record)
int count() const
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609

◆ DEF_TEST() [2/4]

DEF_TEST ( Recorder_boundsOverflow  ,
reporter   
)

Definition at line 127 of file RecorderTest.cpp.

127 {
129
130 SkRecord record;
131 SkRecorder recorder(&record, bigBounds);
132 REPORTER_ASSERT(reporter, recorder.imageInfo().width() > 0 &&
133 recorder.imageInfo().height() > 0);
134}
reporter
#define SK_ScalarMin
Definition SkScalar.h:25
#define SK_ScalarMax
Definition SkScalar.h:24

◆ DEF_TEST() [3/4]

DEF_TEST ( Recorder_drawImage_takeReference  ,
reporter   
)

Definition at line 81 of file RecorderTest.cpp.

81 {
82
84 {
86 surface->getCanvas()->clear(SK_ColorGREEN);
87 image = surface->makeImageSnapshot();
88 }
89
90 {
91 SkRecord record;
92 SkRecorder recorder(&record, 100, 100);
93
94 // DrawImage is supposed to take a reference
95 recorder.drawImage(image.get(), 0, 0, SkSamplingOptions());
97
98 Tally tally;
99 tally.apply(record);
100
101#if defined(SK_RESOLVE_FILTERS_BEFORE_RESTORE)
102 REPORTER_ASSERT(reporter, 1 == tally.count<SkRecords::DrawImage>());
103#else
104 REPORTER_ASSERT(reporter, 1 == tally.count<SkRecords::DrawImageRect>());
105#endif
106 }
108
109 {
110 SkRecord record;
111 SkRecorder recorder(&record, 100, 100);
112
113 // DrawImageRect is supposed to take a reference
114 recorder.drawImageRect(image.get(), SkRect::MakeWH(100, 100), SkRect::MakeWH(100, 100),
117
118 Tally tally;
119 tally.apply(record);
120
121 REPORTER_ASSERT(reporter, 1 == tally.count<SkRecords::DrawImageRect>());
122 }
124}
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
@ kFast_SrcRectConstraint
sample outside bounds; faster
Definition SkCanvas.h:1543
bool unique() const
Definition SkRefCnt.h:50
T * get() const
Definition SkRefCnt.h:303
VkSurfaceKHR surface
Definition main.cc:49
sk_sp< SkImage > image
Definition examples.cpp:29
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static SkImageInfo MakeN32Premul(int width, int height)

◆ DEF_TEST() [4/4]

DEF_TEST ( Recorder_RefLeaking  ,
 
)

Definition at line 62 of file RecorderTest.cpp.

62 {
63 // We use SaveLayer to test:
64 // - its SkRect argument is optional and SkRect is POD. Just testing that that works.
65 // - its SkPaint argument is optional and SkPaint is not POD. The bug was here.
66
67 SkRect bounds = SkRect::MakeWH(320, 240);
69 paint.setShader(SkShaders::Empty());
70
71 REPORTER_ASSERT(r, paint.getShader()->unique());
72 {
73 SkRecord record;
74 SkRecorder recorder(&record, 1920, 1080);
75 recorder.saveLayer(&bounds, &paint);
76 REPORTER_ASSERT(r, !paint.getShader()->unique());
77 }
78 REPORTER_ASSERT(r, paint.getShader()->unique());
79}
const Paint & paint
Optional< SkRect > bounds
Definition SkRecords.h:189

Variable Documentation

◆ kRecordTypes

const int kRecordTypes = SK_RECORD_TYPES(COUNT)
static

Definition at line 26 of file RecorderTest.cpp.