Flutter Engine
The Flutter Engine
Functions
PictureShaderTest.cpp File Reference
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPicture.h"
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkSamplingOptions.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTileMode.h"
#include "src/core/SkPicturePriv.h"
#include "src/core/SkResourceCache.h"
#include "tests/Test.h"
#include <cstdint>
#include <initializer_list>

Go to the source code of this file.

Functions

 DEF_TEST (PictureShader_caching, reporter)
 
 DEF_TEST (PictureShader_caching2, reporter)
 

Function Documentation

◆ DEF_TEST() [1/2]

DEF_TEST ( PictureShader_caching  ,
reporter   
)

Definition at line 26 of file PictureShaderTest.cpp.

26 {
27 auto makePicture = [] () {
28 SkPictureRecorder recorder;
29 recorder.beginRecording(100, 100)->drawColor(SK_ColorGREEN);
30 return recorder.finishRecordingAsPicture();
31 };
32
33 sk_sp<SkPicture> picture = makePicture();
35
37
38 {
42 surface->getCanvas()->drawPaint(paint);
43
44 // We should have about 3 refs by now: local + shader + shader cache.
46 }
47
48 // Draw another picture shader to have a chance to purge.
49 {
51 paint.setShader(makePicture()->makeShader(SkTileMode::kRepeat, SkTileMode::kRepeat,
53 surface->getCanvas()->drawPaint(paint);
54
55 }
56
57 // All but the local ref should be gone now.
59}
reporter
Definition: FontMgrTest.cpp:39
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
void drawColor(SkColor color, SkBlendMode mode=SkBlendMode::kSrcOver)
Definition: SkCanvas.h:1182
SkCanvas * beginRecording(const SkRect &bounds, sk_sp< SkBBoxHierarchy > bbh)
sk_sp< SkPicture > finishRecordingAsPicture()
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, SkFilterMode mode, const SkMatrix *localMatrix, const SkRect *tileRect) const
bool unique() const
Definition: SkRefCnt.h:50
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
sk_sp< const SkPicture > picture
Definition: SkRecords.h:299
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static SkImageInfo MakeN32Premul(int width, int height)

◆ DEF_TEST() [2/2]

DEF_TEST ( PictureShader_caching2  ,
reporter   
)

Definition at line 67 of file PictureShaderTest.cpp.

67 {
68 auto picture = []() {
69 SkPictureRecorder recorder;
70 recorder.beginRecording(100, 100)->drawColor(SK_ColorGREEN);
71 return recorder.finishRecordingAsPicture();
72 }();
74
75 struct Data {
76 uint64_t sharedID;
77 int counter;
78 } data = {
80 0,
81 };
82
83 auto counter = [](const SkResourceCache::Rec& rec, void* dataPtr) {
84 if (rec.getKey().getSharedID() == ((Data*)dataPtr)->sharedID) {
85 ((Data*)dataPtr)->counter += 1;
86 }
87 };
88
90 REPORTER_ASSERT(reporter, data.counter == 0);
91
92 // Draw with a view variants of picture-shaders that all use the same picture.
93 // Only expect 1 cache entry for all (since same CTM for all).
95 for (SkTileMode m : {
97 }) {
100 surface->getCanvas()->drawPaint(paint);
101 }
102
103 // Don't expect any additional refs on the picture
105
106 // Check that we did cache something, but only 1 thing
107 data.counter = 0;
109 REPORTER_ASSERT(reporter, data.counter == 1);
110
111 // Now delete the picture, and check the we purge the cache entry
112
113 picture.reset();
115
116 data.counter = 0;
118 REPORTER_ASSERT(reporter, data.counter == 0);
119}
SkTileMode
Definition: SkTileMode.h:13
static uint64_t MakeSharedID(uint32_t pictureID)
Definition: SkPicturePriv.h:40
uint32_t uniqueID() const
Definition: SkPicture.h:155
static void CheckMessages()
static void VisitAll(Visitor, void *context)
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310
struct PathData * Data(SkPath *path)
Definition: path_ops.cc:52
uint64_t getSharedID() const
virtual const Key & getKey() const =0
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63