Flutter Engine
The Flutter Engine
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Classes | Typedefs | Functions
SkRemoteGlyphCacheTest.cpp File Reference
#include "include/core/SkAlphaType.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkColorType.h"
#include "include/core/SkData.h"
#include "include/core/SkFont.h"
#include "include/core/SkFontStyle.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkGraphics.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkSerialProcs.h"
#include "include/core/SkSurface.h"
#include "include/core/SkSurfaceProps.h"
#include "include/core/SkTextBlob.h"
#include "include/core/SkTypeface.h"
#include "include/core/SkTypes.h"
#include "include/gpu/GpuTypes.h"
#include "include/gpu/GrContextOptions.h"
#include "include/gpu/GrDirectContext.h"
#include "include/gpu/GrRecordingContext.h"
#include "include/gpu/ganesh/SkSurfaceGanesh.h"
#include "include/private/base/SkMalloc.h"
#include "include/private/base/SkMutex.h"
#include "include/private/chromium/SkChromeRemoteGlyphCache.h"
#include "include/private/chromium/Slug.h"
#include "src/core/SkFontPriv.h"
#include "src/core/SkGlyph.h"
#include "src/core/SkReadBuffer.h"
#include "src/core/SkStrikeSpec.h"
#include "src/core/SkTHash.h"
#include "src/core/SkTypeface_remote.h"
#include "src/core/SkWriteBuffer.h"
#include "src/gpu/ganesh/GrCaps.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
#include "src/gpu/ganesh/GrShaderCaps.h"
#include "src/text/gpu/SDFTControl.h"
#include "tests/CtsEnforcement.h"
#include "tests/Test.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
#include "tools/fonts/FontToolUtils.h"
#include "tools/fonts/TestEmptyTypeface.h"
#include <cmath>
#include <cstdint>
#include <cstring>
#include <initializer_list>
#include <memory>
#include <optional>
#include <vector>

Go to the source code of this file.

Classes

class  DiscardableManager
 
class  SkRemoteGlyphCacheTest
 

Typedefs

using Slug = sktext::gpu::Slug
 

Functions

sk_sp< SkTextBlobbuildTextBlob (sk_sp< SkTypeface > tf, int glyphCount, int textSize=1)
 
static void compare_blobs (const SkBitmap &expected, const SkBitmap &actual, skiatest::Reporter *reporter, int tolerance=0)
 
sk_sp< SkSurfaceMakeSurface (int width, int height, GrRecordingContext *rContext)
 
SkSurfaceProps FindSurfaceProps (GrRecordingContext *rContext)
 
SkBitmap RasterBlob (sk_sp< SkTextBlob > blob, int width, int height, const SkPaint &paint, GrRecordingContext *rContext, const SkMatrix *matrix=nullptr, SkScalar x=0)
 
SkBitmap RasterBlobThroughSlug (sk_sp< SkTextBlob > blob, int width, int height, const SkPaint &paint, GrRecordingContext *rContext, const SkMatrix *matrix=nullptr, SkScalar x=0)
 
SkBitmap RasterSlug (sk_sp< Slug > slug, int width, int height, const SkPaint &paint, GrRecordingContext *rContext, const SkMatrix *matrix=nullptr, SkScalar x=0)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SkRemoteGlyphCache_StrikeSerialization, reporter, ctxInfo, CtsEnforcement::kNever)
 
static void use_padding_options (GrContextOptions *options)
 
 DEF_GANESH_TEST_FOR_CONTEXTS (SkRemoteGlyphCache_StrikeSerializationSlug, skgpu::IsRenderingContext, reporter, ctxInfo, use_padding_options, CtsEnforcement::kNever)
 
 DEF_GANESH_TEST_FOR_CONTEXTS (SkRemoteGlyphCache_StrikeSerializationSlugForcePath, skgpu::IsRenderingContext, reporter, ctxInfo, use_padding_options, CtsEnforcement::kNever)
 
 DEF_GANESH_TEST_FOR_CONTEXTS (SkRemoteGlyphCache_SlugSerialization, skgpu::IsRenderingContext, reporter, ctxInfo, use_padding_options, CtsEnforcement::kNever)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SkRemoteGlyphCache_ReleaseTypeFace, reporter, ctxInfo, CtsEnforcement::kNever)
 
 DEF_TEST (SkRemoteGlyphCache_StrikeLockingServer, reporter)
 
 DEF_TEST (SkRemoteGlyphCache_StrikeDeletionServer, reporter)
 
 DEF_TEST (SkRemoteGlyphCache_StrikePinningClient, reporter)
 
 DEF_TEST (SkRemoteGlyphCache_ClientMemoryAccounting, reporter)
 
 DEF_TEST (SkRemoteGlyphCache_PurgesServerEntries, reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SkRemoteGlyphCache_DrawTextAsPath, reporter, ctxInfo, CtsEnforcement::kNever)
 
sk_sp< SkTextBlobmake_blob_causing_fallback (sk_sp< SkTypeface > targetTf, const SkTypeface *glyphTf, skiatest::Reporter *reporter)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SkRemoteGlyphCache_DrawTextAsMaskWithPathFallback, reporter, ctxInfo, CtsEnforcement::kNever)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SkRemoteGlyphCache_DrawTextXY, reporter, ctxInfo, CtsEnforcement::kNever)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SkRemoteGlyphCache_DrawTextAsDFT, reporter, ctxInfo, CtsEnforcement::kNever)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SkRemoteGlyphCache_CacheMissReporting, reporter, ctxInfo, CtsEnforcement::kNever)
 
sk_sp< SkTextBlobMakeEmojiBlob (sk_sp< SkTypeface > serverTf, SkScalar textSize, sk_sp< SkTypeface > clientTf=nullptr)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SkRemoteGlyphCache_TypefaceWithNoPaths, reporter, ctxInfo, CtsEnforcement::kNever)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SkRemoteGlyphCache_TypefaceWithPaths_MaskThenPath, reporter, ctxInfo, CtsEnforcement::kNever)
 
 DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS (SkRemoteGlyphCache_TypefaceWithPaths_PathThenMask, reporter, ctxInfo, CtsEnforcement::kNever)
 
 DEF_TEST (SkTypefaceProxy_Basic_Serial, reporter)
 
 DEF_TEST (SkGraphics_Limits, reporter)
 

Typedef Documentation

◆ Slug

Definition at line 68 of file SkRemoteGlyphCacheTest.cpp.

Function Documentation

◆ buildTextBlob()

sk_sp< SkTextBlob > buildTextBlob ( sk_sp< SkTypeface tf,
int  glyphCount,
int  textSize = 1 
)

Definition at line 161 of file SkRemoteGlyphCacheTest.cpp.

