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 // SkTestCanvas is a simple way to make a testing canvas which is allowed to use private 9 // facilities of SkCanvas without having to add a friend to SkCanvas.h. 10 // 11 // You create a Key (a simple empty struct) to make a template specialization class. You need to 12 // make a key for each of the different Canvases you need. The implementations of the canvases 13 // are in SkCanvas.cpp, which allows the use of helper classes. 14 15 #ifndef SkTestCanvas_DEFINED 16 #define SkTestCanvas_DEFINED 17 18 #include "include/core/SkCanvas.h" 19 #include "include/core/SkRefCnt.h" 20 #include "include/private/chromium/SkChromeRemoteGlyphCache.h" 21 22 #include <memory> 23 24 class SkPaint; 25 26 namespace sktext { class GlyphRunList; } 27 28 // You can only make template specializations of SkTestCanvas. 29 template <typename Key> class SkTestCanvas; 30 31 // A test canvas to test using slug rendering instead of text blob rendering. 32 struct SkSlugTestKey {}; 33 template <> 34 class SkTestCanvas<SkSlugTestKey> : public SkCanvas { 35 public: 36 SkTestCanvas(SkCanvas* canvas); 37 void onDrawGlyphRunList( 38 const sktext::GlyphRunList& glyphRunList, const SkPaint& paint) override; 39 }; 40 41 struct SkSerializeSlugTestKey {}; 42 template <> 43 class SkTestCanvas<SkSerializeSlugTestKey> : public SkCanvas { 44 public: 45 SkTestCanvas(SkCanvas* canvas); 46 void onDrawGlyphRunList( 47 const sktext::GlyphRunList& glyphRunList, const SkPaint& paint) override; 48 }; 49 50 struct SkRemoteSlugTestKey {}; 51 template <> 52 class SkTestCanvas<SkRemoteSlugTestKey> : public SkCanvas { 53 public: 54 SkTestCanvas(SkCanvas* canvas); 55 ~SkTestCanvas() override; 56 void onDrawGlyphRunList( 57 const sktext::GlyphRunList& glyphRunList, const SkPaint& paint) override; 58 59 private: 60 std::unique_ptr<SkStrikeServer::DiscardableHandleManager> fServerHandleManager; 61 sk_sp<SkStrikeClient::DiscardableHandleManager> fClientHandleManager; 62 SkStrikeServer fStrikeServer; 63 SkStrikeClient fStrikeClient; 64 }; 65 66 #endif // SkTestCanvas_DEFINED 67