Flutter Engine
The Flutter Engine
Classes | Typedefs | Functions | Variables
DrawOpAtlasTest.cpp File Reference
#include "include/core/SkBitmap.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkFont.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkSize.h"
#include "include/core/SkSurfaceProps.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrTypes.h"
#include "include/private/gpu/ganesh/GrTypesPriv.h"
#include "src/gpu/AtlasTypes.h"
#include "src/gpu/SkBackingFit.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrDeferredUpload.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrDrawOpAtlas.h"
#include "src/gpu/ganesh/GrDstProxyView.h"
#include "src/gpu/ganesh/GrOnFlushResourceProvider.h"
#include "src/gpu/ganesh/GrOpFlushState.h"
#include "src/gpu/ganesh/GrSurfaceProxy.h"
#include "src/gpu/ganesh/GrSurfaceProxyView.h"
#include "src/gpu/ganesh/GrXferProcessor.h"
#include "src/gpu/ganesh/SurfaceDrawContext.h"
#include "src/gpu/ganesh/ops/AtlasTextOp.h"
#include "src/gpu/ganesh/ops/GrOp.h"
#include "src/gpu/ganesh/text/GrAtlasManager.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include "tools/fonts/FontToolUtils.h"
#include "tools/gpu/ganesh/AtlasTextOpTools.h"
#include "tools/gpu/ganesh/GrAtlasTools.h"
#include <cstddef>
#include <cstdint>
#include <memory>

Go to the source code of this file.

Classes

class  AssertOnEvict
 
class  TestingUploadTarget
 

Typedefs

using MaskFormat = skgpu::MaskFormat
 

Functions

static void check (skiatest::Reporter *r, GrDrawOpAtlas *atlas, uint32_t expectedActive, uint32_t expectedMax, int expectedAlloced)
 