161 {
162 SkFont font;
163 SkASSERT(tf);
164 font.setTypeface(tf);
165 font.setHinting(SkFontHinting::kNormal);
166 font.setSize(textSize);
168 font.setSubpixel(true);
169
171 SkRect bounds = SkRect::MakeWH(10, 10);
172 const auto& runBuffer = builder.allocRunPosH(font, glyphCount, 0, &bounds);
173 SkASSERT(runBuffer.utf8text == nullptr);
174 SkASSERT(runBuffer.clusters == nullptr);
175
176 for (int i = 0; i < glyphCount; i++) {
177 runBuffer.glyphs[i] = static_cast<SkGlyphID>(i);
178 runBuffer.pos[i] = SkIntToScalar(i);
179 }
180 return builder.make();
181}
#define SkASSERT(cond)
Definition: SkAssert.h:116
@ kNormal
glyph outlines modified to improve constrast
#define SkIntToScalar(x)
Definition: SkScalar.h:57
uint16_t SkGlyphID
Definition: SkTypes.h:179
Definition: SkFont.h:35
@ kAntiAlias
may have transparent pixels on glyph edges
Optional< SkRect > bounds
Definition: SkRecords.h:189
font
Font Metadata and Metrics.
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609

◆ compare_blobs()

static void compare_blobs ( const SkBitmap expected,
const SkBitmap actual,
skiatest::Reporter reporter,
int  tolerance = 0 
)
static

Definition at line 183 of file SkRemoteGlyphCacheTest.cpp.

184 {
185 SkASSERT(expected.width() == actual.width());
186 SkASSERT(expected.height() == actual.height());
187 for (int i = 0; i < expected.width(); ++i) {
188 for (int j = 0; j < expected.height(); ++j) {
189 SkColor expectedColor = expected.getColor(i, j);
190 SkColor actualColor = actual.getColor(i, j);
191 if (0 == tolerance) {
192 REPORTER_ASSERT(reporter, expectedColor == actualColor);
193 } else {
194 for (int k = 0; k < 4; ++k) {
195 int expectedChannel = (expectedColor >> (k*8)) & 0xff;
196 int actualChannel = (actualColor >> (k*8)) & 0xff;
197 REPORTER_ASSERT(reporter, abs(expectedChannel - actualChannel) <= tolerance);
198 }
199 }
200 }
201 }
202}
reporter
Definition: FontMgrTest.cpp:39
uint32_t SkColor
Definition: SkColor.h:37
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
SkColor getColor(int x, int y) const
Definition: SkBitmap.h:874
int width() const
Definition: SkBitmap.h:149
int height() const
Definition: SkBitmap.h:158
SIN Vec< N, float > abs(const Vec< N, float > &x)
Definition: SkVx.h:707

◆ DEF_GANESH_TEST_FOR_CONTEXTS() [1/3]

DEF_GANESH_TEST_FOR_CONTEXTS ( SkRemoteGlyphCache_SlugSerialization  ,
skgpu::IsRenderingContext  ,
reporter  ,
ctxInfo  ,
use_padding_options  ,
CtsEnforcement::kNever   
)

Definition at line 398 of file SkRemoteGlyphCacheTest.cpp.

403 {
404 auto dContext = ctxInfo.directContext();
405 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
406 SkStrikeServer server(discardableManager.get());
407 SkStrikeClient client(discardableManager, false);
408 const SkPaint paint;
409
410 // Server.
411 auto serverTypeface = ToolUtils::CreateTestTypeface("monospace", SkFontStyle());
412
413 int glyphCount = 10;
414 auto serverBlob = buildTextBlob(serverTypeface, glyphCount);
415 auto props = FindSurfaceProps(dContext);
416 std::unique_ptr<SkCanvas> analysisCanvas = server.makeAnalysisCanvas(
417 10, 10, props, nullptr, dContext->supportsDistanceFieldText(),
418 !dContext->priv().caps()->disablePerspectiveSDFText());
419
420 // Generate strike updates.
421 auto srcSlug = Slug::ConvertBlob(analysisCanvas.get(), *serverBlob, {0.3f, 0}, paint);
422 auto dstSlugData = srcSlug->serialize();
423
424 std::vector<uint8_t> serverStrikeData;
425 server.writeStrikeData(&serverStrikeData);
426
427 // Client.
429 client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
430
431 SkBitmap expected = RasterSlug(srcSlug, 10, 10, paint, dContext);
432 auto dstSlug = client.deserializeSlugForTest(dstSlugData->data(), dstSlugData->size());
433 REPORTER_ASSERT(reporter, dstSlug != nullptr);
434 SkBitmap actual = RasterSlug(dstSlug, 10, 10, paint, dContext);
435 compare_blobs(expected, actual, reporter);
436 REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
437
438 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
439 discardableManager->unlockAndDeleteAll();
440}
SkSurfaceProps FindSurfaceProps(GrRecordingContext *rContext)
SkBitmap RasterSlug(sk_sp< Slug > slug, int width, int height, const SkPaint &paint, GrRecordingContext *rContext, const SkMatrix *matrix=nullptr, SkScalar x=0)
static void compare_blobs(const SkBitmap &expected, const SkBitmap &actual, skiatest::Reporter *reporter, int tolerance=0)
sk_sp< SkTextBlob > buildTextBlob(sk_sp< SkTypeface > tf, int glyphCount, int textSize=1)
T * get() const
Definition: SkRefCnt.h:303
static sk_sp< Slug > ConvertBlob(SkCanvas *canvas, const SkTextBlob &blob, SkPoint origin, const SkPaint &paint)
Definition: Slug.cpp:20
const Paint & paint
Definition: color_source.cc:38
sk_sp< SkTypeface > CreateTestTypeface(const char *name, SkFontStyle style)

◆ DEF_GANESH_TEST_FOR_CONTEXTS() [2/3]

DEF_GANESH_TEST_FOR_CONTEXTS ( SkRemoteGlyphCache_StrikeSerializationSlug  ,
skgpu::IsRenderingContext  ,
reporter  ,
ctxInfo  ,
use_padding_options  ,
CtsEnforcement::kNever   
)

Definition at line 310 of file SkRemoteGlyphCacheTest.cpp.

315 {
316 auto dContext = ctxInfo.directContext();
317 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
318 SkStrikeServer server(discardableManager.get());
319 SkStrikeClient client(discardableManager, false);
320 const SkPaint paint;
321
322 // Server.
323 auto serverTypeface = ToolUtils::CreateTestTypeface("monospace", SkFontStyle());
324 const SkTypefaceID serverTypefaceID = serverTypeface->uniqueID();
325
326 int glyphCount = 10;
327 auto serverBlob = buildTextBlob(serverTypeface, glyphCount);
328 auto props = FindSurfaceProps(dContext);
329 std::unique_ptr<SkCanvas> analysisCanvas = server.makeAnalysisCanvas(
330 10, 10, props, nullptr, dContext->supportsDistanceFieldText(),
331 !dContext->priv().caps()->disablePerspectiveSDFText());
332
333 // Generate strike updates.
334 (void)Slug::ConvertBlob(analysisCanvas.get(), *serverBlob, {0, 0}, paint);
335
336 std::vector<uint8_t> serverStrikeData;
337 server.writeStrikeData(&serverStrikeData);
338
339 // Client.
341 client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
342 auto clientTypeface = client.retrieveTypefaceUsingServerIDForTest(serverTypefaceID);
343 auto clientBlob = buildTextBlob(clientTypeface, glyphCount);
344
345 SkBitmap expected = RasterBlobThroughSlug(serverBlob, 10, 10, paint, dContext);
346 SkBitmap actual = RasterBlobThroughSlug(clientBlob, 10, 10, paint, dContext);
347 compare_blobs(expected, actual, reporter);
348 REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
349
350 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
351 discardableManager->unlockAndDeleteAll();
352}
SkBitmap RasterBlobThroughSlug(sk_sp< SkTextBlob > blob, int width, int height, const SkPaint &paint, GrRecordingContext *rContext, const SkMatrix *matrix=nullptr, SkScalar x=0)
uint32_t SkTypefaceID
Definition: SkTypeface.h:38

