Flutter Engine
The Flutter Engine
Functions
BackendTextureTest.cpp File Reference
#include "tests/Test.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkSurface.h"
#include "include/gpu/MutableTextureState.h"
#include "include/gpu/graphite/BackendTexture.h"
#include "include/gpu/graphite/Context.h"
#include "include/gpu/graphite/Image.h"
#include "include/gpu/graphite/Recorder.h"
#include "include/gpu/graphite/Surface.h"
#include "include/gpu/vk/VulkanMutableTextureState.h"
#include "include/gpu/vk/VulkanTypes.h"
#include "src/gpu/graphite/Caps.h"
#include "src/gpu/graphite/ContextPriv.h"
#include "src/gpu/graphite/ResourceTypes.h"

Go to the source code of this file.

Functions

 DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS (BackendTextureTest, reporter, context, CtsEnforcement::kNextRelease)
 
 DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS (SurfaceBackendTextureTest, reporter, context, CtsEnforcement::kNextRelease)
 
 DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS (ImageBackendTextureTest, reporter, context, CtsEnforcement::kNextRelease)
 

Function Documentation

◆ DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS() [1/3]

DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS ( BackendTextureTest  ,
reporter  ,
context  ,
CtsEnforcement::kNextRelease   
)

Definition at line 31 of file BackendTextureTest.cpp.

32 {
33 // TODO: Remove this check once Vulkan supports creating default TexutreInfo from caps and we
34 // implement createBackendTexture.
35 if (context->backend() == BackendApi::kVulkan) {
36 return;
37 }
38
39 auto caps = context->priv().caps();
40 auto recorder = context->makeRecorder();
41
42 TextureInfo info = caps->getDefaultSampledTextureInfo(kRGBA_8888_SkColorType,
43 /*mipmapped=*/Mipmapped::kNo,
46 REPORTER_ASSERT(reporter, info.isValid());
47
48 auto texture1 = recorder->createBackendTexture(kSize, info);
49 REPORTER_ASSERT(reporter, texture1.isValid());
50
51 // We make a copy to do the remaining tests so we still have texture1 to safely delete the
52 // backend object.
53 auto texture1Copy = texture1;
54 REPORTER_ASSERT(reporter, texture1Copy.isValid());
55 REPORTER_ASSERT(reporter, texture1 == texture1Copy);
56
57 auto texture2 = recorder->createBackendTexture(kSize, info);
58 REPORTER_ASSERT(reporter, texture2.isValid());
59
60 REPORTER_ASSERT(reporter, texture1Copy != texture2);
61
62 // Test state after assignment
63 texture1Copy = texture2;
64 REPORTER_ASSERT(reporter, texture1Copy.isValid());
65 REPORTER_ASSERT(reporter, texture1Copy == texture2);
66
67 BackendTexture invalidTexture;
68 REPORTER_ASSERT(reporter, !invalidTexture.isValid());
69
70 texture1Copy = invalidTexture;
71 REPORTER_ASSERT(reporter, !texture1Copy.isValid());
72
73 texture1Copy = texture1;
74 REPORTER_ASSERT(reporter, texture1Copy.isValid());
75 REPORTER_ASSERT(reporter, texture1 == texture1Copy);
76
77 recorder->deleteBackendTexture(texture1);
78 recorder->deleteBackendTexture(texture2);
79
80 // Test that deleting is safe from the Context or a different Recorder.
81 texture1 = recorder->createBackendTexture(kSize, info);
82 context->deleteBackendTexture(texture1);
83
84 auto recorder2 = context->makeRecorder();
85 texture1 = recorder->createBackendTexture(kSize, info);
86 recorder2->deleteBackendTexture(texture1);
87}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
reporter
Definition: FontMgrTest.cpp:39
@ 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
@ kVulkan
Definition: embedder.h:86
constexpr int kSize

◆ DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS() [2/3]

DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS ( ImageBackendTextureTest  ,
reporter  ,
context  ,
CtsEnforcement::kNextRelease   
)

Definition at line 152 of file BackendTextureTest.cpp.

153 {
154 // TODO: Right now this just tests very basic combinations of images. This should be expanded
155 // to cover a much broader set of things once we add more support in Graphite for different
156 // formats, color types, etc.
157
158 // TODO: Remove this check once Vulkan supports creating default TexutreInfo from caps and we
159 // implement createBackendTexture.
160 if (context->backend() == BackendApi::kVulkan) {
161 return;
162 }
163
164 const Caps* caps = context->priv().caps();
165 std::unique_ptr<Recorder> recorder = context->makeRecorder();
166
167 for (Mipmapped mipmapped : { Mipmapped::kYes, Mipmapped::kNo }) {
168 for (Renderable renderable : { Renderable::kYes, Renderable::kNo }) {
169
171 mipmapped,
173 renderable);
174
175 BackendTexture texture = recorder->createBackendTexture(kSize, info);
176 REPORTER_ASSERT(reporter, texture.isValid());
177
179 texture,
182 /*colorSpace=*/nullptr);
185
186 image.reset();
187
188 // We should fail when trying to wrap the same texture in an image with a non-compatible
189 // color type.
190 image = SkImages::WrapTexture(recorder.get(),
191 texture,
194 /* colorSpace= */ nullptr);
196
197 recorder->deleteBackendTexture(texture);
198 }
199 }
200}
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
@ kAlpha_8_SkColorType
pixel with alpha in 8-bit byte
Definition: SkColorType.h:21
bool hasMipmaps() const
Definition: SkImage.cpp:292
void reset(T *ptr=nullptr)
Definition: SkRefCnt.h:310
virtual TextureInfo getDefaultSampledTextureInfo(SkColorType, Mipmapped mipmapped, Protected, Renderable) const =0
FlTexture * texture
SK_API sk_sp< SkImage > WrapTexture(skgpu::graphite::Recorder *, const skgpu::graphite::BackendTexture &, SkColorType colorType, SkAlphaType alphaType, sk_sp< SkColorSpace > colorSpace, skgpu::Origin origin, GenerateMipmapsFromBase generateMipmapsFromBase, TextureReleaseProc=nullptr, ReleaseContext=nullptr, std::string_view label={})
sk_sp< const SkImage > image
Definition: SkRecords.h:269
Renderable
Definition: GpuTypes.h:69
Mipmapped
Definition: GpuTypes.h:53