static bool fill_plot (GrDrawOpAtlas *atlas, GrResourceProvider *resourceProvider, GrDeferredUploadTarget *target, skgpu::AtlasLocator *atlasLocator, int alpha)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (BasicDrawOpAtlas, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (GrAtlasTextOpPreparation, reporter, ctxInfo, CtsEnforcement::kApiLevel_T)
 
void test_atlas_config (skiatest::Reporter *reporter, int maxTextureSize, size_t maxBytes, MaskFormat maskFormat, SkISize expectedDimensions, SkISize expectedPlotDimensions)
 
 DEF_GANESH_TEST (GrDrawOpAtlasConfig_Basic, reporter, options, CtsEnforcement::kApiLevel_T)
 

Variables

static const int kNumPlots = 2
 
static const int kPlotSize = 32
 
static const int kAtlasSize = kNumPlots * kPlotSize
 

Typedef Documentation

◆ MaskFormat

Definition at line 53 of file DrawOpAtlasTest.cpp.

Function Documentation

◆ check()

static void check ( skiatest::Reporter r,
GrDrawOpAtlas atlas,
uint32_t  expectedActive,
uint32_t  expectedMax,
int  expectedAlloced 
)
static

Definition at line 66 of file DrawOpAtlasTest.cpp.

67 {
68 REPORTER_ASSERT(r, expectedActive == atlas->numActivePages());
69 REPORTER_ASSERT(r, expectedMax == atlas->maxPages());
71}
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
static int NumAllocated(const GrDrawOpAtlas *)
sk_sp< const SkImage > atlas
Definition: SkRecords.h:331

◆ DEF_GANESH_TEST()

DEF_GANESH_TEST ( GrDrawOpAtlasConfig_Basic  ,
reporter  ,
options  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 249 of file DrawOpAtlasTest.cpp.

249 {
250 // 1/4 MB
251 test_atlas_config(reporter, 65536, 256 * 1024, MaskFormat::kARGB,
252 { 256, 256 }, { 256, 256 });
253 test_atlas_config(reporter, 65536, 256 * 1024, MaskFormat::kA8,
254 { 512, 512 }, { 256, 256 });
255 // 1/2 MB
256 test_atlas_config(reporter, 65536, 512 * 1024, MaskFormat::kARGB,
257 { 512, 256 }, { 256, 256 });
258 test_atlas_config(reporter, 65536, 512 * 1024, MaskFormat::kA8,
259 { 1024, 512 }, { 256, 256 });
260 // 1 MB
261 test_atlas_config(reporter, 65536, 1024 * 1024, MaskFormat::kARGB,
262 { 512, 512 }, { 256, 256 });
263 test_atlas_config(reporter, 65536, 1024 * 1024, MaskFormat::kA8,
264 { 1024, 1024 }, { 256, 256 });
265 // 2 MB
266 test_atlas_config(reporter, 65536, 2 * 1024 * 1024, MaskFormat::kARGB,
267 { 1024, 512 }, { 256, 256 });
268 test_atlas_config(reporter, 65536, 2 * 1024 * 1024, MaskFormat::kA8,
269 { 2048, 1024 }, { 512, 256 });
270 // 4 MB
271 test_atlas_config(reporter, 65536, 4 * 1024 * 1024, MaskFormat::kARGB,
272 { 1024, 1024 }, { 256, 256 });
273 test_atlas_config(reporter, 65536, 4 * 1024 * 1024, MaskFormat::kA8,
274 { 2048, 2048 }, { 512, 512 });
275 // 8 MB
276 test_atlas_config(reporter, 65536, 8 * 1024 * 1024, MaskFormat::kARGB,
277 { 2048, 1024 }, { 256, 256 });
278 test_atlas_config(reporter, 65536, 8 * 1024 * 1024, MaskFormat::kA8,
279 { 2048, 2048 }, { 512, 512 });
280 // 16 MB (should be same as 8 MB)
281 test_atlas_config(reporter, 65536, 16 * 1024 * 1024, MaskFormat::kARGB,
282 { 2048, 1024 }, { 256, 256 });
283 test_atlas_config(reporter, 65536, 16 * 1024 * 1024, MaskFormat::kA8,
284 { 2048, 2048 }, { 512, 512 });
285
286 // 4MB, restricted texture size
287 test_atlas_config(reporter, 1024, 8 * 1024 * 1024, MaskFormat::kARGB,
288 { 1024, 1024 }, { 256, 256 });
289 test_atlas_config(reporter, 1024, 8 * 1024 * 1024, MaskFormat::kA8,
290 { 1024, 1024 }, { 256, 256 });
291
292 // 3 MB (should be same as 2 MB)
293 test_atlas_config(reporter, 65536, 3 * 1024 * 1024, MaskFormat::kARGB,
294 { 1024, 512 }, { 256, 256 });
295 test_atlas_config(reporter, 65536, 3 * 1024 * 1024, MaskFormat::kA8,
296 { 2048, 1024 }, { 512, 256 });
297
298 // minimum size
299 test_atlas_config(reporter, 65536, 0, MaskFormat::kARGB,
300 { 256, 256 }, { 256, 256 });
301 test_atlas_config(reporter, 65536, 0, MaskFormat::kA8,
302 { 512, 512 }, { 256, 256 });
303}
void test_atlas_config(skiatest::Reporter *reporter, int maxTextureSize, size_t maxBytes, MaskFormat maskFormat, SkISize expectedDimensions, SkISize expectedPlotDimensions)
reporter
Definition: FontMgrTest.cpp:39

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [1/2]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( BasicDrawOpAtlas  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 118 of file DrawOpAtlasTest.cpp.

121 {
122 auto context = ctxInfo.directContext();
123 auto proxyProvider = context->priv().proxyProvider();
124 auto resourceProvider = context->priv().resourceProvider();
125 auto drawingManager = context->priv().drawingManager();
126 const GrCaps* caps = context->priv().caps();
127
128 GrOnFlushResourceProvider onFlushResourceProvider(drawingManager);
129 TestingUploadTarget uploadTarget;
130
131 GrColorType atlasColorType = GrColorType::kAlpha_8;
132 GrBackendFormat format = caps->getDefaultBackendFormat(atlasColorType,
134
135 AssertOnEvict evictor;
137
138 std::unique_ptr<GrDrawOpAtlas> atlas = GrDrawOpAtlas::Make(
139 proxyProvider,
140 format,
141 GrColorTypeToSkColorType(atlasColorType),
142 GrColorTypeBytesPerPixel(atlasColorType),
145 &counter,
147 &evictor,
148 /*label=*/"BasicDrawOpAtlasTest");
149 check(reporter, atlas.get(), 0, 4, 0);
150
151 // Fill up the first level
152 skgpu::AtlasLocator atlasLocators[kNumPlots * kNumPlots];
153 for (int i = 0; i < kNumPlots * kNumPlots; ++i) {
154 bool result = fill_plot(
155 atlas.get(), resourceProvider, &uploadTarget, &atlasLocators[i], i * 32);
157 check(reporter, atlas.get(), 1, 4, 1);
158 }
159
160 atlas->instantiate(&onFlushResourceProvider);
161 check(reporter, atlas.get(), 1, 4, 1);
162
163 // Force allocation of a second level
164 skgpu::AtlasLocator atlasLocator;
165 bool result = fill_plot(atlas.get(), resourceProvider, &uploadTarget, &atlasLocator, 4 * 32);
167 check(reporter, atlas.get(), 2, 4, 2);
168
169 // Simulate a lot of draws using only the first plot. The last texture should be compacted.
170 for (int i = 0; i < 512; ++i) {
171 atlas->setLastUseToken(atlasLocators[0], uploadTarget.tokenTracker()->nextDrawToken());
172 uploadTarget.issueDrawToken();
173 uploadTarget.issueFlushToken();
174 atlas->compact(uploadTarget.tokenTracker()->nextFlushToken());
175 }
176
177 check(reporter, atlas.get(), 1, 4, 1);
178}
static void check(skiatest::Reporter *r, GrDrawOpAtlas *atlas, uint32_t expectedActive, uint32_t expectedMax, int expectedAlloced)
static const int kAtlasSize
static const int kNumPlots
static bool fill_plot(GrDrawOpAtlas *atlas, GrResourceProvider *resourceProvider, GrDeferredUploadTarget *target, skgpu::AtlasLocator *atlasLocator, int alpha)
static constexpr size_t GrColorTypeBytesPerPixel(GrColorType ct)
Definition: GrTypesPriv.h:896
static constexpr SkColorType GrColorTypeToSkColorType(GrColorType ct)
Definition: GrTypesPriv.h:589
GrColorType
Definition: GrTypesPriv.h:540
Definition: GrCaps.h:57
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
Definition: GrCaps.cpp:400
static std::unique_ptr< GrDrawOpAtlas > Make(GrProxyProvider *proxyProvider, const GrBackendFormat &format, SkColorType ct, size_t bpp, int width, int height, int plotWidth, int plotHeight, skgpu::AtlasGenerationCounter *generationCounter, AllowMultitexturing allowMultitexturing, skgpu::PlotEvictionCallback *evictor, std::string_view label)
const skgpu::TokenTracker * tokenTracker() final
T * get() const
Definition: SkRefCnt.h:303
AtlasToken nextFlushToken() const
Definition: AtlasTypes.h:207
AtlasToken nextDrawToken() const
Definition: AtlasTypes.h:214
GAsyncResult * result
uint32_t uint32_t * format

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [2/2]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( GrAtlasTextOpPreparation  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kApiLevel_T   
)

Definition at line 182 of file DrawOpAtlasTest.cpp.

185 {
186 auto dContext = ctxInfo.directContext();
187
188 auto gpu = dContext->priv().getGpu();
189 auto resourceProvider = dContext->priv().resourceProvider();
190
191 auto sdc = skgpu::ganesh::SurfaceDrawContext::Make(dContext,
193 nullptr,
195 {32, 32},
197 /*label=*/"AtlasTextOpPreparation");
198
200 paint.setColor(SK_ColorRED);
201
203 font.setEdging(SkFont::Edging::kAlias);
204
205 const char* text = "a";
206
207 GrOp::Owner op =
208 AtlasTextOpTools::CreateOp(sdc.get(), paint, font, SkMatrix::I(), text, 16, 16);
209 if (!op) {
210 return;
211 }
212
213 auto atlasTextOp = (AtlasTextOp*)op.get();
214 atlasTextOp->finalize(*dContext->priv().caps(), nullptr, GrClampType::kAuto);
215
216 TestingUploadTarget uploadTarget;
217
218 GrOpFlushState flushState(gpu, resourceProvider, uploadTarget.writeableTokenTracker());
219
220 GrSurfaceProxyView surfaceView = sdc->writeSurfaceView();
221 GrOpFlushState::OpArgs opArgs(op.get(),
222 surfaceView,
223 false /*usesMSAASurface*/,
224 nullptr,
228
229 // Modify the atlas manager so it can't allocate any pages. This will force a failure
230 // in the preparation of the text op
231 auto atlasManager = dContext->priv().getAtlasManager();
232 unsigned int numProxies;
233 atlasManager->getViews(MaskFormat::kA8, &numProxies);
234 GrAtlasManagerTools::SetMaxPages(atlasManager, 0);
235
236 flushState.setOpArgs(&opArgs);
237 op->prepare(&flushState);
238 flushState.setOpArgs(nullptr);
239}
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
static void SetMaxPages(GrAtlasManager *, uint32_t maxPages)
std::unique_ptr< GrOp > Owner
Definition: GrOp.h:72
Definition: SkFont.h:35
@ kAlias
no transparent pixels on glyph edges
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
skgpu::TokenTracker * writeableTokenTracker()
static std::unique_ptr< SurfaceDrawContext > Make(GrRecordingContext *, GrColorType, sk_sp< GrSurfaceProxy >, sk_sp< SkColorSpace >, GrSurfaceOrigin, const SkSurfaceProps &)
const Paint & paint
Definition: color_source.cc:38
std::u16string text
SkFont DefaultFont()
font
Font Metadata and Metrics.

◆ fill_plot()

static bool fill_plot ( GrDrawOpAtlas atlas,
GrResourceProvider resourceProvider,
GrDeferredUploadTarget target,
skgpu::AtlasLocator atlasLocator,
int  alpha 
)
static

Definition at line 98 of file DrawOpAtlasTest.cpp.

102 {
104
106 data.allocPixels(ii);
107 data.eraseARGB(alpha, 0, 0, 0);
108
110 code = atlas->addToAtlas(resourceProvider, target, kPlotSize, kPlotSize,
111 data.getAddr(0, 0), atlasLocator);
113}
static const int kPlotSize
uint32_t * target
static SkImageInfo MakeA8(int width, int height)
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ test_atlas_config()

void test_atlas_config ( skiatest::Reporter reporter,
int  maxTextureSize,
size_t  maxBytes,
MaskFormat  maskFormat,
SkISize  expectedDimensions,
SkISize  expectedPlotDimensions 
)

Definition at line 241 of file DrawOpAtlasTest.cpp.

243 {
244 GrDrawOpAtlasConfig config(maxTextureSize, maxBytes);
245 REPORTER_ASSERT(reporter, config.atlasDimensions(maskFormat) == expectedDimensions);
246 REPORTER_ASSERT(reporter, config.plotDimensions(maskFormat) == expectedPlotDimensions);
247}

Variable Documentation

◆ kAtlasSize

const int kAtlasSize = kNumPlots * kPlotSize
static

Definition at line 57 of file DrawOpAtlasTest.cpp.

◆ kNumPlots

const int kNumPlots = 2
static

Definition at line 55 of file DrawOpAtlasTest.cpp.

◆ kPlotSize

const int kPlotSize = 32
static

Definition at line 56 of file DrawOpAtlasTest.cpp.