◆ DEF_GANESH_TEST_FOR_CONTEXTS() [3/3]

DEF_GANESH_TEST_FOR_CONTEXTS ( SkRemoteGlyphCache_StrikeSerializationSlugForcePath  ,
skgpu::IsRenderingContext  ,
reporter  ,
ctxInfo  ,
use_padding_options  ,
CtsEnforcement::kNever   
)

Definition at line 354 of file SkRemoteGlyphCacheTest.cpp.

359 {
360 auto dContext = ctxInfo.directContext();
361 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
362 SkStrikeServer server(discardableManager.get());
363 SkStrikeClient client(discardableManager, false);
364 const SkPaint paint;
365
366 // Server.
367 auto serverTypeface = ToolUtils::CreateTestTypeface("monospace", SkFontStyle());
368 const SkTypefaceID serverTypefaceID = serverTypeface->uniqueID();
369
370 int glyphCount = 10;
371 auto serverBlob = buildTextBlob(serverTypeface, glyphCount, 360);
372 auto props = FindSurfaceProps(dContext);
373 std::unique_ptr<SkCanvas> analysisCanvas = server.makeAnalysisCanvas(
374 10, 10, props, nullptr, dContext->supportsDistanceFieldText(),
375 !dContext->priv().caps()->disablePerspectiveSDFText());
376
377 // Generate strike updates.
378 (void)Slug::ConvertBlob(analysisCanvas.get(), *serverBlob, {0, 0}, paint);
379
380 std::vector<uint8_t> serverStrikeData;
381 server.writeStrikeData(&serverStrikeData);
382
383 // Client.
385 client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
386 auto clientTypeface = client.retrieveTypefaceUsingServerIDForTest(serverTypefaceID);
387 auto clientBlob = buildTextBlob(clientTypeface, glyphCount, 360);
388
389 SkBitmap expected = RasterBlobThroughSlug(serverBlob, 10, 10, paint, dContext);
390 SkBitmap actual = RasterBlobThroughSlug(clientBlob, 10, 10, paint, dContext);
391 compare_blobs(expected, actual, reporter);
392 REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
393
394 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
395 discardableManager->unlockAndDeleteAll();
396}

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [1/10]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( SkRemoteGlyphCache_CacheMissReporting  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 877 of file SkRemoteGlyphCacheTest.cpp.

880 {
881 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
882 SkStrikeServer server(discardableManager.get());
883 SkStrikeClient client(discardableManager, false);
884
885 auto serverTypeface = ToolUtils::CreateTestTypeface("monospace", SkFontStyle());
886 REPORTER_ASSERT(reporter, serverTypeface);
887
888 // Create the clientTypeface proxy directly from the serverTypeface.
889 auto clientTypeface = sk_make_sp<SkTypefaceProxy>(
890 serverTypeface->uniqueID(),
891 serverTypeface->countGlyphs(),
892 serverTypeface->fontStyle(),
893 serverTypeface->isFixedPitch(),
894 /*glyphMaskNeedsCurrentColor=*/ false,
895 discardableManager,
896 /*isLogging=*/ false);
897
898 REPORTER_ASSERT(reporter, clientTypeface);
899 int glyphCount = 10;
900 auto clientBlob = buildTextBlob(clientTypeface, glyphCount);
901
902 // Raster the client-side blob without the glyph data, we should get cache miss notifications.
905 RasterBlob(clientBlob, 10, 10, paint, ctxInfo.directContext(), &matrix);
907 discardableManager->cacheMissCount(SkStrikeClient::kFontMetrics) == 1);
909 discardableManager->cacheMissCount(SkStrikeClient::kGlyphMetrics) == 10);
910
911 // There shouldn't be any image or path requests, since we mark the glyph as empty on a cache
912 // miss.
913 REPORTER_ASSERT(reporter, discardableManager->cacheMissCount(SkStrikeClient::kGlyphImage) == 0);
914 REPORTER_ASSERT(reporter, discardableManager->cacheMissCount(SkStrikeClient::kGlyphPath) == 0);
915
916 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
917 discardableManager->unlockAndDeleteAll();
918}
SkBitmap RasterBlob(sk_sp< SkTextBlob > blob, int width, int height, const SkPaint &paint, GrRecordingContext *rContext, const SkMatrix *matrix=nullptr, SkScalar x=0)
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [2/10]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( SkRemoteGlyphCache_DrawTextAsDFT  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 823 of file SkRemoteGlyphCacheTest.cpp.

826 {
827 auto direct = ctxInfo.directContext();
828 if (!direct->priv().caps()->shaderCaps()->supportsDistanceFieldText()) {
829 return;
830 }
831 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
832 SkStrikeServer server(discardableManager.get());
833 SkStrikeClient client(discardableManager, false);
836
837 // A scale transform forces fallback to dft.
840 direct->priv().asRecordingContext()->priv().getSDFTControl(true);
842 {0, 0});
843 REPORTER_ASSERT(reporter, control.isSDFT(approximateDeviceTextSize, paint, matrix));
844
845 // Server.
846 auto serverTypeface = ToolUtils::CreateTestTypeface("monospace", SkFontStyle());
847 const SkTypefaceID serverTypefaceID = serverTypeface->uniqueID();
848
849 int glyphCount = 10;
850 auto serverBlob = buildTextBlob(serverTypeface, glyphCount);
851 const SkSurfaceProps props;
852 std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
853 10, 10, props, nullptr, direct->supportsDistanceFieldText(),
854 !direct->priv().caps()->disablePerspectiveSDFText());
855 cache_diff_canvas->concat(matrix);
856 cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
857
858 std::vector<uint8_t> serverStrikeData;
859 server.writeStrikeData(&serverStrikeData);
860
861 // Client.
863 client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
864 auto clientTypeface = client.retrieveTypefaceUsingServerIDForTest(serverTypefaceID);
865 auto clientBlob = buildTextBlob(clientTypeface, glyphCount);
866
867 SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, direct, &matrix);
868 SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, direct, &matrix);
869 compare_blobs(expected, actual, reporter);
870 REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
871
872 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
873 discardableManager->unlockAndDeleteAll();
874}
static SkScalar ApproximateTransformedTextSize(const SkFont &font, const SkMatrix &matrix, const SkPoint &textLocation)
Definition: SkFont.cpp:366
static SkMatrix Scale(SkScalar sx, SkScalar sy)
Definition: SkMatrix.h:75
bool isSDFT(SkScalar approximateDeviceTextSize, const SkPaint &paint, const SkMatrix &matrix) const
Definition: SDFTControl.cpp:69
float SkScalar
Definition: extension.cpp:12
SkFont DefaultFont()

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [3/10]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( SkRemoteGlyphCache_DrawTextAsMaskWithPathFallback  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 737 of file SkRemoteGlyphCacheTest.cpp.

740 {
741 auto direct = ctxInfo.directContext();
742 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
743 SkStrikeServer server(discardableManager.get());
744 SkStrikeClient client(discardableManager, false);
745
747
748 auto serverTypeface = ToolUtils::CreateTypefaceFromResource("fonts/HangingS.ttf");
749 // TODO: when the cq bots can handle this font remove the check.
750 if (serverTypeface == nullptr) {
751 return;
752 }
753 const SkTypefaceID serverTypefaceID = serverTypeface->uniqueID();
754
755 auto serverBlob = make_blob_causing_fallback(serverTypeface, serverTypeface.get(), reporter);
756
757 auto props = FindSurfaceProps(direct);
758 std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
759 10, 10, props, nullptr, direct->supportsDistanceFieldText(),
760 !direct->priv().caps()->disablePerspectiveSDFText());
761 cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
762
763 std::vector<uint8_t> serverStrikeData;
764 server.writeStrikeData(&serverStrikeData);
765
766 // Client.
768 client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
769 auto clientTypeface = client.retrieveTypefaceUsingServerIDForTest(serverTypefaceID);
770 auto clientBlob = make_blob_causing_fallback(clientTypeface, serverTypeface.get(), reporter);
771
772 SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, direct);
773 SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, direct);
774 compare_blobs(expected, actual, reporter);
775 REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
776
777 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
778 discardableManager->unlockAndDeleteAll();
779}
sk_sp< SkTextBlob > make_blob_causing_fallback(sk_sp< SkTypeface > targetTf, const SkTypeface *glyphTf, skiatest::Reporter *reporter)
sk_sp< SkTypeface > CreateTypefaceFromResource(const char *resource, int ttcIndex)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [4/10]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( SkRemoteGlyphCache_DrawTextAsPath  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 657 of file SkRemoteGlyphCacheTest.cpp.

660 {
661 auto direct = ctxInfo.directContext();
662 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
663 SkStrikeServer server(discardableManager.get());
664 SkStrikeClient client(discardableManager, false);
667 paint.setStrokeWidth(0);
671
672 // Server.
673 auto serverTypeface = ToolUtils::CreateTestTypeface("monospace", SkFontStyle());
674 const SkTypefaceID serverTypefaceID = serverTypeface->uniqueID();
675
676 int glyphCount = 10;
677 auto serverBlob = buildTextBlob(serverTypeface, glyphCount);
678 auto props = FindSurfaceProps(direct);
679 std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
680 10, 10, props, nullptr, direct->supportsDistanceFieldText(),
681 !direct->priv().caps()->disablePerspectiveSDFText());
682 cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
683
684 std::vector<uint8_t> serverStrikeData;
685 server.writeStrikeData(&serverStrikeData);
686
687 // Client.
689 client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
690 auto clientTypeface = client.retrieveTypefaceUsingServerIDForTest(serverTypefaceID);
691 auto clientBlob = buildTextBlob(clientTypeface, glyphCount);
692
693 SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, direct);
694 SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, direct);
695 compare_blobs(expected, actual, reporter, 1);
696 REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
697
698 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
699 discardableManager->unlockAndDeleteAll();
700}
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
static bool ShouldDrawAsPath(const SkPaint &paint, const SkFont &font, const SkMatrix &matrix)

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [5/10]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( SkRemoteGlyphCache_DrawTextXY  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 781 of file SkRemoteGlyphCacheTest.cpp.

784 {
785 auto direct = ctxInfo.directContext();
786 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
787 SkStrikeServer server(discardableManager.get());
788 SkStrikeClient client(discardableManager, false);
790 paint.setAntiAlias(true);
791
792 // Server.
793 auto serverTypeface = ToolUtils::CreateTestTypeface("monospace", SkFontStyle());
794 const SkTypefaceID serverTypefaceID = serverTypeface->uniqueID();
795
796 int glyphCount = 10;
797 auto serverBlob = buildTextBlob(serverTypeface, glyphCount);
798 auto props = FindSurfaceProps(direct);
799 std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
800 10, 10, props, nullptr, direct->supportsDistanceFieldText(),
801 !direct->priv().caps()->disablePerspectiveSDFText());
802 cache_diff_canvas->drawTextBlob(serverBlob.get(), 0.5, 0, paint);
803
804 std::vector<uint8_t> serverStrikeData;
805 server.writeStrikeData(&serverStrikeData);
806
807 // Client.
809 client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
810 auto clientTypeface = client.retrieveTypefaceUsingServerIDForTest(serverTypefaceID);
811 auto clientBlob = buildTextBlob(clientTypeface, glyphCount);
812
813 SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, direct, nullptr, 0.5);
814 SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, direct, nullptr, 0.5);
815 compare_blobs(expected, actual, reporter);
816 REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
817
818 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
819 discardableManager->unlockAndDeleteAll();
820}

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [6/10]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( SkRemoteGlyphCache_ReleaseTypeFace  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 442 of file SkRemoteGlyphCacheTest.cpp.

445 {
446 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
447 SkStrikeServer server(discardableManager.get());
448 SkStrikeClient client(discardableManager, false);
449
450 // Server.
451 auto serverTypeface = TestEmptyTypeface::Make();
452 REPORTER_ASSERT(reporter, serverTypeface->unique());
453
454 {
455 const SkPaint paint;
456 int glyphCount = 10;
457 auto serverBlob = buildTextBlob(serverTypeface, glyphCount);
458 const SkSurfaceProps props;
459 std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
460 10, 10, props, nullptr, ctxInfo.directContext()->supportsDistanceFieldText(),
461 !ctxInfo.directContext()->priv().caps()->disablePerspectiveSDFText());
462 cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
463 REPORTER_ASSERT(reporter, !serverTypeface->unique());
464
465 std::vector<uint8_t> serverStrikeData;
466 server.writeStrikeData(&serverStrikeData);
467 }
468 REPORTER_ASSERT(reporter, serverTypeface->unique());
469
470 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
471 discardableManager->unlockAndDeleteAll();
472}
static sk_sp< SkTypeface > Make()

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [7/10]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( SkRemoteGlyphCache_StrikeSerialization  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 260 of file SkRemoteGlyphCacheTest.cpp.

263 {
264 auto dContext = ctxInfo.directContext();
265 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
266 SkStrikeServer server(discardableManager.get());
267 SkStrikeClient client(discardableManager, false);
268 const SkPaint paint;
269
270 // Server.
271 auto serverTypeface = ToolUtils::CreateTestTypeface("monospace", SkFontStyle());
272 const SkTypefaceID serverTypefaceID = serverTypeface->uniqueID();
273
274 int glyphCount = 10;
275 auto serverBlob = buildTextBlob(serverTypeface, glyphCount);
276 auto props = FindSurfaceProps(dContext);
277 std::unique_ptr<SkCanvas> analysisCanvas = server.makeAnalysisCanvas(
278 10, 10, props, nullptr, dContext->supportsDistanceFieldText(),
279 !dContext->priv().caps()->disablePerspectiveSDFText());
280 analysisCanvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
281
282 std::vector<uint8_t> serverStrikeData;
283 server.writeStrikeData(&serverStrikeData);
284
285 // Client.
287 client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
288 auto clientTypeface = client.retrieveTypefaceUsingServerIDForTest(serverTypefaceID);
289
290 // Ensure typeface serialization/deserialization worked.
292 static_cast<SkTypefaceProxy*>(clientTypeface.get())->remoteTypefaceID() ==
293 serverTypefaceID);
294
295 auto clientBlob = buildTextBlob(clientTypeface, glyphCount);
296
297 SkBitmap expected = RasterBlob(serverBlob, 10, 10, paint, dContext);
298 SkBitmap actual = RasterBlob(clientBlob, 10, 10, paint, dContext);
299 compare_blobs(expected, actual, reporter);
300 REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
301
302 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
303 discardableManager->unlockAndDeleteAll();
304}
SkTypefaceID remoteTypefaceID() const

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [8/10]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( SkRemoteGlyphCache_TypefaceWithNoPaths  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 944 of file SkRemoteGlyphCacheTest.cpp.

947 {
948 auto direct = ctxInfo.directContext();
949 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
950 SkStrikeServer server(discardableManager.get());
951 SkStrikeClient client(discardableManager, false);
952
953 auto serverTypeface = ToolUtils::EmojiSample().typeface;
954 const SkTypefaceID serverTypefaceID = serverTypeface->uniqueID();
955
956 auto props = FindSurfaceProps(direct);
957 std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
958 500, 500, props, nullptr, direct->supportsDistanceFieldText(),
959 !direct->priv().caps()->disablePerspectiveSDFText());
960 for (SkScalar textSize : { 70, 180, 270, 340}) {
961 auto serverBlob = MakeEmojiBlob(serverTypeface, textSize);
962
964 cache_diff_canvas->drawTextBlob(serverBlob.get(), 100, 100, paint);
965
966 std::vector<uint8_t> serverStrikeData;
967 server.writeStrikeData(&serverStrikeData);
968 if (!serverStrikeData.empty()) {
970 client.readStrikeData(serverStrikeData.data(),
971 serverStrikeData.size()));
972 }
973 auto clientTypeface = client.retrieveTypefaceUsingServerIDForTest(serverTypefaceID);
974 auto clientBlob = MakeEmojiBlob(serverTypeface, textSize, clientTypeface);
975 REPORTER_ASSERT(reporter, clientBlob);
976
977 RasterBlob(clientBlob, 500, 500, paint, direct);
978 REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
979 discardableManager->resetCacheMissCounts();
980 }
981
982 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
983 discardableManager->unlockAndDeleteAll();
984}
sk_sp< SkTextBlob > MakeEmojiBlob(sk_sp< SkTypeface > serverTf, SkScalar textSize, sk_sp< SkTypeface > clientTf=nullptr)
SkTypefaceID uniqueID() const
Definition: SkTypeface.h:101
EmojiTestSample EmojiSample()
sk_sp< SkTypeface > typeface
Definition: FontToolUtils.h:48

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [9/10]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( SkRemoteGlyphCache_TypefaceWithPaths_MaskThenPath  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 1019 of file SkRemoteGlyphCacheTest.cpp.

1022 {
1023 auto direct = ctxInfo.directContext();
1024 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
1025 SkStrikeServer server(discardableManager.get());
1026 SkStrikeClient client(discardableManager, true);
1027
1028 auto serverTypeface = ToolUtils::DefaultPortableTypeface();
1029 const SkTypefaceID serverTypefaceID = serverTypeface->uniqueID();
1030
1031 auto props = FindSurfaceProps(direct);
1032 std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
1033 500, 500, props, nullptr, direct->supportsDistanceFieldText(),
1034 !direct->priv().caps()->disablePerspectiveSDFText());
1035 SkPaint paint;
1036 using Rgct = SkRemoteGlyphCacheTest;
1037
1038 // Draw from mask out of the strike which provides paths.
1039 {
1040 auto serverBlob = Rgct::MakeNormalBlob(&paint, serverTypeface, true, 64);
1041 cache_diff_canvas->drawTextBlob(serverBlob.get(), 100, 100, paint);
1042 }
1043 // Draw from path out of the strike which provides paths.
1044 {
1045 auto serverBlob = Rgct::MakeNormalBlob(&paint, serverTypeface, false, 440);
1046 cache_diff_canvas->drawTextBlob(serverBlob.get(), 100, 100, paint);
1047 }
1048 std::vector<uint8_t> serverStrikeData;
1049 server.writeStrikeData(&serverStrikeData);
1050 if (!serverStrikeData.empty()) {
1052 client.readStrikeData(serverStrikeData.data(),
1053 serverStrikeData.size()));
1054 }
1055
1056 auto clientTypeface = client.retrieveTypefaceUsingServerIDForTest(serverTypefaceID);
1057
1058 {
1059 auto clientBlob = Rgct::MakeNormalBlob(&paint, serverTypeface, true, 64, clientTypeface);
1060 REPORTER_ASSERT(reporter, clientBlob);
1061
1062 RasterBlob(clientBlob, 100, 100, paint, direct);
1063 REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
1064 discardableManager->resetCacheMissCounts();
1065 }
1066 {
1067 auto clientBlob = Rgct::MakeNormalBlob(&paint, serverTypeface, false, 440, clientTypeface);
1068 REPORTER_ASSERT(reporter, clientBlob);
1069
1070 RasterBlob(clientBlob, 100, 100, paint, direct);
1071 REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
1072 discardableManager->resetCacheMissCounts();
1073 }
1074 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
1075 discardableManager->unlockAndDeleteAll();
1076}
sk_sp< SkTypeface > DefaultPortableTypeface()