◆ DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS() [3/3]

DEF_GRAPHITE_TEST_FOR_ALL_CONTEXTS ( SurfaceBackendTextureTest  ,
reporter  ,
context  ,
CtsEnforcement::kNextRelease   
)

Definition at line 90 of file BackendTextureTest.cpp.

91 {
92 // TODO: Right now this just tests very basic combinations of surfaces. This should be expanded
93 // to cover a much broader set of things once we add more support in Graphite for different
94 // formats, color types, etc.
95
96 // TODO: Remove this check once Vulkan supports creating default TexutreInfo from caps and we
97 // implement createBackendTexture.
98 if (context->backend() == BackendApi::kVulkan) {
99 return;
100 }
101
102 auto caps = context->priv().caps();
103 std::unique_ptr<Recorder> recorder = context->makeRecorder();
104
105 TextureInfo info = caps->getDefaultSampledTextureInfo(kRGBA_8888_SkColorType,
106 /*mipmapped=*/Mipmapped::kNo,
109
110 auto texture = recorder->createBackendTexture(kSize, info);
111 REPORTER_ASSERT(reporter, texture.isValid());
112
114 texture,
116 /*colorSpace=*/nullptr,
117 /*props=*/nullptr);
119
120 surface.reset();
121
122 // We should fail when trying to wrap the same texture in a surface with a non-compatible
123 // color type.
125 texture,
127 /*colorSpace=*/nullptr,
128 /*props=*/nullptr);
130
131 recorder->deleteBackendTexture(texture);
132
133 // We should fail to wrap a non-renderable texture in a surface.
134 info = caps->getDefaultSampledTextureInfo(kRGBA_8888_SkColorType,
135 /*mipmapped=*/Mipmapped::kNo,
138 texture = recorder->createBackendTexture(kSize, info);
139 REPORTER_ASSERT(reporter, texture.isValid());
140
142 texture,
144 /*colorSpace=*/nullptr,
145 /*props=*/nullptr);
146
148 recorder->deleteBackendTexture(texture);
149}
VkSurfaceKHR surface
Definition: main.cc:49
SK_API sk_sp< SkSurface > WrapBackendTexture(GrRecordingContext *context, const GrBackendTexture &backendTexture, GrSurfaceOrigin origin, int sampleCnt, SkColorType colorType, sk_sp< SkColorSpace > colorSpace, const SkSurfaceProps *surfaceProps, TextureReleaseProc textureReleaseProc=nullptr, ReleaseContext releaseContext=nullptr)