Flutter Engine
The Flutter Engine
RecorderTest.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "tests/Test.h"
9
15
16using namespace skgpu::graphite;
18
19// Tests to make sure the managing of back pointers between Recorder and Device all work properly.
20DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(RecorderDevicePtrTest, reporter, context,
22 std::unique_ptr<Recorder> recorder = context->makeRecorder();
23
25
26 // Add multiple devices to later test different patterns of destruction.
27 sk_sp<Device> device1 = Device::Make(recorder.get(),
28 info,
33 LoadOp::kClear,
34 "RecorderTestTexture");
35 sk_sp<Device> device2 = Device::Make(recorder.get(),
36 info,
41 LoadOp::kClear,
42 "RecorderTestTexture");
43 sk_sp<Device> device3 = Device::Make(recorder.get(),
44 info,
49 LoadOp::kClear,
50 "RecorderTestTexture");
51 sk_sp<Device> device4 = Device::Make(recorder.get(),
52 info,
57 LoadOp::kClear,
58 "RecorderTestTexture");
59 REPORTER_ASSERT(reporter, device1->recorder() == recorder.get());
60 REPORTER_ASSERT(reporter, device2->recorder() == recorder.get());
61 REPORTER_ASSERT(reporter, device3->recorder() == recorder.get());
62 REPORTER_ASSERT(reporter, device4->recorder() == recorder.get());
63 REPORTER_ASSERT(reporter, recorder->priv().deviceIsRegistered(device1.get()));
64 REPORTER_ASSERT(reporter, recorder->priv().deviceIsRegistered(device2.get()));
65 REPORTER_ASSERT(reporter, recorder->priv().deviceIsRegistered(device3.get()));
66 REPORTER_ASSERT(reporter, recorder->priv().deviceIsRegistered(device4.get()));
67
68 // Test freeing a device in the middle, marking it as immutable as ~Surface() our FilterResult
69 // would when done with the device.
70 device2->setImmutable();
71 REPORTER_ASSERT(reporter, device2->recorder() == nullptr);
72 REPORTER_ASSERT(reporter, device2->unique()); // Only the test holds a ref now
73 REPORTER_ASSERT(reporter, !recorder->priv().deviceIsRegistered(device2.get()));
74 device2.reset();
75
76 REPORTER_ASSERT(reporter, recorder->priv().deviceIsRegistered(device1.get()));
77 REPORTER_ASSERT(reporter, recorder->priv().deviceIsRegistered(device3.get()));
78 REPORTER_ASSERT(reporter, recorder->priv().deviceIsRegistered(device4.get()));
79
80 // Test freeing a device that wasn't marked as immutable, which should have its ref dropped
81 // automatically when the recorder flushes.
82 Device* dev4Ptr = device4.get();
83 device4.reset();
84 REPORTER_ASSERT(reporter, dev4Ptr->unique()); // The recorder holds a ref still
85 REPORTER_ASSERT(reporter, recorder->priv().deviceIsRegistered(dev4Ptr));
86 recorder->priv().flushTrackedDevices(); // should delete device4 now
87 REPORTER_ASSERT(reporter, !recorder->priv().deviceIsRegistered(dev4Ptr));
88
89 REPORTER_ASSERT(reporter, recorder->priv().deviceIsRegistered(device1.get()));
90 REPORTER_ASSERT(reporter, recorder->priv().deviceIsRegistered(device3.get()));
91
92 // Delete the recorder and make sure remaining devices no longer have a valid recorder.
93 recorder.reset();
94 REPORTER_ASSERT(reporter, device1->recorder() == nullptr);
95 REPORTER_ASSERT(reporter, device3->recorder() == nullptr);
96
97 // Make sure freeing Devices after recorder doesn't cause any crash. This would get checked
98 // naturually when these devices go out of scope, but manually reseting will give us a better
99 // stack trace if something does go wrong.
100 device1.reset();
101 device3.reset();
102}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
reporter
Definition: FontMgrTest.cpp:39
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
Definition: SkColorType.h:24
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
bool unique() const
Definition: SkRefCnt.h:50
T * get() const
Definition: SkRefCnt.h:303
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310
DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS(RecorderDevicePtrTest, reporter, context, CtsEnforcement::kNextRelease)
SK_API sk_sp< SkDocument > Make(SkWStream *dst, const SkSerialProcs *=nullptr, std::function< void(const SkPicture *)> onEndPage=nullptr)
Mipmapped
Definition: GpuTypes.h:53
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)