◆ DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS() [10/10]

DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS ( SkRemoteGlyphCache_TypefaceWithPaths_PathThenMask  ,
reporter  ,
ctxInfo  ,
CtsEnforcement::kNever   
)

Definition at line 1078 of file SkRemoteGlyphCacheTest.cpp.

1081 {
1082 auto direct = ctxInfo.directContext();
1083 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
1084 SkStrikeServer server(discardableManager.get());
1085 SkStrikeClient client(discardableManager, true);
1086
1087 auto serverTypeface = ToolUtils::DefaultPortableTypeface();
1088 const SkTypefaceID serverTypefaceID = serverTypeface->uniqueID();
1089
1090 auto props = FindSurfaceProps(direct);
1091 std::unique_ptr<SkCanvas> cache_diff_canvas = server.makeAnalysisCanvas(
1092 500, 500, props, nullptr, direct->supportsDistanceFieldText(),
1093 !direct->priv().caps()->disablePerspectiveSDFText());
1094 SkPaint paint;
1095 using Rgct = SkRemoteGlyphCacheTest;
1096
1097 // Draw from path out of the strike which provides paths.
1098 {
1099 auto serverBlob = Rgct::MakeNormalBlob(&paint, serverTypeface, false, 440);
1100 cache_diff_canvas->drawTextBlob(serverBlob.get(), 100, 100, paint);
1101 }
1102 // Draw from mask out of the strike which provides paths.
1103 {
1104 auto serverBlob = Rgct::MakeNormalBlob(&paint, serverTypeface, true, 64);
1105 cache_diff_canvas->drawTextBlob(serverBlob.get(), 100, 100, paint);
1106 }
1107 std::vector<uint8_t> serverStrikeData;
1108 server.writeStrikeData(&serverStrikeData);
1109 if (!serverStrikeData.empty()) {
1111 client.readStrikeData(serverStrikeData.data(),
1112 serverStrikeData.size()));
1113 }
1114
1115 auto clientTypeface = client.retrieveTypefaceUsingServerIDForTest(serverTypefaceID);
1116
1117 {
1118 auto clientBlob = Rgct::MakeNormalBlob(&paint, serverTypeface, true, 64, clientTypeface);
1119 REPORTER_ASSERT(reporter, clientBlob);
1120
1121 RasterBlob(clientBlob, 100, 100, paint, direct);
1122 REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
1123 discardableManager->resetCacheMissCounts();
1124 }
1125 {
1126 auto clientBlob = Rgct::MakeNormalBlob(&paint, serverTypeface, false, 440, clientTypeface);
1127 REPORTER_ASSERT(reporter, clientBlob);
1128
1129 RasterBlob(clientBlob, 100, 100, paint, direct);
1130 REPORTER_ASSERT(reporter, !discardableManager->hasCacheMiss());
1131 discardableManager->resetCacheMissCounts();
1132 }
1133 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
1134 discardableManager->unlockAndDeleteAll();
1135}

