Flutter Engine
The Flutter Engine
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 123 of file RecorderTest.cpp.

123 {
125
126 SkRecord record;
127 SkRecorder recorder(&record, bigBounds);
128 REPORTER_ASSERT(reporter, recorder.imageInfo().width() > 0 &&
129 recorder.imageInfo().height() > 0);
130}
reporter
Definition: FontMgrTest.cpp:39
#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
102 }
104
105 {
106 SkRecord record;
107 SkRecorder recorder(&record, 100, 100);
108
109 // DrawImageRect is supposed to take a reference
110 recorder.drawImageRect(image.get(), SkRect::MakeWH(100, 100), SkRect::MakeWH(100, 100),
113
114 Tally tally;
115 tally.apply(record);
116
118 }
120}
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< const SkImage > image
Definition: SkRecords.h:269
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
SK_API void DrawImageRect(SkCanvas *canvas, const SkImage *image, const SkRect &src, const SkRect &dst, const SkSamplingOptions &sampling={}, const SkPaint *paint=nullptr, SkCanvas::SrcRectConstraint constraint=SkCanvas::kFast_SrcRectConstraint)
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
Definition: color_source.cc:38
Optional< SkRect > bounds
Definition: SkRecords.h:189
SK_API sk_sp< SkShader > Empty()

Variable Documentation

◆ kRecordTypes

const int kRecordTypes = SK_RECORD_TYPES(COUNT)
static

Definition at line 26 of file RecorderTest.cpp.