◆ DEF_TEST() [1/7]

DEF_TEST ( SkGraphics_Limits  ,
reporter   
)

Definition at line 1165 of file SkRemoteGlyphCacheTest.cpp.

1165 {
1166 const auto prev1 = SkGraphics::GetTypefaceCacheCountLimit();
1167
1168 auto prev2 = SkGraphics::SetTypefaceCacheCountLimit(prev1 + 1);
1169 REPORTER_ASSERT(reporter, prev1 == prev2);
1171 REPORTER_ASSERT(reporter, prev2 == prev1 + 1);
1172
1173 SkGraphics::SetTypefaceCacheCountLimit(prev1); // restore orig
1174}
static int SetTypefaceCacheCountLimit(int count)
Definition: SkGraphics.cpp:87
static int GetTypefaceCacheCountLimit()
Definition: SkGraphics.cpp:83

◆ DEF_TEST() [2/7]

DEF_TEST ( SkRemoteGlyphCache_ClientMemoryAccounting  ,
reporter   
)

Definition at line 583 of file SkRemoteGlyphCacheTest.cpp.

583 {
584 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
585 SkStrikeServer server(discardableManager.get());
586 SkStrikeClient client(discardableManager, false);
587
588 // Server.
589 auto serverTypeface = ToolUtils::CreateTestTypeface("monospace", SkFontStyle());
590
591 int glyphCount = 10;
592 auto serverBlob = buildTextBlob(serverTypeface, glyphCount);
593
594 const SkSurfaceProps props;
595 std::unique_ptr<SkCanvas> cache_diff_canvas =
596 server.makeAnalysisCanvas(10, 10, props, nullptr, true, true);
598 cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
599
600 std::vector<uint8_t> serverStrikeData;
601 server.writeStrikeData(&serverStrikeData);
602
603 // Client.
605 client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
606
607 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
608 discardableManager->unlockAndDeleteAll();
609}

◆ DEF_TEST() [3/7]

DEF_TEST ( SkRemoteGlyphCache_PurgesServerEntries  ,
reporter   
)

Definition at line 611 of file SkRemoteGlyphCacheTest.cpp.

611 {
612 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
613 SkStrikeServer server(discardableManager.get());
614 server.setMaxEntriesInDescriptorMapForTesting(1u);
615 SkStrikeClient client(discardableManager, false);
616
617 {
618 auto serverTypeface = ToolUtils::CreateTestTypeface("monospace", SkFontStyle());
619 int glyphCount = 10;
620 auto serverBlob = buildTextBlob(serverTypeface, glyphCount);
621
622 const SkSurfaceProps props;
623 std::unique_ptr<SkCanvas> cache_diff_canvas =
624 server.makeAnalysisCanvas(10, 10, props, nullptr, true, true);
626 REPORTER_ASSERT(reporter, server.remoteStrikeMapSizeForTesting() == 0u);
627 cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
628 REPORTER_ASSERT(reporter, server.remoteStrikeMapSizeForTesting() == 1u);
629 }
630
631 // Serialize to release the lock from the strike server and delete all current
632 // handles.
633 std::vector<uint8_t> fontData;
634 server.writeStrikeData(&fontData);
635 discardableManager->unlockAndDeleteAll();
636
637 // Use a different typeface. Creating a new strike should evict the previous
638 // one.
639 {
640 auto serverTypeface = ToolUtils::CreateTestTypeface("Georgia", SkFontStyle());
641 int glyphCount = 10;
642 auto serverBlob = buildTextBlob(serverTypeface, glyphCount);
643
644 const SkSurfaceProps props;
645 std::unique_ptr<SkCanvas> cache_diff_canvas =
646 server.makeAnalysisCanvas(10, 10, props, nullptr, true, true);
648 REPORTER_ASSERT(reporter, server.remoteStrikeMapSizeForTesting() == 1u);
649 cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
650 REPORTER_ASSERT(reporter, server.remoteStrikeMapSizeForTesting() == 1u);
651 }
652
653 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
654 discardableManager->unlockAndDeleteAll();
655}

◆ DEF_TEST() [4/7]

DEF_TEST ( SkRemoteGlyphCache_StrikeDeletionServer  ,
reporter   
)

Definition at line 508 of file SkRemoteGlyphCacheTest.cpp.

508 {
509 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
510 SkStrikeServer server(discardableManager.get());
511 SkStrikeClient client(discardableManager, false);
512
513 auto serverTypeface = ToolUtils::CreateTestTypeface("monospace", SkFontStyle());
514 int glyphCount = 10;
515 auto serverBlob = buildTextBlob(serverTypeface, glyphCount);
516
517 const SkSurfaceProps props;
518 std::unique_ptr<SkCanvas> cache_diff_canvas =
519 server.makeAnalysisCanvas(10, 10, props, nullptr, true, true);
521 cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
522 REPORTER_ASSERT(reporter, discardableManager->handleCount() == 1u);
523
524 // Write the strike data and delete all the handles. Re-analyzing the blob should create new
525 // handles.
526 std::vector<uint8_t> fontData;
527 server.writeStrikeData(&fontData);
528
529 // Another analysis pass, to ensure that deleting handles after a complete cache hit still
530 // works. This is a regression test for crbug.com/999682.
531 cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
532 server.writeStrikeData(&fontData);
533 REPORTER_ASSERT(reporter, discardableManager->handleCount() == 1u);
534
535 discardableManager->unlockAndDeleteAll();
536 cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
537 REPORTER_ASSERT(reporter, discardableManager->handleCount() == 2u);
538
539 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
540 discardableManager->unlockAndDeleteAll();
541}

◆ DEF_TEST() [5/7]

DEF_TEST ( SkRemoteGlyphCache_StrikeLockingServer  ,
reporter   
)

Definition at line 474 of file SkRemoteGlyphCacheTest.cpp.

474 {
475 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
476 SkStrikeServer server(discardableManager.get());
477 SkStrikeClient client(discardableManager, false);
478
479 auto serverTypeface = ToolUtils::CreateTestTypeface("monospace", SkFontStyle());
480 int glyphCount = 10;
481 auto serverBlob = buildTextBlob(serverTypeface, glyphCount);
482
483 const SkSurfaceProps props;
484 std::unique_ptr<SkCanvas> cache_diff_canvas =
485 server.makeAnalysisCanvas(10, 10, props, nullptr, true, true);
487 cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
488
489 // The strike from the blob should be locked after it has been drawn on the canvas.
490 REPORTER_ASSERT(reporter, discardableManager->handleCount() == 1u);
491 REPORTER_ASSERT(reporter, discardableManager->lockedHandles().count() == 1u);
492
493 // Write the strike data and unlock everything. Re-analyzing the blob should lock the handle
494 // again.
495 std::vector<uint8_t> fontData;
496 server.writeStrikeData(&fontData);
497 discardableManager->unlockAll();
498 REPORTER_ASSERT(reporter, discardableManager->lockedHandles().count() == 0u);
499
500 cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
501 REPORTER_ASSERT(reporter, discardableManager->handleCount() == 1u);
502 REPORTER_ASSERT(reporter, discardableManager->lockedHandles().count() == 1u);
503
504 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
505 discardableManager->unlockAndDeleteAll();
506}

◆ DEF_TEST() [6/7]

DEF_TEST ( SkRemoteGlyphCache_StrikePinningClient  ,
reporter   
)

Definition at line 543 of file SkRemoteGlyphCacheTest.cpp.

543 {
544 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
545 SkStrikeServer server(discardableManager.get());
546 SkStrikeClient client(discardableManager, false);
547
548 // Server.
549 auto serverTypeface = ToolUtils::CreateTestTypeface("monospace", SkFontStyle());
550 const SkTypefaceID serverTypefaceID = serverTypeface->uniqueID();
551
552 int glyphCount = 10;
553 auto serverBlob = buildTextBlob(serverTypeface, glyphCount);
554
555 const SkSurfaceProps props;
556 std::unique_ptr<SkCanvas> cache_diff_canvas =
557 server.makeAnalysisCanvas(10, 10, props, nullptr, true, true);
559 cache_diff_canvas->drawTextBlob(serverBlob.get(), 0, 0, paint);
560
561 std::vector<uint8_t> serverStrikeData;
562 server.writeStrikeData(&serverStrikeData);
563
564 // Client.
566 client.readStrikeData(serverStrikeData.data(), serverStrikeData.size()));
567 auto* clientTypeface = client.retrieveTypefaceUsingServerIDForTest(serverTypefaceID).get();
568
569 // The cache remains alive until it is pinned in the discardable manager.
571 REPORTER_ASSERT(reporter, !clientTypeface->unique());
572
573 // Once the strike is unpinned and purged, SkStrikeClient should be the only owner of the
574 // clientTf.
575 discardableManager->unlockAndDeleteAll();
577 REPORTER_ASSERT(reporter, clientTypeface->unique());
578
579 // Must unlock everything on termination, otherwise valgrind complains about memory leaks.
580 discardableManager->unlockAndDeleteAll();
581}
static void PurgeFontCache()
Definition: SkGraphics.cpp:72

◆ DEF_TEST() [7/7]

DEF_TEST ( SkTypefaceProxy_Basic_Serial  ,
reporter   
)

Definition at line 1137 of file SkRemoteGlyphCacheTest.cpp.

1137 {
1138 auto typeface = ToolUtils::CreateTestTypeface("monospace", SkFontStyle());
1139 sk_sp<DiscardableManager> discardableManager = sk_make_sp<DiscardableManager>();
1140 SkTypefaceProxyPrototype srcProto{*typeface};
1141
1142 SkBinaryWriteBuffer writeBuffer({});
1143 srcProto.flatten(writeBuffer);
1144
1145 auto data = writeBuffer.snapshotAsData();
1146 SkReadBuffer readBuffer{data->data(), data->size()};
1147 std::optional<SkTypefaceProxyPrototype> dstProto =
1149 REPORTER_ASSERT(reporter, dstProto.has_value());
1150 auto proxy = sk_make_sp<SkTypefaceProxy>(dstProto.value(), discardableManager, false);
1151 REPORTER_ASSERT(reporter, typeface->uniqueID() == proxy->remoteTypefaceID());
1152 REPORTER_ASSERT(reporter, typeface->uniqueID() != proxy->uniqueID());
1153 REPORTER_ASSERT(reporter, typeface->countGlyphs() == proxy->countGlyphs());
1154 REPORTER_ASSERT(reporter, typeface->fontStyle() == proxy->fontStyle());
1155 REPORTER_ASSERT(reporter, typeface->isFixedPitch() == proxy->isFixedPitch());
1156
1157 // Must be multiple of 4 bytes or the buffer will be invalid.
1158 uint8_t brokenBytes[] = {1, 2, 3, 4, 5, 6, 7, 8};
1159 SkReadBuffer brokenBuffer{std::data(brokenBytes), std::size(brokenBytes)};
1160 std::optional<SkTypefaceProxyPrototype> brokenProto =
1162 REPORTER_ASSERT(reporter, !brokenProto.has_value());
1163}
static std::optional< SkTypefaceProxyPrototype > MakeFromBuffer(SkReadBuffer &buffer)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
std::shared_ptr< const fml::Mapping > data
Definition: texture_gles.cc:63

◆ FindSurfaceProps()

SkSurfaceProps FindSurfaceProps ( GrRecordingContext rContext)

Definition at line 210 of file SkRemoteGlyphCacheTest.cpp.

210 {
211 auto surface = MakeSurface(1, 1, rContext);
212 return surface->props();
213}
sk_sp< SkSurface > MakeSurface(int width, int height, GrRecordingContext *rContext)
VkSurfaceKHR surface
Definition: main.cc:49

◆ make_blob_causing_fallback()

sk_sp< SkTextBlob > make_blob_causing_fallback ( sk_sp< SkTypeface targetTf,
const SkTypeface glyphTf,
skiatest::Reporter reporter 
)

Definition at line 702 of file SkRemoteGlyphCacheTest.cpp.

703 {
705 font.setSubpixel(true);
706 font.setSize(96);
707 font.setHinting(SkFontHinting::kNormal);
708 font.setTypeface(targetTf);
709
712
713 char s[] = "Skia";
714 int runSize = strlen(s);
715
717 SkRect bounds = SkRect::MakeIWH(100, 100);
718 const auto& runBuffer = builder.allocRunPosH(font, runSize, 10, &bounds);
719 SkASSERT(runBuffer.utf8text == nullptr);
720 SkASSERT(runBuffer.clusters == nullptr);
721
723 runBuffer.glyphs, runSize);
724
725 SkRect glyphBounds;
726 font.getWidths(runBuffer.glyphs, 1, nullptr, &glyphBounds);
727
729
730 for (int i = 0; i < runSize; i++) {
731 runBuffer.pos[i] = i * 10;
732 }
733
734 return builder.make();
735}
@ kUTF8
uses bytes to represent UTF-8 or ASCII
sk_sp< T > sk_ref_sp(T *obj)
Definition: SkRefCnt.h:381
int textToGlyphs(const void *text, size_t byteLength, SkTextEncoding encoding, SkGlyphID glyphs[], int maxGlyphCount) const
Definition: SkFont.cpp:181
static constexpr uint16_t kSkSideTooBigForAtlas
Definition: SkGlyph.h:333
struct MyStruct s
static SkRect MakeIWH(int w, int h)
Definition: SkRect.h:623
constexpr float width() const
Definition: SkRect.h:762

◆ MakeEmojiBlob()

sk_sp< SkTextBlob > MakeEmojiBlob ( sk_sp< SkTypeface serverTf,
SkScalar  textSize,
sk_sp< SkTypeface clientTf = nullptr 
)

Definition at line 920 of file SkRemoteGlyphCacheTest.cpp.

921 {
923 font.setTypeface(serverTf);
924 font.setSize(textSize);
925
926 const char* text = ToolUtils::EmojiSample().sampleText;
927 auto blob = SkTextBlob::MakeFromText(text, strlen(text), font);
928 if (clientTf == nullptr) return blob;
929
930 SkSerialProcs s_procs;
931 s_procs.fTypefaceProc = [](SkTypeface*, void* ctx) -> sk_sp<SkData> {
932 return SkData::MakeUninitialized(1u);
933 };
934 auto serialized = blob->serialize(s_procs);
935
936 SkDeserialProcs d_procs;
937 d_procs.fTypefaceCtx = &clientTf;
938 d_procs.fTypefaceProc = [](const void* data, size_t length, void* ctx) -> sk_sp<SkTypeface> {
939 return *(static_cast<sk_sp<SkTypeface>*>(ctx));
940 };
941 return SkTextBlob::Deserialize(serialized->data(), serialized->size(), d_procs);
942}
static sk_sp< SkData > MakeUninitialized(size_t length)
Definition: SkData.cpp:116
static sk_sp< SkTextBlob > MakeFromText(const void *text, size_t byteLength, const SkFont &font, SkTextEncoding encoding=SkTextEncoding::kUTF8)
Definition: SkTextBlob.cpp:788
static sk_sp< SkTextBlob > Deserialize(const void *data, size_t size, const SkDeserialProcs &procs)
Definition: SkTextBlob.cpp:855
size_t length
std::u16string text
SkDeserialTypefaceProc fTypefaceProc
SkSerialTypefaceProc fTypefaceProc
Definition: SkSerialProcs.h:93

◆ MakeSurface()

sk_sp< SkSurface > MakeSurface ( int  width,
int  height,
GrRecordingContext rContext 
)

Definition at line 204 of file SkRemoteGlyphCacheTest.cpp.

204 {
205 const SkImageInfo info =
208}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
int32_t height
int32_t width
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)

◆ RasterBlob()

SkBitmap RasterBlob ( sk_sp< SkTextBlob blob,
int  width,
int  height,
const SkPaint paint,
GrRecordingContext rContext,
const SkMatrix matrix = nullptr,
SkScalar  x = 0 
)

Definition at line 215 of file SkRemoteGlyphCacheTest.cpp.

217 {
218 auto surface = MakeSurface(width, height, rContext);
219 if (matrix) {
220 surface->getCanvas()->concat(*matrix);
221 }
222 surface->getCanvas()->drawTextBlob(blob.get(), x, height/2, paint);
224 bitmap.allocN32Pixels(width, height);
225 surface->readPixels(bitmap, 0, 0);
226 return bitmap;
227}
double x
Definition: bitmap.py:1

◆ RasterBlobThroughSlug()

SkBitmap RasterBlobThroughSlug ( sk_sp< SkTextBlob blob,
int  width,
int  height,
const SkPaint paint,
GrRecordingContext rContext,
const SkMatrix matrix = nullptr,
SkScalar  x = 0 
)

Definition at line 229 of file SkRemoteGlyphCacheTest.cpp.

231 {
232 auto surface = MakeSurface(width, height, rContext);
233 if (matrix) {
234 surface->getCanvas()->concat(*matrix);
235 }
236 auto canvas = surface->getCanvas();
237 auto slug = Slug::ConvertBlob(canvas, *blob, {x, height/2.0f}, paint);
238 slug->draw(canvas, paint);
240 bitmap.allocN32Pixels(width, height);
241 surface->readPixels(bitmap, 0, 0);
242 return bitmap;
243}

◆ RasterSlug()

SkBitmap RasterSlug ( sk_sp< Slug slug,
int  width,
int  height,
const SkPaint paint,
GrRecordingContext rContext,
const SkMatrix matrix = nullptr,
SkScalar  x = 0 
)

Definition at line 245 of file SkRemoteGlyphCacheTest.cpp.

247 {
248 auto surface = MakeSurface(width, height, rContext);
249 auto canvas = surface->getCanvas();
250 if (matrix) {
251 canvas->concat(*matrix);
252 }
253 slug->draw(canvas, paint);
255 bitmap.allocN32Pixels(width, height);
256 surface->readPixels(bitmap, 0, 0);
257 return bitmap;
258}

◆ use_padding_options()

static void use_padding_options ( GrContextOptions options)
static

Definition at line 306 of file SkRemoteGlyphCacheTest.cpp.

306 {
307 options->fSupportBilerpFromGlyphAtlas = true;
308}
const char * options